From e087c110083fbcb0ddffe8d81a52c8812c58d38b Mon Sep 17 00:00:00 2001 From: CHatingPython Date: Fri, 3 Jul 2026 19:28:03 +0200 Subject: [PATCH] feat: add types to module Refs: #39 --- furvm/include/furvm/fwd.hpp | 4 +++ furvm/include/furvm/module.hpp | 46 ++++++++++++++++++++++++++++++++++ 2 files changed, 50 insertions(+) diff --git a/furvm/include/furvm/fwd.hpp b/furvm/include/furvm/fwd.hpp index 4b2d6d7..556ae25 100644 --- a/furvm/include/furvm/fwd.hpp +++ b/furvm/include/furvm/fwd.hpp @@ -154,6 +154,10 @@ struct type; using type_p = std::shared_ptr; +using type_id = std::uint32_t; + +using type_h = handle>; + /** * @class bad_thing_access * @brief Bad thing access exception. diff --git a/furvm/include/furvm/module.hpp b/furvm/include/furvm/module.hpp index 72bb4e7..ecbd900 100644 --- a/furvm/include/furvm/module.hpp +++ b/furvm/include/furvm/module.hpp @@ -4,6 +4,7 @@ #include "furvm/function.hpp" #include "furvm/fwd.hpp" #include "furvm/handle.hpp" +#include "furvm/type.hpp" // IWYU pragma: keep #include #include @@ -187,6 +188,49 @@ public: native_function get_native_function(NameFwd&& name) const { return m_nativeFunctions.at(std::forward(name)); } +public: + /** + * @brief Emplaces a type in the context. + * + * @param args Arguments forwarded to the type constructor. + * @return The emplaced type. + */ + template + auto emplace_type(Args&&... args) { + return m_types.emplace_back(std::forward(args)...); + } + + /** + * @brief Returns a type from the context. + * + * @param args type's id. + * @return A handle to the type. + */ + template + auto type_at(Args&&... args) { + return m_types.at(std::forward(args)...); + } + + /** + * @brief Returns a type from the context. + * + * @param args type's id. + * @return A handle to the type. + */ + template + auto type_at(Args&&... args) const { + return m_types.at(std::forward(args)...); + } + + /** + * @brief Erases a type from the context. + * + * @param args type's id. + */ + template + void erase_type(Args&&... args) { + m_types.erase(std::forward(args)...); + } public: /** * @brief Prints the module in a bytecode form to an output stream. @@ -202,6 +246,8 @@ private: std::unordered_map m_publicFunctions; handle_container m_functions; + handle_container m_types; + std::unordered_map m_nativeFunctions; };