From 5ace40b6aadf63b8ac699b811b437da9d6e20cdd Mon Sep 17 00:00:00 2001 From: CHatingPython Date: Sat, 6 Jun 2026 22:51:44 +0200 Subject: [PATCH] refactor(furvm): change unique pointer to shared pointer for module --- furvm/include/furvm/context.hpp | 15 +++++++-------- furvm/src/main.cpp | 3 ++- 2 files changed, 9 insertions(+), 9 deletions(-) diff --git a/furvm/include/furvm/context.hpp b/furvm/include/furvm/context.hpp index 82ef5c1..6e05f87 100644 --- a/furvm/include/furvm/context.hpp +++ b/furvm/include/furvm/context.hpp @@ -12,8 +12,6 @@ namespace furvm { class context { public: - using value_type = std::unique_ptr; /**< An alias to unique pointer of module. */ - friend class executor; public: context(); @@ -50,7 +48,7 @@ public: * @param index Index to the module. * @return Old value. */ - value_type erase(module_handle index) { + std::shared_ptr erase(module_handle index) { if (index >= m_modules.size()) return nullptr; return std::move(m_modules[index]); } @@ -61,7 +59,7 @@ public: * @param index Position of the module. * @return The module. */ - constexpr value_type& operator[](module_handle index) { return m_modules[index]; } + constexpr std::shared_ptr& operator[](module_handle index) { return m_modules[index]; } /** * @brief Returns a module of this context. @@ -69,7 +67,7 @@ public: * @param index Position of the module. * @return The module. */ - constexpr const value_type& operator[](module_handle index) const { return m_modules[index]; } + constexpr const std::shared_ptr& operator[](module_handle index) const { return m_modules[index]; } /** * @brief Returns a module of this context. @@ -77,7 +75,7 @@ public: * @param index Position of the module. * @return The module. */ - constexpr value_type& at(module_handle index) { return m_modules.at(index); } + constexpr std::shared_ptr& at(module_handle index) { return m_modules.at(index); } /** * @brief Returns a module of this context. @@ -85,7 +83,7 @@ public: * @param index Position of the module. * @return The module. */ - constexpr const value_type& at(module_handle index) const { return m_modules.at(index); } + constexpr const std::shared_ptr& at(module_handle index) const { return m_modules.at(index); } /** * @brief Returns how many does this context have modules. @@ -94,7 +92,8 @@ public: */ constexpr size_t size() const { return m_modules.size(); } private: - std::vector> m_modules; + std::vector> m_modules; + std::vector> m_things; std::vector> m_executors; }; diff --git a/furvm/src/main.cpp b/furvm/src/main.cpp index 3105ce7..e2f119f 100644 --- a/furvm/src/main.cpp +++ b/furvm/src/main.cpp @@ -17,9 +17,10 @@ static constexpr std::array s_bytecode = { int main(void) { auto context = std::make_shared(); - const auto& mainModule = context->emplace(s_bytecode.begin(), s_bytecode.end()); + auto mainModule = context->emplace(s_bytecode.begin(), s_bytecode.end()); auto executor = furvm::executor::create(context); + executor->push_frame(mainModule, 0); return 0; }