mirror of
https://github.com/fluencelabs/parity-wasm
synced 2025-06-22 11:11:54 +00:00
added DummyError alias
This commit is contained in:
@ -14,7 +14,7 @@ use parity_wasm::interpreter::{
|
|||||||
DefaultProgramInstance, DefaultModuleInstance,
|
DefaultProgramInstance, DefaultModuleInstance,
|
||||||
ItemIndex, ExportEntryType,
|
ItemIndex, ExportEntryType,
|
||||||
Error as InterpreterError,
|
Error as InterpreterError,
|
||||||
DummyUserError,
|
DummyError as DummyInterpreterError,
|
||||||
};
|
};
|
||||||
|
|
||||||
fn spec_test_module() -> elements::Module {
|
fn spec_test_module() -> elements::Module {
|
||||||
@ -58,7 +58,7 @@ fn try_deserialize(base_dir: &str, module_path: &str) -> Result<elements::Module
|
|||||||
parity_wasm::deserialize_file(&wasm_path)
|
parity_wasm::deserialize_file(&wasm_path)
|
||||||
}
|
}
|
||||||
|
|
||||||
fn try_load(base_dir: &str, module_path: &str) -> Result<(), parity_wasm::interpreter::Error<DummyUserError>> {
|
fn try_load(base_dir: &str, module_path: &str) -> Result<(), DummyInterpreterError> {
|
||||||
let module = try_deserialize(base_dir, module_path).map_err(|e| parity_wasm::interpreter::Error::Program(format!("{:?}", e)))?;
|
let module = try_deserialize(base_dir, module_path).map_err(|e| parity_wasm::interpreter::Error::Program(format!("{:?}", e)))?;
|
||||||
let program = DefaultProgramInstance::new().expect("Failed creating program");
|
let program = DefaultProgramInstance::new().expect("Failed creating program");
|
||||||
program.add_module("try_load", module, None).map(|_| ())
|
program.add_module("try_load", module, None).map(|_| ())
|
||||||
@ -91,7 +91,7 @@ fn runtime_values(test_vals: &[test::RuntimeValue]) -> Vec<parity_wasm::RuntimeV
|
|||||||
}
|
}
|
||||||
|
|
||||||
fn run_action(program: &DefaultProgramInstance, action: &test::Action)
|
fn run_action(program: &DefaultProgramInstance, action: &test::Action)
|
||||||
-> Result<Option<parity_wasm::RuntimeValue>, InterpreterError<DummyUserError>>
|
-> Result<Option<parity_wasm::RuntimeValue>, DummyInterpreterError>
|
||||||
{
|
{
|
||||||
match *action {
|
match *action {
|
||||||
test::Action::Invoke { ref module, ref field, ref args } => {
|
test::Action::Invoke { ref module, ref field, ref args } => {
|
||||||
|
@ -100,6 +100,9 @@ pub use self::variable::{VariableInstance, VariableType, ExternalVariableValue};
|
|||||||
pub use self::env_native::{env_native_module, UserDefinedElements, UserFunctionExecutor, UserFunctionDescriptor};
|
pub use self::env_native::{env_native_module, UserDefinedElements, UserFunctionExecutor, UserFunctionDescriptor};
|
||||||
pub use self::env::EnvParams;
|
pub use self::env::EnvParams;
|
||||||
|
|
||||||
|
/// Default type of Error if you do not need any custom user errors.
|
||||||
|
pub type DummyError = Error<DummyUserError>;
|
||||||
|
|
||||||
/// Default type of ProgramInstance if you do not need any custom user errors.
|
/// Default type of ProgramInstance if you do not need any custom user errors.
|
||||||
/// To work with custom user errors or interpreter internals, use CustomProgramInstance.
|
/// To work with custom user errors or interpreter internals, use CustomProgramInstance.
|
||||||
pub type DefaultProgramInstance = self::program::ProgramInstance<DummyUserError>;
|
pub type DefaultProgramInstance = self::program::ProgramInstance<DummyUserError>;
|
||||||
|
@ -3,7 +3,7 @@
|
|||||||
use std::sync::Arc;
|
use std::sync::Arc;
|
||||||
use builder::module;
|
use builder::module;
|
||||||
use elements::{ValueType, Opcodes, Opcode, BlockType, Local};
|
use elements::{ValueType, Opcodes, Opcode, BlockType, Local};
|
||||||
use interpreter::{Error, DummyUserError, DefaultProgramInstance, DefaultModuleInstanceInterface, ModuleInstanceInterface, ItemIndex};
|
use interpreter::{Error, DummyError, DefaultProgramInstance, DefaultModuleInstanceInterface, ModuleInstanceInterface, ItemIndex};
|
||||||
use interpreter::value::{RuntimeValue, TryInto};
|
use interpreter::value::{RuntimeValue, TryInto};
|
||||||
|
|
||||||
fn make_function_i32(body: Opcodes) -> (DefaultProgramInstance, Arc<DefaultModuleInstanceInterface>) {
|
fn make_function_i32(body: Opcodes) -> (DefaultProgramInstance, Arc<DefaultModuleInstanceInterface>) {
|
||||||
@ -22,7 +22,7 @@ fn make_function_i32(body: Opcodes) -> (DefaultProgramInstance, Arc<DefaultModul
|
|||||||
(program, module)
|
(program, module)
|
||||||
}
|
}
|
||||||
|
|
||||||
fn run_function_i32(module: &Arc<DefaultModuleInstanceInterface>, arg: i32) -> Result<i32, Error<DummyUserError>> {
|
fn run_function_i32(module: &Arc<DefaultModuleInstanceInterface>, arg: i32) -> Result<i32, DummyError> {
|
||||||
module
|
module
|
||||||
.execute_index(0, vec![RuntimeValue::I32(arg)].into())
|
.execute_index(0, vec![RuntimeValue::I32(arg)].into())
|
||||||
.and_then(|r| r.unwrap().try_into())
|
.and_then(|r| r.unwrap().try_into())
|
||||||
|
Reference in New Issue
Block a user