Rename NativeFunc to TypedFunction

Closes: #2915
This commit is contained in:
Wolfgang Silbermayr
2022-06-06 14:46:18 +02:00
committed by Manos Pitsidianakis
parent 59ee09bccf
commit da4e9fe617
31 changed files with 249 additions and 221 deletions

View File

@@ -22,6 +22,7 @@ Looking for changes that affect our C API? See the [C API Changelog](lib/c-api/C
- [#2836](https://github.com/wasmerio/wasmer/pull/2836) Improve TrapInformation data stored at runtime - [#2836](https://github.com/wasmerio/wasmer/pull/2836) Improve TrapInformation data stored at runtime
- [#2864](https://github.com/wasmerio/wasmer/pull/2864) `wasmer-cli`: remove wasi-experimental-io-devices from default builds - [#2864](https://github.com/wasmerio/wasmer/pull/2864) `wasmer-cli`: remove wasi-experimental-io-devices from default builds
- #2864 wasmer-cli: remove wasi-experimental-io-devices from default builds - #2864 wasmer-cli: remove wasi-experimental-io-devices from default builds
- [#2933](https://github.com/wasmerio/wasmer/pull/2933) Rename NativeFunc to TypedFunction.
### Changed ### Changed
- #2868 Removed loupe crate dependency - #2868 Removed loupe crate dependency

View File

@@ -40,7 +40,7 @@ pub fn run_basic_static_function(store: &Store, compiler_name: &str, c: &mut Cri
}; };
let instance = Instance::new(&module, &import_object).unwrap(); let instance = Instance::new(&module, &import_object).unwrap();
let dyn_f: &Function = instance.exports.get("add").unwrap(); let dyn_f: &Function = instance.exports.get("add").unwrap();
let f: NativeFunc<(i32, i32), i32> = dyn_f.native().unwrap(); let f: TypedFunction<(i32, i32), i32> = dyn_f.native().unwrap();
c.bench_function(&format!("basic static func {}", compiler_name), |b| { c.bench_function(&format!("basic static func {}", compiler_name), |b| {
b.iter(|| { b.iter(|| {
@@ -50,7 +50,7 @@ pub fn run_basic_static_function(store: &Store, compiler_name: &str, c: &mut Cri
}); });
let dyn_f_many: &Function = instance.exports.get("add20").unwrap(); let dyn_f_many: &Function = instance.exports.get("add20").unwrap();
let f_many: NativeFunc< let f_many: TypedFunction<
( (
i32, i32,
i32, i32,

View File

@@ -16,7 +16,7 @@
use anyhow::bail; use anyhow::bail;
use std::fmt; use std::fmt;
use wasmer::{imports, wat2wasm, Function, Instance, Module, NativeFunc, Store}; use wasmer::{imports, wat2wasm, Function, Instance, Module, Store, TypedFunction};
use wasmer_compiler_cranelift::Cranelift; use wasmer_compiler_cranelift::Cranelift;
use wasmer_engine_universal::Universal; use wasmer_engine_universal::Universal;
@@ -82,7 +82,7 @@ fn main() -> anyhow::Result<()> {
// //
// Get the `run` function which we'll use as our entrypoint. // Get the `run` function which we'll use as our entrypoint.
println!("Calling `run` function..."); println!("Calling `run` function...");
let run_func: NativeFunc<(i32, i32), i32> = instance.exports.get_native_function("run")?; let run_func: TypedFunction<(i32, i32), i32> = instance.exports.get_native_function("run")?;
// When we call a function it can either succeed or fail. We expect it to fail. // When we call a function it can either succeed or fail. We expect it to fail.
match run_func.call(1, 7) { match run_func.call(1, 7) {

View File

@@ -79,7 +79,7 @@ fn main() -> Result<(), Box<dyn std::error::Error>> {
assert_eq!(result.to_vec(), vec![Value::I32(3)]); assert_eq!(result.to_vec(), vec![Value::I32(3)]);
// That was fun. But what if we can get rid of the `Value`s? Well, // That was fun. But what if we can get rid of the `Value`s? Well,
// that's possible with the `NativeFunction` API. The function // that's possible with the `TypedFunction` API. The function
// will use native Rust values. // will use native Rust values.
// //
// Note that `native` takes 2 generic parameters: `Args` and // Note that `native` takes 2 generic parameters: `Args` and

View File

@@ -6,7 +6,7 @@
//! cargo run --example hello-world --release --features "cranelift" //! cargo run --example hello-world --release --features "cranelift"
//! ``` //! ```
use wasmer::{imports, wat2wasm, Function, Instance, Module, NativeFunc, Store}; use wasmer::{imports, wat2wasm, Function, Instance, Module, Store, TypedFunction};
use wasmer_compiler_cranelift::Cranelift; use wasmer_compiler_cranelift::Cranelift;
use wasmer_engine_universal::Universal; use wasmer_engine_universal::Universal;
@@ -73,11 +73,11 @@ fn main() -> anyhow::Result<()> {
// and is ready to execute. // and is ready to execute.
let instance = Instance::new(&module, &import_object)?; let instance = Instance::new(&module, &import_object)?;
// We get the `NativeFunc` with no parameters and no results from the instance. // We get the `TypedFunction` with no parameters and no results from the instance.
// //
// Recall that the Wasm module exported a function named "run", this is getting // Recall that the Wasm module exported a function named "run", this is getting
// that exported function from the `Instance`. // that exported function from the `Instance`.
let run_func: NativeFunc<(), ()> = instance.exports.get_native_function("run")?; let run_func: TypedFunction<(), ()> = instance.exports.get_native_function("run")?;
// Finally, we call our exported Wasm function which will call our "say_hello" // Finally, we call our exported Wasm function which will call our "say_hello"
// function and return. // function and return.

View File

@@ -15,7 +15,7 @@
//! Ready? //! Ready?
use std::mem; use std::mem;
use wasmer::{imports, wat2wasm, Bytes, Instance, Module, NativeFunc, Pages, Store}; use wasmer::{imports, wat2wasm, Bytes, Instance, Module, Pages, Store, TypedFunction};
use wasmer_compiler_cranelift::Cranelift; use wasmer_compiler_cranelift::Cranelift;
use wasmer_engine_universal::Universal; use wasmer_engine_universal::Universal;
@@ -73,9 +73,9 @@ fn main() -> anyhow::Result<()> {
// The module exports some utility functions, let's get them. // The module exports some utility functions, let's get them.
// //
// These function will be used later in this example. // These function will be used later in this example.
let mem_size: NativeFunc<(), i32> = instance.exports.get_native_function("mem_size")?; let mem_size: TypedFunction<(), i32> = instance.exports.get_native_function("mem_size")?;
let get_at: NativeFunc<i32, i32> = instance.exports.get_native_function("get_at")?; let get_at: TypedFunction<i32, i32> = instance.exports.get_native_function("get_at")?;
let set_at: NativeFunc<(i32, i32), ()> = instance.exports.get_native_function("set_at")?; let set_at: TypedFunction<(i32, i32), ()> = instance.exports.get_native_function("set_at")?;
let memory = instance.exports.get_memory("memory")?; let memory = instance.exports.get_memory("memory")?;
// We now have an instance ready to be used. // We now have an instance ready to be used.

View File

@@ -1,5 +1,5 @@
use wasmer::{ use wasmer::{
imports, wat2wasm, Function, Instance, Module, NativeFunc, Store, TableType, Type, Value, imports, wat2wasm, Function, Instance, Module, Store, TableType, Type, TypedFunction, Value,
}; };
use wasmer_compiler_cranelift::Cranelift; use wasmer_compiler_cranelift::Cranelift;
use wasmer_engine_universal::Universal; use wasmer_engine_universal::Universal;
@@ -61,7 +61,7 @@ fn main() -> anyhow::Result<()> {
// We get our function that calls (i32, i32) -> i32 functions via table. // We get our function that calls (i32, i32) -> i32 functions via table.
// The first argument is the table index and the next 2 are the 2 arguments // The first argument is the table index and the next 2 are the 2 arguments
// to be passed to the function found in the table. // to be passed to the function found in the table.
let call_via_table: NativeFunc<(i32, i32, i32), i32> = let call_via_table: TypedFunction<(i32, i32, i32), i32> =
instance.exports.get_native_function("call_callback")?; instance.exports.get_native_function("call_callback")?;
// And then call it with table index 1 and arguments 2 and 7. // And then call it with table index 1 and arguments 2 and 7.

View File

@@ -28,7 +28,7 @@ impl From<ExportError> for HostEnvInitError {
/// This trait can be derived like so: /// This trait can be derived like so:
/// ///
/// ``` /// ```
/// use wasmer::{WasmerEnv, LazyInit, Memory, NativeFunc}; /// use wasmer::{WasmerEnv, LazyInit, Memory, TypedFunction};
/// ///
/// #[derive(WasmerEnv, Clone)] /// #[derive(WasmerEnv, Clone)]
/// pub struct MyEnvWithNoInstanceData { /// pub struct MyEnvWithNoInstanceData {
@@ -41,7 +41,7 @@ impl From<ExportError> for HostEnvInitError {
/// #[wasmer(export)] /// #[wasmer(export)]
/// memory: LazyInit<Memory>, /// memory: LazyInit<Memory>,
/// #[wasmer(export(name = "real_name"))] /// #[wasmer(export(name = "real_name"))]
/// func: LazyInit<NativeFunc<(i32, i32), i32>>, /// func: LazyInit<TypedFunction<(i32, i32), i32>>,
/// #[wasmer(export(optional = true, alias = "memory2", alias = "_memory2"))] /// #[wasmer(export(optional = true, alias = "memory2", alias = "_memory2"))]
/// optional_memory: LazyInit<Memory>, /// optional_memory: LazyInit<Memory>,
/// } /// }

View File

@@ -1,6 +1,6 @@
use crate::js::export::Export; use crate::js::export::Export;
use crate::js::externals::{Extern, Function, Global, Memory, Table}; use crate::js::externals::{Extern, Function, Global, Memory, Table};
use crate::js::native::NativeFunc; use crate::js::native::TypedFunction;
use crate::js::WasmTypeList; use crate::js::WasmTypeList;
use indexmap::IndexMap; use indexmap::IndexMap;
use std::fmt; use std::fmt;
@@ -134,11 +134,11 @@ impl Exports {
self.get(name) self.get(name)
} }
/// Get an export as a `NativeFunc`. /// Get an export as a `TypedFunction`.
pub fn get_native_function<Args, Rets>( pub fn get_native_function<Args, Rets>(
&self, &self,
name: &str, name: &str,
) -> Result<NativeFunc<Args, Rets>, ExportError> ) -> Result<TypedFunction<Args, Rets>, ExportError>
where where
Args: WasmTypeList, Args: WasmTypeList,
Rets: WasmTypeList, Rets: WasmTypeList,
@@ -309,7 +309,7 @@ pub trait Exportable<'a>: Sized {
} }
/// A trait for accessing exports (like [`Exportable`]) but it takes generic /// A trait for accessing exports (like [`Exportable`]) but it takes generic
/// `Args` and `Rets` parameters so that `NativeFunc` can be accessed directly /// `Args` and `Rets` parameters so that `TypedFunction` can be accessed directly
/// as well. /// as well.
pub trait ExportableWithGenerics<'a, Args: WasmTypeList, Rets: WasmTypeList>: Sized { pub trait ExportableWithGenerics<'a, Args: WasmTypeList, Rets: WasmTypeList>: Sized {
/// Get an export with the given generics. /// Get an export with the given generics.

View File

@@ -3,8 +3,8 @@ use crate::js::externals::Extern;
use crate::js::store::Store; use crate::js::store::Store;
use crate::js::types::{param_from_js, AsJs /* ValFuncRef */, Val}; use crate::js::types::{param_from_js, AsJs /* ValFuncRef */, Val};
use crate::js::FunctionType; use crate::js::FunctionType;
use crate::js::NativeFunc;
use crate::js::RuntimeError; use crate::js::RuntimeError;
use crate::js::TypedFunction;
use crate::js::WasmerEnv; use crate::js::WasmerEnv;
pub use inner::{FromToNativeWasmType, HostFunction, WasmTypeList, WithEnv, WithoutEnv}; pub use inner::{FromToNativeWasmType, HostFunction, WasmTypeList, WithEnv, WithoutEnv};
use js_sys::{Array, Function as JSFunction}; use js_sys::{Array, Function as JSFunction};
@@ -490,7 +490,7 @@ impl Function {
} }
/// Transform this WebAssembly function into a function with the /// Transform this WebAssembly function into a function with the
/// native ABI. See [`NativeFunc`] to learn more. /// native ABI. See [`TypedFunction`] to learn more.
/// ///
/// # Examples /// # Examples
/// ///
@@ -564,7 +564,7 @@ impl Function {
/// // This results in an error: `RuntimeError` /// // This results in an error: `RuntimeError`
/// let sum_native = sum.native::<(i32, i32), i64>().unwrap(); /// let sum_native = sum.native::<(i32, i32), i64>().unwrap();
/// ``` /// ```
pub fn native<Args, Rets>(&self) -> Result<NativeFunc<Args, Rets>, RuntimeError> pub fn native<Args, Rets>(&self) -> Result<TypedFunction<Args, Rets>, RuntimeError>
where where
Args: WasmTypeList, Args: WasmTypeList,
Rets: WasmTypeList, Rets: WasmTypeList,
@@ -597,7 +597,10 @@ impl Function {
} }
} }
Ok(NativeFunc::new(self.store.clone(), self.exported.clone())) Ok(TypedFunction::new(
self.store.clone(),
self.exported.clone(),
))
} }
#[track_caller] #[track_caller]

View File

@@ -60,7 +60,7 @@ pub use crate::js::instance::{Instance, InstantiationError};
pub use crate::js::js_import_object::JsImportObject; pub use crate::js::js_import_object::JsImportObject;
pub use crate::js::mem_access::{MemoryAccessError, WasmRef, WasmSlice, WasmSliceIter}; pub use crate::js::mem_access::{MemoryAccessError, WasmRef, WasmSlice, WasmSliceIter};
pub use crate::js::module::{Module, ModuleTypeHints}; pub use crate::js::module::{Module, ModuleTypeHints};
pub use crate::js::native::NativeFunc; pub use crate::js::native::TypedFunction;
pub use crate::js::ptr::{Memory32, Memory64, MemorySize, WasmPtr, WasmPtr64}; pub use crate::js::ptr::{Memory32, Memory64, MemorySize, WasmPtr, WasmPtr64};
pub use crate::js::trap::RuntimeError; pub use crate::js::trap::RuntimeError;
@@ -82,3 +82,10 @@ pub use wat::parse_bytes as wat2wasm;
/// Version number of this crate. /// Version number of this crate.
pub const VERSION: &str = env!("CARGO_PKG_VERSION"); pub const VERSION: &str = env!("CARGO_PKG_VERSION");
/// This type is deprecated, it has been replaced by TypedFunction.
#[deprecated(
since = "3.0.0",
note = "NativeFunc has been replaced by TypedFunction"
)]
pub type NativeFunc<Args = (), Rets = ()> = TypedFunction<Args, Rets>;

View File

@@ -1,11 +1,11 @@
//! Native Functions. //! Native Functions.
//! //!
//! This module creates the helper `NativeFunc` that let us call WebAssembly //! This module creates the helper `TypedFunction` that let us call WebAssembly
//! functions with the native ABI, that is: //! functions with the native ABI, that is:
//! //!
//! ```ignore //! ```ignore
//! let add_one = instance.exports.get_function("function_name")?; //! let add_one = instance.exports.get_function("function_name")?;
//! let add_one_native: NativeFunc<i32, i32> = add_one.native().unwrap(); //! let add_one_native: TypedFunction<i32, i32> = add_one.native().unwrap();
//! ``` //! ```
use std::marker::PhantomData; use std::marker::PhantomData;
@@ -21,15 +21,15 @@ use wasmer_types::NativeWasmType;
/// A WebAssembly function that can be called natively /// A WebAssembly function that can be called natively
/// (using the Native ABI). /// (using the Native ABI).
#[derive(Clone)] #[derive(Clone)]
pub struct NativeFunc<Args = (), Rets = ()> { pub struct TypedFunction<Args = (), Rets = ()> {
store: Store, store: Store,
exported: VMFunction, exported: VMFunction,
_phantom: PhantomData<(Args, Rets)>, _phantom: PhantomData<(Args, Rets)>,
} }
unsafe impl<Args, Rets> Send for NativeFunc<Args, Rets> {} unsafe impl<Args, Rets> Send for TypedFunction<Args, Rets> {}
impl<Args, Rets> NativeFunc<Args, Rets> impl<Args, Rets> TypedFunction<Args, Rets>
where where
Args: WasmTypeList, Args: WasmTypeList,
Rets: WasmTypeList, Rets: WasmTypeList,
@@ -43,22 +43,22 @@ where
} }
} }
impl<Args, Rets> From<&NativeFunc<Args, Rets>> for VMFunction impl<Args, Rets> From<&TypedFunction<Args, Rets>> for VMFunction
where where
Args: WasmTypeList, Args: WasmTypeList,
Rets: WasmTypeList, Rets: WasmTypeList,
{ {
fn from(other: &NativeFunc<Args, Rets>) -> Self { fn from(other: &TypedFunction<Args, Rets>) -> Self {
other.exported.clone() other.exported.clone()
} }
} }
impl<Args, Rets> From<NativeFunc<Args, Rets>> for Function impl<Args, Rets> From<TypedFunction<Args, Rets>> for Function
where where
Args: WasmTypeList, Args: WasmTypeList,
Rets: WasmTypeList, Rets: WasmTypeList,
{ {
fn from(other: NativeFunc<Args, Rets>) -> Self { fn from(other: TypedFunction<Args, Rets>) -> Self {
Self { Self {
store: other.store, store: other.store,
exported: other.exported, exported: other.exported,
@@ -69,7 +69,7 @@ where
macro_rules! impl_native_traits { macro_rules! impl_native_traits {
( $( $x:ident ),* ) => { ( $( $x:ident ),* ) => {
#[allow(unused_parens, non_snake_case)] #[allow(unused_parens, non_snake_case)]
impl<$( $x , )* Rets> NativeFunc<( $( $x ),* ), Rets> impl<$( $x , )* Rets> TypedFunction<( $( $x ),* ), Rets>
where where
$( $x: FromToNativeWasmType, )* $( $x: FromToNativeWasmType, )*
Rets: WasmTypeList, Rets: WasmTypeList,
@@ -107,7 +107,7 @@ macro_rules! impl_native_traits {
} }
#[allow(unused_parens)] #[allow(unused_parens)]
impl<'a, $( $x, )* Rets> crate::js::exports::ExportableWithGenerics<'a, ($( $x ),*), Rets> for NativeFunc<( $( $x ),* ), Rets> impl<'a, $( $x, )* Rets> crate::js::exports::ExportableWithGenerics<'a, ($( $x ),*), Rets> for TypedFunction<( $( $x ),* ), Rets>
where where
$( $x: FromToNativeWasmType, )* $( $x: FromToNativeWasmType, )*
Rets: WasmTypeList, Rets: WasmTypeList,

View File

@@ -172,11 +172,11 @@
//! from any instance via `instance.exports`: //! from any instance via `instance.exports`:
//! //!
//! ``` //! ```
//! # use wasmer::{imports, Instance, Function, Memory, NativeFunc}; //! # use wasmer::{imports, Instance, Function, Memory, TypedFunction};
//! # fn exports_example(instance: &Instance) -> anyhow::Result<()> { //! # fn exports_example(instance: &Instance) -> anyhow::Result<()> {
//! let memory = instance.exports.get_memory("memory")?; //! let memory = instance.exports.get_memory("memory")?;
//! let memory: &Memory = instance.exports.get("some_other_memory")?; //! let memory: &Memory = instance.exports.get("some_other_memory")?;
//! let add: NativeFunc<(i32, i32), i32> = instance.exports.get_native_function("add")?; //! let add: TypedFunction<(i32, i32), i32> = instance.exports.get_native_function("add")?;
//! let result = add.call(5, 37)?; //! let result = add.call(5, 37)?;
//! assert_eq!(result, 42); //! assert_eq!(result, 42);
//! # Ok(()) //! # Ok(())
@@ -215,7 +215,7 @@
//! //!
//! In the `wasmer` API we support functions which take their arguments and //! In the `wasmer` API we support functions which take their arguments and
//! return their results dynamically, [`Function`], and functions which //! return their results dynamically, [`Function`], and functions which
//! take their arguments and return their results statically, [`NativeFunc`]. //! take their arguments and return their results statically, [`TypedFunction`].
//! //!
//! ### Memories //! ### Memories
//! //!

View File

@@ -28,7 +28,7 @@ impl From<ExportError> for HostEnvInitError {
/// This trait can be derived like so: /// This trait can be derived like so:
/// ///
/// ``` /// ```
/// use wasmer::{WasmerEnv, LazyInit, Memory, NativeFunc}; /// use wasmer::{WasmerEnv, LazyInit, Memory, TypedFunction};
/// ///
/// #[derive(WasmerEnv, Clone)] /// #[derive(WasmerEnv, Clone)]
/// pub struct MyEnvWithNoInstanceData { /// pub struct MyEnvWithNoInstanceData {
@@ -41,7 +41,7 @@ impl From<ExportError> for HostEnvInitError {
/// #[wasmer(export)] /// #[wasmer(export)]
/// memory: LazyInit<Memory>, /// memory: LazyInit<Memory>,
/// #[wasmer(export(name = "real_name"))] /// #[wasmer(export(name = "real_name"))]
/// func: LazyInit<NativeFunc<(i32, i32), i32>>, /// func: LazyInit<TypedFunction<(i32, i32), i32>>,
/// #[wasmer(export(optional = true, alias = "memory2", alias = "_memory2"))] /// #[wasmer(export(optional = true, alias = "memory2", alias = "_memory2"))]
/// optional_memory: LazyInit<Memory>, /// optional_memory: LazyInit<Memory>,
/// } /// }

View File

@@ -1,5 +1,5 @@
use crate::sys::externals::{Extern, Function, Global, Memory, Table}; use crate::sys::externals::{Extern, Function, Global, Memory, Table};
use crate::sys::native::NativeFunc; use crate::sys::native::TypedFunction;
use crate::sys::WasmTypeList; use crate::sys::WasmTypeList;
use indexmap::IndexMap; use indexmap::IndexMap;
use std::fmt; use std::fmt;
@@ -134,11 +134,11 @@ impl Exports {
self.get(name) self.get(name)
} }
/// Get an export as a `NativeFunc`. /// Get an export as a `TypedFunction`.
pub fn get_native_function<Args, Rets>( pub fn get_native_function<Args, Rets>(
&self, &self,
name: &str, name: &str,
) -> Result<NativeFunc<Args, Rets>, ExportError> ) -> Result<TypedFunction<Args, Rets>, ExportError>
where where
Args: WasmTypeList, Args: WasmTypeList,
Rets: WasmTypeList, Rets: WasmTypeList,
@@ -315,7 +315,7 @@ pub trait Exportable<'a>: Sized {
} }
/// A trait for accessing exports (like [`Exportable`]) but it takes generic /// A trait for accessing exports (like [`Exportable`]) but it takes generic
/// `Args` and `Rets` parameters so that `NativeFunc` can be accessed directly /// `Args` and `Rets` parameters so that `TypedFunction` can be accessed directly
/// as well. /// as well.
pub trait ExportableWithGenerics<'a, Args: WasmTypeList, Rets: WasmTypeList>: Sized { pub trait ExportableWithGenerics<'a, Args: WasmTypeList, Rets: WasmTypeList>: Sized {
/// Get an export with the given generics. /// Get an export with the given generics.

View File

@@ -3,8 +3,8 @@ use crate::sys::externals::Extern;
use crate::sys::store::Store; use crate::sys::store::Store;
use crate::sys::types::{Val, ValFuncRef}; use crate::sys::types::{Val, ValFuncRef};
use crate::sys::FunctionType; use crate::sys::FunctionType;
use crate::sys::NativeFunc;
use crate::sys::RuntimeError; use crate::sys::RuntimeError;
use crate::sys::TypedFunction;
use crate::sys::WasmerEnv; use crate::sys::WasmerEnv;
pub use inner::{FromToNativeWasmType, HostFunction, WasmTypeList, WithEnv, WithoutEnv}; pub use inner::{FromToNativeWasmType, HostFunction, WasmTypeList, WithEnv, WithoutEnv};
@@ -561,7 +561,7 @@ impl Function {
} }
/// Transform this WebAssembly function into a function with the /// Transform this WebAssembly function into a function with the
/// native ABI. See [`NativeFunc`] to learn more. /// native ABI. See [`TypedFunction`] to learn more.
/// ///
/// # Examples /// # Examples
/// ///
@@ -635,7 +635,7 @@ impl Function {
/// // This results in an error: `RuntimeError` /// // This results in an error: `RuntimeError`
/// let sum_native = sum.native::<(i32, i32), i64>().unwrap(); /// let sum_native = sum.native::<(i32, i32), i64>().unwrap();
/// ``` /// ```
pub fn native<Args, Rets>(&self) -> Result<NativeFunc<Args, Rets>, RuntimeError> pub fn native<Args, Rets>(&self) -> Result<TypedFunction<Args, Rets>, RuntimeError>
where where
Args: WasmTypeList, Args: WasmTypeList,
Rets: WasmTypeList, Rets: WasmTypeList,
@@ -668,7 +668,10 @@ impl Function {
} }
} }
Ok(NativeFunc::new(self.store.clone(), self.exported.clone())) Ok(TypedFunction::new(
self.store.clone(),
self.exported.clone(),
))
} }
#[track_caller] #[track_caller]

View File

@@ -35,7 +35,8 @@ pub use crate::sys::imports::Imports;
pub use crate::sys::instance::{Instance, InstantiationError}; pub use crate::sys::instance::{Instance, InstantiationError};
pub use crate::sys::mem_access::{MemoryAccessError, WasmRef, WasmSlice, WasmSliceIter}; pub use crate::sys::mem_access::{MemoryAccessError, WasmRef, WasmSlice, WasmSliceIter};
pub use crate::sys::module::Module; pub use crate::sys::module::Module;
pub use crate::sys::native::NativeFunc; pub use crate::sys::native::TypedFunction;
pub use crate::sys::ptr::{Memory32, Memory64, MemorySize, WasmPtr, WasmPtr64}; pub use crate::sys::ptr::{Memory32, Memory64, MemorySize, WasmPtr, WasmPtr64};
pub use crate::sys::store::{Store, StoreObject}; pub use crate::sys::store::{Store, StoreObject};
pub use crate::sys::tunables::BaseTunables; pub use crate::sys::tunables::BaseTunables;
@@ -126,3 +127,10 @@ pub type JIT = Universal;
#[cfg(feature = "native")] #[cfg(feature = "native")]
#[deprecated(since = "2.0.0", note = "Please use the `native` feature instead")] #[deprecated(since = "2.0.0", note = "Please use the `native` feature instead")]
pub type Native = Dylib; pub type Native = Dylib;
/// This type is deprecated, it has been replaced by TypedFunction.
#[deprecated(
since = "3.0.0",
note = "NativeFunc has been replaced by TypedFunction"
)]
pub type NativeFunc<Args = (), Rets = ()> = TypedFunction<Args, Rets>;

View File

@@ -1,11 +1,11 @@
//! Native Functions. //! Native Functions.
//! //!
//! This module creates the helper `NativeFunc` that let us call WebAssembly //! This module creates the helper `TypedFunction` that let us call WebAssembly
//! functions with the native ABI, that is: //! functions with the native ABI, that is:
//! //!
//! ```ignore //! ```ignore
//! let add_one = instance.exports.get_function("function_name")?; //! let add_one = instance.exports.get_function("function_name")?;
//! let add_one_native: NativeFunc<i32, i32> = add_one.native().unwrap(); //! let add_one_native: TypedFunction<i32, i32> = add_one.native().unwrap();
//! ``` //! ```
use std::marker::PhantomData; use std::marker::PhantomData;
@@ -18,15 +18,15 @@ use wasmer_vm::{VMDynamicFunctionContext, VMFunctionBody, VMFunctionEnvironment,
/// A WebAssembly function that can be called natively /// A WebAssembly function that can be called natively
/// (using the Native ABI). /// (using the Native ABI).
pub struct NativeFunc<Args = (), Rets = ()> { pub struct TypedFunction<Args = (), Rets = ()> {
store: Store, store: Store,
exported: ExportFunction, exported: ExportFunction,
_phantom: PhantomData<(Args, Rets)>, _phantom: PhantomData<(Args, Rets)>,
} }
unsafe impl<Args, Rets> Send for NativeFunc<Args, Rets> {} unsafe impl<Args, Rets> Send for TypedFunction<Args, Rets> {}
impl<Args, Rets> NativeFunc<Args, Rets> impl<Args, Rets> TypedFunction<Args, Rets>
where where
Args: WasmTypeList, Args: WasmTypeList,
Rets: WasmTypeList, Rets: WasmTypeList,
@@ -69,12 +69,12 @@ where
} }
/* /*
impl<Args, Rets> From<&NativeFunc<Args, Rets>> for VMFunction impl<Args, Rets> From<&TypedFunction<Args, Rets>> for VMFunction
where where
Args: WasmTypeList, Args: WasmTypeList,
Rets: WasmTypeList, Rets: WasmTypeList,
{ {
fn from(other: &NativeFunc<Args, Rets>) -> Self { fn from(other: &TypedFunction<Args, Rets>) -> Self {
let signature = FunctionType::new(Args::wasm_types(), Rets::wasm_types()); let signature = FunctionType::new(Args::wasm_types(), Rets::wasm_types());
Self { Self {
address: other.address, address: other.address,
@@ -87,7 +87,7 @@ where
} }
}*/ }*/
impl<Args: WasmTypeList, Rets: WasmTypeList> Clone for NativeFunc<Args, Rets> { impl<Args: WasmTypeList, Rets: WasmTypeList> Clone for TypedFunction<Args, Rets> {
fn clone(&self) -> Self { fn clone(&self) -> Self {
let mut exported = self.exported.clone(); let mut exported = self.exported.clone();
exported.vm_function.upgrade_instance_ref().unwrap(); exported.vm_function.upgrade_instance_ref().unwrap();
@@ -100,22 +100,22 @@ impl<Args: WasmTypeList, Rets: WasmTypeList> Clone for NativeFunc<Args, Rets> {
} }
} }
impl<Args, Rets> From<&NativeFunc<Args, Rets>> for ExportFunction impl<Args, Rets> From<&TypedFunction<Args, Rets>> for ExportFunction
where where
Args: WasmTypeList, Args: WasmTypeList,
Rets: WasmTypeList, Rets: WasmTypeList,
{ {
fn from(other: &NativeFunc<Args, Rets>) -> Self { fn from(other: &TypedFunction<Args, Rets>) -> Self {
other.exported.clone() other.exported.clone()
} }
} }
impl<Args, Rets> From<NativeFunc<Args, Rets>> for Function impl<Args, Rets> From<TypedFunction<Args, Rets>> for Function
where where
Args: WasmTypeList, Args: WasmTypeList,
Rets: WasmTypeList, Rets: WasmTypeList,
{ {
fn from(other: NativeFunc<Args, Rets>) -> Self { fn from(other: TypedFunction<Args, Rets>) -> Self {
Self { Self {
store: other.store, store: other.store,
exported: other.exported, exported: other.exported,
@@ -126,7 +126,7 @@ where
macro_rules! impl_native_traits { macro_rules! impl_native_traits {
( $( $x:ident ),* ) => { ( $( $x:ident ),* ) => {
#[allow(unused_parens, non_snake_case)] #[allow(unused_parens, non_snake_case)]
impl<$( $x , )* Rets> NativeFunc<( $( $x ),* ), Rets> impl<$( $x , )* Rets> TypedFunction<( $( $x ),* ), Rets>
where where
$( $x: FromToNativeWasmType, )* $( $x: FromToNativeWasmType, )*
Rets: WasmTypeList, Rets: WasmTypeList,
@@ -223,7 +223,7 @@ macro_rules! impl_native_traits {
} }
#[allow(unused_parens)] #[allow(unused_parens)]
impl<'a, $( $x, )* Rets> crate::sys::exports::ExportableWithGenerics<'a, ($( $x ),*), Rets> for NativeFunc<( $( $x ),* ), Rets> impl<'a, $( $x, )* Rets> crate::sys::exports::ExportableWithGenerics<'a, ($( $x ),*), Rets> for TypedFunction<( $( $x ),* ), Rets>
where where
$( $x: FromToNativeWasmType, )* $( $x: FromToNativeWasmType, )*
Rets: WasmTypeList, Rets: WasmTypeList,

View File

@@ -337,32 +337,32 @@ mod js {
fn native_function_works() { fn native_function_works() {
let store = Store::default(); let store = Store::default();
let function = Function::new_native(&store, || {}); let function = Function::new_native(&store, || {});
let native_function: NativeFunc<(), ()> = function.native().unwrap(); let typed_function: TypedFunction<(), ()> = function.native().unwrap();
let result = native_function.call(); let result = typed_function.call();
assert!(result.is_ok()); assert!(result.is_ok());
let function = Function::new_native(&store, |a: i32| -> i32 { a + 1 }); let function = Function::new_native(&store, |a: i32| -> i32 { a + 1 });
let native_function: NativeFunc<i32, i32> = function.native().unwrap(); let typed_function: TypedFunction<i32, i32> = function.native().unwrap();
assert_eq!(native_function.call(3).unwrap(), 4); assert_eq!(typed_function.call(3).unwrap(), 4);
// fn rust_abi(a: i32, b: i64, c: f32, d: f64) -> u64 { // fn rust_abi(a: i32, b: i64, c: f32, d: f64) -> u64 {
// (a as u64 * 1000) + (b as u64 * 100) + (c as u64 * 10) + (d as u64) // (a as u64 * 1000) + (b as u64 * 100) + (c as u64 * 10) + (d as u64)
// } // }
// let function = Function::new_native(&store, rust_abi); // let function = Function::new_native(&store, rust_abi);
// let native_function: NativeFunc<(i32, i64, f32, f64), u64> = function.native().unwrap(); // let typed_function: TypedFunction<(i32, i64, f32, f64), u64> = function.native().unwrap();
// assert_eq!(native_function.call(8, 4, 1.5, 5.).unwrap(), 8415); // assert_eq!(typed_function.call(8, 4, 1.5, 5.).unwrap(), 8415);
let function = Function::new_native(&store, || -> i32 { 1 }); let function = Function::new_native(&store, || -> i32 { 1 });
let native_function: NativeFunc<(), i32> = function.native().unwrap(); let typed_function: TypedFunction<(), i32> = function.native().unwrap();
assert_eq!(native_function.call().unwrap(), 1); assert_eq!(typed_function.call().unwrap(), 1);
let function = Function::new_native(&store, |_a: i32| {}); let function = Function::new_native(&store, |_a: i32| {});
let native_function: NativeFunc<i32, ()> = function.native().unwrap(); let typed_function: TypedFunction<i32, ()> = function.native().unwrap();
assert!(native_function.call(4).is_ok()); assert!(typed_function.call(4).is_ok());
// let function = Function::new_native(&store, || -> (i32, i64, f32, f64) { (1, 2, 3.0, 4.0) }); // let function = Function::new_native(&store, || -> (i32, i64, f32, f64) { (1, 2, 3.0, 4.0) });
// let native_function: NativeFunc<(), (i32, i64, f32, f64)> = function.native().unwrap(); // let typed_function: TypedFunction<(), (i32, i64, f32, f64)> = function.native().unwrap();
// assert_eq!(native_function.call().unwrap(), (1, 2, 3.0, 4.0)); // assert_eq!(typed_function.call().unwrap(), (1, 2, 3.0, 4.0));
} }
#[wasm_bindgen_test] #[wasm_bindgen_test]

View File

@@ -609,7 +609,7 @@ mod js {
}; };
let instance = Instance::new(&module, &import_object).unwrap(); let instance = Instance::new(&module, &import_object).unwrap();
let add_one: NativeFunc<i32, i32> = let add_one: TypedFunction<i32, i32> =
instance.exports.get_native_function("add_one").unwrap(); instance.exports.get_native_function("add_one").unwrap();
assert_eq!(add_one.call(1), Ok(2)); assert_eq!(add_one.call(1), Ok(2));
} }
@@ -645,7 +645,7 @@ mod js {
}; };
let instance = Instance::new(&module, &import_object).unwrap(); let instance = Instance::new(&module, &import_object).unwrap();
let run_func: NativeFunc<(i32, i32), i32> = let run_func: TypedFunction<(i32, i32), i32> =
instance.exports.get_native_function("run").unwrap(); instance.exports.get_native_function("run").unwrap();
assert!(run_func.call(1, 7).is_err(), "Expected early termination",); assert!(run_func.call(1, 7).is_err(), "Expected early termination",);
@@ -724,7 +724,7 @@ mod js {
} }
} }
let run_func: NativeFunc<(i32, i32), i32> = let run_func: TypedFunction<(i32, i32), i32> =
instance.exports.get_native_function("run").unwrap(); instance.exports.get_native_function("run").unwrap();
test_result(run_func.call(1, 7)); test_result(run_func.call(1, 7));

View File

@@ -249,35 +249,35 @@ mod js {
// }; // };
// let instance = Instance::new(&module, &imports).unwrap(); // let instance = Instance::new(&module, &imports).unwrap();
// let f1: NativeFunc<(), ()> = instance // let f1: TypedFunction<(), ()> = instance
// .exports // .exports
// .get_native_function("call_host_func1") // .get_native_function("call_host_func1")
// .unwrap(); // .unwrap();
// let f2: NativeFunc<(), ()> = instance // let f2: TypedFunction<(), ()> = instance
// .exports // .exports
// .get_native_function("call_host_func2") // .get_native_function("call_host_func2")
// .unwrap(); // .unwrap();
// let f3: NativeFunc<(), ()> = instance // let f3: TypedFunction<(), ()> = instance
// .exports // .exports
// .get_native_function("call_host_func3") // .get_native_function("call_host_func3")
// .unwrap(); // .unwrap();
// let f4: NativeFunc<(), ()> = instance // let f4: TypedFunction<(), ()> = instance
// .exports // .exports
// .get_native_function("call_host_func4") // .get_native_function("call_host_func4")
// .unwrap(); // .unwrap();
// let f5: NativeFunc<(), ()> = instance // let f5: TypedFunction<(), ()> = instance
// .exports // .exports
// .get_native_function("call_host_func5") // .get_native_function("call_host_func5")
// .unwrap(); // .unwrap();
// let f6: NativeFunc<(), ()> = instance // let f6: TypedFunction<(), ()> = instance
// .exports // .exports
// .get_native_function("call_host_func6") // .get_native_function("call_host_func6")
// .unwrap(); // .unwrap();
// let f7: NativeFunc<(), ()> = instance // let f7: TypedFunction<(), ()> = instance
// .exports // .exports
// .get_native_function("call_host_func7") // .get_native_function("call_host_func7")
// .unwrap(); // .unwrap();
// let f8: NativeFunc<(), ()> = instance // let f8: TypedFunction<(), ()> = instance
// .exports // .exports
// .get_native_function("call_host_func8") // .get_native_function("call_host_func8")
// .unwrap(); // .unwrap();

View File

@@ -89,7 +89,7 @@ mod sys {
} }
fn is_native_function_instance_ref_strong<Args, Rets>( fn is_native_function_instance_ref_strong<Args, Rets>(
f: &NativeFunc<Args, Rets>, f: &TypedFunction<Args, Rets>,
) -> Option<bool> ) -> Option<bool>
where where
Args: WasmTypeList, Args: WasmTypeList,
@@ -120,7 +120,7 @@ mod sys {
assert_eq!(is_memory_instance_ref_strong(&mem), Some(false)); assert_eq!(is_memory_instance_ref_strong(&mem), Some(false));
}; };
let f: NativeFunc<(), ()> = { let f: TypedFunction<(), ()> = {
let store = Store::default(); let store = Store::default();
let module = Module::new(&store, MEM_WAT)?; let module = Module::new(&store, MEM_WAT)?;
let env = MemEnv::default(); let env = MemEnv::default();
@@ -139,7 +139,7 @@ mod sys {
assert_eq!(is_memory_instance_ref_strong(&mem), Some(true)); assert_eq!(is_memory_instance_ref_strong(&mem), Some(true));
} }
let f: NativeFunc<(), ()> = instance.exports.get_native_function("call_host_fn")?; let f: TypedFunction<(), ()> = instance.exports.get_native_function("call_host_fn")?;
f.call()?; f.call()?;
f f
}; };
@@ -164,7 +164,7 @@ mod sys {
assert_eq!(is_global_instance_ref_strong(&global), Some(false)); assert_eq!(is_global_instance_ref_strong(&global), Some(false));
}; };
let f: NativeFunc<(), ()> = { let f: TypedFunction<(), ()> = {
let store = Store::default(); let store = Store::default();
let module = Module::new(&store, GLOBAL_WAT)?; let module = Module::new(&store, GLOBAL_WAT)?;
let env = GlobalEnv::default(); let env = GlobalEnv::default();
@@ -183,7 +183,7 @@ mod sys {
assert_eq!(is_global_instance_ref_strong(&global), Some(true)); assert_eq!(is_global_instance_ref_strong(&global), Some(true));
} }
let f: NativeFunc<(), ()> = instance.exports.get_native_function("call_host_fn")?; let f: TypedFunction<(), ()> = instance.exports.get_native_function("call_host_fn")?;
f.call()?; f.call()?;
f f
}; };
@@ -208,7 +208,7 @@ mod sys {
assert_eq!(is_table_instance_ref_strong(&table), Some(false)); assert_eq!(is_table_instance_ref_strong(&table), Some(false));
}; };
let f: NativeFunc<(), ()> = { let f: TypedFunction<(), ()> = {
let store = Store::default(); let store = Store::default();
let module = Module::new(&store, TABLE_WAT)?; let module = Module::new(&store, TABLE_WAT)?;
let env = TableEnv::default(); let env = TableEnv::default();
@@ -227,7 +227,7 @@ mod sys {
assert_eq!(is_table_instance_ref_strong(&table), Some(true)); assert_eq!(is_table_instance_ref_strong(&table), Some(true));
} }
let f: NativeFunc<(), ()> = instance.exports.get_native_function("call_host_fn")?; let f: TypedFunction<(), ()> = instance.exports.get_native_function("call_host_fn")?;
f.call()?; f.call()?;
f f
}; };
@@ -252,7 +252,7 @@ mod sys {
assert_eq!(is_function_instance_ref_strong(&function), Some(false)); assert_eq!(is_function_instance_ref_strong(&function), Some(false));
}; };
let f: NativeFunc<(), ()> = { let f: TypedFunction<(), ()> = {
let store = Store::default(); let store = Store::default();
let module = Module::new(&store, FUNCTION_WAT)?; let module = Module::new(&store, FUNCTION_WAT)?;
let env = FunctionEnv::default(); let env = FunctionEnv::default();
@@ -271,7 +271,7 @@ mod sys {
assert_eq!(is_function_instance_ref_strong(&function), Some(true)); assert_eq!(is_function_instance_ref_strong(&function), Some(true));
} }
let f: NativeFunc<(), ()> = instance.exports.get_native_function("call_host_fn")?; let f: TypedFunction<(), ()> = instance.exports.get_native_function("call_host_fn")?;
f.call()?; f.call()?;
f f
}; };
@@ -285,7 +285,7 @@ mod sys {
#[derive(Clone, WasmerEnv, Default)] #[derive(Clone, WasmerEnv, Default)]
struct FunctionEnv { struct FunctionEnv {
#[wasmer(export)] #[wasmer(export)]
call_host_fn: LazyInit<NativeFunc<(), ()>>, call_host_fn: LazyInit<TypedFunction<(), ()>>,
} }
let host_fn = |env: &FunctionEnv| { let host_fn = |env: &FunctionEnv| {
@@ -305,7 +305,7 @@ mod sys {
); );
}; };
let f: NativeFunc<(), ()> = { let f: TypedFunction<(), ()> = {
let store = Store::default(); let store = Store::default();
let module = Module::new(&store, FUNCTION_WAT)?; let module = Module::new(&store, FUNCTION_WAT)?;
let env = FunctionEnv::default(); let env = FunctionEnv::default();
@@ -320,7 +320,7 @@ mod sys {
)?; )?;
{ {
let function: NativeFunc<(), ()> = let function: TypedFunction<(), ()> =
instance.exports.get_native_function("call_host_fn")?; instance.exports.get_native_function("call_host_fn")?;
assert_eq!( assert_eq!(
is_native_function_instance_ref_strong(&function), is_native_function_instance_ref_strong(&function),
@@ -328,7 +328,7 @@ mod sys {
); );
} }
let f: NativeFunc<(), ()> = instance.exports.get_native_function("call_host_fn")?; let f: TypedFunction<(), ()> = instance.exports.get_native_function("call_host_fn")?;
f.call()?; f.call()?;
f f
}; };

View File

@@ -351,32 +351,32 @@ mod sys {
fn native_function_works() -> Result<()> { fn native_function_works() -> Result<()> {
let store = Store::default(); let store = Store::default();
let function = Function::new_native(&store, || {}); let function = Function::new_native(&store, || {});
let native_function: NativeFunc<(), ()> = function.native().unwrap(); let native_function: TypedFunction<(), ()> = function.native().unwrap();
let result = native_function.call(); let result = native_function.call();
assert!(result.is_ok()); assert!(result.is_ok());
let function = Function::new_native(&store, |a: i32| -> i32 { a + 1 }); let function = Function::new_native(&store, |a: i32| -> i32 { a + 1 });
let native_function: NativeFunc<i32, i32> = function.native().unwrap(); let native_function: TypedFunction<i32, i32> = function.native().unwrap();
assert_eq!(native_function.call(3).unwrap(), 4); assert_eq!(native_function.call(3).unwrap(), 4);
fn rust_abi(a: i32, b: i64, c: f32, d: f64) -> u64 { fn rust_abi(a: i32, b: i64, c: f32, d: f64) -> u64 {
(a as u64 * 1000) + (b as u64 * 100) + (c as u64 * 10) + (d as u64) (a as u64 * 1000) + (b as u64 * 100) + (c as u64 * 10) + (d as u64)
} }
let function = Function::new_native(&store, rust_abi); let function = Function::new_native(&store, rust_abi);
let native_function: NativeFunc<(i32, i64, f32, f64), u64> = function.native().unwrap(); let native_function: TypedFunction<(i32, i64, f32, f64), u64> = function.native().unwrap();
assert_eq!(native_function.call(8, 4, 1.5, 5.).unwrap(), 8415); assert_eq!(native_function.call(8, 4, 1.5, 5.).unwrap(), 8415);
let function = Function::new_native(&store, || -> i32 { 1 }); let function = Function::new_native(&store, || -> i32 { 1 });
let native_function: NativeFunc<(), i32> = function.native().unwrap(); let native_function: TypedFunction<(), i32> = function.native().unwrap();
assert_eq!(native_function.call().unwrap(), 1); assert_eq!(native_function.call().unwrap(), 1);
let function = Function::new_native(&store, |_a: i32| {}); let function = Function::new_native(&store, |_a: i32| {});
let native_function: NativeFunc<i32, ()> = function.native().unwrap(); let native_function: TypedFunction<i32, ()> = function.native().unwrap();
assert!(native_function.call(4).is_ok()); assert!(native_function.call(4).is_ok());
let function = let function =
Function::new_native(&store, || -> (i32, i64, f32, f64) { (1, 2, 3.0, 4.0) }); Function::new_native(&store, || -> (i32, i64, f32, f64) { (1, 2, 3.0, 4.0) });
let native_function: NativeFunc<(), (i32, i64, f32, f64)> = function.native().unwrap(); let native_function: TypedFunction<(), (i32, i64, f32, f64)> = function.native().unwrap();
assert_eq!(native_function.call().unwrap(), (1, 2, 3.0, 4.0)); assert_eq!(native_function.call().unwrap(), (1, 2, 3.0, 4.0));
Ok(()) Ok(())
@@ -397,7 +397,7 @@ mod sys {
let f = { let f = {
let module = Module::new(&store, wat)?; let module = Module::new(&store, wat)?;
let instance = Instance::new(&module, &imports! {})?; let instance = Instance::new(&module, &imports! {})?;
let f: NativeFunc<(i32, i32), i32> = instance.exports.get_native_function("sum")?; let f: TypedFunction<(i32, i32), i32> = instance.exports.get_native_function("sum")?;
assert_eq!(f.call(4, 5)?, 9); assert_eq!(f.call(4, 5)?, 9);
f f
@@ -424,7 +424,8 @@ mod sys {
let f = { let f = {
let module = Module::new(&store, wat)?; let module = Module::new(&store, wat)?;
let instance = Instance::new(&module, &imports! {})?; let instance = Instance::new(&module, &imports! {})?;
let f: NativeFunc<(i32, i32), i32> = instance.exports.get_with_generics_weak("sum")?; let f: TypedFunction<(i32, i32), i32> =
instance.exports.get_with_generics_weak("sum")?;
assert_eq!(f.call(4, 5)?, 9); assert_eq!(f.call(4, 5)?, 9);
f f

View File

@@ -228,14 +228,14 @@ mod sys {
}; };
let instance = Instance::new(&module, &imports)?; let instance = Instance::new(&module, &imports)?;
let f1: NativeFunc<(), ()> = instance.exports.get_native_function("call_host_func1")?; let f1: TypedFunction<(), ()> = instance.exports.get_native_function("call_host_func1")?;
let f2: NativeFunc<(), ()> = instance.exports.get_native_function("call_host_func2")?; let f2: TypedFunction<(), ()> = instance.exports.get_native_function("call_host_func2")?;
let f3: NativeFunc<(), ()> = instance.exports.get_native_function("call_host_func3")?; let f3: TypedFunction<(), ()> = instance.exports.get_native_function("call_host_func3")?;
let f4: NativeFunc<(), ()> = instance.exports.get_native_function("call_host_func4")?; let f4: TypedFunction<(), ()> = instance.exports.get_native_function("call_host_func4")?;
let f5: NativeFunc<(), ()> = instance.exports.get_native_function("call_host_func5")?; let f5: TypedFunction<(), ()> = instance.exports.get_native_function("call_host_func5")?;
let f6: NativeFunc<(), ()> = instance.exports.get_native_function("call_host_func6")?; let f6: TypedFunction<(), ()> = instance.exports.get_native_function("call_host_func6")?;
let f7: NativeFunc<(), ()> = instance.exports.get_native_function("call_host_func7")?; let f7: TypedFunction<(), ()> = instance.exports.get_native_function("call_host_func7")?;
let f8: NativeFunc<(), ()> = instance.exports.get_native_function("call_host_func8")?; let f8: TypedFunction<(), ()> = instance.exports.get_native_function("call_host_func8")?;
f1.call()?; f1.call()?;
f2.call()?; f2.call()?;

View File

@@ -80,7 +80,7 @@ mod sys {
fn func_ref_call(values: &[Value]) -> Result<Vec<Value>, RuntimeError> { fn func_ref_call(values: &[Value]) -> Result<Vec<Value>, RuntimeError> {
// TODO: look into `Box<[Value]>` being returned breakage // TODO: look into `Box<[Value]>` being returned breakage
let f = values[0].unwrap_funcref().as_ref().unwrap(); let f = values[0].unwrap_funcref().as_ref().unwrap();
let f: NativeFunc<(i32, i32), i32> = f.native()?; let f: TypedFunction<(i32, i32), i32> = f.native()?;
Ok(vec![Value::I32(f.call(7, 9)?)]) Ok(vec![Value::I32(f.call(7, 9)?)])
} }
@@ -94,7 +94,7 @@ mod sys {
// TODO(reftypes): this should work // TODO(reftypes): this should work
/* /*
"func_ref_call_native" => Function::new_native(&store, |f: Function| -> Result<i32, RuntimeError> { "func_ref_call_native" => Function::new_native(&store, |f: Function| -> Result<i32, RuntimeError> {
let f: NativeFunc::<(i32, i32), i32> = f.native()?; let f: TypedFunction::<(i32, i32), i32> = f.native()?;
f.call(7, 9) f.call(7, 9)
}) })
*/ */
@@ -114,7 +114,7 @@ mod sys {
} }
{ {
let f: NativeFunc<(), i32> = instance let f: TypedFunction<(), i32> = instance
.exports .exports
.get_native_function("call_host_func_with_wasm_func")?; .get_native_function("call_host_func_with_wasm_func")?;
let result = f.call()?; let result = f.call()?;
@@ -184,7 +184,7 @@ mod sys {
panic!("result is not an extern ref!"); panic!("result is not an extern ref!");
} }
let f: NativeFunc<(), ExternRef> = instance.exports.get_native_function(run)?; let f: TypedFunction<(), ExternRef> = instance.exports.get_native_function(run)?;
let result: ExternRef = f.call()?; let result: ExternRef = f.call()?;
assert!(result.is_null()); assert!(result.is_null());
} }
@@ -200,7 +200,8 @@ mod sys {
panic!("result is not an extern ref!"); panic!("result is not an extern ref!");
} }
let f: NativeFunc<(), ExternRef> = instance.exports.get_native_function(get_hashmap)?; let f: TypedFunction<(), ExternRef> =
instance.exports.get_native_function(get_hashmap)?;
let result: ExternRef = f.call()?; let result: ExternRef = f.call()?;
let inner: &HashMap<String, String> = result.downcast().unwrap(); let inner: &HashMap<String, String> = result.downcast().unwrap();
@@ -223,7 +224,7 @@ mod sys {
)"#; )"#;
let module = Module::new(&store, wat)?; let module = Module::new(&store, wat)?;
let instance = Instance::new(&module, &imports! {})?; let instance = Instance::new(&module, &imports! {})?;
let f: NativeFunc<ExternRef, ()> = instance.exports.get_native_function("drop")?; let f: TypedFunction<ExternRef, ()> = instance.exports.get_native_function("drop")?;
let er = ExternRef::new(3u32); let er = ExternRef::new(3u32);
f.call(er.clone())?; f.call(er.clone())?;
@@ -270,7 +271,7 @@ mod sys {
let fr_global: &Global = instance.exports.get_global("fr_immutable_global")?; let fr_global: &Global = instance.exports.get_global("fr_immutable_global")?;
if let Value::FuncRef(Some(f)) = fr_global.get() { if let Value::FuncRef(Some(f)) = fr_global.get() {
let native_func: NativeFunc<(), u32> = f.native()?; let native_func: TypedFunction<(), u32> = f.native()?;
assert_eq!(native_func.call()?, 73); assert_eq!(native_func.call()?, 73);
} else { } else {
panic!("Did not find non-null func ref in the global"); panic!("Did not find non-null func ref in the global");
@@ -290,7 +291,7 @@ mod sys {
fr_global.set(Val::FuncRef(Some(f)))?; fr_global.set(Val::FuncRef(Some(f)))?;
if let Value::FuncRef(Some(f)) = fr_global.get() { if let Value::FuncRef(Some(f)) = fr_global.get() {
let native: NativeFunc<(i32, i32), i32> = f.native()?; let native: TypedFunction<(i32, i32), i32> = f.native()?;
assert_eq!(native.call(5, 7)?, 12); assert_eq!(native.call(5, 7)?, 12);
} else { } else {
panic!("Did not find extern ref in the global"); panic!("Did not find extern ref in the global");
@@ -318,7 +319,7 @@ mod sys {
let module = Module::new(&store, wat)?; let module = Module::new(&store, wat)?;
let instance = Instance::new(&module, &imports! {})?; let instance = Instance::new(&module, &imports! {})?;
let f: NativeFunc<(ExternRef, i32), ExternRef> = let f: TypedFunction<(ExternRef, i32), ExternRef> =
instance.exports.get_native_function("insert_into_table")?; instance.exports.get_native_function("insert_into_table")?;
let er = ExternRef::new(3usize); let er = ExternRef::new(3usize);
@@ -362,7 +363,7 @@ mod sys {
global.set(Val::ExternRef(er.clone()))?; global.set(Val::ExternRef(er.clone()))?;
assert_eq!(er.strong_count(), 2); assert_eq!(er.strong_count(), 2);
} }
let get_from_global: NativeFunc<(), ExternRef> = let get_from_global: TypedFunction<(), ExternRef> =
instance.exports.get_native_function("get_from_global")?; instance.exports.get_native_function("get_from_global")?;
let er = get_from_global.call()?; let er = get_from_global.call()?;
@@ -387,7 +388,7 @@ mod sys {
let module = Module::new(&store, wat)?; let module = Module::new(&store, wat)?;
let instance = Instance::new(&module, &imports! {})?; let instance = Instance::new(&module, &imports! {})?;
let pass_extern_ref: NativeFunc<ExternRef, ()> = let pass_extern_ref: TypedFunction<ExternRef, ()> =
instance.exports.get_native_function("pass_extern_ref")?; instance.exports.get_native_function("pass_extern_ref")?;
let er = ExternRef::new(3usize); let er = ExternRef::new(3usize);
@@ -417,13 +418,13 @@ mod sys {
let module = Module::new(&store, wat)?; let module = Module::new(&store, wat)?;
let instance = Instance::new(&module, &imports! {})?; let instance = Instance::new(&module, &imports! {})?;
let grow_table_with_ref: NativeFunc<(ExternRef, i32), i32> = instance let grow_table_with_ref: TypedFunction<(ExternRef, i32), i32> = instance
.exports .exports
.get_native_function("grow_table_with_ref")?; .get_native_function("grow_table_with_ref")?;
let fill_table_with_ref: NativeFunc<(ExternRef, i32, i32), ()> = instance let fill_table_with_ref: TypedFunction<(ExternRef, i32, i32), ()> = instance
.exports .exports
.get_native_function("fill_table_with_ref")?; .get_native_function("fill_table_with_ref")?;
let copy_into_table2: NativeFunc<(), ()> = let copy_into_table2: TypedFunction<(), ()> =
instance.exports.get_native_function("copy_into_table2")?; instance.exports.get_native_function("copy_into_table2")?;
let table1: &Table = instance.exports.get_table("table1")?; let table1: &Table = instance.exports.get_table("table1")?;
let table2: &Table = instance.exports.get_table("table2")?; let table2: &Table = instance.exports.get_table("table2")?;

View File

@@ -1,6 +1,6 @@
#![allow(dead_code)] #![allow(dead_code)]
use wasmer::{Function, Global, LazyInit, Memory, NativeFunc, Table, WasmerEnv}; use wasmer::{Function, Global, LazyInit, Memory, Table, TypedFunction, WasmerEnv};
#[derive(WasmerEnv, Clone)] #[derive(WasmerEnv, Clone)]
struct MyEnv { struct MyEnv {
@@ -36,7 +36,7 @@ struct MyEnvWithFuncs {
#[wasmer(export)] #[wasmer(export)]
memory: LazyInit<Memory>, memory: LazyInit<Memory>,
#[wasmer(export)] #[wasmer(export)]
sum: LazyInit<NativeFunc<(i32, i32), i32>>, sum: LazyInit<TypedFunction<(i32, i32), i32>>,
} }
#[derive(WasmerEnv, Clone)] #[derive(WasmerEnv, Clone)]
@@ -46,7 +46,7 @@ struct MyEnvWithEverything {
#[wasmer(export)] #[wasmer(export)]
memory: LazyInit<Memory>, memory: LazyInit<Memory>,
#[wasmer(export)] #[wasmer(export)]
sum: LazyInit<NativeFunc<(), i32>>, sum: LazyInit<TypedFunction<(), i32>>,
#[wasmer(export)] #[wasmer(export)]
multiply: LazyInit<Function>, multiply: LazyInit<Function>,
#[wasmer(export)] #[wasmer(export)]

View File

@@ -20,7 +20,7 @@ use std::path::PathBuf;
use std::sync::{Arc, Mutex, RwLock}; use std::sync::{Arc, Mutex, RwLock};
use wasmer::{ use wasmer::{
imports, namespace, Exports, Function, FunctionType, Global, Imports, Instance, LazyInit, imports, namespace, Exports, Function, FunctionType, Global, Imports, Instance, LazyInit,
Memory, MemoryType, Module, NativeFunc, Pages, RuntimeError, Store, Table, TableType, Val, Memory, MemoryType, Module, Pages, RuntimeError, Store, Table, TableType, TypedFunction, Val,
ValType, WasmPtr, WasmerEnv, ValType, WasmPtr, WasmerEnv,
}; };
@@ -137,140 +137,140 @@ pub struct EmscriptenData {
pub globals: EmscriptenGlobalsData, pub globals: EmscriptenGlobalsData,
#[wasmer(export(alias = "_malloc", optional = true))] #[wasmer(export(alias = "_malloc", optional = true))]
pub malloc: LazyInit<NativeFunc<u32, u32>>, pub malloc: LazyInit<TypedFunction<u32, u32>>,
#[wasmer(export(alias = "_free", optional = true))] #[wasmer(export(alias = "_free", optional = true))]
pub free: LazyInit<NativeFunc<u32>>, pub free: LazyInit<TypedFunction<u32>>,
#[wasmer(export(alias = "_memalign", optional = true))] #[wasmer(export(alias = "_memalign", optional = true))]
pub memalign: LazyInit<NativeFunc<(u32, u32), u32>>, pub memalign: LazyInit<TypedFunction<(u32, u32), u32>>,
#[wasmer(export(alias = "_memset", optional = true))] #[wasmer(export(alias = "_memset", optional = true))]
pub memset: LazyInit<NativeFunc<(u32, u32, u32), u32>>, pub memset: LazyInit<TypedFunction<(u32, u32, u32), u32>>,
#[wasmer(export(name = "stackAlloc", optional = true))] #[wasmer(export(name = "stackAlloc", optional = true))]
pub stack_alloc: LazyInit<NativeFunc<u32, u32>>, pub stack_alloc: LazyInit<TypedFunction<u32, u32>>,
pub jumps: Arc<Mutex<Vec<[u32; 27]>>>, pub jumps: Arc<Mutex<Vec<[u32; 27]>>>,
pub opened_dirs: HashMap<i32, Box<LibcDirWrapper>>, pub opened_dirs: HashMap<i32, Box<LibcDirWrapper>>,
#[wasmer(export(name = "dynCall_i", optional = true))] #[wasmer(export(name = "dynCall_i", optional = true))]
pub dyn_call_i: LazyInit<NativeFunc<i32, i32>>, pub dyn_call_i: LazyInit<TypedFunction<i32, i32>>,
#[wasmer(export(name = "dynCall_ii", optional = true))] #[wasmer(export(name = "dynCall_ii", optional = true))]
pub dyn_call_ii: LazyInit<NativeFunc<(i32, i32), i32>>, pub dyn_call_ii: LazyInit<TypedFunction<(i32, i32), i32>>,
#[wasmer(export(name = "dynCall_iii", optional = true))] #[wasmer(export(name = "dynCall_iii", optional = true))]
pub dyn_call_iii: LazyInit<NativeFunc<(i32, i32, i32), i32>>, pub dyn_call_iii: LazyInit<TypedFunction<(i32, i32, i32), i32>>,
#[wasmer(export(name = "dynCall_iiii", optional = true))] #[wasmer(export(name = "dynCall_iiii", optional = true))]
pub dyn_call_iiii: LazyInit<NativeFunc<(i32, i32, i32, i32), i32>>, pub dyn_call_iiii: LazyInit<TypedFunction<(i32, i32, i32, i32), i32>>,
#[wasmer(export(name = "dynCall_iifi", optional = true))] #[wasmer(export(name = "dynCall_iifi", optional = true))]
pub dyn_call_iifi: LazyInit<NativeFunc<(i32, i32, f64, i32), i32>>, pub dyn_call_iifi: LazyInit<TypedFunction<(i32, i32, f64, i32), i32>>,
#[wasmer(export(name = "dynCall_v", optional = true))] #[wasmer(export(name = "dynCall_v", optional = true))]
pub dyn_call_v: LazyInit<NativeFunc<i32>>, pub dyn_call_v: LazyInit<TypedFunction<i32>>,
#[wasmer(export(name = "dynCall_vi", optional = true))] #[wasmer(export(name = "dynCall_vi", optional = true))]
pub dyn_call_vi: LazyInit<NativeFunc<(i32, i32)>>, pub dyn_call_vi: LazyInit<TypedFunction<(i32, i32)>>,
#[wasmer(export(name = "dynCall_vii", optional = true))] #[wasmer(export(name = "dynCall_vii", optional = true))]
pub dyn_call_vii: LazyInit<NativeFunc<(i32, i32, i32)>>, pub dyn_call_vii: LazyInit<TypedFunction<(i32, i32, i32)>>,
#[wasmer(export(name = "dynCall_viii", optional = true))] #[wasmer(export(name = "dynCall_viii", optional = true))]
pub dyn_call_viii: LazyInit<NativeFunc<(i32, i32, i32, i32)>>, pub dyn_call_viii: LazyInit<TypedFunction<(i32, i32, i32, i32)>>,
#[wasmer(export(name = "dynCall_viiii", optional = true))] #[wasmer(export(name = "dynCall_viiii", optional = true))]
pub dyn_call_viiii: LazyInit<NativeFunc<(i32, i32, i32, i32, i32)>>, pub dyn_call_viiii: LazyInit<TypedFunction<(i32, i32, i32, i32, i32)>>,
// round 2 // round 2
#[wasmer(export(name = "dynCall_dii", optional = true))] #[wasmer(export(name = "dynCall_dii", optional = true))]
pub dyn_call_dii: LazyInit<NativeFunc<(i32, i32, i32), f64>>, pub dyn_call_dii: LazyInit<TypedFunction<(i32, i32, i32), f64>>,
#[wasmer(export(name = "dynCall_diiii", optional = true))] #[wasmer(export(name = "dynCall_diiii", optional = true))]
pub dyn_call_diiii: LazyInit<NativeFunc<(i32, i32, i32, i32, i32), f64>>, pub dyn_call_diiii: LazyInit<TypedFunction<(i32, i32, i32, i32, i32), f64>>,
#[wasmer(export(name = "dynCall_iiiii", optional = true))] #[wasmer(export(name = "dynCall_iiiii", optional = true))]
pub dyn_call_iiiii: LazyInit<NativeFunc<(i32, i32, i32, i32, i32), i32>>, pub dyn_call_iiiii: LazyInit<TypedFunction<(i32, i32, i32, i32, i32), i32>>,
#[wasmer(export(name = "dynCall_iiiiii", optional = true))] #[wasmer(export(name = "dynCall_iiiiii", optional = true))]
pub dyn_call_iiiiii: LazyInit<NativeFunc<(i32, i32, i32, i32, i32, i32), i32>>, pub dyn_call_iiiiii: LazyInit<TypedFunction<(i32, i32, i32, i32, i32, i32), i32>>,
#[wasmer(export(name = "dynCall_iiiiiii", optional = true))] #[wasmer(export(name = "dynCall_iiiiiii", optional = true))]
pub dyn_call_iiiiiii: LazyInit<NativeFunc<(i32, i32, i32, i32, i32, i32, i32), i32>>, pub dyn_call_iiiiiii: LazyInit<TypedFunction<(i32, i32, i32, i32, i32, i32, i32), i32>>,
#[wasmer(export(name = "dynCall_iiiiiiii", optional = true))] #[wasmer(export(name = "dynCall_iiiiiiii", optional = true))]
pub dyn_call_iiiiiiii: LazyInit<NativeFunc<(i32, i32, i32, i32, i32, i32, i32, i32), i32>>, pub dyn_call_iiiiiiii: LazyInit<TypedFunction<(i32, i32, i32, i32, i32, i32, i32, i32), i32>>,
#[wasmer(export(name = "dynCall_iiiiiiiii", optional = true))] #[wasmer(export(name = "dynCall_iiiiiiiii", optional = true))]
pub dyn_call_iiiiiiiii: pub dyn_call_iiiiiiiii:
LazyInit<NativeFunc<(i32, i32, i32, i32, i32, i32, i32, i32, i32), i32>>, LazyInit<TypedFunction<(i32, i32, i32, i32, i32, i32, i32, i32, i32), i32>>,
#[wasmer(export(name = "dynCall_iiiiiiiiii", optional = true))] #[wasmer(export(name = "dynCall_iiiiiiiiii", optional = true))]
pub dyn_call_iiiiiiiiii: pub dyn_call_iiiiiiiiii:
LazyInit<NativeFunc<(i32, i32, i32, i32, i32, i32, i32, i32, i32, i32), i32>>, LazyInit<TypedFunction<(i32, i32, i32, i32, i32, i32, i32, i32, i32, i32), i32>>,
#[wasmer(export(name = "dynCall_iiiiiiiiiii", optional = true))] #[wasmer(export(name = "dynCall_iiiiiiiiiii", optional = true))]
pub dyn_call_iiiiiiiiiii: pub dyn_call_iiiiiiiiiii:
LazyInit<NativeFunc<(i32, i32, i32, i32, i32, i32, i32, i32, i32, i32, i32), i32>>, LazyInit<TypedFunction<(i32, i32, i32, i32, i32, i32, i32, i32, i32, i32, i32), i32>>,
#[wasmer(export(name = "dynCall_vd", optional = true))] #[wasmer(export(name = "dynCall_vd", optional = true))]
pub dyn_call_vd: LazyInit<NativeFunc<(i32, f64)>>, pub dyn_call_vd: LazyInit<TypedFunction<(i32, f64)>>,
#[wasmer(export(name = "dynCall_viiiii", optional = true))] #[wasmer(export(name = "dynCall_viiiii", optional = true))]
pub dyn_call_viiiii: LazyInit<NativeFunc<(i32, i32, i32, i32, i32, i32)>>, pub dyn_call_viiiii: LazyInit<TypedFunction<(i32, i32, i32, i32, i32, i32)>>,
#[wasmer(export(name = "dynCall_viiiiii", optional = true))] #[wasmer(export(name = "dynCall_viiiiii", optional = true))]
pub dyn_call_viiiiii: LazyInit<NativeFunc<(i32, i32, i32, i32, i32, i32, i32)>>, pub dyn_call_viiiiii: LazyInit<TypedFunction<(i32, i32, i32, i32, i32, i32, i32)>>,
#[wasmer(export(name = "dynCall_viiiiiii", optional = true))] #[wasmer(export(name = "dynCall_viiiiiii", optional = true))]
pub dyn_call_viiiiiii: LazyInit<NativeFunc<(i32, i32, i32, i32, i32, i32, i32, i32)>>, pub dyn_call_viiiiiii: LazyInit<TypedFunction<(i32, i32, i32, i32, i32, i32, i32, i32)>>,
#[wasmer(export(name = "dynCall_viiiiiiii", optional = true))] #[wasmer(export(name = "dynCall_viiiiiiii", optional = true))]
pub dyn_call_viiiiiiii: LazyInit<NativeFunc<(i32, i32, i32, i32, i32, i32, i32, i32, i32)>>, pub dyn_call_viiiiiiii: LazyInit<TypedFunction<(i32, i32, i32, i32, i32, i32, i32, i32, i32)>>,
#[wasmer(export(name = "dynCall_viiiiiiiii", optional = true))] #[wasmer(export(name = "dynCall_viiiiiiiii", optional = true))]
pub dyn_call_viiiiiiiii: pub dyn_call_viiiiiiiii:
LazyInit<NativeFunc<(i32, i32, i32, i32, i32, i32, i32, i32, i32, i32)>>, LazyInit<TypedFunction<(i32, i32, i32, i32, i32, i32, i32, i32, i32, i32)>>,
#[wasmer(export(name = "dynCall_viiiiiiiiii", optional = true))] #[wasmer(export(name = "dynCall_viiiiiiiiii", optional = true))]
pub dyn_call_viiiiiiiiii: pub dyn_call_viiiiiiiiii:
LazyInit<NativeFunc<(i32, i32, i32, i32, i32, i32, i32, i32, i32, i32, i32)>>, LazyInit<TypedFunction<(i32, i32, i32, i32, i32, i32, i32, i32, i32, i32, i32)>>,
#[wasmer(export(name = "dynCall_iij", optional = true))] #[wasmer(export(name = "dynCall_iij", optional = true))]
pub dyn_call_iij: LazyInit<NativeFunc<(i32, i32, i32, i32), i32>>, pub dyn_call_iij: LazyInit<TypedFunction<(i32, i32, i32, i32), i32>>,
#[wasmer(export(name = "dynCall_iji", optional = true))] #[wasmer(export(name = "dynCall_iji", optional = true))]
pub dyn_call_iji: LazyInit<NativeFunc<(i32, i32, i32, i32), i32>>, pub dyn_call_iji: LazyInit<TypedFunction<(i32, i32, i32, i32), i32>>,
#[wasmer(export(name = "dynCall_iiji", optional = true))] #[wasmer(export(name = "dynCall_iiji", optional = true))]
pub dyn_call_iiji: LazyInit<NativeFunc<(i32, i32, i32, i32, i32), i32>>, pub dyn_call_iiji: LazyInit<TypedFunction<(i32, i32, i32, i32, i32), i32>>,
#[wasmer(export(name = "dynCall_iiijj", optional = true))] #[wasmer(export(name = "dynCall_iiijj", optional = true))]
pub dyn_call_iiijj: LazyInit<NativeFunc<(i32, i32, i32, i32, i32, i32, i32), i32>>, pub dyn_call_iiijj: LazyInit<TypedFunction<(i32, i32, i32, i32, i32, i32, i32), i32>>,
#[wasmer(export(name = "dynCall_j", optional = true))] #[wasmer(export(name = "dynCall_j", optional = true))]
pub dyn_call_j: LazyInit<NativeFunc<i32, i32>>, pub dyn_call_j: LazyInit<TypedFunction<i32, i32>>,
#[wasmer(export(name = "dynCall_ji", optional = true))] #[wasmer(export(name = "dynCall_ji", optional = true))]
pub dyn_call_ji: LazyInit<NativeFunc<(i32, i32), i32>>, pub dyn_call_ji: LazyInit<TypedFunction<(i32, i32), i32>>,
#[wasmer(export(name = "dynCall_jii", optional = true))] #[wasmer(export(name = "dynCall_jii", optional = true))]
pub dyn_call_jii: LazyInit<NativeFunc<(i32, i32, i32), i32>>, pub dyn_call_jii: LazyInit<TypedFunction<(i32, i32, i32), i32>>,
#[wasmer(export(name = "dynCall_jij", optional = true))] #[wasmer(export(name = "dynCall_jij", optional = true))]
pub dyn_call_jij: LazyInit<NativeFunc<(i32, i32, i32, i32), i32>>, pub dyn_call_jij: LazyInit<TypedFunction<(i32, i32, i32, i32), i32>>,
#[wasmer(export(name = "dynCall_jjj", optional = true))] #[wasmer(export(name = "dynCall_jjj", optional = true))]
pub dyn_call_jjj: LazyInit<NativeFunc<(i32, i32, i32, i32, i32), i32>>, pub dyn_call_jjj: LazyInit<TypedFunction<(i32, i32, i32, i32, i32), i32>>,
#[wasmer(export(name = "dynCall_viiij", optional = true))] #[wasmer(export(name = "dynCall_viiij", optional = true))]
pub dyn_call_viiij: LazyInit<NativeFunc<(i32, i32, i32, i32, i32, i32)>>, pub dyn_call_viiij: LazyInit<TypedFunction<(i32, i32, i32, i32, i32, i32)>>,
#[wasmer(export(name = "dynCall_viiijiiii", optional = true))] #[wasmer(export(name = "dynCall_viiijiiii", optional = true))]
pub dyn_call_viiijiiii: pub dyn_call_viiijiiii:
LazyInit<NativeFunc<(i32, i32, i32, i32, i32, i32, i32, i32, i32, i32)>>, LazyInit<TypedFunction<(i32, i32, i32, i32, i32, i32, i32, i32, i32, i32)>>,
#[wasmer(export(name = "dynCall_viiijiiiiii", optional = true))] #[wasmer(export(name = "dynCall_viiijiiiiii", optional = true))]
pub dyn_call_viiijiiiiii: pub dyn_call_viiijiiiiii:
LazyInit<NativeFunc<(i32, i32, i32, i32, i32, i32, i32, i32, i32, i32, i32, i32)>>, LazyInit<TypedFunction<(i32, i32, i32, i32, i32, i32, i32, i32, i32, i32, i32, i32)>>,
#[wasmer(export(name = "dynCall_viij", optional = true))] #[wasmer(export(name = "dynCall_viij", optional = true))]
pub dyn_call_viij: LazyInit<NativeFunc<(i32, i32, i32, i32, i32)>>, pub dyn_call_viij: LazyInit<TypedFunction<(i32, i32, i32, i32, i32)>>,
#[wasmer(export(name = "dynCall_viiji", optional = true))] #[wasmer(export(name = "dynCall_viiji", optional = true))]
pub dyn_call_viiji: LazyInit<NativeFunc<(i32, i32, i32, i32, i32, i32)>>, pub dyn_call_viiji: LazyInit<TypedFunction<(i32, i32, i32, i32, i32, i32)>>,
#[wasmer(export(name = "dynCall_viijiii", optional = true))] #[wasmer(export(name = "dynCall_viijiii", optional = true))]
pub dyn_call_viijiii: LazyInit<NativeFunc<(i32, i32, i32, i32, i32, i32, i32, i32)>>, pub dyn_call_viijiii: LazyInit<TypedFunction<(i32, i32, i32, i32, i32, i32, i32, i32)>>,
#[wasmer(export(name = "dynCall_viijj", optional = true))] #[wasmer(export(name = "dynCall_viijj", optional = true))]
pub dyn_call_viijj: LazyInit<NativeFunc<(i32, i32, i32, i32, i32, i32, i32)>>, pub dyn_call_viijj: LazyInit<TypedFunction<(i32, i32, i32, i32, i32, i32, i32)>>,
#[wasmer(export(name = "dynCall_vj", optional = true))] #[wasmer(export(name = "dynCall_vj", optional = true))]
pub dyn_call_vj: LazyInit<NativeFunc<(i32, i32, i32)>>, pub dyn_call_vj: LazyInit<TypedFunction<(i32, i32, i32)>>,
#[wasmer(export(name = "dynCall_vjji", optional = true))] #[wasmer(export(name = "dynCall_vjji", optional = true))]
pub dyn_call_vjji: LazyInit<NativeFunc<(i32, i32, i32, i32, i32, i32)>>, pub dyn_call_vjji: LazyInit<TypedFunction<(i32, i32, i32, i32, i32, i32)>>,
#[wasmer(export(name = "dynCall_vij", optional = true))] #[wasmer(export(name = "dynCall_vij", optional = true))]
pub dyn_call_vij: LazyInit<NativeFunc<(i32, i32, i32, i32)>>, pub dyn_call_vij: LazyInit<TypedFunction<(i32, i32, i32, i32)>>,
#[wasmer(export(name = "dynCall_viji", optional = true))] #[wasmer(export(name = "dynCall_viji", optional = true))]
pub dyn_call_viji: LazyInit<NativeFunc<(i32, i32, i32, i32, i32)>>, pub dyn_call_viji: LazyInit<TypedFunction<(i32, i32, i32, i32, i32)>>,
#[wasmer(export(name = "dynCall_vijiii", optional = true))] #[wasmer(export(name = "dynCall_vijiii", optional = true))]
pub dyn_call_vijiii: LazyInit<NativeFunc<(i32, i32, i32, i32, i32, i32, i32)>>, pub dyn_call_vijiii: LazyInit<TypedFunction<(i32, i32, i32, i32, i32, i32, i32)>>,
#[wasmer(export(name = "dynCall_vijj", optional = true))] #[wasmer(export(name = "dynCall_vijj", optional = true))]
pub dyn_call_vijj: LazyInit<NativeFunc<(i32, i32, i32, i32, i32, i32)>>, pub dyn_call_vijj: LazyInit<TypedFunction<(i32, i32, i32, i32, i32, i32)>>,
#[wasmer(export(name = "dynCall_viid", optional = true))] #[wasmer(export(name = "dynCall_viid", optional = true))]
pub dyn_call_viid: LazyInit<NativeFunc<(i32, i32, i32, f64)>>, pub dyn_call_viid: LazyInit<TypedFunction<(i32, i32, i32, f64)>>,
#[wasmer(export(name = "dynCall_vidd", optional = true))] #[wasmer(export(name = "dynCall_vidd", optional = true))]
pub dyn_call_vidd: LazyInit<NativeFunc<(i32, i32, f64, f64)>>, pub dyn_call_vidd: LazyInit<TypedFunction<(i32, i32, f64, f64)>>,
#[wasmer(export(name = "dynCall_viidii", optional = true))] #[wasmer(export(name = "dynCall_viidii", optional = true))]
pub dyn_call_viidii: LazyInit<NativeFunc<(i32, i32, i32, f64, i32, i32)>>, pub dyn_call_viidii: LazyInit<TypedFunction<(i32, i32, i32, f64, i32, i32)>>,
#[wasmer(export(name = "dynCall_viidddddddd", optional = true))] #[wasmer(export(name = "dynCall_viidddddddd", optional = true))]
pub dyn_call_viidddddddd: pub dyn_call_viidddddddd:
LazyInit<NativeFunc<(i32, i32, i32, f64, f64, f64, f64, f64, f64, f64, f64)>>, LazyInit<TypedFunction<(i32, i32, i32, f64, f64, f64, f64, f64, f64, f64, f64)>>,
pub temp_ret_0: i32, pub temp_ret_0: i32,
#[wasmer(export(name = "stackSave", optional = true))] #[wasmer(export(name = "stackSave", optional = true))]
pub stack_save: LazyInit<NativeFunc<(), i32>>, pub stack_save: LazyInit<TypedFunction<(), i32>>,
#[wasmer(export(name = "stackRestore", optional = true))] #[wasmer(export(name = "stackRestore", optional = true))]
pub stack_restore: LazyInit<NativeFunc<i32>>, pub stack_restore: LazyInit<TypedFunction<i32>>,
#[wasmer(export(name = "setThrew", alias = "_setThrew", optional = true))] #[wasmer(export(name = "setThrew", alias = "_setThrew", optional = true))]
pub set_threw: LazyInit<NativeFunc<(i32, i32)>>, pub set_threw: LazyInit<TypedFunction<(i32, i32)>>,
pub mapped_dirs: HashMap<String, PathBuf>, pub mapped_dirs: HashMap<String, PathBuf>,
} }

View File

@@ -341,7 +341,7 @@ fn dynamic_function_with_env_wasmer_env_init_works(config: crate::Config) -> Res
}, },
}, },
)?; )?;
let f: NativeFunc<(), ()> = instance.exports.get_native_function("main")?; let f: TypedFunction<(), ()> = instance.exports.get_native_function("main")?;
f.call()?; f.call()?;
Ok(()) Ok(())
} }
@@ -381,12 +381,12 @@ fn multi_use_host_fn_manages_memory_correctly(config: crate::Config) -> Result<(
let instance1 = Instance::new(&module, &imports)?; let instance1 = Instance::new(&module, &imports)?;
let instance2 = Instance::new(&module, &imports)?; let instance2 = Instance::new(&module, &imports)?;
{ {
let f1: NativeFunc<(), ()> = instance1.exports.get_native_function("main")?; let f1: TypedFunction<(), ()> = instance1.exports.get_native_function("main")?;
f1.call()?; f1.call()?;
} }
drop(instance1); drop(instance1);
{ {
let f2: NativeFunc<(), ()> = instance2.exports.get_native_function("main")?; let f2: TypedFunction<(), ()> = instance2.exports.get_native_function("main")?;
f2.call()?; f2.call()?;
} }
drop(instance2); drop(instance2);
@@ -425,8 +425,8 @@ fn instance_local_memory_lifetime(config: crate::Config) -> Result<()> {
}, },
}; };
let instance = Instance::new(&module, &imports)?; let instance = Instance::new(&module, &imports)?;
let set_at: NativeFunc<(i32, i32), ()> = instance.exports.get_native_function("set_at")?; let set_at: TypedFunction<(i32, i32), ()> = instance.exports.get_native_function("set_at")?;
let get_at: NativeFunc<i32, i32> = instance.exports.get_native_function("get_at")?; let get_at: TypedFunction<i32, i32> = instance.exports.get_native_function("get_at")?;
set_at.call(200, 123)?; set_at.call(200, 123)?;
assert_eq!(get_at.call(200)?, 123); assert_eq!(get_at.call(200)?, 123);

View File

@@ -25,7 +25,7 @@ fn run_add_with_limit(mut config: crate::Config, limit: u64) -> Result<()> {
let instance = Instance::new(&module, &import_object)?; let instance = Instance::new(&module, &import_object)?;
let f: NativeFunc<(i32, i32), i32> = instance.exports.get_native_function("add")?; let f: TypedFunction<(i32, i32), i32> = instance.exports.get_native_function("add")?;
f.call(4, 6)?; f.call(4, 6)?;
Ok(()) Ok(())
} }
@@ -56,7 +56,7 @@ fn run_loop(mut config: crate::Config, limit: u64, iter_count: i32) -> Result<()
let instance = Instance::new(&module, &import_object)?; let instance = Instance::new(&module, &import_object)?;
let f: NativeFunc<i32, ()> = instance.exports.get_native_function("test")?; let f: TypedFunction<i32, ()> = instance.exports.get_native_function("test")?;
f.call(iter_count)?; f.call(iter_count)?;
Ok(()) Ok(())
} }
@@ -159,7 +159,7 @@ fn complex_loop(mut config: crate::Config) -> Result<()> {
let instance = Instance::new(&module, &import_object)?; let instance = Instance::new(&module, &import_object)?;
let f: NativeFunc<(i32, i32), i32> = instance.exports.get_native_function("add_to")?; let f: TypedFunction<(i32, i32), i32> = instance.exports.get_native_function("add_to")?;
// FIXME: Since now a metering error is signaled with an `unreachable`, it is impossible to verify // FIXME: Since now a metering error is signaled with an `unreachable`, it is impossible to verify
// the error type. Fix this later. // the error type. Fix this later.

View File

@@ -104,7 +104,7 @@ fn middleware_basic(mut config: crate::Config) -> Result<()> {
let instance = Instance::new(&module, &import_object)?; let instance = Instance::new(&module, &import_object)?;
let f: NativeFunc<(i32, i32), i32> = instance.exports.get_native_function("add")?; let f: TypedFunction<(i32, i32), i32> = instance.exports.get_native_function("add")?;
let result = f.call(4, 6)?; let result = f.call(4, 6)?;
assert_eq!(result, 24); assert_eq!(result, 24);
Ok(()) Ok(())
@@ -127,7 +127,7 @@ fn middleware_one_to_multi(mut config: crate::Config) -> Result<()> {
let instance = Instance::new(&module, &import_object)?; let instance = Instance::new(&module, &import_object)?;
let f: NativeFunc<(i32, i32), i32> = instance.exports.get_native_function("add")?; let f: TypedFunction<(i32, i32), i32> = instance.exports.get_native_function("add")?;
let result = f.call(4, 6)?; let result = f.call(4, 6)?;
assert_eq!(result, 25); assert_eq!(result, 25);
Ok(()) Ok(())
@@ -151,7 +151,7 @@ fn middleware_multi_to_one(mut config: crate::Config) -> Result<()> {
let instance = Instance::new(&module, &import_object)?; let instance = Instance::new(&module, &import_object)?;
let f: NativeFunc<(i32, i32), i32> = instance.exports.get_native_function("testfunc")?; let f: TypedFunction<(i32, i32), i32> = instance.exports.get_native_function("testfunc")?;
let result = f.call(10, 20)?; let result = f.call(10, 20)?;
assert_eq!(result, 10); assert_eq!(result, 10);
Ok(()) Ok(())
@@ -175,7 +175,7 @@ fn middleware_chain_order_1(mut config: crate::Config) -> Result<()> {
let instance = Instance::new(&module, &import_object)?; let instance = Instance::new(&module, &import_object)?;
let f: NativeFunc<(i32, i32), i32> = instance.exports.get_native_function("add")?; let f: TypedFunction<(i32, i32), i32> = instance.exports.get_native_function("add")?;
let result = f.call(4, 6)?; let result = f.call(4, 6)?;
assert_eq!(result, 24); assert_eq!(result, 24);
Ok(()) Ok(())
@@ -199,7 +199,7 @@ fn middleware_chain_order_2(mut config: crate::Config) -> Result<()> {
let instance = Instance::new(&module, &import_object)?; let instance = Instance::new(&module, &import_object)?;
let f: NativeFunc<(i32, i32), i32> = instance.exports.get_native_function("add")?; let f: TypedFunction<(i32, i32), i32> = instance.exports.get_native_function("add")?;
let result = f.call(4, 6)?; let result = f.call(4, 6)?;
assert_eq!(result, 48); assert_eq!(result, 48);
Ok(()) Ok(())

View File

@@ -55,7 +55,7 @@ fn native_function_works_for_wasm(config: crate::Config) -> anyhow::Result<()> {
let instance = Instance::new(&module, &import_object)?; let instance = Instance::new(&module, &import_object)?;
{ {
let f: NativeFunc<(i32, i32), i32> = instance.exports.get_native_function("add")?; let f: TypedFunction<(i32, i32), i32> = instance.exports.get_native_function("add")?;
let result = f.call(4, 6)?; let result = f.call(4, 6)?;
assert_eq!(result, 10); assert_eq!(result, 10);
} }
@@ -68,7 +68,7 @@ fn native_function_works_for_wasm(config: crate::Config) -> anyhow::Result<()> {
{ {
let dyn_f: &Function = instance.exports.get("double_then_add")?; let dyn_f: &Function = instance.exports.get("double_then_add")?;
let f: NativeFunc<(i32, i32), i32> = dyn_f.native().unwrap(); let f: TypedFunction<(i32, i32), i32> = dyn_f.native().unwrap();
let result = f.call(4, 6)?; let result = f.call(4, 6)?;
assert_eq!(result, 20); assert_eq!(result, 20);
} }
@@ -151,7 +151,7 @@ fn non_native_functions_and_closures_with_no_env_work(config: crate::Config) ->
let instance = Instance::new(&module, &import_object)?; let instance = Instance::new(&module, &import_object)?;
let test: NativeFunc<(i32, i32, i32, i32, i32), i32> = let test: TypedFunction<(i32, i32, i32, i32, i32), i32> =
instance.exports.get_native_function("test")?; instance.exports.get_native_function("test")?;
let result = test.call(2, 3, 4, 5, 6)?; let result = test.call(2, 3, 4, 5, 6)?;
@@ -182,14 +182,14 @@ fn native_function_works_for_wasm_function_manyparams(config: crate::Config) ->
{ {
let dyn_f: &Function = instance.exports.get("longf")?; let dyn_f: &Function = instance.exports.get("longf")?;
let f: NativeFunc<(), i64> = dyn_f.native().unwrap(); let f: TypedFunction<(), i64> = dyn_f.native().unwrap();
let result = f.call()?; let result = f.call()?;
assert_eq!(result, 1234567890); assert_eq!(result, 1234567890);
} }
{ {
let dyn_f: &Function = instance.exports.get("longf_pure")?; let dyn_f: &Function = instance.exports.get("longf_pure")?;
let f: NativeFunc<(u32, u32, u32, u32, u32, u16, u64, u64, u16, u32), i64> = let f: TypedFunction<(u32, u32, u32, u32, u32, u16, u64, u64, u16, u32), i64> =
dyn_f.native().unwrap(); dyn_f.native().unwrap();
let result = f.call(1, 2, 3, 4, 5, 6, 7, 8, 9, 0)?; let result = f.call(1, 2, 3, 4, 5, 6, 7, 8, 9, 0)?;
assert_eq!(result, 1234567890); assert_eq!(result, 1234567890);
@@ -222,14 +222,14 @@ fn native_function_works_for_wasm_function_manyparams_dynamic(
{ {
let dyn_f: &Function = instance.exports.get("longf")?; let dyn_f: &Function = instance.exports.get("longf")?;
let f: NativeFunc<(), i64> = dyn_f.native().unwrap(); let f: TypedFunction<(), i64> = dyn_f.native().unwrap();
let result = f.call()?; let result = f.call()?;
assert_eq!(result, 1234567890); assert_eq!(result, 1234567890);
} }
{ {
let dyn_f: &Function = instance.exports.get("longf_pure")?; let dyn_f: &Function = instance.exports.get("longf_pure")?;
let f: NativeFunc<(u32, u32, u32, u32, u32, u16, u64, u64, u16, u32), i64> = let f: TypedFunction<(u32, u32, u32, u32, u32, u16, u64, u64, u16, u32), i64> =
dyn_f.native().unwrap(); dyn_f.native().unwrap();
let result = f.call(1, 2, 3, 4, 5, 6, 7, 8, 9, 0)?; let result = f.call(1, 2, 3, 4, 5, 6, 7, 8, 9, 0)?;
assert_eq!(result, 1234567890); assert_eq!(result, 1234567890);
@@ -272,7 +272,8 @@ fn static_host_function_without_env(config: crate::Config) -> anyhow::Result<()>
// Native static host function that returns a tuple. // Native static host function that returns a tuple.
{ {
let f = Function::new_native(&store, f); let f = Function::new_native(&store, f);
let f_native: NativeFunc<(i32, i64, f32, f64), (f64, f32, i64, i32)> = f.native().unwrap(); let f_native: TypedFunction<(i32, i64, f32, f64), (f64, f32, i64, i32)> =
f.native().unwrap();
let result = f_native.call(1, 3, 5.0, 7.0)?; let result = f_native.call(1, 3, 5.0, 7.0)?;
assert_eq!(result, (28.0, 15.0, 6, 1)); assert_eq!(result, (28.0, 15.0, 6, 1));
} }
@@ -280,7 +281,7 @@ fn static_host_function_without_env(config: crate::Config) -> anyhow::Result<()>
// Native static host function that returns a tuple. // Native static host function that returns a tuple.
{ {
let long_f = Function::new_native(&store, long_f); let long_f = Function::new_native(&store, long_f);
let long_f_native: NativeFunc< let long_f_native: TypedFunction<
(u32, u32, u32, u32, u32, u16, u64, u64, u16, u32), (u32, u32, u32, u32, u32, u16, u64, u64, u16, u32),
(u32, u64, u32), (u32, u64, u32),
> = long_f.native().unwrap(); > = long_f.native().unwrap();
@@ -291,7 +292,8 @@ fn static_host_function_without_env(config: crate::Config) -> anyhow::Result<()>
// Native static host function that returns a result of a tuple. // Native static host function that returns a result of a tuple.
{ {
let f = Function::new_native(&store, f_ok); let f = Function::new_native(&store, f_ok);
let f_native: NativeFunc<(i32, i64, f32, f64), (f64, f32, i64, i32)> = f.native().unwrap(); let f_native: TypedFunction<(i32, i64, f32, f64), (f64, f32, i64, i32)> =
f.native().unwrap();
let result = f_native.call(1, 3, 5.0, 7.0)?; let result = f_native.call(1, 3, 5.0, 7.0)?;
assert_eq!(result, (28.0, 15.0, 6, 1)); assert_eq!(result, (28.0, 15.0, 6, 1));
} }
@@ -334,7 +336,8 @@ fn static_host_function_with_env(config: crate::Config) -> anyhow::Result<()> {
let env = Env(Arc::new(Mutex::new(100))); let env = Env(Arc::new(Mutex::new(100)));
let f = Function::new_native_with_env(&store, env.clone(), f); let f = Function::new_native_with_env(&store, env.clone(), f);
let f_native: NativeFunc<(i32, i64, f32, f64), (f64, f32, i64, i32)> = f.native().unwrap(); let f_native: TypedFunction<(i32, i64, f32, f64), (f64, f32, i64, i32)> =
f.native().unwrap();
assert_eq!(*env.0.lock().unwrap(), 100); assert_eq!(*env.0.lock().unwrap(), 100);
@@ -349,7 +352,8 @@ fn static_host_function_with_env(config: crate::Config) -> anyhow::Result<()> {
let env = Env(Arc::new(Mutex::new(100))); let env = Env(Arc::new(Mutex::new(100)));
let f = Function::new_native_with_env(&store, env.clone(), f_ok); let f = Function::new_native_with_env(&store, env.clone(), f_ok);
let f_native: NativeFunc<(i32, i64, f32, f64), (f64, f32, i64, i32)> = f.native().unwrap(); let f_native: TypedFunction<(i32, i64, f32, f64), (f64, f32, i64, i32)> =
f.native().unwrap();
assert_eq!(*env.0.lock().unwrap(), 100); assert_eq!(*env.0.lock().unwrap(), 100);
@@ -381,7 +385,7 @@ fn dynamic_host_function_without_env(config: crate::Config) -> anyhow::Result<()
]) ])
}, },
); );
let f_native: NativeFunc<(i32, i64, f32, f64), (f64, f32, i64, i32)> = f.native().unwrap(); let f_native: TypedFunction<(i32, i64, f32, f64), (f64, f32, i64, i32)> = f.native().unwrap();
let result = f_native.call(1, 3, 5.0, 7.0)?; let result = f_native.call(1, 3, 5.0, 7.0)?;
assert_eq!(result, (28.0, 15.0, 6, 1)); assert_eq!(result, (28.0, 15.0, 6, 1));
@@ -426,7 +430,7 @@ fn dynamic_host_function_with_env(config: crate::Config) -> anyhow::Result<()> {
}, },
); );
let f_native: NativeFunc<(i32, i64, f32, f64), (f64, f32, i64, i32)> = f.native().unwrap(); let f_native: TypedFunction<(i32, i64, f32, f64), (f64, f32, i64, i32)> = f.native().unwrap();
assert_eq!(*env.0.lock().unwrap(), 100); assert_eq!(*env.0.lock().unwrap(), 100);