llvm
Clyne 2 years ago
parent 78507c65c4
commit 4accf644f6
Signed by: clyne
GPG Key ID: 4C835D6F5F30690A

@ -52,8 +52,9 @@ Func CoreWords::get(int index)
case 28: return op_const; case 28: return op_const;
case 29: return op_if; case 29: return op_if;
case 30: return op_then; case 30: return op_then;
case 31: return op_literal; case 31: return op_else;
case 32: return op_jump; case 32: return op_literal;
case 33: return op_jump;
default: return nullptr; default: return nullptr;
} }
} }
@ -273,12 +274,27 @@ int CoreWords::op_then(State& state)
{ {
if (state.compiling) { if (state.compiling) {
const auto ifaddr = state.pop(); const auto ifaddr = state.pop();
if (state.dict.read(ifaddr) == 0)
state.dict.write(ifaddr, state.dict.here); state.dict.write(ifaddr, state.dict.here);
} }
return 0; 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;
}
int CoreWords::findi(std::string_view str) int CoreWords::findi(std::string_view str)
{ {
std::size_t i; std::size_t i;

@ -27,7 +27,7 @@ int user_sys(State&);
class CoreWords class CoreWords
{ {
public: 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 HiddenWordLiteral = VisibleWordCount; // index
constexpr static auto HiddenWordJump = VisibleWordCount + 1; // index constexpr static auto HiddenWordJump = VisibleWordCount + 1; // index
constexpr static auto WordCount = HiddenWordJump + 1; // size constexpr static auto WordCount = HiddenWordJump + 1; // size
@ -47,7 +47,7 @@ private:
"=\0<\0allot\0&\0|\0" "=\0<\0allot\0&\0|\0"
"^\0<<\0>>\0(\0:\0" "^\0<<\0>>\0(\0:\0"
";\1here\0imm\0const\0" ";\1here\0imm\0const\0"
"if\1then\1"; "if\1then\1else\1";
static Func get(int); static Func get(int);
@ -84,6 +84,7 @@ private:
static int op_jump(State&); static int op_jump(State&);
static int op_if(State&); static int op_if(State&);
static int op_then(State&); static int op_then(State&);
static int op_else(State&);
}; };
#endif // ALEEFORTH_COREWORDS_HPP #endif // ALEEFORTH_COREWORDS_HPP

Loading…
Cancel
Save