--- gforth/prims2x.fs 2000/12/24 15:54:18 1.55 +++ gforth/prims2x.fs 2000/12/26 19:31:56 1.57 @@ -315,12 +315,13 @@ 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 }} @@ -646,6 +647,31 @@ 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 +! ; + : stack-used? { stack -- f } stack stack-in @ stack stack-out @ or 0<> ;