As I said, the example is straight out of "Thinking Forth". It's in Appendix B where Leo Brodie explains how
DOER/MAKE works and gives implementations for various Forth systems. I don't think any of them were subroutine threaded systems though. I don't know if the Forth you're using is ITC ( indirect threaded ), DTC ( direct threaded ), or STC ( subroutine threaded ), or possibly some other threading technique. I successfully ported
DOER/MAKE to my Forth, Fleet Forth for the Commodore 64, a short while ago. It's an ITC Forth. Last night I took a look at Durex Forth for the Commodore 64. It appears to use subroutine threaded code. I managed to port
DOER/MAKE to it. Be warned! it has had minimal testing! That said, it should work with other subroutine threaded Forths for the 6502 based processors. Maybe someone using Tali Forth or Liara Forth could test it?
Code:
( DOER/MAKE For A Subroutine Threaded Forth)
: NOTHING ;
: DOER
CREATE ['] NOTHING , DOES>
@ 1- >R ;
VARIABLE DMARKER \ Doer marker
: (MAKE)
R> 1+ DUP 2+ DUP 3 +
SWAP 1+ @ >BODY !
@ ?DUP IF >R THEN ;
: MAKE
STATE @ 0= ABORT" COMPILING ONLY!"
POSTPONE (MAKE)
HERE DMARKER ! 0 , ; IMMEDIATE
: ;AND
POSTPONE EXIT
HERE 1- DMARKER @ ! ; IMMEDIATE
: UNDO
['] NOTHING ' >BODY ! ;
If you've had time to read "Thinking Forth", you'll notice one ability that's missing. The ability to use
MAKE outside a colon definition to create an unnamed section of high level code that the
DOER word performs. That ability is
not needed in the examples I've shown and it would require knowledge of how a given system implements
: ( colon) and
; ( semicolon).
Cheers,
Jim
[Edit: Corrected two typos.]