configure stack and dict sizes

main
Clyne 4 weeks ago
parent 784f819f97
commit f633ca9108
Signed by: clyne
GPG Key ID: 7BA5A2980566A649

@ -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 all: x86-64

@ -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,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(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
W(latest, "latest", &w_allot) LIT(&LATEST), peek, END W(latest, "latest", &w_allot) LIT(&LATEST), peek, END
W(negate, "negate", &w_latest) LIT(-1), mul, END W(negate, "negate", &w_latest) LIT(-1), mul, END
W(invert, "invert", &w_negate) LIT(-1), xor, END W(invert, "invert", &w_negate) LIT(-1), xor, END
W(dec, "1-", &w_invert) LIT(1), sub, END W(dec, "1-", &w_invert) LIT(1), sub, END
W(inc, "1+", &w_dec) LIT(1), add, END W(inc, "1+", &w_dec) LIT(1), add, END
W(aligned, "aligned", &w_inc) LIT(sizeof(*sp) - 1), add, LIT(~(sizeof(*sp) - 1)), W(aligned, "aligned", &w_inc) LIT(sizeof(*sp) - 1), add, LIT(~(sizeof(*sp) - 1)),
and, END and, END
W(align, "align", &w_aligned) FTH(here), FTH(aligned), LIT(&here), poke, 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, W(colon, ":", &w_align) FTH(here), LIT(0), comma, FTH(latest), comma,
compname, FTH(allot), FTH(align), dup, 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; } *--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)

@ -90,7 +90,7 @@ register intptr_t tmp asm("r7");
extern void foci_putchar(int); extern void foci_putchar(int);
extern int foci_getchar(void); extern int foci_getchar(void);
void init(void); void init(intptr_t *dictmem);
int depth(void); int depth(void);
int compiling(void); int compiling(void);
void interpret(void); void interpret(void);

@ -2,6 +2,8 @@
#include "foci.h" #include "foci.h"
static intptr_t dict[100];
int main() int main()
{ {
WDTCTL = WDTPW | WDTHOLD; WDTCTL = WDTPW | WDTHOLD;
@ -18,7 +20,7 @@ int main()
UCA0MCTL = UCBRS0; // Modulation UCBRSx = 1 UCA0MCTL = UCBRS0; // Modulation UCBRSx = 1
UCA0CTL1 &= ~UCSWRST; UCA0CTL1 &= ~UCSWRST;
init(); init(dict);
foci_putchar('o'); foci_putchar('o');
foci_putchar('k'); foci_putchar('k');

@ -18,19 +18,11 @@
#include <stdio.h> #include <stdio.h>
void foci_putchar(int ch) static intptr_t dict[8192];
{
putchar(ch);
}
int foci_getchar(void)
{
return getchar();
}
int main() int main()
{ {
init(); init(dict);
for (;;) { for (;;) {
interpret(); interpret();
@ -40,3 +32,13 @@ int main()
return 0; return 0;
} }
void foci_putchar(int ch)
{
putchar(ch);
}
int foci_getchar(void)
{
return getchar();
}

Loading…
Cancel
Save