continue env

This commit is contained in:
Svyatoslav Nikolsky
2017-05-04 19:25:00 +03:00
parent 3c7ee09f8e
commit 5c97dc0ce9
2 changed files with 12 additions and 2 deletions

View File

@@ -101,6 +101,16 @@ impl ModuleImports {
.and_then(|p| p.module(name).ok_or(Error::Program(format!("module {} is not loaded", name)))) .and_then(|p| p.module(name).ok_or(Error::Program(format!("module {} is not loaded", name))))
} }
/// Get function index.
pub fn function(&self, import: &ImportEntry) -> Result<u32, Error> {
let (_, export) = self.external_export(import)?;
if let Internal::Function(external_index) = export {
return Ok(external_index);
}
Err(Error::Program(format!("wrong import {} from module {} (expecting function)", import.field(), import.module())))
}
/// Get table reference. /// Get table reference.
pub fn table(&self, import: &ImportEntry) -> Result<Arc<TableInstance>, Error> { pub fn table(&self, import: &ImportEntry) -> Result<Arc<TableInstance>, Error> {
let (module, export) = self.external_export(import)?; let (module, export) = self.external_export(import)?;

View File

@@ -226,8 +226,8 @@ impl ModuleInstanceInterface for ModuleInstance {
.ok_or(Error::Function(format!("trying to access external function with index {} in module without import section", index))) .ok_or(Error::Function(format!("trying to access external function with index {} in module without import section", index)))
.and_then(|s| s.entries().get(index as usize) .and_then(|s| s.entries().get(index as usize)
.ok_or(Error::Function(format!("trying to access external function with index {} in module with {}-entries import section", index, s.entries().len())))) .ok_or(Error::Function(format!("trying to access external function with index {} in module with {}-entries import section", index, s.entries().len()))))
.and_then(|e| self.imports.module(e.module())) .and_then(|e| Ok((self.imports.module(e.module())?, self.imports.function(e)?)))
.and_then(|m| m.call_internal_function(outer, index, None)), .and_then(|(m, index)| m.call_internal_function(outer, index, None)),
} }
} }