A significantly reduced set of and in some cases redefined semantics for Forth primitives. The intention is to take advantage of the existing microprocessor as much as possible as a stack CPU. Many CPUs are amazingly adept at doing this, with only relatively minor amounts of compiler intelligence. Resulting binaries offer adequate (but certainly not stellar) performance, and is often possible with a compiler measuring only a few hundreds of bytes.
Typical characteristics of a MachineForth include:
- Tail recursion elimination
- Non-destructive IF (in ANSI Forth, IF pops the value it tests off the stack; in MachineForth, IF actually tests the CPU's zero flag directly).
- A new core word, -IF, is used to quickly check for less-than-zero conditions.
- ?, 0=, or some other primitive to set the CPU's zero-flag correctly for the benefit of IF.
- 0< or similar primitive to set the CPU's negative-flag correctly for the benefit of -IF.
- Compiled words have no headers in the output image; the output of a MachineForth compiler is very often a static binary image, as you'd get from, say, a C compiler.
Despite the fact that
MachineForth actually is at a lower-level than ANSI Forth when starting out, it still is a meta-language, and hence, can evolve towards higher levels of abstraction very quickly. Due to the reduction in control flow and tail recursion elimination, it can often do so more compactly as well.
See http://www.colorforth.com/forth.html for a sample mapping of ColorForth primitives, derived from an earlier set of MachineForth primitives, and how they map to Intel Pentium machine language instructions. The chart isn't as clear as I'd like, but it saves me from having to cut-n-paste-n-clean-up here.
Contrast with AnsForth.
See also SeaForthArchitecture