| 1 | package Wasm::Wasmtime::Extern; | ||||||||||
| 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 Wasm::Wasmtime::FFI; | ||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||
| 7 | |||||||||||
| 8 | 16 | require Wasm::Wasmtime::Func; | |||||||||
| 9 | 16 | require Wasm::Wasmtime::Global; | |||||||||
| 10 | 16 | require Wasm::Wasmtime::Table; | |||||||||
| 11 | 16 | require Wasm::Wasmtime::Memory; | |||||||||
| 12 | |||||||||||
| 13 | # ABSTRACT: Wasmtime extern class | ||||||||||
| 14 | 16 | our $VERSION = '0.23'; # VERSION | |||||||||
| 15 | |||||||||||
| 16 | |||||||||||
| 17 | 16 | $ffi_prefix = 'wasm_extern_'; | |||||||||
| 18 | |||||||||||
| 19 | 16 | $ffi->attach( [ kind => '_kind' ] => ['opaque'] => 'uint8' ); | |||||||||
| 20 | |||||||||||
| 21 | 16 | my @cast; | |||||||||
| 22 | |||||||||||
| 23 | sub _cast | ||||||||||
| 24 | { | ||||||||||
| 25 | 64 | ▶ | my(undef, $index) = @_; | ||||||||
|
Subroutine
_cast: called CC=1 SCAR=0.0
| |||||||||||
| 26 | 64 | my $caller = caller; | |||||||||
| 27 | 64 | my($name) = map { lc $_ } $caller =~ /::([a-z]+)$/i; | |||||||||
| 28 | 64 | $cast[$index] = $ffi->function( "wasm_extern_as_$name" => ['opaque'] => "wasm_${name}_t" )->sub_ref; | |||||||||
| 29 | } | ||||||||||
| 30 | |||||||||||
| 31 | $ffi->custom_type('wasm_extern_t' => { | ||||||||||
| 32 | native_type => 'opaque', | ||||||||||
| 33 | native_to_perl => sub { | ||||||||||
| 34 | 109 | ▶ | my $extern = shift; | ||||||||
|
Subroutine
__ANON__: called CC=2 SCAR=7.0
| |||||||||||
| 35 | 109 | ▶ | Carp::croak("extern error") unless defined $extern; | ||||||||
|
Branch: 1 branch
| |||||||||||
| 36 | 109 | my $kind = _kind($extern); | |||||||||
| 37 | 109 | $cast[$kind]->($extern); | |||||||||
| 38 | }, | ||||||||||
| 39 | 16 | }); | |||||||||
| 40 | |||||||||||
| 41 | $ffi->attach_cast('new', 'opaque', 'wasm_extern_t', sub { | ||||||||||
| 42 | 106 | ▶ | my($xsub, undef, $ptr, $owner) = @_; | ||||||||
|
Subroutine
__ANON__: called CC=1 SCAR=0.0
| |||||||||||
| 43 | 106 | my $self = $xsub->($ptr); | |||||||||
| 44 | 106 | $self->{owner} = $owner; | |||||||||
| 45 | 106 | $self; | |||||||||
| 46 | 16 | }); | |||||||||
| 47 | |||||||||||
| 48 | 16 | ▶ | use constant is_func => 0; | ||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||
| 49 | 16 | ▶ | use constant is_global => 0; | ||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||
| 50 | 16 | ▶ | use constant is_table => 0; | ||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||
| 51 | 16 | ▶ | use constant is_memory => 0; | ||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||
| 52 | |||||||||||
| 53 | 0 | ▶ | sub kind { die "internal error" }; | ||||||||
|
Subroutine
kind: not called CC=1 SCAR=6.9
Pod
documented
| |||||||||||
| 54 | |||||||||||
| 55 | 16 | _generate_vec_class(); | |||||||||
| 56 | |||||||||||
| 57 | 16 | 1; | |||||||||
| 58 | |||||||||||
| 59 | __END__ | ||||||||||