Terminate on code EOF when not checking input
This commit is contained in:
parent
602ca92b6a
commit
765bc2a269
@ -1,7 +1,8 @@
|
||||
package state
|
||||
|
||||
const (
|
||||
FLAG_INMATCH = 1
|
||||
FLAG_TERMINATE = 2
|
||||
FLAG_READIN = 1
|
||||
FLAG_INMATCH = 2
|
||||
FLAG_TERMINATE = 3
|
||||
FLAG_DIRTY = 4
|
||||
)
|
||||
|
@ -125,7 +125,19 @@ func(vm *Vm) RunDeadCheck(b []byte, ctx context.Context) ([]byte, error) {
|
||||
if len(b) > 0 {
|
||||
return b, nil
|
||||
}
|
||||
r, err := vm.st.MatchFlag(state.FLAG_TERMINATE, false)
|
||||
r, err := vm.st.MatchFlag(state.FLAG_READIN, true)
|
||||
if err != nil {
|
||||
panic(err)
|
||||
}
|
||||
if r {
|
||||
log.Printf("Not processing input. Setting terminate")
|
||||
_, err := vm.st.SetFlag(state.FLAG_TERMINATE)
|
||||
if err != nil {
|
||||
panic(err)
|
||||
}
|
||||
return b, nil
|
||||
}
|
||||
r, err = vm.st.MatchFlag(state.FLAG_TERMINATE, false)
|
||||
if err != nil {
|
||||
panic(err)
|
||||
}
|
||||
@ -133,6 +145,8 @@ func(vm *Vm) RunDeadCheck(b []byte, ctx context.Context) ([]byte, error) {
|
||||
log.Printf("Terminate found!!")
|
||||
return b, nil
|
||||
}
|
||||
|
||||
|
||||
log.Printf("no code remaining but not terminating")
|
||||
location, _ := vm.st.Where()
|
||||
if location == "" {
|
||||
@ -252,13 +266,25 @@ func(vm *Vm) RunInCmp(b []byte, ctx context.Context) ([]byte, error) {
|
||||
if err != nil {
|
||||
return b, err
|
||||
}
|
||||
v, err := vm.st.GetFlag(state.FLAG_INMATCH)
|
||||
|
||||
change, err := vm.st.SetFlag(state.FLAG_READIN)
|
||||
if err != nil {
|
||||
return b, err
|
||||
panic(err)
|
||||
}
|
||||
if v {
|
||||
have, err := vm.st.GetFlag(state.FLAG_INMATCH)
|
||||
if err != nil {
|
||||
panic(err)
|
||||
}
|
||||
if have {
|
||||
if change {
|
||||
_, err = vm.st.ResetFlag(state.FLAG_INMATCH)
|
||||
if err != nil {
|
||||
panic(err)
|
||||
}
|
||||
} else {
|
||||
return b, nil
|
||||
}
|
||||
}
|
||||
input, err := vm.st.GetInput()
|
||||
if err != nil {
|
||||
return b, err
|
||||
@ -275,7 +301,11 @@ func(vm *Vm) RunInCmp(b []byte, ctx context.Context) ([]byte, error) {
|
||||
|
||||
_, err = vm.st.SetFlag(state.FLAG_INMATCH)
|
||||
if err != nil {
|
||||
return b, err
|
||||
panic(err)
|
||||
}
|
||||
_, err = vm.st.ResetFlag(state.FLAG_READIN)
|
||||
if err != nil {
|
||||
panic(err)
|
||||
}
|
||||
|
||||
target, _, err = applyTarget([]byte(target), vm.st, vm.ca, ctx)
|
||||
@ -300,7 +330,6 @@ func(vm *Vm) RunHalt(b []byte, ctx context.Context) ([]byte, error) {
|
||||
return b, err
|
||||
}
|
||||
log.Printf("found HALT, stopping")
|
||||
_, err = vm.st.ResetFlag(state.FLAG_INMATCH)
|
||||
return b, err
|
||||
}
|
||||
|
||||
|
@ -396,6 +396,6 @@ func TestRunReturn(t *testing.T) {
|
||||
}
|
||||
location, _ = st.Where()
|
||||
if location != "root" {
|
||||
t.Fatalf("expected location 'foo', got '%s'", location)
|
||||
t.Fatalf("expected location 'root', got '%s'", location)
|
||||
}
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user