Jul 15 2009
Progress Report: My Forth Interpreter
Implementing my own Forth interpreter is taking a little longer than anticipated. Each Forth word is almost like a puzzle. What’s the smallest number of words each can be written in? What’s the most efficient implementation? For an example, take a look at Implementing MIN in Forth without Conditional Code. The smallest version of MIN is 2 words shorter than eForth’s MIN.
Even words with a trivial implementation can pose an interesting problem. For example which of the following is most efficient:
Jones Forth TUCK (Corrected)
: TUCK DUP -ROT ;
Alternative TUCK
: TUCK SWAP OVER ;
If DUP, -ROT, SWAP and OVER are all primative, the alternative implementation will execute two fewer instructions on an 80×86 Forth. However, -ROT is often implemented in Forth which would cause the Jones Forth TUCK to be substantially slower. Here’s a typical implementation of -ROT:
: -ROT SWAP >R SWAP R> ;
Note: there’s an error in Jones Forth. The implementation of ROT and -ROT are reversed.
If you can think of an alternative two word implementation of TUCK or four word implementation of -ROT, please let me know.








: -rot ( a b c — c a b ) rot rot ;