NAME
Wasm::Wasmer - WebAssembly in Perl via Wasmer
SYNOPSIS
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) . $/;
DESCRIPTION
This distribution provides an XS binding for Wasmer. This provides a simple, fast way to run WebAssembly (WASM) in Perl.
MODULE RELATIONSHIPS
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.
CHARACTER ENCODING
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.
PLATFORM SUPPORT
As of this writing, Wasmer’s platform support constrains this module to supporting Linux and macOS only. (Windows might also work?)
SEE ALSO
Wasm::Wasmtime is an FFI binding to https://wasmtime.dev, a similar project to Wasmer.
Wasm provides syntactic sugar around Wasm::Wasmtime.
FUNCTIONS
This namespace defines the following:
$bin = wat2wasm( $TEXT )
Converts WASM text format to its binary-format equivalent. $TEXT should be (character-decoded) text.
LICENSE & COPYRIGHT
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..