home *** CD-ROM | disk | FTP | other *** search
- \ OPTIMIZ.SEQ Library Optimizers for Target Compiler
-
- ONLY FORTH ALSO COMPILER ALSO DEFINITIONS TARGET ALSO
-
- >FORTH
-
- : TVER ." \2 80196 Version 1.01 \2" ;
- ' TVER IS TVERSION \ install startup message
-
- ' NOOP IS DATA-SEG-FIX \ not a segmented machine
-
- WARNING OFF \ NO REDEFINITION WARNING IN LIBRARY
- FORTH \ we want a Forth NOT a target variable
- VARIABLE IMM-HERE \ Most recent place where immediate move
- \ to BX was compiled
-
- \ ***************************************************************************
- \ New function for END-CODE, needs to not use REVEAL
-
- ASM96 also forth also
-
- : CEND-CODE ( -- )
- ll-global? 0=
- if ll-errs? \ check for local label errors
- then
- ARUNSAVE IS RUN
- PREVIOUS A; ;
-
- previous previous target
-
- : %END-MACRO ( -- ) \ complete assembly of a MACRO
- ?reopt
- [ASM96]
- compile a; \ make sure ASM96 is done
- compile cend-code \ pop ASM96 vocabulary
- [compile] FOR; ; \ complete colon def
-
- ' %END-MACRO IS END-MACRO \ install in END-MACRO
-
- : %END-LCODE ( -- ) \ complete assembly of a LCODE
- ?reopt
- [ASM96]
- compile a; \ make sure ASM96 is done
- compile cend-code \ pop ASM96 vocabulary
- compile do_resolve \ resolve forward references
- [compile] FOR; ; \ complete colon def
-
- ' %END-LCODE IS END-LCODE \ install in END-LCODE
-
- : %END-L: ( -- ) \ complete a library CALL definition
- [ASM96]
- compile setassem
- compile ret
- compile a; \ make sure ASM96 is done
- compile cend-code \ pop ASM96 vocabulary
- compile unnest ;
-
- ' %END-L: IS END-L:
-
- : %END-LM: ( -- ) \ complete a library MACRO : definition
- [ASM96]
- compile setassem
- compile cend-code
- compile unnest ;
-
- ' %END-LM: IS END-LM:
-
- ' NOOP IS START-T:
-
- : %END-T: ( -- ) \ complete a target CALL definition
- \ [ASM96]
- \ setassem \ do ASM96 setup
- %on> callbyte
- $0F0 C,-T \ compile RET
- \ ret a; \ terminate with a RET instruction
- %off> callbyte
- ;
- \ fend-code ; \ do ASM96 finishup
-
- ' %END-T: IS END-T:
-
- : %COMP_CALL ( a1 -- ) \ compile a target CALL
- \ a1 = CFA of symbol
- %on> callbyte
- $0EF C,-T \ compile CALL
- %off> callbyte
- dup >resaddr @ dup -1 <> \ if resolved already
- if here-t 2+ - ,-T \ resolve this call
- >count incr \ bump use count
- \ ELSE, add it to the chain of
- else drop \ discard the "-1"
- \ references to be resolved.
- dup >chain @ ,-T \ link chain @ to here
- here-t 2- over >chain ! \ link here into chain
- >res \ add to resolution stack
- then
- ;
-
- ' %COMP_CALL IS COMP_CALL
-
- : %COMP_JMP_IMM ( a1 -- ) \ a1 = actual address
- %on> firstcodebyte
- 233 C,-T
- %off> firstcodebyte
- %on> othercodebyte
- HERE-T 2+ - ,-T
- %off> othercodebyte
- ;
-
- ' %COMP_JMP_IMM IS COMP_JMP_IMM
-
- : %SUB_RET ( -- )
- -1 ALLOT-T ;
-
-
- ' SUB_RET IS SUB_RET
-
- : %TCODE-START ( -- )
- setassem
- [assembler]
- llab-init ;
-
- ' %TCODE-START IS TCODE-START
-
- : %LCODE-START ( -- )
- compile tcode-start \ initialize the ASM96
- ASM96 ; \ and select ASM96 vocabulary now!
-
- ' %LCODE-START IS LCODE-START
-
- : %MACRO-START ( -- )
- compile setassem \ initialize the ASM96
- ASM96 ; \ and select ASM96 vocabulary now!
-
- ' %MACRO-START IS MACRO-START
-
- ASM96 ALSO \ words for defining ram space
- : DCB tlabel 0 C, [compile] end-code ;
- : DCW tlabel 0 , [compile] end-code ;
- : DCL tlabel 0 , 0 , [compile] end-code ;
-
-
- \ ***************************************************************************
- \ Start of the set of functions supported in the target compiler.
- \ These are mostely macros which will compile in-line assembly code.
- \ Colon definitions are compiled as routines when defined, and are
- \ accessed by a CALL when referenced.
-
- ONLY FORTH ALSO COMPILER ALSO HTARGET ALSO TARGET ALSO DEFINITIONS
- ASM96 ALSO
-
- >LIBRARY \ Select the Library versions of
- \ defining words.
-
- \ ***************************************************************************
- \ DONOT CHANGE the first three instructions of SYSINIT. The ADD instruction
- \ must be HOT patched by the image save routine so DS will be set properly
- \ when the image loads in. The $E4F6 value is verified by the patch routine
- \ to make sure the code has not changed. It is then replaced with the proper
- \ value to add to AX so DS will be correct.
-
- VARIABLE DP \ DP is really a variable that always exists,
- \ and is always at address DATA-START.
- DP [FORTH] DROP [TARGET] \ allocate it NOW to assure it's at
- \ the beginning.
- hex
- 1A constant psp
- 1C constant w0
- 1D constant w1
- 1E constant w2
- 1F constant w3
- 20 constant ttos
- 21 constant ttosh
- ' ttosh alias ttos1
- 22 constant ttos2
- 23 constant ttos3
-
- 24 Dseg registers
- decimal
-
- comment:
- hex \ kernel registers
- 1A constant ROW_COUNTER
- 1C constant DPOINT \ pointers and counters
- 20 constant DCOUNT \ for display block move
-
- 22 constant SP_FLAGS \ serial port status image
-
- 2E constant psp
- 30 constant w0
- 31 constant w1
- 32 constant w2
- 33 constant w3
- 34 constant ttos
- ttos 1+ constant ttosh
- \ application registers
- 36 constant tlcdx
- 38 constant tlcdy
- 3A constant tcolor
-
- decimal
- comment;
-
- MACRO IMAGE-INIT ( -- ) \ Target compiler runtime initialization
- [ASM96]
-
- END-MACRO
-
- FORTH DEFINITIONS >FORTH
-
-
- : TARGET-INIT ( -- ) \ initialize the terget compiler
- ?LIB ABORT" Cant use TARGET-INIT in a library routine"
- ONLY FORTH ALSO COMPILER ALSO
- TARGET ALSO DEFINITIONS ASM96 ALSO
- tseg_init \ Initialize the target compile buffer
- >target \ select target defining words
- target \ Select the target vocabulary
- ; IMMEDIATE
-
- ' TARGET-INIT IS TARGET-INITIALIZE
-
- ASM96 DEFINITIONS FORTH >LIBRARY
-
- \ ***************************************************************************
- \ OPTIMIZERS !!
- \ ***************************************************************************
- \ Optimizer for the ! (store) MACRO. Looks for the following instruction
- \ sequence:
- \ DEC SI
- \ DEC SI
- \ MOV 0 [SI], BX
- \ MOV BX, # xxxx
- \ LODSW
- \ MOV 0 [BX], AX
- \
- \ When these instructions are found preceeding a store instruction, they
- \ are changed to:
- \ MOV AX, BX
- \ MOV xxxx ax
- \
- \ This provides a substantial savings in both space and time.
-
- FORTH >FORTH
-
-
-
- \ ***************************************************************************
- \ A second optimizer for the ! (store) MACRO. Looks for the following
- \ instruction sequence:
- \
- \ DEC SI 3 cycles
- \ DEC SI 3 cycles
- \ MOV 0 [SI], BX \ save BX 14 cycles
- \ MOV BX, # xxxx \ LIT xxxx 4 cycles
- \ MOV yyyy BX \ memory yyyy store 9 cycles
- \ LODSW \ load BX 12 cycles
- \ MOV BX, AX 2 cycles
- \
- \ When these instructions are found preceeding a store instruction, they
- \ are changed to:
- \
- \ MOV yyyy # xxxx WORD 10 cycles
- \
- \ This provides a savings of 8 bytes and 37 cycles per occurance.
-
-
- >LIBRARY
-
- \ ***************************************************************************
- \ Optimizer for the @ (fetch) MACRO. Looks for this instruction sequence
- \ to preceed it:
- \ MOV BX, # xxxx
- \
- \ When these instructions are found preceeding a store instruction, they
- \ are changed to:
- \ MOV bx, xxxx
- \
- \ This provides a savings in both space and time.
-
- FORTH >FORTH
-
-
- >LIBRARY
-
- \ ***************************************************************************
- \ MACRO to move TTOS to the stack and vice versa
- \ ***************************************************************************
-
- FORTH >FORTH
-
-
- : SAVE_TTOS ( -- ) \ macro to SAVE TTOS, not an optimizer
- A;
- [ASM96]
- SUB PSP # 2 A;
- ST TTOS [] PSP A;
- [TARGET]
- ;
-
- : LOAD_TTOS ( -- ) \ macro to LOAD TTOS, not an optimizer
- A;
- [ASM96]
- LD TTOS []+ PSP A;
- [TARGET]
- ;
-
- >LIBRARY
-
-