[Stack]
- Change RemoveCurrentContext for PopCurrentContext - Add CopTo method to stack
This commit is contained in:
parent
c177e5577e
commit
da27c2b3f0
2 changed files with 20 additions and 7 deletions
|
@ -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)
|
||||
}
|
||||
|
|
|
@ -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
|
||||
|
|
Loading…
Reference in a new issue