version 1.145, 2003/10/09 20:25:59
|
version 1.168, 2007/12/31 17:34:58
|
Line 1
|
Line 1
|
\ converts primitives to, e.g., C code |
\ converts primitives to, e.g., C code |
|
|
\ Copyright (C) 1995,1996,1997,1998,2000,2003 Free Software Foundation, Inc. |
\ Copyright (C) 1995,1996,1997,1998,2000,2003,2004,2005,2006,2007 Free Software Foundation, Inc. |
|
|
\ This file is part of Gforth. |
\ This file is part of Gforth. |
|
|
Line 51
|
Line 51
|
\ (stack-in-index-xt and a test for stack==instruction-stream); there |
\ (stack-in-index-xt and a test for stack==instruction-stream); there |
\ should be only one. |
\ should be only one. |
|
|
|
|
\ for backwards compatibility, jaw |
\ for backwards compatibility, jaw |
require compat/strcomp.fs |
require compat/strcomp.fs |
|
|
|
[undefined] outfile-execute [if] |
|
: outfile-execute ( ... xt file-id -- ... ) |
|
\ unsafe replacement |
|
outfile-id >r to outfile-id execute r> to outfile-id ; |
|
[then] |
|
|
warnings off |
warnings off |
|
|
\ redefinitions of kernel words not present in gforth-0.6.1 |
\ redefinitions of kernel words not present in gforth-0.6.1 |
Line 102 variable include-skipped-insts
|
Line 109 variable include-skipped-insts
|
\ inline arguments (false) |
\ inline arguments (false) |
include-skipped-insts off |
include-skipped-insts off |
|
|
|
2variable threaded-code-pointer-type \ type used for geninst etc. |
|
s" Inst **" threaded-code-pointer-type 2! |
|
|
variable immarg \ values for immediate arguments (to be used in IMM_ARG macros) |
variable immarg \ values for immediate arguments (to be used in IMM_ARG macros) |
$12340000 immarg ! |
$12340000 immarg ! |
|
|
Line 134 $12340000 immarg !
|
Line 144 $12340000 immarg !
|
over - type cr |
over - type cr |
line-start @ rawinput @ over - typewhite ." ^" cr ; |
line-start @ rawinput @ over - typewhite ." ^" cr ; |
|
|
|
: print-error { addr u -- } |
|
filename 2@ type ." :" line @ 0 .r ." : " addr u type cr |
|
print-error-line ; |
|
|
: ?print-error { f addr u -- } |
: ?print-error { f addr u -- } |
f ?not? if |
f ?not? if |
outfile-id >r try |
addr u ['] print-error stderr outfile-execute |
stderr to outfile-id |
|
filename 2@ type ." :" line @ 0 .r ." : " addr u type cr |
|
print-error-line |
|
0 |
|
recover endtry |
|
r> to outfile-id throw |
|
1 (bye) \ abort |
1 (bye) \ abort |
endif ; |
endif ; |
|
|
Line 201 struct%
|
Line 209 struct%
|
end-struct ss% \ stack-state |
end-struct ss% \ stack-state |
|
|
struct% |
struct% |
|
cell% field state-enabled |
cell% field state-number |
cell% field state-number |
cell% max-stacks * field state-sss |
cell% max-stacks * field state-sss |
end-struct state% |
end-struct state% |
Line 231 variable next-state-number 0 next-state-
|
Line 240 variable next-state-number 0 next-state-
|
rdrop ; |
rdrop ; |
|
|
: map-stacks { xt -- } |
: map-stacks { xt -- } |
\ perform xt for all stacks |
\ perform xt ( stack -- ) for all stacks |
next-stack-number @ 0 +do |
next-stack-number @ 0 +do |
stacks i th @ xt execute |
stacks i th @ xt execute |
loop ; |
loop ; |
|
|
: map-stacks1 { xt -- } |
: map-stacks1 { xt -- } |
\ perform xt for all stacks except inst-stream |
\ perform xt ( stack -- ) for all stacks except inst-stream |
next-stack-number @ 1 +do |
next-stack-number @ 1 +do |
stacks i th @ xt execute |
stacks i th @ xt execute |
loop ; |
loop ; |
Line 246 variable next-state-number 0 next-state-
|
Line 255 variable next-state-number 0 next-state-
|
|
|
: init-item ( addr u addr1 -- ) |
: init-item ( addr u addr1 -- ) |
\ initialize item at addr1 with name addr u |
\ initialize item at addr1 with name addr u |
\ !! remove stack prefix |
\ the stack prefix is removed by the stack-prefix |
dup item% %size erase |
dup item% %size erase |
item-name 2! ; |
item-name 2! ; |
|
|
Line 267 struct%
|
Line 276 struct%
|
cell% 2* field prim-name |
cell% 2* field prim-name |
cell% 2* field prim-wordset |
cell% 2* field prim-wordset |
cell% 2* field prim-c-name |
cell% 2* field prim-c-name |
|
cell% 2* field prim-c-name-orig \ for reprocessed prims, the original name |
cell% 2* field prim-doc |
cell% 2* field prim-doc |
cell% 2* field prim-c-code |
cell% 2* field prim-c-code |
cell% 2* field prim-forth-code |
cell% 2* field prim-forth-code |
Line 279 struct%
|
Line 289 struct%
|
cell% field prim-effect-out-end |
cell% field prim-effect-out-end |
cell% max-stacks * field prim-stacks-in \ number of in items per stack |
cell% max-stacks * field prim-stacks-in \ number of in items per stack |
cell% max-stacks * field prim-stacks-out \ number of out items per stack |
cell% max-stacks * field prim-stacks-out \ number of out items per stack |
|
cell% max-stacks * field prim-stacks-sync \ sync flag per stack |
end-struct prim% |
end-struct prim% |
|
|
: make-prim ( -- prim ) |
: make-prim ( -- prim ) |
Line 302 variable in-part \ true if processing a
|
Line 313 variable in-part \ true if processing a
|
r> to prim |
r> to prim |
throw ; |
throw ; |
|
|
|
: prim-c-name-2! ( c-addr u -- ) |
|
2dup prim prim-c-name 2! prim prim-c-name-orig 2! ; |
|
|
1000 constant max-combined |
1000 constant max-combined |
create combined-prims max-combined cells allot |
create combined-prims max-combined cells allot |
variable num-combined |
variable num-combined |
Line 346 wordlist constant primitives
|
Line 360 wordlist constant primitives
|
\ address of number of stack items in effect out |
\ address of number of stack items in effect out |
stack-number @ cells prim prim-stacks-out + ; |
stack-number @ cells prim prim-stacks-out + ; |
|
|
|
: stack-prim-stacks-sync ( stack -- addr ) |
|
prim prim-stacks-sync swap stack-number @ th ; |
|
|
\ global vars |
\ global vars |
variable c-line |
variable c-line |
2variable c-filename |
2variable c-filename |
Line 354 variable name-line
|
Line 371 variable name-line
|
2variable last-name-filename |
2variable last-name-filename |
Variable function-number 0 function-number ! |
Variable function-number 0 function-number ! |
Variable function-old 0 function-old ! |
Variable function-old 0 function-old ! |
: function-diff ( n -- ) |
: function-diff ( -- ) |
." GROUPADD(" function-number @ function-old @ - 0 .r ." )" cr |
." GROUPADD(" function-number @ function-old @ - 0 .r ." )" cr |
function-number @ function-old ! ; |
function-number @ function-old ! ; |
: forth-fdiff ( -- ) |
: forth-fdiff ( -- ) |
Line 492 defer inst-stream-f ( -- stack )
|
Line 509 defer inst-stream-f ( -- stack )
|
." vm_two" |
." vm_two" |
r@ item-stack-type-name type ." 2" |
r@ item-stack-type-name type ." 2" |
r@ item-type @ print-type-prefix ." (" |
r@ item-type @ print-type-prefix ." (" |
r@ item-in-index r@ item-stack @ 2dup ." (Cell)" stack-read |
r@ item-in-index r@ item-stack @ 2dup stack-read |
." , " -1 under+ ." (Cell)" stack-read |
." , " -1 under+ stack-read |
." , " r@ item-name 2@ type |
." , " r@ item-name 2@ type |
." )" cr |
." )" cr |
rdrop ; |
rdrop ; |
|
|
: same-as-in? ( item -- f ) |
: same-as-in? ( item -- f ) |
\ f is true iff the offset and stack of item is the same as on input |
\ f is true iff the offset and stack of item is the same as on input |
>r |
>r |
r@ item-first @ if |
r@ item-stack @ stack-prim-stacks-sync @ if |
rdrop false exit |
rdrop false exit |
endif |
endif |
r@ item-name 2@ prim prim-items-wordlist @ search-wordlist 0= abort" bug" |
r@ item-first @ if |
execute @ |
rdrop false exit |
dup r@ = |
endif |
if \ item first appeared in output |
r@ item-name 2@ prim prim-items-wordlist @ search-wordlist 0= abort" bug" |
drop false |
execute @ |
else |
dup r@ = |
dup item-stack @ r@ item-stack @ = |
if \ item first appeared in output |
swap item-offset @ r@ item-offset @ = and |
drop false |
endif |
else |
rdrop ; |
dup item-stack @ r@ item-stack @ = |
|
swap item-offset @ r@ item-offset @ = and |
|
endif |
|
rdrop ; |
|
|
: item-out-index ( item -- n ) |
: item-out-index ( item -- n ) |
\ n is the index of item (in the out-effect) |
\ n is the index of item (in the out-effect) |
Line 531 defer inst-stream-f ( -- stack )
|
Line 551 defer inst-stream-f ( -- stack )
|
: store-single { item -- } |
: store-single { item -- } |
item item-stack @ { stack } |
item item-stack @ { stack } |
store-optimization @ in-part @ 0= and item same-as-in? and |
store-optimization @ in-part @ 0= and item same-as-in? and |
item item-in-index stack state-in stack-reg 0= and \ in in memory? |
item item-in-index stack state-in stack-reg \ in reg/mem |
item item-out-index stack state-out stack-reg 0= and \ out in memory? |
item item-out-index stack state-out stack-reg = and \ out reg/mem |
0= if |
0= if |
item really-store-single cr |
item really-store-single cr |
endif ; |
endif ; |
Line 611 does> ( item -- )
|
Line 631 does> ( item -- )
|
UNLOOP EXIT |
UNLOOP EXIT |
endif |
endif |
-1 s+loop |
-1 s+loop |
\ we did not find a type, abort |
\ we did not find a type, abort |
|
abort |
false s" unknown prefix" ?print-error ; |
false s" unknown prefix" ?print-error ; |
|
|
: declaration ( item -- ) |
: declaration ( item -- ) |
Line 645 does> ( item -- )
|
Line 666 does> ( item -- )
|
stack item item-stack ! |
stack item item-stack ! |
item declaration ; |
item declaration ; |
|
|
|
: set-prim-stacks-sync ( stack -- ) |
|
stack-prim-stacks-sync on ; |
|
|
|
: clear-prim-stacks-sync ( stack -- ) |
|
stack-prim-stacks-sync off ; |
|
|
|
|
|
get-current prefixes set-current |
|
: ... ( item -- ) |
|
\ this "prefix" ensures that the appropriate stack is synced with memory |
|
dup item-name 2@ s" ..." str= 0= abort" '...' must end the item name" |
|
item-stack @ dup if |
|
set-prim-stacks-sync |
|
else \ prefixless "..." syncs all stacks |
|
drop ['] set-prim-stacks-sync map-stacks1 |
|
endif ; |
|
set-current |
|
|
|
create ...-item ( -- addr ) \ just used for letting stack-prefixes work on it |
|
item% %allot drop \ stores the stack temporarily until used by ... |
|
|
|
: init-item1 ( addr1 addr u -- addr2 ) |
|
\ initialize item at addr1 with name addr u, next item is at addr2 |
|
\ !! make sure that any mention of "..." is only stack-prefixed |
|
2dup s" ..." search nip nip if ( addr1 addr u ) |
|
0 ...-item item-stack ! \ initialize to prefixless |
|
2dup ...-item item-name 2! |
|
...-item rot rot execute-prefix ( addr1 ) |
|
else |
|
2 pick init-item item% %size + |
|
endif ; |
|
|
\ types pointed to by stacks for use in combined prims |
\ types pointed to by stacks for use in combined prims |
\ !! output-c-combined shouldn't use these names! |
\ !! output-c-combined shouldn't use these names! |
: stack-type-name ( addr u "name" -- ) |
: stack-type-name ( addr u "name" -- ) |
Line 707 stack inst-stream IP Cell
|
Line 760 stack inst-stream IP Cell
|
: state ( "name" -- ) |
: state ( "name" -- ) |
\ create a state initialized with default-sss |
\ create a state initialized with default-sss |
create state% %allot { s } |
create state% %allot { s } |
|
s state-enabled on |
next-state-number @ s state-number ! 1 next-state-number +! |
next-state-number @ s state-number ! 1 next-state-number +! |
max-stacks 0 ?do |
max-stacks 0 ?do |
default-ss s state-sss i th ! |
default-ss s state-sss i th ! |
loop ; |
loop ; |
|
|
|
: state-disable ( state -- ) |
|
state-enabled off ; |
|
|
|
: state-enabled? ( state -- f ) |
|
state-enabled @ ; |
|
|
|
: .state ( state -- ) |
|
0 >body - >name .name ; |
|
|
: set-ss ( ss stack state -- ) |
: set-ss ( ss stack state -- ) |
state-sss swap stack-number @ th ! ; |
state-sss swap stack-number @ th ! ; |
|
|
Line 738 stack inst-stream IP Cell
|
Line 801 stack inst-stream IP Cell
|
prim prim-effect-out prim prim-effect-out-end @ ['] compute-offset-out map-items |
prim prim-effect-out prim prim-effect-out-end @ ['] compute-offset-out map-items |
inst-stream stack-out @ 0= s" # can only be on the input side" ?print-error ; |
inst-stream stack-out @ 0= s" # can only be on the input side" ?print-error ; |
|
|
|
: init-simple { prim -- } |
|
\ much of the initialization is elsewhere |
|
['] clear-prim-stacks-sync map-stacks ; |
|
|
: process-simple ( -- ) |
: process-simple ( -- ) |
prim prim { W^ key } key cell |
prim prim { W^ key } key cell |
combinations ['] constant insert-wordlist |
combinations ['] constant insert-wordlist |
Line 753 stack inst-stream IP Cell
|
Line 820 stack inst-stream IP Cell
|
stack state-in stack-state-items stack stack-in @ - 0 max |
stack state-in stack-state-items stack stack-in @ - 0 max |
stack state-out stack-state-items stack stack-out @ - 0 max ; |
stack state-out stack-state-items stack stack-out @ - 0 max ; |
|
|
|
: spill-stack-items { stack -- u } |
|
\ there are u items to spill in stack |
|
stack unused-stack-items |
|
stack stack-prim-stacks-sync @ if |
|
drop 0 |
|
endif |
|
swap - ; |
|
|
: spill-stack { stack -- } |
: spill-stack { stack -- } |
\ spill regs of state-in that are not used by prim and are not in state-out |
\ spill regs of state-in that are not used by prim and are not in state-out |
stack state-in stack-offset { offset } |
stack state-in stack-offset { offset } |
stack state-in stack-state-items ( items ) |
stack state-in stack-state-items ( items ) |
dup stack unused-stack-items - - +do |
dup stack spill-stack-items + +do |
\ loop through the bottom items |
\ loop through the bottom items |
stack stack-pointer 2@ type |
stack stack-pointer 2@ type |
i offset - stack normal-stack-access0 ." = " |
i offset - stack normal-stack-access0 ." = " |
Line 767 stack inst-stream IP Cell
|
Line 842 stack inst-stream IP Cell
|
: spill-state ( -- ) |
: spill-state ( -- ) |
['] spill-stack map-stacks1 ; |
['] spill-stack map-stacks1 ; |
|
|
|
: fill-stack-items { stack -- u } |
|
\ there are u items to fill in stack |
|
stack unused-stack-items |
|
stack stack-prim-stacks-sync @ if |
|
swap drop 0 swap |
|
endif |
|
- ; |
|
|
: fill-stack { stack -- } |
: fill-stack { stack -- } |
stack state-out stack-offset { offset } |
stack state-out stack-offset { offset } |
stack state-out stack-state-items ( items ) |
stack state-out stack-state-items ( items ) |
dup stack unused-stack-items - + +do |
dup stack fill-stack-items + +do |
\ loop through the bottom items |
\ loop through the bottom items |
i stack state-out normal-stack-access1 ." = " |
i stack state-out normal-stack-access1 ." = " |
stack stack-pointer 2@ type |
stack stack-pointer 2@ type |
Line 826 stack inst-stream IP Cell
|
Line 909 stack inst-stream IP Cell
|
stack-access-transform @ dup >r execute |
stack-access-transform @ dup >r execute |
0 r> execute - ; |
0 r> execute - ; |
|
|
: stack-pointer-update { stack -- } |
: update-stack-pointer { stack n -- } |
\ and moves |
n if \ this check is not necessary, gcc would do this for us |
\ stacks grow downwards |
|
stack stack-diff ( in-out ) |
|
stack state-in stack-offset - |
|
stack state-out stack-offset + ( [in-in_offset]-[out-out_offset] ) |
|
?dup-if \ this check is not necessary, gcc would do this for us |
|
stack inst-stream = if |
stack inst-stream = if |
." INC_IP(" 0 .r ." );" cr |
." INC_IP(" n 0 .r ." );" cr |
else |
else |
stack stack-pointer 2@ type ." += " |
stack stack-pointer 2@ type ." += " |
stack stack-update-transform 0 .r ." ;" cr |
n stack stack-update-transform 0 .r ." ;" cr |
endif |
endif |
endif |
endif ; |
stack stack-moves ; |
|
|
: stack-pointer-update { stack -- } |
|
\ and moves |
|
\ stacks grow downwards |
|
stack stack-prim-stacks-sync @ if |
|
stack stack-in @ |
|
stack state-in stack-offset - |
|
stack swap update-stack-pointer |
|
else |
|
stack stack-diff ( in-out ) |
|
stack state-in stack-offset - |
|
stack state-out stack-offset + ( [in-in_offset]-[out-out_offset] ) |
|
stack swap update-stack-pointer |
|
stack stack-moves |
|
endif ; |
|
|
: stack-pointer-updates ( -- ) |
: stack-pointer-updates ( -- ) |
['] stack-pointer-update map-stacks ; |
['] stack-pointer-update map-stacks ; |
|
|
|
: stack-pointer-update2 { stack -- } |
|
stack stack-prim-stacks-sync @ if |
|
stack state-out stack-offset |
|
stack stack-out @ - |
|
stack swap update-stack-pointer |
|
endif ; |
|
|
|
: stack-pointer-updates2 ( -- ) |
|
\ update stack pointers after C code, where necessary |
|
['] stack-pointer-update2 map-stacks ; |
|
|
: store ( item -- ) |
: store ( item -- ) |
\ f is true if the item should be stored |
\ f is true if the item should be stored |
\ f is false if the store is probably not necessary |
\ f is false if the store is probably not necessary |
Line 906 variable tail-nextp2 \ xt to execute for
|
Line 1009 variable tail-nextp2 \ xt to execute for
|
|
|
: output-label2 ( -- ) |
: output-label2 ( -- ) |
." LABEL2(" prim prim-c-name 2@ type ." )" cr |
." LABEL2(" prim prim-c-name 2@ type ." )" cr |
." NEXT_P2;" cr ; |
." NEXT_P1_5;" cr |
|
." LABEL3(" prim prim-c-name 2@ type ." )" cr |
|
." DO_GOTO;" cr ; |
|
|
: output-c-tail1 { xt -- } |
: output-c-tail1 { xt -- } |
\ the final part of the generated C code, with xt printing LABEL2 or not. |
\ the final part of the generated C code, with xt printing LABEL2 or not. |
output-super-end |
output-super-end |
print-debug-results |
print-debug-results |
output-nextp1 |
output-nextp1 |
|
stack-pointer-updates2 |
stores |
stores |
fill-state |
fill-state |
xt execute ; |
xt execute ; |
|
|
|
: output-c-vm-jump-tail ( -- ) |
|
\ !! this functionality not yet implemented for superinstructions |
|
output-super-end |
|
print-debug-results |
|
stores |
|
fill-state |
|
." LABEL2(" prim prim-c-name 2@ type ." )" cr |
|
." LABEL3(" prim prim-c-name 2@ type ." )" cr |
|
." DO_GOTO;" cr ; |
|
|
: output-c-tail1-no-stores { xt -- } |
: output-c-tail1-no-stores { xt -- } |
\ the final part of the generated C code for combinations |
\ the final part of the generated C code for combinations |
output-super-end |
output-super-end |
Line 928 variable tail-nextp2 \ xt to execute for
|
Line 1044 variable tail-nextp2 \ xt to execute for
|
tail-nextp2 @ output-c-tail1 ; |
tail-nextp2 @ output-c-tail1 ; |
|
|
: output-c-tail2 ( -- ) |
: output-c-tail2 ( -- ) |
['] output-label2 output-c-tail1 ; |
prim prim-c-code 2@ s" VM_JUMP(" search nip nip if |
|
output-c-vm-jump-tail |
|
else |
|
['] output-label2 output-c-tail1 |
|
endif ; |
|
|
: output-c-tail-no-stores ( -- ) |
: output-c-tail-no-stores ( -- ) |
tail-nextp2 @ output-c-tail1-no-stores ; |
tail-nextp2 @ output-c-tail1-no-stores ; |
Line 955 variable tail-nextp2 \ xt to execute for
|
Line 1075 variable tail-nextp2 \ xt to execute for
|
|
|
: print-entry ( -- ) |
: print-entry ( -- ) |
." LABEL(" prim prim-c-name 2@ type ." )" ; |
." LABEL(" prim prim-c-name 2@ type ." )" ; |
|
|
: output-c ( -- ) |
: prim-type ( addr u -- ) |
print-entry ." /* " prim prim-name 2@ type ." ( " prim prim-stack-string 2@ type ." ) */" cr |
\ print out a primitive, but avoid "*/" |
|
2dup s" */" search nip nip IF |
|
bounds ?DO I c@ dup '* = IF drop 'x THEN emit LOOP |
|
ELSE type THEN ; |
|
|
|
: output-c ( -- ) |
|
print-entry ." /* " prim prim-name 2@ prim-type |
|
." ( " prim prim-stack-string 2@ type ." ) " |
|
state-in .state ." -- " state-out .state ." */" cr |
." /* " prim prim-doc 2@ type ." */" cr |
." /* " prim prim-doc 2@ type ." */" cr |
." NAME(" quote prim prim-name 2@ type quote ." )" cr \ debugging |
." NAME(" quote prim prim-name 2@ type quote ." )" cr \ debugging |
." {" cr |
." {" cr |
Line 1035 variable tail-nextp2 \ xt to execute for
|
Line 1163 variable tail-nextp2 \ xt to execute for
|
prim prim-branch? |
prim prim-branch? |
prim prim-c-code 2@ s" SUPER_END" search nip nip 0<> or |
prim prim-c-code 2@ s" SUPER_END" search nip nip 0<> or |
prim prim-c-code 2@ s" SUPER_CONTINUE" search nip nip 0= and |
prim prim-c-code 2@ s" SUPER_CONTINUE" search nip nip 0= and |
negate 0 .r ." , /* " prim prim-name 2@ type ." */" cr ; |
negate 0 .r ." , /* " prim prim-name 2@ prim-type ." */" cr ; |
|
|
: gen-arg-parm { item -- } |
: gen-arg-parm { item -- } |
item item-stack @ inst-stream = if |
item item-stack @ inst-stream = if |
Line 1057 variable tail-nextp2 \ xt to execute for
|
Line 1185 variable tail-nextp2 \ xt to execute for
|
|
|
: output-gen ( -- ) |
: output-gen ( -- ) |
\ generate C code for generating VM instructions |
\ generate C code for generating VM instructions |
." void gen_" prim prim-c-name 2@ type ." (Inst **ctp" gen-args-parm ." )" cr |
." void gen_" prim prim-c-name 2@ type ." (" |
|
threaded-code-pointer-type 2@ type ." ctp" gen-args-parm ." )" cr |
." {" cr |
." {" cr |
." gen_inst(ctp, vm_prim[" function-number @ 0 .r ." ]);" cr |
." gen_inst(ctp, " function-number @ 0 .r ." );" cr |
gen-args-gen |
gen-args-gen |
." }" cr ; |
." }" cr ; |
|
|
Line 1106 variable tail-nextp2 \ xt to execute for
|
Line 1235 variable tail-nextp2 \ xt to execute for
|
: output-alias ( -- ) |
: output-alias ( -- ) |
( primitive-number @ . ." alias " ) ." Primitive " prim prim-name 2@ type cr ; |
( primitive-number @ . ." alias " ) ." Primitive " prim prim-name 2@ type cr ; |
|
|
: output-c-prim-num ( -- ) |
defer output-c-prim-num ( -- ) |
|
|
|
:noname ( -- ) |
." N_" prim prim-c-name 2@ type ." ," cr ; |
." N_" prim prim-c-name 2@ type ." ," cr ; |
|
is output-c-prim-num |
|
|
: output-forth ( -- ) |
: output-forth ( -- ) |
prim prim-forth-code @ 0= |
prim prim-forth-code @ 0= |
Line 1342 variable reprocessed-num 0 reprocessed-n
|
Line 1474 variable reprocessed-num 0 reprocessed-n
|
|
|
: state-prim1 { in-state out-state prim -- } |
: state-prim1 { in-state out-state prim -- } |
in-state out-state state-default dup d= ?EXIT |
in-state out-state state-default dup d= ?EXIT |
|
in-state state-enabled? out-state state-enabled? and 0= ?EXIT |
in-state to state-in |
in-state to state-in |
out-state to state-out |
out-state to state-out |
prim reprocess-simple ; |
prim reprocess-simple ; |
Line 1360 variable reprocessed-num 0 reprocessed-n
|
Line 1493 variable reprocessed-num 0 reprocessed-n
|
: compute-default-state-out ( n-in -- n-out ) |
: compute-default-state-out ( n-in -- n-out ) |
\ for the current prim |
\ for the current prim |
cache-stack stack-in @ - 0 max |
cache-stack stack-in @ - 0 max |
|
cache-stack stack-prim-stacks-sync @ if |
|
drop 0 |
|
endif |
cache-stack stack-out @ + cache-states 2@ nip 1- min ; |
cache-stack stack-out @ + cache-states 2@ nip 1- min ; |
|
|
: gen-prim-states ( prim -- ) |
: gen-prim-states ( prim -- ) |
Line 1438 variable reprocessed-num 0 reprocessed-n
|
Line 1574 variable reprocessed-num 0 reprocessed-n
|
|
|
: output-part ( p -- ) |
: output-part ( p -- ) |
to prim |
to prim |
." /* " prim prim-name 2@ type ." ( " prim prim-stack-string 2@ type ." ) */" cr |
." /* " prim prim-name 2@ prim-type ." ( " prim prim-stack-string 2@ type ." ) */" cr |
." NAME(" quote prim prim-name 2@ type quote ." )" cr \ debugging |
." NAME(" quote prim prim-name 2@ type quote ." )" cr \ debugging |
." {" cr |
." {" cr |
print-declarations |
print-declarations |
Line 1505 variable reprocessed-num 0 reprocessed-n
|
Line 1641 variable reprocessed-num 0 reprocessed-n
|
\ This is intended as initializer for a structure like this |
\ This is intended as initializer for a structure like this |
|
|
\ struct cost { |
\ struct cost { |
\ int loads; /* number of stack loads */ |
\ char loads; /* number of stack loads */ |
\ int stores; /* number of stack stores */ |
\ char stores; /* number of stack stores */ |
\ int updates; /* number of stack pointer updates */ |
\ char updates; /* number of stack pointer updates */ |
\ int offset; /* offset into super2 table */ |
\ char branch; /* is it a branch (SET_IP) */ |
\ int length; /* number of components */ |
\ char state_in; /* state on entry */ |
|
\ char state_out; /* state on exit */ |
|
\ short offset; /* offset into super2 table */ |
|
\ char length; /* number of components */ |
\ }; |
\ }; |
|
|
\ How do you know which primitive or combined instruction this |
\ How do you know which primitive or combined instruction this |
Line 1539 variable reprocessed-num 0 reprocessed-n
|
Line 1678 variable reprocessed-num 0 reprocessed-n
|
loop ; |
loop ; |
|
|
: output-num-part ( p -- ) |
: output-num-part ( p -- ) |
." N_" prim-c-name 2@ type ." ," ; |
." N_" prim-c-name-orig 2@ type ." ," ; |
\ prim-num @ 4 .r ." ," ; |
\ prim-num @ 4 .r ." ," ; |
|
|
: output-name-comment ( -- ) |
: output-name-comment ( -- ) |
." /* " prim prim-name 2@ type ." */" ; |
." /* " prim prim-name 2@ prim-type ." */" ; |
|
|
variable offset-super2 0 offset-super2 ! \ offset into the super2 table |
variable offset-super2 0 offset-super2 ! \ offset into the super2 table |
|
|
Line 1552 variable offset-super2 0 offset-super2
|
Line 1691 variable offset-super2 0 offset-super2
|
rot 2 .r ." ," swap 2 .r ." ," 2 .r ." , " |
rot 2 .r ." ," swap 2 .r ." ," 2 .r ." , " |
prim prim-branch? negate . ." ," |
prim prim-branch? negate . ." ," |
state-in state-number @ 2 .r ." ," |
state-in state-number @ 2 .r ." ," |
state-out state-number @ 2 .r ." ," ; |
state-out state-number @ 2 .r ." ," |
|
inst-stream stack-in @ 1 .r ." ," |
|
; |
|
|
: output-costs-gforth-simple ( -- ) |
: output-costs-gforth-simple ( -- ) |
output-costs-prefix |
output-costs-prefix |
Line 1568 variable offset-super2 0 offset-super2
|
Line 1709 variable offset-super2 0 offset-super2
|
output-name-comment |
output-name-comment |
cr ; |
cr ; |
|
|
: output-costs ( -- ) |
\ : output-costs ( -- ) |
\ description of superinstructions and simple instructions |
\ \ description of superinstructions and simple instructions |
." {" prim compute-costs |
\ ." {" prim compute-costs |
rot 2 .r ." ," swap 2 .r ." ," 2 .r ." ," |
\ rot 2 .r ." ," swap 2 .r ." ," 2 .r ." ," |
offset-super2 @ 5 .r ." ," |
\ offset-super2 @ 5 .r ." ," |
super2-length dup 2 .r ." }," offset-super2 +! |
\ super2-length dup 2 .r ." ," offset-super2 +! |
output-name-comment |
\ inst-stream stack-in @ 1 .r ." }," |
cr ; |
\ output-name-comment |
|
\ cr ; |
|
|
: output-super2 ( -- ) |
: output-super2-simple ( -- ) |
\ table of superinstructions without requirement for existing prefixes |
prim prim-c-name 2@ prim prim-c-name-orig 2@ d= if |
combined if |
|
['] output-num-part map-combined |
|
else |
|
prim output-num-part |
prim output-num-part |
endif |
output-name-comment |
|
cr |
|
endif ; |
|
|
|
: output-super2-combined ( -- ) |
|
['] output-num-part map-combined |
output-name-comment |
output-name-comment |
cr ; |
cr ; |
|
|
Line 1678 nl-char singleton eof-char over add-memb
|
Line 1822 nl-char singleton eof-char over add-memb
|
(( letter (( letter || digit )) ** |
(( letter (( letter || digit )) ** |
)) <- c-ident ( -- ) |
)) <- c-ident ( -- ) |
|
|
(( ` # ?? (( letter || digit || ` : )) ++ |
(( ` . ` . ` . |
|
)) <- sync-stack ( -- ) |
|
|
|
(( ` # ?? (( letter || digit || ` : )) ++ sync-stack ?? |
|
|| sync-stack |
)) <- stack-ident ( -- ) |
)) <- stack-ident ( -- ) |
|
|
(( nowhitebq nowhite ** )) |
(( nowhitebq nowhite ** )) |
Line 1707 Variable c-flag
|
Line 1855 Variable c-flag
|
)) <- else-comment |
)) <- else-comment |
|
|
(( ` + {{ start }} nonl ** {{ end |
(( ` + {{ start }} nonl ** {{ end |
dup |
dup |
IF c-flag @ |
IF |
IF |
c-flag @ IF |
function-diff |
function-diff |
." #ifdef HAS_" bounds ?DO I c@ toupper emit LOOP cr |
." #ifdef HAS_" 2dup bounds ?DO I c@ toupper emit LOOP cr |
THEN |
THEN |
forth-flag @ |
forth-flag @ IF |
IF forth-fdiff ." has? " type ." [IF]" cr THEN |
forth-fdiff ." has? " 2dup type ." [IF]" cr |
ELSE 2drop |
THEN |
|
2drop |
|
ELSE |
|
2drop |
c-flag @ IF |
c-flag @ IF |
function-diff ." #endif" cr THEN |
function-diff ." #endif" cr THEN |
forth-flag @ IF forth-fdiff ." [THEN]" cr THEN |
forth-flag @ IF forth-fdiff ." [THEN]" cr THEN |
Line 1724 Variable c-flag
|
Line 1875 Variable c-flag
|
|
|
(( (( ` g || ` G )) {{ start }} nonl ** |
(( (( ` g || ` G )) {{ start }} nonl ** |
{{ end |
{{ end |
forth-flag @ IF forth-fdiff ." group " type cr THEN |
forth-flag @ IF forth-fdiff ." group " 2dup type cr THEN |
c-flag @ IF function-diff |
c-flag @ IF function-diff |
." GROUP(" type ." , " function-number @ 0 .r ." )" cr THEN }} |
." GROUP(" 2dup type ." , " function-number @ 0 .r ." )" cr THEN |
|
2drop }} |
)) <- group-comment |
)) <- group-comment |
|
|
(( (( eval-comment || forth-comment || c-comment || else-comment || if-comment || group-comment )) ?? nonl ** )) <- comment-body |
(( (( eval-comment || forth-comment || c-comment || else-comment || if-comment || group-comment )) ?? nonl ** )) <- comment-body |
|
|
(( ` \ comment-body nleof )) <- comment ( -- ) |
(( ` \ comment-body nleof )) <- comment ( -- ) |
|
|
(( {{ start }} stack-ident {{ end 2 pick init-item item% %size + }} white ** )) ** |
(( {{ start }} stack-ident {{ end init-item1 }} white ** )) ** |
<- stack-items |
<- stack-items ( addr1 -- addr2 ) |
|
|
(( {{ prim prim-effect-in }} stack-items {{ prim prim-effect-in-end ! }} |
(( {{ prim prim-effect-in }} stack-items {{ prim prim-effect-in-end ! }} |
` - ` - white ** |
` - ` - white ** |
{{ prim prim-effect-out }} stack-items {{ prim prim-effect-out-end ! }} |
{{ prim prim-effect-out }} stack-items {{ prim prim-effect-out-end ! }} |
)) <- stack-effect ( -- ) |
)) <- stack-effect ( -- ) |
|
|
(( {{ prim create-prim }} |
(( {{ prim create-prim prim init-simple }} |
` ( white ** {{ start }} stack-effect {{ end prim prim-stack-string 2! }} ` ) white ** |
` ( white ** {{ start }} stack-effect {{ end prim prim-stack-string 2! }} ` ) white ** |
(( {{ start }} forth-ident {{ end prim prim-wordset 2! }} white ** |
(( {{ start }} forth-ident {{ end prim prim-wordset 2! }} white ** |
(( {{ start }} c-ident {{ end prim prim-c-name 2! }} )) ?? |
(( {{ start }} c-ident {{ end prim-c-name-2! }} )) ?? |
)) ?? nleof |
)) ?? nleof |
(( ` " ` " {{ start }} (( noquote ++ ` " )) ++ {{ end 1- prim prim-doc 2! }} ` " white ** nleof )) ?? |
(( ` " ` " {{ start }} (( noquote ++ ` " )) ++ {{ end 1- prim prim-doc 2! }} ` " white ** nleof )) ?? |
{{ skipsynclines off line @ c-line ! filename 2@ c-filename 2! start }} |
{{ skipsynclines off line @ c-line ! filename 2@ c-filename 2! start }} |
Line 1766 Variable c-flag
|
Line 1918 Variable c-flag
|
line @ name-line ! filename 2@ name-filename 2! |
line @ name-line ! filename 2@ name-filename 2! |
function-number @ prim prim-num ! |
function-number @ prim prim-num ! |
start }} [ifdef] vmgen c-ident [else] forth-ident [then] {{ end |
start }} [ifdef] vmgen c-ident [else] forth-ident [then] {{ end |
2dup prim prim-name 2! prim prim-c-name 2! }} white ** |
2dup prim prim-name 2! prim-c-name-2! }} white ** |
(( ` / white ** {{ start }} c-ident {{ end prim prim-c-name 2! }} white ** )) ?? |
(( ` / white ** {{ start }} c-ident {{ end prim-c-name-2! }} white ** )) ?? |
(( simple-primitive || combined-primitive )) |
(( simple-primitive || combined-primitive )) |
{{ 1 function-number +! }} |
{{ 1 function-number +! }} |
)) <- primitive ( -- ) |
)) <- primitive ( -- ) |