| 1 | package Wasm::Wasmtime::WasiInstance; | ||||||||||||||||||||||||||||
| 2 | |||||||||||||||||||||||||||||
| 3 | 10 | ▶ | use strict; | ||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 4 | 10 | ▶ | use warnings; | ||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 5 | 10 | ▶ | use 5.008004; | ||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 6 | 10 | ▶ | use Wasm::Wasmtime::FFI; | ||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 7 | 10 | ▶ | use Wasm::Wasmtime::Store; | ||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 8 | 10 | ▶ | use Wasm::Wasmtime::Trap; | ||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 9 | 10 | ▶ | use Wasm::Wasmtime::WasiConfig; | ||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 10 | |||||||||||||||||||||||||||||
| 11 | # ABSTRACT: WASI instance class | ||||||||||||||||||||||||||||
| 12 | 10 | our $VERSION = '0.23'; # VERSION | |||||||||||||||||||||||||||
| 13 | |||||||||||||||||||||||||||||
| 14 | |||||||||||||||||||||||||||||
| 15 | 10 | $ffi_prefix = 'wasi_instance_'; | |||||||||||||||||||||||||||
| 16 | 10 | $ffi->load_custom_type('::PtrObject' => 'wasi_instance_t' => __PACKAGE__); | |||||||||||||||||||||||||||
| 17 | |||||||||||||||||||||||||||||
| 18 | |||||||||||||||||||||||||||||
| 19 | $ffi->attach( new => ['wasm_store_t', 'string', 'wasi_config_t', 'opaque*'] => 'wasi_instance_t' => sub { | ||||||||||||||||||||||||||||
| 20 | 6 | ▶ | my $xsub = shift; | ||||||||||||||||||||||||||
|
Subroutine
__ANON__: called CC=5 SCAR=17.6
| |||||||||||||||||||||||||||||
| 21 | 6 | my $class = shift; | |||||||||||||||||||||||||||
| 22 | 6 | my $store = shift; | |||||||||||||||||||||||||||
| 23 | 6 | my $name = shift; | |||||||||||||||||||||||||||
| 24 | 6 | ▶ | my $config = defined $_[0] && ref($_[0]) eq 'Wasm::Wasmtime::WasiConfig' ? shift : Wasm::Wasmtime::WasiConfig->new; | ||||||||||||||||||||||||||
|
Branch: 1 branch
Condition66%2/3
defined $_[0] and ref $_[0] eq "Wasm::Wasmtime::WasiConfig"
MC/DC50%1/2
defined $_[0] and ref $_[0] eq "Wasm::Wasmtime::WasiConfig"
defined $_[0]
ref $_[0] eq "Wasm::Wasmtime::WasiConfig"
Truth table66%2/3
A and B
A= defined $_[0]B= ref $_[0] eq "Wasm::Wasmtime::WasiConfig"
| |||||||||||||||||||||||||||||
| 25 | 6 | my $trap; | |||||||||||||||||||||||||||
| 26 | 6 | my $instance = $xsub->($store, $name, $config, \$trap); | |||||||||||||||||||||||||||
| 27 | 6 | delete $config->{ptr}; | |||||||||||||||||||||||||||
| 28 | 6 | ▶ | unless($instance) | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 29 | { | ||||||||||||||||||||||||||||
| 30 | 0 | ▶ | if($trap) | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 31 | { | ||||||||||||||||||||||||||||
| 32 | 0 | die Wasm::Wasmtime::Trap->new($trap); | |||||||||||||||||||||||||||
| 33 | } | ||||||||||||||||||||||||||||
| 34 | 0 | Carp::croak("failed to create wasi instance"); | |||||||||||||||||||||||||||
| 35 | } | ||||||||||||||||||||||||||||
| 36 | 6 | $instance; | |||||||||||||||||||||||||||
| 37 | 10 | }); | |||||||||||||||||||||||||||
| 38 | |||||||||||||||||||||||||||||
| 39 | # TODO: bind_import | ||||||||||||||||||||||||||||
| 40 | |||||||||||||||||||||||||||||
| 41 | 10 | _generate_destroy(); | |||||||||||||||||||||||||||
| 42 | |||||||||||||||||||||||||||||
| 43 | 10 | 1; | |||||||||||||||||||||||||||
| 44 | |||||||||||||||||||||||||||||
| 45 | __END__ | ||||||||||||||||||||||||||||