feat(furvm): introduce jump and jump not zero instructions

This commit is contained in:
2026-06-14 23:49:29 +02:00
parent e809eb82c7
commit eec25e3aea
2 changed files with 25 additions and 0 deletions
+15
View File
@@ -86,6 +86,21 @@ enum class instruction_t : byte {
*/
Call,
/**
* @brief Jumps to an instruction relative to the current instruction.
*
* Jumps to an instruction relative to the current instruction with offset denoted by next byte.
*/
Jump,
/**
* @brief Jumps to an instruction relative to the current instruction if top thing on the stack is not zero.
*
* Jumps to an instruction relative to the current instruction with offset denoted by next byte if the top thing on
* the stack is not zero (is true).
*/
JumpNotZero,
/**
* @brief Pops the current call frame.
*/
+10
View File
@@ -139,11 +139,13 @@ void executor::step() {
case instruction_t::Load: {
variable_t variable = static_cast<std::uint16_t>(frame.mod->byte(frame.position)) |
(static_cast<std::uint16_t>(frame.mod->byte(frame.position + 1)) << 8);
frame.position += 2;
push_thing(load_thing(variable));
} break;
case instruction_t::Store: {
variable_t variable = static_cast<std::uint16_t>(frame.mod->byte(frame.position)) |
(static_cast<std::uint16_t>(frame.mod->byte(frame.position + 1)) << 8);
frame.position += 2;
store_thing(variable, std::move(pop_thing()));
} break;
case instruction_t::Call: {
@@ -161,6 +163,14 @@ void executor::step() {
} break;
}
} break;
case instruction_t::Jump: {
frame.position += frame.mod->byte(frame.position++);
} break;
case instruction_t::JumpNotZero: {
byte offset = frame.mod->byte(frame.position++);
auto cond = pop_thing();
if (cond->int32() != 0) frame.position += offset;
} break;
case instruction_t::Return: {
pop_frame();
if (m_frames.empty()) m_flags = m_flags | executor_flags::Done;