feat(furvm): introduce length of operator

Closes: #54
This commit is contained in:
2026-07-11 23:17:59 +02:00
parent cd715ae779
commit e1b75ccc8e
4 changed files with 19 additions and 7 deletions
+9 -3
View File
@@ -245,13 +245,19 @@ void executor::step() {
break;
case thing_type::Ptr: size->get<thing_type::u64>() = static_cast<thing_type::u64>(sizeof(void*)); break;
case thing_type::Array:
size->get<thing_type::u64>() = static_cast<thing_type::u64>(
(thing->type().value.array.size == 0) ? thing->get<furvm::thing<>::array>().dynamic.size
: thing->type().value.array.size);
/* TODO: Return actual memory size of the array
* By the memory size I mean the length times sizeof single element.
*/
size->get<thing_type::u64>() = thing->length();
break;
default: throw std::runtime_error("unreachable");
}
} break;
case instruction_t::Lengthof: {
auto thing = pop_thing();
auto length = push_thing({ (struct thing_type){ thing_type::U64 }, m_context->thing_alloc() });
length->get<thing_type::u64>() = thing->length();
} 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);