another tests added

This commit is contained in:
Svyatoslav Nikolsky
2017-06-13 12:01:59 +03:00
parent c8614bf6fe
commit 0ee2826943
21 changed files with 537 additions and 300 deletions

View File

@ -4,11 +4,11 @@ use parking_lot::RwLock;
use elements::{FunctionType, Internal, ValueType};
use interpreter::Error;
use interpreter::module::{ModuleInstanceInterface, ExecutionParams, ItemIndex,
CallerContext};
CallerContext, ExportEntryType};
use interpreter::memory::MemoryInstance;
use interpreter::table::TableInstance;
use interpreter::value::RuntimeValue;
use interpreter::variable::VariableInstance;
use interpreter::variable::{VariableInstance, VariableType};
/// Min index of native function.
pub const NATIVE_INDEX_FUNC_MIN: u32 = 10001;
@ -65,6 +65,10 @@ impl<'a> NativeModuleInstance<'a> {
}
impl<'a> ModuleInstanceInterface for NativeModuleInstance<'a> {
fn instantiate<'b>(&self, is_user_module: bool, externals: Option<&'b HashMap<String, Arc<ModuleInstanceInterface + 'b>>>) -> Result<(), Error> {
self.env.instantiate(is_user_module, externals)
}
fn execute_index(&self, index: u32, params: ExecutionParams) -> Result<Option<RuntimeValue>, Error> {
self.env.execute_index(index, params)
}
@ -73,12 +77,28 @@ impl<'a> ModuleInstanceInterface for NativeModuleInstance<'a> {
self.env.execute_export(name, params)
}
fn export_entry(&self, name: &str) -> Result<Internal, Error> {
fn export_entry<'b>(&self, name: &str, externals: Option<&'b HashMap<String, Arc<ModuleInstanceInterface + 'b>>>, required_type: &ExportEntryType) -> Result<Internal, Error> {
if let Some(index) = self.by_name.get(name) {
return Ok(Internal::Function(NATIVE_INDEX_FUNC_MIN + *index));
}
self.env.export_entry(name)
self.env.export_entry(name, externals, required_type)
}
fn function_type<'b>(&self, function_index: ItemIndex, externals: Option<&'b HashMap<String, Arc<ModuleInstanceInterface + 'b>>>) -> Result<FunctionType, Error> {
let index = match function_index {
ItemIndex::IndexSpace(index) | ItemIndex::Internal(index) => index,
ItemIndex::External(_) => unreachable!("trying to call function, exported by native env module"),
};
if index < NATIVE_INDEX_FUNC_MIN {
return self.env.function_type(function_index, externals);
}
self.functions
.get((index - NATIVE_INDEX_FUNC_MIN) as usize)
.ok_or(Error::Native(format!("missing native env function with index {}", index)))
.map(|f| FunctionType::new(f.params.clone(), f.result.clone()))
}
fn table(&self, index: ItemIndex) -> Result<Arc<TableInstance>, Error> {
@ -89,12 +109,12 @@ impl<'a> ModuleInstanceInterface for NativeModuleInstance<'a> {
self.env.memory(index)
}
fn global(&self, index: ItemIndex) -> Result<Arc<VariableInstance>, Error> {
self.env.global(index)
fn global(&self, index: ItemIndex, variable_type: Option<VariableType>) -> Result<Arc<VariableInstance>, Error> {
self.env.global(index, variable_type)
}
fn call_function(&self, outer: CallerContext, index: ItemIndex) -> Result<Option<RuntimeValue>, Error> {
self.env.call_function(outer, index)
fn call_function(&self, outer: CallerContext, index: ItemIndex, function_type: Option<&FunctionType>) -> Result<Option<RuntimeValue>, Error> {
self.env.call_function(outer, index, function_type)
}
fn call_function_indirect(&self, outer: CallerContext, table_index: ItemIndex, type_index: u32, func_index: u32) -> Result<Option<RuntimeValue>, Error> {