From c5af341f88ce818f7d266f502a984ed4d39fd2ee Mon Sep 17 00:00:00 2001 From: Brad Nelson Date: Tue, 5 Jan 2021 22:30:11 -0800 Subject: [PATCH] Fixing xlib test. --- ueforth/common/opcodes.h | 14 ++++++++------ ueforth/posix/xlib_test.fs | 23 +++++++++++++---------- ueforth/web/fuse_web.js | 1 + ueforth/web/web.template.js | 6 +++--- 4 files changed, 25 insertions(+), 19 deletions(-) diff --git a/ueforth/common/opcodes.h b/ueforth/common/opcodes.h index 6398a39..ddce2cb 100644 --- a/ueforth/common/opcodes.h +++ b/ueforth/common/opcodes.h @@ -19,17 +19,19 @@ typedef uint64_t udcell_t; #define COMMA(n) *g_sys.heap++ = (n) #define IMMEDIATE() g_sys.last[-1] |= 1 #define DOES(ip) *g_sys.last = (cell_t) && OP_DODOES; g_sys.last[1] = (cell_t) ip +#define UMSMOD ud = *(udcell_t *) &sp[-1]; \ + --sp; *sp = (cell_t) (ud % tos); \ + tos = (cell_t) (ud / tos) +#define SSMOD d = (dcell_t) *sp * (dcell_t) sp[-1]; \ + --sp; *sp = (cell_t) (((udcell_t) d) % tos); \ + tos = (cell_t) (d < 0 ? ~(~d / tos) : d / tos) #define OPCODE_LIST \ X("0=", OP_ZEQUAL, tos = !tos ? -1 : 0) \ X("0<", OP_ZLESS, tos = tos < 0 ? -1 : 0) \ X("+", OP_PLUS, tos = (tos + *sp) | 0; --sp) \ - X("UM/MOD", OP_UMSMOD, ud = *(udcell_t *) &sp[-1]; \ - --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) (((udcell_t) d) % tos); \ - tos = (cell_t) (d < 0 ? ~(~d / tos) : d / tos)) \ + X("UM/MOD", OP_UMSMOD, UMSMOD) \ + X("*/MOD", OP_SSMOD, SSMOD) \ X("AND", OP_AND, tos = tos & *sp; --sp) \ X("OR", OP_OR, tos = tos | *sp; --sp) \ X("XOR", OP_XOR, tos = tos ^ *sp; --sp) \ diff --git a/ueforth/posix/xlib_test.fs b/ueforth/posix/xlib_test.fs index 4726e65..53bb3ab 100644 --- a/ueforth/posix/xlib_test.fs +++ b/ueforth/posix/xlib_test.fs @@ -22,16 +22,19 @@ variable width variable height create event xevent-size allot +: draw + width @ . height @ . + display gc black XSetForeground drop + display gc black XSetBackground drop + display window gc 0 0 width @ height @ XFillRectangle drop + display gc white XSetForeground drop + display gc white XSetBackground drop + display window gc 0 0 width @ 2/ height @ 2/ XFillRectangle drop +; : de event xevent-size event c@ . - event c@ Expose = if = - width @ . height @ . - display gc black XSetForeground drop - display gc black XSetBackground drop - display window gc 0 0 width @ height @ XFillRectangle drop - display gc white XSetForeground drop - display gc white XSetBackground drop - display window gc 0 0 width @ 2/ height @ 2/ XFillRectangle drop + event c@ Expose = if + draw ." Expose" then event c@ ButtonPress = if ." ButtonPress" then @@ -43,10 +46,10 @@ create event xevent-size allot event c@ ConfigureNotify = if event 3 16 * 8 + + l@ width ! event 3 16 * 12 + + l@ height ! - width @ . height @ . + ." width & height: " width @ . height @ . ." ConfigureNotify" then event c@ MapNotify = if ." MapNotify" then cr ; : 1e display event XNextEvent drop de ; -: gg begin 1e again ; +: gg begin draw 1e again ; diff --git a/ueforth/web/fuse_web.js b/ueforth/web/fuse_web.js index 5e6e5ac..4b18f85 100755 --- a/ueforth/web/fuse_web.js +++ b/ueforth/web/fuse_web.js @@ -41,6 +41,7 @@ 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'); +cases = ReplaceAll(cases, 'goto **(void **) w', 'break decode'); code = code.replace('{{boot}}', function() { return boot; }); code = code.replace('{{dict}}', function() { return dict; }); diff --git a/ueforth/web/web.template.js b/ueforth/web/web.template.js index 665f9f6..da83b74 100644 --- a/ueforth/web/web.template.js +++ b/ueforth/web/web.template.js @@ -67,10 +67,10 @@ function Interpreter(stdlib, foreign, heap) { tos = i32[sp>>2]|0; sp = (sp - 4)|0; for (;;) { w = i32[ip>>2]|0; - for (;;) { - ir = i32[((ip + (w<<2))|0)>>2]|0; + decode: for (;;) { + ir = u8[w]|0; ip = (ip + 4)|0; - switch (ir & 0xff) { + switch (ir) { case 0: // OP_DOCOLON rp = (rp + 4) | 0; i32[rp] = ip; ip = (w + 4) | 0; break;