From 587d1d0d69cb3d823c5853865fb05b80d1d45895 Mon Sep 17 00:00:00 2001 From: Virgil Dupras Date: Wed, 18 Mar 2020 16:39:22 -0400 Subject: [PATCH] forth: add word "UNTIL" --- apps/forth/core.fs | 7 ++++--- apps/forth/dictionary.txt | 1 + 2 files changed, 5 insertions(+), 3 deletions(-) diff --git a/apps/forth/core.fs b/apps/forth/core.fs index 9f0e95d..5d161bd 100644 --- a/apps/forth/core.fs +++ b/apps/forth/core.fs @@ -3,11 +3,12 @@ : +! SWAP OVER @ + SWAP ! ; : ALLOT HERE +! ; : C, H C! 1 ALLOT ; -: BEGIN H ; IMMEDIATE : COMPILE ' ['] LITN EXECUTE ['] , , ; IMMEDIATE +: BEGIN H ; IMMEDIATE : AGAIN COMPILE (bbr) H -^ C, ; IMMEDIATE +: UNTIL COMPILE SKIP? COMPILE (bbr) H -^ C, ; IMMEDIATE : NOT 1 SWAP SKIP? EXIT 0 * ; -: ( BEGIN LITS ) WORD SCMP NOT SKIP? AGAIN ; IMMEDIATE +: ( BEGIN LITS ) WORD SCMP NOT UNTIL ; 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 @@ -17,7 +18,7 @@ (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. - + NOT: a bit convulted because we don't have IF yet ) : IF ( -- a | a: br cell addr ) diff --git a/apps/forth/dictionary.txt b/apps/forth/dictionary.txt index 581e54d..3d42588 100644 --- a/apps/forth/dictionary.txt +++ b/apps/forth/dictionary.txt @@ -91,6 +91,7 @@ SKIP? f -- If f is true, skip the execution of the next atom. Use this right before ";" and you're gonna have a bad time. THEN I:a -- *I* Set branching cell at a. +UNTIL f -- *I* Jump backwards to BEGIN if f is *false*. *** Parameter Stack *** DROP a --