diff --git a/pkg/vm/vm.go b/pkg/vm/vm.go index a209a1382..f0647d8d6 100644 --- a/pkg/vm/vm.go +++ b/pkg/vm/vm.go @@ -722,7 +722,7 @@ func (v *VM) execute(ctx *Context, op Instruction) { } case REVERSE: - a := v.estack.Peek(0).Array() + a := v.estack.Pop().Array() if len(a) > 1 { for i, j := 0, len(a)-1; i <= j; i, j = i+1, j-1 { a[i], a[j] = a[j], a[i] diff --git a/pkg/vm/vm_test.go b/pkg/vm/vm_test.go index 02b82b3a0..2193afcb9 100644 --- a/pkg/vm/vm_test.go +++ b/pkg/vm/vm_test.go @@ -1317,7 +1317,7 @@ func TestREVERSEBadNotArray(t *testing.T) { } func TestREVERSEGoodOneElem(t *testing.T) { - prog := makeProgram(REVERSE) + prog := makeProgram(DUP, REVERSE) elements := []int{22} vm := load(prog) vm.estack.PushVal(1) @@ -1337,7 +1337,7 @@ func TestREVERSEGoodStruct(t *testing.T) { eall := [][]int{eodd, even} for _, elements := range eall { - prog := makeProgram(REVERSE) + prog := makeProgram(DUP, REVERSE) vm := load(prog) vm.estack.PushVal(1) @@ -1366,7 +1366,7 @@ func TestREVERSEGood(t *testing.T) { eall := [][]int{eodd, even} for _, elements := range eall { - prog := makeProgram(REVERSE) + prog := makeProgram(DUP, REVERSE) vm := load(prog) vm.estack.PushVal(1) vm.estack.PushVal(elements)