}
inline bool Call(InterpState &S, CodePtr &PC, const Function *Func) {
- auto NewFrame = std::make_unique<InterpFrame>(S, Func, PC);
- Pointer ThisPtr;
if (Func->hasThisPointer()) {
- ThisPtr = NewFrame->getThis();
+ size_t ThisOffset =
+ Func->getArgSize() + (Func->hasRVO() ? primSize(PT_Ptr) : 0);
+ const Pointer &ThisPtr = S.Stk.peek<Pointer>(ThisOffset);
+
if (!CheckInvoke(S, PC, ThisPtr))
return false;
if (!CheckCallable(S, PC, Func))
return false;
+ auto NewFrame = std::make_unique<InterpFrame>(S, Func, PC);
InterpFrame *FrameBefore = S.Current;
S.Current = NewFrame.get();
/// Returns a reference to the value on the top of the stack.
template <typename T> T &peek() const {
- return *reinterpret_cast<T *>(peek(aligned_size<T>()));
+ return *reinterpret_cast<T *>(peekData(aligned_size<T>()));
+ }
+
+ template <typename T> T &peek(size_t Offset) const {
+ assert(aligned(Offset));
+ return *reinterpret_cast<T *>(peekData(Offset));
}
/// Returns a pointer to the top object.
- void *top() const { return Chunk ? peek(0) : nullptr; }
+ void *top() const { return Chunk ? peekData(0) : nullptr; }
/// Returns the size of the stack in bytes.
size_t size() const { return StackSize; }
/// Grows the stack to accommodate a value and returns a pointer to it.
void *grow(size_t Size);
/// Returns a pointer from the top of the stack.
- void *peek(size_t Size) const;
+ void *peekData(size_t Size) const;
/// Shrinks the stack.
void shrink(size_t Size);