This improves the experimental logging listener to show parameter name
and values like so:
```
--> ._start.command_export()
--> .__wasm_call_ctors()
--> .__wasilibc_initialize_environ()
==> wasi_snapshot_preview1.environ_sizes_get(result.environc=1048572,result.environBufSize=1048568)
<== ESUCCESS
<-- ()
==> wasi_snapshot_preview1.fd_prestat_get(fd=3,result.prestat=1048568)
<== ESUCCESS
--> .dlmalloc(2)
--> .sbrk(0)
<-- (1114112)
<-- (1060080)
--snip--
```
The convention `==>` implies it was a host function call
(def.IsHostFunction). This also improves the lifecycle by creating
listeners during compile. Finally, this backfills param names for
assemblyscript and wasi.
Signed-off-by: Adrian Cole <adrian@tetrate.io>
47 lines
1.2 KiB
Go
47 lines
1.2 KiB
Go
package assemblyscript_test
|
|
|
|
import (
|
|
"context"
|
|
_ "embed"
|
|
"log"
|
|
|
|
"github.com/tetratelabs/wazero"
|
|
"github.com/tetratelabs/wazero/assemblyscript"
|
|
)
|
|
|
|
// This shows how to instantiate AssemblyScript's special imports.
|
|
func Example_instantiate() {
|
|
ctx := context.Background()
|
|
|
|
r := wazero.NewRuntime()
|
|
defer r.Close(ctx) // This closes everything this Runtime created.
|
|
|
|
// This adds the "env" module to the runtime, with AssemblyScript's special
|
|
// function imports.
|
|
if _, err := assemblyscript.Instantiate(ctx, r); err != nil {
|
|
log.Panicln(err)
|
|
}
|
|
|
|
// Output:
|
|
}
|
|
|
|
// This shows how to instantiate AssemblyScript's special imports when you also
|
|
// need other functions in the "env" module.
|
|
func Example_functionExporter() {
|
|
ctx := context.Background()
|
|
|
|
r := wazero.NewRuntime()
|
|
defer r.Close(ctx) // This closes everything this Runtime created.
|
|
|
|
// First construct your own module builder for "env"
|
|
envBuilder := r.NewModuleBuilder("env").
|
|
ExportFunction("get_int", func() uint32 { return 1 })
|
|
|
|
// Now, add AssemblyScript special function imports into it.
|
|
assemblyscript.NewFunctionExporter().
|
|
WithAbortMessageDisabled().
|
|
ExportFunctions(envBuilder)
|
|
|
|
// Output:
|
|
}
|