From 4b50a9fafe793abf3c2c16e203072a98a0702814 Mon Sep 17 00:00:00 2001 From: Clyne Sullivan Date: Thu, 9 Nov 2023 14:48:49 -0500 Subject: move main execution to State; bring back verify() --- libalee/state.cpp | 26 ++++++++++++++++++++++++-- 1 file changed, 24 insertions(+), 2 deletions(-) (limited to 'libalee/state.cpp') diff --git a/libalee/state.cpp b/libalee/state.cpp index 6e12999..34e4936 100644 --- a/libalee/state.cpp +++ b/libalee/state.cpp @@ -42,17 +42,39 @@ void State::load(const State::Context& ctx) context = ctx; } +void State::execute1(Addr ins) +{ +repeat: + if (ins >= Dictionary::Begin) [[likely]] { + // Subroutine call + pushr(context.ip); + context.ip = ins; + } else { + if (ins < CoreWords::WordCount) { + if (CoreWords::run(ins, *this)) [[unlikely]] { + ins = pop(); + goto repeat; + } + } else { + push(static_cast(ins - CoreWords::WordCount)); + } + + context.ip += sizeof(Cell); + } +} + Error State::execute(Addr addr) { auto stat = static_cast(setjmp(context.jmpbuf)); if (stat == Error::none) { - CoreWords::run(addr, *this); + context.ip = 0; + execute1(addr); if (context.ip >= Dictionary::Begin) { // longjmp will exit this loop. for (;;) - CoreWords::run(dict.read(context.ip), *this); + execute1(dict.read(context.ip)); } else { // addr was a CoreWord, all done now. context.ip = 0; -- cgit v1.2.3