Renamed wasmer::Func to wasmer::Function

This commit is contained in:
Syrus
2020-05-04 14:00:03 -07:00
parent 0bd6a0dd6b
commit a993dc4897
11 changed files with 136 additions and 136 deletions

View File

@@ -1,4 +1,4 @@
use crate::externals::{Extern, Func, Global, Memory, Table}; use crate::externals::{Extern, Function, Global, Memory, Table};
use crate::import_object::LikeNamespace; use crate::import_object::LikeNamespace;
use indexmap::IndexMap; use indexmap::IndexMap;
use std::iter::FromIterator; use std::iter::FromIterator;
@@ -103,7 +103,7 @@ impl Exports {
} }
/// Get an export as a `Func`. /// Get an export as a `Func`.
pub fn get_func(&self, name: &str) -> Result<&Func, ExportError> { pub fn get_func(&self, name: &str) -> Result<&Function, ExportError> {
self.get(name) self.get(name)
} }

View File

@@ -16,7 +16,7 @@ use wasmer_runtime::{
#[derive(Clone)] #[derive(Clone)]
pub enum Extern { pub enum Extern {
Function(Func), Function(Function),
Global(Global), Global(Global),
Table(Table), Table(Table),
Memory(Memory), Memory(Memory),
@@ -34,7 +34,7 @@ impl Extern {
pub(crate) fn from_export(store: &Store, export: Export) -> Extern { pub(crate) fn from_export(store: &Store, export: Export) -> Extern {
match export { match export {
Export::Function(f) => Extern::Function(Func::from_export(store, f)), Export::Function(f) => Extern::Function(Function::from_export(store, f)),
Export::Memory(m) => Extern::Memory(Memory::from_export(store, m)), Export::Memory(m) => Extern::Memory(Memory::from_export(store, m)),
Export::Global(g) => Extern::Global(Global::from_export(store, g)), Export::Global(g) => Extern::Global(Global::from_export(store, g)),
Export::Table(t) => Extern::Table(Table::from_export(store, t)), Export::Table(t) => Extern::Table(Table::from_export(store, t)),
@@ -70,8 +70,8 @@ impl StoreObject for Extern {
} }
} }
impl From<Func> for Extern { impl From<Function> for Extern {
fn from(r: Func) -> Self { fn from(r: Function) -> Self {
Extern::Function(r) Extern::Function(r)
} }
} }
@@ -492,7 +492,7 @@ pub enum InnerFunc {
/// A WebAssembly `function`. /// A WebAssembly `function`.
#[derive(Clone, PartialEq)] #[derive(Clone, PartialEq)]
pub struct Func { pub struct Function {
store: Store, store: Store,
// If the Function is owned by the Store, not the instance // If the Function is owned by the Store, not the instance
inner: InnerFunc, inner: InnerFunc,
@@ -500,12 +500,12 @@ pub struct Func {
exported: ExportFunction, exported: ExportFunction,
} }
impl Func { impl Function {
/// Creates a new `Func` with the given parameters. /// Creates a new `Func` with the given parameters.
/// ///
/// * `store` - a global cache to store information in /// * `store` - a global cache to store information in
/// * `func` - the function. /// * `func` - the function.
pub fn new<F, Args, Rets, Env>(store: &Store, func: F) -> Func pub fn new<F, Args, Rets, Env>(store: &Store, func: F) -> Self
where where
F: HostFunction<Args, Rets, WithoutEnv, Env>, F: HostFunction<Args, Rets, WithoutEnv, Env>,
Args: WasmTypeList, Args: WasmTypeList,
@@ -517,7 +517,7 @@ impl Func {
let vmctx = (func.env().unwrap_or(std::ptr::null_mut()) as *mut _) as *mut VMContext; let vmctx = (func.env().unwrap_or(std::ptr::null_mut()) as *mut _) as *mut VMContext;
let func_type = func.ty(); let func_type = func.ty();
let signature = store.engine().register_signature(&func_type); let signature = store.engine().register_signature(&func_type);
Func { Self {
store: store.clone(), store: store.clone(),
owned_by_store: true, owned_by_store: true,
inner: InnerFunc::Host(HostFunc { inner: InnerFunc::Host(HostFunc {
@@ -536,7 +536,7 @@ impl Func {
/// * `store` - a global cache to store information in. /// * `store` - a global cache to store information in.
/// * `env` - the function environment. /// * `env` - the function environment.
/// * `func` - the function. /// * `func` - the function.
pub fn new_env<F, Args, Rets, Env>(store: &Store, env: &mut Env, func: F) -> Func pub fn new_env<F, Args, Rets, Env>(store: &Store, env: &mut Env, func: F) -> Self
where where
F: HostFunction<Args, Rets, WithEnv, Env>, F: HostFunction<Args, Rets, WithEnv, Env>,
Args: WasmTypeList, Args: WasmTypeList,
@@ -548,7 +548,7 @@ impl Func {
let vmctx = (func.env().unwrap_or(std::ptr::null_mut()) as *mut _) as *mut VMContext; let vmctx = (func.env().unwrap_or(std::ptr::null_mut()) as *mut _) as *mut VMContext;
let func_type = func.ty(); let func_type = func.ty();
let signature = store.engine().register_signature(&func_type); let signature = store.engine().register_signature(&func_type);
Func { Self {
store: store.clone(), store: store.clone(),
owned_by_store: true, owned_by_store: true,
inner: InnerFunc::Host(HostFunc { inner: InnerFunc::Host(HostFunc {
@@ -662,9 +662,9 @@ impl Func {
Ok(results.into_boxed_slice()) Ok(results.into_boxed_slice())
} }
pub(crate) fn from_export(store: &Store, wasmer_export: ExportFunction) -> Func { pub(crate) fn from_export(store: &Store, wasmer_export: ExportFunction) -> Self {
let trampoline = store.engine().trampoline(wasmer_export.signature).unwrap(); let trampoline = store.engine().trampoline(wasmer_export.signature).unwrap();
Func { Self {
store: store.clone(), store: store.clone(),
owned_by_store: false, owned_by_store: false,
inner: InnerFunc::Wasm(WasmFunc { trampoline }), inner: InnerFunc::Wasm(WasmFunc { trampoline }),
@@ -681,7 +681,7 @@ impl Func {
} }
} }
impl<'a> Exportable<'a> for Func { impl<'a> Exportable<'a> for Function {
fn to_export(&self) -> Export { fn to_export(&self) -> Export {
self.exported.clone().into() self.exported.clone().into()
} }
@@ -693,7 +693,7 @@ impl<'a> Exportable<'a> for Func {
} }
} }
impl std::fmt::Debug for Func { impl std::fmt::Debug for Function {
fn fmt(&self, _f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result { fn fmt(&self, _f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
Ok(()) Ok(())
} }

View File

@@ -201,7 +201,7 @@ impl Extend<((String, String), Export)> for ImportObject {
/// ///
/// let import_object = imports! { /// let import_object = imports! {
/// "env" => { /// "env" => {
/// "foo" => Func::new(&store, foo) /// "foo" => Function::new(&store, foo)
/// } /// }
/// }; /// };
/// ///

View File

@@ -13,7 +13,7 @@ mod tunables;
mod types; mod types;
pub use crate::exports::{ExportError, Exportable, Exports}; pub use crate::exports::{ExportError, Exportable, Exports};
pub use crate::externals::{Extern, Func, Global, Memory, Table}; pub use crate::externals::{Extern, Function, Global, Memory, Table};
pub use crate::import_object::{ImportObject, ImportObjectIterator, LikeNamespace}; pub use crate::import_object::{ImportObject, ImportObjectIterator, LikeNamespace};
pub use crate::instance::Instance; pub use crate::instance::Instance;
pub use crate::memory_view::MemoryView; pub use crate::memory_view::MemoryView;

View File

@@ -1,4 +1,4 @@
use crate::externals::Func; use crate::externals::Function;
use crate::store::{Store, StoreObject}; use crate::store::{Store, StoreObject};
use crate::RuntimeError; use crate::RuntimeError;
use std::ptr; use std::ptr;
@@ -8,7 +8,7 @@ pub use wasm_common::{
MemoryType, Mutability, TableType, Type as ValType, MemoryType, Mutability, TableType, Type as ValType,
}; };
pub type Val = Value<Func>; pub type Val = Value<Function>;
impl StoreObject for Val { impl StoreObject for Val {
fn comes_from_same_store(&self, store: &Store) -> bool { fn comes_from_same_store(&self, store: &Store) -> bool {
@@ -21,8 +21,8 @@ impl StoreObject for Val {
} }
} }
impl From<Func> for Val { impl From<Function> for Val {
fn from(val: Func) -> Val { fn from(val: Function) -> Val {
Val::FuncRef(val) Val::FuncRef(val)
} }
} }
@@ -66,7 +66,7 @@ impl ValAnyFunc for Val {
signature: item.type_index, signature: item.type_index,
vmctx: item.vmctx, vmctx: item.vmctx,
}; };
let f = Func::from_export(store, export); let f = Function::from_export(store, export);
Val::FuncRef(f) Val::FuncRef(f)
} }
} }

View File

@@ -26,7 +26,7 @@ pub use crate::syscalls::types;
pub use crate::utils::{get_wasi_version, is_wasi_module, WasiVersion}; pub use crate::utils::{get_wasi_version, is_wasi_module, WasiVersion};
use thiserror::Error; use thiserror::Error;
use wasmer::{imports, Func, ImportObject, Memory, Store}; use wasmer::{imports, Function, ImportObject, Memory, Store};
/// This is returned in `RuntimeError`. /// This is returned in `RuntimeError`.
/// Use `downcast` or `downcast_ref` to retrieve the `ExitCode`. /// Use `downcast` or `downcast_ref` to retrieve the `ExitCode`.
@@ -100,51 +100,51 @@ pub fn generate_import_object_from_env(
fn generate_import_object_snapshot0(store: &Store, env: &mut WasiEnv) -> ImportObject { fn generate_import_object_snapshot0(store: &Store, env: &mut WasiEnv) -> ImportObject {
imports! { imports! {
"wasi_unstable" => { "wasi_unstable" => {
"args_get" => Func::new_env(store, env, args_get), "args_get" => Function::new_env(store, env, args_get),
"args_sizes_get" => Func::new_env(store, env, args_sizes_get), "args_sizes_get" => Function::new_env(store, env, args_sizes_get),
"clock_res_get" => Func::new_env(store, env, clock_res_get), "clock_res_get" => Function::new_env(store, env, clock_res_get),
"clock_time_get" => Func::new_env(store, env, clock_time_get), "clock_time_get" => Function::new_env(store, env, clock_time_get),
"environ_get" => Func::new_env(store, env, environ_get), "environ_get" => Function::new_env(store, env, environ_get),
"environ_sizes_get" => Func::new_env(store, env, environ_sizes_get), "environ_sizes_get" => Function::new_env(store, env, environ_sizes_get),
"fd_advise" => Func::new_env(store, env, fd_advise), "fd_advise" => Function::new_env(store, env, fd_advise),
"fd_allocate" => Func::new_env(store, env, fd_allocate), "fd_allocate" => Function::new_env(store, env, fd_allocate),
"fd_close" => Func::new_env(store, env, fd_close), "fd_close" => Function::new_env(store, env, fd_close),
"fd_datasync" => Func::new_env(store, env, fd_datasync), "fd_datasync" => Function::new_env(store, env, fd_datasync),
"fd_fdstat_get" => Func::new_env(store, env, fd_fdstat_get), "fd_fdstat_get" => Function::new_env(store, env, fd_fdstat_get),
"fd_fdstat_set_flags" => Func::new_env(store, env, fd_fdstat_set_flags), "fd_fdstat_set_flags" => Function::new_env(store, env, fd_fdstat_set_flags),
"fd_fdstat_set_rights" => Func::new_env(store, env, fd_fdstat_set_rights), "fd_fdstat_set_rights" => Function::new_env(store, env, fd_fdstat_set_rights),
"fd_filestat_get" => Func::new_env(store, env, legacy::snapshot0::fd_filestat_get), "fd_filestat_get" => Function::new_env(store, env, legacy::snapshot0::fd_filestat_get),
"fd_filestat_set_size" => Func::new_env(store, env, fd_filestat_set_size), "fd_filestat_set_size" => Function::new_env(store, env, fd_filestat_set_size),
"fd_filestat_set_times" => Func::new_env(store, env, fd_filestat_set_times), "fd_filestat_set_times" => Function::new_env(store, env, fd_filestat_set_times),
"fd_pread" => Func::new_env(store, env, fd_pread), "fd_pread" => Function::new_env(store, env, fd_pread),
"fd_prestat_get" => Func::new_env(store, env, fd_prestat_get), "fd_prestat_get" => Function::new_env(store, env, fd_prestat_get),
"fd_prestat_dir_name" => Func::new_env(store, env, fd_prestat_dir_name), "fd_prestat_dir_name" => Function::new_env(store, env, fd_prestat_dir_name),
"fd_pwrite" => Func::new_env(store, env, fd_pwrite), "fd_pwrite" => Function::new_env(store, env, fd_pwrite),
"fd_read" => Func::new_env(store, env, fd_read), "fd_read" => Function::new_env(store, env, fd_read),
"fd_readdir" => Func::new_env(store, env, fd_readdir), "fd_readdir" => Function::new_env(store, env, fd_readdir),
"fd_renumber" => Func::new_env(store, env, fd_renumber), "fd_renumber" => Function::new_env(store, env, fd_renumber),
"fd_seek" => Func::new_env(store, env, legacy::snapshot0::fd_seek), "fd_seek" => Function::new_env(store, env, legacy::snapshot0::fd_seek),
"fd_sync" => Func::new_env(store, env, fd_sync), "fd_sync" => Function::new_env(store, env, fd_sync),
"fd_tell" => Func::new_env(store, env, fd_tell), "fd_tell" => Function::new_env(store, env, fd_tell),
"fd_write" => Func::new_env(store, env, fd_write), "fd_write" => Function::new_env(store, env, fd_write),
"path_create_directory" => Func::new_env(store, env, path_create_directory), "path_create_directory" => Function::new_env(store, env, path_create_directory),
"path_filestat_get" => Func::new_env(store, env, legacy::snapshot0::path_filestat_get), "path_filestat_get" => Function::new_env(store, env, legacy::snapshot0::path_filestat_get),
"path_filestat_set_times" => Func::new_env(store, env, path_filestat_set_times), "path_filestat_set_times" => Function::new_env(store, env, path_filestat_set_times),
"path_link" => Func::new_env(store, env, path_link), "path_link" => Function::new_env(store, env, path_link),
"path_open" => Func::new_env(store, env, path_open), "path_open" => Function::new_env(store, env, path_open),
"path_readlink" => Func::new_env(store, env, path_readlink), "path_readlink" => Function::new_env(store, env, path_readlink),
"path_remove_directory" => Func::new_env(store, env, path_remove_directory), "path_remove_directory" => Function::new_env(store, env, path_remove_directory),
"path_rename" => Func::new_env(store, env, path_rename), "path_rename" => Function::new_env(store, env, path_rename),
"path_symlink" => Func::new_env(store, env, path_symlink), "path_symlink" => Function::new_env(store, env, path_symlink),
"path_unlink_file" => Func::new_env(store, env, path_unlink_file), "path_unlink_file" => Function::new_env(store, env, path_unlink_file),
"poll_oneoff" => Func::new_env(store, env, legacy::snapshot0::poll_oneoff), "poll_oneoff" => Function::new_env(store, env, legacy::snapshot0::poll_oneoff),
"proc_exit" => Func::new_env(store, env, proc_exit), "proc_exit" => Function::new_env(store, env, proc_exit),
"proc_raise" => Func::new_env(store, env, proc_raise), "proc_raise" => Function::new_env(store, env, proc_raise),
"random_get" => Func::new_env(store, env, random_get), "random_get" => Function::new_env(store, env, random_get),
"sched_yield" => Func::new_env(store, env, sched_yield), "sched_yield" => Function::new_env(store, env, sched_yield),
"sock_recv" => Func::new_env(store, env, sock_recv), "sock_recv" => Function::new_env(store, env, sock_recv),
"sock_send" => Func::new_env(store, env, sock_send), "sock_send" => Function::new_env(store, env, sock_send),
"sock_shutdown" => Func::new_env(store, env, sock_shutdown), "sock_shutdown" => Function::new_env(store, env, sock_shutdown),
}, },
} }
} }
@@ -153,51 +153,51 @@ fn generate_import_object_snapshot0(store: &Store, env: &mut WasiEnv) -> ImportO
fn generate_import_object_snapshot1(store: &Store, env: &mut WasiEnv) -> ImportObject { fn generate_import_object_snapshot1(store: &Store, env: &mut WasiEnv) -> ImportObject {
imports! { imports! {
"wasi_snapshot_preview1" => { "wasi_snapshot_preview1" => {
"args_get" => Func::new_env(store, env, args_get), "args_get" => Function::new_env(store, env, args_get),
"args_sizes_get" => Func::new_env(store, env, args_sizes_get), "args_sizes_get" => Function::new_env(store, env, args_sizes_get),
"clock_res_get" => Func::new_env(store, env, clock_res_get), "clock_res_get" => Function::new_env(store, env, clock_res_get),
"clock_time_get" => Func::new_env(store, env, clock_time_get), "clock_time_get" => Function::new_env(store, env, clock_time_get),
"environ_get" => Func::new_env(store, env, environ_get), "environ_get" => Function::new_env(store, env, environ_get),
"environ_sizes_get" => Func::new_env(store, env, environ_sizes_get), "environ_sizes_get" => Function::new_env(store, env, environ_sizes_get),
"fd_advise" => Func::new_env(store, env, fd_advise), "fd_advise" => Function::new_env(store, env, fd_advise),
"fd_allocate" => Func::new_env(store, env, fd_allocate), "fd_allocate" => Function::new_env(store, env, fd_allocate),
"fd_close" => Func::new_env(store, env, fd_close), "fd_close" => Function::new_env(store, env, fd_close),
"fd_datasync" => Func::new_env(store, env, fd_datasync), "fd_datasync" => Function::new_env(store, env, fd_datasync),
"fd_fdstat_get" => Func::new_env(store, env, fd_fdstat_get), "fd_fdstat_get" => Function::new_env(store, env, fd_fdstat_get),
"fd_fdstat_set_flags" => Func::new_env(store, env, fd_fdstat_set_flags), "fd_fdstat_set_flags" => Function::new_env(store, env, fd_fdstat_set_flags),
"fd_fdstat_set_rights" => Func::new_env(store, env, fd_fdstat_set_rights), "fd_fdstat_set_rights" => Function::new_env(store, env, fd_fdstat_set_rights),
"fd_filestat_get" => Func::new_env(store, env, fd_filestat_get), "fd_filestat_get" => Function::new_env(store, env, fd_filestat_get),
"fd_filestat_set_size" => Func::new_env(store, env, fd_filestat_set_size), "fd_filestat_set_size" => Function::new_env(store, env, fd_filestat_set_size),
"fd_filestat_set_times" => Func::new_env(store, env, fd_filestat_set_times), "fd_filestat_set_times" => Function::new_env(store, env, fd_filestat_set_times),
"fd_pread" => Func::new_env(store, env, fd_pread), "fd_pread" => Function::new_env(store, env, fd_pread),
"fd_prestat_get" => Func::new_env(store, env, fd_prestat_get), "fd_prestat_get" => Function::new_env(store, env, fd_prestat_get),
"fd_prestat_dir_name" => Func::new_env(store, env, fd_prestat_dir_name), "fd_prestat_dir_name" => Function::new_env(store, env, fd_prestat_dir_name),
"fd_pwrite" => Func::new_env(store, env, fd_pwrite), "fd_pwrite" => Function::new_env(store, env, fd_pwrite),
"fd_read" => Func::new_env(store, env, fd_read), "fd_read" => Function::new_env(store, env, fd_read),
"fd_readdir" => Func::new_env(store, env, fd_readdir), "fd_readdir" => Function::new_env(store, env, fd_readdir),
"fd_renumber" => Func::new_env(store, env, fd_renumber), "fd_renumber" => Function::new_env(store, env, fd_renumber),
"fd_seek" => Func::new_env(store, env, fd_seek), "fd_seek" => Function::new_env(store, env, fd_seek),
"fd_sync" => Func::new_env(store, env, fd_sync), "fd_sync" => Function::new_env(store, env, fd_sync),
"fd_tell" => Func::new_env(store, env, fd_tell), "fd_tell" => Function::new_env(store, env, fd_tell),
"fd_write" => Func::new_env(store, env, fd_write), "fd_write" => Function::new_env(store, env, fd_write),
"path_create_directory" => Func::new_env(store, env, path_create_directory), "path_create_directory" => Function::new_env(store, env, path_create_directory),
"path_filestat_get" => Func::new_env(store, env, path_filestat_get), "path_filestat_get" => Function::new_env(store, env, path_filestat_get),
"path_filestat_set_times" => Func::new_env(store, env, path_filestat_set_times), "path_filestat_set_times" => Function::new_env(store, env, path_filestat_set_times),
"path_link" => Func::new_env(store, env, path_link), "path_link" => Function::new_env(store, env, path_link),
"path_open" => Func::new_env(store, env, path_open), "path_open" => Function::new_env(store, env, path_open),
"path_readlink" => Func::new_env(store, env, path_readlink), "path_readlink" => Function::new_env(store, env, path_readlink),
"path_remove_directory" => Func::new_env(store, env, path_remove_directory), "path_remove_directory" => Function::new_env(store, env, path_remove_directory),
"path_rename" => Func::new_env(store, env, path_rename), "path_rename" => Function::new_env(store, env, path_rename),
"path_symlink" => Func::new_env(store, env, path_symlink), "path_symlink" => Function::new_env(store, env, path_symlink),
"path_unlink_file" => Func::new_env(store, env, path_unlink_file), "path_unlink_file" => Function::new_env(store, env, path_unlink_file),
"poll_oneoff" => Func::new_env(store, env, poll_oneoff), "poll_oneoff" => Function::new_env(store, env, poll_oneoff),
"proc_exit" => Func::new_env(store, env, proc_exit), "proc_exit" => Function::new_env(store, env, proc_exit),
"proc_raise" => Func::new_env(store, env, proc_raise), "proc_raise" => Function::new_env(store, env, proc_raise),
"random_get" => Func::new_env(store, env, random_get), "random_get" => Function::new_env(store, env, random_get),
"sched_yield" => Func::new_env(store, env, sched_yield), "sched_yield" => Function::new_env(store, env, sched_yield),
"sock_recv" => Func::new_env(store, env, sock_recv), "sock_recv" => Function::new_env(store, env, sock_recv),
"sock_send" => Func::new_env(store, env, sock_send), "sock_send" => Function::new_env(store, env, sock_send),
"sock_shutdown" => Func::new_env(store, env, sock_shutdown), "sock_shutdown" => Function::new_env(store, env, sock_shutdown),
} }
} }
} }

View File

@@ -633,36 +633,36 @@ mod test_func {
#[test] #[test]
fn test_function_types() { fn test_function_types() {
assert_eq!(Func::new(func).ty(), FunctionType::new(vec![], vec![])); assert_eq!(Function::new(func).ty(), FunctionType::new(vec![], vec![]));
assert_eq!( assert_eq!(
Func::new(func__i32).ty(), Function::new(func__i32).ty(),
FunctionType::new(vec![], vec![Type::I32]) FunctionType::new(vec![], vec![Type::I32])
); );
assert_eq!( assert_eq!(
Func::new(func_i32).ty(), Function::new(func_i32).ty(),
FunctionType::new(vec![Type::I32], vec![]) FunctionType::new(vec![Type::I32], vec![])
); );
assert_eq!( assert_eq!(
Func::new(func_i32__i32).ty(), Function::new(func_i32__i32).ty(),
FunctionType::new(vec![Type::I32], vec![Type::I32]) FunctionType::new(vec![Type::I32], vec![Type::I32])
); );
assert_eq!( assert_eq!(
Func::new(func_i32_i32__i32).ty(), Function::new(func_i32_i32__i32).ty(),
FunctionType::new(vec![Type::I32, Type::I32], vec![Type::I32]) FunctionType::new(vec![Type::I32, Type::I32], vec![Type::I32])
); );
assert_eq!( assert_eq!(
Func::new(func_i32_i32__i32_i32).ty(), Function::new(func_i32_i32__i32_i32).ty(),
FunctionType::new(vec![Type::I32, Type::I32], vec![Type::I32, Type::I32]) FunctionType::new(vec![Type::I32, Type::I32], vec![Type::I32, Type::I32])
); );
assert_eq!( assert_eq!(
Func::new(func_f32_i32__i32_f32).ty(), Function::new(func_f32_i32__i32_f32).ty(),
FunctionType::new(vec![Type::F32, Type::I32], vec![Type::I32, Type::F32]) FunctionType::new(vec![Type::F32, Type::I32], vec![Type::I32, Type::F32])
); );
} }
#[test] #[test]
fn test_function_pointer() { fn test_function_pointer() {
let f = Func::new(func_i32__i32); let f = Function::new(func_i32__i32);
let function = unsafe { let function = unsafe {
std::mem::transmute::<*const FunctionBody, fn(i32, i32, i32) -> i32>(f.address) std::mem::transmute::<*const FunctionBody, fn(i32, i32, i32) -> i32>(f.address)
}; };
@@ -680,7 +680,7 @@ mod test_func {
pub num: i32, pub num: i32,
}; };
let mut my_env = Env { num: 2 }; let mut my_env = Env { num: 2 };
let f = Func::new_env(&mut my_env, func_i32__i32_env); let f = Function::new_env(&mut my_env, func_i32__i32_env);
let function = unsafe { let function = unsafe {
std::mem::transmute::<*const FunctionBody, fn(&mut Env, i32, i32) -> i32>(f.address) std::mem::transmute::<*const FunctionBody, fn(&mut Env, i32, i32) -> i32>(f.address)
}; };
@@ -690,7 +690,7 @@ mod test_func {
#[test] #[test]
fn test_function_call() { fn test_function_call() {
let f = Func::new(func_i32__i32); let f = Function::new(func_i32__i32);
let x = |args: <(i32, i32) as WasmTypeList>::Array, let x = |args: <(i32, i32) as WasmTypeList>::Array,
rets: &mut <(i32, i32) as WasmTypeList>::Array| { rets: &mut <(i32, i32) as WasmTypeList>::Array| {
let result = func_i32_i32__i32_i32(args[0] as _, args[1] as _); let result = func_i32_i32__i32_i32(args[0] as _, args[1] as _);

View File

@@ -121,7 +121,7 @@ impl Run {
// Try to instantiate the wasm file, with no provided imports // Try to instantiate the wasm file, with no provided imports
let imports = imports! {}; let imports = imports! {};
let instance = Instance::new(&module, &imports)?; let instance = Instance::new(&module, &imports)?;
let start: &Func = instance.exports.get("_start")?; let start: &Function = instance.exports.get("_start")?;
start.call(&[])?; start.call(&[])?;
Ok(()) Ok(())
@@ -185,7 +185,7 @@ impl Run {
invoke: &str, invoke: &str,
args: &Vec<String>, args: &Vec<String>,
) -> Result<Box<[Val]>> { ) -> Result<Box<[Val]>> {
let func: &Func = instance.exports.get(&invoke)?; let func: &Function = instance.exports.get(&invoke)?;
let func_ty = func.ty(); let func_ty = func.ty();
let required_arguments = func_ty.params().len(); let required_arguments = func_ty.params().len();
let provided_arguments = args.len(); let provided_arguments = args.len();

View File

@@ -1,7 +1,7 @@
use anyhow::{bail, Result}; use anyhow::{bail, Result};
use std::path::PathBuf; use std::path::PathBuf;
use wasmer::{Func, Instance, Memory, Module}; use wasmer::{Function, Instance, Memory, Module};
use wasmer_wasi::{ use wasmer_wasi::{
generate_import_object_from_env, get_wasi_version, WasiEnv, WasiState, WasiVersion, generate_import_object_from_env, get_wasi_version, WasiEnv, WasiState, WasiVersion,
}; };
@@ -114,7 +114,7 @@ impl Wasi {
let memory: &Memory = instance.exports.get("memory")?; let memory: &Memory = instance.exports.get("memory")?;
wasi_env.set_memory(memory); wasi_env.set_memory(memory);
let start: &Func = instance.exports.get("_start")?; let start: &Function = instance.exports.get("_start")?;
start.call(&[])?; start.call(&[])?;

View File

@@ -3,16 +3,16 @@ use wasmer::*;
/// Return an instance implementing the "spectest" interface used in the /// Return an instance implementing the "spectest" interface used in the
/// spec testsuite. /// spec testsuite.
pub fn spectest_importobject(store: &Store) -> ImportObject { pub fn spectest_importobject(store: &Store) -> ImportObject {
let print = Func::new(store, || {}); let print = Function::new(store, || {});
let print_i32 = Func::new(store, |val: i32| println!("{}: i32", val)); let print_i32 = Function::new(store, |val: i32| println!("{}: i32", val));
let print_i64 = Func::new(store, |val: i64| println!("{}: i64", val)); let print_i64 = Function::new(store, |val: i64| println!("{}: i64", val));
let print_f32 = Func::new(store, |val: f32| println!("{}: f32", val)); let print_f32 = Function::new(store, |val: f32| println!("{}: f32", val));
let print_f64 = Func::new(store, |val: f64| println!("{}: f64", val)); let print_f64 = Function::new(store, |val: f64| println!("{}: f64", val));
let print_i32_f32 = Func::new(store, |i: i32, f: f32| { let print_i32_f32 = Function::new(store, |i: i32, f: f32| {
println!("{}: i32", i); println!("{}: i32", i);
println!("{}: f32", f); println!("{}: f32", f);
}); });
let print_f64_f64 = Func::new(store, |f1: f64, f2: f64| { let print_f64_f64 = Function::new(store, |f1: f64, f2: f64| {
println!("{}: f64", f1); println!("{}: f64", f1);
println!("{}: f64", f2); println!("{}: f64", f2);
}); });

View File

@@ -306,7 +306,7 @@ impl Wast {
args: &[Val], args: &[Val],
) -> Result<Vec<Val>> { ) -> Result<Vec<Val>> {
let instance = self.get_instance(instance_name.as_ref().map(|x| &**x))?; let instance = self.get_instance(instance_name.as_ref().map(|x| &**x))?;
let func: &Func = instance.exports.get(field)?; let func: &Function = instance.exports.get(field)?;
match func.call(args) { match func.call(args) {
Ok(result) => Ok(result.into()), Ok(result) => Ok(result.into()),
Err(e) => Err(e.into()), Err(e) => Err(e.into()),