commit 8446e634ae5b09e130f1a20bedde6f08cec2cde2
parent 00e3a9fb8761cc372e353c712a04558931c24280
Author: lash <dev@holbrook.no>
Date: Sun, 23 Apr 2023 12:50:11 +0100
Rehabilitate examples, fix state bit match bug
Diffstat:
4 files changed, 28 insertions(+), 11 deletions(-)
diff --git a/engine/engine.go b/engine/engine.go
@@ -178,7 +178,7 @@ func(en *Engine) exec(ctx context.Context, input []byte) (bool, error) {
}
Logg.Debugf("end new VM run", "code", code)
- v, err := en.st.MatchFlag(state.FLAG_TERMINATE, false)
+ v, err := en.st.MatchFlag(state.FLAG_TERMINATE, true)
if err != nil {
return false, err
}
diff --git a/state/state.go b/state/state.go
@@ -151,15 +151,8 @@ func(st *State) MatchFlag(sig uint32, matchSet bool) (bool, error) {
if err != nil {
return false, err
}
- return matchSet && r, nil
-// if matchSet {
-// if !r {
-// return false, nil
-// }
-// } else if r {
-// return true, nil
-// }
-// return false, nil
+ Logg.Debugf("rrr", "r", r, "match", matchSet)
+ return matchSet == r, nil
}
// GetIndex scans a byte slice in same order as in storage, and returns the index of the first set bit.
diff --git a/state/state_test.go b/state/state_test.go
@@ -217,3 +217,25 @@ func TestStateNavigate(t *testing.T) {
t.Fatalf("expected idx 0, got %v", i)
}
}
+
+func TestStateFlagMatch(t *testing.T) {
+ st := NewState(2)
+ st.SetFlag(8)
+ v, _ := st.MatchFlag(8, true)
+ if !v {
+ t.Fatalf("unexpected flag")
+ }
+ v, _ = st.MatchFlag(8, false)
+ if v {
+ t.Fatalf("unexpected flag")
+ }
+
+ v, _ = st.MatchFlag(9, true)
+ if v {
+ t.Fatalf("unexpected flag")
+ }
+ v, _ = st.MatchFlag(9, false)
+ if !v {
+ t.Fatalf("unexpected flag")
+ }
+}
diff --git a/vm/runner.go b/vm/runner.go
@@ -227,12 +227,14 @@ func(vm *Vm) runDeadCheck(ctx context.Context, b []byte) ([]byte, error) {
return b, nil
}
-
Logg.TraceCtxf(ctx, "no code remaining but not terminating")
location, _ := vm.st.Where()
if location == "" {
return b, fmt.Errorf("dead runner with no current location")
+ } else if location == "_catch" {
+ return b, fmt.Errorf("unexpected catch endless loop detected for state: %s", vm.st)
}
+
input, err := vm.st.GetInput()
if err != nil {
input = []byte("(no input)")