fix(furvm): improve executor flags

This commit is contained in:
2026-08-17 11:20:14 +02:00
parent 26d935e22a
commit 195d154474
2 changed files with 22 additions and 1 deletions
+9 -1
View File
@@ -83,6 +83,14 @@ public:
* @return The flags. * @return The flags.
*/ */
executor_flags flags() const { return m_flags; } executor_flags flags() const { return m_flags; }
bool done() const { return (m_flags & executor_flags::Done) == executor_flags::Done; }
bool suspended() const { return (m_flags & executor_flags::Suspended) == executor_flags::Suspended; }
void unsuspend() { m_flags = m_flags & ~executor_flags::Suspended; }
void clear_flags() { m_flags = m_frames.empty() ? executor_flags::Done : furvm::executor_flags{ 0 }; }
public: public:
/** /**
* @brief Pushes a new frame. * @brief Pushes a new frame.
@@ -173,7 +181,7 @@ private:
private: private:
static bool compare_thing_types(const thing_type& lhs, const thing_type& rhs); static bool compare_thing_types(const thing_type& lhs, const thing_type& rhs);
private: private:
executor_flags m_flags{}; // NOLINT(bugprone-invalid-enum-default-initialization) executor_flags m_flags = executor_flags::Done;
context* m_context; context* m_context;
std::stack<frame> m_frames; std::stack<frame> m_frames;
+13
View File
@@ -104,6 +104,12 @@ void executor::push_frame(const mod_h& mod, function function) {
default: throw std::runtime_error("unexpected function type"); default: throw std::runtime_error("unexpected function type");
} }
if (m_newFrameCb) m_newFrameCb(*this); if (m_newFrameCb) m_newFrameCb(*this);
if (!m_frames.empty()) {
m_flags = m_flags & ~executor_flags::Done;
} else {
m_flags = m_flags | executor_flags::Done;
}
} }
struct executor::frame executor::pop_frame() { struct executor::frame executor::pop_frame() {
@@ -117,6 +123,13 @@ struct executor::frame executor::pop_frame() {
} }
if (m_stack.size() != frame.stackBase) throw std::runtime_error("unexhausted stack"); if (m_stack.size() != frame.stackBase) throw std::runtime_error("unexhausted stack");
if (returnValue.has_value()) push_thing(std::move(returnValue.value())); if (returnValue.has_value()) push_thing(std::move(returnValue.value()));
if (!m_frames.empty()) {
m_flags = m_flags & ~executor_flags::Done;
} else {
m_flags = m_flags | executor_flags::Done;
}
return frame; return frame;
} }