@@ -5,6 +5,7 @@
|
|||||||
#include "furvm/fwd.hpp"
|
#include "furvm/fwd.hpp"
|
||||||
#include "furvm/module.hpp"
|
#include "furvm/module.hpp"
|
||||||
|
|
||||||
|
#include <memory>
|
||||||
#include <queue>
|
#include <queue>
|
||||||
#include <string>
|
#include <string>
|
||||||
#include <type_traits>
|
#include <type_traits>
|
||||||
@@ -86,6 +87,12 @@ public:
|
|||||||
* @return The module count.
|
* @return The module count.
|
||||||
*/
|
*/
|
||||||
constexpr size_t module_count() const { return m_modules.size(); }
|
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:
|
public:
|
||||||
/**
|
/**
|
||||||
* @brief Removes unreferenced things from the thing list.
|
* @brief Removes unreferenced things from the thing list.
|
||||||
|
|||||||
@@ -26,15 +26,6 @@ static inline executor_flags operator~(executor_flags flags) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
class executor {
|
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:
|
public:
|
||||||
/**
|
/**
|
||||||
* @brief Executor frame.
|
* @brief Executor frame.
|
||||||
@@ -50,14 +41,14 @@ public:
|
|||||||
};
|
};
|
||||||
public:
|
public:
|
||||||
/**
|
/**
|
||||||
* @brief Private constructor.
|
* @brief Returns a new executor.
|
||||||
*
|
*
|
||||||
* @param id
|
* @param context Context.
|
||||||
* @param context
|
|
||||||
*/
|
*/
|
||||||
executor(egzekutor, executor_handle id, const context_p& context);
|
executor(const context_p& context)
|
||||||
|
: m_context(context) {}
|
||||||
|
|
||||||
~executor();
|
~executor() = default;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @brief Move constructor.
|
* @brief Move constructor.
|
||||||
@@ -72,21 +63,6 @@ public:
|
|||||||
executor(const executor&) = delete;
|
executor(const executor&) = delete;
|
||||||
executor& operator=(const executor&) = delete;
|
executor& operator=(const executor&) = delete;
|
||||||
public:
|
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.
|
* @brief Returns flags of this executor.
|
||||||
*
|
*
|
||||||
@@ -173,9 +149,8 @@ public:
|
|||||||
*/
|
*/
|
||||||
void step();
|
void step();
|
||||||
private:
|
private:
|
||||||
executor_handle m_id;
|
executor_flags m_flags{}; // NOLINT(bugprone-invalid-enum-default-initialization)
|
||||||
executor_flags m_flags{}; // NOLINT(bugprone-invalid-enum-default-initialization)
|
context_p m_context;
|
||||||
context_p m_context;
|
|
||||||
|
|
||||||
std::stack<struct frame> m_frames;
|
std::stack<struct frame> m_frames;
|
||||||
std::stack<thing_p> m_stack;
|
std::stack<thing_p> m_stack;
|
||||||
|
|||||||
@@ -12,19 +12,6 @@
|
|||||||
|
|
||||||
namespace furvm {
|
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) {
|
void executor::push_frame(const mod_p& mod, function_handle function) {
|
||||||
const auto& func = mod->function_at(function);
|
const auto& func = mod->function_at(function);
|
||||||
if (func->type() != function_t::Normal) throw std::runtime_error("unexpected function type");
|
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);
|
std::ofstream file("./test.furm", std::ios::binary);
|
||||||
furvm::serializer::serialize_module(file, mainModule);
|
furvm::serializer::serialize_module(file, mainModule);
|
||||||
|
|
||||||
auto executor = furvm::executor::create(context);
|
auto executor = context->emplace_executor(context);
|
||||||
executor->push_frame(mainModule, 0);
|
executor->push_frame(mainModule, 0);
|
||||||
|
|
||||||
static constexpr std::size_t FPC = 3; // Frames per collection
|
static constexpr std::size_t FPC = 3; // Frames per collection
|
||||||
|
|||||||
Reference in New Issue
Block a user