diff --git a/go/dev/interactive.go b/go/dev/interactive.go index 8332c18..dedc5c6 100644 --- 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 index 2ab1612..a327407 100644 --- 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 index a15df30..eb0c391 100644 --- 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