diff --git a/pkg/vm/stack/invocationstack.go b/pkg/vm/stack/invocationstack.go index a3a66b8ec..49f058f62 100644 --- a/pkg/vm/stack/invocationstack.go +++ b/pkg/vm/stack/invocationstack.go @@ -29,11 +29,17 @@ func (i *Invocation) CurrentContext() (*Context, error) { return i.peekContext(0) } -// RemoveCurrentContext removes the context on the top of the invocation stack -// This is a convenience method for Pop -func (i *Invocation) RemoveCurrentContext() error { - _, err := i.Pop() - return err +// PopCurrentContext Pops a context item from the top of the stack +func (i *Invocation) PopCurrentContext() (*Context, error) { + item, err := i.Pop() + if err != nil { + return nil, err + } + ctx, err := item.Context() + if err != nil { + return nil, err + } + return ctx, err } // CallingContext will return the cntext item @@ -49,8 +55,7 @@ func (i *Invocation) CallingContext() (*Context, error) { // started the program func (i *Invocation) EntryContext() (*Context, error) { - // firstItemIndex refers to the first item - // that was popped on the stack + // firstItemIndex refers to the first item that was popped on the stack firstItemIndex := uint16(i.Len() - 1) // N.B. if this overflows because len is zero, then an error will be returned return i.peekContext(firstItemIndex) } diff --git a/pkg/vm/stack/stack.go b/pkg/vm/stack/stack.go index e857a9ada..8d1ac5b78 100644 --- a/pkg/vm/stack/stack.go +++ b/pkg/vm/stack/stack.go @@ -119,6 +119,14 @@ func (ras *RandomAccess) Peek(n uint16) (Item, error) { return ras.vals[index], nil } +// CopyTo will copy all of the stack items from `ras` into the stack that is passed as an argument +// XXX: once maxstacksize is implemented, we will return error if size goes over +// There will also be additional checks needed once stack isolation is added +func (ras *RandomAccess) CopyTo(stack *RandomAccess) error { + stack.vals = append(stack.vals, ras.vals...) + return nil +} + // Convenience Functions // PopInt will remove the last stack item that was added