From 5632b65540687ac89f154fde1acae023ecd894d2 Mon Sep 17 00:00:00 2001 From: Clyne Sullivan Date: Mon, 20 Feb 2023 19:28:46 -0500 Subject: [PATCH] fix execution lookup; add unloop --- compat.txt | 2 +- core.fth | 3 ++- corewords.cpp | 9 ++------- corewords.hpp | 2 +- state.cpp | 6 ++++-- 5 files changed, 10 insertions(+), 12 deletions(-) diff --git a/compat.txt b/compat.txt index ae1b2db..6891a2d 100644 --- a/compat.txt +++ b/compat.txt @@ -123,7 +123,7 @@ yes 6.1.2310 TYPE 6.1.2340 U< 6.1.2360 UM* 6.1.2370 UM/MOD - 6.1.2380 UNLOOP +yes 6.1.2380 UNLOOP yes 6.1.2390 UNTIL yes 6.1.2410 VARIABLE yes 6.1.2430 WHILE diff --git a/core.fth b/core.fth index 7164597..3f10371 100644 --- a/core.fth +++ b/core.fth @@ -66,9 +66,10 @@ : until ['] _jmp0 , , drop ; imm : do postpone 2>r here ; imm +: unloop postpone 2r> ['] 2drop , ; imm : +loop postpone 2r> ['] rot , ['] + , ['] 2dup , postpone 2>r ['] - , ['] 0= , ['] _jmp0 , , - postpone 2r> ['] 2drop , ; imm + postpone unloop ; imm : loop 1 postpone literal postpone +loop ; imm : i postpone r@ ; imm diff --git a/corewords.cpp b/corewords.cpp index de71f3e..3fc5f51 100644 --- a/corewords.cpp +++ b/corewords.cpp @@ -321,14 +321,9 @@ Func CoreWords::find(State& state, Word word) return i >= 0 ? get(i & ~Compiletime) : nullptr; } -bool CoreWords::run(int i, State& state) +void CoreWords::run(int i, State& state) { - i &= ~Compiletime; - - bool isaword = i >= 0 && i < WordCount; - if (isaword) + if (i >= 0 && i < WordCount) get(i)(state); - - return isaword; } diff --git a/corewords.hpp b/corewords.hpp index 0c00100..126878e 100644 --- a/corewords.hpp +++ b/corewords.hpp @@ -37,7 +37,7 @@ public: static int findi(std::string_view); static int findi(State&, Word); static Func find(State&, Word); - static bool run(int, State&); + static void run(int, State&); private: // Ends with '\0': regular word diff --git a/state.cpp b/state.cpp index 2f1990b..16a573e 100644 --- a/state.cpp +++ b/state.cpp @@ -40,7 +40,7 @@ void State::compiling(bool yes) void State::execute(Addr addr) { - if (addr < Dictionary::Begin) { + if (addr < CoreWords::WordCount) { // Must be a core-word CoreWords::run(addr, *this); } else { @@ -51,7 +51,9 @@ void State::execute(Addr addr) ip += sizeof(Cell); const auto ins = dict.read(ip); - if (!CoreWords::run(ins, *this)) { + if (ins < CoreWords::WordCount) { + CoreWords::run(ins, *this); + } else { pushr(ip); ip = ins - sizeof(Cell); }