Skip to content

Commit

Permalink
feat(DaedalusVm): add unsafe_clear_stack function
Browse files Browse the repository at this point in the history
  • Loading branch information
lmichaelis committed Aug 9, 2024
1 parent 7121a33 commit 7c79999
Show file tree
Hide file tree
Showing 2 changed files with 8 additions and 8 deletions.
12 changes: 4 additions & 8 deletions include/zenkit/DaedalusVm.hh
Original file line number Diff line number Diff line change
Expand Up @@ -153,20 +153,15 @@ namespace zenkit {
unsafe_call(sym);

if constexpr (std::is_same_v<R, IgnoreReturnValue>) {
// clear the stack
_m_stack_ptr = 0;

this->unsafe_clear_stack();
return {};
} else if constexpr (!std::is_same_v<R, void>) {
auto ret = pop_call_return_value<R>();

// 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();
}
}

Expand Down Expand Up @@ -647,6 +642,7 @@ namespace zenkit {
ZKAPI void unsafe_jump(uint32_t address);
ZKAPI std::shared_ptr<DaedalusInstance> unsafe_get_gi();
ZKAPI void unsafe_set_gi(std::shared_ptr<DaedalusInstance> i);
ZKAPI void unsafe_clear_stack();

/// \return the symbol referring to the global <tt>var C_NPC self</tt>.
[[nodiscard]] ZKAPI DaedalusSymbol* global_self() {
Expand Down
4 changes: 4 additions & 0 deletions src/DaedalusVm.cc
Original file line number Diff line number Diff line change
Expand Up @@ -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);

Expand Down

0 comments on commit 7c79999

Please sign in to comment.