home *** CD-ROM | disk | FTP | other *** search
/ ProfitPress Mega CDROM2 …eeware (MSDOS)(1992)(Eng) / ProfitPress-MegaCDROM2.B6I / PROG / MISC / FPC355_4.ZIP / TCOMSRC.ZIP / LONGLABL.SEQ < prev    next >
Encoding:
Text File  |  1990-01-31  |  3.7 KB  |  119 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. short_branch            \ default to short branches
  41. short_library           \ also use short 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. : >resL ( ^line -- )
  68.         [ FORTH ]
  69.         2+ @ dup 0=     \ if nothing to resolve
  70.         IF      drop exit           \   then exit
  71.         THEN    DUP>R
  72.      1+ BEGIN                       \ stack contains directory address of
  73.                                     \   displacement to be resolved
  74.                 DUP 1- TC@ $E9 =        \ if we have a JMP WORD instruction
  75.                 IF      DUP T@ >R               \ save link for now
  76.                         ASMHERE OVER - 2-       \ calculate displacement
  77.                         OVER T!                 \ and put in jump instruction
  78.                         R> $FFFD OVER <>        \ $FFFD signifies end of list
  79.                 ELSE    DUP TC@ >R
  80.                         ASMHERE OVER - 1-
  81.                         DUP $7F U>
  82.                         if      0 " Branch out of range, use LONG_BRANCH"
  83.                                 "errmsg3 abort
  84.                         then
  85.                         OVER TC! R> $FE OVER <> \ $FE signifies end of list
  86.                 THEN
  87.         WHILE
  88.                 R@ TC@ $E9 <>
  89.                 IF      $ff00 or    \ sign extend since link is backward
  90.                 THEN
  91.                 + 2+                \ now move to next item on list
  92.         REPEAT
  93.         R>DROP  2DROP ;
  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 >resL               \ resolve forward references if needed
  103.         ASMHERE swap ! ;        \ and set label for subsequent refs
  104.  
  105. : $:|   ( n -- )        \ allow use as prefix/postfix
  106.         [ FORTH ]
  107.         ?LONG 0=
  108.         IF      ['] $:f
  109.         ELSE    ['] $$:f
  110.         THEN    a;! a; ;
  111.  
  112. ONLY FORTH ALSO DEFINITIONS
  113.  
  114. }
  115.  =========================================================
  116.                 END LOCAL LABELS SECTION:
  117.  =========================================================
  118.  
  119.