home *** CD-ROM | disk | FTP | other *** search
/ Power-Programmierung / CD1.mdf / forth / compiler / love / chap04.doc < prev    next >
Text File  |  1993-04-11  |  4KB  |  117 lines

  1. Chapter4                L_O_V_E FORTH
  2.  
  3.  
  4. 4.0  L.O.V.E. Forth Compatability Notes
  5.      ----------------------------------
  6.  
  7.     Here are some notes on compatibility between single segment forth
  8. 83 systems and L.O.V.E. Forth.
  9.  
  10. Storing into CONSTANTs
  11.  
  12. Old:  0 CONSTANT #flower-pots
  13.       44 ' #flower-pots >BODY !
  14.  
  15. Love: 0 CONSTANT #flower-pots
  16.       44 ' #flower-pots TS:>BODY TS:!
  17.  
  18.     In L.O.V.E. Forth, the data cell for   CONSTANT   is stored in the
  19. thread Segment.  TS:! is like ! and TS:>BODY is like >BODY but are directed
  20. to the thread segment.
  21.  
  22. Revectoring
  23.  
  24. Old:      : PRINTER-EMIT PRN1-EMIT ;
  25.           ' COM1-EMIT ' PRINTER-EMIT >BODY !
  26.           (where PRN1-EMIT and COM1-EMIT have been previously defined)
  27.  
  28. Love:     ' COM1-EMIT ' PRINTER-EMIT TS:>BODY TS:!
  29.  
  30.     In L.O.V.E. Forth the threaded addresses are changed/stored with
  31. TS:! .  Note that revectoring can more easily be accomplished with the
  32. revecoring  word set   REDEFINE   RESTORE    MAKE_DYNAMIC GETVECTOR etc).
  33. See the  documentation of these words for more information.
  34.  
  35. Adding code to the dictionary
  36.  
  37.     Sometimes in compiler words, code or branching offsets are added to
  38. the dictionary with , .  This cannot be used in L.O.V.E. Forth as , (comma)
  39. adds to the variable segment (VS:). To add to the thread segment the word
  40. TS:, is used.
  41.  
  42.         For example:
  43.         : AGAIN   COMPILE BRANCH  ,     ; IMMEDIATE
  44.  
  45.         becomes:
  46.         : AGAIN   COMPILE BRANCH  TS:,  ; IMMEDIATE
  47.  
  48.     COMPILE   and   [COMPILE]   perform their expected functions.
  49. Compiler words using these will work in L.O.V.E. Forth as in other forths.
  50. Note that the following standard words are also implemented, to make
  51. control structures easy:   <MARK   <RESOLVE   >MARK   >RESOLVE
  52.  
  53.  
  54. CREATE - DOES>
  55.  
  56.     In standard Forth   CREATE DOES>   words are used both for defining
  57. data structures and for defining run-time words (such as CASE statements).
  58. These functions are destinct in L.O.V.E. Forth.
  59.  
  60.     CREATE  DOES> pair at run time returns an address in the VS: as a
  61. parameter field for data storage uses,   CREATE:  DOES:> pair at run-time
  62. returns an address in the   TS: for use in defining control structures etc.
  63.  
  64. Example 1.
  65.  
  66.       ( word to create a byte array )
  67.       : CARRAY CREATE ALLOT             ( comp time: n -- )
  68.       DOES> + ;                         ( run time: n -- addr )
  69.  
  70.       20 CARRAY flower-power
  71.       20 CARRAY flower-tower
  72.       5 flower-power C@  19 flower-tower C!  ( set location 19)
  73.  
  74.       Here there is no change from other standard Forths.
  75.  
  76. Example 2.
  77.  
  78.       ( a word to make case statements )
  79.       (    it works by fetching a spec'd thread to execute )
  80.       : CASE: CREATE: ] SMUDGE          ( comp time:  -- )
  81.       DOES:> SWAP 2* + TS:@ EXECUTE ;   ( run time: n -- )
  82.  
  83.       CASE: FLOWER-TYPES
  84.             PETUNIA   ROSE    DANDYLION  CHRYSANTHEMUM ;
  85.  
  86.       Here the   CREATE: DOES:> pair and TS:@ replace the CREATE DOES>
  87.       and @ from standard Forth.
  88.  
  89. Example 3.
  90.  
  91.       Note that   CREATE   alone can still be used for data storage,
  92.       as in other Forths
  93.  
  94.       CREATE #leaves-per-flower
  95.       4 C, 5 C, 1 C, 27 C, 102 C, 7 C,
  96.  
  97.       #leaves-per-flower 4 + C@ .      ( would print 102 )
  98.  
  99.       However if   CREATE   is used for compiling a list of threads
  100.       CREATE: must be used, and access must be made with TS:@  .
  101.  
  102.       CREATE: FLOWER-DESCRIPTIONS ]
  103.          PERRYWINKLE   BATCHELORS-BUTTON  FORGET-ME-NOT [
  104.  
  105.       FLOWER-DESCRIPTIONS 2+ TS:@ EXECUTE
  106.  
  107.       CREATE: and TS:@ replace   CREATE   and @ from standard Forth.
  108.  
  109. Example 4.
  110.  
  111.     Love Forth always allots   VARIABLES   and   DVARIABLES   on an
  112. even byte boundary (in VS:).  This means that   HERE   may be increased by
  113. an extra byte on occation.  To disable this, simply re-define VARIABLE
  114. and   DVARIABLE:
  115.  
  116.       : VARIABLE  CREATE   2 ALLOT ;
  117.       : DVARIABLE VARIABLE 2 ALLOT ;