home *** CD-ROM | disk | FTP | other *** search
/ ProfitPress Mega CDROM2 …eeware (MSDOS)(1992)(Eng) / ProfitPress-MegaCDROM2.B6I / PROG / MISC / FPC355_5.ZIP / TCOM96.ZIP / TCOM96 / COMPILER / OPT96.SEQ < prev    next >
Encoding:
Text File  |  1991-04-22  |  10.2 KB  |  310 lines

  1. \ OPTIMIZ.SEQ     Library Optimizers for Target Compiler
  2.  
  3. ONLY FORTH ALSO COMPILER ALSO DEFINITIONS TARGET ALSO
  4.  
  5. >FORTH
  6.  
  7. : TVER ." \2 80196 Version 1.01 \2" ;
  8. ' TVER IS TVERSION              \ install startup message
  9.  
  10. ' NOOP IS DATA-SEG-FIX          \ not a segmented machine
  11.  
  12. WARNING OFF                     \ NO REDEFINITION WARNING IN LIBRARY
  13. FORTH                           \ we want a Forth NOT a target variable
  14. VARIABLE IMM-HERE               \ Most recent place where immediate move
  15.                                 \ to BX was compiled
  16.  
  17. \ ***************************************************************************
  18. \ New function for END-CODE, needs to not use REVEAL
  19.  
  20. ASM96 also forth also
  21.  
  22. : CEND-CODE     ( -- )
  23.                 ll-global? 0=
  24.                 if      ll-errs?        \ check for local label errors
  25.                 then
  26.                 ARUNSAVE IS RUN
  27.                 PREVIOUS A; ;
  28.  
  29. previous previous target
  30.  
  31. : %END-MACRO    ( -- )          \ complete assembly of a MACRO
  32.                 ?reopt
  33.                 [ASM96]
  34.                 compile a;                      \ make sure ASM96 is done
  35.                 compile cend-code               \ pop ASM96 vocabulary
  36.                 [compile] FOR; ;                \ complete colon def
  37.  
  38. ' %END-MACRO IS END-MACRO       \ install in END-MACRO
  39.  
  40. : %END-LCODE    ( -- )          \ complete assembly of a LCODE
  41.                 ?reopt
  42.                 [ASM96]
  43.                 compile a;                      \ make sure ASM96 is done
  44.                 compile cend-code               \ pop ASM96 vocabulary
  45.                 compile do_resolve              \ resolve forward references
  46.                 [compile] FOR; ;                \ complete colon def
  47.  
  48. ' %END-LCODE IS END-LCODE       \ install in END-LCODE
  49.  
  50. : %END-L:       ( -- )          \ complete a library CALL definition
  51.                 [ASM96]
  52.                 compile setassem
  53.                 compile ret
  54.                 compile a;                      \ make sure ASM96 is done
  55.                 compile cend-code               \ pop ASM96 vocabulary
  56.                 compile unnest ;
  57.  
  58. ' %END-L: IS END-L:
  59.  
  60. : %END-LM:      ( -- )          \ complete a library MACRO : definition
  61.                 [ASM96]
  62.                 compile setassem
  63.                 compile cend-code
  64.                 compile unnest ;
  65.  
  66. ' %END-LM: IS END-LM:
  67.  
  68. ' NOOP IS START-T:
  69.  
  70. : %END-T: ( -- ) \ complete a target CALL definition
  71. \        [ASM96]
  72. \        setassem                \ do ASM96 setup
  73.         %on>  callbyte
  74.         $0F0 C,-T                       \ compile RET
  75. \        ret a;                  \ terminate with a RET instruction
  76.         %off> callbyte
  77.         ;
  78. \        fend-code ;             \ do ASM96 finishup
  79.  
  80. ' %END-T: IS END-T:
  81.  
  82. : %COMP_CALL ( a1 -- )  \ compile a target CALL
  83.                         \ a1 = CFA of symbol
  84.         %on>  callbyte
  85.         $0EF C,-T                       \ compile CALL
  86.         %off> callbyte
  87.         dup     >resaddr @ dup -1 <>    \ if resolved already
  88.         if      here-t 2+ - ,-T         \ resolve this call
  89.                         >count incr             \ bump use count
  90.                                         \ ELSE, add it to the chain of
  91.         else    drop                    \ discard the "-1"
  92.                                                 \ references to be resolved.
  93.                         dup >chain @ ,-T        \ link chain @ to here
  94.                         here-t 2- over >chain ! \ link here into chain
  95.                         >res                    \ add to resolution stack
  96.         then
  97.         ;
  98.  
  99. ' %COMP_CALL IS COMP_CALL
  100.  
  101. : %COMP_JMP_IMM ( a1 -- )                      \ a1 = actual address
  102.         %on>  firstcodebyte
  103.         233 C,-T
  104.         %off> firstcodebyte
  105.         %on>  othercodebyte
  106.         HERE-T 2+ - ,-T
  107.         %off> othercodebyte
  108.         ;
  109.  
  110. ' %COMP_JMP_IMM IS COMP_JMP_IMM
  111.  
  112. : %SUB_RET      ( -- )
  113.                 -1 ALLOT-T ;
  114.  
  115.  
  116. ' SUB_RET IS SUB_RET
  117.  
  118. : %TCODE-START  ( -- )
  119.                 setassem
  120.                 [assembler]
  121.                 llab-init ;
  122.  
  123. ' %TCODE-START IS TCODE-START
  124.  
  125. : %LCODE-START  ( -- )
  126.                 compile tcode-start     \ initialize the ASM96
  127.                 ASM96 ;             \ and select ASM96 vocabulary now!
  128.  
  129. ' %LCODE-START IS LCODE-START
  130.  
  131. : %MACRO-START  ( -- )
  132.                 compile setassem        \ initialize the ASM96
  133.                 ASM96 ;             \ and select ASM96 vocabulary now!
  134.  
  135. ' %MACRO-START IS MACRO-START
  136.  
  137. ASM96 ALSO              \ words for defining ram space
  138. : DCB  tlabel 0 C,    [compile] end-code ;
  139. : DCW  tlabel 0 ,     [compile] end-code ;
  140. : DCL  tlabel 0 , 0 , [compile] end-code ;
  141.  
  142.  
  143. \ ***************************************************************************
  144. \ Start of the set of functions supported in the target compiler.
  145. \ These are mostely macros which will compile in-line assembly code.
  146. \ Colon definitions are compiled as routines when defined, and are
  147. \ accessed by a CALL when referenced.
  148.  
  149. ONLY FORTH ALSO COMPILER ALSO HTARGET ALSO TARGET ALSO DEFINITIONS
  150. ASM96 ALSO
  151.  
  152. >LIBRARY                        \ Select the Library versions of
  153.                                 \ defining words.
  154.  
  155. \ ***************************************************************************
  156. \ DONOT CHANGE the first three instructions of SYSINIT. The ADD instruction
  157. \ must be HOT patched by the image save routine so DS will be set properly
  158. \ when the image loads in. The $E4F6 value is verified by the patch routine
  159. \ to make sure the code has not changed. It is then replaced with the proper
  160. \ value to add to AX so DS will be correct.
  161.  
  162. VARIABLE DP                     \ DP is really a variable that always exists,
  163.                                 \ and is always at address DATA-START.
  164. DP [FORTH] DROP [TARGET]        \ allocate it NOW to assure it's at
  165.                                 \ the beginning.
  166. hex
  167. 1A      constant        psp
  168. 1C      constant        w0
  169. 1D      constant        w1
  170. 1E      constant        w2
  171. 1F      constant        w3
  172. 20      constant        ttos
  173. 21      constant        ttosh
  174.         ' ttosh alias   ttos1
  175. 22      constant        ttos2
  176. 23      constant        ttos3
  177.  
  178. 24 Dseg registers
  179. decimal
  180.  
  181. comment:
  182. hex                             \ kernel registers
  183. 1A      constant        ROW_COUNTER
  184. 1C      constant        DPOINT          \ pointers and counters
  185. 20      constant        DCOUNT          \ for display block move
  186.  
  187. 22      constant        SP_FLAGS        \ serial port status image
  188.  
  189. 2E      constant        psp
  190. 30      constant        w0
  191. 31      constant        w1
  192. 32      constant        w2
  193. 33      constant        w3
  194. 34      constant        ttos
  195. ttos 1+ constant        ttosh
  196.                                 \ application registers
  197. 36      constant        tlcdx
  198. 38      constant        tlcdy
  199. 3A      constant        tcolor
  200.  
  201. decimal
  202. comment;
  203.  
  204. MACRO IMAGE-INIT ( -- )         \ Target compiler runtime initialization
  205.                 [ASM96]
  206.  
  207.        END-MACRO
  208.  
  209. FORTH DEFINITIONS               >FORTH
  210.  
  211.  
  212. : TARGET-INIT   ( -- )          \ initialize the terget compiler
  213.                 ?LIB ABORT" Cant use TARGET-INIT in a library routine"
  214.                 ONLY FORTH ALSO COMPILER ALSO
  215.                 TARGET ALSO DEFINITIONS ASM96 ALSO
  216.                 tseg_init       \ Initialize the target compile buffer
  217.                 >target         \ select target defining words
  218.                 target          \ Select the target vocabulary
  219.                 ;  IMMEDIATE
  220.  
  221. ' TARGET-INIT IS TARGET-INITIALIZE
  222.  
  223. ASM96 DEFINITIONS FORTH     >LIBRARY
  224.  
  225. \ ***************************************************************************
  226. \                           OPTIMIZERS !!
  227. \ ***************************************************************************
  228. \ Optimizer for the ! (store) MACRO. Looks for the following instruction
  229. \ sequence:
  230. \               DEC SI
  231. \               DEC SI
  232. \               MOV 0 [SI], BX
  233. \               MOV BX, # xxxx
  234. \               LODSW
  235. \               MOV 0 [BX], AX
  236. \
  237. \ When these instructions are found preceeding a store instruction, they
  238. \ are changed to:
  239. \               MOV AX, BX
  240. \               MOV xxxx ax
  241. \
  242. \ This provides a substantial savings in both space and time.
  243.  
  244. FORTH   >FORTH
  245.  
  246.  
  247.  
  248. \ ***************************************************************************
  249. \ A second optimizer for the ! (store) MACRO. Looks for the following
  250. \ instruction sequence:
  251. \
  252. \               DEC SI                                          3 cycles
  253. \               DEC SI                                          3 cycles
  254. \               MOV 0 [SI], BX          \ save BX              14 cycles
  255. \               MOV BX, # xxxx          \ LIT xxxx              4 cycles
  256. \               MOV yyyy BX             \ memory yyyy store     9 cycles
  257. \               LODSW                   \ load BX              12 cycles
  258. \               MOV BX, AX                                      2 cycles
  259. \
  260. \ When these instructions are found preceeding a store instruction, they
  261. \ are changed to:
  262. \
  263. \               MOV yyyy # xxxx WORD                            10 cycles
  264. \
  265. \ This provides a savings of 8 bytes and 37 cycles per occurance.
  266.  
  267.  
  268. >LIBRARY
  269.  
  270. \ ***************************************************************************
  271. \ Optimizer for the @ (fetch) MACRO. Looks for this instruction sequence
  272. \ to preceed it:
  273. \               MOV BX, # xxxx
  274. \
  275. \ When these instructions are found preceeding a store instruction, they
  276. \ are changed to:
  277. \               MOV bx, xxxx
  278. \
  279. \ This provides a savings in both space and time.
  280.  
  281. FORTH   >FORTH
  282.  
  283.  
  284. >LIBRARY
  285.  
  286. \ ***************************************************************************
  287. \ MACRO to move TTOS to the stack and vice versa
  288. \ ***************************************************************************
  289.  
  290. FORTH   >FORTH
  291.  
  292.  
  293. : SAVE_TTOS     ( -- )          \ macro to SAVE TTOS, not an optimizer
  294.                 A;
  295.                 [ASM96]
  296.                 SUB  PSP # 2        A;
  297.                 ST   TTOS [] PSP    A;
  298.                 [TARGET]
  299.                 ;
  300.  
  301. : LOAD_TTOS     ( -- )          \ macro to LOAD TTOS, not an optimizer
  302.                 A;
  303.                 [ASM96]
  304.                 LD  TTOS []+ PSP    A;
  305.                 [TARGET]
  306.                 ;
  307.  
  308. >LIBRARY
  309.  
  310.