pull exit check out of State::execute

llvm
Clyne 2 years ago
parent eb6009acbf
commit 739fce1848

@ -168,19 +168,23 @@ execute:
break; break;
case 25: // exit case 25: // exit
state.ip = state.popr(); state.ip = state.popr();
if (state.ip == 0) {
std::longjmp(state.jmpbuf,
static_cast<int>(State::Error::exit));
}
break; break;
case 26: // semic case 26: // semic
state.dict.add(findi("exit")); state.dict.add(findi("exit"));
state.compiling(false); state.compiling(false);
break; break;
case 27: // _jmp case 27: // _jmp0
state.ip = state.beyondip() - sizeof(Cell); if (state.pop()) {
break;
case 28: // _jmp0
if (state.pop())
state.beyondip(); state.beyondip();
else break;
state.ip = state.beyondip() - sizeof(Cell); }
[[fallthrough]];
case 28: // _jmp
state.ip = state.beyondip() - sizeof(Cell);
break; break;
case 29: // depth case 29: // depth
state.push(state.size()); state.push(state.size());

@ -44,8 +44,8 @@ private:
"_@\0_!\0>r\0r>\0=\0" "_@\0_!\0>r\0r>\0=\0"
"<\0&\0|\0^\0" "<\0&\0|\0^\0"
"<<\0>>\0:\0'\0execute\0" "<<\0>>\0:\0'\0execute\0"
"exit\0;\1_jmp\0" "exit\0;\1_jmp0\0_jmp\0"
"_jmp0\0depth\0_rdepth\0key\0"; "depth\0_rdepth\0key\0";
}; };
#endif // ALEEFORTH_COREWORDS_HPP #endif // ALEEFORTH_COREWORDS_HPP

@ -35,20 +35,20 @@ State::Error State::execute(Addr addr)
{ {
auto stat = setjmp(jmpbuf); auto stat = setjmp(jmpbuf);
if (!stat) { if (!stat) {
ip = 0; if (addr < CoreWords::WordCount) {
CoreWords::run(addr, *this);
} else {
auto ins = addr;
auto ins = addr; for (;;) {
for (;;) { CoreWords::run(ins, *this);
CoreWords::run(ins, *this); ip += sizeof(Cell);
ins = dict.read(ip);
if (!ip) }
break;
ip += sizeof(Cell);
ins = dict.read(ip);
} }
} else { } else {
return static_cast<State::Error>(stat); auto err = static_cast<State::Error>(stat);
return err == State::Error::exit ? State::Error::none : err;
} }
return State::Error::none; return State::Error::none;

@ -37,7 +37,8 @@ struct State
pushr, pushr,
popr, popr,
top, top,
pick pick,
exit
}; };
Addr ip = 0; Addr ip = 0;

Loading…
Cancel
Save