version 1.65, 2001/01/18 14:57:37
|
version 1.68, 2001/01/18 19:43:02
|
Line 104 struct%
|
Line 104 struct%
|
cell% field item-stack \ descriptor for the stack used, 0 is default |
cell% field item-stack \ descriptor for the stack used, 0 is default |
cell% field item-type \ descriptor for the item type |
cell% field item-type \ descriptor for the item type |
cell% field item-offset \ offset in stack items, 0 for the deepest element |
cell% field item-offset \ offset in stack items, 0 for the deepest element |
|
cell% field item-first \ true if this is the first occurence of the item |
end-struct item% |
end-struct item% |
|
|
struct% |
struct% |
Line 166 variable name-line
|
Line 167 variable name-line
|
2variable name-filename |
2variable name-filename |
2variable last-name-filename |
2variable last-name-filename |
|
|
variable primitive-number -10 primitive-number ! |
|
Variable function-number 0 function-number ! |
Variable function-number 0 function-number ! |
|
|
\ for several reasons stack items of a word are stored in a wordlist |
\ for several reasons stack items of a word are stored in a wordlist |
Line 182 variable items
|
Line 182 variable items
|
: complement ( set1 -- set2 ) |
: complement ( set1 -- set2 ) |
empty ['] bit-equivalent binary-set-operation ; |
empty ['] bit-equivalent binary-set-operation ; |
|
|
\ the parser |
|
|
|
eof-char max-member \ the whole character set + EOF |
|
|
|
: getinput ( -- n ) |
|
rawinput @ endrawinput @ = |
|
if |
|
eof-char |
|
else |
|
cookedinput @ c@ |
|
endif ; |
|
|
|
:noname ( n -- ) |
|
dup bl > if |
|
emit space |
|
else |
|
. |
|
endif ; |
|
print-token ! |
|
|
|
: testchar? ( set -- f ) |
|
getinput member? ; |
|
' testchar? test-vector ! |
|
|
|
: checksyncline ( -- ) |
|
\ when input points to a newline, check if the next line is a |
|
\ sync line. If it is, perform the appropriate actions. |
|
rawinput @ >r |
|
s" #line " r@ over compare 0<> if |
|
rdrop 1 line +! EXIT |
|
endif |
|
0. r> 6 chars + 20 >number drop >r drop line ! r> ( c-addr ) |
|
dup c@ bl = if |
|
char+ dup c@ [char] " <> abort" sync line syntax" |
|
char+ dup 100 [char] " scan drop swap 2dup - save-mem filename 2! |
|
char+ |
|
endif |
|
dup c@ nl-char <> abort" sync line syntax" |
|
skipsynclines @ if |
|
dup char+ rawinput ! |
|
rawinput @ c@ cookedinput @ c! |
|
endif |
|
drop ; |
|
|
|
: print-error-line ( -- ) |
|
\ print the current line and position |
|
line-start @ endrawinput @ over - 2dup nl-char scan drop nip ( start end ) |
|
over - type cr |
|
line-start @ rawinput @ over - typewhite ." ^" cr ; |
|
|
|
: ?nextchar ( f -- ) |
|
?not? if |
|
outfile-id >r try |
|
stderr to outfile-id |
|
filename 2@ type ." :" line @ 0 .r ." : syntax error, wrong char:" |
|
getinput . cr |
|
print-error-line |
|
0 |
|
recover endtry |
|
r> to outfile-id throw |
|
abort |
|
endif |
|
rawinput @ endrawinput @ <> if |
|
rawinput @ c@ |
|
1 chars rawinput +! |
|
1 chars cookedinput +! |
|
nl-char = if |
|
checksyncline |
|
rawinput @ line-start ! |
|
endif |
|
rawinput @ c@ cookedinput @ c! |
|
endif ; |
|
|
|
: charclass ( set "name" -- ) |
|
['] ?nextchar terminal ; |
|
|
|
: .. ( c1 c2 -- set ) |
|
( creates a set that includes the characters c, c1<=c<=c2 ) |
|
empty copy-set |
|
swap 1+ rot do |
|
i over add-member |
|
loop ; |
|
|
|
: ` ( -- terminal ) ( use: ` c ) |
|
( creates anonymous terminal for the character c ) |
|
char singleton ['] ?nextchar make-terminal ; |
|
|
|
char a char z .. char A char Z .. union char _ singleton union charclass letter |
|
char 0 char 9 .. charclass digit |
|
bl singleton tab-char over add-member charclass white |
|
nl-char singleton eof-char over add-member complement charclass nonl |
|
nl-char singleton eof-char over add-member |
|
char : over add-member complement charclass nocolonnl |
|
bl 1+ maxchar .. char \ singleton complement intersection |
|
charclass nowhitebq |
|
bl 1+ maxchar .. charclass nowhite |
|
char " singleton eof-char over add-member complement charclass noquote |
|
nl-char singleton charclass nl |
|
eof-char singleton charclass eof |
|
|
|
|
|
(( letter (( letter || digit )) ** |
|
)) <- c-ident ( -- ) |
|
|
|
(( ` # ?? (( letter || digit || ` : )) ** |
|
)) <- stack-ident ( -- ) |
|
|
|
(( nowhitebq nowhite ** )) |
|
<- forth-ident ( -- ) |
|
|
|
Variable forth-flag |
|
Variable c-flag |
|
|
|
(( (( ` e || ` E )) {{ start }} nonl ** |
|
{{ end evaluate }} |
|
)) <- eval-comment ( ... -- ... ) |
|
|
|
(( (( ` f || ` F )) {{ start }} nonl ** |
|
{{ end forth-flag @ IF type cr ELSE 2drop THEN }} |
|
)) <- forth-comment ( -- ) |
|
|
|
(( (( ` c || ` C )) {{ start }} nonl ** |
|
{{ end c-flag @ IF type cr ELSE 2drop THEN }} |
|
)) <- c-comment ( -- ) |
|
|
|
(( ` - nonl ** {{ |
|
forth-flag @ IF ." [ELSE]" cr THEN |
|
c-flag @ IF ." #else" cr THEN }} |
|
)) <- else-comment |
|
|
|
(( ` + {{ start }} nonl ** {{ end |
|
dup |
|
IF c-flag @ |
|
IF ." #ifdef HAS_" bounds ?DO I c@ toupper emit LOOP cr |
|
THEN |
|
forth-flag @ |
|
IF ." has? " type ." [IF]" cr THEN |
|
ELSE 2drop |
|
c-flag @ IF ." #endif" cr THEN |
|
forth-flag @ IF ." [THEN]" cr THEN |
|
THEN }} |
|
)) <- if-comment |
|
|
|
(( (( eval-comment || forth-comment || c-comment || else-comment || if-comment )) ?? nonl ** )) <- comment-body |
|
|
|
(( ` \ comment-body nl )) <- comment ( -- ) |
|
|
|
(( {{ start }} stack-ident {{ end 2 pick init-item item% %size + }} white ** )) ** |
|
<- stack-items |
|
|
|
(( {{ effect-in }} stack-items {{ effect-in-end ! }} |
|
` - ` - white ** |
|
{{ effect-out }} stack-items {{ effect-out-end ! }} |
|
)) <- stack-effect ( -- ) |
|
|
|
(( {{ 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 }} (( 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 white ** )) ** eof )) |
|
parser primitives2something |
|
warnings @ [IF] |
|
.( parser generated ok ) cr |
|
[THEN] |
|
|
|
: primfilter ( file-id xt -- ) |
|
\ fileid is for the input file, xt ( -- ) is for the output word |
|
output ! |
|
here dup rawinput ! dup line-start ! cookedinput ! |
|
here unused rot read-file throw |
|
dup here + endrawinput ! |
|
allot |
|
align |
|
checksyncline |
|
\ begin |
|
\ getinput dup eof-char = ?EXIT emit true ?nextchar |
|
\ again ; |
|
primitives2something ; |
|
|
|
\ types |
\ types |
|
|
: stack-access ( n stack -- ) |
: stack-access ( n stack -- ) |
Line 502 does> ( item -- )
|
Line 311 does> ( item -- )
|
typ item item-type ! |
typ item item-type ! |
typ type-stack @ item item-stack !default |
typ type-stack @ item item-stack !default |
item item-name 2@ items @ search-wordlist 0= if \ new name |
item item-name 2@ items @ search-wordlist 0= if \ new name |
item item-name 2@ 2dup nextname item declare |
item item-name 2@ nextname item declare |
typ type-c-name 2@ type space type ." ;" cr |
item item-first on |
|
\ typ type-c-name 2@ type space type ." ;" cr |
else |
else |
drop |
drop |
|
item item-first off |
endif ; |
endif ; |
|
|
: execute-prefix ( item addr1 u1 -- ) |
: execute-prefix ( item addr1 u1 -- ) |
Line 532 does> ( item -- )
|
Line 343 does> ( 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 ; |
|
|
|
: print-declaration { item -- } |
|
item item-first @ if |
|
item item-type @ type-c-name 2@ type space |
|
item item-name 2@ type ." ;" cr |
|
endif ; |
|
|
|
: print-declarations ( -- ) |
|
effect-in effect-in-end @ ['] print-declaration map-items |
|
effect-out effect-out-end @ ['] print-declaration map-items ; |
|
|
: stack-prefix ( stack "prefix" -- ) |
: stack-prefix ( stack "prefix" -- ) |
name tuck nextname create ( stack length ) 2, |
name tuck nextname create ( stack length ) 2, |
does> ( item -- ) |
does> ( item -- ) |
Line 664 does> ( item -- )
|
Line 485 does> ( item -- )
|
." NAME(" quote forth-name 2@ type quote ." )" cr \ debugging |
." NAME(" quote forth-name 2@ type quote ." )" cr \ debugging |
." {" cr |
." {" cr |
." DEF_CA" cr |
." DEF_CA" cr |
declarations |
print-declarations |
compute-offsets \ for everything else |
|
." NEXT_P0;" cr |
." NEXT_P0;" cr |
flush-tos |
flush-tos |
fetches |
fetches |
Line 695 does> ( item -- )
|
Line 515 does> ( item -- )
|
\ 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(" quote forth-name 2@ type quote ." , vm_out);" cr |
." fputs(" quote forth-name 2@ type quote ." , vm_out);" cr |
." /* " declarations ." */" cr |
|
compute-offsets |
|
disasm-args |
disasm-args |
." ip += " inst-stream stack-in @ 1+ 0 .r ." ;" cr |
." ip += " inst-stream stack-in @ 1+ 0 .r ." ;" cr |
." } else " |
." } else " ; |
1 function-number +! ; |
|
|
|
: gen-arg-parm { item -- } |
: gen-arg-parm { item -- } |
item item-stack @ inst-stream = if |
item item-stack @ inst-stream = if |
Line 722 does> ( item -- )
|
Line 539 does> ( item -- )
|
|
|
: output-gen ( -- ) |
: output-gen ( -- ) |
\ generate C code for generating VM instructions |
\ generate C code for generating VM instructions |
." /* " declarations ." */" cr |
|
compute-offsets |
|
." void gen_" c-name 2@ type ." (Inst **ctp" gen-args-parm ." )" cr |
." void gen_" c-name 2@ type ." (Inst **ctp" gen-args-parm ." )" cr |
." {" cr |
." {" cr |
." gen_inst(ctp, vm_prim[" function-number @ 0 .r ." ]);" cr |
." gen_inst(ctp, vm_prim[" function-number @ 0 .r ." ]);" cr |
gen-args-gen |
gen-args-gen |
." }" cr |
." }" 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<> ; |
|
|
: output-funclabel ( -- ) |
: output-funclabel ( -- ) |
1 function-number +! |
|
." &I_" c-name 2@ type ." ," cr ; |
." &I_" c-name 2@ type ." ," cr ; |
|
|
: output-forthname ( -- ) |
: output-forthname ( -- ) |
1 function-number +! |
|
'" emit forth-name 2@ type '" emit ." ," cr ; |
'" emit forth-name 2@ type '" emit ." ," cr ; |
|
|
: output-c-func ( -- ) |
: output-c-func ( -- ) |
\ used for word libraries |
\ used for word libraries |
1 function-number +! |
|
." 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(" quote forth-name 2@ type quote ." )" cr |
." NAME(" quote forth-name 2@ type quote ." )" cr |
\ debugging |
\ debugging |
." {" cr |
." {" cr |
declarations |
print-declarations |
compute-offsets \ for everything else |
|
inst-stream stack-used? IF ." Cell *ip=IP;" cr THEN |
inst-stream stack-used? IF ." Cell *ip=IP;" cr THEN |
data-stack stack-used? IF ." Cell *sp=SP;" cr THEN |
data-stack stack-used? IF ." Cell *sp=SP;" cr THEN |
fp-stack stack-used? IF ." Cell *fp=*FP;" cr THEN |
fp-stack stack-used? IF ." Cell *fp=*FP;" cr THEN |
Line 772 does> ( item -- )
|
Line 582 does> ( item -- )
|
cr ; |
cr ; |
|
|
: output-label ( -- ) |
: output-label ( -- ) |
." (Label)&&I_" c-name 2@ type ." ," cr |
." (Label)&&I_" c-name 2@ type ." ," cr ; |
-1 primitive-number +! ; |
|
|
|
: output-alias ( -- ) |
: output-alias ( -- ) |
( primitive-number @ . ." alias " ) ." Primitive " forth-name 2@ type cr |
( primitive-number @ . ." alias " ) ." Primitive " forth-name 2@ type cr ; |
-1 primitive-number +! ; |
|
|
|
: output-forth ( -- ) |
: output-forth ( -- ) |
forth-code @ 0= |
forth-code @ 0= |
Line 787 does> ( item -- )
|
Line 595 does> ( item -- )
|
ELSE ." : " forth-name 2@ type ." ( " |
ELSE ." : " forth-name 2@ type ." ( " |
stack-string 2@ type ." )" cr |
stack-string 2@ type ." )" cr |
forth-code 2@ type cr |
forth-code 2@ type cr |
-1 primitive-number +! |
|
THEN ; |
THEN ; |
|
|
: output-tag-file ( -- ) |
: output-tag-file ( -- ) |
Line 819 does> ( item -- )
|
Line 626 does> ( item -- )
|
set-current ; |
set-current ; |
[THEN] |
[THEN] |
|
|
|
|
|
\ the parser |
|
|
|
eof-char max-member \ the whole character set + EOF |
|
|
|
: getinput ( -- n ) |
|
rawinput @ endrawinput @ = |
|
if |
|
eof-char |
|
else |
|
cookedinput @ c@ |
|
endif ; |
|
|
|
:noname ( n -- ) |
|
dup bl > if |
|
emit space |
|
else |
|
. |
|
endif ; |
|
print-token ! |
|
|
|
: testchar? ( set -- f ) |
|
getinput member? ; |
|
' testchar? test-vector ! |
|
|
|
: checksyncline ( -- ) |
|
\ when input points to a newline, check if the next line is a |
|
\ sync line. If it is, perform the appropriate actions. |
|
rawinput @ >r |
|
s" #line " r@ over compare 0<> if |
|
rdrop 1 line +! EXIT |
|
endif |
|
0. r> 6 chars + 20 >number drop >r drop line ! r> ( c-addr ) |
|
dup c@ bl = if |
|
char+ dup c@ [char] " <> abort" sync line syntax" |
|
char+ dup 100 [char] " scan drop swap 2dup - save-mem filename 2! |
|
char+ |
|
endif |
|
dup c@ nl-char <> abort" sync line syntax" |
|
skipsynclines @ if |
|
dup char+ rawinput ! |
|
rawinput @ c@ cookedinput @ c! |
|
endif |
|
drop ; |
|
|
|
: print-error-line ( -- ) |
|
\ print the current line and position |
|
line-start @ endrawinput @ over - 2dup nl-char scan drop nip ( start end ) |
|
over - type cr |
|
line-start @ rawinput @ over - typewhite ." ^" cr ; |
|
|
|
: ?nextchar ( f -- ) |
|
?not? if |
|
outfile-id >r try |
|
stderr to outfile-id |
|
filename 2@ type ." :" line @ 0 .r ." : syntax error, wrong char:" |
|
getinput . cr |
|
print-error-line |
|
0 |
|
recover endtry |
|
r> to outfile-id throw |
|
abort |
|
endif |
|
rawinput @ endrawinput @ <> if |
|
rawinput @ c@ |
|
1 chars rawinput +! |
|
1 chars cookedinput +! |
|
nl-char = if |
|
checksyncline |
|
rawinput @ line-start ! |
|
endif |
|
rawinput @ c@ cookedinput @ c! |
|
endif ; |
|
|
|
: charclass ( set "name" -- ) |
|
['] ?nextchar terminal ; |
|
|
|
: .. ( c1 c2 -- set ) |
|
( creates a set that includes the characters c, c1<=c<=c2 ) |
|
empty copy-set |
|
swap 1+ rot do |
|
i over add-member |
|
loop ; |
|
|
|
: ` ( -- terminal ) ( use: ` c ) |
|
( creates anonymous terminal for the character c ) |
|
char singleton ['] ?nextchar make-terminal ; |
|
|
|
char a char z .. char A char Z .. union char _ singleton union charclass letter |
|
char 0 char 9 .. charclass digit |
|
bl singleton tab-char over add-member charclass white |
|
nl-char singleton eof-char over add-member complement charclass nonl |
|
nl-char singleton eof-char over add-member |
|
char : over add-member complement charclass nocolonnl |
|
bl 1+ maxchar .. char \ singleton complement intersection |
|
charclass nowhitebq |
|
bl 1+ maxchar .. charclass nowhite |
|
char " singleton eof-char over add-member complement charclass noquote |
|
nl-char singleton charclass nl |
|
eof-char singleton charclass eof |
|
|
|
|
|
(( letter (( letter || digit )) ** |
|
)) <- c-ident ( -- ) |
|
|
|
(( ` # ?? (( letter || digit || ` : )) ** |
|
)) <- stack-ident ( -- ) |
|
|
|
(( nowhitebq nowhite ** )) |
|
<- forth-ident ( -- ) |
|
|
|
Variable forth-flag |
|
Variable c-flag |
|
|
|
(( (( ` e || ` E )) {{ start }} nonl ** |
|
{{ end evaluate }} |
|
)) <- eval-comment ( ... -- ... ) |
|
|
|
(( (( ` f || ` F )) {{ start }} nonl ** |
|
{{ end forth-flag @ IF type cr ELSE 2drop THEN }} |
|
)) <- forth-comment ( -- ) |
|
|
|
(( (( ` c || ` C )) {{ start }} nonl ** |
|
{{ end c-flag @ IF type cr ELSE 2drop THEN }} |
|
)) <- c-comment ( -- ) |
|
|
|
(( ` - nonl ** {{ |
|
forth-flag @ IF ." [ELSE]" cr THEN |
|
c-flag @ IF ." #else" cr THEN }} |
|
)) <- else-comment |
|
|
|
(( ` + {{ start }} nonl ** {{ end |
|
dup |
|
IF c-flag @ |
|
IF ." #ifdef HAS_" bounds ?DO I c@ toupper emit LOOP cr |
|
THEN |
|
forth-flag @ |
|
IF ." has? " type ." [IF]" cr THEN |
|
ELSE 2drop |
|
c-flag @ IF ." #endif" cr THEN |
|
forth-flag @ IF ." [THEN]" cr THEN |
|
THEN }} |
|
)) <- if-comment |
|
|
|
(( (( eval-comment || forth-comment || c-comment || else-comment || if-comment )) ?? nonl ** )) <- comment-body |
|
|
|
(( ` \ comment-body nl )) <- comment ( -- ) |
|
|
|
(( {{ start }} stack-ident {{ end 2 pick init-item item% %size + }} white ** )) ** |
|
<- stack-items |
|
|
|
(( {{ effect-in }} stack-items {{ effect-in-end ! }} |
|
` - ` - white ** |
|
{{ effect-out }} stack-items {{ effect-out-end ! }} |
|
)) <- stack-effect ( -- ) |
|
|
|
(( {{ 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 }} (( 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! }} |
|
)) ?? {{ declarations compute-offsets printprim 1 function-number +! }} |
|
(( nl || eof )) |
|
)) <- primitive ( -- ) |
|
|
|
(( (( comment || primitive || nl white ** )) ** eof )) |
|
parser primitives2something |
|
warnings @ [IF] |
|
.( parser generated ok ) cr |
|
[THEN] |
|
|
|
: primfilter ( file-id xt -- ) |
|
\ fileid is for the input file, xt ( -- ) is for the output word |
|
output ! |
|
here dup rawinput ! dup line-start ! cookedinput ! |
|
here unused rot read-file throw |
|
dup here + endrawinput ! |
|
allot |
|
align |
|
checksyncline |
|
\ begin |
|
\ getinput dup eof-char = ?EXIT emit true ?nextchar |
|
\ again ; |
|
primitives2something ; |
|
|
: process-file ( addr u xt -- ) |
: process-file ( addr u xt -- ) |
>r |
>r |
save-mem 2dup filename 2! |
save-mem 2dup filename 2! |