diff --git a/examples/interpret.rs b/examples/interpret.rs index a5971a3..3c0a7a0 100644 --- a/examples/interpret.rs +++ b/examples/interpret.rs @@ -24,7 +24,7 @@ fn main() { // - a module declaration // - "main" module doesn't import native module(s) this is why we don't need to provide external native modules here // This test shows how to implement native module https://github.com/NikVolf/parity-wasm/blob/master/src/interpreter/tests/basics.rs#L197 - let module = program.add_module("main", module, &mut ()).expect("Failed to initialize module"); + program.add_module("main", module, &mut ()).expect("Failed to initialize module"); // The argument should be parsable as a valid integer let argument: i32 = args[2].parse().expect("Integer argument required"); diff --git a/examples/invoke.rs b/examples/invoke.rs index c178161..a29df4d 100644 --- a/examples/invoke.rs +++ b/examples/invoke.rs @@ -2,7 +2,7 @@ extern crate parity_wasm; use std::env::args; -use parity_wasm::{interpreter, RuntimeValue}; +use parity_wasm::RuntimeValue; use parity_wasm::elements::{Internal, External, Type, FunctionType, ValueType}; @@ -76,7 +76,7 @@ fn main() { // - a module declaration // - "main" module doesn't import native module(s) this is why we don't need to provide external native modules here // This test shows how to implement native module https://github.com/NikVolf/parity-wasm/blob/master/src/interpreter/tests/basics.rs#L197 - let module = program.add_module("main", module, &mut ()).expect("Failed to initialize module"); + program.add_module("main", module, &mut ()).expect("Failed to initialize module"); println!("Result: {:?}", program.invoke_export("main", func_name, args, &mut ()).expect("")); } diff --git a/src/builder/module.rs b/src/builder/module.rs index 7deb726..211cc84 100644 --- a/src/builder/module.rs +++ b/src/builder/module.rs @@ -95,7 +95,7 @@ impl From for elements::Module { let import = module.import; if import.entries().len() > 0 { sections.push(elements::Section::Import(import)); - } + } let functions = module.functions; if functions.entries().len() > 0 { sections.push(elements::Section::Function(functions)); @@ -159,7 +159,7 @@ impl ModuleBuilder where F: Invoke { } /// Fill module with sections from iterator - pub fn with_sections(mut self, sections: I) -> Self + pub fn with_sections(mut self, sections: I) -> Self where I: IntoIterator { self.module.other.extend(sections); @@ -262,7 +262,7 @@ impl ModuleBuilder where F: Invoke { self.module.import.entries_mut().len() as u32 - 1 } - /// Push export entry to module. + /// Push export entry to module. pub fn push_export(&mut self, export: elements::ExportEntry) -> u32 { self.module.export.entries_mut().push(export); self.module.export.entries_mut().len() as u32 - 1 @@ -349,7 +349,7 @@ impl ModuleBuilder where F: Invoke { /// .build(); /// /// assert_eq!(module.export_section().expect("export section to exist").entries().len(), 1); - /// ``` + /// ``` pub fn export(self) -> export::ExportBuilder { export::ExportBuilder::with_callback(self) } @@ -368,7 +368,7 @@ impl ModuleBuilder where F: Invoke { /// .build(); /// /// assert_eq!(module.global_section().expect("global section to exist").entries().len(), 1); - /// ``` + /// ``` pub fn global(self) -> global::GlobalBuilder { global::GlobalBuilder::with_callback(self) } @@ -390,18 +390,18 @@ impl ModuleBuilder where F: Invoke { } } -impl Invoke for ModuleBuilder +impl Invoke for ModuleBuilder where F: Invoke { type Result = Self; fn invoke(self, section: elements::FunctionSection) -> Self { self.with_section(elements::Section::Function(section)) - } + } } impl Invoke for ModuleBuilder - where F: Invoke + where F: Invoke { type Result = Self; @@ -412,7 +412,7 @@ impl Invoke for ModuleBuilder impl Invoke for ModuleBuilder - where F: Invoke + where F: Invoke { type Result = Self; @@ -424,7 +424,7 @@ impl Invoke for ModuleBuilder } impl Invoke for ModuleBuilder - where F: Invoke + where F: Invoke { type Result = Self; @@ -436,7 +436,7 @@ impl Invoke for ModuleBuilder } impl Invoke for ModuleBuilder - where F: Invoke + where F: Invoke { type Result = Self; @@ -448,7 +448,7 @@ impl Invoke for ModuleBuilder } impl Invoke for ModuleBuilder - where F: Invoke + where F: Invoke { type Result = Self; @@ -458,7 +458,7 @@ impl Invoke for ModuleBuilder } impl Invoke for ModuleBuilder - where F: Invoke + where F: Invoke { type Result = Self; @@ -468,7 +468,7 @@ impl Invoke for ModuleBuilder } impl Invoke for ModuleBuilder - where F: Invoke + where F: Invoke { type Result = Self; @@ -477,22 +477,23 @@ impl Invoke for ModuleBuilder } } -impl Invoke for ModuleBuilder +impl Invoke for ModuleBuilder where F: Invoke { type Result = Self; fn invoke(self, segment: elements::DataSegment) -> Self { self.with_data_segment(segment) - } + } } /// Start new module builder +/// /// # Examples /// /// ``` /// use parity_wasm::builder; -/// +/// /// let module = builder::module() /// .function() /// .signature().param().i32().build() @@ -553,7 +554,7 @@ mod tests { .global().value_type().i64().mutable().init_expr(::elements::Opcode::I64Const(5)).build() .build(); - assert_eq!(module.global_section().expect("global section to exist").entries().len(), 1); + assert_eq!(module.global_section().expect("global section to exist").entries().len(), 1); } #[test] diff --git a/src/common/stack.rs b/src/common/stack.rs index 532dca7..b22cca8 100644 --- a/src/common/stack.rs +++ b/src/common/stack.rs @@ -47,22 +47,12 @@ impl StackWithLimit where T: Clone { self.limit } - pub fn values(&self) -> &VecDeque { - &self.values - } - pub fn top(&self) -> Result<&T, Error> { self.values .back() .ok_or(Error("non-empty stack expected".into())) } - pub fn top_mut(&mut self) -> Result<&mut T, Error> { - self.values - .back_mut() - .ok_or(Error("non-empty stack expected".into())) - } - pub fn get(&self, index: usize) -> Result<&T, Error> { if index >= self.values.len() { return Err(Error(format!("trying to get value at position {} on stack of size {}", index, self.values.len()))); @@ -80,19 +70,6 @@ impl StackWithLimit where T: Clone { Ok(()) } - pub fn push_penultimate(&mut self, value: T) -> Result<(), Error> { - if self.values.is_empty() { - return Err(Error("trying to insert penultimate element into empty stack".into())); - } - self.push(value)?; - - let last_index = self.values.len() - 1; - let penultimate_index = last_index - 1; - self.values.swap(last_index, penultimate_index); - - Ok(()) - } - pub fn pop(&mut self) -> Result { self.values .pop_back() diff --git a/src/interpreter/host.rs b/src/interpreter/host.rs index 9244e09..a97730f 100644 --- a/src/interpreter/host.rs +++ b/src/interpreter/host.rs @@ -1,4 +1,4 @@ -use std::any::{Any, TypeId}; +use std::any::Any; use std::sync::Arc; use std::marker::PhantomData; use std::collections::HashMap; @@ -370,59 +370,3 @@ impl< FunctionType::new(vec![P1::value_type(), P2::value_type()], Ret::value_type()) } } - -use interpreter::UserError; -use interpreter::store::MemoryId; - -// custom user error -#[derive(Debug, Clone, PartialEq)] -struct UserErrorWithCode { - error_code: i32, -} - -impl ::std::fmt::Display for UserErrorWithCode { - fn fmt(&self, f: &mut ::std::fmt::Formatter) -> Result<(), ::std::fmt::Error> { - write!(f, "{}", self.error_code) - } -} - -impl UserError for UserErrorWithCode {} - -// TODO: Rename to state -// user function executor -struct FunctionExecutor { - pub memory: MemoryId, - pub values: Vec, -} - -// TODO: Remove this stuff -fn build_env_module() -> HostModule { - let mut builder = HostModuleBuilder::::new(); - builder.with_func2("add", |store: &mut Store, state: &mut FunctionExecutor, arg: i32, unused: i32| { - let memory_value = state.memory.resolve(store).get(0, 1).unwrap()[0]; - let fn_argument_unused = unused as u8; - let fn_argument = arg as u8; - assert_eq!(fn_argument_unused, 0); - - let sum = memory_value + fn_argument; - state.memory.resolve(store).set(0, &vec![sum]).unwrap(); - state.values.push(sum as i32); - Ok(Some(sum as i32)) - }); - builder.with_func2("sub", |store: &mut Store, state: &mut FunctionExecutor, arg: i32, unused: i32| { - let memory_value = state.memory.resolve(store).get(0, 1).unwrap()[0]; - let fn_argument_unused = unused as u8; - let fn_argument = arg as u8; - assert_eq!(fn_argument_unused, 0); - - let diff = memory_value - fn_argument; - state.memory.resolve(store).set(0, &vec![diff]).unwrap(); - state.values.push(diff as i32); - Ok(Some(diff as i32)) - }); - builder.with_func0("err", |store: &mut Store, state: &mut FunctionExecutor| -> Result, Error> { - Err(Error::User(Box::new(UserErrorWithCode { error_code: 777 }))) - }); - builder.with_memory("memory", MemoryType::new(256, None)); - builder.build() -} diff --git a/src/interpreter/memory.rs b/src/interpreter/memory.rs index f54fecf..d432669 100644 --- a/src/interpreter/memory.rs +++ b/src/interpreter/memory.rs @@ -205,7 +205,6 @@ mod tests { use super::MemoryInstance; use interpreter::Error; use elements::MemoryType; - use std::sync::Arc; fn create_memory(initial_content: &[u8]) -> MemoryInstance { let mem = MemoryInstance::new(&MemoryType::new(1, Some(1))) diff --git a/src/interpreter/runner.rs b/src/interpreter/runner.rs index 7c200b4..29c0e24 100644 --- a/src/interpreter/runner.rs +++ b/src/interpreter/runner.rs @@ -1107,10 +1107,6 @@ impl FunctionContext { &self.frame_stack } - pub fn frame_stack_mut(&mut self) -> &mut StackWithLimit { - &mut self.frame_stack - } - pub fn push_frame(&mut self, labels: &HashMap, frame_type: BlockFrameType, block_type: BlockType) -> Result<(), Error> { let begin_position = self.position; let branch_position = match frame_type { diff --git a/src/interpreter/stack.rs b/src/interpreter/stack.rs index ae81933..e0b8a3a 100644 --- a/src/interpreter/stack.rs +++ b/src/interpreter/stack.rs @@ -11,12 +11,6 @@ impl StackWithLimit { TryInto::try_into(value) } - pub fn pop_pair(&mut self) -> Result<(RuntimeValue, RuntimeValue), InterpreterError> { - let right = self.pop()?; - let left = self.pop()?; - Ok((left, right)) - } - pub fn pop_pair_as(&mut self) -> Result<(T, T), InterpreterError> where RuntimeValue: TryInto, diff --git a/src/interpreter/tests/basics.rs b/src/interpreter/tests/basics.rs index 7f1b99e..c049c43 100644 --- a/src/interpreter/tests/basics.rs +++ b/src/interpreter/tests/basics.rs @@ -1,15 +1,10 @@ ///! Basic tests for instructions/constructions, missing in wabt tests -use std::sync::Arc; -use std::cell::RefCell; -use std::collections::HashMap; use builder::module; use elements::{ExportEntry, Internal, ImportEntry, External, GlobalEntry, GlobalType, - InitExpr, ValueType, Opcodes, Opcode, FunctionType, TableType, MemoryType}; + InitExpr, ValueType, Opcodes, Opcode, TableType, MemoryType}; use interpreter::{Error, UserError, ProgramInstance}; -use interpreter::memory::MemoryInstance; -use interpreter::value::{RuntimeValue, TryInto}; -use interpreter::variable::{VariableInstance, ExternalVariableValue, VariableType}; +use interpreter::value::RuntimeValue; use interpreter::host::{HostModuleBuilder, HostModule}; use interpreter::store::{Store, MemoryId}; use super::utils::program_with_default_env; @@ -241,7 +236,7 @@ fn native_env_global() { // try to add module, exporting non-existant env' variable => error { - let mut host_module_builder = HostModuleBuilder::::new(); + let host_module_builder = HostModuleBuilder::::new(); assert!(module_constructor(host_module_builder.build()).is_err()); } @@ -278,7 +273,7 @@ fn native_custom_error() { .build() .build(); - let module_instance = program.add_module("main", module, &mut state).unwrap(); + program.add_module("main", module, &mut state).unwrap(); let user_error = match program.invoke_index( "main", 0, diff --git a/src/interpreter/tests/wabt.rs b/src/interpreter/tests/wabt.rs index 528ab07..b068cdf 100644 --- a/src/interpreter/tests/wabt.rs +++ b/src/interpreter/tests/wabt.rs @@ -2,7 +2,7 @@ use builder::module; use elements::{ValueType, Opcodes, Opcode, BlockType, Local}; -use interpreter::{Error, ProgramInstance, ItemIndex}; +use interpreter::{Error, ProgramInstance}; use interpreter::value::{RuntimeValue, TryInto}; fn make_function_i32(body: Opcodes) -> ProgramInstance { @@ -520,7 +520,7 @@ fn call_1() { .build(); let mut program = ProgramInstance::new(); - let module = program.add_module("main", module, &mut ()).unwrap(); + program.add_module("main", module, &mut ()).unwrap(); assert_eq!(program.invoke_index("main", 0, vec![], &mut ()).unwrap().unwrap(), RuntimeValue::I32(10)); } @@ -567,7 +567,7 @@ fn call_2() { .build(); let mut program = ProgramInstance::new(); - let module = program.add_module("main", module, &mut ()).unwrap(); + program.add_module("main", module, &mut ()).unwrap(); assert_eq!(program.invoke_index("main", 0, vec![], &mut ()).unwrap().unwrap(), RuntimeValue::I32(3628800)); } @@ -612,7 +612,7 @@ fn call_zero_args() { .build(); let mut program = ProgramInstance::new(); - let module = program.add_module("main", module, &mut ()).unwrap(); + program.add_module("main", module, &mut ()).unwrap(); assert_eq!(program.invoke_index("main", 2, vec![], &mut ()).unwrap().unwrap(), RuntimeValue::I32(43)); } @@ -658,7 +658,7 @@ fn callindirect_1() { .build(); let mut program = ProgramInstance::new(); - let module = program.add_module("main", module, &mut ()).unwrap(); + program.add_module("main", module, &mut ()).unwrap(); assert_eq!(program.invoke_index("main", 2, vec![RuntimeValue::I32(0)], &mut ()).unwrap().unwrap(), RuntimeValue::I32(0)); assert_eq!(program.invoke_index("main", 2, vec![RuntimeValue::I32(1)], &mut ()).unwrap().unwrap(), RuntimeValue::I32(1)); } @@ -731,7 +731,7 @@ fn callindirect_2() { .build(); let mut program = ProgramInstance::new(); - let module = program.add_module("main", module, &mut ()).unwrap(); + program.add_module("main", module, &mut ()).unwrap(); assert_eq!(program.invoke_index("main", 3, vec![RuntimeValue::I32(10), RuntimeValue::I32(4), RuntimeValue::I32(0)], &mut ()).unwrap().unwrap(), RuntimeValue::I32(14)); assert_eq!(program.invoke_index("main", 3, vec![RuntimeValue::I32(10), RuntimeValue::I32(4), RuntimeValue::I32(1)], &mut ()).unwrap().unwrap(), RuntimeValue::I32(6)); match program.invoke_index("main", 3, vec![RuntimeValue::I32(10), RuntimeValue::I32(4), RuntimeValue::I32(2)], &mut ()) { @@ -813,7 +813,7 @@ fn select() { .build(); let mut program = ProgramInstance::new(); - let module = program.add_module("main", module, &mut ()).unwrap(); + program.add_module("main", module, &mut ()).unwrap(); assert_eq!(program.invoke_index("main", 0, vec![RuntimeValue::I32(0)], &mut ()).unwrap().unwrap(), RuntimeValue::I32(2)); assert_eq!(program.invoke_index("main", 0, vec![RuntimeValue::I32(1)], &mut ()).unwrap().unwrap(), RuntimeValue::I32(1)); assert_eq!(program.invoke_index("main", 1, vec![RuntimeValue::I32(0)], &mut ()).unwrap().unwrap(), RuntimeValue::I64(2)); @@ -966,7 +966,7 @@ fn binary_i32() { .build(); let mut program = ProgramInstance::new(); - let module = program.add_module("main", module, &mut ()).unwrap(); + program.add_module("main", module, &mut ()).unwrap(); assert_eq!(program.invoke_index("main", 0, vec![], &mut ()).unwrap().unwrap(), RuntimeValue::I32(3)); assert_eq!(program.invoke_index("main", 1, vec![], &mut ()).unwrap().unwrap(), RuntimeValue::I32(16)); assert_eq!(program.invoke_index("main", 2, vec![], &mut ()).unwrap().unwrap(), RuntimeValue::I32(21)); @@ -1126,7 +1126,7 @@ fn binary_i64() { .build(); let mut program = ProgramInstance::new(); - let module = program.add_module("main", module, &mut ()).unwrap(); + program.add_module("main", module, &mut ()).unwrap(); assert_eq!(program.invoke_index("main", 0, vec![], &mut ()).unwrap().unwrap(), RuntimeValue::I64(3)); assert_eq!(program.invoke_index("main", 1, vec![], &mut ()).unwrap().unwrap(), RuntimeValue::I64(16)); assert_eq!(program.invoke_index("main", 2, vec![], &mut ()).unwrap().unwrap(), RuntimeValue::I64(21)); @@ -1216,7 +1216,7 @@ fn binary_f32() { .build(); let mut program = ProgramInstance::new(); - let module = program.add_module("main", module, &mut ()).unwrap(); + program.add_module("main", module, &mut ()).unwrap(); assert_eq!(program.invoke_index("main", 0, vec![], &mut ()).unwrap().unwrap(), RuntimeValue::F32(5.000000)); assert_eq!(program.invoke_index("main", 1, vec![], &mut ()).unwrap().unwrap(), RuntimeValue::F32(-9995.500000)); assert_eq!(program.invoke_index("main", 2, vec![], &mut ()).unwrap().unwrap(), RuntimeValue::F32(-8487.187500)); @@ -1298,7 +1298,7 @@ fn binary_f64() { .build(); let mut program = ProgramInstance::new(); - let module = program.add_module("main", module, &mut ()).unwrap(); + program.add_module("main", module, &mut ()).unwrap(); assert_eq!(program.invoke_index("main", 0, vec![], &mut ()).unwrap().unwrap(), RuntimeValue::F64(1111111110.000000)); assert_eq!(program.invoke_index("main", 1, vec![], &mut ()).unwrap().unwrap(), RuntimeValue::F64(123400000000000007812762268812638756607430593436581896388608.000000)); assert_eq!(program.invoke_index("main", 2, vec![], &mut ()).unwrap().unwrap(), RuntimeValue::F64(-15179717820000.000000)); @@ -1351,7 +1351,7 @@ fn cast() { .build(); let mut program = ProgramInstance::new(); - let module = program.add_module("main", module, &mut ()).unwrap(); + program.add_module("main", module, &mut ()).unwrap(); assert_eq!(program.invoke_index("main", 0, vec![], &mut ()).unwrap().unwrap(), RuntimeValue::F32(4.5)); assert_eq!(program.invoke_index("main", 1, vec![], &mut ()).unwrap().unwrap(), RuntimeValue::I32(-1067450368)); // 3227516928 assert_eq!(program.invoke_index("main", 2, vec![], &mut ()).unwrap().unwrap(), RuntimeValue::F64(125.125000)); @@ -1617,7 +1617,7 @@ fn compare_i32() { .build(); let mut program = ProgramInstance::new(); - let module = program.add_module("main", module, &mut ()).unwrap(); + program.add_module("main", module, &mut ()).unwrap(); assert_eq!(program.invoke_index("main", 0, vec![], &mut ()).unwrap().unwrap(), RuntimeValue::I32(1)); assert_eq!(program.invoke_index("main", 1, vec![], &mut ()).unwrap().unwrap(), RuntimeValue::I32(0)); assert_eq!(program.invoke_index("main", 2, vec![], &mut ()).unwrap().unwrap(), RuntimeValue::I32(1)); @@ -1907,7 +1907,7 @@ fn compare_i64() { .build(); let mut program = ProgramInstance::new(); - let module = program.add_module("main", module, &mut ()).unwrap(); + program.add_module("main", module, &mut ()).unwrap(); assert_eq!(program.invoke_index("main", 0, vec![], &mut ()).unwrap().unwrap(), RuntimeValue::I32(1)); assert_eq!(program.invoke_index("main", 1, vec![], &mut ()).unwrap().unwrap(), RuntimeValue::I32(0)); assert_eq!(program.invoke_index("main", 2, vec![], &mut ()).unwrap().unwrap(), RuntimeValue::I32(1)); @@ -2091,7 +2091,7 @@ fn compare_f32() { .build(); let mut program = ProgramInstance::new(); - let module = program.add_module("main", module, &mut ()).unwrap(); + program.add_module("main", module, &mut ()).unwrap(); assert_eq!(program.invoke_index("main", 0, vec![], &mut ()).unwrap().unwrap(), RuntimeValue::I32(1)); assert_eq!(program.invoke_index("main", 1, vec![], &mut ()).unwrap().unwrap(), RuntimeValue::I32(0)); assert_eq!(program.invoke_index("main", 2, vec![], &mut ()).unwrap().unwrap(), RuntimeValue::I32(1)); @@ -2263,7 +2263,7 @@ fn compare_f64() { .build(); let mut program = ProgramInstance::new(); - let module = program.add_module("main", module, &mut ()).unwrap(); + program.add_module("main", module, &mut ()).unwrap(); assert_eq!(program.invoke_index("main", 0, vec![], &mut ()).unwrap().unwrap(), RuntimeValue::I32(1)); assert_eq!(program.invoke_index("main", 1, vec![], &mut ()).unwrap().unwrap(), RuntimeValue::I32(0)); assert_eq!(program.invoke_index("main", 2, vec![], &mut ()).unwrap().unwrap(), RuntimeValue::I32(1)); @@ -2331,7 +2331,7 @@ fn convert_i32() { .build(); let mut program = ProgramInstance::new(); - let module = program.add_module("main", module, &mut ()).unwrap(); + program.add_module("main", module, &mut ()).unwrap(); assert_eq!(program.invoke_index("main", 0, vec![], &mut ()).unwrap().unwrap(), RuntimeValue::I32(-1)); // 4294967295 assert_eq!(program.invoke_index("main", 1, vec![], &mut ()).unwrap().unwrap(), RuntimeValue::I32(-100)); // 4294967196 assert_eq!(program.invoke_index("main", 2, vec![], &mut ()).unwrap().unwrap(), RuntimeValue::I32(-1294967296)); // 3000000000 @@ -2404,7 +2404,7 @@ fn convert_i64() { .build(); let mut program = ProgramInstance::new(); - let module = program.add_module("main", module, &mut ()).unwrap(); + program.add_module("main", module, &mut ()).unwrap(); assert_eq!(program.invoke_index("main", 0, vec![], &mut ()).unwrap().unwrap(), RuntimeValue::I64(4294967295)); assert_eq!(program.invoke_index("main", 1, vec![], &mut ()).unwrap().unwrap(), RuntimeValue::I64(-1)); // 18446744073709551615 assert_eq!(program.invoke_index("main", 2, vec![], &mut ()).unwrap().unwrap(), RuntimeValue::I32(1)); @@ -2462,7 +2462,7 @@ fn convert_f32() { .build(); let mut program = ProgramInstance::new(); - let module = program.add_module("main", module, &mut ()).unwrap(); + program.add_module("main", module, &mut ()).unwrap(); assert_eq!(program.invoke_index("main", 0, vec![], &mut ()).unwrap().unwrap(), RuntimeValue::F32(-1.000000)); assert_eq!(program.invoke_index("main", 1, vec![], &mut ()).unwrap().unwrap(), RuntimeValue::F32(4294967296.000000)); assert_eq!(program.invoke_index("main", 2, vec![], &mut ()).unwrap().unwrap(), RuntimeValue::F32(12345679.000000)); @@ -2519,7 +2519,7 @@ fn convert_f64() { .build(); let mut program = ProgramInstance::new(); - let module = program.add_module("main", module, &mut ()).unwrap(); + program.add_module("main", module, &mut ()).unwrap(); assert_eq!(program.invoke_index("main", 0, vec![], &mut ()).unwrap().unwrap(), RuntimeValue::F64(-1.000000)); assert_eq!(program.invoke_index("main", 1, vec![], &mut ()).unwrap().unwrap(), RuntimeValue::F64(4294967295.000000)); assert_eq!(program.invoke_index("main", 2, vec![], &mut ()).unwrap().unwrap(), RuntimeValue::F64(12345679.000000)); @@ -2579,7 +2579,7 @@ fn load_i32() { .build(); let mut program = ProgramInstance::new(); - let module = program.add_module("main", module, &mut ()).unwrap(); + program.add_module("main", module, &mut ()).unwrap(); assert_eq!(program.invoke_index("main", 0, vec![], &mut ()).unwrap().unwrap(), RuntimeValue::I32(-1)); assert_eq!(program.invoke_index("main", 1, vec![], &mut ()).unwrap().unwrap(), RuntimeValue::I32(-1)); assert_eq!(program.invoke_index("main", 2, vec![], &mut ()).unwrap().unwrap(), RuntimeValue::I32(-1)); @@ -2655,7 +2655,7 @@ fn load_i64() { .build(); let mut program = ProgramInstance::new(); - let module = program.add_module("main", module, &mut ()).unwrap(); + program.add_module("main", module, &mut ()).unwrap(); assert_eq!(program.invoke_index("main", 0, vec![], &mut ()).unwrap().unwrap(), RuntimeValue::I64(-1)); assert_eq!(program.invoke_index("main", 1, vec![], &mut ()).unwrap().unwrap(), RuntimeValue::I64(-1)); assert_eq!(program.invoke_index("main", 2, vec![], &mut ()).unwrap().unwrap(), RuntimeValue::I64(-1)); @@ -2685,7 +2685,7 @@ fn load_f32() { .build(); let mut program = ProgramInstance::new(); - let module = program.add_module("main", module, &mut ()).unwrap(); + program.add_module("main", module, &mut ()).unwrap(); assert_eq!(program.invoke_index("main", 0, vec![], &mut ()).unwrap().unwrap(), RuntimeValue::F32(25.750000)); } @@ -2709,7 +2709,7 @@ fn load_f64() { .build(); let mut program = ProgramInstance::new(); - let module = program.add_module("main", module, &mut ()).unwrap(); + program.add_module("main", module, &mut ()).unwrap(); assert_eq!(program.invoke_index("main", 0, vec![], &mut ()).unwrap().unwrap(), RuntimeValue::F64(1023.875000)); } @@ -2766,7 +2766,7 @@ fn store_i32() { .build(); let mut program = ProgramInstance::new(); - let module = program.add_module("main", module, &mut ()).unwrap(); + program.add_module("main", module, &mut ()).unwrap(); assert_eq!(program.invoke_index("main", 0, vec![], &mut ()).unwrap().unwrap(), RuntimeValue::I32(-16909061)); assert_eq!(program.invoke_index("main", 1, vec![], &mut ()).unwrap().unwrap(), RuntimeValue::I32(-859059511)); assert_eq!(program.invoke_index("main", 2, vec![], &mut ()).unwrap().unwrap(), RuntimeValue::I32(-123456)); @@ -2836,7 +2836,7 @@ fn store_i64() { .build(); let mut program = ProgramInstance::new(); - let module = program.add_module("main", module, &mut ()).unwrap(); + program.add_module("main", module, &mut ()).unwrap(); assert_eq!(program.invoke_index("main", 0, vec![], &mut ()).unwrap().unwrap(), RuntimeValue::I64(4278058235)); assert_eq!(program.invoke_index("main", 1, vec![], &mut ()).unwrap().unwrap(), RuntimeValue::I64(3435907785)); assert_eq!(program.invoke_index("main", 2, vec![], &mut ()).unwrap().unwrap(), RuntimeValue::I64(4294843840)); @@ -2864,7 +2864,7 @@ fn store_f32() { .build(); let mut program = ProgramInstance::new(); - let module = program.add_module("main", module, &mut ()).unwrap(); + program.add_module("main", module, &mut ()).unwrap(); assert_eq!(program.invoke_index("main", 0, vec![], &mut ()).unwrap().unwrap(), RuntimeValue::I32(1069547520)); } @@ -2889,7 +2889,7 @@ fn store_f64() { .build(); let mut program = ProgramInstance::new(); - let module = program.add_module("main", module, &mut ()).unwrap(); + program.add_module("main", module, &mut ()).unwrap(); assert_eq!(program.invoke_index("main", 0, vec![], &mut ()).unwrap().unwrap(), RuntimeValue::I32(-1064352256)); } @@ -2940,7 +2940,7 @@ fn unary_i32() { .build(); let mut program = ProgramInstance::new(); - let module = program.add_module("main", module, &mut ()).unwrap(); + program.add_module("main", module, &mut ()).unwrap(); assert_eq!(program.invoke_index("main", 0, vec![], &mut ()).unwrap().unwrap(), RuntimeValue::I32(0)); assert_eq!(program.invoke_index("main", 1, vec![], &mut ()).unwrap().unwrap(), RuntimeValue::I32(1)); assert_eq!(program.invoke_index("main", 2, vec![], &mut ()).unwrap().unwrap(), RuntimeValue::I32(24)); @@ -2995,7 +2995,7 @@ fn unary_i64() { .build(); let mut program = ProgramInstance::new(); - let module = program.add_module("main", module, &mut ()).unwrap(); + program.add_module("main", module, &mut ()).unwrap(); assert_eq!(program.invoke_index("main", 0, vec![], &mut ()).unwrap().unwrap(), RuntimeValue::I32(0)); assert_eq!(program.invoke_index("main", 1, vec![], &mut ()).unwrap().unwrap(), RuntimeValue::I32(1)); assert_eq!(program.invoke_index("main", 2, vec![], &mut ()).unwrap().unwrap(), RuntimeValue::I64(56)); @@ -3094,7 +3094,7 @@ fn unary_f32() { .build(); let mut program = ProgramInstance::new(); - let module = program.add_module("main", module, &mut ()).unwrap(); + program.add_module("main", module, &mut ()).unwrap(); assert_eq!(program.invoke_index("main", 1, vec![], &mut ()).unwrap().unwrap(), RuntimeValue::F32(-100.000000)); assert_eq!(program.invoke_index("main", 2, vec![], &mut ()).unwrap().unwrap(), RuntimeValue::F32(100.000000)); assert_eq!(program.invoke_index("main", 3, vec![], &mut ()).unwrap().unwrap(), RuntimeValue::I32(1)); @@ -3197,7 +3197,7 @@ fn unary_f64() { .build(); let mut program = ProgramInstance::new(); - let module = program.add_module("main", module, &mut ()).unwrap(); + program.add_module("main", module, &mut ()).unwrap(); assert_eq!(program.invoke_index("main", 1, vec![], &mut ()).unwrap().unwrap(), RuntimeValue::F64(-100.000000)); assert_eq!(program.invoke_index("main", 2, vec![], &mut ()).unwrap().unwrap(), RuntimeValue::F64(100.000000)); assert_eq!(program.invoke_index("main", 3, vec![], &mut ()).unwrap().unwrap(), RuntimeValue::I32(1)); diff --git a/src/interpreter/tests/wasm.rs b/src/interpreter/tests/wasm.rs index a5446ed..6581dae 100644 --- a/src/interpreter/tests/wasm.rs +++ b/src/interpreter/tests/wasm.rs @@ -1,8 +1,6 @@ use elements::deserialize_file; use elements::Module; -use interpreter::ExecutionParams; use interpreter::value::RuntimeValue; -use interpreter::module::{ItemIndex}; use super::utils::program_with_default_env; #[test] @@ -23,7 +21,7 @@ fn interpreter_inc_i32() { let module_result = program.add_module("main", module, &mut ()); - let module = module_result + module_result .expect("Failed to initialize module"); let retval = program.invoke_export("main", FUNCTION_NAME, args, &mut ()).expect(""); @@ -44,7 +42,7 @@ fn interpreter_accumulate_u8() { // Load the module-structure from wasm-file and add to program let module: Module = deserialize_file(WASM_FILE).expect("Failed to deserialize module from buffer"); - let module = program + program .add_module("main", module, &mut ()) .expect("Failed to initialize module");