]> code.bitgloo.com Git - clyne/foci.git/commitdiff
configure stack and dict sizes
authorClyne Sullivan <clyne@bitgloo.com>
Tue, 28 Jan 2025 03:02:13 +0000 (22:02 -0500)
committerClyne Sullivan <clyne@bitgloo.com>
Tue, 28 Jan 2025 03:02:13 +0000 (22:02 -0500)
Makefile
foci.c
foci.h
msp430/main.c
x86/main.c

index 71dce0009ebeff5a82702677c4ab8cf0565d4c25..cef251f090788f2aa8b2fd8276136e7b8230cc19 100644 (file)
--- a/Makefile
+++ b/Makefile
@@ -1,4 +1,6 @@
-CFLAGS := -O3 -ggdb -g3 -Wall -Wextra -I.
+CFLAGS := -O3 -ggdb -g3 -Wall -Wextra -I. \
+                 -DFOCI_DATA_STACK_SIZE=12 \
+                 -DFOCI_RETURN_STACK_SIZE=12
 
 all: x86-64
 
diff --git a/foci.c b/foci.c
index 77b4b674aafeb1fb90c7913f462eb7441eca8479..2488c9c38a3fb3b76ffcbcf99e6613d2df97b662 100644 (file)
--- a/foci.c
+++ b/foci.c
 
 #define END_OF(arr) ((arr) + (sizeof((arr)) / sizeof(*(arr))))
 
-static intptr_t dstack[8];
-static intptr_t **rstack[8];
-static intptr_t dict[100] = {
-    0, 10, 0
-};
-#define state  dict[0]
-#define BASE   dict[1]
-#define LATEST dict[2]
-#define BEGIN  dict[3]
-static intptr_t *here = &BEGIN;
+static intptr_t STATE;
+static intptr_t BASE;
+static intptr_t LATEST;
+
+static intptr_t dstack[FOCI_DATA_STACK_SIZE];
+static intptr_t **rstack[FOCI_RETURN_STACK_SIZE];
+static intptr_t *dictmem;
+static intptr_t *here;
 static char *in;
-
-static intptr_t *   saved_sp;
-static intptr_t *** saved_rp;
+static intptr_t *saved_sp;
+static intptr_t ***saved_rp;
 
 NAKED void enter(void) { *--rp = ++pp; pp = (intptr_t **)*pp; goto *(*pp); }
 NAKED void  push(void) { *--sp = (intptr_t)*++pp; NEXT; }
@@ -118,23 +115,23 @@ N(xor,    "xor",    &w_or)    { sp[1] ^= sp[0]; ++sp; NEXT; }
 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; }
+C(intr,   "[",      &w_compname) { STATE = 0; NEXT; }
+N(comp,   "]",      &w_intr)  { STATE = -1; NEXT; }
 N(comma,  ",",      &w_comp)  { *here++ = *sp++; NEXT; }
-W(cell,   "cell",   &w_comma)   LIT(sizeof(*sp)),   END
-W(cellp,  "cell+",  &w_cell)    FTH(cell), add,     END
-W(cells,  "cells",  &w_cellp)   FTH(cell), mul,     END
-W(dict,   "_d",     &w_cells)   LIT(dict),          END
-W(base,   "base",   &w_dict)    LIT(&BASE), END
-W(here,   "here",   &w_base)    LIT(&here), peek,   END
-W(allot,  "allot",  &w_here)    LIT(&here), FTH(addto), END
-W(latest, "latest", &w_allot)   LIT(&LATEST), peek, END
-W(negate, "negate", &w_latest)  LIT(-1), mul, END
-W(invert, "invert", &w_negate)  LIT(-1), xor, END
-W(dec,    "1-",     &w_invert)  LIT(1), sub,  END
-W(inc,    "1+",     &w_dec)     LIT(1), add,  END
-W(aligned, "aligned", &w_inc)   LIT(sizeof(*sp) - 1), add, LIT(~(sizeof(*sp) - 1)),
-                                and, END
+W(cell,   "cell",   &w_comma) LIT(sizeof(*sp)),   END
+W(cellp,  "cell+",  &w_cell)  FTH(cell), add,     END
+W(cells,  "cells",  &w_cellp) FTH(cell), mul,     END
+N(dict,   "_d",     &w_cells) { *--sp = (intptr_t)dictmem; NEXT; }
+W(base,   "base",   &w_dict)  LIT(&BASE), END
+W(here,   "here",   &w_base)  LIT(&here), peek,   END
+W(allot,  "allot",  &w_here)  LIT(&here), FTH(addto), END
+W(latest, "latest", &w_allot) LIT(&LATEST), peek, END
+W(negate, "negate", &w_latest) LIT(-1), mul, END
+W(invert, "invert", &w_negate) LIT(-1), xor, END
+W(dec,    "1-",     &w_invert) LIT(1), sub,  END
+W(inc,    "1+",     &w_dec)    LIT(1), add,  END
+W(aligned, "aligned", &w_inc)  LIT(sizeof(*sp) - 1), add, LIT(~(sizeof(*sp) - 1)),
+                               and, END
 W(align,  "align",  &w_aligned) FTH(here), FTH(aligned), LIT(&here), poke, END
 W(colon,  ":",      &w_align)   FTH(here), LIT(0), comma, FTH(latest), comma,
                                 compname, FTH(allot), FTH(align), dup,
@@ -166,7 +163,7 @@ N(popr2,  "2r>",    &w_pushr2)  { *--sp = (intptr_t)rp[1];
                                   *--sp = (intptr_t)rp[0]; rp += 2; NEXT; }
 #define LATEST_INIT &w_popr2
 
-void enter_forth(const void * const ptr)
+void enter_forth(const void *ptr)
 {
     STASH;
     sp = saved_sp;
@@ -244,7 +241,7 @@ static void parse_word(const char *start, const char *end)
         const char *nend;
         intptr_t n = parse_number(start, &nend, BASE);
         if (nend == end) {
-            if (state) {
+            if (STATE) {
                 *here++ = (intptr_t)push;
                 *here++ = n;
             } else {
@@ -256,7 +253,7 @@ static void parse_word(const char *start, const char *end)
                 foci_putchar(*err++);
         }
     } else {
-        if (state && !(l->attr & ATTR_IMMEDIATE)) {
+        if (STATE && !(l->attr & ATTR_IMMEDIATE)) {
             if (!(l->attr & ATTR_NATIVE)) {
                 *here++ = (intptr_t)enter;
                 *here++ = (intptr_t)l->body;
@@ -289,12 +286,16 @@ void interpret(void)
     }
 }
 
-void init(void)
+void init(intptr_t *dictmemm)
 {
+    dictmem = dictmemm;
+    STATE = 0;
+    BASE = 10;
+    LATEST = (intptr_t)LATEST_INIT;
+    here = dictmem;
+    in = 0;
     saved_sp = END_OF(dstack);
     saved_rp = END_OF(rstack);
-
-    LATEST = (intptr_t)LATEST_INIT;
 }
 
 int depth(void)
@@ -304,7 +305,7 @@ int depth(void)
 
 int compiling(void)
 {
-    return state;
+    return STATE;
 }
 
 void define(struct word_t *w)
diff --git a/foci.h b/foci.h
index 9c21c2712b3187bb0cbc5dcc14e1ae61e3f0b802..b666b96fa3e5485e0ef922272a738816874a7764 100644 (file)
--- a/foci.h
+++ b/foci.h
@@ -90,7 +90,7 @@ register intptr_t     tmp asm("r7");
 extern void foci_putchar(int);
 extern int  foci_getchar(void);
 
-void init(void);
+void init(intptr_t *dictmem);
 int depth(void);
 int compiling(void);
 void interpret(void);
index fd0489fcba0e1dcaa089196b42e5c76b25afc58a..9d9cc8372dab961e86c61a7cf376cbc1b783c3dd 100644 (file)
@@ -2,6 +2,8 @@
 
 #include "foci.h"
 
+static intptr_t dict[100];
+
 int main()
 {
     WDTCTL = WDTPW | WDTHOLD;
@@ -18,7 +20,7 @@ int main()
     UCA0MCTL = UCBRS0;    // Modulation UCBRSx = 1
     UCA0CTL1 &= ~UCSWRST;
 
-    init();
+    init(dict);
 
     foci_putchar('o');
     foci_putchar('k');
index e6230de9803b99df7393db0fe83656bc07a2e37c..1415cc27ff594a1532e1ba0cf92618b23df51b68 100644 (file)
 
 #include <stdio.h>
 
-void foci_putchar(int ch)
-{
-    putchar(ch);
-}
-
-int foci_getchar(void)
-{
-    return getchar();
-}
+static intptr_t dict[8192];
 
 int main()
 {
-    init();
+    init(dict);
 
     for (;;) {
         interpret();
@@ -40,3 +32,13 @@ int main()
     return 0;
 }
 
+void foci_putchar(int ch)
+{
+    putchar(ch);
+}
+
+int foci_getchar(void)
+{
+    return getchar();
+}
+