diff --git a/include/zenkit/DaedalusVm.hh b/include/zenkit/DaedalusVm.hh index ede9dd66..d71f8cd3 100644 --- a/include/zenkit/DaedalusVm.hh +++ b/include/zenkit/DaedalusVm.hh @@ -153,20 +153,15 @@ namespace zenkit { unsafe_call(sym); if constexpr (std::is_same_v) { - // clear the stack - _m_stack_ptr = 0; - + this->unsafe_clear_stack(); return {}; } else if constexpr (!std::is_same_v) { auto ret = pop_call_return_value(); - // clear the stack - _m_stack_ptr = 0; - + this->unsafe_clear_stack(); return ret; } else { - // clear the stack - _m_stack_ptr = 0; + this->unsafe_clear_stack(); } } @@ -647,6 +642,7 @@ namespace zenkit { ZKAPI void unsafe_jump(uint32_t address); ZKAPI std::shared_ptr unsafe_get_gi(); ZKAPI void unsafe_set_gi(std::shared_ptr i); + ZKAPI void unsafe_clear_stack(); /// \return the symbol referring to the global var C_NPC self. [[nodiscard]] ZKAPI DaedalusSymbol* global_self() { diff --git a/src/DaedalusVm.cc b/src/DaedalusVm.cc index 1b8c4e91..d00f1bd0 100644 --- a/src/DaedalusVm.cc +++ b/src/DaedalusVm.cc @@ -120,6 +120,10 @@ namespace zenkit { _m_instance = std::move(i); } + void DaedalusVm::unsafe_clear_stack() { + _m_stack_ptr = 0; + } + bool DaedalusVm::exec() { auto instr = instruction_at(_m_pc);