mirror of
https://github.com/nspcc-dev/neo-go.git
synced 2024-11-26 19:42:23 +00:00
vm: add Value() method to Element
It gives access to the internal value's Value() which is essential for interop functions that need to get something from InteropItems. And it also simplifies some already existing code along the way.
This commit is contained in:
parent
0c963875af
commit
d62a367900
3 changed files with 9 additions and 4 deletions
|
@ -10,13 +10,13 @@ type InteropFunc func(vm *VM) error
|
|||
// runtimeLog will handle the syscall "Neo.Runtime.Log" for printing and logging stuff.
|
||||
func runtimeLog(vm *VM) error {
|
||||
item := vm.Estack().Pop()
|
||||
fmt.Printf("NEO-GO-VM (log) > %s\n", item.value.Value())
|
||||
fmt.Printf("NEO-GO-VM (log) > %s\n", item.Value())
|
||||
return nil
|
||||
}
|
||||
|
||||
// runtimeNotify will handle the syscall "Neo.Runtime.Notify" for printing and logging stuff.
|
||||
func runtimeNotify(vm *VM) error {
|
||||
item := vm.Estack().Pop()
|
||||
fmt.Printf("NEO-GO-VM (notify) > %s\n", item.value.Value())
|
||||
fmt.Printf("NEO-GO-VM (notify) > %s\n", item.Value())
|
||||
return nil
|
||||
}
|
||||
|
|
|
@ -58,6 +58,11 @@ func (e *Element) Prev() *Element {
|
|||
return nil
|
||||
}
|
||||
|
||||
// Value returns value of the StackItem contained in the element.
|
||||
func (e *Element) Value() interface{} {
|
||||
return e.value.Value()
|
||||
}
|
||||
|
||||
// BigInt attempts to get the underlying value of the element as a big integer.
|
||||
// Will panic if the assertion failed which will be caught by the VM.
|
||||
func (e *Element) BigInt() *big.Int {
|
||||
|
|
|
@ -181,7 +181,7 @@ func (v *VM) Context() *Context {
|
|||
if v.istack.Len() == 0 {
|
||||
return nil
|
||||
}
|
||||
return v.istack.Peek(0).value.Value().(*Context)
|
||||
return v.istack.Peek(0).Value().(*Context)
|
||||
}
|
||||
|
||||
// PopResult is used to pop the first item of the evaluation stack. This allows
|
||||
|
@ -827,7 +827,7 @@ func (v *VM) execute(ctx *Context, op Instruction) {
|
|||
elem := v.estack.Pop()
|
||||
// Cause there is no native (byte) item type here, hence we need to check
|
||||
// the type of the item for array size operations.
|
||||
switch t := elem.value.Value().(type) {
|
||||
switch t := elem.Value().(type) {
|
||||
case []StackItem:
|
||||
v.estack.PushVal(len(t))
|
||||
case map[interface{}]StackItem:
|
||||
|
|
Loading…
Reference in a new issue