refactor: improve thing types

Change thing_t enumeration to thing_type structure.

Closes: #30
This commit is contained in:
2026-06-29 20:34:42 +02:00
parent 8466902281
commit 6ab9254746
5 changed files with 121 additions and 105 deletions
+2 -2
View File
@@ -91,7 +91,7 @@ void executor::step() {
switch (instr) {
case instruction_t::NoOperation: break;
case instruction_t::PushB2I: {
push_thing({ thing_t::Int32, m_context->thing_alloc() })->int32() = frame.mod->byte(frame.position++);
push_thing({ IntType, m_context->thing_alloc() })->get<int_t>() = frame.mod->byte(frame.position++);
} break;
case instruction_t::Drop: {
pop_thing();
@@ -181,7 +181,7 @@ void executor::step() {
case instruction_t::JumpNotZero: {
byte offset = frame.mod->byte(frame.position++);
auto cond = pop_thing();
if (cond->int32() != 0) frame.position += (std::int8_t)offset;
if (cond->get<int_t>() != 0) frame.position += (std::int8_t)offset;
} break;
case instruction_t::Return: {
pop_frame();
+2 -8
View File
@@ -24,14 +24,8 @@ int main(void) {
furvm::mod_h furlangModule = context->emplace_module("furlang");
furvm::function_h printFunc = furlangModule->emplace_function("print", 1, "print");
furlangModule->set_native_function("print", [](furvm::executor& executor) {
furvm::thing_h thing = executor.load_thing(0);
switch (thing->type()) {
case furvm::thing_t::Int32: {
std::cout << thing->int32() << '\n';
} break;
}
});
furlangModule->set_native_function("print",
[](furvm::executor& executor) { std::cout << executor.load_thing(0)->get<furvm::int_t>() << '\n'; });
furvm::mod_h mainModule = context->emplace_module("main", s_bytecode.begin(), s_bytecode.end());
furvm::function_h mainFunc = mainModule->emplace_function("main", 0, 0);