From 09fb5b9bb927a774a30bfc6e89f2e3ae3816360a Mon Sep 17 00:00:00 2001 From: Brad Nelson Date: Wed, 13 Jul 2022 21:31:01 -0700 Subject: [PATCH] Restructure more to allow tiers. --- Makefile | 37 ++++++++++++--------- common/forth_namespace_tests.fs | 31 +++++++++-------- common/interp.h | 10 +++--- common/{opcodes.h => tier0_opcodes.h} | 2 +- common/{extra_opcodes.h => tier1_opcodes.h} | 28 +++++----------- common/{extra1.fs => tier1a_forth.fs} | 12 +------ common/{extra2.fs => tier1b_forth.fs} | 0 common/{extra3.fs => tier1c_forth.fs} | 2 -- common/tier2_forth.fs | 27 +++++++++++++++ common/tier2_opcodes.h | 27 +++++++++++++++ esp32/sim_main.cpp | 5 +-- esp32/template.ino | 5 +-- posix/main.c | 5 +-- site/internals.html | 2 +- web/dump_web_opcodes.c | 12 ++++--- web/fuse_web.js | 13 ++++++++ windows/interp.h | 15 +++++---- windows/main.c | 5 +-- 18 files changed, 151 insertions(+), 87 deletions(-) rename common/{opcodes.h => tier0_opcodes.h} (99%) rename common/{extra_opcodes.h => tier1_opcodes.h} (78%) rename common/{extra1.fs => tier1a_forth.fs} (83%) rename common/{extra2.fs => tier1b_forth.fs} (100%) rename common/{extra3.fs => tier1c_forth.fs} (93%) create mode 100644 common/tier2_forth.fs create mode 100644 common/tier2_opcodes.h diff --git a/Makefile b/Makefile index ec2f8a6..04bd1ee 100644 --- a/Makefile +++ b/Makefile @@ -190,14 +190,12 @@ COMMON_PHASE1 = common/comments.fs \ common/structures.fs COMMON_PHASE1e = common/comments.fs \ - common/extra1.fs \ + common/tier2_forth.fs \ common/boot.fs \ - common/extra2.fs \ common/io.fs \ common/conditionals.fs \ common/vocabulary.fs \ common/floats.fs \ - common/extra3.fs \ common/structures.fs COMMON_PHASE2 = common/tasks.fs common/utils.fs common/locals.fs \ @@ -247,7 +245,8 @@ $(GEN)/esp32_boot.h: tools/source_to_string.js $(ESP32_BOOT) | $(GEN) $(GEN)/dump_web_opcodes: \ web/dump_web_opcodes.c \ - common/opcodes.h \ + common/tier0_opcodes.h \ + common/tier1_opcodes.h \ common/bits.h \ common/floats.h | $(GEN) $(CXX) $(CFLAGS) $< -o $@ @@ -330,8 +329,9 @@ $(POSIX): $(POSIX)/ueforth: \ posix/main.c \ - common/opcodes.h \ - common/extra_opcodes.h \ + common/tier0_opcodes.h \ + common/tier1_opcodes.h \ + common/tier2_opcodes.h \ common/calls.h \ common/calling.h \ common/floats.h \ @@ -354,8 +354,9 @@ $(WINDOWS): $(WINDOWS)/uEf32.obj: \ windows/main.c \ - common/opcodes.h \ - common/extra_opcodes.h \ + common/tier0_opcodes.h \ + common/tier1_opcodes.h \ + common/tier2_opcodes.h \ common/calls.h \ common/calling.h \ common/floats.h \ @@ -372,8 +373,9 @@ $(WINDOWS)/uEf32.exe: \ $(WINDOWS)/uEf64.obj: \ windows/main.c \ - common/opcodes.h \ - common/extra_opcodes.h \ + common/tier0_opcodes.h \ + common/tier1_opcodes.h \ + common/tier2_opcodes.h \ common/calls.h \ common/calling.h \ common/floats.h \ @@ -406,8 +408,9 @@ $(GEN)/esp32_sim_opcodes.h: $(GEN)/print-esp32-builtins | $(GEN) $(ESP32_SIM)/Esp32forth-sim: \ esp32/sim_main.cpp \ esp32/main.cpp \ - common/opcodes.h \ - common/extra_opcodes.h \ + common/tier0_opcodes.h \ + common/tier1_opcodes.h \ + common/tier2_opcodes.h \ common/floats.h \ common/calling.h \ common/floats.h \ @@ -429,8 +432,9 @@ $(ESP32)/ESP32forth: ESP32_PARTS = tools/replace.js \ esp32/template.ino \ - common/opcodes.h \ - common/extra_opcodes.h \ + common/tier0_opcodes.h \ + common/tier1_opcodes.h \ + common/tier2_opcodes.h \ common/floats.h \ common/calling.h \ common/bits.h \ @@ -446,8 +450,9 @@ $(ESP32)/ESP32forth/ESP32forth.ino: $(ESP32_PARTS) | $(ESP32)/ESP32forth cat esp32/template.ino | tools/replace.js \ VERSION=$(VERSION) \ REVISION=$(REVISION) \ - opcodes=@common/opcodes.h \ - extra_opcodes=@common/extra_opcodes.h \ + tier0_opcodes=@common/tier0_opcodes.h \ + tier1_opcodes=@common/tier1_opcodes.h \ + tier2_opcodes=@common/tier2_opcodes.h \ calling=@common/calling.h \ floats=@common/floats.h \ bits=@common/bits.h \ diff --git a/common/forth_namespace_tests.fs b/common/forth_namespace_tests.fs index 3fe2e3c..1deea38 100644 --- a/common/forth_namespace_tests.fs +++ b/common/forth_namespace_tests.fs @@ -140,7 +140,19 @@ e: check-boot out: ( ;e -e: check-extra-opcodes +e: check-tier2-opcodes + out: >flags + out: >params + out: >size + out: >link& + out: >link + out: >name + out: >body + out: aligned + out: align +;e + +e: check-tier1-opcodes out: nip out: rdrop out: */ @@ -190,19 +202,9 @@ e: check-extra-opcodes out: here out: allot - out: aligned - out: align out: , out: c, - out: >flags - out: >params - out: >size - out: >link& - out: >link - out: >name - out: >body - out: current out: #tib out: >in @@ -212,7 +214,7 @@ e: check-extra-opcodes out: latestxt ;e -e: check-core-opcodes +e: check-tier0-opcodes out: 0= out: 0< out: + @@ -454,8 +456,9 @@ e: check-phase1 e: check-opcodes check-float-opcodes - check-extra-opcodes - check-core-opcodes + check-tier2-opcodes + check-tier1-opcodes + check-tier0-opcodes ;e e: check-desktop diff --git a/common/interp.h b/common/interp.h index 095aeae..bb188dc 100644 --- a/common/interp.h +++ b/common/interp.h @@ -22,8 +22,9 @@ static cell_t *forth_run(cell_t *init_rp) { name, ((VOC_ ## flags >> 8) & 0xff) | BUILTIN_MARK, \ sizeof(name) - 1, (VOC_ ## flags & 0xff), && OP_ ## op, PLATFORM_OPCODE_LIST - EXTRA_OPCODE_LIST - OPCODE_LIST + TIER2_OPCODE_LIST + TIER1_OPCODE_LIST + TIER0_OPCODE_LIST #undef Z 0, 0, 0, 0, 0, }; @@ -38,7 +39,8 @@ static cell_t *forth_run(cell_t *init_rp) { rp = init_rp; UNPARK; NEXT; #define Z(flags, name, op, code) OP_ ## op: { code; } NEXT; PLATFORM_OPCODE_LIST - EXTRA_OPCODE_LIST - OPCODE_LIST + TIER2_OPCODE_LIST + TIER1_OPCODE_LIST + TIER0_OPCODE_LIST #undef Z } diff --git a/common/opcodes.h b/common/tier0_opcodes.h similarity index 99% rename from common/opcodes.h rename to common/tier0_opcodes.h index 849958e..75f5d38 100644 --- a/common/opcodes.h +++ b/common/tier0_opcodes.h @@ -79,7 +79,7 @@ typedef struct { const void *code; } BUILTIN_WORD; -#define OPCODE_LIST \ +#define TIER0_OPCODE_LIST \ X("0=", ZEQUAL, tos = !tos ? -1 : 0) \ X("0<", ZLESS, tos = (tos|0) < 0 ? -1 : 0) \ X("+", PLUS, tos += *sp--) \ diff --git a/common/extra_opcodes.h b/common/tier1_opcodes.h similarity index 78% rename from common/extra_opcodes.h rename to common/tier1_opcodes.h index b208b22..ce4b749 100644 --- a/common/extra_opcodes.h +++ b/common/tier1_opcodes.h @@ -12,7 +12,7 @@ // See the License for the specific language governing permissions and // limitations under the License. -#define EXTRA_OPCODE_LIST \ +#define TIER1_OPCODE_LIST \ Y(nip, NIP) \ Y(rdrop, --rp) \ XV(forth, "*/", STARSLASH, SSMOD_FUNC; NIP) \ @@ -26,12 +26,12 @@ Y(rot, w = sp[-1]; sp[-1] = *sp; *sp = tos; tos = w) \ X("-rot", MROT, w = tos; tos = *sp; *sp = sp[-1]; sp[-1] = w) \ X("?dup", QDUP, if (tos) DUP) \ - X("<", LESS, tos = (*sp--) < tos ? -1 : 0) \ - X(">", GREATER, tos = (*sp--) > tos ? -1 : 0) \ - X("<=", LESSEQ, tos = (*sp--) <= tos ? -1 : 0) \ - X(">=", GREATEREQ, tos = (*sp--) >= tos ? -1 : 0) \ - X("=", EQUAL, tos = (*sp--) == tos ? -1 : 0) \ - X("<>", NOTEQUAL, tos = (*sp--) != tos ? -1 : 0) \ + X("<", LESS, tos = *sp < tos ? -1 : 0; --sp) \ + X(">", GREATER, tos = *sp > tos ? -1 : 0; --sp) \ + X("<=", LESSEQ, tos = *sp <= tos ? -1 : 0; --sp) \ + X(">=", GREATEREQ, tos = *sp >= tos ? -1 : 0; --sp) \ + X("=", EQUAL, tos = *sp == tos ? -1 : 0; --sp) \ + X("<>", NOTEQUAL, tos = *sp != tos ? -1 : 0; --sp) \ X("0<>", ZNOTEQUAL, tos = tos ? -1 : 0) \ Y(bl, DUP; tos = ' ') \ Y(nl, DUP; tos = '\n') \ @@ -48,7 +48,7 @@ X("2drop", TWODROP, NIP; DROP) \ X("2dup", TWODUP, DUP; tos = sp[-1]; DUP; tos = sp[-1]) \ X("2@", TWOAT, DUP; *sp = *(cell_t *) tos; tos = ((cell_t *) tos)[1]) \ - X("2!", TWOSTORE, ((cell_t *) tos)[0] = sp[-1]; \ + X("2!", TWOSTORE, *(cell_t *) tos = sp[-1]; \ ((cell_t *) tos)[1] = *sp; sp -= 2; DROP) \ Y(cmove, memmove((void *) *sp, (void *) sp[-1], tos); sp -= 2; DROP) \ X("cmove>", cmove2, memmove((void *) *sp, (void *) sp[-1], tos); sp -= 2; DROP) \ @@ -60,17 +60,8 @@ Y(abs, tos = tos < 0 ? -tos : tos) \ Y(here, DUP; tos = (cell_t) g_sys->heap) \ Y(allot, g_sys->heap = (cell_t *) (tos + (cell_t) g_sys->heap); DROP) \ - Y(aligned, tos = CELL_ALIGNED(tos)) \ - Y(align, g_sys->heap = (cell_t *) CELL_ALIGNED(g_sys->heap)) \ X(",", COMMA, COMMA(tos); DROP) \ X("c,", CCOMMA, CCOMMA(tos); DROP) \ - X(">flags", TOFLAGS, tos = *TOFLAGS(tos)) \ - X(">params", TOPARAMS, tos = *TOPARAMS(tos)) \ - X(">size", TOSIZE, tos = TOSIZE(tos)) \ - X(">link&", TOLINKAT, tos = (cell_t) TOLINK(tos)) \ - X(">link", TOLINK, tos = *TOLINK(tos)) \ - X(">name", TONAME, DUP; *sp = (cell_t) TONAME(tos); tos = *TONAMELEN(tos)) \ - X(">body", TOBODY, tos = (cell_t) TOBODY(tos)) \ XV(internals, "'heap", THEAP, DUP; tos = (cell_t) &g_sys->heap) \ Y(current, DUP; tos = (cell_t) &g_sys->current) \ XV(internals, "'context", TCONTEXT, DUP; tos = (cell_t) &g_sys->context) \ @@ -89,8 +80,5 @@ XV(internals, "'argc", ARGC, DUP; tos = (cell_t) &g_sys->argc) \ XV(internals, "'argv", ARGV, DUP; tos = (cell_t) &g_sys->argv) \ XV(internals, "'runner", RUNNER, DUP; tos = (cell_t) &g_sys->runner) \ - YV(internals, fill32, cell_t c = tos; DROP; cell_t n = tos; DROP; \ - uint32_t *a = (uint32_t *) tos; DROP; \ - for (;n;--n) *a++ = c) \ Y(context, DUP; tos = (cell_t) (g_sys->context + 1)) \ Y(latestxt, DUP; tos = (cell_t) g_sys->latestxt) diff --git a/common/extra1.fs b/common/tier1a_forth.fs similarity index 83% rename from common/extra1.fs rename to common/tier1a_forth.fs index 211082a..6864c1b 100644 --- a/common/extra1.fs +++ b/common/tier1a_forth.fs @@ -54,8 +54,6 @@ ( Dictionary ) : here ( -- a ) 'sys @ ; : allot ( n -- ) 'sys +! ; -: aligned ( a -- a ) cell 1 - dup >r + r> invert and ; -: align here aligned here - allot ; : , ( n -- ) here ! cell allot ; : c, ( ch -- ) here c! 1 allot ; @@ -68,6 +66,7 @@ sys: 'tib sys: #tib sys: >in sys: state sys: base sys: 'argc sys: 'argv sys: 'runner +drop : context ( -- a ) 'context @ cell+ ; : latestxt ( -- xt ) 'latestxt @ ; @@ -77,15 +76,6 @@ : ' bl parse 2dup find dup >r -rot r> 0= 'notfound @ execute 2drop ; : literal aliteral ; immediate -( Dictionary Format ) -: >flags& ( xt -- a ) cell - ; : >flags ( xt -- flags ) >flags& c@ ; -: >name-length ( xt -- n ) >flags& 1+ c@ ; -: >params ( xt -- n ) >flags& 2 + sw@ $ffff and ; -: >size ( xt -- n ) dup >params cells swap >name-length aligned + 3 cells + ; -: >link& ( xt -- a ) 2 cells - ; : >link ( xt -- a ) >link& @ ; -: >name ( xt -- a n ) dup >name-length swap >link& over aligned - swap ; -: >body ( xt -- a ) dup @ [ ' >flags @ ] literal = 2 + cells + ; - : f= ( r r -- f ) f- f0= ; : f< ( r r -- f ) f- f0< ; : f> ( r r -- f ) fswap f< ; diff --git a/common/extra2.fs b/common/tier1b_forth.fs similarity index 100% rename from common/extra2.fs rename to common/tier1b_forth.fs diff --git a/common/extra3.fs b/common/tier1c_forth.fs similarity index 93% rename from common/extra3.fs rename to common/tier1c_forth.fs index b76f341..818abf1 100644 --- a/common/extra3.fs +++ b/common/tier1c_forth.fs @@ -18,8 +18,6 @@ 3.14159265359e fconstant pi -: fill32 ( a n v ) swap >r swap r> 0 ?do 2dup ! cell+ loop 2drop ; - ( Transfer internals that are extra opcodes ) internals definitions transfer{ diff --git a/common/tier2_forth.fs b/common/tier2_forth.fs new file mode 100644 index 0000000..0a75c9f --- /dev/null +++ b/common/tier2_forth.fs @@ -0,0 +1,27 @@ +\ Copyright 2022 Bradley D. Nelson +\ +\ Licensed under the Apache License, Version 2.0 (the "License"); +\ you may not use this file except in compliance with the License. +\ You may obtain a copy of the License at +\ +\ http://www.apache.org/licenses/LICENSE-2.0 +\ +\ Unless required by applicable law or agreed to in writing, software +\ distributed under the License is distributed on an "AS IS" BASIS, +\ WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +\ See the License for the specific language governing permissions and +\ limitations under the License. + +( Dictionary Format ) +: >flags& ( xt -- a ) cell - ; : >flags ( xt -- flags ) >flags& c@ ; +: >name-length ( xt -- n ) >flags& 1+ c@ ; +: >params ( xt -- n ) >flags& 2 + sw@ $ffff and ; +: >size ( xt -- n ) dup >params cells swap >name-length aligned + 3 cells + ; +: >link& ( xt -- a ) 2 cells - ; : >link ( xt -- a ) >link& @ ; +: >name ( xt -- a n ) dup >name-length swap >link& over aligned - swap ; +: >body ( xt -- a ) dup @ [ ' >flags @ ] literal = 2 + cells + ; + +: aligned ( a -- a ) cell 1 - dup >r + r> invert and ; +: align here aligned here - allot ; + +: fill32 ( a n v ) swap >r swap r> 0 ?do 2dup ! cell+ loop 2drop ; diff --git a/common/tier2_opcodes.h b/common/tier2_opcodes.h new file mode 100644 index 0000000..0b8b752 --- /dev/null +++ b/common/tier2_opcodes.h @@ -0,0 +1,27 @@ +// Copyright 2021 Bradley D. Nelson +// +// Licensed under the Apache License, Version 2.0 (the "License"); +// you may not use this file except in compliance with the License. +// You may obtain a copy of the License at +// +// http://www.apache.org/licenses/LICENSE-2.0 +// +// Unless required by applicable law or agreed to in writing, software +// distributed under the License is distributed on an "AS IS" BASIS, +// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +// See the License for the specific language governing permissions and +// limitations under the License. + +#define TIER2_OPCODE_LIST \ + X(">flags", TOFLAGS, tos = *TOFLAGS(tos)) \ + X(">params", TOPARAMS, tos = *TOPARAMS(tos)) \ + X(">size", TOSIZE, tos = TOSIZE(tos)) \ + X(">link&", TOLINKAT, tos = (cell_t) TOLINK(tos)) \ + X(">link", TOLINK, tos = *TOLINK(tos)) \ + X(">name", TONAME, DUP; *sp = (cell_t) TONAME(tos); tos = *TONAMELEN(tos)) \ + X(">body", TOBODY, tos = (cell_t) TOBODY(tos)) \ + Y(aligned, tos = CELL_ALIGNED(tos)) \ + Y(align, g_sys->heap = (cell_t *) CELL_ALIGNED(g_sys->heap)) \ + YV(internals, fill32, cell_t c = tos; DROP; cell_t n = tos; DROP; \ + uint32_t *a = (uint32_t *) tos; DROP; \ + for (;n;--n) *a++ = c) diff --git a/esp32/sim_main.cpp b/esp32/sim_main.cpp index 38bfd9b..2198ac0 100644 --- a/esp32/sim_main.cpp +++ b/esp32/sim_main.cpp @@ -13,8 +13,9 @@ // limitations under the License. #include "esp32/options.h" -#include "common/opcodes.h" -#include "common/extra_opcodes.h" +#include "common/tier0_opcodes.h" +#include "common/tier1_opcodes.h" +#include "common/tier2_opcodes.h" #include "common/floats.h" #include "common/calling.h" diff --git a/esp32/template.ino b/esp32/template.ino index 0a57b44..eb9f6b7 100644 --- a/esp32/template.ino +++ b/esp32/template.ino @@ -20,8 +20,9 @@ */ {{options}} -{{opcodes}} -{{extra_opcodes}} +{{tier0_opcodes}} +{{tier1_opcodes}} +{{tier2_opcodes}} {{floats}} {{calling}} {{builtins.h}} diff --git a/posix/main.c b/posix/main.c index 9e0374f..fdd569d 100644 --- a/posix/main.c +++ b/posix/main.c @@ -15,8 +15,9 @@ #include #include -#include "common/opcodes.h" -#include "common/extra_opcodes.h" +#include "common/tier0_opcodes.h" +#include "common/tier1_opcodes.h" +#include "common/tier2_opcodes.h" #include "common/floats.h" #include "common/calling.h" #include "common/calls.h" diff --git a/site/internals.html b/site/internals.html index 03236f7..d0a4ee5 100644 --- a/site/internals.html +++ b/site/internals.html @@ -98,7 +98,7 @@ additional non-essential extra opcodes were added in place of high-level words.

-See opcodes.h. +See tier0_opcodes.h.

diff --git a/web/dump_web_opcodes.c b/web/dump_web_opcodes.c index 2698688..206c03f 100644 --- a/web/dump_web_opcodes.c +++ b/web/dump_web_opcodes.c @@ -19,7 +19,8 @@ #define SSMOD_FUNC SSMOD_FUNC #define COMMA COMMA -#include "common/opcodes.h" +#include "common/tier0_opcodes.h" +#include "common/tier1_opcodes.h" #include "common/floats.h" #include "common/bits.h" @@ -32,7 +33,8 @@ enum { #define Z(flags, name, op, code) OP_ ## op, PLATFORM_OPCODE_LIST - OPCODE_LIST + TIER1_OPCODE_LIST + TIER0_OPCODE_LIST #undef Z }; @@ -54,7 +56,8 @@ int main(int argc, char *argv[]) { #define Z(flags, name, op, code) \ printf(" case %d: // %s\n %s; break;\n", OP_ ## op, name, #code); PLATFORM_OPCODE_LIST - OPCODE_LIST + TIER1_OPCODE_LIST + TIER0_OPCODE_LIST #undef Z } else if (argc == 2 && strcmp(argv[1], "dict") == 0) { #define V(name) \ @@ -67,7 +70,8 @@ int main(int argc, char *argv[]) { ((VOC_ ## flags >> 8) & 0xff) | BUILTIN_MARK, \ (VOC_ ## flags & 0xff), OP_ ## op); PLATFORM_OPCODE_LIST - OPCODE_LIST + TIER1_OPCODE_LIST + TIER0_OPCODE_LIST #undef Z } else if (argc == 2 && strcmp(argv[1], "sys") == 0) { G_SYS *g_sys = 0; diff --git a/web/fuse_web.js b/web/fuse_web.js index 0f401dd..b210947 100755 --- a/web/fuse_web.js +++ b/web/fuse_web.js @@ -37,19 +37,29 @@ cases = ReplaceAll(cases, 'DUP;', '*++sp = tos;'); cases = ReplaceAll(cases, 'tos += sizeof(float)', 'tos = (tos + 4)|0'); cases = ReplaceAll(cases, 'tos *= sizeof(float)', 'tos = (tos * 4)|0'); +cases = ReplaceAll(cases, 'tos += sizeof(cell_t)', 'tos = (tos + 4)|0'); +cases = ReplaceAll(cases, 'tos *= sizeof(cell_t)', 'tos = (tos * 4)|0'); cases = ReplaceAll(cases, 'tos += *sp--', 'tos = (tos + *sp)|0; --sp'); +cases = ReplaceAll(cases, 'tos = (*sp--) - tos', 'tos = (*sp - tos)|0; --sp'); +cases = ReplaceAll(cases, 'tos *= *sp--', 'tos = imul(tos, *sp); --sp'); +cases = ReplaceAll(cases, ' -tos', ' (-tos)|0'); +cases = ReplaceAll(cases, '++tos', 'tos = (tos + 1)|0'); +cases = ReplaceAll(cases, '--tos', 'tos = (tos - 1)|0'); + cases = ReplaceAll(cases, /tos (.)= /, 'tos = tos $1 '); cases = ReplaceAll(cases, '*((cell_t *) *ip) = ', 'i32[i32[ip>>2]>>2] = '); cases = ReplaceAll(cases, /[*](.)p[+][+]/, '*$1p, ++$1p'); cases = ReplaceAll(cases, /[*](.)p[-][-]/, '*$1p, --$1p'); cases = ReplaceAll(cases, /[*][+][+](.)p/, '++$1p, *$1p'); cases = ReplaceAll(cases, '*(cell_t *) tos = ', 'i32[tos>>2] = '); +cases = ReplaceAll(cases, '((cell_t *) tos)[1] = ', 'i32[(tos + 4)>>2] = '); cases = ReplaceAll(cases, '*(int32_t *) tos = ', 'i32[tos>>2] = '); cases = ReplaceAll(cases, '*(int16_t *) tos = ', 'i16[tos>>1] = '); cases = ReplaceAll(cases, '*(uint8_t *) tos = ', 'u8[tos] = '); cases = ReplaceAll(cases, '*(float *) tos = ', 'f32[tos>>2] = '); cases = ReplaceAll(cases, '*(cell_t *) tos', '(i32[tos>>2]|0)'); +cases = ReplaceAll(cases, '((cell_t *) tos)[1]', '(i32[(tos + 4)>>2]|0)'); cases = ReplaceAll(cases, '*(int32_t *) tos', '(i32[tos>>2]|0)'); cases = ReplaceAll(cases, '*(uint32_t *) tos', '(i32[tos>>2]>>>0)'); cases = ReplaceAll(cases, '*(int16_t *) tos', '(i16[tos>>1]|0)'); @@ -90,12 +100,15 @@ cases = ReplaceAll(cases, '(float *) ', ''); cases = ReplaceAll(cases, '(float) ', ''); cases = ReplaceAll(cases, '0.0f', 'fround(0.0)'); cases = ReplaceAll(cases, '1.0f', 'fround(1.0)'); +cases = ReplaceAll(cases, "' '", '32'); +cases = ReplaceAll(cases, "'\\n'", '10'); cases = ReplaceAll(cases, /[(]ucell_t[)] ([^ ;)]+)/, '($1>>>0)'); cases = ReplaceAll(cases, '*(w + 4)', '(i32[(w + 4)>>2]|0)'); cases = ReplaceAll(cases, 'w + 4 * 2', '(w+8)|0'); cases = ReplaceAll(cases, 'w + 4', '(w+4)|0'); +cases = ReplaceAll(cases, '(g_sys->context + 1)', '(i32[g_sys_context>>2]|0 + 4)|0'); cases = ReplaceAll(cases, '&g_sys->builtins->code', '((i32[g_sys_builtins>>2] + 8)|0)'); cases = ReplaceAll(cases, /[&]g_sys[-][>]([A-Za-z_]+)/, 'g_sys_$1'); cases = ReplaceAll(cases, /g_sys[-][>]([A-Za-z_]+) [=] /, 'i32[g_sys_$1>>2] = '); diff --git a/windows/interp.h b/windows/interp.h index 9d80c87..0dbb637 100644 --- a/windows/interp.h +++ b/windows/interp.h @@ -19,8 +19,9 @@ enum { #define Z(flags, name, op, code) OP_ ## op, PLATFORM_OPCODE_LIST - EXTRA_OPCODE_LIST - OPCODE_LIST + TIER2_OPCODE_LIST + TIER1_OPCODE_LIST + TIER0_OPCODE_LIST #undef Z }; @@ -30,8 +31,9 @@ static cell_t *forth_run(cell_t *init_rp) { name, ((VOC_ ## flags >> 8) & 0xff) | BUILTIN_MARK, sizeof(name) - 1, \ (VOC_ ## flags & 0xff), (void *) OP_ ## op, PLATFORM_OPCODE_LIST - EXTRA_OPCODE_LIST - OPCODE_LIST + TIER2_OPCODE_LIST + TIER1_OPCODE_LIST + TIER0_OPCODE_LIST #undef Z 0, 0, 0, }; @@ -51,8 +53,9 @@ work: switch (*(cell_t *) w & 0xff) { #define Z(flags, name, op, code) case OP_ ## op: { code; } NEXT; PLATFORM_OPCODE_LIST - EXTRA_OPCODE_LIST - OPCODE_LIST + TIER2_OPCODE_LIST + TIER1_OPCODE_LIST + TIER0_OPCODE_LIST #undef Z } } diff --git a/windows/main.c b/windows/main.c index 3c620c0..1fd6eed 100644 --- a/windows/main.c +++ b/windows/main.c @@ -27,8 +27,9 @@ if (*sp < 0) { *sp += tos; tos = b - 1; } else { tos = b; } #endif -#include "common/opcodes.h" -#include "common/extra_opcodes.h" +#include "common/tier0_opcodes.h" +#include "common/tier1_opcodes.h" +#include "common/tier2_opcodes.h" #include "common/floats.h" #include "common/calling.h" #include "common/calls.h"