diff --git a/furc/src/back/furvm.cpp b/furc/src/back/furvm.cpp index 658b641..0a10701 100644 --- a/furc/src/back/furvm.cpp +++ b/furc/src/back/furvm.cpp @@ -170,7 +170,7 @@ void furvm_generator::generate_operand(furvm::mod& mod, function_context& ctx, c static_assert(sizeof(var) == 2, "sizeof(furvm::variable_t) has changed"); } break; case furlang::ir::operand_t::Integer: { - mod.bytecode().push_back(static_cast(furvm::instruction_t::PushB2I)); + mod.bytecode().push_back(static_cast(furvm::instruction_t::PushS32)); mod.bytecode().push_back(operand.integer()); } break; case furlang::ir::operand_t::Variable: diff --git a/furvm/include/furvm/instruction.hpp b/furvm/include/furvm/instruction.hpp index 958af29..be6cba0 100644 --- a/furvm/include/furvm/instruction.hpp +++ b/furvm/include/furvm/instruction.hpp @@ -12,11 +12,34 @@ enum class instruction_t : byte { NoOperation = 0, /** - * @brief Pushes an integer from a byte onto the stack. - * - * Pushes an integer constructed from a next byte onto the stack. + * @brief Pushes an s8 integer from a byte onto the stack. */ - PushB2I, + PushS8, + + /** + * @brief Pushes an u8 integer from a byte onto the stack. + */ + PushU8, + + /** + * @brief Pushes an s16 integer from two byte onto the stack. + */ + PushS16, + + /** + * @brief Pushes an u16 integer from two byte onto the stack. + */ + PushU16, + + /** + * @brief Pushes an s32 integer from a byte onto the stack. + */ + PushS32, + + /** + * @brief Pushes an u32 integer from a byte onto the stack. + */ + PushU32, /** * @brief Pushes a constant onto the stack. diff --git a/furvm/src/executor.cpp b/furvm/src/executor.cpp index f58d4d1..332030e 100644 --- a/furvm/src/executor.cpp +++ b/furvm/src/executor.cpp @@ -133,9 +133,33 @@ void executor::step() { instruction_t instr = static_cast((*frame.mod).byte(frame.position++)); switch (instr) { case instruction_t::NoOperation: break; - case instruction_t::PushB2I: { - push_thing({ (struct thing_type){ thing_type::S32 }, m_context->thing_alloc() })->get() = - frame.mod->byte(frame.position++); + case instruction_t::PushS8: { + push_thing({ (struct thing_type){ thing_type::S8 }, m_context->thing_alloc() })->get() = + static_cast(frame.mod->byte(frame.position++)); + } break; + case instruction_t::PushU8: { + push_thing({ (struct thing_type){ thing_type::U8 }, m_context->thing_alloc() })->get() = + static_cast(frame.mod->byte(frame.position++)); + } break; + case instruction_t::PushS16: { + thing_type::u16 value = frame.mod->byte(frame.position++); + value |= static_cast(frame.mod->byte(frame.position++) << 8); + push_thing({ (struct thing_type){ thing_type::S16 }, m_context->thing_alloc() })->get() = + static_cast(value); + } break; + case instruction_t::PushU16: { + thing_type::u16 value = frame.mod->byte(frame.position++); + value |= static_cast(frame.mod->byte(frame.position++) << 8); + push_thing({ (struct thing_type){ thing_type::U16 }, m_context->thing_alloc() })->get() = + value; + } break; + case instruction_t::PushS32: { + push_thing({ (struct thing_type){ thing_type::S32 }, m_context->thing_alloc() })->get() = + static_cast(frame.mod->byte(frame.position++)); + } break; + case instruction_t::PushU32: { + push_thing({ (struct thing_type){ thing_type::U32 }, m_context->thing_alloc() })->get() = + static_cast(frame.mod->byte(frame.position++)); } break; case instruction_t::Array: { mod_type_id typeId = static_cast(frame.mod->byte(frame.position)) |