mirror of
https://github.com/fluencelabs/parity-wasm
synced 2025-06-22 19:21:59 +00:00
func_by_index
This commit is contained in:
@ -103,7 +103,9 @@ impl ProgramInstance {
|
|||||||
let module_id = self.modules.get(module_name).ok_or_else(|| {
|
let module_id = self.modules.get(module_name).ok_or_else(|| {
|
||||||
Error::Program(format!("Module {} not found", module_name))
|
Error::Program(format!("Module {} not found", module_name))
|
||||||
})?;
|
})?;
|
||||||
let func_id = module_id.resolve_func(&self.store, func_idx);
|
let func_id = module_id.func_by_index(&self.store, func_idx).ok_or_else(|| {
|
||||||
|
Error::Program(format!("Module doesn't contain function at index {}", func_idx))
|
||||||
|
})?;
|
||||||
|
|
||||||
self.store.invoke(func_id, args, state)
|
self.store.invoke(func_id, args, state)
|
||||||
}
|
}
|
||||||
|
@ -413,8 +413,15 @@ impl<'store, St: 'static> Interpreter<'store, St> {
|
|||||||
Ok(InstructionOutcome::Return)
|
Ok(InstructionOutcome::Return)
|
||||||
}
|
}
|
||||||
|
|
||||||
fn run_call<'a>(&mut self, context: &mut FunctionContext, func_idx: u32) -> Result<InstructionOutcome, Error> {
|
fn run_call<'a>(
|
||||||
let func = context.module().resolve_func(self.store, func_idx);
|
&mut self,
|
||||||
|
context: &mut FunctionContext,
|
||||||
|
func_idx: u32,
|
||||||
|
) -> Result<InstructionOutcome, Error> {
|
||||||
|
let func = context
|
||||||
|
.module()
|
||||||
|
.func_by_index(self.store, func_idx)
|
||||||
|
.expect("Due to validation func should exists");
|
||||||
Ok(InstructionOutcome::ExecuteCall(func))
|
Ok(InstructionOutcome::ExecuteCall(func))
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -56,12 +56,12 @@ impl ModuleId {
|
|||||||
.expect("Due to validation global should exists")
|
.expect("Due to validation global should exists")
|
||||||
}
|
}
|
||||||
|
|
||||||
pub fn resolve_func(&self, store: &Store, idx: u32) -> FuncId {
|
pub fn func_by_index(&self, store: &Store, idx: u32) -> Option<FuncId> {
|
||||||
let instance = store.resolve_module(*self);
|
let instance = store.resolve_module(*self);
|
||||||
*instance
|
instance
|
||||||
.funcs
|
.funcs
|
||||||
.get(idx as usize)
|
.get(idx as usize)
|
||||||
.expect("Due to validation func should exists")
|
.cloned()
|
||||||
}
|
}
|
||||||
|
|
||||||
pub fn resolve_type(&self, store: &Store, idx: u32) -> TypeId {
|
pub fn resolve_type(&self, store: &Store, idx: u32) -> TypeId {
|
||||||
|
Reference in New Issue
Block a user