forked from TrueCloudLab/neoneo-go
vm: implement ISNULL opcode
This commit is contained in:
parent
3db030bbb6
commit
f7f48d0048
3 changed files with 22 additions and 0 deletions
|
@ -119,6 +119,8 @@ const (
|
||||||
SYSCALL Opcode = 0x68
|
SYSCALL Opcode = 0x68
|
||||||
TAILCALL Opcode = 0x69
|
TAILCALL Opcode = 0x69
|
||||||
|
|
||||||
|
ISNULL Opcode = 0x70
|
||||||
|
|
||||||
// Stack
|
// Stack
|
||||||
DUPFROMALTSTACK Opcode = 0x6A
|
DUPFROMALTSTACK Opcode = 0x6A
|
||||||
TOALTSTACK Opcode = 0x6B
|
TOALTSTACK Opcode = 0x6B
|
||||||
|
|
|
@ -563,6 +563,10 @@ func (v *VM) execute(ctx *Context, op opcode.Opcode, parameter []byte) (err erro
|
||||||
case opcode.PUSHNULL:
|
case opcode.PUSHNULL:
|
||||||
v.estack.PushVal(NullItem{})
|
v.estack.PushVal(NullItem{})
|
||||||
|
|
||||||
|
case opcode.ISNULL:
|
||||||
|
res := v.estack.Pop().value.Equals(NullItem{})
|
||||||
|
v.estack.PushVal(res)
|
||||||
|
|
||||||
// Stack operations.
|
// Stack operations.
|
||||||
case opcode.TOALTSTACK:
|
case opcode.TOALTSTACK:
|
||||||
v.astack.Push(v.estack.Pop())
|
v.astack.Push(v.estack.Pop())
|
||||||
|
|
|
@ -206,6 +206,22 @@ func TestPUSHNULL(t *testing.T) {
|
||||||
require.True(t, v.estack.Pop().Bool())
|
require.True(t, v.estack.Pop().Bool())
|
||||||
}
|
}
|
||||||
|
|
||||||
|
func TestISNULL(t *testing.T) {
|
||||||
|
t.Run("Integer", func(t *testing.T) {
|
||||||
|
prog := makeProgram(opcode.PUSH1, opcode.ISNULL)
|
||||||
|
v := load(prog)
|
||||||
|
runVM(t, v)
|
||||||
|
require.False(t, v.estack.Pop().Bool())
|
||||||
|
})
|
||||||
|
|
||||||
|
t.Run("Null", func(t *testing.T) {
|
||||||
|
prog := makeProgram(opcode.PUSHNULL, opcode.ISNULL)
|
||||||
|
v := load(prog)
|
||||||
|
runVM(t, v)
|
||||||
|
require.True(t, v.estack.Pop().Bool())
|
||||||
|
})
|
||||||
|
}
|
||||||
|
|
||||||
// appendBigStruct returns a program which:
|
// appendBigStruct returns a program which:
|
||||||
// 1. pushes size Structs on stack
|
// 1. pushes size Structs on stack
|
||||||
// 2. packs them into a new struct
|
// 2. packs them into a new struct
|
||||||
|
|
Loading…
Reference in a new issue