From 6fbff7131cd6d5bc54a01635fb03d284d48570eb Mon Sep 17 00:00:00 2001 From: Brad Nelson Date: Wed, 2 Feb 2022 20:04:02 -0800 Subject: [PATCH] Fix issue with sizes in colon words + see. --- ueforth/common/core.h | 8 ++++++-- ueforth/common/opcodes.h | 4 ++-- ueforth/common/utils.fs | 4 ++-- 3 files changed, 10 insertions(+), 6 deletions(-) diff --git a/ueforth/common/core.h b/ueforth/common/core.h index ce879e3..51e4db3 100644 --- a/ueforth/common/core.h +++ b/ueforth/common/core.h @@ -123,12 +123,16 @@ static cell_t find(const char *name, cell_t len) { return 0; } -static void create(const char *name, cell_t nlength, cell_t flags, void *op) { - if (g_sys.latestxt) { +static void finish(void) { + if (g_sys.latestxt && !(g_sys.latestxt[-1] >> 16)) { cell_t sz = g_sys.heap - &g_sys.latestxt[1]; if (sz < 0 || sz > 0xffff) { sz = 0xffff; } g_sys.latestxt[-1] |= (sz << 16); } +} + +static void create(const char *name, cell_t nlength, cell_t flags, void *op) { + finish(); g_sys.heap = (cell_t *) CELL_ALIGNED(g_sys.heap); char *pos = (char *) g_sys.heap; for (cell_t n = nlength; n; --n) { *pos++ = *name++; } // name diff --git a/ueforth/common/opcodes.h b/ueforth/common/opcodes.h index 618bdc1..33e1dd9 100644 --- a/ueforth/common/opcodes.h +++ b/ueforth/common/opcodes.h @@ -29,7 +29,7 @@ typedef uintptr_t ucell_t; #define PUSH DUP; tos = (cell_t) #define COMMA(n) *g_sys.heap++ = (n) #define DOIMMEDIATE() (*g_sys.current)[-1] |= IMMEDIATE -#define UNSMUDGE() (*g_sys.current)[-1] &= ~SMUDGE +#define UNSMUDGE() (*g_sys.current)[-1] &= ~SMUDGE; finish() #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 @@ -105,4 +105,4 @@ typedef int64_t dcell_t; sp = evaluate1(sp, &tfp); \ fp = tfp; w = *sp--; DROP; if (w) JMPW) \ Y(EXIT, ip = (cell_t *) *rp--) \ - X(";", SEMICOLON, UNSMUDGE(); COMMA(g_sys.DOEXIT_XT); g_sys.state = 0) + X(";", SEMICOLON, COMMA(g_sys.DOEXIT_XT); UNSMUDGE(); g_sys.state = 0) diff --git a/ueforth/common/utils.fs b/ueforth/common/utils.fs index 61a8900..13cae65 100644 --- a/ueforth/common/utils.fs +++ b/ueforth/common/utils.fs @@ -52,8 +52,8 @@ internals definitions over ['] DONEXT = or if see. cell+ exit then see. ; -: exit= ( xt -- ) ['] exit = ; -: see-loop >body begin dup @ exit= 0= while see-one repeat drop ; +: see-loop dup >body swap >params 1- cells over + + begin 2dup < while swap see-one swap repeat 2drop ; : see-xt ( xt -- ) dup @ ['] see-loop @ <> if ." Unsupported word type: " see. cr exit then