-
Notifications
You must be signed in to change notification settings - Fork 3
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Signed-off-by: George Cosma <[email protected]>
- Loading branch information
1 parent
7555d9d
commit 7de2fe2
Showing
2 changed files
with
173 additions
and
53 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,37 @@ | ||
use alloc::string::String; | ||
use alloc::vec::Vec; | ||
|
||
use crate::execution::{hooks::HookSet, value::InteropValueList, RuntimeInstance}; | ||
use crate::{RuntimeError, ValType, Value}; | ||
|
||
pub struct FunctionRef { | ||
pub(crate) module_name: String, | ||
pub(crate) function_name: String, | ||
pub(crate) module_index: usize, | ||
pub(crate) function_index: usize, | ||
/// If the function is exported from the module or not. This is used to determine if the function name - index | ||
/// mapping should be verified. The module name - index mapping is always verified. | ||
/// | ||
/// If this is set to false then the user must make sure that the function reference will still be valid when the | ||
/// function is called. This means that the module must not be unloaded. | ||
pub(crate) exported: bool, | ||
} | ||
|
||
impl FunctionRef { | ||
pub fn invoke<H: HookSet, Param: InteropValueList, Returns: InteropValueList>( | ||
&self, | ||
runtime: &mut RuntimeInstance<H>, | ||
params: Param, | ||
) -> Result<Returns, RuntimeError> { | ||
runtime.invoke(self, params) | ||
} | ||
|
||
pub fn invoke_dynamic<H: HookSet>( | ||
&self, | ||
runtime: &mut RuntimeInstance<H>, | ||
params: Vec<Value>, | ||
ret_types: &[ValType], | ||
) -> Result<Vec<Value>, RuntimeError> { | ||
runtime.invoke_dynamic(self, params, ret_types) | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters