commit 7c1bc78c986bfae7e4308c84549e464fd8972fd0
parent a3073f6189b34da5d4e8bc71cb7f1b3882dde154
Author: lash <dev@holbrook.no>
Date: Thu, 6 Apr 2023 10:55:11 +0100
Add invalid input node in testdata
Diffstat:
3 files changed, 19 insertions(+), 6 deletions(-)
diff --git a/go/dev/interactive.go b/go/dev/interactive.go
@@ -43,12 +43,11 @@ func main() {
in = strings.TrimSpace(in)
running, err = en.Exec([]byte(in), ctx)
if err != nil {
- fmt.Fprintf(os.Stderr, "execution terminated: %v\n", err)
+ fmt.Fprintf(os.Stderr, "unexpected termination: %v\n", err)
os.Exit(1)
}
b := bytes.NewBuffer(nil)
en.WriteResult(b)
fmt.Println(b.String())
}
-
}
diff --git a/go/testdata/testdata.go b/go/testdata/testdata.go
@@ -86,13 +86,24 @@ func baz() error {
return out("baz", b, tpl)
}
+func defaultCatch() error {
+ b := []byte{}
+ b = vm.NewLine(b, vm.MOUT, []string{"0", "back"}, nil, nil)
+ b = vm.NewLine(b, vm.HALT, nil, nil, nil)
+ b = vm.NewLine(b, vm.MOVE, []string{"_"}, nil, nil)
+
+ tpl := "invalid input"
+
+ return out("_catch", b, tpl)
+}
+
func generate() error {
err := os.MkdirAll(DataDir, 0755)
if err != nil {
return err
}
- fns := []genFunc{root, foo, bar, baz}
+ fns := []genFunc{root, foo, bar, baz, defaultCatch}
for _, fn := range fns {
err = fn()
if err != nil {
diff --git a/go/vm/runner.go b/go/vm/runner.go
@@ -94,8 +94,6 @@ func RunDeadCheck(b []byte, st *state.State, rs resource.Resource, ctx context.C
return b, fmt.Errorf("dead runner with no current location")
}
b = NewLine(nil, MOVE, []string{"_catch"}, nil, nil)
- b = NewLine(b, HALT, nil, nil, nil)
- b = NewLine(b, MOVE, []string{location}, nil, nil)
log.Printf("code is now %x", b)
return b, nil
}
@@ -180,7 +178,12 @@ func RunMove(b []byte, st *state.State, rs resource.Resource, ctx context.Contex
if err != nil {
return b, err
}
- st.Down(sym)
+ if sym == "_" {
+ st.Up()
+ sym = st.Where()
+ } else {
+ st.Down(sym)
+ }
code, err := rs.GetCode(sym)
if err != nil {
return b, err