go-vise

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

commit 719368301b533b1ed9858ecc73e983236621a1ac
parent 4da19b30479d145a469b61489277d88988cb547a
Author: lash <dev@holbrook.no>
Date:   Wed, 12 Apr 2023 08:42:37 +0100

Catch browse back beyond start

Diffstat:
Mgo/state/state.go | 9++++++++-
Mgo/vm/runner.go | 13++++++++++++-
2 files changed, 20 insertions(+), 2 deletions(-)

diff --git a/go/state/state.go b/go/state/state.go @@ -6,6 +6,13 @@ import ( "strings" ) +type IndexError struct { +} + +func(err *IndexError) Error() string { + return fmt.Sprintf("already at first index") +} + // State holds the command stack, error condition of a unique execution session. // // It also holds cached values for all results of executed symbols. @@ -208,7 +215,7 @@ func(st *State) Previous() (uint16, error) { return 0, fmt.Errorf("state root node not yet defined") } if st.sizeIdx == 0 { - return 0, fmt.Errorf("already at first index") + return 0, &IndexError{} // ("already at first index") } st.sizeIdx -= 1 s, idx := st.Where() diff --git a/go/vm/runner.go b/go/vm/runner.go @@ -313,7 +313,18 @@ func(vm *Vm) RunInCmp(b []byte, ctx context.Context) ([]byte, error) { } target, _, err = applyTarget([]byte(target), vm.st, vm.ca, ctx) - if err != nil { + _, ok := err.(*state.IndexError) + if ok { + _, err = vm.st.ResetFlag(state.FLAG_INMATCH) + if err != nil { + panic(err) + } + _, err = vm.st.SetFlag(state.FLAG_READIN) + if err != nil { + panic(err) + } + return b, nil + } else if err != nil { return b, err } vm.Reset()