From 58a594e3d4ebfe4dffef5035abb8609bad8c80d3 Mon Sep 17 00:00:00 2001 From: Evgenii Stratonikov Date: Wed, 22 Jul 2020 13:25:50 +0300 Subject: [PATCH] vm: remove rvcount It isn't used anymore. --- pkg/vm/context.go | 4 ---- pkg/vm/vm.go | 12 ++---------- 2 files changed, 2 insertions(+), 14 deletions(-) diff --git a/pkg/vm/context.go b/pkg/vm/context.go index 146077268..fba31f11e 100644 --- a/pkg/vm/context.go +++ b/pkg/vm/context.go @@ -26,9 +26,6 @@ type Context struct { // Breakpoints. breakPoints []int - // Return value count, -1 is unspecified. - rvcount int - // Evaluation stack pointer. estack *Stack @@ -53,7 +50,6 @@ func NewContext(b []byte) *Context { return &Context{ prog: b, breakPoints: []int{}, - rvcount: -1, } } diff --git a/pkg/vm/vm.go b/pkg/vm/vm.go index 673c5921b..bd5ab19fc 100644 --- a/pkg/vm/vm.go +++ b/pkg/vm/vm.go @@ -1233,7 +1233,6 @@ func (v *VM) execute(ctx *Context, op opcode.Opcode, parameter []byte) (err erro newCtx := ctx.Copy() newCtx.local = nil newCtx.arguments = nil - newCtx.rvcount = -1 v.istack.PushVal(newCtx) offset := v.getJumpOffset(newCtx, parameter) @@ -1248,7 +1247,6 @@ func (v *VM) execute(ctx *Context, op opcode.Opcode, parameter []byte) (err erro newCtx := ctx.Copy() newCtx.local = nil newCtx.arguments = nil - newCtx.rvcount = -1 v.istack.PushVal(newCtx) v.jumpIf(newCtx, ptr.Position(), true) @@ -1270,13 +1268,9 @@ func (v *VM) execute(ctx *Context, op opcode.Opcode, parameter []byte) (err erro } case opcode.RET: - oldCtx := v.istack.Pop().Value().(*Context) - rvcount := oldCtx.rvcount + v.istack.Pop() oldEstack := v.estack - if rvcount > 0 && oldEstack.Len() < rvcount { - panic("missing some return elements") - } if v.istack.Len() == 0 { v.state = haltState break @@ -1284,9 +1278,7 @@ func (v *VM) execute(ctx *Context, op opcode.Opcode, parameter []byte) (err erro newEstack := v.Context().estack if oldEstack != newEstack { - if rvcount < 0 { - rvcount = oldEstack.Len() - } + rvcount := oldEstack.Len() for i := rvcount; i > 0; i-- { elem := oldEstack.RemoveAt(i - 1) newEstack.Push(elem)