2019-02-10 02:52:12 +00:00
|
|
|
2 const cell
|
|
|
|
: cells cell * ;
|
|
|
|
|
|
|
|
key ) const ')'
|
|
|
|
|
|
|
|
10 const '\n'
|
2019-03-05 22:35:50 +00:00
|
|
|
13 const '\r'
|
2019-02-10 02:52:12 +00:00
|
|
|
key const sp
|
|
|
|
|
|
|
|
128 const F_IMMEDIATE
|
2019-09-29 03:19:02 +00:00
|
|
|
0x100 const F_USERWORD
|
2019-02-10 02:52:12 +00:00
|
|
|
|
|
|
|
: 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_ , , ;
|
|
|
|
|
2019-02-24 15:14:56 +00:00
|
|
|
: inline| ' INLINEDATA_ , here 0 , ;
|
|
|
|
: |inline [ ' then , ] ;
|
|
|
|
|
2019-04-27 15:12:39 +00:00
|
|
|
' cells @ const $DOCOLON ( get the colon execution token )
|
|
|
|
: :| inline| $DOCOLON , ; immediate
|
|
|
|
: |; ' ret , |inline ; immediate
|
|
|
|
|
2019-02-24 15:14:56 +00:00
|
|
|
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
|
|
|
|
|
2019-02-10 02:52:12 +00:00
|
|
|
: 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
|
2019-02-11 00:17:58 +00:00
|
|
|
begin word dup b@ while compileword repeat drop ;
|
2019-05-17 01:05:40 +00:00
|
|
|
: load-input swap-input >r >r interpreter <r <r swap-input ;
|
2019-02-10 02:52:12 +00:00
|
|
|
: loadstring ' key-string load-input drop drop ;
|
2019-03-05 22:35:50 +00:00
|
|
|
|
2019-03-09 23:49:45 +00:00
|
|
|
( image loading )
|
|
|
|
: noop ;
|
|
|
|
|
|
|
|
: defer word new-word $DODEFERRED , ' noop , ;
|
|
|
|
: redefine ( cp cpdeferred ) cell + ! ;
|
|
|
|
: definition ( cpdeferred ) cell + @ ;
|
|
|
|
|
|
|
|
defer onload
|
2019-03-10 00:59:52 +00:00
|
|
|
: postload ' onload definition ' noop ' onload redefine execute ;
|
2019-03-09 23:49:45 +00:00
|
|
|
|
|
|
|
: loadimage ( -- [0 | onload] )
|
2019-04-10 02:00:32 +00:00
|
|
|
imagemagic fget = if
|
|
|
|
fget fget fget fget fget ( onload tasks latest size start )
|
|
|
|
here != if tell + seek drop drop drop 0 else
|
|
|
|
dup here fread here + here! latest! tasks! then
|
|
|
|
else 0 then ;
|
2019-03-09 23:49:45 +00:00
|
|
|
|
|
|
|
: saveimage ( herestart -- )
|
2019-04-10 02:00:32 +00:00
|
|
|
imagemagic fput
|
2019-03-09 23:49:45 +00:00
|
|
|
' onload definition here drop fput
|
|
|
|
tasks fput
|
|
|
|
latest fput
|
|
|
|
dup here swap - fput
|
|
|
|
dup fput
|
|
|
|
dup here swap - swap fwrite ;
|
|
|
|
|
|
|
|
( file loading )
|
2019-03-05 22:35:50 +00:00
|
|
|
: loadimage-if-uptodate ( filename -- b )
|
2019-03-09 23:49:45 +00:00
|
|
|
dup image-uptodate if imagefilename open loadimage close else drop 0 then
|
|
|
|
dup if execute 1 then ;
|
2019-03-05 22:35:50 +00:00
|
|
|
|
2019-03-09 23:49:45 +00:00
|
|
|
: interpretjor ( filename -- )
|
2019-03-05 22:35:50 +00:00
|
|
|
open fdeactivate ' key-file load-input drop factivate close ;
|
|
|
|
|
2019-05-17 01:05:40 +00:00
|
|
|
: preservefp ( xt -- ) fdeactivate >r execute <r factivate ;
|
2019-04-27 15:12:39 +00:00
|
|
|
|
|
|
|
: loadjor :| interpretjor postload |; preservefp ;
|
2019-03-09 23:49:45 +00:00
|
|
|
|
2019-03-05 22:35:50 +00:00
|
|
|
: loadfile ( filename -- )
|
|
|
|
( active file is preserved for the currently-loading file, but the
|
|
|
|
new file is always loaded with no active files )
|
2019-04-27 15:12:39 +00:00
|
|
|
:| dup loadimage-if-uptodate not if
|
2019-05-17 01:05:40 +00:00
|
|
|
here over >r >r interpretjor
|
|
|
|
<r <r imagefilename overwrite saveimage close postload
|
2019-04-27 15:12:39 +00:00
|
|
|
else drop then |; preservefp ;
|