[comp.lang.forth] >R, R> in interpret mode

DAVID@PENNDRLS.BITNET (09/25/90)

So how did you make >R and R> work in interpret mode, Mitch?  The only
thing I've been able to come up with so far is state-smartness and
a scratch stack area.

-- R. David Murray    (DAVID@PENNDRLS.BITNET, DAVID@PENNDRLS.UPENN.EDU)

wmb@MITCH.ENG.SUN.COM (Mitch Bradley) (09/25/90)

> So how did you make >R and R> work in interpret mode, Mitch?

I rearranged the text interpreter so that the word is EXECUTEd in the
outer loop.  Something like this:

VARIABLE WORD-TO-EXECUTE

: INTERPRET-WORD  ( counted-string -- )
   FIND
   (decide if the word should be compiled or executed)  IF
       WORD-TO-EXECUTE !        \ If it should be executed
   ELSE
       ,                        \ If it should be compiled
   THEN
;
: INTERPRET
    BEGIN
       BL WORD  DUP C@
    WHILE
       ['] NOOP  WORD-TO-EXECUTE !
       INTERPRET-WORD
       WORD-TO-EXECUTE @ EXECUTE
    REPEAT
    DROP
;

This isn't my exact code, but you get the idea.

Another solution would be to write the outer interpreter as one big
word, like in FIG Forth.  The key point is that the "EXECUTE" must
be at the same nesting level as the interpreter loop.

Oh, one key point about my system, that makes this all possible:
INTERPRET does not exit at the end of every line!  In my implementation,
WORD reads across line boundaries.

Without this feature, the only solution I can think of offhand is to
completely "unfactor" QUIT into one giant word, i.e.

: QUIT
    BEGIN
       QUERY
       BEGIN  BL WORD  DUP C@  WHILE
          FIND ...
             EXECUTE
          ELSE
             ,
          THEN
       REPEAT   DROP
   AGAIN
;

Mitch