2017-04-27 15:49:14 +03:00
|
|
|
//! WebAssembly interpreter module.
|
2017-04-21 14:35:12 +03:00
|
|
|
|
2017-08-01 13:16:25 +03:00
|
|
|
/// Custom user error.
|
|
|
|
pub trait CustomUserError: 'static + ::std::fmt::Display + ::std::fmt::Debug + Clone + PartialEq {
|
|
|
|
}
|
|
|
|
|
|
|
|
/// Internal interpreter error.
|
|
|
|
#[derive(Debug, Clone, PartialEq)]
|
2017-08-01 14:44:33 +03:00
|
|
|
pub enum Error<E> where E: CustomUserError {
|
2017-04-27 15:49:14 +03:00
|
|
|
/// Program-level error.
|
2017-04-21 14:35:12 +03:00
|
|
|
Program(String),
|
2017-06-07 14:48:02 +03:00
|
|
|
/// Validation error.
|
|
|
|
Validation(String),
|
2017-04-27 15:49:14 +03:00
|
|
|
/// Initialization error.
|
2017-04-21 14:35:12 +03:00
|
|
|
Initialization(String),
|
2017-04-27 15:49:14 +03:00
|
|
|
/// Function-level error.
|
2017-04-21 14:35:12 +03:00
|
|
|
Function(String),
|
2017-04-27 15:49:14 +03:00
|
|
|
/// Table-level error.
|
2017-04-21 14:35:12 +03:00
|
|
|
Table(String),
|
2017-04-27 15:49:14 +03:00
|
|
|
/// Memory-level error.
|
2017-04-21 14:35:12 +03:00
|
|
|
Memory(String),
|
2017-04-27 15:49:14 +03:00
|
|
|
/// Variable-level error.
|
2017-04-21 14:35:12 +03:00
|
|
|
Variable(String),
|
2017-04-27 15:49:14 +03:00
|
|
|
/// Global-level error.
|
2017-04-21 14:35:12 +03:00
|
|
|
Global(String),
|
2017-04-27 15:49:14 +03:00
|
|
|
/// Local-level error.
|
2017-04-21 14:35:12 +03:00
|
|
|
Local(String),
|
2017-04-27 15:49:14 +03:00
|
|
|
/// Stack-level error.
|
2017-04-26 12:37:27 +03:00
|
|
|
Stack(String),
|
2017-04-27 15:49:14 +03:00
|
|
|
/// Value-level error.
|
2017-04-21 14:35:12 +03:00
|
|
|
Value(String),
|
2017-04-27 15:49:14 +03:00
|
|
|
/// Interpreter (code) error.
|
2017-04-21 14:35:12 +03:00
|
|
|
Interpreter(String),
|
2017-05-04 12:01:21 +03:00
|
|
|
/// Env module error.
|
|
|
|
Env(String),
|
2017-05-18 15:08:55 +03:00
|
|
|
/// Native module error.
|
|
|
|
Native(String),
|
2017-04-27 15:49:14 +03:00
|
|
|
/// Trap.
|
2017-04-26 15:41:22 +03:00
|
|
|
Trap(String),
|
2017-08-01 14:44:33 +03:00
|
|
|
/// Custom user error.
|
|
|
|
User(E),
|
2017-04-21 14:35:12 +03:00
|
|
|
}
|
|
|
|
|
2017-08-01 14:44:33 +03:00
|
|
|
impl<E> Into<String> for Error<E> where E: CustomUserError {
|
2017-04-21 14:35:12 +03:00
|
|
|
fn into(self) -> String {
|
|
|
|
match self {
|
|
|
|
Error::Program(s) => s,
|
2017-06-07 14:48:02 +03:00
|
|
|
Error::Validation(s) => s,
|
2017-04-21 14:35:12 +03:00
|
|
|
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,
|
2017-04-26 12:37:27 +03:00
|
|
|
Error::Stack(s) => s,
|
2017-04-21 14:35:12 +03:00
|
|
|
Error::Interpreter(s) => s,
|
|
|
|
Error::Value(s) => s,
|
2017-05-04 12:01:21 +03:00
|
|
|
Error::Env(s) => s,
|
2017-05-18 15:08:55 +03:00
|
|
|
Error::Native(s) => s,
|
2017-04-26 15:41:22 +03:00
|
|
|
Error::Trap(s) => format!("trap: {}", s),
|
2017-08-01 14:44:33 +03:00
|
|
|
Error::User(e) => format!("user: {}", e),
|
2017-04-21 14:35:12 +03:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2017-08-01 13:16:25 +03:00
|
|
|
/// Dummy user error.
|
|
|
|
#[derive(Debug, Clone, PartialEq)]
|
|
|
|
pub struct DummyCustomUserError;
|
|
|
|
|
|
|
|
impl CustomUserError for DummyCustomUserError {}
|
|
|
|
|
|
|
|
impl ::std::fmt::Display for DummyCustomUserError {
|
|
|
|
fn fmt(&self, _f: &mut ::std::fmt::Formatter) -> Result<(), ::std::fmt::Error> { Ok(()) }
|
|
|
|
}
|
|
|
|
|
2017-05-04 11:25:25 +03:00
|
|
|
mod env;
|
2017-05-18 15:08:55 +03:00
|
|
|
mod env_native;
|
2017-04-21 14:35:12 +03:00
|
|
|
mod imports;
|
|
|
|
mod memory;
|
|
|
|
mod module;
|
|
|
|
mod program;
|
|
|
|
mod runner;
|
2017-04-26 12:37:27 +03:00
|
|
|
mod stack;
|
2017-04-21 14:35:12 +03:00
|
|
|
mod table;
|
2017-06-07 14:48:02 +03:00
|
|
|
mod validator;
|
2017-04-21 14:35:12 +03:00
|
|
|
mod value;
|
|
|
|
mod variable;
|
2017-04-27 14:22:02 +03:00
|
|
|
|
|
|
|
#[cfg(test)]
|
|
|
|
mod tests;
|
2017-04-27 14:44:03 +03:00
|
|
|
|
2017-05-19 09:36:50 +03:00
|
|
|
pub use self::memory::MemoryInstance;
|
2017-08-01 14:44:33 +03:00
|
|
|
pub use self::module::{ModuleInstance, ModuleInstanceInterface,
|
2017-08-01 13:16:25 +03:00
|
|
|
ItemIndex, ExportEntryType, CallerContext, ExecutionParams, FunctionSignature};
|
2017-05-19 09:36:50 +03:00
|
|
|
pub use self::table::TableInstance;
|
2017-08-01 14:44:33 +03:00
|
|
|
pub use self::program::ProgramInstance;
|
2017-05-15 15:40:08 +03:00
|
|
|
pub use self::value::RuntimeValue;
|
2017-07-31 11:58:24 +03:00
|
|
|
pub use self::variable::{VariableInstance, VariableType, ExternalVariableValue};
|
|
|
|
pub use self::env_native::{env_native_module, UserDefinedElements, UserFunctionExecutor, UserFunctionDescriptor};
|
2017-08-01 13:16:25 +03:00
|
|
|
pub use self::env::EnvParams;
|
|
|
|
|
|
|
|
/// Default type of ProgramInstance if you do not need any custom user errors.
|
|
|
|
/// To work with custom user errors or interpreter internals, use CustomProgramInstance.
|
2017-08-01 14:44:33 +03:00
|
|
|
pub type DefaultProgramInstance = self::program::ProgramInstance<DummyCustomUserError>;
|
2017-08-01 13:16:25 +03:00
|
|
|
|
|
|
|
/// Default type of ModuleInstance if you do not need any custom user errors.
|
|
|
|
/// To work with custom user errors or interpreter internals, use CustomModuleInstance.
|
2017-08-01 14:44:33 +03:00
|
|
|
pub type DefaultModuleInstance = self::module::ModuleInstance<DummyCustomUserError>;
|
2017-08-01 13:16:25 +03:00
|
|
|
|
|
|
|
/// Default type of ModuleInstanceInterface if you do not need any custom user errors.
|
|
|
|
/// To work with custom user errors or interpreter internals, use CustomModuleInstanceInterface.
|
2017-08-01 14:44:33 +03:00
|
|
|
pub type DefaultModuleInstanceInterface = self::module::ModuleInstanceInterface<DummyCustomUserError>;
|