Modules/Objects/private/interpreter/CallStack.cpp
2024-03-25 11:20:15 +03:00

35 lines
939 B
C++

#include "interpreter/CallStack.hpp"
#include "interpreter/ByteCode.hpp"
#include "primitives/MethodObject.hpp"
using namespace tp;
using namespace obj;
void CallStack::enter(const CallStack::CallFrame& frame) {
if (mStack.size()) {
auto& last_frame = mStack.last();
last_frame.mIp = last_frame.mMethod->mScript->mBytecode.mInstructionIdx;
}
frame.mMethod->mScript->mBytecode.mArgumentsLoaded = 0;
frame.mMethod->mScript->mBytecode.mInstructionIdx = 0;
objects_api::increaseReferenceCount(frame.mMethod);
mStack.append(frame);
}
void CallStack::leave() {
auto frame = mStack.last();
objects_api::destroy(frame.mMethod);
mStack.pop();
if (mStack.size()) {
auto& last_frame = mStack.last();
last_frame.mMethod->mScript->mBytecode.mInstructionIdx = last_frame.mIp;
}
}
ByteCode* CallStack::getBytecode() { return &mStack.last().mMethod->mScript->mBytecode; }
halni CallStack::len() const { return mStack.size(); }