&
- Advertise Here with Today.com
 

Jul 15 2009

Progress Report: My Forth Interpreter

Published by impomatic at 12:37 pm under Programming, forth Edit This

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.

Share and Enjoy:
  • Digg
  • Sphinn
  • del.icio.us
  • Facebook
  • Mixx
  • Google
  • StumbleUpon
  • TwitThis
Possibly-related Articles:                                        (auto-generated)
- Advertise Here with Today.com

One Response to “Progress Report: My Forth Interpreter”

  1. Anonymouson 18 Sep 2009 at 9:37 pm edit this

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

Trackback URI | Comments RSS

Leave a Reply

- Advertise Here
Some Today.com contributors may have received a fee or a promotional product or service from a manufacturer for promotional consideration, while others receive no consideration at all. Each contributor is responsible for disclosing any such promotional consideration.