diff --git a/furvm/include/furvm/context.hpp b/furvm/include/furvm/context.hpp index a8397ef..230bfda 100644 --- a/furvm/include/furvm/context.hpp +++ b/furvm/include/furvm/context.hpp @@ -5,6 +5,7 @@ #include "furvm/fwd.hpp" #include "furvm/module.hpp" +#include #include #include #include @@ -86,6 +87,12 @@ public: * @return The module count. */ constexpr size_t module_count() const { return m_modules.size(); } +public: + template >> + auto& emplace_executor(Args&&... args) { + executor_p executor = std::make_shared(std::forward(args)...); + return m_executors.emplace_back(std::move(executor)); + } public: /** * @brief Removes unreferenced things from the thing list. diff --git a/furvm/include/furvm/executor.hpp b/furvm/include/furvm/executor.hpp index 3f0a187..858f48f 100644 --- a/furvm/include/furvm/executor.hpp +++ b/furvm/include/furvm/executor.hpp @@ -26,15 +26,6 @@ static inline executor_flags operator~(executor_flags flags) { } class executor { -private: - /** - * @brief A private token for the private constructor. - * - * Also `egzekutor` in Polish translates to `executor` I think. - */ - struct egzekutor { - explicit egzekutor() = default; - }; public: /** * @brief Executor frame. @@ -50,14 +41,14 @@ public: }; public: /** - * @brief Private constructor. + * @brief Returns a new executor. * - * @param id - * @param context + * @param context Context. */ - executor(egzekutor, executor_handle id, const context_p& context); + executor(const context_p& context) + : m_context(context) {} - ~executor(); + ~executor() = default; /** * @brief Move constructor. @@ -72,21 +63,6 @@ public: executor(const executor&) = delete; executor& operator=(const executor&) = delete; public: - /** - * @brief Returns a new executor. - * - * @param context Furvm context. - * @return Shared pointer to the new executor. - */ - static executor_p create(const context_p& context); -public: - /** - * @brief Returns an id of this executor. - * - * @return The id. - */ - executor_handle id() const { return m_id; } - /** * @brief Returns flags of this executor. * @@ -173,9 +149,8 @@ public: */ void step(); private: - executor_handle m_id; - executor_flags m_flags{}; // NOLINT(bugprone-invalid-enum-default-initialization) - context_p m_context; + executor_flags m_flags{}; // NOLINT(bugprone-invalid-enum-default-initialization) + context_p m_context; std::stack m_frames; std::stack m_stack; diff --git a/furvm/src/executor.cpp b/furvm/src/executor.cpp index 563c6b0..430cb9d 100644 --- a/furvm/src/executor.cpp +++ b/furvm/src/executor.cpp @@ -12,19 +12,6 @@ namespace furvm { -executor::executor(egzekutor, executor_handle id, const context_p& context) - : m_id(id), m_context(context) {} - -executor::~executor() { - m_context->m_executors[m_id] = nullptr; -} - -executor_p executor::create(const context_p& context) { - auto ex = std::make_shared(egzekutor{}, context->m_executors.size(), context); - context->m_executors.push_back(ex); - return std::move(ex); -} - void executor::push_frame(const mod_p& mod, function_handle function) { const auto& func = mod->function_at(function); if (func->type() != function_t::Normal) throw std::runtime_error("unexpected function type"); diff --git a/furvm/src/main.cpp b/furvm/src/main.cpp index d3238f7..065de61 100644 --- a/furvm/src/main.cpp +++ b/furvm/src/main.cpp @@ -30,7 +30,7 @@ int main(void) { std::ofstream file("./test.furm", std::ios::binary); furvm::serializer::serialize_module(file, mainModule); - auto executor = furvm::executor::create(context); + auto executor = context->emplace_executor(context); executor->push_frame(mainModule, 0); static constexpr std::size_t FPC = 3; // Frames per collection