diff --git a/apps/forth/core.fs b/apps/forth/core.fs index 5d161bd..aa4ffea 100644 --- a/apps/forth/core.fs +++ b/apps/forth/core.fs @@ -3,7 +3,7 @@ : +! SWAP OVER @ + SWAP ! ; : ALLOT HERE +! ; : C, H C! 1 ALLOT ; -: COMPILE ' ['] LITN EXECUTE ['] , , ; IMMEDIATE +: COMPILE ' LITN ['] , , ; IMMEDIATE : BEGIN H ; IMMEDIATE : AGAIN COMPILE (bbr) H -^ C, ; IMMEDIATE : UNTIL COMPILE SKIP? COMPILE (bbr) H -^ C, ; IMMEDIATE @@ -15,9 +15,7 @@ input buffer size in Collapse OS COMPILE; Tough one. Get addr of caller word (example above - (bbr)) and then call LITN on it. However, LITN is an - immediate and has to be indirectly executed. Then, write - a reference to "," so that this word is written to HERE. + (bbr)) and then call LITN on it. NOT: a bit convulted because we don't have IF yet ) @@ -49,3 +47,20 @@ : > CMP 1 = ; : / /MOD SWAP DROP ; : MOD /MOD DROP ; + +( In addition to pushing H this compiles 2 >R so that loop variables are sent + to PS at runtime ) +: DO + COMPILE SWAP COMPILE >R COMPILE >R + H +; IMMEDIATE + +( One could think that we should have a sub word to avoid all these COMPILE, + but we can't because otherwise it messes with the RS ) +: LOOP + COMPILE R> 1 LITN COMPILE + COMPILE DUP COMPILE >R + COMPILE I' COMPILE = COMPILE SKIP? COMPILE (bbr) + H -^ C, + COMPILE R> COMPILE DROP COMPILE R> COMPILE DROP +; IMMEDIATE + diff --git a/apps/forth/dict.asm b/apps/forth/dict.asm index a8d8e38..eb67298 100644 --- a/apps/forth/dict.asm +++ b/apps/forth/dict.asm @@ -444,7 +444,7 @@ ISIMMED: .db "LITN" .fill 3 .dw ISIMMED - .db 1 ; IMMEDIATE + .db 0 LITN: .dw nativeWord ld hl, (HERE) diff --git a/apps/forth/dictionary.txt b/apps/forth/dictionary.txt index 3d42588..16d4376 100644 --- a/apps/forth/dictionary.txt +++ b/apps/forth/dictionary.txt @@ -50,7 +50,7 @@ CONSTANT x n -- Creates cell x that when called pushes its value DOES> -- See description at top of file IMMED? a -- f Checks whether wordref at a is immediate. IMMEDIATE -- Flag the latest defined word as immediate. -LITN n -- *I* Inserts number from TOS as a literal +LITN n -- Write number n as a literal. VARIABLE c -- Creates cell x with 2 bytes allocation. Compilation vs meta-compilation. When you compile a word with "[COMPILE] foo",