Drops support for the WebAssembly text format (#614)
This drops the text format (%.wat) and renames InstantiateModuleFromCode to InstantiateModuleFromBinary as it is no longer ambiguous. We decided to stop supporting the text format as it isn't typically used in production, yet costs a lot of work to develop. Given the resources available and the increased work added with WebAssembly 2.0 and soon WASI 2, we can't afford to spend the time on it. The old parser is used only internally and will eventually be moved to its own repository named watzero, possibly towards archival. See #59 Signed-off-by: Adrian Cole <adrian@tetrate.io>
This commit is contained in:
@@ -12,6 +12,11 @@ import (
|
||||
"github.com/tetratelabs/wazero/api"
|
||||
)
|
||||
|
||||
// addWasm was generated by the following:
|
||||
// cd testdata; wat2wasm --debug-names add.wat
|
||||
//go:embed testdata/add.wasm
|
||||
var addWasm []byte
|
||||
|
||||
// main implements a basic function in both Go and WebAssembly.
|
||||
func main() {
|
||||
// Choose the context to use for function calls.
|
||||
@@ -22,14 +27,7 @@ func main() {
|
||||
defer r.Close(ctx) // This closes everything this Runtime created.
|
||||
|
||||
// Add a module to the runtime named "wasm/math" which exports one function "add", implemented in WebAssembly.
|
||||
wasm, err := r.InstantiateModuleFromCode(ctx, []byte(`(module $wasm/math
|
||||
(func $add (param i32 i32) (result i32)
|
||||
local.get 0
|
||||
local.get 1
|
||||
i32.add
|
||||
)
|
||||
(export "add" (func $add))
|
||||
)`))
|
||||
wasm, err := r.InstantiateModuleFromBinary(ctx, addWasm)
|
||||
if err != nil {
|
||||
log.Panicln(err)
|
||||
}
|
||||
|
||||
BIN
examples/basic/testdata/add.wasm
vendored
Normal file
BIN
examples/basic/testdata/add.wasm
vendored
Normal file
Binary file not shown.
15
examples/basic/testdata/add.wat
vendored
Normal file
15
examples/basic/testdata/add.wat
vendored
Normal file
@@ -0,0 +1,15 @@
|
||||
(module
|
||||
;; Define the optional module name. '$' prefixing is a part of the text format.
|
||||
$wasm/math
|
||||
|
||||
;; add returns $x+$y.
|
||||
;;
|
||||
;; Notes:
|
||||
;; * The stack begins empty and anything left must match the result type.
|
||||
;; * export allows api.Module to return this via ExportedFunction("add")
|
||||
(func (export "add") (param $x i32) (param $y i32) (result i32)
|
||||
local.get $x ;; stack: [$x]
|
||||
local.get $y ;; stack: [$x, $y]
|
||||
i32.add ;; stack: [$x+$y]
|
||||
)
|
||||
)
|
||||
Reference in New Issue
Block a user