提交 7f2f0983 编写于 作者: chai2010's avatar chai2010

增加 os.Exit 函数

上级 e916cb0a
......@@ -15,6 +15,7 @@ import (
"sync"
"github.com/tetratelabs/wazero"
"github.com/tetratelabs/wazero/sys"
"wa-lang.org/wa/internal/app/waruntime"
"wa-lang.org/wa/internal/config"
......@@ -78,6 +79,11 @@ func RunWasm(cfg *config.Config, filename string, wasmArgs ...string) (stdoutStd
_, err = r.InstantiateModule(ctx, code, conf)
if err != nil {
if exitErr, ok := err.(*sys.ExitError); ok {
if exitErr.ExitCode() == 0 {
return outputBuffer.Bytes(), nil
}
}
return outputBuffer.Bytes(), err
}
......
......@@ -5,6 +5,9 @@ var Args []string
#wa:linkname runtime.os_get_args
func os_get_args() => []string
#wa:linkname $runtime.procExit
func Exit(code: i32)
func init {
Args = os_get_args()
}
......@@ -19,6 +19,9 @@ func fdWrite(fd: i32, io: i32, iovs_len: i32, nwritten: i32) => (written: i32) {
return
}
#wa:linkname $runtime.procExit
func procExit(code: i32) {}
#wa:linkname $runtime.waPrintI32
func waPrintI32(i: i32) {}
......
......@@ -17,6 +17,9 @@ func fdWrite(fd: i32, io: i32, iovs_len: i32, nwritten: i32) => (written: i32) {
return
}
#wa:linkname $runtime.procExit
func procExit(code: i32) {}
#wa:linkname $runtime.waPrintI32
func waPrintI32(i: i32) {}
......
......@@ -14,6 +14,10 @@ func argsGet(result_argv: i32, result_argv_buf: i32) => (errno: i32)
#wa:linkname $runtime.fdWrite
func fdWrite(fd: i32, io: i32, iovs_len: i32, nwritten: i32) => (errno: i32)
#wa:import wasi_snapshot_preview1 proc_exit
#wa:linkname $runtime.procExit
func procExit(code: i32)
#wa:linkname puts
func puts(ptr: i32, len: i32)
......
......@@ -13,6 +13,8 @@ import (
"strings"
"time"
"github.com/tetratelabs/wazero/sys"
"wa-lang.org/wa/api"
"wa-lang.org/wa/internal/3rdparty/cli"
"wa-lang.org/wa/internal/app"
......@@ -550,8 +552,10 @@ func cliRun(c *cli.Context) {
if len(stdoutStderr) > 0 {
fmt.Println(string(stdoutStderr))
}
if exitErr, ok := err.(*sys.ExitError); ok {
os.Exit(int(exitErr.ExitCode()))
}
fmt.Println(err)
os.Exit(1)
}
if len(stdoutStderr) > 0 {
fmt.Println(string(stdoutStderr))
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册