@@ -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");
|
static_assert(sizeof(var) == 2, "sizeof(furvm::variable_t) has changed");
|
||||||
} break;
|
} break;
|
||||||
case furlang::ir::operand_t::Integer: {
|
case furlang::ir::operand_t::Integer: {
|
||||||
mod.bytecode().push_back(static_cast<furvm::byte>(furvm::instruction_t::PushB2I));
|
mod.bytecode().push_back(static_cast<furvm::byte>(furvm::instruction_t::PushS32));
|
||||||
mod.bytecode().push_back(operand.integer());
|
mod.bytecode().push_back(operand.integer());
|
||||||
} break;
|
} break;
|
||||||
case furlang::ir::operand_t::Variable:
|
case furlang::ir::operand_t::Variable:
|
||||||
|
|||||||
@@ -12,11 +12,34 @@ enum class instruction_t : byte {
|
|||||||
NoOperation = 0,
|
NoOperation = 0,
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @brief Pushes an integer from a byte onto the stack.
|
* @brief Pushes an s8 integer from a byte onto the stack.
|
||||||
*
|
|
||||||
* Pushes an integer constructed from a next 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.
|
* @brief Pushes a constant onto the stack.
|
||||||
|
|||||||
+27
-3
@@ -133,9 +133,33 @@ void executor::step() {
|
|||||||
instruction_t instr = static_cast<instruction_t>((*frame.mod).byte(frame.position++));
|
instruction_t instr = static_cast<instruction_t>((*frame.mod).byte(frame.position++));
|
||||||
switch (instr) {
|
switch (instr) {
|
||||||
case instruction_t::NoOperation: break;
|
case instruction_t::NoOperation: break;
|
||||||
case instruction_t::PushB2I: {
|
case instruction_t::PushS8: {
|
||||||
push_thing({ (struct thing_type){ thing_type::S32 }, m_context->thing_alloc() })->get<int>() =
|
push_thing({ (struct thing_type){ thing_type::S8 }, m_context->thing_alloc() })->get<thing_type::s8>() =
|
||||||
frame.mod->byte(frame.position++);
|
static_cast<thing_type::s8>(frame.mod->byte(frame.position++));
|
||||||
|
} break;
|
||||||
|
case instruction_t::PushU8: {
|
||||||
|
push_thing({ (struct thing_type){ thing_type::U8 }, m_context->thing_alloc() })->get<thing_type::u8>() =
|
||||||
|
static_cast<thing_type::u8>(frame.mod->byte(frame.position++));
|
||||||
|
} break;
|
||||||
|
case instruction_t::PushS16: {
|
||||||
|
thing_type::u16 value = frame.mod->byte(frame.position++);
|
||||||
|
value |= static_cast<thing_type::u16>(frame.mod->byte(frame.position++) << 8);
|
||||||
|
push_thing({ (struct thing_type){ thing_type::S16 }, m_context->thing_alloc() })->get<thing_type::s16>() =
|
||||||
|
static_cast<thing_type::s16>(value);
|
||||||
|
} break;
|
||||||
|
case instruction_t::PushU16: {
|
||||||
|
thing_type::u16 value = frame.mod->byte(frame.position++);
|
||||||
|
value |= static_cast<thing_type::u16>(frame.mod->byte(frame.position++) << 8);
|
||||||
|
push_thing({ (struct thing_type){ thing_type::U16 }, m_context->thing_alloc() })->get<thing_type::u16>() =
|
||||||
|
value;
|
||||||
|
} break;
|
||||||
|
case instruction_t::PushS32: {
|
||||||
|
push_thing({ (struct thing_type){ thing_type::S32 }, m_context->thing_alloc() })->get<thing_type::s32>() =
|
||||||
|
static_cast<thing_type::s32>(frame.mod->byte(frame.position++));
|
||||||
|
} break;
|
||||||
|
case instruction_t::PushU32: {
|
||||||
|
push_thing({ (struct thing_type){ thing_type::U32 }, m_context->thing_alloc() })->get<thing_type::u32>() =
|
||||||
|
static_cast<thing_type::u32>(frame.mod->byte(frame.position++));
|
||||||
} break;
|
} break;
|
||||||
case instruction_t::Array: {
|
case instruction_t::Array: {
|
||||||
mod_type_id typeId = static_cast<mod_type_id>(frame.mod->byte(frame.position)) |
|
mod_type_id typeId = static_cast<mod_type_id>(frame.mod->byte(frame.position)) |
|
||||||
|
|||||||
Reference in New Issue
Block a user