version 1.120, 2002/03/19 11:13:08
|
version 1.122, 2002/03/20 11:28:26
|
Line 717 Plugin branchtoresolve, ( branch-addr --
|
Line 717 Plugin branchtoresolve, ( branch-addr --
|
Plugin branchtomark, ( -- target-addr ) \ marks a branch destination |
Plugin branchtomark, ( -- target-addr ) \ marks a branch destination |
|
|
Plugin colon, ( tcfa -- ) \ compiles call to tcfa at current position |
Plugin colon, ( tcfa -- ) \ compiles call to tcfa at current position |
Plugin xt, ( tcfa -- ) \ compiles xt |
|
Plugin prim, ( tcfa -- ) \ compiles primitive invocation |
Plugin prim, ( tcfa -- ) \ compiles primitive invocation |
Plugin colonmark, ( -- addr ) \ marks a colon call |
Plugin colonmark, ( -- addr ) \ marks a colon call |
Plugin colon-resolve ( tcfa addr -- ) |
Plugin colon-resolve ( tcfa addr -- ) |
Line 751 Plugin next, ( for-token )
|
Line 750 Plugin next, ( for-token )
|
Plugin leave, ( -- ) |
Plugin leave, ( -- ) |
Plugin ?leave, ( -- ) |
Plugin ?leave, ( -- ) |
|
|
[IFUNDEF] ca>native |
Plugin ca>native \ Convert a code address to the processors |
Plugin ca>native |
\ native address. This is used in doprim, and |
[THEN] |
\ 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 doprim, \ compiles start of a primitive |
Plugin docol, \ compiles start of a colon definition |
Plugin docol, \ compiles start of a colon definition |
Line 904 Variable cross-space-dp-orig
|
Line 908 Variable cross-space-dp-orig
|
THEN ; |
THEN ; |
|
|
Defer is-forward |
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) ( -- ) |
: (ghostheader) ( -- ) |
ghost-list linked <fwd> , 0 , ['] NoExec , what's is-forward , |
ghost-list linked <fwd> , 0 , ['] NoExec , ['] is-forward , |
0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , ; |
0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , ; |
|
|
: ghostheader ( -- ) (ghostheader) 0 , ; |
: ghostheader ( -- ) (ghostheader) 0 , ; |
Line 1092 Ghost lit-perform drop
|
Line 1087 Ghost lit-perform drop
|
Ghost lit+ drop |
Ghost lit+ drop |
Ghost does-exec drop |
Ghost does-exec drop |
|
|
' doer-forward IS is-forward |
|
|
|
Ghost :docol Ghost :doesjump Ghost :dodoes 2drop drop |
Ghost :docol Ghost :doesjump Ghost :dodoes 2drop drop |
Ghost :dovar drop |
Ghost :dovar drop |
|
|
|
|
' prim-forward IS is-forward |
|
|
|
\ \ Parameter for target systems 06oct92py |
\ \ Parameter for target systems 06oct92py |
|
|
|
|
Line 1538 bigendian
|
Line 1528 bigendian
|
2drop 0 ; |
2drop 0 ; |
|
|
: taddr>region-abort ( taddr -- region | 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= |
dup taddr>region dup 0= |
IF drop cr ." Wrong address: " .addr |
IF drop cr ." Wrong address: " .addr |
-1 ABORT" Address out of range!" |
-1 ABORT" Address out of range!" |
Line 1658 T has? relocate H
|
Line 1650 T has? relocate H
|
|
|
>CROSS |
>CROSS |
|
|
: call-forward ( ghost -- ) |
|
\ ." CF" .sourcepos |
|
there 0 colon, 0 do-refered ; |
|
' call-forward IS is-forward |
|
|
|
Ghost (do) Ghost (?do) 2drop |
Ghost (do) Ghost (?do) 2drop |
Ghost (for) drop |
Ghost (for) drop |
Ghost (loop) Ghost (+loop) 2drop |
Ghost (loop) Ghost (+loop) 2drop |
Line 1672 Ghost (.") Ghost (S") Ghost (A
|
Line 1659 Ghost (.") Ghost (S") Ghost (A
|
Ghost (C") drop |
Ghost (C") drop |
Ghost ' drop |
Ghost ' drop |
|
|
\ ' prim-forward IS is-forward |
|
|
|
\ user ghosts |
\ user ghosts |
|
|
Ghost state drop |
Ghost state drop |
Line 1735 previous
|
Line 1720 previous
|
>CROSS |
>CROSS |
|
|
: (cc) T a, H ; ' (cc) plugin-of colon, |
: (cc) T a, H ; ' (cc) plugin-of colon, |
: (xt) T a, H ; ' (xt) plugin-of xt, |
|
: (prim) T a, H ; ' (prim) plugin-of prim, |
: (prim) T a, H ; ' (prim) plugin-of prim, |
|
|
: (cr) >tempdp colon, tempdp> ; ' (cr) plugin-of colon-resolve |
: (cr) >tempdp colon, tempdp> ; ' (cr) plugin-of colon-resolve |
Line 1749 previous
|
Line 1733 previous
|
tempdp> ; ' (dr) plugin-of doer-resolve |
tempdp> ; ' (dr) plugin-of doer-resolve |
|
|
: (cm) ( -- addr ) |
: (cm) ( -- addr ) |
T here align H |
there -1 colon, ; ' (cm) plugin-of colonmark, |
-1 xt, ; ' (cm) plugin-of colonmark, |
|
|
|
>TARGET |
>TARGET |
: compile, ( xt -- ) |
: compile, ( xt -- ) |
Line 1778 previous
|
Line 1761 previous
|
space> |
space> |
; |
; |
|
|
' (refered) IS do-refered |
|
|
|
: refered ( ghost tag -- ) |
: refered ( ghost tag -- ) |
\G creates a resolve structure |
\G creates a resolve structure |
T here aligned H swap (refered) |
T here aligned H swap (refered) |
Line 1837 Defer resolve-warning
|
Line 1818 Defer resolve-warning
|
>link ! ; |
>link ! ; |
|
|
: colon-resolved ( ghost -- ) |
: colon-resolved ( ghost -- ) |
>link @ colon, ; \ compile-call |
\ compiles a call to a colon definition, |
|
\ compile action for >comp field |
|
>link @ colon, ; |
|
|
: prim-resolved ( ghost -- ) |
: prim-resolved ( ghost -- ) |
|
\ compiles a call to a primitive |
>link @ prim, ; |
>link @ prim, ; |
|
|
|
: (is-forward) ( ghost -- ) |
|
colonmark, 0 (refered) ; \ compile space for call |
|
' (is-forward) IS is-forward |
|
|
0 Value resolved |
0 Value resolved |
|
|
: resolve ( ghost tcfa -- ) |
: resolve-forward-references ( ghost resolve-list -- ) |
\G resolve referencies to ghost with tcfa |
\ 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 |
dup taddr>region 0<> IF |
|
\ define this address in the region address type table |
2dup (>regiontype) define-addr-struct addr-xt-ghost |
2dup (>regiontype) define-addr-struct addr-xt-ghost |
|
|
\ we define new address only if empty |
\ we define new address only if empty |
\ this is for not to take over the alias ghost |
\ this is for not to take over the alias ghost |
\ (different ghost, but identical xt) |
\ (different ghost, but identical xt) |
\ but the very first that really defines it |
\ but the very first that really defines it |
dup @ 0= IF ! ELSE 2drop THEN |
dup @ 0= IF ! ELSE 2drop THEN |
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 ! <res> r@ >magic ! |
|
r> swap ; |
|
|
|
: resolve ( ghost tcfa -- ) |
|
\G resolve referencies to ghost with tcfa |
\ is ghost resolved?, second resolve means another |
\ is ghost resolved?, second resolve means another |
\ definition with the same name |
\ definition with the same name |
over undefined? 0= IF exists EXIT THEN |
over undefined? 0= IF exists EXIT THEN |
\ get linked-list |
(resolve) |
swap >r r@ >link @ swap \ ( list tcfa R: ghost ) |
( ghost resolve-list ) |
\ mark ghost as resolved |
resolve-forward-references ; |
dup r@ >link ! <res> r@ >magic ! |
|
r@ to resolved |
: resolve-noforwards ( ghost tcfa -- ) |
r@ >comp @ ['] prim-forward = IF |
\G Same as resolve but complain if there are any |
['] prim-resolved r@ >comp ! THEN |
\G forward references on this ghost |
r@ >comp @ what's is-forward = IF |
\ is ghost resolved?, second resolve means another |
['] prim-resolved r@ >comp ! THEN |
\ definition with the same name |
\ loop through forward referencies |
over undefined? 0= IF exists EXIT THEN |
r> -rot |
(resolve) |
comp-state @ >r Resolving comp-state ! |
IF cr ." No forward references allowed on: " .ghost cr |
resolve-loop |
-1 ABORT" Illegal forward reference" |
r> comp-state ! |
THEN |
|
drop ; |
['] noop IS resolve-warning |
|
; |
|
|
|
\ gexecute ghost, 01nov92py |
\ gexecute ghost, 01nov92py |
|
|
Line 2196 Defer setup-prim-semantics
|
Line 2210 Defer setup-prim-semantics
|
|
|
: mapprim: ( "forthname" "asmlabel" -- ) |
: mapprim: ( "forthname" "asmlabel" -- ) |
-1 aprim-nr +! aprim-nr @ |
-1 aprim-nr +! aprim-nr @ |
Ghost tuck swap resolve <do:> swap tuck >magic ! |
Ghost tuck swap resolve-noforwards <do:> swap tuck >magic ! |
asmprimname, ; |
asmprimname, ; |
|
|
: Doer: ( cfa -- ) \ name |
: Doer: ( cfa -- ) \ name |
Line 2206 Defer setup-prim-semantics
|
Line 2220 Defer setup-prim-semantics
|
.sourcepos ." needs doer: " >in @ bl word count type >in ! cr |
.sourcepos ." needs doer: " >in @ bl word count type >in ! cr |
THEN |
THEN |
Ghost |
Ghost |
tuck swap resolve <do:> swap >magic ! ; |
tuck swap resolve-noforwards <do:> swap >magic ! ; |
|
|
Variable prim# |
Variable prim# |
: first-primitive ( n -- ) prim# ! ; |
: first-primitive ( n -- ) prim# ! ; |
Line 2217 Variable prim#
|
Line 2231 Variable prim#
|
.sourcepos ." needs prim: " >in @ bl word count type >in ! cr |
.sourcepos ." needs prim: " >in @ bl word count type >in ! cr |
THEN |
THEN |
prim# @ (THeader ( S xt ghost ) |
prim# @ (THeader ( S xt ghost ) |
|
['] prim-resolved over >comp ! |
dup >ghost-flags <primitive> set-flag |
dup >ghost-flags <primitive> set-flag |
over resolve T A, H alias-mask flag! |
over resolve-noforwards T A, H alias-mask flag! |
-1 prim# +! ; |
-1 prim# +! ; |
>CROSS |
>CROSS |
|
|
Line 2298 T 2 cells H Value xt>body
|
Line 2313 T 2 cells H Value xt>body
|
|
|
: (docol,) ( -- ) [G'] :docol (doer,) ; ' (docol,) plugin-of docol, |
: (docol,) ( -- ) [G'] :docol (doer,) ; ' (docol,) plugin-of docol, |
|
|
|
' NOOP plugin-of ca>native |
|
|
: (doprim,) ( -- ) |
: (doprim,) ( -- ) |
there xt>body + ca>native T a, H 1 fillcfa ; ' (doprim,) plugin-of doprim, |
there xt>body + ca>native T a, H 1 fillcfa ; ' (doprim,) plugin-of doprim, |
|
|
Line 2336 Defer (end-code)
|
Line 2353 Defer (end-code)
|
>TARGET |
>TARGET |
: Code |
: Code |
defempty? |
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] |
[ T e? prims H 0= [IF] T e? ITC H [ELSE] true [THEN] ] [IF] |
doprim, |
doprim, |
[THEN] |
[THEN] |
depth (code) ; |
depth (code) ; |
|
|
|
\ FIXME : no-compile -1 ABORT" this ghost is not for compilation" ; |
|
|
: Code: |
: Code: |
defempty? |
defempty? |
Ghost dup there ca>native resolve <do:> swap >magic ! |
Ghost >r |
|
r@ there ca>native resolve-noforwards |
|
<do:> r@ >magic ! |
|
r> drop |
depth (code) ; |
depth (code) ; |
|
|
: end-code |
: end-code |
Line 2513 Cond: [ ( -- ) interpreting-state ;Cond
|
Line 2538 Cond: [ ( -- ) interpreting-state ;Cond
|
: !does ( does-action -- ) |
: !does ( does-action -- ) |
tlastcfa @ [G'] :dovar killref |
tlastcfa @ [G'] :dovar killref |
>space here >r ghostheader space> |
>space here >r ghostheader space> |
|
['] colon-resolved r@ >comp ! |
r@ created >do:ghost ! r@ swap resolve |
r@ created >do:ghost ! r@ swap resolve |
r> tlastcfa @ >tempdp dodoes, tempdp> ; |
r> tlastcfa @ >tempdp dodoes, tempdp> ; |
|
|
Line 2796 DO: abort" Not in cross mode" ;DO
|
Line 2822 DO: abort" Not in cross mode" ;DO
|
\ this section defines different compilation |
\ this section defines different compilation |
\ actions for created words |
\ actions for created words |
\ this will help the peephole optimizer |
\ 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 |
\ changes but seperated it from the original |
\ Builder words. The final plan is to put this |
\ Builder words. The final plan is to put this |
\ into a seperate file, together with the peephole |
\ into a seperate file, together with the peephole |
Line 2808 T has? peephole H [IF]
|
Line 2834 T has? peephole H [IF]
|
>CROSS |
>CROSS |
|
|
: (callc) compile call T >body a, H ; ' (callc) plugin-of colon, |
: (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) >tempdp resolved gexecute tempdp> drop ; |
' (call-res) plugin-of colon-resolve |
' (call-res) plugin-of colon-resolve |
: (prim) dup 0< IF $4000 - ELSE |
: (pprim) dup 0< IF $4000 - ELSE |
." wrong usage of (prim) " |
cr ." wrong usage of (prim) " |
dup gdiscover IF .ghost ELSE . THEN cr -2 throw THEN |
dup gdiscover IF .ghost ELSE . THEN cr -1 throw THEN |
T a, H ; ' (prim) plugin-of prim, |
T a, H ; ' (pprim) plugin-of prim, |
|
|
\ if we want this, we have to spilt aconstant |
\ if we want this, we have to spilt aconstant |
\ and constant!! |
\ and constant!! |
Line 3528 previous
|
Line 3555 previous
|
: rot rot ; |
: rot rot ; |
: drop drop ; |
: drop drop ; |
: = = ; |
: = = ; |
|
: <> <> ; |
: 0= 0= ; |
: 0= 0= ; |
: lshift lshift ; |
: lshift lshift ; |
: 2/ 2/ ; |
: 2/ 2/ ; |
Line 3582 previous
|
Line 3610 previous
|
\ : words also ghosts |
\ : words also ghosts |
\ words previous ; |
\ words previous ; |
: .s .s ; |
: .s .s ; |
|
: depth depth ; |
: bye bye ; |
: bye bye ; |
|
|
\ dummy |
\ dummy |