aboutsummaryrefslogtreecommitdiffstats
path: root/state.cpp
diff options
context:
space:
mode:
authorClyne Sullivan <clyne@bitgloo.com>2023-02-26 19:31:00 -0500
committerClyne Sullivan <clyne@bitgloo.com>2023-02-26 19:31:00 -0500
commitc5db61d59fd75b786bd3e5a57a163d37df20a8b9 (patch)
tree74d00b7f264c9f9ef287a36f602cf8ce06450ea3 /state.cpp
parent42d64c6da242bd100533ab0c31c3835b50fa1b2d (diff)
packed literals; faster execution
Diffstat (limited to 'state.cpp')
-rw-r--r--state.cpp29
1 files changed, 14 insertions, 15 deletions
diff --git a/state.cpp b/state.cpp
index 8e0f78d..ea6c601 100644
--- a/state.cpp
+++ b/state.cpp
@@ -33,25 +33,24 @@ void State::compiling(bool yes)
State::Error State::execute(Addr addr)
{
- auto stat = setjmp(jmpbuf);
- if (!stat) {
- if (addr < CoreWords::WordCount) {
- CoreWords::run(addr, *this);
- ip = 0;
- } else {
- auto ins = addr;
+ auto stat = static_cast<State::Error>(setjmp(jmpbuf));
+
+ if (stat == State::Error::none) {
+ CoreWords::run(addr, *this);
- for (;;) {
- CoreWords::run(ins, *this);
- ins = dict.read(ip);
- }
+ if (ip >= Dictionary::Begin) {
+ // longjmp will exit this loop.
+ for (;;)
+ CoreWords::run(dict.read(ip), *this);
+ } else {
+ // addr was a CoreWord, all done now.
+ ip = 0;
}
- } else {
- auto err = static_cast<State::Error>(stat);
- return err == State::Error::exit ? State::Error::none : err;
+ } else if (stat == State::Error::exit) {
+ stat = State::Error::none;
}
- return State::Error::none;
+ return stat;
}
std::size_t State::size() const noexcept