cue/interpreter/wasm: add Wasm support for abi=c
Add a new package, cuelang.org/go/cue/interpreter/wasm that enables
Wasm support in CUE as an external interpreter. Code wishing to use
Wasm must use an `@extern("wasm")` package attribute. Individual
functions are imported from Wasm modules like so:
add: _ @extern("foo.wasm", abi=c, sig="func(int64, int64): int64")
mul: _ @extern("foo.wasm", abi=c, sig="func(float64, float64): float64")
not: _ @extern("foo.wasm", abi=c, sig="func(bool): bool")
Where "foo.wasm" is a compiled Wasm module, and sig is the type
signature of the imported function.
So far, only the C ABI is supported, and only relatively few data
types can be exchanged with the Wasm module. Basically only fixed-sized
integers of any signness, fixed-sized floats, and booleans.
The Wasm module is instantiated in a sandbox, with no access to the
outside world. Users must ensure the functions exposed by the Wasm
modules are pure, that is, they always returns the same answer for
the same arguments. Functions may make use of global state for
memoization and other optimizations as long as purity is preserved
as viewed from the outside. Be aware that functions from the standard
libraries of many languages are often not pure.
Wasm is only enabled if the user explicitly imports
cuelang.org/go/cue/wasm, otherwise it is not available. The Go cue
package does not impart upon the user a dependency on the Wasm
runtime if Wasm is not explicitly requested.
Wasm is enabled and available in the command line tool.
Updates #2035.
Updates #2281.
Updates #2282.
Updates #2007.
Change-Id: I844ec1229ea465dfeca45bc54006e87ed8ef0460
Signed-off-by: Aram Hăvărneanu <aram@mgk.ro>
Reviewed-on: https://review.gerrithub.io/c/cue-lang/cue/+/551738
Unity-Result: CUEcueckoo <cueckoo+gerrithub@cuelang.org>
TryBot-Result: CUEcueckoo <cueckoo+gerrithub@cuelang.org>
Reviewed-by: Marcel van Lohuizen <mpvl@gmail.com>
Reviewed-by: Roger Peppe <rogpeppe@gmail.com>
authored by
This is a binary file and will not be displayed.
This is a binary file and will not be displayed.
This is a binary file and will not be displayed.
This is a binary file and will not be displayed.
This is a binary file and will not be displayed.
This is a binary file and will not be displayed.