From 713aec199fc0e3351f6c490f76e9352da961bbde Mon Sep 17 00:00:00 2001 From: CHatingPython Date: Wed, 12 Aug 2026 23:44:15 +0200 Subject: [PATCH] feat(furvm): add new frame callback to executor --- furvm/include/furvm/executor.hpp | 10 ++++++++++ furvm/src/executor.cpp | 4 +++- 2 files changed, 13 insertions(+), 1 deletion(-) diff --git a/furvm/include/furvm/executor.hpp b/furvm/include/furvm/executor.hpp index e855bdd..6b7f001 100644 --- a/furvm/include/furvm/executor.hpp +++ b/furvm/include/furvm/executor.hpp @@ -5,6 +5,7 @@ #include "furvm/module.hpp" // IWYU pragma: keep #include "furvm/thing.hpp" // IWYU pragma: keep +#include #include #include #include @@ -28,6 +29,8 @@ static inline executor_flags operator~(executor_flags flags) { return executor_flags(~static_cast(flags)); } +using executor_callback = std::function; + class executor { public: /** @@ -73,6 +76,11 @@ public: * @brief Copy constructor. */ executor& operator=(const executor&) = default; +public: + template + void set_new_frame_callback(CallbackFwd&& callback) { + m_newFrameCb = std::forward(callback); + } public: /** * @brief Returns flags of this executor. @@ -177,6 +185,8 @@ private: std::stack m_frames; std::stack m_stack; + + executor_callback m_newFrameCb = nullptr; }; } // namespace furvm diff --git a/furvm/src/executor.cpp b/furvm/src/executor.cpp index 4d812de..c503141 100644 --- a/furvm/src/executor.cpp +++ b/furvm/src/executor.cpp @@ -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) }); modInst->get_native_function(function.native())(*this); pop_frame(); - } break; + return; + } default: throw std::runtime_error("unexpected function type"); } + if (m_newFrameCb) m_newFrameCb(*this); } struct executor::frame executor::pop_frame() {