| Variable forth-flag |
Variable forth-flag |
| Variable c-flag |
Variable c-flag |
| |
|
| |
(( (( ` e || ` E )) {{ start }} nonl ** |
| |
{{ end evaluate }} |
| |
)) <- eval-comment ( ... -- ... ) |
| |
|
| (( (( ` f || ` F )) {{ start }} nonl ** |
(( (( ` f || ` F )) {{ start }} nonl ** |
| {{ end forth-flag @ IF type cr ELSE 2drop THEN }} |
{{ end forth-flag @ IF type cr ELSE 2drop THEN }} |
| )) <- forth-comment ( -- ) |
)) <- forth-comment ( -- ) |
| THEN }} |
THEN }} |
| )) <- if-comment |
)) <- if-comment |
| |
|
| (( (( forth-comment || c-comment || else-comment || if-comment )) ?? nonl ** )) <- comment-body |
(( (( eval-comment || forth-comment || c-comment || else-comment || if-comment )) ?? nonl ** )) <- comment-body |
| |
|
| (( ` \ comment-body nl )) <- comment ( -- ) |
(( ` \ comment-body nl )) <- comment ( -- ) |
| |
|
| {{ effect-out }} stack-items {{ effect-out-end ! }} |
{{ effect-out }} stack-items {{ effect-out-end ! }} |
| )) <- stack-effect ( -- ) |
)) <- 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! }} |
(( {{ line @ name-line ! filename 2@ name-filename 2! }} |
| {{ start }} forth-ident {{ end 2dup forth-name 2! c-name 2! }} white ++ |
{{ start }} forth-ident {{ end 2dup forth-name 2! c-name 2! }} white ++ |
| ` ( white ** {{ start }} stack-effect {{ end stack-string 2! }} ` ) white ** |
` ( white ** {{ start }} stack-effect {{ end stack-string 2! }} ` ) white ** |
| {{ start }} forth-ident {{ end wordset 2! }} white ** |
(( {{ start }} forth-ident {{ end wordset 2! }} white ** |
| (( {{ start }} c-ident {{ end c-name 2! }} )) ?? nl |
(( {{ start }} c-ident {{ end c-name 2! }} )) ?? |
| |
)) ?? nl |
| )) |
)) |
| (( ` " ` " {{ start }} (( noquote ++ ` " )) ++ {{ end 1- doc 2! }} ` " nl )) ?? |
(( ` " ` " {{ start }} (( noquote ++ ` " )) ++ {{ end 1- doc 2! }} ` " white ** nl )) ?? |
| {{ skipsynclines off line @ c-line ! filename 2@ c-filename 2! start }} (( nocolonnl nonl ** nl )) ** {{ end c-code 2! skipsynclines on }} |
{{ skipsynclines off line @ c-line ! filename 2@ c-filename 2! start }} (( nocolonnl nonl ** nl white ** )) ** {{ end c-code 2! skipsynclines on }} |
| (( ` : nl |
(( ` : white ** nl |
| {{ start }} (( nonl ++ nl )) ++ {{ end forth-code 2! }} |
{{ start }} (( nonl ++ nl white ** )) ++ {{ end forth-code 2! }} |
| )) ?? {{ printprim }} |
)) ?? {{ printprim }} |
| (( nl || eof )) |
(( nl || eof )) |
| )) <- primitive ( -- ) |
)) <- primitive ( -- ) |
| |
|
| (( (( comment || primitive || nl )) ** eof )) |
(( (( comment || primitive || nl white ** )) ** eof )) |
| parser primitives2something |
parser primitives2something |
| warnings @ [IF] |
warnings @ [IF] |
| .( parser generated ok ) cr |
.( parser generated ok ) cr |
| >r |
>r |
| ." FETCH_DCELL(" |
." FETCH_DCELL(" |
| r@ item-name 2@ type ." , " |
r@ item-name 2@ type ." , " |
| r@ item-in-index r@ item-stack @ 2dup stack-access |
r@ item-in-index r@ item-stack @ 2dup ." (Cell)" stack-access |
| ." , " -1 under+ stack-access |
." , " -1 under+ ." (Cell)" stack-access |
| ." );" cr |
." );" cr |
| rdrop ; |
rdrop ; |
| |
|
| ." );" cr |
." );" cr |
| rdrop ; |
rdrop ; |
| |
|
| |
: single ( -- xt1 xt2 n ) |
| |
['] fetch-single ['] store-single 1 ; |
| |
|
| : single-type ( -- xt1 xt2 n stack ) |
: double ( -- xt1 xt2 n ) |
| ['] fetch-single ['] store-single 1 data-stack ; |
['] fetch-double ['] store-double 2 ; |
| |
|
| : double-type ( -- xt1 xt2 n stack ) |
|
| ['] fetch-double ['] store-double 2 data-stack ; |
|
| |
|
| : float-type ( -- xt1 xt2 n stack ) |
|
| ['] fetch-single ['] store-single 1 fp-stack ; |
|
| |
|
| : s, ( addr u -- ) |
: s, ( addr u -- ) |
| \ allocate a string |
\ allocate a string |
| stack r@ type-stack ! |
stack r@ type-stack ! |
| rdrop ; |
rdrop ; |
| |
|
| : type-prefix ( addr u xt1 xt2 n stack "prefix" -- ) |
: type-prefix ( xt1 xt2 n stack "prefix" -- ) |
| create-type |
create-type |
| does> ( item -- ) |
does> ( item -- ) |
| \ initialize item |
\ initialize item |
| effect-in effect-in-end @ declaration-list |
effect-in effect-in-end @ declaration-list |
| effect-out effect-out-end @ declaration-list ; |
effect-out effect-out-end @ declaration-list ; |
| |
|
| get-current |
|
| prefixes set-current |
|
| |
|
| s" Bool" single-type type-prefix f |
|
| s" Char" single-type type-prefix c |
|
| s" Cell" single-type type-prefix n |
|
| s" Cell" single-type type-prefix w |
|
| s" UCell" single-type type-prefix u |
|
| s" DCell" double-type type-prefix d |
|
| s" UDCell" double-type type-prefix ud |
|
| s" Float" float-type type-prefix r |
|
| s" Cell *" single-type type-prefix a_ |
|
| s" Char *" single-type type-prefix c_ |
|
| s" Float *" single-type type-prefix f_ |
|
| s" DFloat *" single-type type-prefix df_ |
|
| s" SFloat *" single-type type-prefix sf_ |
|
| s" Xt" single-type type-prefix xt |
|
| s" WID" single-type type-prefix wid |
|
| s" struct F83Name *" single-type type-prefix f83name |
|
| |
|
| return-stack stack-prefix R: |
|
| inst-stream stack-prefix # |
|
| |
|
| set-current |
|
| |
|
| \ offset computation |
\ offset computation |
| \ the leftmost (i.e. deepest) item has offset 0 |
\ the leftmost (i.e. deepest) item has offset 0 |
| \ the rightmost item has the highest offset |
\ the rightmost item has the highest offset |
| stack stack-pointer 2@ type ." += " 0 .r ." ;" cr |
stack stack-pointer 2@ type ." += " 0 .r ." ;" cr |
| endif ; |
endif ; |
| |
|
| |
: inst-pointer-update ( -- ) |
| |
inst-stream stack-in @ ?dup-if |
| |
." INC_IP(" 0 .r ." );" cr |
| |
endif ; |
| |
|
| : stack-pointer-updates ( -- ) |
: stack-pointer-updates ( -- ) |
| inst-stream stack-pointer-update |
inst-pointer-update |
| data-stack stack-pointer-update |
data-stack stack-pointer-update |
| fp-stack stack-pointer-update |
fp-stack stack-pointer-update |
| return-stack stack-pointer-update ; |
return-stack stack-pointer-update ; |
| cr |
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-used? { stack -- f } |
| stack stack-in @ stack stack-out @ or 0<> ; |
stack stack-in @ stack stack-out @ or 0<> ; |
| |
|
| |
|
| : process-file ( addr u xt -- ) |
: process-file ( addr u xt -- ) |
| >r |
>r |
| 2dup filename 2! |
save-mem 2dup filename 2! |
| 0 function-number ! |
0 function-number ! |
| r/o open-file abort" cannot open file" |
r/o open-file abort" cannot open file" |
| warnings @ if |
warnings @ if |