blib/lib/Wasm/Wasmtime/ValType.pm

filter: Statementstmt 100% 40 / 40 Branchbran 75.0% 3 / 4 Conditioncond n/a MC/DCmcdc n/a Subroutinesub 100% 7 / 7 Podpod 100% 1 / 1 totaltotal 98.0% 51 / 52 CC 3 SCAR 5.1
CC
3
Cov
98%
__ANON__
3.0
BEGIN
1.0
BEGIN
1.0
CRAP 1.7
« blib/lib/Wasm/Wasmtime/Instance/Exports.pm ↑ Summary blib/lib/Wasm/Wasmtime/Extern.pm »
1 package Wasm::Wasmtime::ValType;
2  
3 27 ▶use strict;
Subroutine BEGIN: called CC=1 SCAR=0.0
4 27 ▶use warnings;
Subroutine BEGIN: called CC=1 SCAR=0.0
5 27 ▶use 5.008004;
Subroutine BEGIN: called CC=1 SCAR=0.0
6 27 ▶use Wasm::Wasmtime::FFI;
Subroutine BEGIN: called CC=1 SCAR=0.0
7  
8 # ABSTRACT: Wasmtime value type class
9 27 our $VERSION = '0.24'; # VERSION
10  
11  
12 27 $ffi_prefix = 'wasm_valtype_';
13 27 $ffi->load_custom_type('::PtrObject' => 'wasm_valtype_t' => __PACKAGE__);
14  
15 27 my %kind = (
16 0 => 'i32',
17 1 => 'i64',
18 2 => 'f32',
19 3 => 'f64',
20 128 => 'anyref',
21 129 => 'funcref',
22 );
23  
24 27 my %rkind;
25 27 foreach my $key (keys %kind)
26 {
27 162 my $value = $kind{$key};
28 162 $rkind{$value} = $key;
29 }
30 # 'externref' is the wasm-c-api name for kind 128; accept it as an alias
31 27 $rkind{externref} = 128;
32  
33  
34 179 ▶$ffi->attach( new => ['uint8'] => 'wasm_valtype_t' => sub {
Subroutine __ANON__: called CC=3 SCAR=11.0
35 179 my $xsub = shift;
36 179 my $class = shift;
37 179 ▶ if($_[0] =~ /^[0-9]+$/)
Branch: 1 branch
BranchTrueFalseTotal
if ($_[0] =~ /^[0-9]+$/) { } 156 23 179
38 {
39 156 my($ptr, $owner) = @_;
40 156 return bless {
41 ptr => $ptr,
42 owner => $owner,
43 }, $class;
44 }
45 else
46 {
47 23 my($kind) = @_;
48 23 my $kind_num = $rkind{$kind};
49 23 ▶ Carp::croak("no such value type: $kind") unless defined $kind_num;
Branch: 1 branch
BranchTrueFalseTotal
unless defined $kind_num 0 23 23
50 23 return $xsub->($kind_num);
51 }
52 27 });
53  
54  
55 131 ▶sub kind { $kind{shift->kind_num} }
Subroutine kind: called CC=1 SCAR=0.0
Pod documented
56  
57  
58 27 $ffi->attach( [kind => 'kind_num'] => ['wasm_valtype_t'] => 'uint8' );
59  
60  
61 27 *to_string = \&kind;
62  
63 27 _generate_destroy();
64 27 _generate_vec_class( delete => 0 );
65  
66 20 ▶$ffi->attach( [ wasm_valtype_vec_new => 'Wasm::Wasmtime::ValTypeVec::set' ] => ['wasm_valtype_vec_t*','size_t','opaque[]'] => sub {
Subroutine __ANON__: called CC=1 SCAR=0.0
67 20 my($xsub, $self, $valtypes) = @_;
68 20 $xsub->($self, scalar(@$valtypes), $valtypes);
69 20 $self;
70 27 });
71  
72 27 1;
73  
74 __END__
« blib/lib/Wasm/Wasmtime/Instance/Exports.pm ↑ Summary blib/lib/Wasm/Wasmtime/Extern.pm »