51 lines
1.3 KiB
Plaintext
Executable file
51 lines
1.3 KiB
Plaintext
Executable file
2 const cell
|
|
: cells cell * ;
|
|
|
|
key ) const ')'
|
|
|
|
10 const '\n'
|
|
key const sp
|
|
|
|
128 const F_IMMEDIATE
|
|
|
|
: cr '\n' emit ;
|
|
: bl sp emit ;
|
|
|
|
: if ' BZ_ , here 0 , ; immediate
|
|
: else ' GOTO_ , 0 , here swap ! here cell - ; immediate
|
|
: then here swap ! ; immediate
|
|
|
|
: begin here ; immediate
|
|
: while ' BZ_ , here 0 , ; immediate
|
|
: repeat ' GOTO_ , swap , here swap ! ; immediate
|
|
: again ' GOTO_ , , ; immediate
|
|
: until ' BZ_ , , ; immediate
|
|
|
|
: ( begin key ')' = until ; immediate
|
|
: lit ' LIT_ , , ;
|
|
|
|
: inline| ' INLINEDATA_ , here 0 , ;
|
|
: |inline [ ' then , ] ;
|
|
|
|
key " const '"'
|
|
|
|
: s" state if inline| else here then
|
|
begin key dup '"' != over 0 != and while b, repeat drop 0 b,
|
|
state if |inline else dup here! then ; immediate
|
|
|
|
: interpretword F_IMMEDIATE & state not or if execute else , then ;
|
|
: interpretnumber state if lit then ;
|
|
: interpretunknown type s" ?" type cr ;
|
|
: compileword lookup dup
|
|
if interpretword
|
|
else drop number
|
|
if interpretnumber
|
|
else interpretunknown
|
|
then
|
|
then ;
|
|
: interpreter
|
|
begin word dup b@ while compileword repeat drop ;
|
|
: load-input swap-input r> r> interpreter r< r< swap-input ;
|
|
: loadstring ' key-string load-input drop drop ;
|
|
: loadfile fdeactivate ' key-file load-input drop close ;
|