mirror of
https://github.com/hsoft/collapseos.git
synced 2024-11-09 01:48:05 +11:00
80ab395823
Change the mainloop so that words are executed immediately after they're read. This greatly simplifies execution model and allow the "DEFINE" word to become an IMMEDIATE and stop its "copy from compiled words" scheme. The downside to this is that flow control words no longer work when being used directly in the input buffer. They only work as part of a definition. It also broke "RECURSE", but I've replaced it with "BEGIN" and "AGAIN". Another effect of this change is that definitions can now span multiple lines. All in all, it feels good to get rid of that COMPBUF...
30 lines
952 B
Forth
30 lines
952 B
Forth
: H HERE @ ;
|
|
: -^ SWAP - ;
|
|
: +! SWAP OVER @ + SWAP ! ;
|
|
: ALLOT HERE +! ;
|
|
: , H ! 2 ALLOT ;
|
|
: C, H C! 1 ALLOT ;
|
|
: BEGIN H ; IMMEDIATE
|
|
: AGAIN ['] (bbr) , H -^ C, ; IMMEDIATE
|
|
: NOT 1 SWAP SKIP? EXIT 0 * ;
|
|
: ( BEGIN LITS ) WORD SCMP NOT SKIP? AGAIN ; IMMEDIATE
|
|
( Hello, hello, krkrkrkr... do you hear me?
|
|
Ah, voice at last! Some lines above need comments
|
|
BTW: Forth lines limited to 64 cols because of default
|
|
input buffer size in Collapse OS
|
|
NOT: a bit convulted because we don't have IF yet
|
|
IF true, skip following (fbr). Also, push br cell ref H,
|
|
to PS )
|
|
: IF ['] SKIP? , ['] (fbr) , H 1 ALLOT ; IMMEDIATE
|
|
( Subtract TOS from H to get offset to write to IF or ELSE's
|
|
br cell )
|
|
: THEN DUP H -^ SWAP C! ; IMMEDIATE
|
|
( write (fbr) addr, allot, then same as THEN )
|
|
: ELSE ['] (fbr) , 1 ALLOT DUP H -^ SWAP C! H 1 - ; IMMEDIATE
|
|
: ? @ . ;
|
|
: VARIABLE CREATE 2 ALLOT ;
|
|
: CONSTANT CREATE H ! DOES> @ ;
|
|
: = CMP NOT ;
|
|
: < CMP 0 1 - = ;
|
|
: > CMP 1 = ;
|