forked from wasmerio/wasmer-php
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathModule.php
120 lines (103 loc) · 2.34 KB
/
Module.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
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
<?php
declare(strict_types=1);
namespace Wasm;
/**
* @api
*/
final class Module
{
/**
* @var resource The inner `wasm_config_t` resource
*/
private $inner;
/**
* Create a Wasm\Module from a `wasm_module_t` resource.
*
* @throw Exception\InvalidArgumentException If the `$module` argument is not a valid `wasm_module_t` resource
*/
public function __construct($module)
{
if (false === is_resource($module) || 'wasm_module_t' !== get_resource_type($module)) {
throw new Exception\InvalidArgumentException();
}
$this->inner = $module;
}
/**
* @ignore
*/
public function __destruct()
{
try {
\wasm_module_delete($this->inner);
} catch (\TypeError $error) {
if (is_resource($this->inner)) {
throw $error;
}
}
}
/**
* Return the inner module resource.
*
* @return resource A `wasm_module_t` resource
*/
public function inner()
{
return $this->inner;
}
/**
* @api
*/
public function exports(): Vec\ExportType
{
return \wasm_module_exports($this->inner);
}
/**
* @api
*/
public function imports(): Vec\ImportType
{
return \wasm_module_imports($this->inner);
}
/**
* Get or set the module's name.
*
* @api
*/
public function name(?string $name = null): string
{
$previous = \wasm_module_name($this->inner);
if (null === $name) {
return $previous;
}
\wasm_module_set_name($this->inner, $name);
return $previous;
}
/**
* @api
*/
public function serialize(): string
{
return \wasm_module_serialize($this->inner);
}
/**
* @api
*/
public static function deserialize(Store $store, string $serialized): self
{
return new self(\wasm_module_deserialize($store->inner(), $serialized));
}
/**
* @api
*/
public static function new(Store $store, string $wasm): self
{
return new self(\wasm_module_new($store->inner(), $wasm));
}
/**
* @api
*/
public static function validate(Store $store, string $wasm): bool
{
return \wasm_module_validate($store->inner(), $wasm);
}
}