refactor: add size argument to array type

Closes: #43
This commit is contained in:
2026-07-05 23:15:40 +02:00
parent b913fc0c8b
commit 81a439b2ad
4 changed files with 90 additions and 38 deletions
+6 -3
View File
@@ -177,11 +177,14 @@ void executor::step() {
} 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 size = 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::Array: ptr->get<long_t>() = thing.get<array_t>().size; break;
case type_t::Primitive: size->get<long_t>() = static_cast<long_t>(type->primitive); break;
case type_t::Array:
size->get<long_t>() =
(type->array.size == 0) ? thing.get<array_t>().dynamic.size : static_cast<long_t>(type->array.size);
break;
case type_t::Reference:
case type_t::Import:
default: throw std::runtime_error("unreachable");
+7 -2
View File
@@ -58,7 +58,10 @@ std::ostream& mod::serialize(std::ostream& os) const {
switch (type->t) {
case type_t::Primitive: detail::serialize(os, type->primitive); break;
case type_t::Reference: throw std::runtime_error("reference type serialization is unimplemented");
case type_t::Array: detail::serialize(os, type->list.id()); break;
case type_t::Array: {
detail::serialize(os, type->array.size);
detail::serialize(os, type->array.type.id());
} break;
case type_t::Import: {
detail::serialize(os, type->imp.mod);
detail::serialize(os, type->imp.type);
@@ -128,9 +131,11 @@ mod mod::load(std::istream& is) {
} break;
case type_t::Reference: throw std::runtime_error("reference type serialization is unimplemented");
case type_t::Array: {
std::size_t size = 0;
detail::load(is, size);
type_id typeId = 0;
detail::load(is, typeId);
mod.emplace_type(id, std::make_shared<class type>(mod.type_at(typeId))).dispatch();
mod.emplace_type(id, std::make_shared<class type>(mod.type_at(typeId), size)).dispatch();
} break;
case type_t::Import: {
std::string modName;