未验证 提交 d05904de 编写于 作者: C Crypt Keeper 提交者: GitHub

deps: updates wazero to 1.0.0-pre.3 (#37)

This updates [wazero](https://wazero.io/) to [1.0.0-pre.3](https://github.com/tetratelabs/wazero/releases/tag/v1.0.0-pre.3). This is the last release that will build with Go 1.17.

Notably, this improves performance and changes host function syntax.
Signed-off-by: NAdrian Cole <adrian@tetrate.io>
Signed-off-by: NAdrian Cole <adrian@tetrate.io>
上级 6584f922
......@@ -5,6 +5,6 @@ module github.com/wa-lang/wa
go 1.17
require (
github.com/tetratelabs/wazero v1.0.0-pre.1
github.com/tetratelabs/wazero v1.0.0-pre.3
github.com/wa-lang/wabt-go v1.1.0
)
......@@ -39,25 +39,29 @@ func RunWasm(filename string) (stdoutStderr []byte, err error) {
}
ctx := context.Background()
r := wazero.NewRuntimeWithConfig(ctx,
wazero.NewRuntimeConfig().WithWasmCore2(),
)
r := wazero.NewRuntime(ctx)
defer r.Close(ctx)
_, err = r.NewModuleBuilder("wa_js_env").
ExportFunction("waPuts", func(m api.Module, pos, len uint32) {
_, err = r.NewHostModuleBuilder("wa_js_env").
NewFunctionBuilder().
WithFunc(func(ctx context.Context, m api.Module, pos, len uint32) {
bytes, _ := m.Memory().Read(ctx, pos, len)
fmt.Print(string(bytes))
return
}).
ExportFunction("waPrintI32", func(m api.Module, v uint32) {
WithParameterNames("pos", "len").
Export("waPuts").
NewFunctionBuilder().
WithFunc(func(ctx context.Context, v uint32) {
fmt.Print(v)
return
}).
ExportFunction("waPrintRune", func(m api.Module, ch uint32) {
WithParameterNames("v").
Export("waPrintI32").
NewFunctionBuilder().
WithFunc(func(ctx context.Context, ch uint32) {
fmt.Printf("%c", rune(ch))
return
}).
WithParameterNames("ch").
Export("waPrintRune").
Instantiate(ctx, r)
if err != nil {
return nil, err
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册