@@ -5,6 +5,7 @@
|
||||
#include "furvm/fwd.hpp"
|
||||
#include "furvm/module.hpp"
|
||||
|
||||
#include <memory>
|
||||
#include <queue>
|
||||
#include <string>
|
||||
#include <type_traits>
|
||||
@@ -86,6 +87,12 @@ public:
|
||||
* @return The module count.
|
||||
*/
|
||||
constexpr size_t module_count() const { return m_modules.size(); }
|
||||
public:
|
||||
template <typename... Args, typename = std::enable_if_t<std::is_constructible_v<executor, Args...>>>
|
||||
auto& emplace_executor(Args&&... args) {
|
||||
executor_p executor = std::make_shared<class executor>(std::forward<Args>(args)...);
|
||||
return m_executors.emplace_back(std::move(executor));
|
||||
}
|
||||
public:
|
||||
/**
|
||||
* @brief Removes unreferenced things from the thing list.
|
||||
|
||||
@@ -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,7 +149,6 @@ public:
|
||||
*/
|
||||
void step();
|
||||
private:
|
||||
executor_handle m_id;
|
||||
executor_flags m_flags{}; // NOLINT(bugprone-invalid-enum-default-initialization)
|
||||
context_p m_context;
|
||||
|
||||
|
||||
@@ -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<executor>(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");
|
||||
|
||||
+1
-1
@@ -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
|
||||
|
||||
Reference in New Issue
Block a user