--- gforth/cross.fs 2001/11/11 22:33:31 1.116 +++ gforth/cross.fs 2002/03/19 11:13:08 1.120 @@ -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,6 +717,7 @@ 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 -- ) @@ -898,10 +904,19 @@ Variable cross-space-dp-orig THEN ; Defer is-forward +Defer do-refered + +: prim-forward ( ghost -- ) +\ ." PF" .sourcepos + colonmark, 0 do-refered ; \ compile space for call +: doer-forward ( ghost -- ) +\ ." DF" .sourcepos + colonmark, 2 do-refered ; \ compile space for doer +' prim-forward IS is-forward : (ghostheader) ( -- ) - ghost-list linked , 0 , ['] NoExec , ['] is-forward , - 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , ; + ghost-list linked , 0 , ['] NoExec , what's is-forward , + 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , ; : ghostheader ( -- ) (ghostheader) 0 , ; @@ -1051,40 +1066,43 @@ End-Struct addr-struct dup @ ?dup IF nip EXIT THEN addr-struct %allocerase tuck swap ! ; +>cross + \ Predefined ghosts 12dec92py Ghost - drop \ need a ghost otherwise "-" would be treated as a number Ghost 0= drop Ghost branch Ghost ?branch 2drop -Ghost (do) Ghost (?do) 2drop -Ghost (for) drop -Ghost (loop) Ghost (+loop) 2drop -Ghost (next) drop Ghost unloop Ghost ;S 2drop -Ghost lit Ghost (compile) Ghost ! 2drop drop -Ghost (does>) Ghost noop 2drop -Ghost (.") Ghost (S") Ghost (ABORT") 2drop drop -Ghost ' drop -Ghost :docol Ghost :doesjump Ghost :dodoes 2drop drop -Ghost :dovar drop +Ghost lit Ghost ! 2drop +Ghost noop drop Ghost over Ghost = Ghost drop 2drop drop Ghost 2drop drop Ghost 2dup drop -Ghost state drop Ghost call drop Ghost @ drop Ghost useraddr drop Ghost execute drop Ghost + drop -Ghost (C") drop Ghost decimal drop Ghost hex drop +Ghost lit@ drop +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 ->cross \ we define it ans like... wordlist Constant target-environment @@ -1636,6 +1654,29 @@ T has? relocate H : A! swap >address swap dup relon T ! H ; : A, ( w -- ) >address T here H relon T , H ; +\ high-level ghosts + +>CROSS + +: call-forward ( ghost -- ) +\ ." CF" .sourcepos + there 0 colon, 0 do-refered ; +' call-forward IS is-forward + +Ghost (do) Ghost (?do) 2drop +Ghost (for) drop +Ghost (loop) Ghost (+loop) 2drop +Ghost (next) drop +Ghost (does>) Ghost (compile) 2drop +Ghost (.") Ghost (S") Ghost (ABORT") 2drop drop +Ghost (C") drop +Ghost ' drop + +\ ' prim-forward IS is-forward + +\ user ghosts + +Ghost state drop \ \ -------------------- Host/Target copy etc. 29aug01jaw @@ -1694,9 +1735,10 @@ 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 ]comp prim, comp[ tempdp> ; ' (cr) plugin-of colon-resolve +: (cr) >tempdp colon, tempdp> ; ' (cr) plugin-of colon-resolve : (ar) T ! H ; ' (ar) plugin-of addr-resolve : (dr) ( ghost res-pnt target-addr addr ) >tempdp drop over @@ -1708,7 +1750,7 @@ previous : (cm) ( -- addr ) T here align H - -1 prim, ; ' (cm) plugin-of colonmark, + -1 xt, ; ' (cm) plugin-of colonmark, >TARGET : compile, ( xt -- ) @@ -1734,7 +1776,9 @@ previous loadfile , sourceline# , space> - ; +; + +' (refered) IS do-refered : refered ( ghost tag -- ) \G creates a resolve structure @@ -1798,13 +1842,7 @@ Defer resolve-warning : prim-resolved ( ghost -- ) >link @ prim, ; -\ FIXME: not used currently -: does-resolved ( ghost -- ) - dup g>body alit, >do:ghost @ g>body colon, ; - -: (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 @@ -1825,7 +1863,10 @@ Defer resolve-warning swap >r r@ >link @ swap \ ( list tcfa R: ghost ) \ mark ghost as resolved dup r@ >link ! r@ >magic ! - r@ >comp @ ['] is-forward = IF + 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 @@ -1842,7 +1883,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 -- ) @@ -2122,6 +2163,7 @@ Variable aprim-nr -20 aprim-nr ! : copy-execution-semantics ( ghost-from ghost-dest -- ) >r dup >exec @ r@ >exec ! + dup >comp @ r@ >comp ! dup >exec2 @ r@ >exec2 ! dup >exec-compile @ r@ >exec-compile ! dup >ghost-xt @ r@ >ghost-xt ! @@ -2157,19 +2199,20 @@ Defer setup-prim-semantics Ghost tuck swap resolve swap tuck >magic ! asmprimname, ; -: Alias: ( cfa -- ) \ name +: Doer: ( cfa -- ) \ name >in @ skip? IF 2drop EXIT THEN >in ! dup 0< s" prims" T $has? H 0= and IF .sourcepos ." needs doer: " >in @ bl word count type >in ! cr THEN - Ghost tuck swap resolve swap >magic ! ; + Ghost + tuck swap resolve swap >magic ! ; Variable prim# : first-primitive ( n -- ) prim# ! ; : Primitive ( -- ) \ name - >in @ skip? IF 2drop EXIT THEN >in ! - dup 0< s" prims" T $has? H 0= and + >in @ skip? IF drop EXIT THEN >in ! + s" prims" T $has? H 0= IF .sourcepos ." needs prim: " >in @ bl word count type >in ! cr THEN @@ -2259,10 +2302,10 @@ T 2 cells H Value xt>body there xt>body + ca>native T a, H 1 fillcfa ; ' (doprim,) plugin-of doprim, : (doeshandler,) ( -- ) - T cfalign H compile :doesjump T 0 , H ; ' (doeshandler,) plugin-of doeshandler, + T cfalign H [G'] :doesjump addr, T 0 , H ; ' (doeshandler,) plugin-of doeshandler, : (dodoes,) ( does-action-ghost -- ) - ]comp [G'] :dodoes gexecute comp[ + ]comp [G'] :dodoes addr, comp[ addr, \ the relocator in the c engine, does not like the \ does-address to marked for relocation @@ -2455,8 +2498,8 @@ Cond: ; ( -- ) fini, comp[ ;Resolve @ - IF ;Resolve @ ;Resolve cell+ @ resolve - ['] colon-resolved ;Resolve @ >comp ! + IF ['] colon-resolved ;Resolve @ >comp ! + ;Resolve @ ;Resolve cell+ @ resolve THEN interpreting-state ;Cond @@ -2465,26 +2508,23 @@ Cond: [ ( -- ) interpreting-state ;Cond >CROSS -Create GhostDummy ghostheader - GhostDummy >magic ! +0 Value created : !does ( does-action -- ) -\ !! zusammenziehen und dodoes, machen! tlastcfa @ [G'] :dovar killref -\ tlastcfa @ dup there >r tdp ! compile :dodoes r> tdp ! T cell+ ! H ; -\ !! geht so nicht, da dodoes, ghost will! - GhostDummy >link ! GhostDummy - tlastcfa @ >tempdp dodoes, tempdp> ; - + >space here >r ghostheader space> + r@ created >do:ghost ! r@ swap resolve + r> tlastcfa @ >tempdp dodoes, tempdp> ; Defer instant-interpret-does>-hook +: does-resolved ( ghost -- ) + compile does-exec g>xt T a, H ; + : resolve-does>-part ( -- ) \ resolve words made by builders Last-Header-Ghost @ >do:ghost @ ?dup - IF there resolve - \ TODO: set special DOES> resolver action here - THEN ; + IF there resolve THEN ; >TARGET Cond: DOES> @@ -2492,9 +2532,11 @@ Cond: DOES> resolve-does>-part ;Cond -: DOES> switchrom doeshandler, T here H !does - instant-interpret-does>-hook - depth T ] H ; +: DOES> + ['] does-resolved created >comp ! + switchrom doeshandler, T here H !does + instant-interpret-does>-hook + depth T ] H ; >CROSS \ Creation 01nov92py @@ -2512,7 +2554,6 @@ Cond: DOES> ghost to built built >created @ 0= IF built >created on - ['] prim-resolved built >comp ! THEN ; : gdoes, ( ghost -- ) @@ -2532,8 +2573,8 @@ Cond: DOES> ; : takeover-x-semantics ( S constructor-ghost new-ghost -- ) -\g stores execution semantic and compilation semantic in the built word - swap >do:ghost @ + \g stores execution semantic and compilation semantic in the built word + swap >do:ghost @ 2dup swap >do:ghost ! \ we use the >exec2 field for the semantic of a created word, \ using exec or exec2 makes no difference for normal cross-compilation \ but is usefull for instant where the exec field is already @@ -2541,12 +2582,20 @@ Cond: DOES> 2dup >exec @ swap >exec2 ! >comp @ swap >comp ! ; +0 Value createhere + +: create-resolve ( -- ) + created createhere resolve 0 ;Resolve ! ; +: create-resolve-immediate ( -- ) + create-resolve T immediate H ; + : TCreate ( -- ) create-forward-warn IF ['] reswarn-forward IS resolve-warning THEN executed-ghost @ (Theader - dup >created on - 2dup takeover-x-semantics hereresolve gdoes, ; + dup >created on dup to created + 2dup takeover-x-semantics + there to createhere drop gdoes, ; : RTCreate ( -- ) \ creates a new word with code-field in ram @@ -2554,14 +2603,14 @@ Cond: DOES> IF ['] reswarn-forward IS resolve-warning THEN \ make Alias executed-ghost @ (THeader - dup >created on + dup >created on dup to created 2dup takeover-x-semantics there 0 T a, H alias-mask flag! \ store poiter to code-field switchram T cfalign H there swap T ! H there tlastcfa ! - hereresolve gdoes, ; + there to createhere drop gdoes, ; : Build: ( -- [xt] [colon-sys] ) :noname postpone TCreate ; @@ -2575,7 +2624,11 @@ Cond: DOES> [ [THEN] ] ; : ;Build - postpone ; built >exec ! ; immediate + postpone create-resolve postpone ; built >exec ! ; immediate + +: ;Build-immediate + postpone create-resolve-immediate + postpone ; built >exec ! ; immediate : gdoes> ( ghost -- addr flag ) executed-ghost @ g>body ; @@ -2700,7 +2753,7 @@ BuildSmart: ( -- ) [T'] noop T A, H ;Bu by: :dodefer ( ghost -- ) X @ texecute ;DO Builder interpret/compile: -Build: ( inter comp -- ) swap T immediate A, A, H ;Build +Build: ( inter comp -- ) swap T A, A, H ;Build-immediate DO: ( ghost -- ) ABORT" CROSS: Don't execute" ;DO \ Sturctures 23feb95py @@ -2753,7 +2806,14 @@ DO: abort" Not in cross mode" ;DO T has? peephole H [IF] >CROSS + : (callc) compile call T >body a, H ; ' (callc) plugin-of colon, +: (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, \ if we want this, we have to spilt aconstant \ and constant!! @@ -2761,23 +2821,32 @@ T has? peephole H [IF] \ compile: g>body X @ lit, ;compile Builder (Constant) -compile: g>body alit, compile @ ;compile +compile: g>body compile lit@ T a, H ;compile Builder (Value) -compile: g>body alit, compile @ ;compile +compile: g>body compile lit@ T a, H ;compile \ this changes also Variable, AVariable and 2Variable Builder Create -\ compile: g>body alit, ;compile +compile: g>body alit, ;compile Builder User compile: g>body compile useraddr T @ , H ;compile Builder Defer -compile: g>body alit, compile @ compile execute ;compile +compile: g>body compile lit-perform T A, H ;compile Builder (Field) -compile: g>body T @ H lit, compile + ;compile +compile: g>body T @ H compile lit+ T , H ;compile + +Builder interpret/compile: +compile: does-resolved ;compile + +Builder input-method +compile: does-resolved ;compile + +Builder input-var +compile: does-resolved ;compile [THEN]