vm: add some tests for PACK instruction

This commit is contained in:
Roman Khimov 2019-09-06 10:33:43 +03:00
parent 0feaaabe61
commit 5bd50c7bcd
2 changed files with 52 additions and 0 deletions

View file

@ -84,6 +84,18 @@ func (e *Element) Bytes() []byte {
return e.value.Value().([]byte)
}
// Array attempts to get the underlying value of the element as an array of
// other items. Will panic if the item type is different which will be caught
// by the VM.
func (e *Element) Array() []StackItem {
switch t := e.value.(type) {
case *ArrayItem:
return t.value
default:
panic("element is not an array")
}
}
// Stack represents a Stack backed by a double linked list.
type Stack struct {
top Element