refactor(furvm): remove executor handle
This commit is contained in:
@@ -11,6 +11,7 @@
|
||||
|
||||
#include <cstddef>
|
||||
#include <utility>
|
||||
#include <vector>
|
||||
|
||||
namespace furvm {
|
||||
|
||||
@@ -39,15 +40,10 @@ public:
|
||||
context(const context&) = delete;
|
||||
context& operator=(const context&) = delete;
|
||||
public:
|
||||
/**
|
||||
* @brief Emplaces an executor in the context.
|
||||
*
|
||||
* @param args Arguments forwarded to executor's constructor.
|
||||
* @return A handle to the emplaced executor.
|
||||
*/
|
||||
template <typename... Args>
|
||||
auto emplace_executor(Args&&... args) {
|
||||
return m_executors.emplace_back(std::forward<Args>(args)...);
|
||||
auto& allocate_executor() {
|
||||
executor executor(this);
|
||||
return m_executors.emplace_back(std::move(executor));
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -57,7 +53,7 @@ public:
|
||||
* @return A handle to the executor.
|
||||
*/
|
||||
template <typename... Args>
|
||||
auto executor_at(Args&&... args) {
|
||||
auto& executor_at(Args&&... args) {
|
||||
return m_executors.at(std::forward<Args>(args)...);
|
||||
}
|
||||
|
||||
@@ -68,19 +64,11 @@ public:
|
||||
* @return A handle to the executor.
|
||||
*/
|
||||
template <typename... Args>
|
||||
auto executor_at(Args&&... args) const {
|
||||
const auto& executor_at(Args&&... args) const {
|
||||
return m_executors.at(std::forward<Args>(args)...);
|
||||
}
|
||||
|
||||
/**
|
||||
* @brief Erases an executor from the context.
|
||||
*
|
||||
* @param args Id of the executor.
|
||||
*/
|
||||
template <typename... Args>
|
||||
void erase_executor(Args&&... args) {
|
||||
m_executors.erase(std::forward<Args>(args)...);
|
||||
}
|
||||
const std::vector<executor>& executors() const { return m_executors; }
|
||||
public:
|
||||
template <typename... Args>
|
||||
auto emplace_thing(Args&&... args) {
|
||||
@@ -128,9 +116,9 @@ public:
|
||||
|
||||
thing_type_store& tt_store() { return m_thingTypeStore; }
|
||||
private:
|
||||
handle_container<mod_h> m_modules;
|
||||
handle_container<thing_h> m_things;
|
||||
handle_container<executor_h> m_executors;
|
||||
handle_container<mod_h> m_modules;
|
||||
handle_container<thing_h> m_things;
|
||||
std::vector<executor> m_executors;
|
||||
|
||||
furlang::arena m_thingArena;
|
||||
thing_allocator<std::byte> m_thingAllocator;
|
||||
|
||||
@@ -32,6 +32,10 @@ static inline executor_flags operator~(executor_flags flags) {
|
||||
using executor_callback = std::function<void(executor&)>;
|
||||
|
||||
class executor {
|
||||
friend class context;
|
||||
private:
|
||||
executor(context* context)
|
||||
: m_context(context) {}
|
||||
public:
|
||||
/**
|
||||
* @brief Executor frame.
|
||||
@@ -47,14 +51,6 @@ public:
|
||||
std::vector<thing_h> variables; /**< Frame variables. */
|
||||
};
|
||||
public:
|
||||
/**
|
||||
* @brief Returns a new executor.
|
||||
*
|
||||
* @param context Context.
|
||||
*/
|
||||
executor(const context_p& context)
|
||||
: m_context(context) {}
|
||||
|
||||
~executor() = default;
|
||||
|
||||
/**
|
||||
@@ -181,7 +177,7 @@ private:
|
||||
thing_type* mod_to_thing_type(const mod_h& mod, const mod_type& type) const;
|
||||
private:
|
||||
executor_flags m_flags{}; // NOLINT(bugprone-invalid-enum-default-initialization)
|
||||
context_p m_context;
|
||||
context* m_context;
|
||||
|
||||
std::stack<struct frame> m_frames;
|
||||
std::stack<thing_h> m_stack;
|
||||
|
||||
@@ -195,21 +195,11 @@ enum class executor_flags : std::uint32_t;
|
||||
*/
|
||||
class executor;
|
||||
|
||||
/**
|
||||
* @brief An alias to a executor shared pointer.
|
||||
*/
|
||||
using executor_p = std::shared_ptr<executor>;
|
||||
|
||||
/**
|
||||
* @brief Furvm executor's index.
|
||||
*/
|
||||
using executor_id = std::uint32_t;
|
||||
|
||||
/**
|
||||
* @brief A handle to an executor.
|
||||
*/
|
||||
using executor_h = handle<executor, refcount_header<executor_id>>;
|
||||
|
||||
// context.hpp
|
||||
|
||||
/**
|
||||
|
||||
+4
-4
@@ -80,11 +80,11 @@ int main(int argc, char** argv) {
|
||||
std::cout << '\n';
|
||||
});
|
||||
|
||||
furvm::executor_h executor = context->emplace_executor(context);
|
||||
executor->push_frame(mod, *mainFunc);
|
||||
auto& executor = context->allocate_executor();
|
||||
executor.push_frame(mod, *mainFunc);
|
||||
|
||||
while ((executor->flags() & furvm::executor_flags::Done) != furvm::executor_flags::Done) {
|
||||
executor->step();
|
||||
while ((executor.flags() & furvm::executor_flags::Done) != furvm::executor_flags::Done) {
|
||||
executor.step();
|
||||
}
|
||||
|
||||
return 0;
|
||||
|
||||
Reference in New Issue
Block a user