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
pub trait UserError: 'static + ::std::fmt::Display + ::std::fmt::Debug + Clone + PartialEq {
}
#[derive(Debug, Clone, PartialEq)]
pub enum Error<E> where E: UserError {
Program(String),
Validation(String),
Initialization(String),
Function(String),
Table(String),
Memory(String),
Variable(String),
Global(String),
Local(String),
Stack(String),
Value(String),
Interpreter(String),
Env(String),
Native(String),
Trap(String),
User(E),
}
impl<E> Into<String> for Error<E> where E: UserError {
fn into(self) -> String {
match self {
Error::Program(s) => s,
Error::Validation(s) => s,
Error::Initialization(s) => s,
Error::Function(s) => s,
Error::Table(s) => s,
Error::Memory(s) => s,
Error::Variable(s) => s,
Error::Global(s) => s,
Error::Local(s) => s,
Error::Stack(s) => s,
Error::Interpreter(s) => s,
Error::Value(s) => s,
Error::Env(s) => s,
Error::Native(s) => s,
Error::Trap(s) => format!("trap: {}", s),
Error::User(e) => format!("user: {}", e),
}
}
}
#[derive(Debug, Clone, PartialEq)]
pub struct DummyUserError;
impl UserError for DummyUserError {}
impl ::std::fmt::Display for DummyUserError {
fn fmt(&self, _f: &mut ::std::fmt::Formatter) -> Result<(), ::std::fmt::Error> { Ok(()) }
}
mod env;
mod env_native;
mod imports;
mod memory;
mod module;
mod program;
mod runner;
mod stack;
mod table;
mod validator;
mod value;
mod variable;
#[cfg(test)]
mod tests;
pub use self::memory::MemoryInstance;
pub use self::module::{ModuleInstance, ModuleInstanceInterface,
ItemIndex, ExportEntryType, CallerContext, ExecutionParams, FunctionSignature};
pub use self::table::TableInstance;
pub use self::program::ProgramInstance;
pub use self::value::RuntimeValue;
pub use self::variable::{VariableInstance, VariableType, ExternalVariableValue};
pub use self::env_native::{env_native_module, UserDefinedElements, UserFunctionExecutor, UserFunctionDescriptor};
pub use self::env::EnvParams;
pub type DummyError = Error<DummyUserError>;
pub type DefaultProgramInstance = self::program::ProgramInstance<DummyUserError>;
pub type DefaultModuleInstance = self::module::ModuleInstance<DummyUserError>;
pub type DefaultModuleInstanceInterface = self::module::ModuleInstanceInterface<DummyUserError>;