Forth Compiler

The compiler for Forth Language.

In the 1970s and 80s, most Forths were implemented as a Threaded Interpretive Language, which is the fastest method of interpretation. In the 1990s, machine code generating Forth's, using various degrees of optimization, became popular.

Swift Forth (www.forth.com ) uses pattern-based peephole optimization. The sequence X Y Z is replaced with code that implements XYZ in a single step, so the pushing and popping between X and Y and Y and Z isn't needed.

VFX Forth (www.mpeltd.demon.co.uk ) and iForth (home.iae.nl ) use traditional optimization techniques to remove much of Forth's stack manipulation.

Color Forth has similar optimizations for the most common primitives, and guarantees Tail Call Optimization.

Forth has a continuum of implementation techniques spanning threaded interpreted up to machine code optimized compilation. Having the compiler and interpreter intermingled tends to blur the distinction. There are half a dozen different major implementation modes, and each can have varying degrees of optimization. For instance, although gforth (GNU forth) remains threaded for portability reasons, it uses dynamic superinstructions to garner a 2-3 times speedup. (For more in superinstructions, see www.complang.tuwien.ac.at and www.complang.tuwien.ac.at .)


See original on c2.com