|
|
@ -18,20 +18,17 @@
|
|
|
|
|
|
|
|
|
|
|
|
#define END_OF(arr) ((arr) + (sizeof((arr)) / sizeof(*(arr))))
|
|
|
|
#define END_OF(arr) ((arr) + (sizeof((arr)) / sizeof(*(arr))))
|
|
|
|
|
|
|
|
|
|
|
|
static intptr_t dstack[8];
|
|
|
|
static intptr_t STATE;
|
|
|
|
static intptr_t **rstack[8];
|
|
|
|
static intptr_t BASE;
|
|
|
|
static intptr_t dict[100] = {
|
|
|
|
static intptr_t LATEST;
|
|
|
|
0, 10, 0
|
|
|
|
|
|
|
|
};
|
|
|
|
static intptr_t dstack[FOCI_DATA_STACK_SIZE];
|
|
|
|
#define state dict[0]
|
|
|
|
static intptr_t **rstack[FOCI_RETURN_STACK_SIZE];
|
|
|
|
#define BASE dict[1]
|
|
|
|
static intptr_t *dictmem;
|
|
|
|
#define LATEST dict[2]
|
|
|
|
static intptr_t *here;
|
|
|
|
#define BEGIN dict[3]
|
|
|
|
|
|
|
|
static intptr_t *here = &BEGIN;
|
|
|
|
|
|
|
|
static char *in;
|
|
|
|
static char *in;
|
|
|
|
|
|
|
|
static intptr_t *saved_sp;
|
|
|
|
static intptr_t * saved_sp;
|
|
|
|
static intptr_t ***saved_rp;
|
|
|
|
static intptr_t *** saved_rp;
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
NAKED void enter(void) { *--rp = ++pp; pp = (intptr_t **)*pp; goto *(*pp); }
|
|
|
|
NAKED void enter(void) { *--rp = ++pp; pp = (intptr_t **)*pp; goto *(*pp); }
|
|
|
|
NAKED void push(void) { *--sp = (intptr_t)*++pp; NEXT; }
|
|
|
|
NAKED void push(void) { *--sp = (intptr_t)*++pp; NEXT; }
|
|
|
@ -118,13 +115,13 @@ N(xor, "xor", &w_or) { sp[1] ^= sp[0]; ++sp; NEXT; }
|
|
|
|
N(eq, "=", &w_xor) { sp[1] = sp[0] == sp[1]; ++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(lt, "<", &w_eq) { sp[1] = sp[0] > sp[1]; ++sp; NEXT; }
|
|
|
|
N(compname, "_c", &w_lt) ;
|
|
|
|
N(compname, "_c", &w_lt) ;
|
|
|
|
C(intr, "[", &w_compname) { state = 0; NEXT; }
|
|
|
|
C(intr, "[", &w_compname) { STATE = 0; NEXT; }
|
|
|
|
N(comp, "]", &w_intr) { state = -1; NEXT; }
|
|
|
|
N(comp, "]", &w_intr) { STATE = -1; NEXT; }
|
|
|
|
N(comma, ",", &w_comp) { *here++ = *sp++; NEXT; }
|
|
|
|
N(comma, ",", &w_comp) { *here++ = *sp++; NEXT; }
|
|
|
|
W(cell, "cell", &w_comma) LIT(sizeof(*sp)), END
|
|
|
|
W(cell, "cell", &w_comma) LIT(sizeof(*sp)), END
|
|
|
|
W(cellp, "cell+", &w_cell) FTH(cell), add, END
|
|
|
|
W(cellp, "cell+", &w_cell) FTH(cell), add, END
|
|
|
|
W(cells, "cells", &w_cellp) FTH(cell), mul, END
|
|
|
|
W(cells, "cells", &w_cellp) FTH(cell), mul, END
|
|
|
|
W(dict, "_d", &w_cells) LIT(dict), END
|
|
|
|
N(dict, "_d", &w_cells) { *--sp = (intptr_t)dictmem; NEXT; }
|
|
|
|
W(base, "base", &w_dict) LIT(&BASE), END
|
|
|
|
W(base, "base", &w_dict) LIT(&BASE), END
|
|
|
|
W(here, "here", &w_base) LIT(&here), peek, END
|
|
|
|
W(here, "here", &w_base) LIT(&here), peek, END
|
|
|
|
W(allot, "allot", &w_here) LIT(&here), FTH(addto), END
|
|
|
|
W(allot, "allot", &w_here) LIT(&here), FTH(addto), END
|
|
|
@ -166,7 +163,7 @@ N(popr2, "2r>", &w_pushr2) { *--sp = (intptr_t)rp[1];
|
|
|
|
*--sp = (intptr_t)rp[0]; rp += 2; NEXT; }
|
|
|
|
*--sp = (intptr_t)rp[0]; rp += 2; NEXT; }
|
|
|
|
#define LATEST_INIT &w_popr2
|
|
|
|
#define LATEST_INIT &w_popr2
|
|
|
|
|
|
|
|
|
|
|
|
void enter_forth(const void * const ptr)
|
|
|
|
void enter_forth(const void *ptr)
|
|
|
|
{
|
|
|
|
{
|
|
|
|
STASH;
|
|
|
|
STASH;
|
|
|
|
sp = saved_sp;
|
|
|
|
sp = saved_sp;
|
|
|
@ -244,7 +241,7 @@ static void parse_word(const char *start, const char *end)
|
|
|
|
const char *nend;
|
|
|
|
const char *nend;
|
|
|
|
intptr_t n = parse_number(start, &nend, BASE);
|
|
|
|
intptr_t n = parse_number(start, &nend, BASE);
|
|
|
|
if (nend == end) {
|
|
|
|
if (nend == end) {
|
|
|
|
if (state) {
|
|
|
|
if (STATE) {
|
|
|
|
*here++ = (intptr_t)push;
|
|
|
|
*here++ = (intptr_t)push;
|
|
|
|
*here++ = n;
|
|
|
|
*here++ = n;
|
|
|
|
} else {
|
|
|
|
} else {
|
|
|
@ -256,7 +253,7 @@ static void parse_word(const char *start, const char *end)
|
|
|
|
foci_putchar(*err++);
|
|
|
|
foci_putchar(*err++);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
} else {
|
|
|
|
} else {
|
|
|
|
if (state && !(l->attr & ATTR_IMMEDIATE)) {
|
|
|
|
if (STATE && !(l->attr & ATTR_IMMEDIATE)) {
|
|
|
|
if (!(l->attr & ATTR_NATIVE)) {
|
|
|
|
if (!(l->attr & ATTR_NATIVE)) {
|
|
|
|
*here++ = (intptr_t)enter;
|
|
|
|
*here++ = (intptr_t)enter;
|
|
|
|
*here++ = (intptr_t)l->body;
|
|
|
|
*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_sp = END_OF(dstack);
|
|
|
|
saved_rp = END_OF(rstack);
|
|
|
|
saved_rp = END_OF(rstack);
|
|
|
|
|
|
|
|
|
|
|
|
LATEST = (intptr_t)LATEST_INIT;
|
|
|
|
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
int depth(void)
|
|
|
|
int depth(void)
|
|
|
@ -304,7 +305,7 @@ int depth(void)
|
|
|
|
|
|
|
|
|
|
|
|
int compiling(void)
|
|
|
|
int compiling(void)
|
|
|
|
{
|
|
|
|
{
|
|
|
|
return state;
|
|
|
|
return STATE;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
void define(struct word_t *w)
|
|
|
|
void define(struct word_t *w)
|
|
|
|