vm: check for fault flag first in Run()

Switch cases are evaluated sequentially and the fault case is top-priority to
handle.
This commit is contained in:
Roman Khimov 2019-10-03 16:04:02 +03:00
parent 705c7f106f
commit 0c963875af

View file

@ -225,6 +225,9 @@ func (v *VM) Run() {
v.state = noneState
for {
switch {
case v.state.HasFlag(faultState):
fmt.Println("FAULT")
return
case v.state.HasFlag(haltState):
if !v.mute {
fmt.Println(v.Stack("estack"))
@ -235,9 +238,6 @@ func (v *VM) Run() {
i, op := ctx.CurrInstr()
fmt.Printf("at breakpoint %d (%s)\n", i, op.String())
return
case v.state.HasFlag(faultState):
fmt.Println("FAULT")
return
case v.state == noneState:
v.Step()
}