vm: remove rvcount

It isn't used anymore.
This commit is contained in:
Evgenii Stratonikov 2020-07-22 13:25:50 +03:00
parent 261ff3c655
commit 58a594e3d4
2 changed files with 2 additions and 14 deletions

View file

@ -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,
}
}

View file

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