forked from TrueCloudLab/neoneo-go
Merge pull request #442 from nspcc-dev/vm-fix-run
vm: fix tests failing, follow-up to #426
This commit is contained in:
commit
d34ad8d0de
1 changed files with 13 additions and 2 deletions
15
pkg/vm/vm.go
15
pkg/vm/vm.go
|
@ -258,6 +258,12 @@ func (v *VM) Run() error {
|
||||||
return errors.New("no program loaded")
|
return errors.New("no program loaded")
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if v.state.HasFlag(faultState) {
|
||||||
|
// VM already ran something and failed, in general its state is
|
||||||
|
// undefined in this case so we can't run anything.
|
||||||
|
return errors.New("VM has failed")
|
||||||
|
}
|
||||||
|
// haltState (the default) or breakState are safe to continue.
|
||||||
v.state = noneState
|
v.state = noneState
|
||||||
for {
|
for {
|
||||||
// check for breakpoint before executing the next instruction
|
// check for breakpoint before executing the next instruction
|
||||||
|
@ -266,8 +272,13 @@ func (v *VM) Run() error {
|
||||||
v.state |= breakState
|
v.state |= breakState
|
||||||
}
|
}
|
||||||
switch {
|
switch {
|
||||||
case v.state.HasFlag(faultState), v.state.HasFlag(haltState), v.state.HasFlag(breakState):
|
case v.state.HasFlag(faultState):
|
||||||
return errors.New("VM stopped")
|
// Should be caught and reported already by the v.Step(),
|
||||||
|
// but we're checking here anyway just in case.
|
||||||
|
return errors.New("VM has failed")
|
||||||
|
case v.state.HasFlag(haltState), v.state.HasFlag(breakState):
|
||||||
|
// Normal exit from this loop.
|
||||||
|
return nil
|
||||||
case v.state == noneState:
|
case v.state == noneState:
|
||||||
if err := v.Step(); err != nil {
|
if err := v.Step(); err != nil {
|
||||||
return err
|
return err
|
||||||
|
|
Loading…
Reference in a new issue