NAME

Wasm::Wasmer::Store

SYNOPSIS

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.

DESCRIPTION

This class represents a WASM “store” and “engine” pair. See Wasmer’s store and engine modules for a bit more context.

METHODS

$obj = CLASS->new( %OPTS )

Instantiates this class, which wraps Wasmer wasm_engine_t and wasm_store_t instances.

This accepts the arguments that in C would go into the wasm_config_t. Currently that includes:

  • compiler - cranelift, llvm, or singlepass

NB: Your Wasmer may not support all of the above.

$wasi = CLASS->create_wasi( %OPTS )

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

  • args - arrayref

  • env - arrayref of key-value pairs

  • stdin - either undef (default) or inherit

  • stdout - either capture (default) or inherit

  • stderr - either capture (default) or inherit

  • preopen_dirs - arrayref of real paths

  • map_dirs - hashref of WASI-alias to real-path

IMPORTS

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.)

$obj = OBJ->create_memory( %OPTS )

Creates a WebAssembly memory and a Perl Wasm::Wasmer::Memory instance to interface with it. %OPTS are:

  • initial (required)

  • maximum

The equivalent JavaScript interface is WebAssembly.Memory(); see its documentation for more details.

Globals

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.

$obj = OBJ->create_function( %OPTS )

Creates a Wasm::Wasmer::Function instance. %OPTS are:

  • code - (required) A Perl code reference.

  • params - An array reference of Perl constants (e.g., Wasm::Wasmer::WASM_I32) that indicates the function inputs. Defaults to empty.

  • results - Like params but for the outputs.

Tables

(Unsupported for now.)