| 1 | package Wasm::Wasmtime::Global; | ||||||||||||||||||||||||||||
| 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 ); | ||||||||||||||||||||||||||
|
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::GlobalType; | ||||||||||||||||||||||||||
|
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_global => 1; | ||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 13 | 16 | ▶ | use constant kind => 'global'; | ||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 14 | |||||||||||||||||||||||||||||
| 15 | # ABSTRACT: Wasmtime global class | ||||||||||||||||||||||||||||
| 16 | 16 | our $VERSION = '0.24'; # VERSION | |||||||||||||||||||||||||||
| 17 | |||||||||||||||||||||||||||||
| 18 | |||||||||||||||||||||||||||||
| 19 | 16 | $ffi_prefix = 'wasmtime_global_'; | |||||||||||||||||||||||||||
| 20 | |||||||||||||||||||||||||||||
| 21 | |||||||||||||||||||||||||||||
| 22 | 2 | ▶ | $ffi->attach( [ wasmtime_global_new => 'new' ] => ['opaque', 'wasm_globaltype_t', 'wasmtime_val_t', 'wasmtime_global_t'] => 'wasmtime_error_t' => sub { | ||||||||||||||||||||||||||
|
Subroutine
__ANON__: called CC=4 SCAR=15.0
| |||||||||||||||||||||||||||||
| 23 | 2 | my $xsub = shift; | |||||||||||||||||||||||||||
| 24 | 2 | my $class = shift; | |||||||||||||||||||||||||||
| 25 | 2 | my($store, $globaltype, $value) = @_; | |||||||||||||||||||||||||||
| 26 | 2 | ▶ | Carp::croak("Wasm::Wasmtime::Global->new requires a Wasm::Wasmtime::Store") | ||||||||||||||||||||||||||
|
Branch: 1 branch
Condition33%1/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 table33%1/3
A and B
A= is_blessed_ref($store)B= $store->isa("Wasm::Wasmtime::Store")
| |||||||||||||||||||||||||||||
| 27 | unless is_blessed_ref($store) && $store->isa('Wasm::Wasmtime::Store'); | ||||||||||||||||||||||||||||
| 28 | 2 | my $val = Wasm::Wasmtime::Val->from_perl($globaltype->content->kind, $value); | |||||||||||||||||||||||||||
| 29 | 2 | my $data = Wasm::Wasmtime::GlobalData->new; | |||||||||||||||||||||||||||
| 30 | 2 | ▶ | if(my $error = $xsub->($store->context, $globaltype, $val, $data)) | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 31 | { | ||||||||||||||||||||||||||||
| 32 | 0 | Carp::croak($error->message); | |||||||||||||||||||||||||||
| 33 | } | ||||||||||||||||||||||||||||
| 34 | 2 | bless { data => $data, store => $store }, $class; | |||||||||||||||||||||||||||
| 35 | 16 | }); | |||||||||||||||||||||||||||
| 36 | |||||||||||||||||||||||||||||
| 37 | |||||||||||||||||||||||||||||
| 38 | 4 | ▶ | $ffi->attach( [ wasmtime_global_type => 'type' ] => ['opaque', 'wasmtime_global_t'] => 'wasm_globaltype_t' => sub { | ||||||||||||||||||||||||||
|
Subroutine
__ANON__: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 39 | 4 | my($xsub, $self) = @_; | |||||||||||||||||||||||||||
| 40 | 4 | $xsub->($self->context, $self->{data}); | |||||||||||||||||||||||||||
| 41 | 16 | }); | |||||||||||||||||||||||||||
| 42 | |||||||||||||||||||||||||||||
| 43 | |||||||||||||||||||||||||||||
| 44 | 11 | ▶ | $ffi->attach( [ wasmtime_global_get => 'get' ] => ['opaque', 'wasmtime_global_t', 'wasmtime_val_t'] => 'void' => sub { | ||||||||||||||||||||||||||
|
Subroutine
__ANON__: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 45 | 11 | my($xsub, $self) = @_; | |||||||||||||||||||||||||||
| 46 | 11 | my $value = Wasm::Wasmtime::Val->new; | |||||||||||||||||||||||||||
| 47 | 11 | $xsub->($self->context, $self->{data}, $value); | |||||||||||||||||||||||||||
| 48 | 11 | $value->to_perl; | |||||||||||||||||||||||||||
| 49 | 16 | }); | |||||||||||||||||||||||||||
| 50 | |||||||||||||||||||||||||||||
| 51 | |||||||||||||||||||||||||||||
| 52 | 2 | ▶ | $ffi->attach( [ wasmtime_global_set => 'set' ] => ['opaque', 'wasmtime_global_t', 'wasmtime_val_t'] => 'wasmtime_error_t' => sub { | ||||||||||||||||||||||||||
|
Subroutine
__ANON__: called CC=2 SCAR=7.4
| |||||||||||||||||||||||||||||
| 53 | 2 | my($xsub, $self, $value) = @_; | |||||||||||||||||||||||||||
| 54 | 2 | my $val = Wasm::Wasmtime::Val->from_perl($self->type->content->kind, $value); | |||||||||||||||||||||||||||
| 55 | 2 | ▶ | if(my $error = $xsub->($self->context, $self->{data}, $val)) | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 56 | { | ||||||||||||||||||||||||||||
| 57 | 0 | Carp::croak($error->message); | |||||||||||||||||||||||||||
| 58 | } | ||||||||||||||||||||||||||||
| 59 | 2 | return; | |||||||||||||||||||||||||||
| 60 | 16 | }); | |||||||||||||||||||||||||||
| 61 | |||||||||||||||||||||||||||||
| 62 | |||||||||||||||||||||||||||||
| 63 | sub tie | ||||||||||||||||||||||||||||
| 64 | 4 | ▶ | { | ||||||||||||||||||||||||||
|
Subroutine
tie: called CC=1 SCAR=0.0
Pod
documented
| |||||||||||||||||||||||||||||
| 65 | 4 | my $self = shift; | |||||||||||||||||||||||||||
| 66 | 4 | my $ref; | |||||||||||||||||||||||||||
| 67 | 4 | tie $ref, __PACKAGE__, $self; | |||||||||||||||||||||||||||
| 68 | 4 | \$ref; | |||||||||||||||||||||||||||
| 69 | } | ||||||||||||||||||||||||||||
| 70 | |||||||||||||||||||||||||||||
| 71 | 4 | ▶ | sub TIESCALAR { $_[1] } | ||||||||||||||||||||||||||
|
Subroutine
TIESCALAR: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 72 | 16 | *FETCH = \&get; | |||||||||||||||||||||||||||
| 73 | 16 | *STORE = \&set; | |||||||||||||||||||||||||||
| 74 | |||||||||||||||||||||||||||||
| 75 | 16 | 1; | |||||||||||||||||||||||||||
| 76 | |||||||||||||||||||||||||||||
| 77 | __END__ | ||||||||||||||||||||||||||||