Compare commits
2 Commits
d419b62225
...
713aec199f
| Author | SHA1 | Date | |
|---|---|---|---|
|
713aec199f
|
|||
|
15218d7530
|
@@ -5,7 +5,7 @@
|
|||||||
#include "furvm/module.hpp" // IWYU pragma: keep
|
#include "furvm/module.hpp" // IWYU pragma: keep
|
||||||
#include "furvm/thing.hpp" // IWYU pragma: keep
|
#include "furvm/thing.hpp" // IWYU pragma: keep
|
||||||
|
|
||||||
#include <optional>
|
#include <functional>
|
||||||
#include <stack>
|
#include <stack>
|
||||||
#include <utility>
|
#include <utility>
|
||||||
#include <vector>
|
#include <vector>
|
||||||
@@ -29,6 +29,8 @@ static inline executor_flags operator~(executor_flags flags) {
|
|||||||
return executor_flags(~static_cast<std::uint32_t>(flags));
|
return executor_flags(~static_cast<std::uint32_t>(flags));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
using executor_callback = std::function<void(executor&)>;
|
||||||
|
|
||||||
class executor {
|
class executor {
|
||||||
public:
|
public:
|
||||||
/**
|
/**
|
||||||
@@ -74,6 +76,11 @@ public:
|
|||||||
* @brief Copy constructor.
|
* @brief Copy constructor.
|
||||||
*/
|
*/
|
||||||
executor& operator=(const executor&) = default;
|
executor& operator=(const executor&) = default;
|
||||||
|
public:
|
||||||
|
template <typename CallbackFwd>
|
||||||
|
void set_new_frame_callback(CallbackFwd&& callback) {
|
||||||
|
m_newFrameCb = std::forward<CallbackFwd>(callback);
|
||||||
|
}
|
||||||
public:
|
public:
|
||||||
/**
|
/**
|
||||||
* @brief Returns flags of this executor.
|
* @brief Returns flags of this executor.
|
||||||
@@ -103,6 +110,8 @@ public:
|
|||||||
* @return The frame.
|
* @return The frame.
|
||||||
*/
|
*/
|
||||||
frame frame() const;
|
frame frame() const;
|
||||||
|
|
||||||
|
const std::stack<struct frame>& frames() const { return m_frames; }
|
||||||
public:
|
public:
|
||||||
/**
|
/**
|
||||||
* @brief Pushes a thing handle onto the stack.
|
* @brief Pushes a thing handle onto the stack.
|
||||||
@@ -176,6 +185,8 @@ private:
|
|||||||
|
|
||||||
std::stack<struct frame> m_frames;
|
std::stack<struct frame> m_frames;
|
||||||
std::stack<thing_h> m_stack;
|
std::stack<thing_h> m_stack;
|
||||||
|
|
||||||
|
executor_callback m_newFrameCb = nullptr;
|
||||||
};
|
};
|
||||||
|
|
||||||
} // namespace furvm
|
} // namespace furvm
|
||||||
|
|||||||
@@ -74,9 +74,11 @@ void executor::push_frame(const mod_h& mod, function function) {
|
|||||||
m_frames.emplace((struct executor::frame){ mod, 0, m_stack.size(), returnType, std::move(args) });
|
m_frames.emplace((struct executor::frame){ mod, 0, m_stack.size(), returnType, std::move(args) });
|
||||||
modInst->get_native_function(function.native())(*this);
|
modInst->get_native_function(function.native())(*this);
|
||||||
pop_frame();
|
pop_frame();
|
||||||
} break;
|
return;
|
||||||
|
}
|
||||||
default: throw std::runtime_error("unexpected function type");
|
default: throw std::runtime_error("unexpected function type");
|
||||||
}
|
}
|
||||||
|
if (m_newFrameCb) m_newFrameCb(*this);
|
||||||
}
|
}
|
||||||
|
|
||||||
struct executor::frame executor::pop_frame() {
|
struct executor::frame executor::pop_frame() {
|
||||||
|
|||||||
Reference in New Issue
Block a user