version 1.63, 2001/01/09 16:11:36
|
version 1.65, 2001/01/18 14:57:37
|
Line 68 variable rawinput \ pointer to next char
|
Line 68 variable rawinput \ pointer to next char
|
variable endrawinput \ pointer to the end of the input (the char after the last) |
variable endrawinput \ pointer to the end of the input (the char after the last) |
variable cookedinput \ pointer to the next char to be parsed |
variable cookedinput \ pointer to the next char to be parsed |
variable line \ line number of char pointed to by input |
variable line \ line number of char pointed to by input |
1 line ! |
variable line-start \ pointer to start of current line (for error messages) |
|
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 f-comment |
2variable f-comment |
Line 140 s" IP" save-mem s" error don't use # on
|
Line 141 s" IP" save-mem s" error don't use # on
|
dup item% %size erase |
dup item% %size erase |
item-name 2! ; |
item-name 2! ; |
|
|
|
: map-items { addr end xt -- } |
|
\ perform xt for all items in array addr...end |
|
end addr ?do |
|
i xt execute |
|
item% %size +loop ; |
|
|
\ various variables for storing stuff of one primitive |
\ various variables for storing stuff of one primitive |
|
|
2variable forth-name |
2variable forth-name |
Line 219 print-token !
|
Line 226 print-token !
|
endif |
endif |
drop ; |
drop ; |
|
|
|
: print-error-line ( -- ) |
|
\ print the current line and position |
|
line-start @ endrawinput @ over - 2dup nl-char scan drop nip ( start end ) |
|
over - type cr |
|
line-start @ rawinput @ over - typewhite ." ^" cr ; |
|
|
: ?nextchar ( f -- ) |
: ?nextchar ( f -- ) |
?not? if |
?not? if |
filename 2@ type ." :" line @ 0 .r ." : syntax error, wrong char:" |
outfile-id >r try |
getinput . cr |
stderr to outfile-id |
rawinput @ endrawinput @ over - 100 min type cr |
filename 2@ type ." :" line @ 0 .r ." : syntax error, wrong char:" |
|
getinput . cr |
|
print-error-line |
|
0 |
|
recover endtry |
|
r> to outfile-id throw |
abort |
abort |
endif |
endif |
rawinput @ endrawinput @ <> if |
rawinput @ endrawinput @ <> if |
Line 232 print-token !
|
Line 250 print-token !
|
1 chars cookedinput +! |
1 chars cookedinput +! |
nl-char = if |
nl-char = if |
checksyncline |
checksyncline |
|
rawinput @ line-start ! |
endif |
endif |
rawinput @ c@ cookedinput @ c! |
rawinput @ c@ cookedinput @ c! |
endif ; |
endif ; |
Line 343 warnings @ [IF]
|
Line 362 warnings @ [IF]
|
: primfilter ( file-id xt -- ) |
: primfilter ( file-id xt -- ) |
\ fileid is for the input file, xt ( -- ) is for the output word |
\ fileid is for the input file, xt ( -- ) is for the output word |
output ! |
output ! |
here dup rawinput ! cookedinput ! |
here dup rawinput ! dup line-start ! cookedinput ! |
here unused rot read-file throw |
here unused rot read-file throw |
dup here + endrawinput ! |
dup here + endrawinput ! |
allot |
allot |
Line 505 does> ( item -- )
|
Line 524 does> ( item -- )
|
: declaration ( item -- ) |
: declaration ( item -- ) |
dup item-name 2@ execute-prefix ; |
dup item-name 2@ execute-prefix ; |
|
|
|
: declaration-list ( addr1 addr2 -- ) |
|
['] declaration map-items ; |
|
|
|
: declarations ( -- ) |
|
wordlist dup items ! set-current |
|
effect-in effect-in-end @ declaration-list |
|
effect-out effect-out-end @ declaration-list ; |
|
|
: stack-prefix ( stack "prefix" -- ) |
: stack-prefix ( stack "prefix" -- ) |
name tuck nextname create ( stack length ) 2, |
name tuck nextname create ( stack length ) 2, |
does> ( item -- ) |
does> ( item -- ) |
Line 512 does> ( item -- )
|
Line 539 does> ( item -- )
|
item item-name 2@ prefix-length /string item item-name 2! |
item item-name 2@ prefix-length /string item item-name 2! |
stack item item-stack ! |
stack item item-stack ! |
item declaration ; |
item declaration ; |
|
|
: declaration-list ( addr1 addr2 -- ) |
|
swap ?do |
|
i declaration |
|
item% %size +loop ; |
|
|
|
: declarations ( -- ) |
|
wordlist dup items ! set-current |
|
effect-in effect-in-end @ declaration-list |
|
effect-out effect-out-end @ declaration-list ; |
|
|
|
\ offset computation |
\ offset computation |
\ the leftmost (i.e. deepest) item has offset 0 |
\ the leftmost (i.e. deepest) item has offset 0 |
Line 533 does> ( item -- )
|
Line 550 does> ( item -- )
|
item item-stack @ xt execute dup @ >r +! |
item item-stack @ xt execute dup @ >r +! |
r> item item-offset ! ; |
r> item item-offset ! ; |
|
|
: compute-list ( addr1 addr2 xt -- ) |
: compute-offset-in ( addr1 addr2 -- ) |
{ xt } |
['] stack-in compute-offset ; |
swap u+do |
|
i xt compute-offset |
: compute-offset-out ( addr1 addr2 -- ) |
item% %size +loop ; |
['] stack-out compute-offset ; |
|
|
: clear-stack { -- } |
: clear-stack { -- } |
dup stack-in off stack-out off ; |
dup stack-in off stack-out off ; |
Line 545 does> ( item -- )
|
Line 562 does> ( item -- )
|
: compute-offsets ( -- ) |
: compute-offsets ( -- ) |
data-stack clear-stack fp-stack clear-stack return-stack clear-stack |
data-stack clear-stack fp-stack clear-stack return-stack clear-stack |
inst-stream clear-stack |
inst-stream clear-stack |
effect-in effect-in-end @ ['] stack-in compute-list |
effect-in effect-in-end @ ['] compute-offset-in map-items |
effect-out effect-out-end @ ['] stack-out compute-list |
effect-out effect-out-end @ ['] compute-offset-out map-items |
inst-stream stack-out @ 0<> abort" # can only be on the input side" ; |
inst-stream stack-out @ 0<> abort" # can only be on the input side" ; |
|
|
: flush-a-tos { stack -- } |
: flush-a-tos { stack -- } |
Line 578 does> ( item -- )
|
Line 595 does> ( item -- )
|
dup item-type @ type-fetch @ execute ; |
dup item-type @ type-fetch @ execute ; |
|
|
: fetches ( -- ) |
: fetches ( -- ) |
effect-in-end @ effect-in ?do |
effect-in effect-in-end @ ['] fetch map-items ; |
i fetch |
|
item% %size +loop ; |
|
|
|
: stack-pointer-update { stack -- } |
: stack-pointer-update { stack -- } |
\ stack grow downwards |
\ stack grow downwards |
Line 606 does> ( item -- )
|
Line 621 does> ( item -- )
|
dup item-type @ type-store @ execute ; |
dup item-type @ type-store @ execute ; |
|
|
: stores ( -- ) |
: stores ( -- ) |
effect-out-end @ effect-out ?do |
effect-out effect-out-end @ ['] store map-items ; |
i store |
|
item% %size +loop ; |
|
|
|
: output-c-tail ( -- ) |
: output-c-tail ( -- ) |
\ the final part of the generated C code |
\ the final part of the generated C code |
Line 640 does> ( item -- )
|
Line 653 does> ( item -- )
|
: print-debug-args ( -- ) |
: print-debug-args ( -- ) |
." #ifdef VM_DEBUG" cr |
." #ifdef VM_DEBUG" cr |
." if (vm_debug) {" cr |
." if (vm_debug) {" cr |
effect-in-end @ effect-in ?do |
effect-in effect-in-end @ ['] print-debug-arg map-items |
i print-debug-arg |
|
item% %size +loop |
|
." fputc('\n', vm_out);" cr |
." fputc('\n', vm_out);" cr |
." }" cr |
." }" cr |
." #endif" cr ; |
." #endif" cr ; |
Line 678 does> ( item -- )
|
Line 689 does> ( item -- )
|
endif ; |
endif ; |
|
|
: disasm-args ( -- ) |
: disasm-args ( -- ) |
effect-in-end @ effect-in ?do |
effect-in effect-in-end @ ['] disasm-arg map-items ; |
i disasm-arg |
|
item% %size +loop ; |
|
|
|
: output-disasm ( -- ) |
: output-disasm ( -- ) |
\ generate code for disassembling VM instructions |
\ generate code for disassembling VM instructions |
Line 700 does> ( item -- )
|
Line 709 does> ( item -- )
|
endif ; |
endif ; |
|
|
: gen-args-parm ( -- ) |
: gen-args-parm ( -- ) |
effect-in-end @ effect-in ?do |
effect-in effect-in-end @ ['] gen-arg-parm map-items ; |
i gen-arg-parm |
|
item% %size +loop ; |
|
|
|
: gen-arg-gen { item -- } |
: gen-arg-gen { item -- } |
item item-stack @ inst-stream = if |
item item-stack @ inst-stream = if |
Line 711 does> ( item -- )
|
Line 718 does> ( item -- )
|
endif ; |
endif ; |
|
|
: gen-args-gen ( -- ) |
: gen-args-gen ( -- ) |
effect-in-end @ effect-in ?do |
effect-in effect-in-end @ ['] gen-arg-gen map-items ; |
i gen-arg-gen |
|
item% %size +loop ; |
|
|
|
: output-gen ( -- ) |
: output-gen ( -- ) |
\ generate C code for generating VM instructions |
\ generate C code for generating VM instructions |