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
use crate::instance::ImportFunctionEnv;
use crate::vmcontext::{VMFunctionImport, VMGlobalImport, VMMemoryImport, VMTableImport};
use wasmer_types::entity::{BoxedSlice, PrimaryMap};
use wasmer_types::{FunctionIndex, GlobalIndex, MemoryIndex, TableIndex};
#[derive(Clone)]
pub struct Imports {
pub functions: BoxedSlice<FunctionIndex, VMFunctionImport>,
pub host_function_env_initializers: Option<BoxedSlice<FunctionIndex, ImportFunctionEnv>>,
pub tables: BoxedSlice<TableIndex, VMTableImport>,
pub memories: BoxedSlice<MemoryIndex, VMMemoryImport>,
pub globals: BoxedSlice<GlobalIndex, VMGlobalImport>,
}
impl Imports {
pub fn new(
function_imports: PrimaryMap<FunctionIndex, VMFunctionImport>,
host_function_env_initializers: PrimaryMap<FunctionIndex, ImportFunctionEnv>,
table_imports: PrimaryMap<TableIndex, VMTableImport>,
memory_imports: PrimaryMap<MemoryIndex, VMMemoryImport>,
global_imports: PrimaryMap<GlobalIndex, VMGlobalImport>,
) -> Self {
Self {
functions: function_imports.into_boxed_slice(),
host_function_env_initializers: Some(host_function_env_initializers.into_boxed_slice()),
tables: table_imports.into_boxed_slice(),
memories: memory_imports.into_boxed_slice(),
globals: global_imports.into_boxed_slice(),
}
}
pub fn none() -> Self {
Self {
functions: PrimaryMap::new().into_boxed_slice(),
host_function_env_initializers: None,
tables: PrimaryMap::new().into_boxed_slice(),
memories: PrimaryMap::new().into_boxed_slice(),
globals: PrimaryMap::new().into_boxed_slice(),
}
}
pub fn get_imported_function_envs(&mut self) -> BoxedSlice<FunctionIndex, ImportFunctionEnv> {
self.host_function_env_initializers
.take()
.unwrap_or_else(|| PrimaryMap::new().into_boxed_slice())
}
}