F– (pronounced "F minus") is an implementation of ANS Forth that uses a VM generator running on an ANS Forth to compile Forth into source code suitable for plugging into a C-based microcontroller project. F– can easily invoke C functions, or include chunks of C code, since C is its "assembly language". C projects can execute F– functions by invoking the VM. F– allows arbitrary backends to be plugged in so it can be used to express the VM in languages other than C such as assembly, Ada, Verilog, Forth, etc. Forth Inc. offers a concise description of Forth:
Forth is a computer programming language originally designed for embedded and real-time applications. It's a high-level language characterized by an interactive programming style, which dramatically shortens development times, and by extremely small target program size.
The purpose of F– is to provide a portable yet efficient computing platform for embedded applications. It uses a thin client debugger in conjunction with a host PC to provide an interactive Forth console. The target CPU fits a 32-bit VM, math and I/O libraries, multitasker and debugger into a ROM footprint between 4KB and 8KB depending on target language and size/speed tradeoffs. ANS Forth may be used as the target language, enabling you to build a simulator that runs on your PC to model peripherals and missing hardware while executing the same binary that will run on your MCU. This allows a significant amount of development before hardware is available.
The VM uses a fast interpreter to execute bytecode fetched from application memory. Bytecode applications are far more compact than equivalent compiled C applications, allowing more features to be squeezed into a given microcontroller. The experience of the major Forth companies who have C and Forth versions of the same application is that the Forth version generally compiles to half the size of the C version. Since the token threading used by F– is even more compact than this, you can expect to see a 3:1 size advantage (compared to C) when compiling applications for F–. Even so, you can run really large applications without much on-chip ROM (maybe your C libraries used it all up) since the cost of going off-chip to a serial SPI flash is small when time-critical code is on-chip.
F–'s compiler creates a VM as single file of source code containing the ROM image of your Forth application and the VM that executes it. The C version, for example, produces vm.c and vm.h. F– provides a processor-independent platform for running compact applications, leveraging the productivity and compactness of Forth against advances in mainstream tools.
F– loads on top of a 32-bit ANS Forth. If you are using Windows, you will need one of the following:
SwiftForth, a commercial Forth. Evaluation version is suitable.
Win32forth, an open-source Forth.
VFX, another commercial Forth.
If you are using Linux, you can use gForth. At this point, the debugger serial port hasn't been ported to gForth/Linux but hopefully someone will do this.
See the download section of the project page.
See Making contributions to Fminus. If you would rather not hassle with SourceForge's CVS, you can use the discussion group to point out bugs and opportunities for improvement.
There are plenty of things to do:
Expand the user's manual and provide more examples. This is probably the most important, since most people who would benefit from F– are not Forth experts. DPANS94 and “The optional Cross-compiler word set” (XC*5.PDF) should be used as the functional specifications.
Tidy up areas of ANS non-compliance and bugs/features. Also tweak the C code generator.
Port serial.f to gForth/Linux.
Make demo projects for more evaluation boards.
Find a faster way to operate COM ports.
Write a Verilog or VHDL code generator.
Write assembly generators for targets whose C compilers suck.
Here are some free online resources:
Forth Inc. sells a good textbook:
The “Forth Programmer's Handbook”, 3rd edition by Conklin & Rather
This Open Source project is hosted on Source Forge.
Different parts of F– have different licenses:
The generic code generator and the debugger are GPL.
The language-specific code generators (which are libraries of sorts) and source libraries are LGPL.
The license boilerplate of the source code generated by the code generator is user-defined. The license in the archive is “Public Domain” but is easily replaced so you can protect the machine-generated code that ends up in your project.
Lots of thanks to those who have helped make F– possible, among which are:
Charles Moore, who invented Forth and colorForth.
Forth Inc. which promoted ANS Forth and a defacto cross-compiler standard, and produced a textbook-grade handbook.
Tom Zimmer and the Win32forth working group.
Bill Muench, author of eForth.