aboutsummaryrefslogtreecommitdiffstats
path: root/foci.c
diff options
context:
space:
mode:
Diffstat (limited to 'foci.c')
-rw-r--r--foci.c37
1 files changed, 19 insertions, 18 deletions
diff --git a/foci.c b/foci.c
index a75669e..107d317 100644
--- a/foci.c
+++ b/foci.c
@@ -18,9 +18,9 @@
#define END_OF(arr) ((arr) + (sizeof((arr)) / sizeof(*(arr))))
-static intptr_t dstack[16];
-static intptr_t **rstack[16];
-static intptr_t dict[1000] = {
+static intptr_t dstack[8];
+static intptr_t **rstack[8];
+static intptr_t dict[100] = {
0, 10, 0
};
#define state dict[0]
@@ -140,8 +140,8 @@ W(colon, ":", &w_align) FTH(here), LIT(0), comma, FTH(latest), comma,
I(semic, ";", &w_colon) LIT(fexit), comma, LIT(&LATEST), poke, intr, END
I(literal, "literal", &w_semic) LIT(push), comma, comma, END
N(b, "_b", &w_literal) { ++pp; pp = (intptr_t **)*pp; NEXT; }
-N(bz, "_bz", &w_literal) { ++pp; if (!*sp++) { pp = (intptr_t **)*pp; } NEXT; }
-I(fif, "if", &w_b) LIT(bz), comma, FTH(here), LIT(0), comma, END
+N(bz, "_bz", &w_b) { ++pp; if (!*sp++) { pp = (intptr_t **)*pp; } NEXT; }
+I(fif, "if", &w_bz) LIT(bz), comma, FTH(here), LIT(0), comma, END
I(then, "then", &w_fif) FTH(here), LIT(sizeof(intptr_t)), sub, swap, poke, END
I(felse, "else", &w_then) LIT(b), comma, FTH(here), LIT(0), comma, swap, FTH(then), END
W(tick, "\'", &w_felse) compname, drop, lookup, peek, END
@@ -153,7 +153,7 @@ N(dot, ".", &w_hex) ;
N(emit, "emit", &w_dot) { foci_putchar(*sp++); NEXT; }
#define LATEST_INIT &w_emit
-void enter_forth(void *ptr)
+void enter_forth(const void * const ptr)
{
STASH;
sp = saved_sp;
@@ -170,19 +170,20 @@ void enter_forth(void *ptr)
__attribute__((noinline))
static void dotimpl(intptr_t n)
{
- static char dotbuf[16];
+ static const char dottbl[16] = "0123456789abcdef";
+ static char dotbuf[16] = {0};
+ int i;
- char *s = dotbuf + sizeof(dotbuf);
- int neg = n < 0;
- if (neg) n *= -1;
- *--s = '\0';
-
- do *--s = "0123456789abcdef"[n % BASE];
- while (n /= BASE);
- if (neg)
+ if (n < 0) {
+ n *= -1;
foci_putchar('-');
- while (*s)
- foci_putchar(*s++);
+ }
+
+ for (i = 0; n > 0; n /= 10)
+ dotbuf[i++] = dottbl[n % BASE];
+
+ while (--i >= 0)
+ foci_putchar(dotbuf[i]);
foci_putchar(' ');
}
@@ -254,7 +255,7 @@ static void parse_word(const char *start, const char *end)
void interpret(void)
{
- static char buf[128];
+ static char buf[80];
char *s = buf - 1;
do *++s = foci_getchar();