--- gforth/prims2x.fs 2000/12/13 10:15:26 1.54 +++ gforth/prims2x.fs 2000/12/26 20:01:49 1.59 @@ -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 @@ -585,8 +586,13 @@ does> ( item -- ) stack stack-pointer 2@ type ." += " 0 .r ." ;" cr endif ; +: inst-pointer-update ( -- ) + inst-stream stack-in @ ?dup-if + ." INC_IP(" 0 .r ." );" cr + endif ; + : stack-pointer-updates ( -- ) - inst-stream stack-pointer-update + inst-pointer-update data-stack stack-pointer-update fp-stack stack-pointer-update return-stack stack-pointer-update ; @@ -641,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<> ;