go-vise

Constrained Size Output Virtual Machine
Info | Log | Files | Refs | README | LICENSE

commit 765bc2a2697b562f7741175ce871f4f791a05979
parent 602ca92b6a412f8e10d8f191a1d3c8ef7be3d658
Author: lash <dev@holbrook.no>
Date:   Mon, 10 Apr 2023 09:19:18 +0100

Terminate on code EOF when not checking input

Diffstat:
Mgo/state/flag.go | 5+++--
Mgo/vm/runner.go | 43++++++++++++++++++++++++++++++++++++-------
Mgo/vm/runner_test.go | 2+-
3 files changed, 40 insertions(+), 10 deletions(-)

diff --git a/go/state/flag.go b/go/state/flag.go @@ -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 ) diff --git a/go/vm/runner.go b/go/vm/runner.go @@ -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,12 +266,24 @@ 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 { - return b, nil + 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 { @@ -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 } diff --git a/go/vm/runner_test.go b/go/vm/runner_test.go @@ -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) } }