Fix stack init weirdness + bug with interrupts + float stack.

This commit is contained in:
Brad Nelson
2022-01-07 00:06:17 -08:00
parent 15161a8085
commit 614c23a07e
5 changed files with 15 additions and 13 deletions

View File

@ -190,11 +190,11 @@ static cell_t *evaluate1(cell_t *sp, float **fp) {
static cell_t *forth_run(cell_t *initrp);
static void forth_init(int argc, char *argv[], void *heap,
const char *src, cell_t src_len) {
const char *src, cell_t src_len) {
g_sys.heap = ((cell_t *) heap) + 4; // Leave a little room.
cell_t *sp = g_sys.heap + 1; g_sys.heap += STACK_SIZE;
cell_t *rp = g_sys.heap + 1; g_sys.heap += STACK_SIZE;
float *fp = (float *) (g_sys.heap + 1); g_sys.heap += STACK_SIZE;
cell_t *rp = g_sys.heap + 1; g_sys.heap += STACK_SIZE;
cell_t *sp = g_sys.heap + 1; g_sys.heap += STACK_SIZE;
// FORTH vocabulary
*g_sys.heap++ = 0; cell_t *forth = g_sys.heap;
@ -221,8 +221,8 @@ static void forth_init(int argc, char *argv[], void *heap,
g_sys.base = 10;
g_sys.tib = src;
g_sys.ntib = src_len;
*++rp = (cell_t) sp;
*++rp = (cell_t) fp;
*++rp = (cell_t) sp;
*++rp = (cell_t) start;
g_sys.rp = rp;
g_sys.runner = forth_run;

View File

@ -28,9 +28,7 @@ static cell_t *forth_run(cell_t *init_rp) {
}
register cell_t *ip, *rp, *sp, tos, w;
register float *fp;
rp = init_rp; ip = (cell_t *) *rp--; sp = (cell_t *) *rp--;
fp = (float *) *rp--;
DROP; NEXT;
rp = init_rp; UNPARK; NEXT;
#define X(name, op, code) OP_ ## op: { code; } NEXT;
PLATFORM_OPCODE_LIST
OPCODE_LIST

View File

@ -31,7 +31,9 @@ typedef uintptr_t ucell_t;
#define DOIMMEDIATE() (*g_sys.current)[-1] |= IMMEDIATE
#define UNSMUDGE() (*g_sys.current)[-1] &= ~SMUDGE
#define DOES(ip) **g_sys.current = (cell_t) ADDR_DODOES; (*g_sys.current)[1] = (cell_t) ip
#define PARK DUP; *++rp = (cell_t) fp; *++rp = (cell_t) sp; *++rp = (cell_t) ip
#define PARK DUP; *++rp = (cell_t) fp; *++rp = (cell_t) sp; *++rp = (cell_t) ip
#define UNPARK ip = (cell_t *) *rp--; sp = (cell_t *) *rp--; fp = (float *) *rp--; DROP
#ifndef SSMOD_FUNC
# if __SIZEOF_POINTER__ == 8

View File

@ -599,9 +599,11 @@ static void InvokeWebServerOn(WebServer *ws, const char *url, cell_t xt) {
cell_t code[2];
code[0] = xt;
code[1] = g_sys.YIELD_XT;
cell_t stack[INTERRUPT_STACK_CELLS];
cell_t fstack[INTERRUPT_STACK_CELLS];
cell_t rstack[INTERRUPT_STACK_CELLS];
cell_t stack[INTERRUPT_STACK_CELLS];
cell_t *rp = rstack;
*++rp = (cell_t) (fstack + 1);
*++rp = (cell_t) (stack + 1);
*++rp = (cell_t) code;
forth_run(rp);
@ -620,10 +622,12 @@ static void IRAM_ATTR HandleInterrupt(void *arg) {
cell_t code[2];
code[0] = args->xt;
code[1] = g_sys.YIELD_XT;
cell_t stack[INTERRUPT_STACK_CELLS];
cell_t fstack[INTERRUPT_STACK_CELLS];
cell_t rstack[INTERRUPT_STACK_CELLS];
cell_t stack[INTERRUPT_STACK_CELLS];
stack[0] = args->arg;
cell_t *rp = rstack;
*++rp = (cell_t) (fstack + 1);
*++rp = (cell_t) (stack + 1);
*++rp = (cell_t) code;
forth_run(rp);

View File

@ -39,9 +39,7 @@ static cell_t *forth_run(cell_t *init_rp) {
}
register cell_t *ip, *rp, *sp, tos, w;
register float *fp;
rp = init_rp; ip = (cell_t *) *rp--; sp = (cell_t *) *rp--;
fp = (float *) *rp--;
DROP;
rp = init_rp; UNPARK;
for (;;) {
next:
w = *ip++;