Fix warnings

This commit is contained in:
Sergey Pepyakin
2017-12-12 16:31:58 +01:00
parent c5c8af03e1
commit 4b2c100d1f
11 changed files with 61 additions and 157 deletions

View File

@ -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");

View File

@ -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(""));
}

View File

@ -488,6 +488,7 @@ impl<F> Invoke<elements::DataSegment> for ModuleBuilder<F>
}
/// Start new module builder
///
/// # Examples
///
/// ```

View File

@ -47,22 +47,12 @@ impl<T> StackWithLimit<T> where T: Clone {
self.limit
}
pub fn values(&self) -> &VecDeque<T> {
&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<T> StackWithLimit<T> 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<T, Error> {
self.values
.pop_back()

View File

@ -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<i32>,
}
// TODO: Remove this stuff
fn build_env_module() -> HostModule {
let mut builder = HostModuleBuilder::<FunctionExecutor>::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<Option<i32>, Error> {
Err(Error::User(Box::new(UserErrorWithCode { error_code: 777 })))
});
builder.with_memory("memory", MemoryType::new(256, None));
builder.build()
}

View File

@ -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)))

View File

@ -1107,10 +1107,6 @@ impl FunctionContext {
&self.frame_stack
}
pub fn frame_stack_mut(&mut self) -> &mut StackWithLimit<BlockFrame> {
&mut self.frame_stack
}
pub fn push_frame(&mut self, labels: &HashMap<usize, usize>, frame_type: BlockFrameType, block_type: BlockType) -> Result<(), Error> {
let begin_position = self.position;
let branch_position = match frame_type {

View File

@ -11,12 +11,6 @@ impl StackWithLimit<RuntimeValue> {
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<T>(&mut self) -> Result<(T, T), InterpreterError>
where
RuntimeValue: TryInto<T, InterpreterError>,

View File

@ -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::<State>::new();
let host_module_builder = HostModuleBuilder::<State>::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,

View File

@ -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));

View File

@ -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");