| : end ( addr -- addr u ) |
: end ( addr -- addr u ) |
| cookedinput @ over - ; |
cookedinput @ over - ; |
| |
|
| |
: quote ( -- ) |
| |
[char] " emit ; |
| |
|
| variable output \ xt ( -- ) of output word |
variable output \ xt ( -- ) of output word |
| |
|
| : printprim ( -- ) |
: printprim ( -- ) |
| repeat |
repeat |
| 2drop type ; |
2drop type ; |
| |
|
| |
: print-type-prefix ( type -- ) |
| |
body> >head .name ; |
| |
|
| |
: print-debug-arg { item -- } |
| |
." fputs(" quote space item item-name 2@ type ." =" quote ." , vm_out); " |
| |
." printarg_" item item-type @ print-type-prefix |
| |
." (" item item-name 2@ type ." );" cr ; |
| |
|
| |
: print-debug-args ( -- ) |
| |
." #ifdef VM_DEBUG" cr |
| |
." if (vm_debug) {" cr |
| |
effect-in-end @ effect-in ?do |
| |
i print-debug-arg |
| |
item% %size +loop |
| |
." fputc('\n', vm_out);" cr |
| |
." }" cr |
| |
." #endif" cr ; |
| |
|
| : output-c ( -- ) |
: output-c ( -- ) |
| ." I_" c-name 2@ type ." : /* " forth-name 2@ type ." ( " stack-string 2@ type ." ) */" cr |
." I_" c-name 2@ type ." : /* " forth-name 2@ type ." ( " stack-string 2@ type ." ) */" cr |
| ." /* " doc 2@ type ." */" cr |
." /* " doc 2@ type ." */" cr |
| ." NAME(" [char] " emit forth-name 2@ type [char] " emit ." )" cr \ debugging |
." NAME(" quote forth-name 2@ type quote ." )" cr \ debugging |
| ." {" cr |
." {" cr |
| ." DEF_CA" cr |
." DEF_CA" cr |
| declarations |
declarations |
| ." NEXT_P0;" cr |
." NEXT_P0;" cr |
| flush-tos |
flush-tos |
| fetches |
fetches |
| |
print-debug-args |
| stack-pointer-updates |
stack-pointer-updates |
| ." {" cr |
." {" cr |
| ." #line " c-line @ . [char] " emit c-filename 2@ type [char] " emit cr |
." #line " c-line @ . quote c-filename 2@ type quote cr |
| c-code 2@ type-c |
c-code 2@ type-c |
| ." }" cr |
." }" cr |
| output-c-tail |
output-c-tail |
| cr |
cr |
| ; |
; |
| |
|
| : print-type-prefix ( type -- ) |
|
| body> >head .name ; |
|
| |
|
| : disasm-arg { item -- } |
: disasm-arg { item -- } |
| item item-stack @ inst-stream = if |
item item-stack @ inst-stream = if |
| |
." fputc(' ', vm_out); " |
| ." printarg_" item item-type @ print-type-prefix |
." printarg_" item item-type @ print-type-prefix |
| ." (ip[" item item-offset @ 1+ 0 .r ." ]);" cr |
." ((" item item-type @ type-c-name 2@ type ." )" |
| |
." ip[" item item-offset @ 1+ 0 .r ." ]);" cr |
| endif ; |
endif ; |
| |
|
| : disasm-args ( -- ) |
: disasm-args ( -- ) |
| : output-disasm ( -- ) |
: output-disasm ( -- ) |
| \ generate code for disassembling VM instructions |
\ generate code for disassembling VM instructions |
| ." if (ip[0] == prim[" function-number @ 0 .r ." ]) {" cr |
." if (ip[0] == prim[" function-number @ 0 .r ." ]) {" cr |
| ." fputs(" [char] " emit forth-name 2@ type [char] " emit ." ,stdout);" cr |
." fputs(" quote forth-name 2@ type quote ." , vm_out);" cr |
| ." /* " declarations ." */" cr |
." /* " declarations ." */" cr |
| compute-offsets |
compute-offsets |
| disasm-args |
disasm-args |
| ." } else " |
." } else " |
| 1 function-number +! ; |
1 function-number +! ; |
| |
|
| |
|
| |
|
| |
|
| : gen-arg-parm { item -- } |
: gen-arg-parm { item -- } |
| item item-stack @ inst-stream = if |
item item-stack @ inst-stream = if |
| ." , " item item-type @ type-c-name 2@ type space |
." , " item item-type @ type-c-name 2@ type space |
| ." Cell * I_" c-name 2@ type ." (Cell *SP, Cell **FP) /* " forth-name 2@ type |
." Cell * I_" c-name 2@ type ." (Cell *SP, Cell **FP) /* " forth-name 2@ type |
| ." ( " stack-string 2@ type ." ) */" cr |
." ( " stack-string 2@ type ." ) */" cr |
| ." /* " doc 2@ type ." */" cr |
." /* " doc 2@ type ." */" cr |
| ." NAME(" [char] " emit forth-name 2@ type [char] " emit ." )" cr |
." NAME(" quote forth-name 2@ type quote ." )" cr |
| \ debugging |
\ debugging |
| ." {" cr |
." {" cr |
| declarations |
declarations |
| stack-pointer-updates |
stack-pointer-updates |
| fp-stack stack-used? IF ." *FP=fp;" cr THEN |
fp-stack stack-used? IF ." *FP=fp;" cr THEN |
| ." {" cr |
." {" cr |
| ." #line " c-line @ . [char] " emit c-filename 2@ type [char] " emit cr |
." #line " c-line @ . quote c-filename 2@ type quote cr |
| c-code 2@ type |
c-code 2@ type |
| ." }" cr |
." }" cr |
| stores |
stores |