From b913fc0c8bb6c5afde1630da3c0f8447d1ed27ad Mon Sep 17 00:00:00 2001 From: CHatingPython Date: Sun, 5 Jul 2026 22:41:53 +0200 Subject: [PATCH] refactor: rename list to array Closes: #42 --- furvm/include/furvm/thing.hpp | 22 +++++++++++----------- furvm/include/furvm/type.hpp | 22 +++++++++++----------- furvm/src/executor.cpp | 6 +++--- furvm/src/module.cpp | 4 ++-- 4 files changed, 27 insertions(+), 27 deletions(-) diff --git a/furvm/include/furvm/thing.hpp b/furvm/include/furvm/thing.hpp index 3a56d5d..2510048 100644 --- a/furvm/include/furvm/thing.hpp +++ b/furvm/include/furvm/thing.hpp @@ -100,8 +100,8 @@ public: case type_t::Reference: { std::memcpy(res.m_data, m_data, m_size); } break; - case type_t::List: { - copy_list(resolve_type(*m_type->list, m_modules), res.get(), get()); + case type_t::Array: { + copy_list(resolve_type(*m_type->list, m_modules), res.get(), get()); } break; case type_t::Import: throw std::runtime_error("unreachable"); } @@ -278,8 +278,8 @@ public: } void resize(long_t newSize) { - if (m_type->t != type_t::List) throw bad_thing_access(); - auto& list = get(); + if (m_type->t != type_t::Array) throw bad_thing_access(); + auto& list = get(); if (newSize < 0 || newSize == list.size) return; std::byte* newData = new std::byte[compute_size_na(resolve_type(*m_type->list, m_modules)) * newSize]; std::memcpy(newData, @@ -291,8 +291,8 @@ public: } thing at(long_t index) const { - if (m_type->t != type_t::List) throw bad_thing_access(); - auto& list = get(); + if (m_type->t != type_t::Array) throw bad_thing_access(); + auto& list = get(); if (index < 0 || index >= list.size) throw std::out_of_range("index out of range"); thing res = { *m_type->list, m_modules, m_allocator }; res.get() = list.data; // TODO: Account for padding, alignment and stuff @@ -306,7 +306,7 @@ public: return rsv; } private: - static void copy_list(const type_p& innerType, list_t& dst, const list_t& src) { + static void copy_list(const type_p& innerType, array_t& dst, const array_t& src) { dst.size = src.size; if (dst.size <= 0) { dst.data = nullptr; @@ -319,11 +319,11 @@ private: switch (innerType->t) { case type_t::Primitive: case type_t::Reference: std::memcpy(dst.data, src.data, size); break; - case type_t::List: + case type_t::Array: for (std::size_t i = 0; i < size; ++i) { copy_list(*innerType->list, - *std::launder(reinterpret_cast(dst.data)), - *std::launder(reinterpret_cast(src.data))); + *std::launder(reinterpret_cast(dst.data)), + *std::launder(reinterpret_cast(src.data))); } break; case type_t::Import: throw std::runtime_error("unresolved type"); @@ -334,7 +334,7 @@ private: switch (type->t) { case type_t::Primitive: return type->primitive; case type_t::Reference: return sizeof(reference_t); - case type_t::List: return sizeof(list_t); + case type_t::Array: return sizeof(array_t); case type_t::Import: throw std::runtime_error("unresolved type"); } diff --git a/furvm/include/furvm/type.hpp b/furvm/include/furvm/type.hpp index 9b06031..3448a6b 100644 --- a/furvm/include/furvm/type.hpp +++ b/furvm/include/furvm/type.hpp @@ -10,14 +10,14 @@ namespace furvm { enum class type_t : std::uint32_t { Primitive = 0, Reference, - List, + Array, Import, }; using primitive_type = std::uint64_t; using reference_type = type_p; -using list_type = type_h; +using array_type = type_h; struct import_type { mod_id mod; @@ -29,7 +29,7 @@ struct type { union { primitive_type primitive; reference_type reference; - list_type list; + array_type list; import_type imp; }; @@ -42,8 +42,8 @@ struct type { type(const reference_type& reference) : t(type_t::Reference), reference(reference) {} - type(const list_type& list) - : t(type_t::List), list(list) {} + type(const array_type& list) + : t(type_t::Array), list(list) {} type(const import_type& imp) : t(type_t::Import), imp(imp) {} @@ -51,7 +51,7 @@ struct type { ~type() { switch (t) { case type_t::Reference: reference.~reference_type(); break; - case type_t::List: list.~list_type(); break; + case type_t::Array: list.~array_type(); break; case type_t::Import: imp.~import_type(); break; default: break; } @@ -62,7 +62,7 @@ struct type { switch (t) { case type_t::Primitive: primitive = other.primitive; break; case type_t::Reference: reference = std::move(other.reference); break; - case type_t::List: list = std::move(other.list); break; + case type_t::Array: list = std::move(other.list); break; case type_t::Import: imp = std::move(other.imp); break; } } @@ -73,7 +73,7 @@ struct type { switch (t) { case type_t::Primitive: primitive = other.primitive; break; case type_t::Reference: reference = std::move(other.reference); break; - case type_t::List: list = std::move(other.list); break; + case type_t::Array: list = std::move(other.list); break; case type_t::Import: imp = std::move(other.imp); break; } @@ -85,7 +85,7 @@ struct type { switch (t) { case type_t::Primitive: primitive = other.primitive; break; case type_t::Reference: reference = other.reference; break; - case type_t::List: list = other.list; break; + case type_t::Array: list = other.list; break; case type_t::Import: imp = other.imp; break; } } @@ -96,7 +96,7 @@ struct type { switch (t) { case type_t::Primitive: primitive = other.primitive; break; case type_t::Reference: reference = other.reference; break; - case type_t::List: list = other.list; break; + case type_t::Array: list = other.list; break; case type_t::Import: imp = other.imp; break; } @@ -111,7 +111,7 @@ using long_t = std::int64_t; /**< An 8-byte integer. */ using reference_t = std::byte*; -struct list_t { +struct array_t { long_t size; std::byte* data; }; diff --git a/furvm/src/executor.cpp b/furvm/src/executor.cpp index c5c8091..d12cd17 100644 --- a/furvm/src/executor.cpp +++ b/furvm/src/executor.cpp @@ -167,8 +167,8 @@ void executor::step() { auto ptr = push_thing({ *m_context->at("core")->type_at(4), m_context, m_context->thing_alloc() }); switch (furvm::thing<>::resolve_type(thing.type(), m_context)->t) { case type_t::Primitive: ptr->get() = reinterpret_cast(thing.raw()); break; - case type_t::List: - ptr->get() = reinterpret_cast(thing.get().data); + case type_t::Array: + ptr->get() = reinterpret_cast(thing.get().data); break; case type_t::Reference: case type_t::Import: @@ -181,7 +181,7 @@ void executor::step() { auto type = furvm::thing<>::resolve_type(thing.type(), m_context); switch (type->t) { case type_t::Primitive: ptr->get() = static_cast(type->primitive); break; - case type_t::List: ptr->get() = thing.get().size; break; + case type_t::Array: ptr->get() = thing.get().size; break; case type_t::Reference: case type_t::Import: default: throw std::runtime_error("unreachable"); diff --git a/furvm/src/module.cpp b/furvm/src/module.cpp index 1a921b0..8b5adc0 100644 --- a/furvm/src/module.cpp +++ b/furvm/src/module.cpp @@ -58,7 +58,7 @@ 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::List: detail::serialize(os, type->list.id()); break; + case type_t::Array: detail::serialize(os, type->list.id()); break; case type_t::Import: { detail::serialize(os, type->imp.mod); detail::serialize(os, type->imp.type); @@ -127,7 +127,7 @@ mod mod::load(std::istream& is) { mod.emplace_type(id, std::make_shared(primitive)).dispatch(); } break; case type_t::Reference: throw std::runtime_error("reference type serialization is unimplemented"); - case type_t::List: { + case type_t::Array: { type_id typeId = 0; detail::load(is, typeId); mod.emplace_type(id, std::make_shared(mod.type_at(typeId))).dispatch();