vm: make REVERSE consume an item from stack

This commit is contained in:
Evgenii Stratonikov 2019-09-16 15:46:35 +03:00
parent fd264cb06f
commit d2ccc3b017
2 changed files with 4 additions and 4 deletions

View file

@ -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]

View file

@ -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)