Fix rounding, more web fix.

This commit is contained in:
Brad Nelson
2021-01-05 22:16:11 -08:00
parent 476434c92c
commit da8b3f59b6
5 changed files with 20 additions and 6 deletions

View File

@ -147,8 +147,8 @@ static void ueforth(int argc, char *argv[], void *heap,
PLATFORM_OPCODE_LIST
OPCODE_LIST
#undef X
OP_DOCOLON: ++rp; *rp = (cell_t) ip; ip = (cell_t *) (w + sizeof(cell_t)); NEXT;
OP_DOCREATE: DUP; tos = w + sizeof(cell_t) * 2; NEXT;
OP_DODOES: DUP; tos = w + sizeof(cell_t) * 2;
*++rp = (cell_t) ip; ip = (cell_t *) *(cell_t *) (w + sizeof(cell_t)); NEXT;
OP_DOCOL: *++rp = (cell_t) ip; ip = (cell_t *) (w + sizeof(cell_t)); NEXT;
++rp; *rp = (cell_t) ip; ip = (cell_t *) *(cell_t *) (w + sizeof(cell_t)); NEXT;
}

View File

@ -28,8 +28,8 @@ typedef uint64_t udcell_t;
--sp; *sp = (cell_t) (ud % tos); \
tos = (cell_t) (ud / tos)) \
X("*/MOD", OP_SSMOD, d = (dcell_t) *sp * (dcell_t) sp[-1]; \
--sp; *sp = (cell_t) (d % tos); \
tos = (cell_t) (d / tos)) \
--sp; *sp = (cell_t) (((udcell_t) d) % tos); \
tos = (cell_t) (d < 0 ? ~(~d / tos) : d / tos)) \
X("AND", OP_AND, tos = tos & *sp; --sp) \
X("OR", OP_OR, tos = tos | *sp; --sp) \
X("XOR", OP_XOR, tos = tos ^ *sp; --sp) \
@ -70,7 +70,7 @@ typedef uint64_t udcell_t;
X("IMMEDIATE", OP_IMMEDIATE, g_sys.last[-1] |= 1) \
X("'SYS", OP_SYS, DUP; tos = (cell_t) &g_sys) \
X(":", OP_COLON, DUP; DUP; tos = parse(32, sp); \
create((const char *) *sp, tos, 0, && OP_DOCOL); \
create((const char *) *sp, tos, 0, && OP_DOCOLON); \
g_sys.state = -1; --sp; DROP) \
X("EVALUATE1", OP_EVALUATE1, DUP; sp = evaluate1(sp); \
w = *sp; --sp; DROP; \

View File

@ -7,7 +7,9 @@
X("CALL", OP_CALL, sp = Call(sp, tos); DROP) \
enum {
OP_NONE = -1,
OP_DOCOLON = 0,
OP_DOCREATE = 1,
OP_DODOES = 2,
#define X(name, op, code) op,
PLATFORM_OPCODE_LIST
OPCODE_LIST

View File

@ -39,6 +39,8 @@ cases = ReplaceAll(cases, 'g_sys.state', 'i32[(i32[g_sys>>2] + (3 * 4))>>2]');
cases = ReplaceAll(cases, 'g_sys.DOLIT_XT', 'i32[(i32[g_sys>>2] + (10 * 4))>>2]');
cases = ReplaceAll(cases, 'g_sys.DOEXIT_XT', 'i32[(i32[g_sys>>2] + (11 * 4))>>2]');
cases = ReplaceAll(cases, '&g_sys', 'g_sys');
cases = ReplaceAll(cases, '&& OP_DOCOLON', '0');
cases = ReplaceAll(cases, '&& OP_DOCREATE', '1');
code = code.replace('{{boot}}', function() { return boot; });
code = code.replace('{{dict}}', function() { return dict; });

View File

@ -71,6 +71,16 @@ function Interpreter(stdlib, foreign, heap) {
ir = i32[((ip + (w<<2))|0)>>2]|0;
ip = (ip + 4)|0;
switch (ir & 0xff) {
case 0: // OP_DOCOLON
rp = (rp + 4) | 0; i32[rp] = ip; ip = (w + 4) | 0;
break;
case 1: // OP_DOCREATE
sp = (sp + 4) | 0; i32[sp] = tos; tos = (w + 8) | 0; // 4 * 2
break;
case 2: // OP_DODOES
sp = (sp + 4) | 0; i32[sp] = tos; tos = (w + 8) | 0; // 4 * 2
rp = (rp + 4) | 0; i32[rp] = ip; ip = i32[(w + 4) >> 2];
break;
{{cases}}
}
}