feat: introduce sizeof instruction

Closes: #34
This commit is contained in:
2026-07-05 22:33:15 +02:00
parent 642d57622a
commit ee9eadeea8
11 changed files with 32 additions and 2 deletions
+12
View File
@@ -175,6 +175,18 @@ void executor::step() {
default: throw std::runtime_error("unreachable");
}
} break;
case instruction_t::Sizeof: {
auto thing = pop_thing()->resolve();
auto ptr = push_thing({ *m_context->at("core")->type_at(3), m_context, m_context->thing_alloc() });
auto type = furvm::thing<>::resolve_type(thing.type(), m_context);
switch (type->t) {
case type_t::Primitive: ptr->get<long_t>() = static_cast<long_t>(type->primitive); break;
case type_t::List: ptr->get<long_t>() = thing.get<list_t>().size; break;
case type_t::Reference:
case type_t::Import:
default: throw std::runtime_error("unreachable");
}
} break;
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);