5 ms·
zForth – Tiny, embeddable, flexible, compact Forth for embedded systems
- peter_d_sherman 6y ago>"Some of zForth's highlights: o Small dictionary: instead of relying on a fixed cell size, the dictionary is written in variable length cells: small and common numbers take less space then larger, resulting in 30% to 50% space saving o Portable: zForth is written in 100% ANSI C, and runs on virtually all operating systems and all architectures. Tested on x86 Linux/Win32/MS-DOS (Turbo-C 1.0!), x86_64, ARM, ARM thumb, MIPS, Atmel AVR and the 8051. o Small footprint: the kernel C code compiles to about 3 or 4 kB of machine code, depending on the architecture and chosen cell data types. o Tracing: zForth is able to show a nice trace of what it is doing under the hood, see below for an example. o VM: Implemented as a small virtual machine: not the fastest, but safe and flexible. Instead of having direct access to host memory, the forth VM memory is abstracted, allowing proper boundary checking on memory accesses and stack operations. o Flexible data types: at compile time the user is free to choose what C data type should be used for the dictionary and the stacks. zForth supports signed integer sizes from 16 to 128 bit, but also works seamlessly with floating point types like float and double (or even the C99 'complex' type!) o Ease interfacing: calling C code from forth is easy through a host system call primitive, and code has access to the stack for exchanging data between Forth and C. Calling forth from C is easy, just one function to evaluate forth code."
- samsaga2 6y agoThe only way to write a real forth kernel is in assembler. The use of the cpu registers is very particular. It is impossible to do that with a standard compiler.
- colejohnson66 6y agoWhat do you mean?
- MaxBarraclough 6y agoThey're referring to that the 'traditional'/'proper' way to implement Forth is to write the whole thing in assembly and carefully consider how best to make use of the particular instruction-set.
- airbreather 6y agothey leverage off the c compiler to make it easily transportable and able to use different types, everything is a tradeoff and for the right circumstances this is an excellent one. No one says it has ot be assembler, more the point is it easily could be if you wanted, hence the bringing up of new systems/CPU's often using Forth, you bootstrap more quickly.
- Extigy 6y agoI'm not sure I'd go that far, but certainly one of the really nice things about Forth is that it's so easy to bootstrap up from just assembler into something usable.
- sandwell 6y agoI've seen a lot of embedded Forth stuff recently but I don't get the appeal. Clearly there is some benefit over writing assembly, but why is it preferred over portable C, or even higher level languages such as Python on more powerful mcus? FWIW I felt the same way about LISP for a long time until I fell in love with it via Emacs. So please educate me!
- sn41 6y agoForth is not just another language for the sake of it. I am currently learning Forth from Leo Brodie's excellent books "Starting Forth" and "Thinking Forth". It actually changes the way you think. Just as Lisp does - almost a feeling of "a new planet swims into his ken". The main feature of the Forth style is to write lots of 1 to 2 line functions, in such a way that at the high-level, you have essentially a domain-specific language that looks like exactly what you want a program to look like - for example, "RINSE WASH CYCLE SPIN STOP" for a washing machine program, and "RINSE WASH RINSE WASH CYCLE SPIN STOP" for an extra clean option. People claim that once you learn Forth, you start programming Forth-style in other languages like C, Python etc. I can already see the appeal.
- DiabloD3 6y agoLisp and Erlang also do this. My C sometimes looks like Lispy Erlangish weirdness, and my Java often looks like my C. Certain languages just have certain ways of worming their way into your brain and improving the way you think, much to the dismay of everyone who can't think that way yet because the idiom isn't native to that language (yet).
- sandwell 6y agoI love that effect. My JS changed a lot once I grokked LISP, and I finally understood why there was a Haskell course on my degree track. One of the most rewarding training experiences was giving my old Haskell textbook to a junior team member and watching his (at the time .NET, w/LINQ) code change over the course of a few weekends.
- 6y ago
- alexshendi 6y agoNice. Does build on OpenBSD. :)
- rasterdog 6y agoYou read my mind. Thanks
- MaxBarraclough 6y ago> zForth was written for engineers, not for language purists or Forth aficionados Ironically this sounds very much like the thinking of Forth's creator, Chuck Moore, who never wanted Forth to be a standardised language. Also, here's an old reddit thread where zForth's author answers some questions: https://old.reddit.com/r/Forth/comments/4o0x3z/ https://old.reddit.com/r/Forth/comments/4o0x3z/