home *** CD-ROM | disk | FTP | other *** search
/ ProfitPress Mega CDROM2 …eeware (MSDOS)(1992)(Eng) / ProfitPress-MegaCDROM2.B6I / PROG / MISC / FPC355_5.ZIP / TCOM80.ZIP / LABEL80.SEQ < prev    next >
Encoding:
Text File  |  1991-04-25  |  3.7 KB  |  126 lines

  1. \\ LONGLABL.SEQ         Modified local labels for long branches
  2.  
  3. {
  4.  
  5. : %"ERRMSG3     ( cfa A1 N1 -- )        \ a dummy filler till real one
  6.                 cr type drop ;
  7.  
  8. DEFER "ERRMSG3  ' %"errmsg3 is "errmsg3
  9.  
  10. ASSEMBLER DEFINITIONS ALSO
  11.  
  12. DEFER T@        FORTH ' @       ASSEMBLER IS T@
  13.  
  14. ' HERE ALIAS ASMHERE
  15.  
  16. }
  17.  =========================================================
  18.                BEGIN LOCAL LABELS SECTION:
  19.  =========================================================
  20.  
  21. {
  22.  
  23. FORTH DEFINITIONS
  24.  
  25.   0 value ?long
  26.   0 value ?long_lib
  27.  
  28. : long_branch   ( -- )
  29.                 on> ?long ;
  30.  
  31. \ : short_branch  ( -- )
  32. \                 off> ?long ;
  33.  
  34. : long_library  ( -- )
  35.                 on> ?long_lib ;
  36.  
  37. \ : short_library ( -- )
  38. \                 off> ?long_lib ;
  39.  
  40. long_branch            \ default to LONG branches
  41. long_library           \ also use LONG branches in library
  42.  
  43. ASSEMBLER DEFINITIONS
  44.  
  45. }
  46.  Translates a label reference to the appropriate dictionary
  47.  location and sets the "ever referenced?" flag.
  48.  
  49.  If the reference is a forward reference, then a linked list
  50.  of the forward references themselves is built using the
  51.  dictionary byte locations where the jump offsets are
  52.  "compiled".  The reason for using this technique at all is
  53.  that it allows an arbitrary number of forward references per
  54.  label to be made (within the jump offset limitations of
  55.  course) and that it requires table space only for the linked
  56.  list head pointer.  The technique is eloquent if convoluted
  57.  and, as a minimum, needs explanation.
  58. {
  59.  
  60. ' $ ALIAS $|    ( n1 -- n2 )
  61.  
  62. }
  63.  Resolves all local label forward references for a given
  64.  label.
  65. {
  66.  
  67. : >resW ( ^line -- )
  68.         [ FORTH ]
  69.         2+ @ dup 0=     \ if nothing to resolve
  70.         IF      drop exit               \   then exit
  71.         THEN                            \ stack contains addr to be resolved
  72.         BEGIN   1+ DUP T@ >R ASMHERE OVER T!
  73.                 R> TUCK - 1- 0=         \ loop till branch to self
  74.         UNTIL   DROP ;
  75.  
  76. : $$:w  ( n -- )                \ defines a local label
  77.         [ FORTH ]
  78.         true !> ll-used?        \ set "labels used?" flag
  79.         llab>line
  80.         dup @ 0<>
  81.         if      0 " Label can't be multiply defined" "errmsg3 abort
  82.         then
  83.         dup >resW               \ resolve forward references if needed
  84.         ASMHERE swap ! ;        \ and set label for subsequent refs
  85.  
  86. : >resF ( ^line -- )
  87.         [ FORTH ]
  88.         2+ @ dup 0=     \ if nothing to resolve
  89.         IF      drop exit               \   then exit
  90.         THEN                            \ stack contains addr to be resolved
  91.         BEGIN   DUP T@ >R ASMHERE OVER T!
  92.                 R> TUCK - 0=            \ loop till branch to self
  93.         UNTIL   DROP ;
  94.  
  95. : $$:f  ( n -- )                \ defines a local label
  96.         [ FORTH ]
  97.         true !> ll-used?        \ set "labels used?" flag
  98.         llab>line
  99.         dup @ 0<>
  100.         if      0 " Label can't be multiply defined" "errmsg3 abort
  101.         then
  102.         dup >resF               \ resolve forward references if needed
  103.         ASMHERE swap ! ;        \ and set label for subsequent refs
  104.  
  105.                         \ word resolution resolve, for JMP type instructions
  106. : $:|   ( n -- )        \ allow use as prefix/postfix
  107.         [ FORTH ]
  108.         ['] $$:w a;! a; a; ;
  109.  
  110. ' $:| alias $:
  111.  
  112.                         \ word resolution resolve, for FORTH type branches
  113. : $:F   ( n -- )        \ allow use as prefix/postfix
  114.         [ FORTH ]
  115.         ['] $$:f a;! a; a; ;
  116.  
  117. FORTH DEFINITIONS
  118.  
  119. ONLY FORTH ALSO DEFINITIONS
  120.  
  121. }
  122.  =========================================================
  123.                 END LOCAL LABELS SECTION:
  124.  =========================================================
  125.  
  126.