From 6ab92547460852f4be775082ec1f4f7753134106 Mon Sep 17 00:00:00 2001 From: CHatingPython Date: Mon, 29 Jun 2026 20:34:42 +0200 Subject: [PATCH] refactor: improve thing types Change thing_t enumeration to thing_type structure. Closes: #30 --- furc/src/main.cpp | 10 +- furvm/include/furvm/fwd.hpp | 21 +++- furvm/include/furvm/thing.hpp | 181 ++++++++++++++++++---------------- furvm/src/executor.cpp | 4 +- furvm/src/main.cpp | 10 +- 5 files changed, 121 insertions(+), 105 deletions(-) diff --git a/furc/src/main.cpp b/furc/src/main.cpp index ce50a28..313892f 100644 --- a/furc/src/main.cpp +++ b/furc/src/main.cpp @@ -67,14 +67,8 @@ int main(void) { furvmMod->serialize(file); file.close(); - furvmMod->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; - } - }); + furvmMod->set_native_function("print", + [](furvm::executor& executor) { std::cout << executor.load_thing(0)->get() << '\n'; }); furvm::executor_h executor = context->emplace_executor(context); executor->push_frame(furvmMod, *furvmMod->function_at("main")); diff --git a/furvm/include/furvm/fwd.hpp b/furvm/include/furvm/fwd.hpp index a0d9c1b..b0d27e5 100644 --- a/furvm/include/furvm/fwd.hpp +++ b/furvm/include/furvm/fwd.hpp @@ -141,10 +141,27 @@ using mod_h = handle>; // thing.hpp /** - * @enum thing_t + * @enum thing_type_t + * @brief Type of the thing's type. + */ +enum class thing_type_t : std::uint32_t; + +/** + * @struct thing_type * @brief Thing type. */ -enum class thing_t : std::uint8_t; +struct thing_type; + +/** + * @brief Thing type's identifier. + */ +using thing_type_id = std::uint32_t; + +// TODO: Use generic header +/** + * @brief A handle to a thing type. + */ +using thing_type_h = handle>; /** * @class bad_thing_access diff --git a/furvm/include/furvm/thing.hpp b/furvm/include/furvm/thing.hpp index 62cecea..eda6f28 100644 --- a/furvm/include/furvm/thing.hpp +++ b/furvm/include/furvm/thing.hpp @@ -5,31 +5,34 @@ #include "furvm/exceptions.hpp" #include "furvm/fwd.hpp" +#include #include #include #include +#include #include +#include +#include #include #include namespace furvm { -enum class thing_t : std::uint8_t { - Int32, +enum class thing_type_t : std::uint32_t { + Primitive = 0, }; +struct thing_type { + thing_type_t type; + std::uint64_t value; +}; + +using int_t = std::int32_t; /**< A 4-byte integer. */ + /** - * @brief Returns how many bytes a thing would take up. - * - * @param type Type of the thing. - * @return The byte count. + * @brief A 4-byte integer thing type. */ -static inline std::size_t thing_type_size(thing_t type) { - switch (type) { - case thing_t::Int32: return sizeof(std::int32_t); - default: return 0; - } -} +static constexpr thing_type IntType = { thing_type_t::Primitive, sizeof(int_t) }; template