mirror of
https://github.com/fluencelabs/parity-wasm
synced 2025-07-31 22:31:59 +00:00
continue env
This commit is contained in:
@@ -101,6 +101,16 @@ impl ModuleImports {
|
||||
.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.
|
||||
pub fn table(&self, import: &ImportEntry) -> Result<Arc<TableInstance>, Error> {
|
||||
let (module, export) = self.external_export(import)?;
|
||||
|
@@ -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)))
|
||||
.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()))))
|
||||
.and_then(|e| self.imports.module(e.module()))
|
||||
.and_then(|m| m.call_internal_function(outer, index, None)),
|
||||
.and_then(|e| Ok((self.imports.module(e.module())?, self.imports.function(e)?)))
|
||||
.and_then(|(m, index)| m.call_internal_function(outer, index, None)),
|
||||
}
|
||||
}
|
||||
|
||||
|
Reference in New Issue
Block a user