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

标准库增加 apple 包, 支持 mvp 环境测试 test 命令

上级 95583934
......@@ -217,6 +217,32 @@ func Main() {
return nil
},
},
{
Hidden: true,
Name: "test",
Usage: "test packages",
Flags: []cli.Flag{
&cli.StringFlag{
Name: "target",
Usage: fmt.Sprintf("set target os (%s)", strings.Join(config.WaOS_List, "|")),
Value: config.WaOS_Default,
},
&cli.StringFlag{
Name: "tags",
Usage: "set build tags",
},
},
Action: func(c *cli.Context) error {
if c.NArg() < 1 {
cli.ShowAppHelpAndExit(c, 0)
}
appArgs := c.Args().Slice()[1:]
waApp := NewApp(build_Options(c))
waApp.RunTest(c.Args().First(), appArgs...)
return nil
},
},
{
Hidden: true,
Name: "native",
......@@ -348,20 +374,6 @@ func Main() {
return nil
},
},
{
Hidden: true,
Name: "test",
Usage: "test packages",
Action: func(c *cli.Context) error {
if c.NArg() < 1 {
cli.ShowAppHelpAndExit(c, 0)
}
appArgs := c.Args().Slice()[1:]
waApp := NewApp(build_Options(c))
waApp.RunTest(c.Args().First(), appArgs...)
return nil
},
},
{
Name: "fmt",
Usage: "format Wa package sources",
......@@ -502,6 +514,12 @@ func build_Options(c *cli.Context, waBackend ...string) *Option {
if len(waBackend) > 0 {
opt.WaBackend = waBackend[0]
}
if target := c.String("target"); !config.CheckWaOS(target) {
fmt.Printf("unknown target: %s\n", c.String("target"))
os.Exit(1)
}
switch c.String("target") {
case "", "wa", "walang":
opt.TargetOS = config.WaOS_Default
......@@ -511,8 +529,10 @@ func build_Options(c *cli.Context, waBackend ...string) *Option {
opt.TargetOS = config.WaOS_arduino
case config.WaOS_chrome:
opt.TargetOS = config.WaOS_chrome
case config.WaOS_mvp:
opt.TargetOS = config.WaOS_mvp
default:
fmt.Printf("unknown target: %s\n", c.String("target"))
fmt.Printf("unreachable: target: %s\n", c.String("target"))
os.Exit(1)
}
return opt
......
......@@ -8,6 +8,7 @@ import (
"github.com/tetratelabs/wazero"
"github.com/tetratelabs/wazero/api"
"github.com/tetratelabs/wazero/sys"
"wa-lang.org/wa/internal/config"
)
......@@ -78,6 +79,14 @@ func MvpInstantiate(ctx context.Context, rt wazero.Runtime) (api.Closer, error)
WithParameterNames("ptr", "len").
Export("waPuts").
// func ProcExit(code: i32)
NewFunctionBuilder().
WithFunc(func(ctx context.Context, m api.Module, exitCode uint32) {
panic(sys.NewExitError(m.Name(), exitCode))
}).
WithParameterNames("code").
Export("proc_exit").
// Done
Instantiate(ctx, rt)
}
// 版权 @2023 凹语言 作者。保留所有权利。
#wa:build !mvp
func Apple => string {
return "apple"
}
\ No newline at end of file
// 版权 @2023 凹语言 作者。保留所有权利。
func Apple => string {
return "apple-mvp"
}
// 版权 @2023 凹语言 作者。保留所有权利。
import "runtime"
// wa test apple
// wa test -target=mvp apple
func TestApple {
apple := Apple()
if runtime.WAOS == "mvp" {
assert(apple == "apple-mvp", apple)
} else {
assert(apple == "apple", apple)
}
}
......@@ -30,13 +30,33 @@ func fdWrite(fd: i32, io: i32, iovs_len: i32, nwritten: i32) => (written: i32) {
}
#wa:linkname $runtime.procExit
func procExit(code: i32) {}
func procExit(code: i32) {
mvp.ProcExit(code)
}
#wa:linkname $runtime.assert
func assert(ok: i32, pos_msg_ptr: i32, pos_msg_len: i32) {}
func assert(ok: i32, pos_msg_ptr: i32, pos_msg_len: i32) {
if ok == 0 {
print("assert failed (")
waPuts(pos_msg_ptr, pos_msg_len)
mvp.PrintRune(')')
mvp.PrintRune('\n')
procExit(1)
}
}
#wa:linkname $runtime.assertMessage
func assertMessage(ok: i32, msg_ptr: i32, msg_len: i32, pos_msg_ptr: i32, pos_msg_len: i32) {}
#wa:linkname $runtime.assertWithMessage
func assertWithMessage(ok: i32, msg_ptr: i32, msg_len: i32, pos_msg_ptr: i32, pos_msg_len: i32) {
if ok == 0 {
print("assert failed: ")
waPuts(msg_ptr, msg_len)
print(" (")
waPuts(pos_msg_ptr, pos_msg_len)
mvp.PrintRune(')')
mvp.PrintRune('\n')
procExit(1)
}
}
#wa:linkname $runtime.waPrintI32
func waPrintI32(i: i32) {
......
// 版权 @2022 凹语言 作者。保留所有权利。
#wa:import mvp proc_exit
func ProcExit(code: i32)
......@@ -104,6 +104,7 @@ func GetStdPkgList() []string {
}
var stdPkgs = []string{
"apple",
"binary",
"bytes",
"errors",
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册