--- gforth/cross.fs 2002/01/05 22:58:59 1.119 +++ gforth/cross.fs 2002/03/20 11:28:26 1.122 @@ -249,21 +249,26 @@ hex \ the defualt base for the cross hex +\ FIXME delete` \ 1 Constant Cross-Flag \ to check whether assembler compiler plug-ins are \ for cross-compiling \ No! we use "[IFUNDEF]" there to find out whether we are target compiling!!! +\ FIXME move down : comment? ( c-addr u -- c-addr u ) 2dup s" (" compare 0= IF postpone ( ELSE 2dup s" \" compare 0= IF postpone \ THEN THEN ; -: X bl word count [ ' target >wordlist ] Literal search-wordlist - IF state @ IF compile, - ELSE execute THEN - ELSE -1 ABORT" Cross: access method not supported!" - THEN ; immediate +: X ( -- ) +\G The next word in the input is a target word. +\G Equivalent to T but without permanent +\G switch to target dictionary. Used as prefix e.g. for @, !, here etc. + bl word count [ ' target >wordlist ] Literal search-wordlist + IF state @ IF compile, ELSE execute THEN + ELSE -1 ABORT" Cross: access method not supported!" + THEN ; immediate \ Begin CROSS COMPILER: @@ -712,7 +717,6 @@ Plugin branchtoresolve, ( branch-addr -- Plugin branchtomark, ( -- target-addr ) \ marks a branch destination Plugin colon, ( tcfa -- ) \ compiles call to tcfa at current position -Plugin xt, ( tcfa -- ) \ compiles xt Plugin prim, ( tcfa -- ) \ compiles primitive invocation Plugin colonmark, ( -- addr ) \ marks a colon call Plugin colon-resolve ( tcfa addr -- ) @@ -746,9 +750,14 @@ Plugin next, ( for-token ) Plugin leave, ( -- ) Plugin ?leave, ( -- ) -[IFUNDEF] ca>native -Plugin ca>native -[THEN] +Plugin ca>native \ Convert a code address to the processors + \ native address. This is used in doprim, and + \ code/code: primitive definitions word to + \ convert the addresses. + \ The only target where we need this is the misc + \ which is a 16 Bit processor with word addresses + \ but the forth system we build has a normal byte + \ addressed memory model Plugin doprim, \ compiles start of a primitive Plugin docol, \ compiles start of a colon definition @@ -899,16 +908,9 @@ Variable cross-space-dp-orig THEN ; Defer is-forward -Defer do-refered - -: prim-forward ( ghost -- ) - colonmark, 0 do-refered ; \ compile space for call -: doer-forward ( ghost -- ) - colonmark, 2 do-refered ; \ compile space for doer -' prim-forward IS is-forward : (ghostheader) ( -- ) - ghost-list linked , 0 , ['] NoExec , what's is-forward , + ghost-list linked , 0 , ['] NoExec , ['] is-forward , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , ; : ghostheader ( -- ) (ghostheader) 0 , ; @@ -1085,13 +1087,9 @@ Ghost lit-perform drop Ghost lit+ drop Ghost does-exec drop -' doer-forward IS is-forward - Ghost :docol Ghost :doesjump Ghost :dodoes 2drop drop Ghost :dovar drop -' prim-forward IS is-forward - \ \ Parameter for target systems 06oct92py @@ -1530,6 +1528,8 @@ bigendian 2drop 0 ; : taddr>region-abort ( taddr -- region | 0 ) +\G Same as taddr>region but aborts if taddr is not +\G a valid address in the target address space dup taddr>region dup 0= IF drop cr ." Wrong address: " .addr -1 ABORT" Address out of range!" @@ -1650,10 +1650,6 @@ T has? relocate H >CROSS -: call-forward ( ghost -- ) - there 0 colon, 0 do-refered ; -' call-forward IS is-forward - Ghost (do) Ghost (?do) 2drop Ghost (for) drop Ghost (loop) Ghost (+loop) 2drop @@ -1663,8 +1659,6 @@ Ghost (.") Ghost (S") Ghost (A Ghost (C") drop Ghost ' drop -\ ' prim-forward IS is-forward - \ user ghosts Ghost state drop @@ -1726,7 +1720,6 @@ previous >CROSS : (cc) T a, H ; ' (cc) plugin-of colon, -: (xt) T a, H ; ' (xt) plugin-of xt, : (prim) T a, H ; ' (prim) plugin-of prim, : (cr) >tempdp colon, tempdp> ; ' (cr) plugin-of colon-resolve @@ -1740,8 +1733,7 @@ previous tempdp> ; ' (dr) plugin-of doer-resolve : (cm) ( -- addr ) - T here align H - -1 xt, ; ' (cm) plugin-of colonmark, + there -1 colon, ; ' (cm) plugin-of colonmark, >TARGET : compile, ( xt -- ) @@ -1769,8 +1761,6 @@ previous space> ; -' (refered) IS do-refered - : refered ( ghost tag -- ) \G creates a resolve structure T here aligned H swap (refered) @@ -1828,45 +1818,78 @@ Defer resolve-warning >link ! ; : colon-resolved ( ghost -- ) - >link @ colon, ; \ compile-call +\ compiles a call to a colon definition, +\ compile action for >comp field + >link @ colon, ; : prim-resolved ( ghost -- ) +\ compiles a call to a primitive >link @ prim, ; +: (is-forward) ( ghost -- ) + colonmark, 0 (refered) ; \ compile space for call +' (is-forward) IS is-forward + 0 Value resolved -: resolve ( ghost tcfa -- ) -\G resolve referencies to ghost with tcfa +: resolve-forward-references ( ghost resolve-list -- ) + \ loop through forward referencies + comp-state @ >r Resolving comp-state ! + over >link @ resolve-loop + r> comp-state ! + + ['] noop IS resolve-warning ; + + +: (resolve) ( ghost tcfa -- ghost resolve-list ) + \ check for a valid address, it is a primitive reference + \ otherwise dup taddr>region 0<> IF + \ define this address in the region address type table 2dup (>regiontype) define-addr-struct addr-xt-ghost - \ we define new address only if empty \ this is for not to take over the alias ghost \ (different ghost, but identical xt) \ but the very first that really defines it dup @ 0= IF ! ELSE 2drop THEN THEN + swap >r + r@ to resolved + +\ r@ >comp @ ['] is-forward = +\ ABORT" >comp action not set on a resolved ghost" + + \ copmile action defaults to colon-resolved + \ if this is not right something must be set before + \ calling resolve + r@ >comp @ ['] is-forward = IF + ['] colon-resolved r@ >comp ! + THEN + r@ >link @ swap \ ( list tcfa R: ghost ) + \ mark ghost as resolved + r@ >link ! r@ >magic ! + r> swap ; +: resolve ( ghost tcfa -- ) +\G resolve referencies to ghost with tcfa \ is ghost resolved?, second resolve means another \ definition with the same name over undefined? 0= IF exists EXIT THEN - \ get linked-list - swap >r r@ >link @ swap \ ( list tcfa R: ghost ) - \ mark ghost as resolved - dup r@ >link ! r@ >magic ! - r@ to resolved - r@ >comp @ ['] prim-forward = IF - ['] prim-resolved r@ >comp ! THEN - r@ >comp @ what's is-forward = IF - ['] prim-resolved r@ >comp ! THEN - \ loop through forward referencies - r> -rot - comp-state @ >r Resolving comp-state ! - resolve-loop - r> comp-state ! - - ['] noop IS resolve-warning - ; + (resolve) + ( ghost resolve-list ) + resolve-forward-references ; + +: resolve-noforwards ( ghost tcfa -- ) +\G Same as resolve but complain if there are any +\G forward references on this ghost + \ is ghost resolved?, second resolve means another + \ definition with the same name + over undefined? 0= IF exists EXIT THEN + (resolve) + IF cr ." No forward references allowed on: " .ghost cr + -1 ABORT" Illegal forward reference" + THEN + drop ; \ gexecute ghost, 01nov92py @@ -1874,7 +1897,7 @@ Defer resolve-warning dup >comp @ EXECUTE ; : gexecute ( ghost -- ) - dup >magic @ = IF -1 ABORT" CROSS: gexecute on immediate word" THEN + dup >magic @ = ABORT" CROSS: gexecute on immediate word" (gexecute) ; : addr, ( ghost -- ) @@ -2187,7 +2210,7 @@ Defer setup-prim-semantics : mapprim: ( "forthname" "asmlabel" -- ) -1 aprim-nr +! aprim-nr @ - Ghost tuck swap resolve swap tuck >magic ! + Ghost tuck swap resolve-noforwards swap tuck >magic ! asmprimname, ; : Doer: ( cfa -- ) \ name @@ -2197,7 +2220,7 @@ Defer setup-prim-semantics .sourcepos ." needs doer: " >in @ bl word count type >in ! cr THEN Ghost - tuck swap resolve swap >magic ! ; + tuck swap resolve-noforwards swap >magic ! ; Variable prim# : first-primitive ( n -- ) prim# ! ; @@ -2208,8 +2231,9 @@ Variable prim# .sourcepos ." needs prim: " >in @ bl word count type >in ! cr THEN prim# @ (THeader ( S xt ghost ) + ['] prim-resolved over >comp ! dup >ghost-flags set-flag - over resolve T A, H alias-mask flag! + over resolve-noforwards T A, H alias-mask flag! -1 prim# +! ; >CROSS @@ -2289,6 +2313,8 @@ T 2 cells H Value xt>body : (docol,) ( -- ) [G'] :docol (doer,) ; ' (docol,) plugin-of docol, + ' NOOP plugin-of ca>native + : (doprim,) ( -- ) there xt>body + ca>native T a, H 1 fillcfa ; ' (doprim,) plugin-of doprim, @@ -2327,15 +2353,23 @@ Defer (end-code) >TARGET : Code defempty? - (THeader there resolve + (THeader ( ghost ) + ['] prim-resolved over >comp ! + there resolve-noforwards + [ T e? prims H 0= [IF] T e? ITC H [ELSE] true [THEN] ] [IF] doprim, [THEN] depth (code) ; +\ FIXME : no-compile -1 ABORT" this ghost is not for compilation" ; + : Code: defempty? - Ghost dup there ca>native resolve swap >magic ! + Ghost >r + r@ there ca>native resolve-noforwards + r@ >magic ! + r> drop depth (code) ; : end-code @@ -2504,6 +2538,7 @@ Cond: [ ( -- ) interpreting-state ;Cond : !does ( does-action -- ) tlastcfa @ [G'] :dovar killref >space here >r ghostheader space> + ['] colon-resolved r@ >comp ! r@ created >do:ghost ! r@ swap resolve r> tlastcfa @ >tempdp dodoes, tempdp> ; @@ -2787,7 +2822,7 @@ DO: abort" Not in cross mode" ;DO \ this section defines different compilation \ actions for created words \ this will help the peephole optimizer -\ I (jaw) took this from bernds lates cross-compiler +\ I (jaw) took this from bernds latest cross-compiler \ changes but seperated it from the original \ Builder words. The final plan is to put this \ into a seperate file, together with the peephole @@ -2799,12 +2834,13 @@ T has? peephole H [IF] >CROSS : (callc) compile call T >body a, H ; ' (callc) plugin-of colon, +: (callcm) T here 0 a, 0 a, H ; ' (callcm) plugin-of colonmark, : (call-res) >tempdp resolved gexecute tempdp> drop ; ' (call-res) plugin-of colon-resolve -: (prim) dup 0< IF $4000 - ELSE - ." wrong usage of (prim) " - dup gdiscover IF .ghost ELSE . THEN cr -2 throw THEN - T a, H ; ' (prim) plugin-of prim, +: (pprim) dup 0< IF $4000 - ELSE + cr ." wrong usage of (prim) " + dup gdiscover IF .ghost ELSE . THEN cr -1 throw THEN + T a, H ; ' (pprim) plugin-of prim, \ if we want this, we have to spilt aconstant \ and constant!! @@ -3519,6 +3555,7 @@ previous : rot rot ; : drop drop ; : = = ; +: <> <> ; : 0= 0= ; : lshift lshift ; : 2/ 2/ ; @@ -3573,6 +3610,7 @@ previous \ : words also ghosts \ words previous ; : .s .s ; +: depth depth ; : bye bye ; \ dummy