Merge pull request #1222 from nspcc-dev/fix/rvcount

Remove return value count
This commit is contained in:
Roman Khimov 2020-07-23 10:34:34 +03:00 committed by GitHub
commit 18dcc16553
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
4 changed files with 2 additions and 32 deletions

View file

@ -51,7 +51,6 @@ func evalWithArgs(t *testing.T, src string, op []byte, args []stackitem.Item, re
func assertResult(t *testing.T, vm *vm.VM, result interface{}) { func assertResult(t *testing.T, vm *vm.VM, result interface{}) {
assert.Equal(t, result, vm.PopResult()) assert.Equal(t, result, vm.PopResult())
assert.Equal(t, 0, vm.Astack().Len())
assert.Equal(t, 0, vm.Istack().Len()) assert.Equal(t, 0, vm.Istack().Len())
} }

View file

@ -26,15 +26,9 @@ type Context struct {
// Breakpoints. // Breakpoints.
breakPoints []int breakPoints []int
// Return value count, -1 is unspecified.
rvcount int
// Evaluation stack pointer. // Evaluation stack pointer.
estack *Stack estack *Stack
// Alt stack pointer.
astack *Stack
static *Slot static *Slot
local *Slot local *Slot
arguments *Slot arguments *Slot
@ -56,7 +50,6 @@ func NewContext(b []byte) *Context {
return &Context{ return &Context{
prog: b, prog: b,
breakPoints: []int{}, breakPoints: []int{},
rvcount: -1,
} }
} }

View file

@ -70,7 +70,6 @@ type VM struct {
istack *Stack // invocation stack. istack *Stack // invocation stack.
estack *Stack // execution stack. estack *Stack // execution stack.
astack *Stack // alt stack.
refs *refCounter refs *refCounter
@ -100,7 +99,6 @@ func NewWithTrigger(t trigger.Type) *VM {
} }
vm.estack = vm.newItemStack("evaluation") vm.estack = vm.newItemStack("evaluation")
vm.astack = vm.newItemStack("alt")
vm.RegisterInteropGetter(getDefaultVMInterop) vm.RegisterInteropGetter(getDefaultVMInterop)
return vm return vm
@ -142,11 +140,6 @@ func (v *VM) Estack() *Stack {
return v.estack return v.estack
} }
// Astack returns the alt stack so interop hooks can utilize this.
func (v *VM) Astack() *Stack {
return v.astack
}
// Istack returns the invocation stack so interop hooks can utilize this. // Istack returns the invocation stack so interop hooks can utilize this.
func (v *VM) Istack() *Stack { func (v *VM) Istack() *Stack {
return v.istack return v.istack
@ -264,7 +257,6 @@ func (v *VM) Load(prog []byte) {
// Clear all stacks and state, it could be a reload. // Clear all stacks and state, it could be a reload.
v.istack.Clear() v.istack.Clear()
v.estack.Clear() v.estack.Clear()
v.astack.Clear()
v.state = noneState v.state = noneState
v.gasConsumed = 0 v.gasConsumed = 0
v.LoadScript(prog) v.LoadScript(prog)
@ -281,7 +273,6 @@ func (v *VM) LoadScript(b []byte) {
func (v *VM) LoadScriptWithFlags(b []byte, f smartcontract.CallFlag) { func (v *VM) LoadScriptWithFlags(b []byte, f smartcontract.CallFlag) {
ctx := NewContext(b) ctx := NewContext(b)
ctx.estack = v.estack ctx.estack = v.estack
ctx.astack = v.astack
ctx.callFlag = f ctx.callFlag = f
v.istack.PushVal(ctx) v.istack.PushVal(ctx)
} }
@ -319,9 +310,6 @@ func (v *VM) PopResult() interface{} {
// Stack returns json formatted representation of the given stack. // Stack returns json formatted representation of the given stack.
func (v *VM) Stack(n string) string { func (v *VM) Stack(n string) string {
var s *Stack var s *Stack
if n == "astack" {
s = v.astack
}
if n == "istack" { if n == "istack" {
s = v.istack s = v.istack
} }
@ -1245,7 +1233,6 @@ func (v *VM) execute(ctx *Context, op opcode.Opcode, parameter []byte) (err erro
newCtx := ctx.Copy() newCtx := ctx.Copy()
newCtx.local = nil newCtx.local = nil
newCtx.arguments = nil newCtx.arguments = nil
newCtx.rvcount = -1
v.istack.PushVal(newCtx) v.istack.PushVal(newCtx)
offset := v.getJumpOffset(newCtx, parameter) offset := v.getJumpOffset(newCtx, parameter)
@ -1260,7 +1247,6 @@ func (v *VM) execute(ctx *Context, op opcode.Opcode, parameter []byte) (err erro
newCtx := ctx.Copy() newCtx := ctx.Copy()
newCtx.local = nil newCtx.local = nil
newCtx.arguments = nil newCtx.arguments = nil
newCtx.rvcount = -1
v.istack.PushVal(newCtx) v.istack.PushVal(newCtx)
v.jumpIf(newCtx, ptr.Position(), true) v.jumpIf(newCtx, ptr.Position(), true)
@ -1282,13 +1268,9 @@ func (v *VM) execute(ctx *Context, op opcode.Opcode, parameter []byte) (err erro
} }
case opcode.RET: case opcode.RET:
oldCtx := v.istack.Pop().Value().(*Context) v.istack.Pop()
rvcount := oldCtx.rvcount
oldEstack := v.estack oldEstack := v.estack
if rvcount > 0 && oldEstack.Len() < rvcount {
panic("missing some return elements")
}
if v.istack.Len() == 0 { if v.istack.Len() == 0 {
v.state = haltState v.state = haltState
break break
@ -1296,15 +1278,12 @@ func (v *VM) execute(ctx *Context, op opcode.Opcode, parameter []byte) (err erro
newEstack := v.Context().estack newEstack := v.Context().estack
if oldEstack != newEstack { if oldEstack != newEstack {
if rvcount < 0 { rvcount := oldEstack.Len()
rvcount = oldEstack.Len()
}
for i := rvcount; i > 0; i-- { for i := rvcount; i > 0; i-- {
elem := oldEstack.RemoveAt(i - 1) elem := oldEstack.RemoveAt(i - 1)
newEstack.Push(elem) newEstack.Push(elem)
} }
v.estack = newEstack v.estack = newEstack
v.astack = v.Context().astack
} }
case opcode.NEWMAP: case opcode.NEWMAP:

View file

@ -149,7 +149,6 @@ func TestPushBytes1to75(t *testing.T) {
errExec := vm.execute(nil, opcode.RET, nil) errExec := vm.execute(nil, opcode.RET, nil)
require.NoError(t, errExec) require.NoError(t, errExec)
assert.Equal(t, 0, vm.astack.Len())
assert.Equal(t, 0, vm.istack.Len()) assert.Equal(t, 0, vm.istack.Len())
buf.Reset() buf.Reset()
} }