case 28: return op_const;
case 29: return op_if;
case 30: return op_then;
- case 31: return op_literal;
- case 32: return op_jump;
+ case 31: return op_else;
+ case 32: return op_literal;
+ case 33: return op_jump;
default: return nullptr;
}
}
{
if (state.compiling) {
const auto ifaddr = state.pop();
+ if (state.dict.read(ifaddr) == 0)
+ state.dict.write(ifaddr, state.dict.here);
+ }
+
+ return 0;
+}
+
+int CoreWords::op_else(State& state)
+{
+ if (state.compiling) {
+ const auto ifaddr = state.pop();
+ state.push(state.dict.here);
+ state.dict.add(0);
state.dict.write(ifaddr, state.dict.here);
+ } else {
+ state.ip = state.beyondip() - 1;
}
return 0;
class CoreWords
{
public:
- constexpr static std::size_t VisibleWordCount = 31; // size
+ constexpr static std::size_t VisibleWordCount = 32; // size
constexpr static auto HiddenWordLiteral = VisibleWordCount; // index
constexpr static auto HiddenWordJump = VisibleWordCount + 1; // index
constexpr static auto WordCount = HiddenWordJump + 1; // size
"=\0<\0allot\0&\0|\0"
"^\0<<\0>>\0(\0:\0"
";\1here\0imm\0const\0"
- "if\1then\1";
+ "if\1then\1else\1";
static Func get(int);
static int op_jump(State&);
static int op_if(State&);
static int op_then(State&);
+ static int op_else(State&);
};
#endif // ALEEFORTH_COREWORDS_HPP