[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)
|
return i.peekContext(0)
|
||||||
}
|
}
|
||||||
|
|
||||||
// RemoveCurrentContext removes the context on the top of the invocation stack
|
// PopCurrentContext Pops a context item from the top of the stack
|
||||||
// This is a convenience method for Pop
|
func (i *Invocation) PopCurrentContext() (*Context, error) {
|
||||||
func (i *Invocation) RemoveCurrentContext() error {
|
item, err := i.Pop()
|
||||||
_, err := i.Pop()
|
if err != nil {
|
||||||
return err
|
return nil, err
|
||||||
|
}
|
||||||
|
ctx, err := item.Context()
|
||||||
|
if err != nil {
|
||||||
|
return nil, err
|
||||||
|
}
|
||||||
|
return ctx, err
|
||||||
}
|
}
|
||||||
|
|
||||||
// CallingContext will return the cntext item
|
// CallingContext will return the cntext item
|
||||||
|
@ -49,8 +55,7 @@ func (i *Invocation) CallingContext() (*Context, error) {
|
||||||
// started the program
|
// started the program
|
||||||
func (i *Invocation) EntryContext() (*Context, error) {
|
func (i *Invocation) EntryContext() (*Context, error) {
|
||||||
|
|
||||||
// firstItemIndex refers to the first item
|
// firstItemIndex refers to the first item that was popped on the stack
|
||||||
// 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
|
firstItemIndex := uint16(i.Len() - 1) // N.B. if this overflows because len is zero, then an error will be returned
|
||||||
return i.peekContext(firstItemIndex)
|
return i.peekContext(firstItemIndex)
|
||||||
}
|
}
|
||||||
|
|
|
@ -119,6 +119,14 @@ func (ras *RandomAccess) Peek(n uint16) (Item, error) {
|
||||||
return ras.vals[index], nil
|
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
|
// Convenience Functions
|
||||||
|
|
||||||
// PopInt will remove the last stack item that was added
|
// PopInt will remove the last stack item that was added
|
||||||
|
|
Loading…
Reference in a new issue