forked from wasmerio/wasmer-php
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathExtern.php
88 lines (75 loc) · 1.63 KB
/
Extern.php
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
<?php
declare(strict_types=1);
namespace Wasm;
use Wasm\Type\ExternType;
/**
* @api
*/
final class Extern
{
/**
* @var resource The inner `wasm_extern_t` resource
*/
private $inner;
/**
* Create a Wasm\Module\Extern from a `wasm_extern_t` resource.
*
* @param $extern resource a `wasm_extern_t` resource
*
* @throw Exception\InvalidArgumentException If the `$extern` argument is not a valid `wasm_extern_t` resource
*/
public function __construct($extern)
{
if (false === is_resource($extern) || 'wasm_extern_t' !== get_resource_type($extern)) {
throw new Exception\InvalidArgumentException();
}
$this->inner = $extern;
}
/**
* @ignore
*/
public function __destruct()
{
if (null !== $this->inner) {
\wasm_extern_delete($this->inner);
$this->inner = null;
}
}
/**
* Return the inner extern resource.
*
* @return resource A `wasm_extern_t` resource
*/
public function inner()
{
return $this->inner;
}
/**
* @api
*/
public function asFunc(): Func
{
return new Func(\wasm_extern_as_func($this->inner));
}
/**
* @api
*/
public function asGlobal(): Globl
{
return new Globl(\wasm_extern_as_global($this->inner));
}
/**
* @api
*/
public function kind(): int
{
return \wasm_extern_kind($this->inner);
}
/**
* @api
*/
public function type(): ExternType
{
return new ExternType(\wasm_extern_type($this->inner));
}
}