mirror of
https://github.com/fluencelabs/wasmer
synced 2025-06-21 12:41:32 +00:00
Add method to call function at index on Ctx
This commit is contained in:
@ -518,7 +518,7 @@ impl LikeNamespace for Rc<Instance> {
|
|||||||
}
|
}
|
||||||
|
|
||||||
#[must_use]
|
#[must_use]
|
||||||
fn call_func_with_index(
|
pub(crate) fn call_func_with_index(
|
||||||
info: &ModuleInfo,
|
info: &ModuleInfo,
|
||||||
runnable: &dyn RunnableModule,
|
runnable: &dyn RunnableModule,
|
||||||
import_backing: &ImportBacking,
|
import_backing: &ImportBacking,
|
||||||
|
@ -1,9 +1,11 @@
|
|||||||
pub use crate::backing::{ImportBacking, LocalBacking, INTERNALS_SIZE};
|
pub use crate::backing::{ImportBacking, LocalBacking, INTERNALS_SIZE};
|
||||||
use crate::{
|
use crate::{
|
||||||
|
error::{CallError, CallResult, RuntimeError},
|
||||||
|
instance::call_func_with_index,
|
||||||
memory::{Memory, MemoryType},
|
memory::{Memory, MemoryType},
|
||||||
module::{ModuleInfo, ModuleInner},
|
module::{ModuleInfo, ModuleInner},
|
||||||
structures::TypedIndex,
|
structures::TypedIndex,
|
||||||
types::{LocalOrImport, MemoryIndex},
|
types::{FuncIndex, LocalOrImport, MemoryIndex, Value},
|
||||||
vmcalls,
|
vmcalls,
|
||||||
};
|
};
|
||||||
use std::{
|
use std::{
|
||||||
@ -393,6 +395,27 @@ impl Ctx {
|
|||||||
(*self.internal.internals)[field.index()] = value;
|
(*self.internal.internals)[field.index()] = value;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/// Calls a host or Wasm function at the given index
|
||||||
|
pub fn call_with_index(&mut self, index: FuncIndex, args: &[Value]) -> CallResult<Vec<Value>> {
|
||||||
|
let module = unsafe { &(*self.module) };
|
||||||
|
if module.info.func_assoc.get(index).is_none() {
|
||||||
|
return Err(CallError::Runtime(RuntimeError::Trap {
|
||||||
|
msg: format!("Index out of bounds: {}", index.index()).into_boxed_str(),
|
||||||
|
}));
|
||||||
|
}
|
||||||
|
let mut output = vec![];
|
||||||
|
call_func_with_index(
|
||||||
|
&module.info,
|
||||||
|
module.runnable_module.as_ref(),
|
||||||
|
unsafe { &*self.import_backing },
|
||||||
|
self as *mut Ctx,
|
||||||
|
index,
|
||||||
|
args,
|
||||||
|
&mut output,
|
||||||
|
)?;
|
||||||
|
Ok(output)
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
#[doc(hidden)]
|
#[doc(hidden)]
|
||||||
|
Reference in New Issue
Block a user