compiler: clean up stack on branch statements

When `return` or `break` statement is encountered inside
a for/range/switch statement, top stack items can be auxilliary.
They need to be cleaned up before returning from the function.
This commit is contained in:
Evgenii Stratonikov 2020-03-06 15:11:14 +03:00
parent 3f1e8f66b6
commit 2a1402f25d
3 changed files with 63 additions and 2 deletions

View file

@ -23,10 +23,17 @@ func runTestCases(t *testing.T, tcases []testCase) {
}
}
func evalWithoutStackChecks(t *testing.T, src string, result interface{}) {
v := vmAndCompile(t, src)
require.NoError(t, v.Run())
assertResult(t, v, result)
}
func eval(t *testing.T, src string, result interface{}) {
vm := vmAndCompile(t, src)
err := vm.Run()
require.NoError(t, err)
assert.Equal(t, 1, vm.Estack().Len(), "stack contains unexpected items")
assertResult(t, vm, result)
}
@ -35,6 +42,7 @@ func evalWithArgs(t *testing.T, src string, op []byte, args []vm.StackItem, resu
vm.LoadArgs(op, args)
err := vm.Run()
require.NoError(t, err)
assert.Equal(t, 1, vm.Estack().Len(), "stack contains unexpected items")
assertResult(t, vm, result)
}