Wasm::Wasmer::Store
my $store = Wasm::Wasmer::Store->new();
For more fine-grained control over compilation and performance you can pass options like, e.g.:
my $store = Wasm::Wasmer::Store->new( compiler => 'llvm', ); my $func = $store->create_function( code => sub { ... }, params => [ Wasm::Wasmer::WASM_I32, Wasm::Wasmer::WASM_I32 ], results => [ Wasm::Wasmer::WASM_F64 ], );
See Wasm::Wasmer::Module for what you can do with $store.
This class represents a WASM “store” and “engine” pair. See Wasmer’s store and engine modules for a bit more context.
Instantiates this class, which wraps Wasmer wasm_engine_t and wasm_store_t instances.
wasm_engine_t
wasm_store_t
This accepts the arguments that in C would go into the wasm_config_t. Currently that includes:
wasm_config_t
compiler - cranelift, llvm, or singlepass
compiler
cranelift
llvm
singlepass
NB: Your Wasmer may not support all of the above.
Creates a Wasm::Wasmer::WASI instance. Give $wasi to the appropriate method of Wasm::Wasmer::Module.
The %OPTS correspond to Wasmer’s corresponding interface. All are optional:
name - defaults to empty-string
name
args - arrayref
args
env - arrayref of key-value pairs
env
stdin - either undef (default) or inherit
stdin
inherit
stdout - either capture (default) or inherit
stdout
capture
stderr - either capture (default) or inherit
stderr
preopen_dirs - arrayref of real paths
preopen_dirs
map_dirs - hashref of WASI-alias to real-path
map_dirs
To import a global or memory into WebAssembly you first need to create a Perl object to represent that WebAssembly object.
The following create WebAssembly objects in the store and return Perl objects that interact with those WebAssembly objects.
(NB: The Perl objects do not trigger destruction of the WebAssembly objects when they go away. Only destroying the store achieves that.)
Creates a WebAssembly memory and a Perl Wasm::Wasmer::Memory instance to interface with it. %OPTS are:
initial (required)
initial
maximum
The equivalent JavaScript interface is WebAssembly.Memory(); see its documentation for more details.
WebAssembly.Memory()
Rather than a single method, this class exposes separate methods to create globals of different types:
OBJ->create_i32_const($VALUE)
OBJ->create_i32_mut($VALUE)
OBJ->create_i64_const($VALUE)
OBJ->create_i64_mut($VALUE)
OBJ->create_f32_const($VALUE)
OBJ->create_f32_mut($VALUE)
OBJ->create_f64_const($VALUE)
OBJ->create_f64_mut($VALUE)
Each of the above creates a WebAssembly global and a Perl Wasm::Wasmer::Global instance to interface with it.
Creates a Wasm::Wasmer::Function instance. %OPTS are:
code - (required) A Perl code reference.
code
params - An array reference of Perl constants (e.g., Wasm::Wasmer::WASM_I32) that indicates the function inputs. Defaults to empty.
params
results - Like params but for the outputs.
results
(Unsupported for now.)
To install Wasm::Wasmer, copy and paste the appropriate command in to your terminal.
cpanm
cpanm Wasm::Wasmer
CPAN shell
perl -MCPAN -e shell install Wasm::Wasmer
For more information on module installation, please visit the detailed CPAN module installation guide.