diff --git a/src/interpreter/mod.rs b/src/interpreter/mod.rs index 173f547..8c1a1ad 100644 --- a/src/interpreter/mod.rs +++ b/src/interpreter/mod.rs @@ -1,4 +1,4 @@ -#![allow(dead_code, unused_variables, missing_docs)] +#![allow(missing_docs)] #[derive(Debug, Clone, PartialEq)] pub enum Error { @@ -50,3 +50,7 @@ mod variable; #[cfg(test)] mod tests; + +pub use self::module::ModuleInstance; +pub use self::program::ProgramInstance; +pub use self::value::RuntimeValue; \ No newline at end of file diff --git a/src/interpreter/module.rs b/src/interpreter/module.rs index 47a5c63..52241f6 100644 --- a/src/interpreter/module.rs +++ b/src/interpreter/module.rs @@ -104,6 +104,11 @@ impl ModuleInstance { }) } + /// Execute start function of the module. + pub fn execute_main(&self, _args: &[RuntimeValue]) -> Result, Error> { + unimplemented!() + } + /// Get module description reference. pub fn module(&self) -> &Module { &self.module @@ -206,7 +211,7 @@ impl ModuleInstance { } /// Call function with given index in the given table. - pub fn call_function_indirect(&self, outer: &mut FunctionContext, table_index: ItemIndex, type_index: u32, func_index: u32) -> Result, Error> { + pub fn call_function_indirect(&self, outer: &mut FunctionContext, table_index: ItemIndex, _type_index: u32, func_index: u32) -> Result, Error> { // TODO: check signature match self.imports.parse_table_index(table_index) { ItemIndex::IndexSpace(_) => unreachable!("parse_function_index resolves IndexSpace option"), diff --git a/src/interpreter/program.rs b/src/interpreter/program.rs index e030e61..c99a15e 100644 --- a/src/interpreter/program.rs +++ b/src/interpreter/program.rs @@ -27,13 +27,14 @@ impl ProgramInstance { } /// Instantiate module. - pub fn add_module(&self, name: &str, module: Module) -> Result<(), Error> { + pub fn add_module(&self, name: &str, module: Module) -> Result, Error> { let mut modules = self.essence.modules.write(); match modules.entry(name.into()) { Entry::Occupied(_) => Err(Error::Program(format!("module {} already instantiated", name))), Entry::Vacant(entry) => { - entry.insert(Arc::new(ModuleInstance::new(Arc::downgrade(&self.essence), module)?)); - Ok(()) + let module_instance = Arc::new(ModuleInstance::new(Arc::downgrade(&self.essence), module)?); + entry.insert(module_instance.clone()); + Ok(module_instance) }, } } diff --git a/src/interpreter/runner.rs b/src/interpreter/runner.rs index cdd629e..66cdff1 100644 --- a/src/interpreter/runner.rs +++ b/src/interpreter/runner.rs @@ -82,7 +82,7 @@ impl Interpreter { &Opcode::Return => Interpreter::run_return(context), &Opcode::Call(index) => Interpreter::run_call(context, index), - &Opcode::CallIndirect(index, reserved) => Interpreter::run_call_indirect(context, index), + &Opcode::CallIndirect(index, _reserved) => Interpreter::run_call_indirect(context, index), &Opcode::Drop => Interpreter::run_drop(context), &Opcode::Select => Interpreter::run_select(context), @@ -261,11 +261,11 @@ impl Interpreter { } } - fn run_unreachable(context: &mut FunctionContext) -> Result { + fn run_unreachable(_context: &mut FunctionContext) -> Result { Err(Error::Trap("programmatic".into())) } - fn run_nop(context: &mut FunctionContext) -> Result { + fn run_nop(_context: &mut FunctionContext) -> Result { Ok(InstructionOutcome::RunNextInstruction) } @@ -299,15 +299,15 @@ impl Interpreter { } } - fn run_else(context: &mut FunctionContext) -> Result { + fn run_else(_context: &mut FunctionContext) -> Result { Ok(InstructionOutcome::End) } - fn run_end(context: &mut FunctionContext) -> Result { + fn run_end(_context: &mut FunctionContext) -> Result { Ok(InstructionOutcome::End) } - fn run_br(context: &mut FunctionContext, label_idx: u32) -> Result { + fn run_br(_context: &mut FunctionContext, label_idx: u32) -> Result { Ok(InstructionOutcome::Branch(label_idx as usize)) } @@ -324,7 +324,7 @@ impl Interpreter { Ok(InstructionOutcome::Branch(table.get(index as usize).cloned().unwrap_or(default) as usize)) } - fn run_return(context: &mut FunctionContext) -> Result { + fn run_return(_context: &mut FunctionContext) -> Result { Ok(InstructionOutcome::Return) } @@ -781,9 +781,9 @@ impl Interpreter { .map(|_| InstructionOutcome::RunNextInstruction) } - fn run_copysign(context: &mut FunctionContext) -> Result + fn run_copysign(_context: &mut FunctionContext) -> Result where RuntimeValue: From + TryInto, T: Float { - Err(Error::NotImplemented) + Err(Error::NotImplemented) // TODO } fn run_wrap(context: &mut FunctionContext) -> Result diff --git a/src/interpreter/table.rs b/src/interpreter/table.rs index 09c317d..da5b009 100644 --- a/src/interpreter/table.rs +++ b/src/interpreter/table.rs @@ -12,8 +12,6 @@ pub struct TableInstance { variable_type: VariableType, /// Table memory buffer. buffer: RwLock>, - /// Maximum buffer size. - maximum_size: u32, } impl TableInstance { @@ -23,7 +21,6 @@ impl TableInstance { buffer: RwLock::new( vec![VariableInstance::new(true, variable_type, RuntimeValue::Null)?; table_type.limits().initial() as usize] ), - maximum_size: table_type.limits().maximum().unwrap_or(u32::MAX), })) } diff --git a/src/interpreter/utils.rs b/src/interpreter/utils.rs index 2b335af..e283cae 100644 --- a/src/interpreter/utils.rs +++ b/src/interpreter/utils.rs @@ -1,7 +1,7 @@ -pub fn to_little_endian_bytes(number: T) -> Vec { +pub fn to_little_endian_bytes(_number: T) -> Vec { unimplemented!() } -pub fn from_little_endian_bytes(buffer: &[u8]) -> T { +pub fn from_little_endian_bytes(_buffer: &[u8]) -> T { unimplemented!() } diff --git a/src/lib.rs b/src/lib.rs index 4ce4b2e..117eb89 100644 --- a/src/lib.rs +++ b/src/lib.rs @@ -16,3 +16,9 @@ pub use elements::{ serialize, serialize_to_file, }; + +pub use interpreter::{ + ProgramInstance, + ModuleInstance, + RuntimeValue, +};