mirror of
https://github.com/mii443/wasmer.git
synced 2025-12-12 05:18:43 +00:00
Renamed wasmer::Func to wasmer::Function
This commit is contained in:
@@ -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 indexmap::IndexMap;
|
||||
use std::iter::FromIterator;
|
||||
@@ -103,7 +103,7 @@ impl Exports {
|
||||
}
|
||||
|
||||
/// 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)
|
||||
}
|
||||
|
||||
|
||||
@@ -16,7 +16,7 @@ use wasmer_runtime::{
|
||||
|
||||
#[derive(Clone)]
|
||||
pub enum Extern {
|
||||
Function(Func),
|
||||
Function(Function),
|
||||
Global(Global),
|
||||
Table(Table),
|
||||
Memory(Memory),
|
||||
@@ -34,7 +34,7 @@ impl Extern {
|
||||
|
||||
pub(crate) fn from_export(store: &Store, export: Export) -> Extern {
|
||||
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::Global(g) => Extern::Global(Global::from_export(store, g)),
|
||||
Export::Table(t) => Extern::Table(Table::from_export(store, t)),
|
||||
@@ -70,8 +70,8 @@ impl StoreObject for Extern {
|
||||
}
|
||||
}
|
||||
|
||||
impl From<Func> for Extern {
|
||||
fn from(r: Func) -> Self {
|
||||
impl From<Function> for Extern {
|
||||
fn from(r: Function) -> Self {
|
||||
Extern::Function(r)
|
||||
}
|
||||
}
|
||||
@@ -492,7 +492,7 @@ pub enum InnerFunc {
|
||||
|
||||
/// A WebAssembly `function`.
|
||||
#[derive(Clone, PartialEq)]
|
||||
pub struct Func {
|
||||
pub struct Function {
|
||||
store: Store,
|
||||
// If the Function is owned by the Store, not the instance
|
||||
inner: InnerFunc,
|
||||
@@ -500,12 +500,12 @@ pub struct Func {
|
||||
exported: ExportFunction,
|
||||
}
|
||||
|
||||
impl Func {
|
||||
impl Function {
|
||||
/// Creates a new `Func` with the given parameters.
|
||||
///
|
||||
/// * `store` - a global cache to store information in
|
||||
/// * `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
|
||||
F: HostFunction<Args, Rets, WithoutEnv, Env>,
|
||||
Args: WasmTypeList,
|
||||
@@ -517,7 +517,7 @@ impl Func {
|
||||
let vmctx = (func.env().unwrap_or(std::ptr::null_mut()) as *mut _) as *mut VMContext;
|
||||
let func_type = func.ty();
|
||||
let signature = store.engine().register_signature(&func_type);
|
||||
Func {
|
||||
Self {
|
||||
store: store.clone(),
|
||||
owned_by_store: true,
|
||||
inner: InnerFunc::Host(HostFunc {
|
||||
@@ -536,7 +536,7 @@ impl Func {
|
||||
/// * `store` - a global cache to store information in.
|
||||
/// * `env` - the function environment.
|
||||
/// * `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
|
||||
F: HostFunction<Args, Rets, WithEnv, Env>,
|
||||
Args: WasmTypeList,
|
||||
@@ -548,7 +548,7 @@ impl Func {
|
||||
let vmctx = (func.env().unwrap_or(std::ptr::null_mut()) as *mut _) as *mut VMContext;
|
||||
let func_type = func.ty();
|
||||
let signature = store.engine().register_signature(&func_type);
|
||||
Func {
|
||||
Self {
|
||||
store: store.clone(),
|
||||
owned_by_store: true,
|
||||
inner: InnerFunc::Host(HostFunc {
|
||||
@@ -662,9 +662,9 @@ impl Func {
|
||||
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();
|
||||
Func {
|
||||
Self {
|
||||
store: store.clone(),
|
||||
owned_by_store: false,
|
||||
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 {
|
||||
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 {
|
||||
Ok(())
|
||||
}
|
||||
|
||||
@@ -201,7 +201,7 @@ impl Extend<((String, String), Export)> for ImportObject {
|
||||
///
|
||||
/// let import_object = imports! {
|
||||
/// "env" => {
|
||||
/// "foo" => Func::new(&store, foo)
|
||||
/// "foo" => Function::new(&store, foo)
|
||||
/// }
|
||||
/// };
|
||||
///
|
||||
|
||||
@@ -13,7 +13,7 @@ mod tunables;
|
||||
mod types;
|
||||
|
||||
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::instance::Instance;
|
||||
pub use crate::memory_view::MemoryView;
|
||||
|
||||
@@ -1,4 +1,4 @@
|
||||
use crate::externals::Func;
|
||||
use crate::externals::Function;
|
||||
use crate::store::{Store, StoreObject};
|
||||
use crate::RuntimeError;
|
||||
use std::ptr;
|
||||
@@ -8,7 +8,7 @@ pub use wasm_common::{
|
||||
MemoryType, Mutability, TableType, Type as ValType,
|
||||
};
|
||||
|
||||
pub type Val = Value<Func>;
|
||||
pub type Val = Value<Function>;
|
||||
|
||||
impl StoreObject for Val {
|
||||
fn comes_from_same_store(&self, store: &Store) -> bool {
|
||||
@@ -21,8 +21,8 @@ impl StoreObject for Val {
|
||||
}
|
||||
}
|
||||
|
||||
impl From<Func> for Val {
|
||||
fn from(val: Func) -> Val {
|
||||
impl From<Function> for Val {
|
||||
fn from(val: Function) -> Val {
|
||||
Val::FuncRef(val)
|
||||
}
|
||||
}
|
||||
@@ -66,7 +66,7 @@ impl ValAnyFunc for Val {
|
||||
signature: item.type_index,
|
||||
vmctx: item.vmctx,
|
||||
};
|
||||
let f = Func::from_export(store, export);
|
||||
let f = Function::from_export(store, export);
|
||||
Val::FuncRef(f)
|
||||
}
|
||||
}
|
||||
|
||||
@@ -26,7 +26,7 @@ pub use crate::syscalls::types;
|
||||
pub use crate::utils::{get_wasi_version, is_wasi_module, WasiVersion};
|
||||
|
||||
use thiserror::Error;
|
||||
use wasmer::{imports, Func, ImportObject, Memory, Store};
|
||||
use wasmer::{imports, Function, ImportObject, Memory, Store};
|
||||
|
||||
/// This is returned in `RuntimeError`.
|
||||
/// 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 {
|
||||
imports! {
|
||||
"wasi_unstable" => {
|
||||
"args_get" => Func::new_env(store, env, args_get),
|
||||
"args_sizes_get" => Func::new_env(store, env, args_sizes_get),
|
||||
"clock_res_get" => Func::new_env(store, env, clock_res_get),
|
||||
"clock_time_get" => Func::new_env(store, env, clock_time_get),
|
||||
"environ_get" => Func::new_env(store, env, environ_get),
|
||||
"environ_sizes_get" => Func::new_env(store, env, environ_sizes_get),
|
||||
"fd_advise" => Func::new_env(store, env, fd_advise),
|
||||
"fd_allocate" => Func::new_env(store, env, fd_allocate),
|
||||
"fd_close" => Func::new_env(store, env, fd_close),
|
||||
"fd_datasync" => Func::new_env(store, env, fd_datasync),
|
||||
"fd_fdstat_get" => Func::new_env(store, env, fd_fdstat_get),
|
||||
"fd_fdstat_set_flags" => Func::new_env(store, env, fd_fdstat_set_flags),
|
||||
"fd_fdstat_set_rights" => Func::new_env(store, env, fd_fdstat_set_rights),
|
||||
"fd_filestat_get" => Func::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_times" => Func::new_env(store, env, fd_filestat_set_times),
|
||||
"fd_pread" => Func::new_env(store, env, fd_pread),
|
||||
"fd_prestat_get" => Func::new_env(store, env, fd_prestat_get),
|
||||
"fd_prestat_dir_name" => Func::new_env(store, env, fd_prestat_dir_name),
|
||||
"fd_pwrite" => Func::new_env(store, env, fd_pwrite),
|
||||
"fd_read" => Func::new_env(store, env, fd_read),
|
||||
"fd_readdir" => Func::new_env(store, env, fd_readdir),
|
||||
"fd_renumber" => Func::new_env(store, env, fd_renumber),
|
||||
"fd_seek" => Func::new_env(store, env, legacy::snapshot0::fd_seek),
|
||||
"fd_sync" => Func::new_env(store, env, fd_sync),
|
||||
"fd_tell" => Func::new_env(store, env, fd_tell),
|
||||
"fd_write" => Func::new_env(store, env, fd_write),
|
||||
"path_create_directory" => Func::new_env(store, env, path_create_directory),
|
||||
"path_filestat_get" => Func::new_env(store, env, legacy::snapshot0::path_filestat_get),
|
||||
"path_filestat_set_times" => Func::new_env(store, env, path_filestat_set_times),
|
||||
"path_link" => Func::new_env(store, env, path_link),
|
||||
"path_open" => Func::new_env(store, env, path_open),
|
||||
"path_readlink" => Func::new_env(store, env, path_readlink),
|
||||
"path_remove_directory" => Func::new_env(store, env, path_remove_directory),
|
||||
"path_rename" => Func::new_env(store, env, path_rename),
|
||||
"path_symlink" => Func::new_env(store, env, path_symlink),
|
||||
"path_unlink_file" => Func::new_env(store, env, path_unlink_file),
|
||||
"poll_oneoff" => Func::new_env(store, env, legacy::snapshot0::poll_oneoff),
|
||||
"proc_exit" => Func::new_env(store, env, proc_exit),
|
||||
"proc_raise" => Func::new_env(store, env, proc_raise),
|
||||
"random_get" => Func::new_env(store, env, random_get),
|
||||
"sched_yield" => Func::new_env(store, env, sched_yield),
|
||||
"sock_recv" => Func::new_env(store, env, sock_recv),
|
||||
"sock_send" => Func::new_env(store, env, sock_send),
|
||||
"sock_shutdown" => Func::new_env(store, env, sock_shutdown),
|
||||
"args_get" => Function::new_env(store, env, args_get),
|
||||
"args_sizes_get" => Function::new_env(store, env, args_sizes_get),
|
||||
"clock_res_get" => Function::new_env(store, env, clock_res_get),
|
||||
"clock_time_get" => Function::new_env(store, env, clock_time_get),
|
||||
"environ_get" => Function::new_env(store, env, environ_get),
|
||||
"environ_sizes_get" => Function::new_env(store, env, environ_sizes_get),
|
||||
"fd_advise" => Function::new_env(store, env, fd_advise),
|
||||
"fd_allocate" => Function::new_env(store, env, fd_allocate),
|
||||
"fd_close" => Function::new_env(store, env, fd_close),
|
||||
"fd_datasync" => Function::new_env(store, env, fd_datasync),
|
||||
"fd_fdstat_get" => Function::new_env(store, env, fd_fdstat_get),
|
||||
"fd_fdstat_set_flags" => Function::new_env(store, env, fd_fdstat_set_flags),
|
||||
"fd_fdstat_set_rights" => Function::new_env(store, env, fd_fdstat_set_rights),
|
||||
"fd_filestat_get" => Function::new_env(store, env, legacy::snapshot0::fd_filestat_get),
|
||||
"fd_filestat_set_size" => Function::new_env(store, env, fd_filestat_set_size),
|
||||
"fd_filestat_set_times" => Function::new_env(store, env, fd_filestat_set_times),
|
||||
"fd_pread" => Function::new_env(store, env, fd_pread),
|
||||
"fd_prestat_get" => Function::new_env(store, env, fd_prestat_get),
|
||||
"fd_prestat_dir_name" => Function::new_env(store, env, fd_prestat_dir_name),
|
||||
"fd_pwrite" => Function::new_env(store, env, fd_pwrite),
|
||||
"fd_read" => Function::new_env(store, env, fd_read),
|
||||
"fd_readdir" => Function::new_env(store, env, fd_readdir),
|
||||
"fd_renumber" => Function::new_env(store, env, fd_renumber),
|
||||
"fd_seek" => Function::new_env(store, env, legacy::snapshot0::fd_seek),
|
||||
"fd_sync" => Function::new_env(store, env, fd_sync),
|
||||
"fd_tell" => Function::new_env(store, env, fd_tell),
|
||||
"fd_write" => Function::new_env(store, env, fd_write),
|
||||
"path_create_directory" => Function::new_env(store, env, path_create_directory),
|
||||
"path_filestat_get" => Function::new_env(store, env, legacy::snapshot0::path_filestat_get),
|
||||
"path_filestat_set_times" => Function::new_env(store, env, path_filestat_set_times),
|
||||
"path_link" => Function::new_env(store, env, path_link),
|
||||
"path_open" => Function::new_env(store, env, path_open),
|
||||
"path_readlink" => Function::new_env(store, env, path_readlink),
|
||||
"path_remove_directory" => Function::new_env(store, env, path_remove_directory),
|
||||
"path_rename" => Function::new_env(store, env, path_rename),
|
||||
"path_symlink" => Function::new_env(store, env, path_symlink),
|
||||
"path_unlink_file" => Function::new_env(store, env, path_unlink_file),
|
||||
"poll_oneoff" => Function::new_env(store, env, legacy::snapshot0::poll_oneoff),
|
||||
"proc_exit" => Function::new_env(store, env, proc_exit),
|
||||
"proc_raise" => Function::new_env(store, env, proc_raise),
|
||||
"random_get" => Function::new_env(store, env, random_get),
|
||||
"sched_yield" => Function::new_env(store, env, sched_yield),
|
||||
"sock_recv" => Function::new_env(store, env, sock_recv),
|
||||
"sock_send" => Function::new_env(store, env, sock_send),
|
||||
"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 {
|
||||
imports! {
|
||||
"wasi_snapshot_preview1" => {
|
||||
"args_get" => Func::new_env(store, env, args_get),
|
||||
"args_sizes_get" => Func::new_env(store, env, args_sizes_get),
|
||||
"clock_res_get" => Func::new_env(store, env, clock_res_get),
|
||||
"clock_time_get" => Func::new_env(store, env, clock_time_get),
|
||||
"environ_get" => Func::new_env(store, env, environ_get),
|
||||
"environ_sizes_get" => Func::new_env(store, env, environ_sizes_get),
|
||||
"fd_advise" => Func::new_env(store, env, fd_advise),
|
||||
"fd_allocate" => Func::new_env(store, env, fd_allocate),
|
||||
"fd_close" => Func::new_env(store, env, fd_close),
|
||||
"fd_datasync" => Func::new_env(store, env, fd_datasync),
|
||||
"fd_fdstat_get" => Func::new_env(store, env, fd_fdstat_get),
|
||||
"fd_fdstat_set_flags" => Func::new_env(store, env, fd_fdstat_set_flags),
|
||||
"fd_fdstat_set_rights" => Func::new_env(store, env, fd_fdstat_set_rights),
|
||||
"fd_filestat_get" => Func::new_env(store, env, fd_filestat_get),
|
||||
"fd_filestat_set_size" => Func::new_env(store, env, fd_filestat_set_size),
|
||||
"fd_filestat_set_times" => Func::new_env(store, env, fd_filestat_set_times),
|
||||
"fd_pread" => Func::new_env(store, env, fd_pread),
|
||||
"fd_prestat_get" => Func::new_env(store, env, fd_prestat_get),
|
||||
"fd_prestat_dir_name" => Func::new_env(store, env, fd_prestat_dir_name),
|
||||
"fd_pwrite" => Func::new_env(store, env, fd_pwrite),
|
||||
"fd_read" => Func::new_env(store, env, fd_read),
|
||||
"fd_readdir" => Func::new_env(store, env, fd_readdir),
|
||||
"fd_renumber" => Func::new_env(store, env, fd_renumber),
|
||||
"fd_seek" => Func::new_env(store, env, fd_seek),
|
||||
"fd_sync" => Func::new_env(store, env, fd_sync),
|
||||
"fd_tell" => Func::new_env(store, env, fd_tell),
|
||||
"fd_write" => Func::new_env(store, env, fd_write),
|
||||
"path_create_directory" => Func::new_env(store, env, path_create_directory),
|
||||
"path_filestat_get" => Func::new_env(store, env, path_filestat_get),
|
||||
"path_filestat_set_times" => Func::new_env(store, env, path_filestat_set_times),
|
||||
"path_link" => Func::new_env(store, env, path_link),
|
||||
"path_open" => Func::new_env(store, env, path_open),
|
||||
"path_readlink" => Func::new_env(store, env, path_readlink),
|
||||
"path_remove_directory" => Func::new_env(store, env, path_remove_directory),
|
||||
"path_rename" => Func::new_env(store, env, path_rename),
|
||||
"path_symlink" => Func::new_env(store, env, path_symlink),
|
||||
"path_unlink_file" => Func::new_env(store, env, path_unlink_file),
|
||||
"poll_oneoff" => Func::new_env(store, env, poll_oneoff),
|
||||
"proc_exit" => Func::new_env(store, env, proc_exit),
|
||||
"proc_raise" => Func::new_env(store, env, proc_raise),
|
||||
"random_get" => Func::new_env(store, env, random_get),
|
||||
"sched_yield" => Func::new_env(store, env, sched_yield),
|
||||
"sock_recv" => Func::new_env(store, env, sock_recv),
|
||||
"sock_send" => Func::new_env(store, env, sock_send),
|
||||
"sock_shutdown" => Func::new_env(store, env, sock_shutdown),
|
||||
"args_get" => Function::new_env(store, env, args_get),
|
||||
"args_sizes_get" => Function::new_env(store, env, args_sizes_get),
|
||||
"clock_res_get" => Function::new_env(store, env, clock_res_get),
|
||||
"clock_time_get" => Function::new_env(store, env, clock_time_get),
|
||||
"environ_get" => Function::new_env(store, env, environ_get),
|
||||
"environ_sizes_get" => Function::new_env(store, env, environ_sizes_get),
|
||||
"fd_advise" => Function::new_env(store, env, fd_advise),
|
||||
"fd_allocate" => Function::new_env(store, env, fd_allocate),
|
||||
"fd_close" => Function::new_env(store, env, fd_close),
|
||||
"fd_datasync" => Function::new_env(store, env, fd_datasync),
|
||||
"fd_fdstat_get" => Function::new_env(store, env, fd_fdstat_get),
|
||||
"fd_fdstat_set_flags" => Function::new_env(store, env, fd_fdstat_set_flags),
|
||||
"fd_fdstat_set_rights" => Function::new_env(store, env, fd_fdstat_set_rights),
|
||||
"fd_filestat_get" => Function::new_env(store, env, fd_filestat_get),
|
||||
"fd_filestat_set_size" => Function::new_env(store, env, fd_filestat_set_size),
|
||||
"fd_filestat_set_times" => Function::new_env(store, env, fd_filestat_set_times),
|
||||
"fd_pread" => Function::new_env(store, env, fd_pread),
|
||||
"fd_prestat_get" => Function::new_env(store, env, fd_prestat_get),
|
||||
"fd_prestat_dir_name" => Function::new_env(store, env, fd_prestat_dir_name),
|
||||
"fd_pwrite" => Function::new_env(store, env, fd_pwrite),
|
||||
"fd_read" => Function::new_env(store, env, fd_read),
|
||||
"fd_readdir" => Function::new_env(store, env, fd_readdir),
|
||||
"fd_renumber" => Function::new_env(store, env, fd_renumber),
|
||||
"fd_seek" => Function::new_env(store, env, fd_seek),
|
||||
"fd_sync" => Function::new_env(store, env, fd_sync),
|
||||
"fd_tell" => Function::new_env(store, env, fd_tell),
|
||||
"fd_write" => Function::new_env(store, env, fd_write),
|
||||
"path_create_directory" => Function::new_env(store, env, path_create_directory),
|
||||
"path_filestat_get" => Function::new_env(store, env, path_filestat_get),
|
||||
"path_filestat_set_times" => Function::new_env(store, env, path_filestat_set_times),
|
||||
"path_link" => Function::new_env(store, env, path_link),
|
||||
"path_open" => Function::new_env(store, env, path_open),
|
||||
"path_readlink" => Function::new_env(store, env, path_readlink),
|
||||
"path_remove_directory" => Function::new_env(store, env, path_remove_directory),
|
||||
"path_rename" => Function::new_env(store, env, path_rename),
|
||||
"path_symlink" => Function::new_env(store, env, path_symlink),
|
||||
"path_unlink_file" => Function::new_env(store, env, path_unlink_file),
|
||||
"poll_oneoff" => Function::new_env(store, env, poll_oneoff),
|
||||
"proc_exit" => Function::new_env(store, env, proc_exit),
|
||||
"proc_raise" => Function::new_env(store, env, proc_raise),
|
||||
"random_get" => Function::new_env(store, env, random_get),
|
||||
"sched_yield" => Function::new_env(store, env, sched_yield),
|
||||
"sock_recv" => Function::new_env(store, env, sock_recv),
|
||||
"sock_send" => Function::new_env(store, env, sock_send),
|
||||
"sock_shutdown" => Function::new_env(store, env, sock_shutdown),
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -633,36 +633,36 @@ mod test_func {
|
||||
|
||||
#[test]
|
||||
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!(
|
||||
Func::new(func__i32).ty(),
|
||||
Function::new(func__i32).ty(),
|
||||
FunctionType::new(vec![], vec![Type::I32])
|
||||
);
|
||||
assert_eq!(
|
||||
Func::new(func_i32).ty(),
|
||||
Function::new(func_i32).ty(),
|
||||
FunctionType::new(vec![Type::I32], vec![])
|
||||
);
|
||||
assert_eq!(
|
||||
Func::new(func_i32__i32).ty(),
|
||||
Function::new(func_i32__i32).ty(),
|
||||
FunctionType::new(vec![Type::I32], vec![Type::I32])
|
||||
);
|
||||
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])
|
||||
);
|
||||
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])
|
||||
);
|
||||
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])
|
||||
);
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn test_function_pointer() {
|
||||
let f = Func::new(func_i32__i32);
|
||||
let f = Function::new(func_i32__i32);
|
||||
let function = unsafe {
|
||||
std::mem::transmute::<*const FunctionBody, fn(i32, i32, i32) -> i32>(f.address)
|
||||
};
|
||||
@@ -680,7 +680,7 @@ mod test_func {
|
||||
pub num: i32,
|
||||
};
|
||||
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 {
|
||||
std::mem::transmute::<*const FunctionBody, fn(&mut Env, i32, i32) -> i32>(f.address)
|
||||
};
|
||||
@@ -690,7 +690,7 @@ mod test_func {
|
||||
|
||||
#[test]
|
||||
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,
|
||||
rets: &mut <(i32, i32) as WasmTypeList>::Array| {
|
||||
let result = func_i32_i32__i32_i32(args[0] as _, args[1] as _);
|
||||
|
||||
@@ -121,7 +121,7 @@ impl Run {
|
||||
// Try to instantiate the wasm file, with no provided imports
|
||||
let imports = imports! {};
|
||||
let instance = Instance::new(&module, &imports)?;
|
||||
let start: &Func = instance.exports.get("_start")?;
|
||||
let start: &Function = instance.exports.get("_start")?;
|
||||
start.call(&[])?;
|
||||
|
||||
Ok(())
|
||||
@@ -185,7 +185,7 @@ impl Run {
|
||||
invoke: &str,
|
||||
args: &Vec<String>,
|
||||
) -> Result<Box<[Val]>> {
|
||||
let func: &Func = instance.exports.get(&invoke)?;
|
||||
let func: &Function = instance.exports.get(&invoke)?;
|
||||
let func_ty = func.ty();
|
||||
let required_arguments = func_ty.params().len();
|
||||
let provided_arguments = args.len();
|
||||
|
||||
@@ -1,7 +1,7 @@
|
||||
use anyhow::{bail, Result};
|
||||
use std::path::PathBuf;
|
||||
|
||||
use wasmer::{Func, Instance, Memory, Module};
|
||||
use wasmer::{Function, Instance, Memory, Module};
|
||||
use wasmer_wasi::{
|
||||
generate_import_object_from_env, get_wasi_version, WasiEnv, WasiState, WasiVersion,
|
||||
};
|
||||
@@ -114,7 +114,7 @@ impl Wasi {
|
||||
let memory: &Memory = instance.exports.get("memory")?;
|
||||
wasi_env.set_memory(memory);
|
||||
|
||||
let start: &Func = instance.exports.get("_start")?;
|
||||
let start: &Function = instance.exports.get("_start")?;
|
||||
|
||||
start.call(&[])?;
|
||||
|
||||
|
||||
@@ -3,16 +3,16 @@ use wasmer::*;
|
||||
/// Return an instance implementing the "spectest" interface used in the
|
||||
/// spec testsuite.
|
||||
pub fn spectest_importobject(store: &Store) -> ImportObject {
|
||||
let print = Func::new(store, || {});
|
||||
let print_i32 = Func::new(store, |val: i32| println!("{}: i32", val));
|
||||
let print_i64 = Func::new(store, |val: i64| println!("{}: i64", val));
|
||||
let print_f32 = Func::new(store, |val: f32| println!("{}: f32", val));
|
||||
let print_f64 = Func::new(store, |val: f64| println!("{}: f64", val));
|
||||
let print_i32_f32 = Func::new(store, |i: i32, f: f32| {
|
||||
let print = Function::new(store, || {});
|
||||
let print_i32 = Function::new(store, |val: i32| println!("{}: i32", val));
|
||||
let print_i64 = Function::new(store, |val: i64| println!("{}: i64", val));
|
||||
let print_f32 = Function::new(store, |val: f32| println!("{}: f32", val));
|
||||
let print_f64 = Function::new(store, |val: f64| println!("{}: f64", val));
|
||||
let print_i32_f32 = Function::new(store, |i: i32, f: f32| {
|
||||
println!("{}: i32", i);
|
||||
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", f2);
|
||||
});
|
||||
|
||||
@@ -306,7 +306,7 @@ impl Wast {
|
||||
args: &[Val],
|
||||
) -> Result<Vec<Val>> {
|
||||
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) {
|
||||
Ok(result) => Ok(result.into()),
|
||||
Err(e) => Err(e.into()),
|
||||
|
||||
Reference in New Issue
Block a user