diff --git a/main.go b/main.go index 3a0f2e9e194f71b7f6f4d3a0326afa36b8ac0ecc..f151f774720759027e88d80df671fac92d32180d 100644 --- a/main.go +++ b/main.go @@ -6,7 +6,6 @@ package main import ( "fmt" "os" - "os/exec" "runtime/debug" "strings" "time" @@ -58,16 +57,33 @@ func main() { cli.ShowAppHelpAndExit(c, 0) } - waApp := app.NewApp(build_Options(c)) - data, err := waApp.Run(c.Args().First(), nil) - if len(data) != 0 { - fmt.Print(string(data)) + ctx := app.NewApp(build_Options(c)) + output, err := ctx.WASM(c.Args().First()) + if err != nil { + fmt.Println(err) + os.Exit(1) } - if errx, ok := err.(*exec.ExitError); ok { - os.Exit(errx.ExitCode()) + + outfile := "a.out.wat" + if !c.Bool("debug") { + defer os.Remove(outfile) } + + if err = os.WriteFile(outfile, []byte(output), 0666); err != nil { + fmt.Println(err) + os.Exit(1) + } + + stdoutStderr, err := app.RunWasm(outfile) if err != nil { + if len(stdoutStderr) > 0 { + fmt.Println(string(stdoutStderr)) + } fmt.Println(err) + os.Exit(1) + } + if len(stdoutStderr) > 0 { + fmt.Println(string(stdoutStderr)) } return nil }