mirror of
https://github.com/mii443/wasmer.git
synced 2025-12-16 17:18:57 +00:00
Improved docs
This commit is contained in:
@@ -1,5 +1,12 @@
|
||||
// Native Funcs
|
||||
// use wasmer_runtime::ExportFunction;
|
||||
//! Native Functions.
|
||||
//!
|
||||
//! This module creates the helper `NativeFunc` that let us call WebAssembly
|
||||
//! functions with the native ABI, that is:
|
||||
//!
|
||||
//! ```ignore
|
||||
//! let add_one = instance.exports.get_function("func_name")?;
|
||||
//! let add_one_native: NativeFunc<i32, i32> = add_one.native().unwrap();
|
||||
//! ```
|
||||
use std::marker::PhantomData;
|
||||
|
||||
use crate::externals::function::{FunctionDefinition, WasmFunctionDefinition};
|
||||
@@ -111,6 +118,10 @@ macro_rules! impl_native_traits {
|
||||
{
|
||||
/// Call the typed func and return results.
|
||||
pub fn call(&self, $( $x: $x, )* ) -> Result<Rets, RuntimeError> {
|
||||
match self.definition {
|
||||
FunctionDefinition::Wasm(WasmFunctionDefinition {
|
||||
trampoline
|
||||
}) => {
|
||||
// TODO: when `const fn` related features mature more, we can declare a single array
|
||||
// of the correct size here.
|
||||
let mut params_list = [ $( $x.to_native().to_binary() ),* ];
|
||||
@@ -127,11 +138,6 @@ macro_rules! impl_native_traits {
|
||||
}
|
||||
rets_list.as_mut()
|
||||
};
|
||||
|
||||
match self.definition {
|
||||
FunctionDefinition::Wasm(WasmFunctionDefinition {
|
||||
trampoline
|
||||
}) => {
|
||||
unsafe {
|
||||
wasmer_call_trampoline(
|
||||
self.vmctx,
|
||||
@@ -173,7 +179,6 @@ macro_rules! impl_native_traits {
|
||||
};
|
||||
}
|
||||
|
||||
// impl_native_traits!();
|
||||
impl_native_traits!();
|
||||
impl_native_traits!(A1);
|
||||
impl_native_traits!(A1, A2);
|
||||
@@ -201,5 +206,3 @@ impl_native_traits!(
|
||||
impl_native_traits!(
|
||||
A1, A2, A3, A4, A5, A6, A7, A8, A9, A10, A11, A12, A13, A14, A15, A16, A17, A18, A19, A20
|
||||
);
|
||||
|
||||
// impl_native_traits!(A1, A2, A3);
|
||||
|
||||
@@ -1,3 +1,9 @@
|
||||
//! Ordered Resolvers are a custom kind of [`Resolver`] that retrieves
|
||||
//! `Export`s based on the index of the import, and not the module or name.
|
||||
//!
|
||||
//! This resolver is used in the Wasm-C-API as the imports are provided
|
||||
//! by index and not by module and name.
|
||||
|
||||
use std::iter::FromIterator;
|
||||
use wasmer_engine::Resolver;
|
||||
|
||||
@@ -5,8 +11,11 @@ use crate::exports::Exportable;
|
||||
use crate::Extern;
|
||||
use wasmer_runtime::Export;
|
||||
|
||||
/// An `OrderedResolver` stores all the `externs` provided to an Instance
|
||||
/// in a Vec, so we can retrieve them later based on index.
|
||||
#[derive(Clone)]
|
||||
pub struct OrderedResolver {
|
||||
/// The externs to be resolved by inddex
|
||||
externs: Vec<Extern>,
|
||||
}
|
||||
impl Resolver for OrderedResolver {
|
||||
|
||||
Reference in New Issue
Block a user