version 1.106, 2002/06/02 15:46:16
|
version 1.111, 2002/08/20 16:59:01
|
Line 60 include startup.fs
|
Line 60 include startup.fs
|
: struct% struct ; \ struct is redefined in gray |
: struct% struct ; \ struct is redefined in gray |
|
|
warnings off |
warnings off |
|
\ warnings on |
|
|
include ./gray.fs |
include ./gray.fs |
|
|
32 constant max-effect \ number of things on one side of a stack effect |
32 constant max-effect \ number of things on one side of a stack effect |
4 constant max-stacks \ the max. number of stacks (including inst-stream). |
4 constant max-stacks \ the max. number of stacks (including inst-stream). |
255 constant maxchar |
255 constant maxchar |
Line 78 variable line-start \ pointer to start o
|
Line 78 variable line-start \ pointer to start o
|
0 line ! |
0 line ! |
2variable filename \ filename of original input file |
2variable filename \ filename of original input file |
0 0 filename 2! |
0 0 filename 2! |
|
2variable out-filename \ filename of the output file (for sync lines) |
|
0 0 out-filename 2! |
2variable f-comment |
2variable f-comment |
0 0 f-comment 2! |
0 0 f-comment 2! |
variable skipsynclines \ are sync lines ("#line ...") invisible to the parser? |
variable skipsynclines \ are sync lines ("#line ...") invisible to the parser? |
skipsynclines on |
skipsynclines on |
|
variable out-nls \ newlines in output (for output sync lines) |
|
0 out-nls ! |
|
|
: th ( addr1 n -- addr2 ) |
: th ( addr1 n -- addr2 ) |
cells + ; |
cells + ; |
Line 121 skipsynclines on
|
Line 125 skipsynclines on
|
0 |
0 |
recover endtry |
recover endtry |
r> to outfile-id throw |
r> to outfile-id throw |
abort |
1 (bye) \ abort |
endif ; |
endif ; |
|
|
: quote ( -- ) |
: quote ( -- ) |
[char] " emit ; |
[char] " emit ; |
|
|
|
\ count output lines to generate sync lines for output |
|
|
|
: count-nls ( addr u -- ) |
|
bounds u+do |
|
i c@ nl-char = negate out-nls +! |
|
loop ; |
|
|
|
:noname ( addr u -- ) |
|
2dup count-nls |
|
defers type ; |
|
is type |
|
|
variable output \ xt ( -- ) of output word for simple primitives |
variable output \ xt ( -- ) of output word for simple primitives |
variable output-combined \ xt ( -- ) of output word for combined primitives |
variable output-combined \ xt ( -- ) of output word for combined primitives |
|
|
Line 625 stack inst-stream IP Cell
|
Line 641 stack inst-stream IP Cell
|
endif |
endif |
2drop ; |
2drop ; |
|
|
: output-c-tail ( -- ) |
: output-c-tail1 ( -- ) |
\ the final part of the generated C code |
\ the final part of the generated C code except LABEL2 and NEXT_P2 |
output-super-end |
output-super-end |
print-debug-results |
print-debug-results |
." NEXT_P1;" cr |
." NEXT_P1;" cr |
stores |
stores |
fill-tos |
fill-tos ; |
|
|
|
: output-c-tail ( -- ) |
|
\ the final part of the generated C code, without LABEL2 |
|
output-c-tail1 |
." NEXT_P2;" ; |
." NEXT_P2;" ; |
|
|
|
: output-c-tail2 ( -- ) |
|
\ the final part of the generated C code, including LABEL2 |
|
output-c-tail1 |
|
." LABEL2(" prim prim-c-name 2@ type ." )" cr |
|
." NEXT_P2;" cr ; |
|
|
: type-c-code ( c-addr u xt -- ) |
: type-c-code ( c-addr u xt -- ) |
\ like TYPE, but replaces "TAIL;" with tail code produced by xt |
\ like TYPE, but replaces "INST_TAIL;" with tail code produced by xt |
{ xt } |
{ xt } |
|
." {" cr |
|
." #line " c-line @ . quote c-filename 2@ type quote cr |
begin ( c-addr1 u1 ) |
begin ( c-addr1 u1 ) |
2dup s" TAIL;" search |
2dup s" INST_TAIL;" search |
while ( c-addr1 u1 c-addr3 u3 ) |
while ( c-addr1 u1 c-addr3 u3 ) |
2dup 2>r drop nip over - type |
2dup 2>r drop nip over - type |
xt execute |
xt execute |
2r> 5 /string |
2r> 10 /string |
\ !! resync #line missing |
\ !! resync #line missing |
repeat |
repeat |
2drop type ; |
2drop type |
|
." #line " out-nls @ 2 + . quote out-filename 2@ type quote cr |
|
." }" cr ; |
|
|
: print-entry ( -- ) |
: print-entry ( -- ) |
." LABEL(" prim prim-c-name 2@ type ." ):" ; |
." LABEL(" prim prim-c-name 2@ type ." )" ; |
|
|
: output-c ( -- ) |
: output-c ( -- ) |
print-entry ." /* " prim prim-name 2@ type ." ( " prim prim-stack-string 2@ type ." ) */" cr |
print-entry ." /* " prim prim-name 2@ type ." ( " prim prim-stack-string 2@ type ." ) */" 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 |
." DEF_CA" cr |
." DEF_CA" cr |
print-declarations |
print-declarations |
." NEXT_P0;" cr |
." NEXT_P0;" cr |
flush-tos |
flush-tos |
fetches |
fetches |
print-debug-args |
print-debug-args |
stack-pointer-updates |
stack-pointer-updates |
." {" cr |
prim prim-c-code 2@ ['] output-c-tail type-c-code |
." #line " c-line @ . quote c-filename 2@ type quote cr |
output-c-tail2 |
prim prim-c-code 2@ ['] output-c-tail type-c-code |
." }" cr |
." }" cr |
cr |
output-c-tail |
|
." }" cr |
|
cr |
|
; |
; |
|
|
: disasm-arg { item -- } |
: disasm-arg { item -- } |
item item-stack @ inst-stream = if |
item item-stack @ inst-stream = if |
." fputc(' ', vm_out); " |
." {" cr |
\ !! change this to first convert args to the right type and |
item print-declaration |
\ then print them |
item fetch |
." /* printarg_" item item-type @ print-type-prefix |
item print-debug-arg |
." ((" item item-type @ type-c-name 2@ type ." )" |
." }" cr |
." ip[" item item-offset @ 1+ 0 .r ." ]); */" cr |
|
endif ; |
endif ; |
|
|
: disasm-args ( -- ) |
: disasm-args ( -- ) |
Line 900 stack inst-stream IP Cell
|
Line 926 stack inst-stream IP Cell
|
\ #line 516 "./prim" |
\ #line 516 "./prim" |
\ n = n1+n2; |
\ n = n1+n2; |
\ } |
\ } |
\ NEXT_P1; |
|
\ _x_sp0 = (Cell)n; |
\ _x_sp0 = (Cell)n; |
\ NEXT_P2; |
|
\ } |
\ } |
\ NEXT_P1; |
\ NEXT_P1; |
\ spTOS = (Cell)_x_sp0; |
\ spTOS = (Cell)_x_sp0; |
Line 1019 stack inst-stream IP Cell
|
Line 1043 stack inst-stream IP Cell
|
part-fetches |
part-fetches |
print-debug-args |
print-debug-args |
prim add-depths \ !! right place? |
prim add-depths \ !! right place? |
." {" cr |
|
." #line " c-line @ . quote c-filename 2@ type quote cr |
|
prim prim-c-code 2@ ['] output-combined-tail type-c-code |
prim prim-c-code 2@ ['] output-combined-tail type-c-code |
." }" cr |
|
part-output-c-tail |
part-output-c-tail |
." }" cr ; |
." }" cr ; |
|
|
Line 1047 stack inst-stream IP Cell
|
Line 1068 stack inst-stream IP Cell
|
\ print-debug-args |
\ print-debug-args |
stack-pointer-updates |
stack-pointer-updates |
output-parts |
output-parts |
output-c-tail |
output-c-tail2 |
." }" cr |
." }" cr |
cr ; |
cr ; |
|
|
Line 1158 bl singleton tab-char over add-member
|
Line 1179 bl singleton tab-char over add-member
|
nl-char singleton eof-char over add-member complement charclass nonl |
nl-char singleton eof-char over add-member complement charclass nonl |
nl-char singleton eof-char over add-member |
nl-char singleton eof-char over add-member |
char : over add-member complement charclass nocolonnl |
char : over add-member complement charclass nocolonnl |
|
nl-char singleton eof-char over add-member |
|
char } over add-member complement charclass nobracenl |
bl 1+ maxchar .. char \ singleton complement intersection |
bl 1+ maxchar .. char \ singleton complement intersection |
charclass nowhitebq |
charclass nowhitebq |
bl 1+ maxchar .. charclass nowhite |
bl 1+ maxchar .. charclass nowhite |
Line 1169 nl-char singleton eof-char over add-memb
|
Line 1192 nl-char singleton eof-char over add-memb
|
(( letter (( letter || digit )) ** |
(( letter (( letter || digit )) ** |
)) <- c-ident ( -- ) |
)) <- c-ident ( -- ) |
|
|
(( ` # ?? (( letter || digit || ` : )) ** |
(( ` # ?? (( letter || digit || ` : )) ++ |
)) <- stack-ident ( -- ) |
)) <- stack-ident ( -- ) |
|
|
(( nowhitebq nowhite ** )) |
(( nowhitebq nowhite ** )) |
Line 1232 Variable c-flag
|
Line 1255 Variable c-flag
|
(( {{ start }} c-ident {{ end prim prim-c-name 2! }} )) ?? |
(( {{ start }} c-ident {{ end prim 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 }} (( nocolonnl nonl ** nleof white ** )) ** {{ end prim prim-c-code 2! skipsynclines on }} |
{{ skipsynclines off line @ c-line ! filename 2@ c-filename 2! start }} |
|
(( (( ` { nonl ** nleof (( (( nobracenl {{ line @ drop }} nonl ** )) ?? nleof )) ** ` } white ** nleof white ** )) |
|
|| (( nocolonnl nonl ** nleof white ** )) ** )) |
|
{{ end prim prim-c-code 2! skipsynclines on }} |
(( ` : white ** nleof |
(( ` : white ** nleof |
{{ start }} (( nonl ++ nleof white ** )) ++ {{ end prim prim-forth-code 2! }} |
{{ start }} (( nonl ++ nleof white ** )) ++ {{ end prim prim-forth-code 2! }} |
)) ?? {{ process-simple }} |
)) ?? {{ process-simple }} |
Line 1247 Variable c-flag
|
Line 1273 Variable c-flag
|
(( {{ make-prim to prim 0 to combined |
(( {{ make-prim to prim 0 to combined |
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 }} forth-ident {{ end 2dup prim prim-name 2! prim prim-c-name 2! }} white ++ |
start }} [ifdef] vmgen c-ident [else] forth-ident [then] {{ end |
|
2dup prim prim-name 2! prim prim-c-name 2! }} white ** |
(( ` / white ** {{ start }} c-ident {{ end prim prim-c-name 2! }} white ** )) ?? |
(( ` / white ** {{ start }} c-ident {{ end prim prim-c-name 2! }} white ** )) ?? |
(( simple-primitive || combined-primitive )) {{ 1 function-number +! }} |
(( simple-primitive || combined-primitive )) {{ 1 function-number +! }} |
)) <- primitive ( -- ) |
)) <- primitive ( -- ) |