home *** CD-ROM | disk | FTP | other *** search
- ( New looping construct STEP..DOWN)
- ( This code is provided as an example of how to build new constructs in)
- ( AFORTH, this is a fairly trivial example, for more details study the)
- ( the source for the CASE..OF..ENDOF..ENDCASE construct and refer to the)
- ( books listed in the bibliography)
- ( Copyright © Stratagem4, 1994)
-
- : STEP ( loop counter handler)
- COMPILE >R ( loop counter to return stack)
- HERE ; ( place HERE on stack)
- IMMEDIATE ( always executes, remember control constructs are always)
- ( compiler words)
- : (DOWN) ( the actual run-time routine)
- DR> ( fetch return address)
- R> ( and loop counter)
- 1- DUP IF ( decrement counter)
- >R ( save new value)
- D@ D>R ( and branch address)
- ELSE ( end of loop)
- DROP ( drop loop counter)
- 4D+ D>R ( skip over branch address)
- THEN ;
-
- : DOWN ( loop implementor)
- COMPILE (DOWN) ( compile run-time code)
- D, ; ( save HERE from STEP in dictionary)
- IMMEDIATE ( always executes)
-