line |
stmt |
bran |
cond |
sub |
pod |
time |
code |
1
|
|
|
|
|
|
|
package Wasm::Wasmtime::ImportType; |
2
|
|
|
|
|
|
|
|
3
|
22
|
|
|
22
|
|
232944
|
use strict; |
|
22
|
|
|
|
|
49
|
|
|
22
|
|
|
|
|
650
|
|
4
|
22
|
|
|
22
|
|
117
|
use warnings; |
|
22
|
|
|
|
|
49
|
|
|
22
|
|
|
|
|
510
|
|
5
|
22
|
|
|
22
|
|
401
|
use 5.008004; |
|
22
|
|
|
|
|
78
|
|
6
|
22
|
|
|
22
|
|
151
|
use Carp (); |
|
22
|
|
|
|
|
49
|
|
|
22
|
|
|
|
|
490
|
|
7
|
22
|
|
|
22
|
|
121
|
use Ref::Util qw( is_blessed_ref ); |
|
22
|
|
|
|
|
64
|
|
|
22
|
|
|
|
|
1177
|
|
8
|
22
|
|
|
22
|
|
569
|
use Wasm::Wasmtime::FFI; |
|
22
|
|
|
|
|
53
|
|
|
22
|
|
|
|
|
2328
|
|
9
|
22
|
|
|
22
|
|
2567
|
use Wasm::Wasmtime::ExternType; |
|
22
|
|
|
|
|
55
|
|
|
22
|
|
|
|
|
11770
|
|
10
|
|
|
|
|
|
|
|
11
|
|
|
|
|
|
|
# ABSTRACT: Wasmtime import type class |
12
|
|
|
|
|
|
|
our $VERSION = '0.21'; # VERSION |
13
|
|
|
|
|
|
|
|
14
|
|
|
|
|
|
|
|
15
|
|
|
|
|
|
|
$ffi_prefix = 'wasm_importtype_'; |
16
|
|
|
|
|
|
|
$ffi->load_custom_type('::PtrObject' => 'wasm_importtype_t' => __PACKAGE__); |
17
|
|
|
|
|
|
|
|
18
|
|
|
|
|
|
|
|
19
|
|
|
|
|
|
|
$ffi->attach( new => ['wasm_byte_vec_t*', 'wasm_byte_vec_t*', 'opaque'] => 'wasm_importtype_t' => sub { |
20
|
|
|
|
|
|
|
my $xsub = shift; |
21
|
|
|
|
|
|
|
my $class = shift; |
22
|
|
|
|
|
|
|
if(defined $_[2] && is_blessed_ref $_[2]) |
23
|
|
|
|
|
|
|
{ |
24
|
|
|
|
|
|
|
my $externtype = $_[2]; |
25
|
|
|
|
|
|
|
# not sure this is actually useful? |
26
|
|
|
|
|
|
|
if(is_blessed_ref($externtype) && $externtype->isa('Wasm::Wasmtime::ExternType')) |
27
|
|
|
|
|
|
|
{ |
28
|
|
|
|
|
|
|
my $module = Wasm::Wasmtime::ByteVec->new(shift); |
29
|
|
|
|
|
|
|
my $name = Wasm::Wasmtime::ByteVec->new(shift); |
30
|
|
|
|
|
|
|
my $self = $xsub->($module, $name, $externtype->{ptr}); |
31
|
|
|
|
|
|
|
$module->delete; |
32
|
|
|
|
|
|
|
$name->delete; |
33
|
|
|
|
|
|
|
return $self; |
34
|
|
|
|
|
|
|
} |
35
|
|
|
|
|
|
|
else |
36
|
|
|
|
|
|
|
{ |
37
|
|
|
|
|
|
|
Carp::croak("Not an externtype"); |
38
|
|
|
|
|
|
|
} |
39
|
|
|
|
|
|
|
} |
40
|
|
|
|
|
|
|
else |
41
|
|
|
|
|
|
|
{ |
42
|
|
|
|
|
|
|
my($ptr,$owner) = @_; |
43
|
|
|
|
|
|
|
return bless { |
44
|
|
|
|
|
|
|
ptr => $ptr, |
45
|
|
|
|
|
|
|
owner => $owner, |
46
|
|
|
|
|
|
|
}, $class; |
47
|
|
|
|
|
|
|
} |
48
|
|
|
|
|
|
|
}); |
49
|
|
|
|
|
|
|
|
50
|
|
|
|
|
|
|
|
51
|
|
|
|
|
|
|
$ffi->attach( name => ['wasm_importtype_t'] => 'wasm_byte_vec_t*' => sub { |
52
|
|
|
|
|
|
|
my($xsub, $self) = @_; |
53
|
|
|
|
|
|
|
my $name = $xsub->($self); |
54
|
|
|
|
|
|
|
$name->get; |
55
|
|
|
|
|
|
|
}); |
56
|
|
|
|
|
|
|
|
57
|
|
|
|
|
|
|
|
58
|
|
|
|
|
|
|
$ffi->attach( type => ['wasm_importtype_t'] => 'wasm_externtype_t' => sub { |
59
|
|
|
|
|
|
|
my($xsub, $self) = @_; |
60
|
|
|
|
|
|
|
my $type = $xsub->($self); |
61
|
|
|
|
|
|
|
$type->{owner} = $self->{owner} || $self; |
62
|
|
|
|
|
|
|
$type; |
63
|
|
|
|
|
|
|
}); |
64
|
|
|
|
|
|
|
|
65
|
|
|
|
|
|
|
|
66
|
|
|
|
|
|
|
$ffi->attach( module => ['wasm_importtype_t'] => 'wasm_byte_vec_t*' => sub { |
67
|
|
|
|
|
|
|
my($xsub, $self) = @_; |
68
|
|
|
|
|
|
|
my $name = $xsub->($self); |
69
|
|
|
|
|
|
|
$name->get; |
70
|
|
|
|
|
|
|
}); |
71
|
|
|
|
|
|
|
|
72
|
|
|
|
|
|
|
|
73
|
|
|
|
|
|
|
sub to_string |
74
|
|
|
|
|
|
|
{ |
75
|
2
|
|
|
2
|
1
|
428
|
my($self) = @_; |
76
|
2
|
|
|
|
|
7
|
my $kind = $self->type->kind; |
77
|
2
|
|
|
|
|
7
|
$kind =~ s/type$//; |
78
|
|
|
|
|
|
|
# TODO: escape strings ? |
79
|
2
|
|
|
|
|
8
|
sprintf '(%s (import "%s" "%s") %s)', $kind, $self->module, $self->name, $self->type->to_string; |
80
|
|
|
|
|
|
|
} |
81
|
|
|
|
|
|
|
|
82
|
|
|
|
|
|
|
_generate_destroy(); |
83
|
|
|
|
|
|
|
_generate_vec_class(); |
84
|
|
|
|
|
|
|
|
85
|
|
|
|
|
|
|
1; |
86
|
|
|
|
|
|
|
|
87
|
|
|
|
|
|
|
__END__ |