home *** CD-ROM | disk | FTP | other *** search
/ Fresh Fish 5 / FreshFish_July-August1994.bin / bbs / dev / aforth-1.4.lha / AForth-1.4 / progs / stepdown.f < prev   
Encoding:
Text File  |  1994-03-31  |  942 b   |  28 lines

  1. ( New looping construct STEP..DOWN)
  2. ( This code is provided as an example of how to build new constructs in)
  3. ( AFORTH, this is a fairly trivial example, for more details study the)
  4. ( the source for the CASE..OF..ENDOF..ENDCASE construct and refer to the)
  5. ( books listed in the bibliography)
  6. ( Copyright © Stratagem4, 1994)
  7.  
  8. : STEP    ( loop counter handler)
  9.     COMPILE >R    ( loop counter to return stack)
  10.     HERE ;        ( place HERE on stack)
  11. IMMEDIATE        ( always executes, remember control constructs are always)
  12.                 ( compiler words)
  13. : (DOWN)    ( the actual run-time routine)
  14.     DR>        ( fetch return address)
  15.     R>        ( and loop counter)
  16.     1- DUP IF    ( decrement counter)
  17.         >R        ( save new value)
  18.         D@ D>R    ( and branch address)
  19.     ELSE    ( end of loop)
  20.         DROP    ( drop loop counter)
  21.         4D+ D>R    ( skip over branch address)
  22.     THEN ;
  23.  
  24. : DOWN    ( loop implementor)
  25.     COMPILE (DOWN)    ( compile run-time code)
  26.     D, ;        ( save HERE from STEP in dictionary)
  27. IMMEDIATE    ( always executes)
  28.