fix execution lookup; add unloop

llvm
Clyne 2 years ago
parent bc118ad31f
commit 5632b65540
Signed by: clyne
GPG Key ID: 3267C8EBF3F9AFC7

@ -123,7 +123,7 @@ yes 6.1.2310 TYPE
6.1.2340 U< 6.1.2340 U<
6.1.2360 UM* 6.1.2360 UM*
6.1.2370 UM/MOD 6.1.2370 UM/MOD
6.1.2380 UNLOOP yes 6.1.2380 UNLOOP
yes 6.1.2390 UNTIL yes 6.1.2390 UNTIL
yes 6.1.2410 VARIABLE yes 6.1.2410 VARIABLE
yes 6.1.2430 WHILE yes 6.1.2430 WHILE

@ -66,9 +66,10 @@
: until ['] _jmp0 , , drop ; imm : until ['] _jmp0 , , drop ; imm
: do postpone 2>r here ; imm : do postpone 2>r here ; imm
: unloop postpone 2r> ['] 2drop , ; imm
: +loop postpone 2r> ['] rot , ['] + , ['] 2dup , : +loop postpone 2r> ['] rot , ['] + , ['] 2dup ,
postpone 2>r ['] - , ['] 0= , ['] _jmp0 , , postpone 2>r ['] - , ['] 0= , ['] _jmp0 , ,
postpone 2r> ['] 2drop , ; imm postpone unloop ; imm
: loop 1 postpone literal postpone +loop ; imm : loop 1 postpone literal postpone +loop ; imm
: i postpone r@ ; imm : i postpone r@ ; imm

@ -321,14 +321,9 @@ Func CoreWords::find(State& state, Word word)
return i >= 0 ? get(i & ~Compiletime) : nullptr; return i >= 0 ? get(i & ~Compiletime) : nullptr;
} }
bool CoreWords::run(int i, State& state) void CoreWords::run(int i, State& state)
{ {
i &= ~Compiletime; if (i >= 0 && i < WordCount)
bool isaword = i >= 0 && i < WordCount;
if (isaword)
get(i)(state); get(i)(state);
return isaword;
} }

@ -37,7 +37,7 @@ public:
static int findi(std::string_view); static int findi(std::string_view);
static int findi(State&, Word); static int findi(State&, Word);
static Func find(State&, Word); static Func find(State&, Word);
static bool run(int, State&); static void run(int, State&);
private: private:
// Ends with '\0': regular word // Ends with '\0': regular word

@ -40,7 +40,7 @@ void State::compiling(bool yes)
void State::execute(Addr addr) void State::execute(Addr addr)
{ {
if (addr < Dictionary::Begin) { if (addr < CoreWords::WordCount) {
// Must be a core-word // Must be a core-word
CoreWords::run(addr, *this); CoreWords::run(addr, *this);
} else { } else {
@ -51,7 +51,9 @@ void State::execute(Addr addr)
ip += sizeof(Cell); ip += sizeof(Cell);
const auto ins = dict.read(ip); const auto ins = dict.read(ip);
if (!CoreWords::run(ins, *this)) { if (ins < CoreWords::WordCount) {
CoreWords::run(ins, *this);
} else {
pushr(ip); pushr(ip);
ip = ins - sizeof(Cell); ip = ins - sizeof(Cell);
} }

Loading…
Cancel
Save