--- gforth/prims2x.fs 2000/12/24 15:54:18 1.55 +++ gforth/prims2x.fs 2001/01/04 15:35:08 1.61 @@ -315,22 +315,23 @@ Variable c-flag {{ effect-out }} stack-items {{ effect-out-end ! }} )) <- stack-effect ( -- ) -(( {{ s" " doc 2! s" " forth-code 2! }} +(( {{ s" " doc 2! s" " forth-code 2! s" " wordset 2! }} (( {{ line @ name-line ! filename 2@ name-filename 2! }} {{ start }} forth-ident {{ end 2dup forth-name 2! c-name 2! }} white ++ ` ( white ** {{ start }} stack-effect {{ end stack-string 2! }} ` ) white ** - {{ start }} forth-ident {{ end wordset 2! }} white ** - (( {{ start }} c-ident {{ end c-name 2! }} )) ?? nl + (( {{ start }} forth-ident {{ end wordset 2! }} white ** + (( {{ start }} c-ident {{ end c-name 2! }} )) ?? + )) ?? nl )) - (( ` " ` " {{ start }} (( noquote ++ ` " )) ++ {{ end 1- doc 2! }} ` " nl )) ?? - {{ skipsynclines off line @ c-line ! filename 2@ c-filename 2! start }} (( nocolonnl nonl ** nl )) ** {{ end c-code 2! skipsynclines on }} - (( ` : nl - {{ start }} (( nonl ++ nl )) ++ {{ end forth-code 2! }} + (( ` " ` " {{ start }} (( noquote ++ ` " )) ++ {{ end 1- doc 2! }} ` " white ** nl )) ?? + {{ skipsynclines off line @ c-line ! filename 2@ c-filename 2! start }} (( nocolonnl nonl ** nl white ** )) ** {{ end c-code 2! skipsynclines on }} + (( ` : white ** nl + {{ start }} (( nonl ++ nl white ** )) ++ {{ end forth-code 2! }} )) ?? {{ printprim }} (( nl || eof )) )) <- primitive ( -- ) -(( (( comment || primitive || nl )) ** eof )) +(( (( comment || primitive || nl white ** )) ** eof )) parser primitives2something warnings @ [IF] .( parser generated ok ) cr @@ -382,8 +383,8 @@ warnings @ [IF] >r ." FETCH_DCELL(" r@ item-name 2@ type ." , " - r@ item-in-index r@ item-stack @ 2dup stack-access - ." , " -1 under+ stack-access + r@ item-in-index r@ item-stack @ 2dup ." (Cell)" stack-access + ." , " -1 under+ ." (Cell)" stack-access ." );" cr rdrop ; @@ -646,6 +647,67 @@ does> ( item -- ) cr ; +: print-type-prefix ( type -- ) + body> >head .name ; + +: disasm-arg { item -- } + item item-stack @ inst-stream = if + ." printarg_" item item-type @ print-type-prefix + ." (ip[" item item-offset @ 1+ 0 .r ." ]);" cr + endif ; + +: disasm-args ( -- ) + effect-in-end @ effect-in ?do + i disasm-arg + item% %size +loop ; + +: output-disasm ( -- ) + \ generate code for disassembling VM instructions + ." if (ip[0] == prim[" function-number @ 0 .r ." ]) {" cr + ." fputs(" [char] " emit forth-name 2@ type [char] " emit ." ,stdout);" cr + ." /* " declarations ." */" cr + compute-offsets + disasm-args + ." ip += " inst-stream stack-in @ 1+ 0 .r ." ;" cr + ." } else " + 1 function-number +! ; + + + + +: gen-arg-parm { item -- } + item item-stack @ inst-stream = if + ." , " item item-type @ type-c-name 2@ type space + item item-name 2@ type + endif ; + +: gen-args-parm ( -- ) + effect-in-end @ effect-in ?do + i gen-arg-parm + item% %size +loop ; + +: gen-arg-gen { item -- } + item item-stack @ inst-stream = if + ." genarg_" item item-type @ print-type-prefix + ." (ctp, " item item-name 2@ type ." );" cr + endif ; + +: gen-args-gen ( -- ) + effect-in-end @ effect-in ?do + i gen-arg-gen + item% %size +loop ; + +: output-gen ( -- ) + \ generate C code for generating VM instructions + ." /* " declarations ." */" cr + compute-offsets + ." void gen_" c-name 2@ type ." (Inst **ctp" gen-args-parm ." )" cr + ." {" cr + ." gen_inst(ctp, vm_prim[" function-number @ 0 .r ." ]);" cr + gen-args-gen + ." }" cr + 1 function-number +! ; + : stack-used? { stack -- f } stack stack-in @ stack stack-out @ or 0<> ; @@ -736,7 +798,7 @@ does> ( item -- ) : process-file ( addr u xt -- ) >r - 2dup filename 2! + save-mem 2dup filename 2! 0 function-number ! r/o open-file abort" cannot open file" warnings @ if