]> code.bitgloo.com Git - clyne/foci.git/commitdiff
more loop words
authorClyne Sullivan <clyne@bitgloo.com>
Tue, 28 Jan 2025 02:23:47 +0000 (21:23 -0500)
committerClyne Sullivan <clyne@bitgloo.com>
Tue, 28 Jan 2025 02:23:47 +0000 (21:23 -0500)
README.md
foci.c

index b6634f669bb614994aca3640d10fc76deb4dad15..ca0d89ef6c666c7db6a7890453f34f30f9363148 100644 (file)
--- a/README.md
+++ b/README.md
@@ -9,9 +9,10 @@ Register usage is the only platform-specific requirement; otherwise, `foci` is w
 ## Available words
 
 ```
-dup drop swap rot -rot over tuck @ !  c@ c!  + +!  - * / mod and or xor _c [ ]
-, cell cell+ cells _d base here allot latest negate invert 1- 1+ aligned align
-: ; literal _b _bz if then else \' [\'] execute decimal hex .  emit
+dup drop swap rot -rot over tuck @ ! c@ c! + +! - * / mod and or xor = < [ ] ,
+cell cell+ cells base here allot latest negate invert 1- 1+ aligned align : ;
+literal if then else ' ['] execute decimal hex . emit begin until again while
+repeat
 ```
 
 ## Build instructions
diff --git a/foci.c b/foci.c
index 8dedfbd0e80e6c91bd6ae8cef2547d480973f809..e896015b94ebe16741df280489b0ba9a72c0a337 100644 (file)
--- a/foci.c
+++ b/foci.c
@@ -26,8 +26,8 @@ static intptr_t dict[100] = {
 #define state  dict[0]
 #define BASE   dict[1]
 #define LATEST dict[2]
-#define begin  dict[3]
-static intptr_t *here = &begin;
+#define BEGIN  dict[3]
+static intptr_t *here = &BEGIN;
 static char *in;
 
 static intptr_t *   saved_sp;
@@ -115,7 +115,9 @@ N(mod,    "mod",    &w_ndiv)  { sp[1] %= sp[0]; ++sp; NEXT; }
 N(and,    "and",    &w_mod)   { sp[1] &= sp[0]; ++sp; NEXT; }
 N(or,     "or",     &w_and)   { sp[1] |= sp[0]; ++sp; NEXT; }
 N(xor,    "xor",    &w_or)    { sp[1] ^= sp[0]; ++sp; NEXT; }
-N(compname, "_c",   &w_xor)   ;
+N(eq,     "=",      &w_xor)   { sp[1] = sp[0] == sp[1]; ++sp; NEXT; }
+N(lt,     "<",      &w_eq)    { sp[1] = sp[0] > sp[1]; ++sp; NEXT; }
+N(compname, "_c",   &w_lt)    ;
 C(intr,   "[",      &w_compname) { state = 0; NEXT; }
 N(comp,   "]",      &w_intr)  { state = -1; NEXT; }
 N(comma,  ",",      &w_comp)  { *here++ = *sp++; NEXT; }
@@ -151,7 +153,12 @@ W(decimal, "decimal", &w_execute) LIT(10), LIT(&BASE), poke, END
 W(hex,     "hex",    &w_decimal) LIT(16), LIT(&BASE), poke, END
 N(dot,    ".",      &w_hex)     ;
 N(emit,   "emit",   &w_dot)     { foci_putchar(*sp++); NEXT; }
-#define LATEST_INIT &w_emit
+I(begin,  "begin",  &w_emit)    FTH(here), LIT(sizeof(intptr_t)), sub, END
+I(until,  "until",  &w_begin)   LIT(bz), comma, comma, END
+I(again,  "again",  &w_until)   LIT(b), comma, comma, END
+I(fwhile, "while",  &w_again)   FTH(fif), END
+I(repeat, "repeat", &w_fwhile)  swap, FTH(again), FTH(then), END
+#define LATEST_INIT &w_repeat
 
 void enter_forth(const void * const ptr)
 {