| 1 | package Wasm::Wasmtime::Table; | ||||||||||||||||||||||||||||
| 2 | |||||||||||||||||||||||||||||
| 3 | 16 | ▶ | use strict; | ||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 4 | 16 | ▶ | use warnings; | ||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 5 | 16 | ▶ | use 5.008004; | ||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 6 | 16 | ▶ | use base qw( Wasm::Wasmtime::Extern ); | ||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 7 | 16 | ▶ | use Ref::Util qw( is_blessed_ref is_plain_arrayref ); | ||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 8 | 16 | ▶ | use Wasm::Wasmtime::FFI; | ||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 9 | 16 | ▶ | use Wasm::Wasmtime::Store; | ||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 10 | 16 | ▶ | use Wasm::Wasmtime::TableType; | ||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 11 | 16 | ▶ | use Carp (); | ||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 12 | 16 | ▶ | use constant is_table => 1; | ||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 13 | 16 | ▶ | use constant kind => 'table'; | ||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 14 | |||||||||||||||||||||||||||||
| 15 | # ABSTRACT: Wasmtime table class | ||||||||||||||||||||||||||||
| 16 | 16 | our $VERSION = '0.24'; # VERSION | |||||||||||||||||||||||||||
| 17 | |||||||||||||||||||||||||||||
| 18 | |||||||||||||||||||||||||||||
| 19 | 16 | $ffi_prefix = 'wasmtime_table_'; | |||||||||||||||||||||||||||
| 20 | |||||||||||||||||||||||||||||
| 21 | sub _null_val | ||||||||||||||||||||||||||||
| 22 | 0 | ▶ | { | ||||||||||||||||||||||||||
|
Subroutine
_null_val: not called CC=2 SCAR=17.9
| |||||||||||||||||||||||||||||
| 23 | 0 | my($kind) = @_; | |||||||||||||||||||||||||||
| 24 | 0 | my $num = $Wasm::Wasmtime::FFI::VAL_KIND_NUM{$kind}; | |||||||||||||||||||||||||||
| 25 | 0 | ▶ | Carp::croak("cannot create table of element type $kind") unless defined $num; | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 26 | 0 | my $val = Wasm::Wasmtime::Val->new; | |||||||||||||||||||||||||||
| 27 | 0 | $val->kind($num); | |||||||||||||||||||||||||||
| 28 | 0 | $val; # zeroed union == null funcref / null externref | |||||||||||||||||||||||||||
| 29 | } | ||||||||||||||||||||||||||||
| 30 | |||||||||||||||||||||||||||||
| 31 | |||||||||||||||||||||||||||||
| 32 | 0 | ▶ | $ffi->attach( [ wasmtime_table_new => 'new' ] => ['opaque', 'wasm_tabletype_t', 'wasmtime_val_t', 'wasmtime_table_t'] => 'wasmtime_error_t' => sub { | ||||||||||||||||||||||||||
|
Subroutine
__ANON__: not called CC=4 SCAR=30.0
| |||||||||||||||||||||||||||||
| 33 | 0 | my $xsub = shift; | |||||||||||||||||||||||||||
| 34 | 0 | my $class = shift; | |||||||||||||||||||||||||||
| 35 | 0 | my($store, $tabletype) = @_; | |||||||||||||||||||||||||||
| 36 | 0 | ▶ | Carp::croak("Wasm::Wasmtime::Table->new requires a Wasm::Wasmtime::Store") | ||||||||||||||||||||||||||
|
Branch: 1 branch
Condition0%0/3
is_blessed_ref($store) and $store->isa("Wasm::Wasmtime::Store")
MC/DC0%0/2
is_blessed_ref($store) and $store->isa("Wasm::Wasmtime::Store")
is_blessed_ref($store)
$store->isa("Wasm::Wasmtime::Store")
Truth table0%0/3
A and B
A= is_blessed_ref($store)B= $store->isa("Wasm::Wasmtime::Store")
| |||||||||||||||||||||||||||||
| 37 | unless is_blessed_ref($store) && $store->isa('Wasm::Wasmtime::Store'); | ||||||||||||||||||||||||||||
| 38 | 0 | my $init = _null_val($tabletype->element->kind); | |||||||||||||||||||||||||||
| 39 | 0 | my $data = Wasm::Wasmtime::TableData->new; | |||||||||||||||||||||||||||
| 40 | 0 | ▶ | if(my $error = $xsub->($store->context, $tabletype, $init, $data)) | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 41 | { | ||||||||||||||||||||||||||||
| 42 | 0 | Carp::croak($error->message); | |||||||||||||||||||||||||||
| 43 | } | ||||||||||||||||||||||||||||
| 44 | 0 | bless { data => $data, store => $store }, $class; | |||||||||||||||||||||||||||
| 45 | 16 | }); | |||||||||||||||||||||||||||
| 46 | |||||||||||||||||||||||||||||
| 47 | |||||||||||||||||||||||||||||
| 48 | 2 | ▶ | $ffi->attach( [ wasmtime_table_type => 'type' ] => ['opaque', 'wasmtime_table_t'] => 'wasm_tabletype_t' => sub { | ||||||||||||||||||||||||||
|
Subroutine
__ANON__: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 49 | 2 | my($xsub, $self) = @_; | |||||||||||||||||||||||||||
| 50 | 2 | $xsub->($self->context, $self->{data}); | |||||||||||||||||||||||||||
| 51 | 16 | }); | |||||||||||||||||||||||||||
| 52 | |||||||||||||||||||||||||||||
| 53 | |||||||||||||||||||||||||||||
| 54 | 1 | ▶ | $ffi->attach( [ wasmtime_table_size => 'size' ] => ['opaque', 'wasmtime_table_t'] => 'uint64' => sub { | ||||||||||||||||||||||||||
|
Subroutine
__ANON__: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 55 | 1 | my($xsub, $self) = @_; | |||||||||||||||||||||||||||
| 56 | 1 | $xsub->($self->context, $self->{data}); | |||||||||||||||||||||||||||
| 57 | 16 | }); | |||||||||||||||||||||||||||
| 58 | |||||||||||||||||||||||||||||
| 59 | |||||||||||||||||||||||||||||
| 60 | 0 | ▶ | $ffi->attach( [ wasmtime_table_get => 'get' ] => ['opaque', 'wasmtime_table_t', 'uint64', 'wasmtime_val_t'] => 'bool' => sub { | ||||||||||||||||||||||||||
|
Subroutine
__ANON__: not called CC=2 SCAR=17.9
| |||||||||||||||||||||||||||||
| 61 | 0 | my($xsub, $self, $index) = @_; | |||||||||||||||||||||||||||
| 62 | 0 | my $val = Wasm::Wasmtime::Val->new; | |||||||||||||||||||||||||||
| 63 | 0 | ▶ | return undef unless $xsub->($self->context, $self->{data}, $index, $val); | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 64 | 0 | $val->to_perl; | |||||||||||||||||||||||||||
| 65 | 16 | }); | |||||||||||||||||||||||||||
| 66 | |||||||||||||||||||||||||||||
| 67 | |||||||||||||||||||||||||||||
| 68 | 0 | ▶ | $ffi->attach( [ wasmtime_table_grow => 'grow' ] => ['opaque', 'wasmtime_table_t', 'uint64', 'wasmtime_val_t', 'uint64*'] => 'wasmtime_error_t' => sub { | ||||||||||||||||||||||||||
|
Subroutine
__ANON__: not called CC=2 SCAR=17.9
| |||||||||||||||||||||||||||||
| 69 | 0 | my($xsub, $self, $delta) = @_; | |||||||||||||||||||||||||||
| 70 | 0 | my $init = _null_val($self->type->element->kind); | |||||||||||||||||||||||||||
| 71 | 0 | my $prev = 0; | |||||||||||||||||||||||||||
| 72 | 0 | my $error = $xsub->($self->context, $self->{data}, $delta, $init, \$prev); | |||||||||||||||||||||||||||
| 73 | 0 | ▶ | $error ? !!0 : !!1; | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 74 | 16 | }); | |||||||||||||||||||||||||||
| 75 | |||||||||||||||||||||||||||||
| 76 | 16 | 1; | |||||||||||||||||||||||||||
| 77 | |||||||||||||||||||||||||||||
| 78 | __END__ | ||||||||||||||||||||||||||||