Wasm::Wasmer - WebAssembly in Perl via Wasmer
use Wasm::Wasmer;
my $wasm = Wasm::Wasmer::wat2wasm( <<END );
(module
(type (func (param i32 i32) (result i32)))
(func $add (type 0)
local.get 0
local.get 1
i32.add)
(export "sum" (func $add))
)
END
my $instance = Wasm::Wasmer::Module->new($wasm)->create_instance();
# Prints 7:
print $instance->call('sum', 2, 5) . $/;
This distribution provides an XS binding for Wasmer. This provides a simple, fast way to run WebAssembly (WASM) in Perl.
We mostly follow the relationships from Wasmer’s C API:
- Wasm::Wasmer::Store manages Wasmer’s state, including storage of any imports & exports. It contains compiler & engine configuration as well. This object can be auto-created by default or manually instantiated.
- Wasm::Wasmer::Module uses a Wasm::Wasmer::Store instance to represent a parsed WASM module. This one you always instantiate manually.
- Wasm::Wasmer::Instance uses a Wasm::Wasmer::Module instance to represent an in-progress WASM program. You’ll instantiate these via methods on the Wasm::Wasmer::Module object.
Generally speaking, strings that in common usage are human-readable (e.g., names of imports & exports) are character strings. Ensure that you’ve properly character-decoded such strings, or any non-ASCII characters will cause encoding bugs.
(TIP: Always incorporate code points 128-255 into your testing.)
Binary payloads (e.g., memory contents) are byte strings.
As of this writing, Wasmer’s platform support constrains this module to supporting Linux and macOS only. (Windows might also work?)
Wasm::Wasm3 is an XS binding to wasm3, a broadly-portable WebAssembly interpreter. Try it if you need to run WASM and don’t have Wasmer (or Wasmtime).
Wasm::Wasmtime is an FFI binding to https://wasmtime.dev, a similar project to Wasmer.
Wasm provides syntactic sugar around Wasm::Wasmtime.
This namespace defines the following:
Converts WASM text format to its binary-format equivalent. $TEXT should be (character-decoded) text.
Copyright 2022 Gasper Software Consulting. All rights reserved.
This library is licensed under the same terms as Perl itself. See perlartistic.
This library was originally a research project at cPanel, L.L.C..