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.
breakPoints []int breakPoints []int
// Return value count, -1 is unspecified.
rvcount int
// Evaluation stack pointer. // Evaluation stack pointer.
estack *Stack estack *Stack
@ -53,7 +50,6 @@ func NewContext(b []byte) *Context {
return &Context{ return &Context{
prog: b, prog: b,
breakPoints: []int{}, 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 := 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)
@ -1248,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)
@ -1270,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
@ -1284,9 +1278,7 @@ 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)