diff --git a/examples/early_exit.rs b/examples/early_exit.rs index f58244789..1a0ec8e37 100644 --- a/examples/early_exit.rs +++ b/examples/early_exit.rs @@ -16,10 +16,7 @@ use anyhow::bail; use std::fmt; -use wasmer::{ - imports, wat2wasm, Function, FunctionEnv, FunctionEnvMut, Instance, Module, Store, - TypedFunction, -}; +use wasmer::{imports, wat2wasm, Function, FunctionEnvMut, Instance, Module, Store, TypedFunction}; use wasmer_compiler_cranelift::Cranelift; // First we need to create an error type that we'll use to signal the end of execution. @@ -58,7 +55,6 @@ fn main() -> anyhow::Result<()> { // the default provided by Wasmer. // You can use `Store::default()` for that. let mut store = Store::new(Cranelift::default()); - let env = FunctionEnv::new(&mut store, ()); println!("Compiling module..."); // Let's compile the Wasm module. @@ -73,7 +69,7 @@ fn main() -> anyhow::Result<()> { // Create an import object. let import_object = imports! { "env" => { - "early_exit" => Function::new_native(&mut store, &env, early_exit), + "early_exit" => Function::new_typed(&mut store, early_exit), } }; diff --git a/examples/engine_headless.rs b/examples/engine_headless.rs index 6ff9c95d2..c0cbf2b33 100644 --- a/examples/engine_headless.rs +++ b/examples/engine_headless.rs @@ -45,7 +45,7 @@ //! Ready? use tempfile::NamedTempFile; -use wasmer::{imports, wat2wasm, EngineBuilder, FunctionEnv, Instance, Module, Store, Value}; +use wasmer::{imports, wat2wasm, EngineBuilder, Instance, Module, Store, Value}; use wasmer_compiler_cranelift::Cranelift; fn main() -> Result<(), Box> { diff --git a/examples/errors.rs b/examples/errors.rs index d2bedfbf6..c2035cbcd 100644 --- a/examples/errors.rs +++ b/examples/errors.rs @@ -13,7 +13,7 @@ //! //! Ready? -use wasmer::{imports, wat2wasm, FunctionEnv, Instance, Module, Store, TypedFunction}; +use wasmer::{imports, wat2wasm, Instance, Module, Store, TypedFunction}; use wasmer_compiler_cranelift::Cranelift; fn main() -> Result<(), Box> { @@ -61,7 +61,7 @@ fn main() -> Result<(), Box> { let div_by_zero: TypedFunction<(), i32> = instance .exports .get_function("div_by_zero")? - .native(&mut store)?; + .typed(&mut store)?; println!("Calling `div_by_zero` function..."); // Let's call the `div_by_zero` exported function. diff --git a/examples/exports_function.rs b/examples/exports_function.rs index 958a86d09..4eb9cf5f6 100644 --- a/examples/exports_function.rs +++ b/examples/exports_function.rs @@ -17,7 +17,7 @@ //! //! Ready? -use wasmer::{imports, wat2wasm, FunctionEnv, Instance, Module, Store, TypedFunction, Value}; +use wasmer::{imports, wat2wasm, Instance, Module, Store, TypedFunction, Value}; use wasmer_compiler_cranelift::Cranelift; fn main() -> Result<(), Box> { @@ -81,17 +81,17 @@ fn main() -> Result<(), Box> { // that's possible with the `TypedFunction` API. The function // will use native Rust values. // - // Note that `native` takes 2 generic parameters: `Args` and + // Note that `typed` takes 2 generic parameters: `Args` and // `Rets`, respectively for the parameters and the results. If // those values don't match the exported function signature, an // error will be raised. - let sum_native: TypedFunction<(i32, i32), i32> = sum.native(&mut store)?; + let sum_typed: TypedFunction<(i32, i32), i32> = sum.typed(&mut store)?; println!("Calling `sum` function (natively)..."); // Let's call the `sum` exported function. The parameters are // statically typed Rust values of type `i32` and `i32`. The // result, in this case particular case, in a unit of type `i32`. - let result = sum_native.call(&mut store, 3, 4)?; + let result = sum_typed.call(&mut store, 3, 4)?; println!("Results: {:?}", result); assert_eq!(result, 7); diff --git a/examples/exports_global.rs b/examples/exports_global.rs index 06921b0d8..86787d878 100644 --- a/examples/exports_global.rs +++ b/examples/exports_global.rs @@ -15,9 +15,7 @@ //! //! Ready? -use wasmer::{ - imports, wat2wasm, FunctionEnv, Instance, Module, Mutability, Store, Type, TypedFunction, Value, -}; +use wasmer::{imports, wat2wasm, Instance, Module, Mutability, Store, Type, TypedFunction, Value}; use wasmer_compiler_cranelift::Cranelift; fn main() -> Result<(), Box> { @@ -92,7 +90,7 @@ fn main() -> Result<(), Box> { let get_one: TypedFunction<(), f32> = instance .exports .get_function("get_one")? - .native(&mut store)?; + .typed(&mut store)?; let one_value = get_one.call(&mut store)?; let some_value = some.get(&mut store); @@ -124,7 +122,7 @@ fn main() -> Result<(), Box> { let set_some: TypedFunction = instance .exports .get_function("set_some")? - .native(&mut store)?; + .typed(&mut store)?; set_some.call(&mut store, 21.0)?; let some_result = some.get(&mut store); println!("`some` value after `set_some`: {:?}", some_result); diff --git a/examples/exports_memory.rs b/examples/exports_memory.rs index c6c3d058e..f3b4a7d4b 100644 --- a/examples/exports_memory.rs +++ b/examples/exports_memory.rs @@ -11,7 +11,7 @@ //! //! Ready? -use wasmer::{imports, wat2wasm, FunctionEnv, Instance, Module, Store, TypedFunction, WasmPtr}; +use wasmer::{imports, wat2wasm, Instance, Module, Store, TypedFunction, WasmPtr}; use wasmer_compiler_cranelift::Cranelift; fn main() -> Result<(), Box> { diff --git a/examples/features.rs b/examples/features.rs index 4f8a80038..28ea86e7e 100644 --- a/examples/features.rs +++ b/examples/features.rs @@ -10,9 +10,7 @@ //! //! Ready? -use wasmer::{ - imports, wat2wasm, EngineBuilder, Features, FunctionEnv, Instance, Module, Store, Value, -}; +use wasmer::{imports, wat2wasm, EngineBuilder, Features, Instance, Module, Store, Value}; use wasmer_compiler_cranelift::Cranelift; fn main() -> anyhow::Result<()> { diff --git a/examples/hello_world.rs b/examples/hello_world.rs index 73ad8620a..0b5221f47 100644 --- a/examples/hello_world.rs +++ b/examples/hello_world.rs @@ -6,10 +6,7 @@ //! cargo run --example hello-world --release --features "cranelift" //! ``` -use wasmer::{ - imports, wat2wasm, Function, FunctionEnv, FunctionEnvMut, Instance, Module, Store, - TypedFunction, -}; +use wasmer::{imports, wat2wasm, Function, FunctionEnvMut, Instance, Module, Store, TypedFunction}; use wasmer_compiler_cranelift::Cranelift; fn main() -> anyhow::Result<()> { @@ -52,10 +49,6 @@ fn main() -> anyhow::Result<()> { // A `Module` is a compiled WebAssembly module that isn't ready to execute yet. let module = Module::new(&store, wasm_bytes)?; - // Next we'll set up our `Module` so that we can execute it. First, create - // a `FunctionEnv` in which to instantiate our `Module`. - let context = FunctionEnv::new(&mut store, ()); - // We define a function to act as our "env" "say_hello" function imported in the // Wasm program above. fn say_hello_world(_env: FunctionEnvMut<'_, ()>) { @@ -67,7 +60,7 @@ fn main() -> anyhow::Result<()> { // We use the default namespace "env". "env" => { // And call our function "say_hello". - "say_hello" => Function::new_native(&mut store, &context, say_hello_world), + "say_hello" => Function::new_typed(&mut store, say_hello_world), } }; diff --git a/examples/imports_exports.rs b/examples/imports_exports.rs index c8d187041..93ac580da 100644 --- a/examples/imports_exports.rs +++ b/examples/imports_exports.rs @@ -16,8 +16,8 @@ //! Ready? use wasmer::{ - imports, wat2wasm, Function, FunctionEnv, FunctionType, Global, Instance, Memory, Module, - Store, Table, Type, Value, + imports, wat2wasm, Function, FunctionType, Global, Instance, Memory, Module, Store, Table, + Type, Value, }; use wasmer_compiler_cranelift::Cranelift; @@ -44,7 +44,6 @@ fn main() -> Result<(), Box> { // the default provided by Wasmer. // You can use `Store::default()` for that. let mut store = Store::new(Cranelift::default()); - let env = FunctionEnv::new(&mut store, ()); println!("Compiling module..."); // Let's compile the Wasm module. @@ -59,7 +58,7 @@ fn main() -> Result<(), Box> { // covered in more detail in other examples. println!("Creating the imported function..."); let host_function_signature = FunctionType::new(vec![], vec![Type::I32]); - let host_function = Function::new(&mut store, &env, &host_function_signature, |_env, _args| { + let host_function = Function::new(&mut store, &host_function_signature, |_env, _args| { Ok(vec![Value::I32(42)]) }); diff --git a/examples/imports_function.rs b/examples/imports_function.rs index d454cc8d0..a93d936af 100644 --- a/examples/imports_function.rs +++ b/examples/imports_function.rs @@ -29,12 +29,12 @@ fn main() -> Result<(), Box> { br#" (module (func $multiply_dynamic (import "env" "multiply_dynamic") (param i32) (result i32)) - (func $multiply_native (import "env" "multiply_native") (param i32) (result i32)) + (func $multiply_typed (import "env" "multiply_typed") (param i32) (result i32)) (type $sum_t (func (param i32) (param i32) (result i32))) (func $sum_f (type $sum_t) (param $x i32) (param $y i32) (result i32) (call $multiply_dynamic (local.get $x)) - (call $multiply_native (local.get $y)) + (call $multiply_typed (local.get $y)) i32.add) (export "sum" (func $sum_f))) "#, @@ -45,9 +45,8 @@ fn main() -> Result<(), Box> { // the default provided by Wasmer. // You can use `Store::default()` for that. let mut store = Store::new(Cranelift::default()); - let env1 = FunctionEnv::new(&mut store, ()); struct MyEnv; - let env2 = FunctionEnv::new(&mut store, MyEnv {}); + let env = FunctionEnv::new(&mut store, MyEnv {}); println!("Compiling module..."); // Let's compile the Wasm module. @@ -55,36 +54,31 @@ fn main() -> Result<(), Box> { // Create the functions let multiply_dynamic_signature = FunctionType::new(vec![Type::I32], vec![Type::I32]); - let multiply_dynamic = Function::new( - &mut store, - &env1, - &multiply_dynamic_signature, - |_env, args| { - println!("Calling `multiply_dynamic`..."); + let multiply_dynamic = Function::new(&mut store, &multiply_dynamic_signature, |_env, args| { + println!("Calling `multiply_dynamic`..."); - let result = args[0].unwrap_i32() * 2; + let result = args[0].unwrap_i32() * 2; - println!("Result of `multiply_dynamic`: {:?}", result); + println!("Result of `multiply_dynamic`: {:?}", result); - Ok(vec![Value::I32(result)]) - }, - ); + Ok(vec![Value::I32(result)]) + }); fn multiply(_env: FunctionEnvMut, a: i32) -> i32 { - println!("Calling `multiply_native`..."); + println!("Calling `multiply_typed`..."); let result = a * 3; - println!("Result of `multiply_native`: {:?}", result); + println!("Result of `multiply_typed`: {:?}", result); result } - let multiply_native = Function::new_native(&mut store, &env2, multiply); + let multiply_typed = Function::new_typed_with_env(&mut store, &env, multiply); // Create an import object. let import_object = imports! { "env" => { "multiply_dynamic" => multiply_dynamic, - "multiply_native" => multiply_native, + "multiply_typed" => multiply_typed, } }; @@ -96,7 +90,7 @@ fn main() -> Result<(), Box> { // // The Wasm module exports a function called `sum`. Let's get it. let sum: TypedFunction<(i32, i32), i32> = - instance.exports.get_function("sum")?.native(&mut store)?; + instance.exports.get_function("sum")?.typed(&mut store)?; println!("Calling `sum` function..."); // Let's call the `sum` exported function. It will call each diff --git a/examples/imports_function_env.rs b/examples/imports_function_env.rs index e56e45bbb..dc870625e 100644 --- a/examples/imports_function_env.rs +++ b/examples/imports_function_env.rs @@ -97,8 +97,8 @@ fn main() -> Result<(), Box> { // Create an import object. let import_object = imports! { "env" => { - "get_counter" => Function::new_native(&mut store, &env, get_counter), - "add_to_counter" => Function::new_native(&mut store, &env, add_to_counter), + "get_counter" => Function::new_typed_with_env(&mut store, &env, get_counter), + "add_to_counter" => Function::new_typed_with_env(&mut store, &env, add_to_counter), } }; @@ -112,7 +112,7 @@ fn main() -> Result<(), Box> { let increment_counter_loop: TypedFunction = instance .exports .get_function("increment_counter_loop")? - .native(&mut store)?; + .typed(&mut store)?; let counter_value: i32 = *shared_counter.lock().unwrap(); println!("Initial ounter value: {:?}", counter_value); diff --git a/examples/imports_global.rs b/examples/imports_global.rs index a00c97564..44a2946c9 100644 --- a/examples/imports_global.rs +++ b/examples/imports_global.rs @@ -15,9 +15,7 @@ //! //! Ready? -use wasmer::{ - imports, wat2wasm, FunctionEnv, Global, Instance, Module, Store, TypedFunction, Value, -}; +use wasmer::{imports, wat2wasm, Global, Instance, Module, Store, TypedFunction, Value}; use wasmer_compiler_cranelift::Cranelift; fn main() -> Result<(), Box> { @@ -69,11 +67,11 @@ fn main() -> Result<(), Box> { let get_some: TypedFunction<(), f32> = instance .exports .get_function("get_some")? - .native(&mut store)?; + .typed(&mut store)?; let get_other: TypedFunction<(), f32> = instance .exports .get_function("get_other")? - .native(&mut store)?; + .typed(&mut store)?; let some_result = get_some.call(&mut store)?; let other_result = get_other.call(&mut store)?; @@ -106,7 +104,7 @@ fn main() -> Result<(), Box> { let set_other: TypedFunction = instance .exports .get_function("set_other")? - .native(&mut store)?; + .typed(&mut store)?; set_other.call(&mut store, 42.0)?; println!("other value (via Global API): {:?}", other.get(&mut store)); diff --git a/examples/instance.rs b/examples/instance.rs index e563af07e..fa57d2dc6 100644 --- a/examples/instance.rs +++ b/examples/instance.rs @@ -14,7 +14,7 @@ //! //! Ready? -use wasmer::{imports, wat2wasm, FunctionEnv, Instance, Module, Store, TypedFunction}; +use wasmer::{imports, wat2wasm, Instance, Module, Store, TypedFunction}; use wasmer_compiler_cranelift::Cranelift; fn main() -> Result<(), Box> { @@ -62,7 +62,7 @@ fn main() -> Result<(), Box> { let add_one: TypedFunction = instance .exports .get_function("add_one")? - .native(&mut store)?; + .typed(&mut store)?; println!("Calling `add_one` function..."); let result = add_one.call(&mut store, 1)?; diff --git a/examples/memory.rs b/examples/memory.rs index 3cd1815a1..030d014fc 100644 --- a/examples/memory.rs +++ b/examples/memory.rs @@ -15,9 +15,7 @@ //! Ready? use std::mem; -use wasmer::{ - imports, wat2wasm, Bytes, FunctionEnv, Instance, Module, Pages, Store, TypedFunction, -}; +use wasmer::{imports, wat2wasm, Bytes, Instance, Module, Pages, Store, TypedFunction}; use wasmer_compiler_cranelift::Cranelift; // this example is a work in progress: diff --git a/examples/metering.rs b/examples/metering.rs index 0d37491e0..e5d8c70d7 100644 --- a/examples/metering.rs +++ b/examples/metering.rs @@ -18,9 +18,7 @@ use anyhow::bail; use std::sync::Arc; use wasmer::wasmparser::Operator; use wasmer::CompilerConfig; -use wasmer::{ - imports, wat2wasm, EngineBuilder, FunctionEnv, Instance, Module, Store, TypedFunction, -}; +use wasmer::{imports, wat2wasm, EngineBuilder, Instance, Module, Store, TypedFunction}; use wasmer_compiler_cranelift::Cranelift; use wasmer_middlewares::{ metering::{get_remaining_points, set_remaining_points, MeteringPoints}, @@ -91,7 +89,7 @@ fn main() -> anyhow::Result<()> { let add_one: TypedFunction = instance .exports .get_function("add_one")? - .native(&mut store)?; + .typed(&mut store)?; println!("Calling `add_one` function once..."); add_one.call(&mut store, 1)?; diff --git a/examples/table.rs b/examples/table.rs index 17a5b50e6..c3b9b35b7 100644 --- a/examples/table.rs +++ b/examples/table.rs @@ -1,6 +1,6 @@ use wasmer::{ - imports, wat2wasm, Function, FunctionEnv, FunctionEnvMut, Instance, Module, Store, TableType, - Type, TypedFunction, Value, + imports, wat2wasm, Function, FunctionEnvMut, Instance, Module, Store, TableType, Type, + TypedFunction, Value, }; use wasmer_compiler_cranelift::Cranelift; @@ -52,7 +52,6 @@ fn main() -> anyhow::Result<()> { // We set up our store with an engine and a compiler. let mut store = Store::new(Cranelift::default()); - let env = FunctionEnv::new(&mut store, ()); // Then compile our Wasm. let module = Module::new(&store, wasm_bytes)?; let import_object = imports! {}; @@ -88,7 +87,7 @@ fn main() -> anyhow::Result<()> { // == Setting elements in a table == // We first construct a `Function` over our host_callback. - let func = Function::new_native(&mut store, &env, host_callback); + let func = Function::new_typed(&mut store, host_callback); // And set table index 1 of that table to the host_callback `Function`. guest_table.set(&mut store, 1, func.into())?; @@ -102,7 +101,7 @@ fn main() -> anyhow::Result<()> { // == Growing a table == // We again construct a `Function` over our host_callback. - let func = Function::new_native(&mut store, &env, host_callback); + let func = Function::new_typed(&mut store, host_callback); // And grow the table by 3 elements, filling in our host_callback in all the // new elements of the table. @@ -133,7 +132,7 @@ fn main() -> anyhow::Result<()> { assert_eq!(result, 18); // Now overwrite index 0 with our host_callback. - let func = Function::new_native(&mut store, &env, host_callback); + let func = Function::new_typed(&mut store, host_callback); guest_table.set(&mut store, 0, func.into())?; // And verify that it does what we expect. let result = call_via_table.call(&mut store, 0, 2, 7)?; diff --git a/examples/tunables_limit_memory.rs b/examples/tunables_limit_memory.rs index 2b2f36900..104f1acc6 100644 --- a/examples/tunables_limit_memory.rs +++ b/examples/tunables_limit_memory.rs @@ -3,8 +3,8 @@ use std::ptr::NonNull; use wasmer::{ imports, vm::{self, MemoryError, MemoryStyle, TableStyle, VMMemoryDefinition, VMTableDefinition}, - wat2wasm, BaseTunables, FunctionEnv, Instance, Memory, MemoryType, Module, Pages, Store, - TableType, Target, Tunables, + wat2wasm, BaseTunables, Instance, Memory, MemoryType, Module, Pages, Store, TableType, Target, + Tunables, }; use wasmer_compiler_cranelift::Cranelift; diff --git a/lib/api/src/js/externals/function.rs b/lib/api/src/js/externals/function.rs index e9477b39c..0b0938df7 100644 --- a/lib/api/src/js/externals/function.rs +++ b/lib/api/src/js/externals/function.rs @@ -64,7 +64,24 @@ impl Function { /// Creates a new host `Function` (dynamic) with the provided signature. /// /// If you know the signature of the host function at compile time, - /// consider using [`Function::new_native`] for less runtime overhead. + /// consider using [`Function::new_typed`] for less runtime overhead. + pub fn new(store: &mut impl AsStoreMut, ty: FT, func: F) -> Self + where + FT: Into, + F: Fn(&[Value]) -> Result, RuntimeError> + 'static + Send + Sync, + { + let env = FunctionEnv::new(&mut store.as_store_mut(), ()); + let wrapped_func = move |_env: FunctionEnvMut<()>, + args: &[Value]| + -> Result, RuntimeError> { func(args) }; + Self::new_with_env(store, &env, ty, wrapped_func) + } + + /// Creates a new host `Function` (dynamic) with the provided signature. + /// + /// If you know the signature of the host function at compile time, + /// consider using [`Function::new_typed`] or [`Function::new_typed_with_env`] + /// for less runtime overhead. /// /// # Examples /// @@ -74,7 +91,7 @@ impl Function { /// # /// let signature = FunctionType::new(vec![Type::I32, Type::I32], vec![Type::I32]); /// - /// let f = Function::new(&store, &signature, |args| { + /// let f = Function::new_with_env(&store, &signature, |args| { /// let sum = args[0].unwrap_i32() + args[1].unwrap_i32(); /// Ok(vec![Value::I32(sum)]) /// }); @@ -88,13 +105,13 @@ impl Function { /// # /// const I32_I32_TO_I32: ([Type; 2], [Type; 1]) = ([Type::I32, Type::I32], [Type::I32]); /// - /// let f = Function::new(&store, I32_I32_TO_I32, |args| { + /// let f = Function::new_with_env(&store, I32_I32_TO_I32, |args| { /// let sum = args[0].unwrap_i32() + args[1].unwrap_i32(); /// Ok(vec![Value::I32(sum)]) /// }); /// ``` #[allow(clippy::cast_ptr_alignment)] - pub fn new( + pub fn new_with_env( store: &mut impl AsStoreMut, env: &FunctionEnv, ty: FT, @@ -164,7 +181,25 @@ impl Function { Self::from_vm_export(&mut store, vm_function) } - /// Creates a new host `Function` from a native function. + #[deprecated( + since = "3.0.0", + note = "new_native_with_env() has been renamed to new_typed_with_env()." + )] + /// Creates a new host `Function` with an environment from a typed function. + pub fn new_native_with_env( + store: &mut impl AsStoreMut, + env: &FunctionEnv, + func: F, + ) -> Self + where + F: HostFunction, + Args: WasmTypeList, + Rets: WasmTypeList, + { + Self::new_typed_with_env(store, env, func) + } + + /// Creates a new host `Function` from a typed function. /// /// The function signature is automatically retrieved using the /// Rust typing system. @@ -179,9 +214,9 @@ impl Function { /// a + b /// } /// - /// let f = Function::new_native(&store, sum); + /// let f = Function::new_typed_with_env(&store, sum); /// ``` - pub fn new_native( + pub fn new_typed_with_env( store: &mut impl AsStoreMut, env: &FunctionEnv, func: F, @@ -226,7 +261,7 @@ impl Function { /// a + b /// } /// - /// let f = Function::new_native(&store, sum); + /// let f = Function::new_typed(&store, sum); /// /// assert_eq!(f.ty().params(), vec![Type::I32, Type::I32]); /// assert_eq!(f.ty().results(), vec![Type::I32]); @@ -242,13 +277,12 @@ impl Function { /// ``` /// # use wasmer::{Function, FunctionEnv, FunctionEnvMut, Store, Type}; /// # let mut store = Store::default(); - /// # let env = FunctionEnv::new(&mut store, ()); /// # - /// fn sum(_env: FunctionEnvMut<()>, a: i32, b: i32) -> i32 { + /// fn sum(a: i32, b: i32) -> i32 { /// a + b /// } /// - /// let f = Function::new_native(&store, &env, sum); + /// let f = Function::new_typed(&store, sum); /// /// assert_eq!(f.param_arity(&store), 2); /// ``` @@ -263,13 +297,12 @@ impl Function { /// ``` /// # use wasmer::{Function, FunctionEnv, FunctionEnvMut, Store, Type}; /// # let mut store = Store::default(); - /// # let env = FunctionEnv::new(&mut store, ()); /// # - /// fn sum(_env: FunctionEnvMut<()>, a: i32, b: i32) -> i32 { + /// fn sum(a: i32, b: i32) -> i32 { /// a + b /// } /// - /// let f = Function::new_native(&store, &env, sum); + /// let f = Function::new_typed(&store, sum); /// /// assert_eq!(f.result_arity(&store), 1); /// ``` @@ -362,8 +395,20 @@ impl Function { } } - /// Transform this WebAssembly function into a function with the - /// native ABI. See [`TypedFunction`] to learn more. + #[deprecated(since = "3.0.0", note = "native() has been renamed to typed().")] + pub fn native( + &self, + store: &impl AsStoreRef, + ) -> Result, RuntimeError> + where + Args: WasmTypeList, + Rets: WasmTypeList, + { + self.typed(store) + } + + /// Transform this WebAssembly function into a typed function. + /// See [`TypedFunction`] to learn more. /// /// # Examples /// @@ -383,9 +428,9 @@ impl Function { /// # let instance = Instance::new(&module, &import_object).unwrap(); /// # /// let sum = instance.exports.get_function("sum").unwrap(); - /// let sum_native = sum.native::<(i32, i32), i32>().unwrap(); + /// let sum_typed = sum.typed::<(i32, i32), i32>().unwrap(); /// - /// assert_eq!(sum_native.call(&mut store, 1, 2).unwrap(), 3); + /// assert_eq!(sum_typed.call(&mut store, 1, 2).unwrap(), 3); /// ``` /// /// # Errors @@ -411,7 +456,7 @@ impl Function { /// let sum = instance.exports.get_function("sum").unwrap(); /// /// // This results in an error: `RuntimeError` - /// let sum_native = sum.native::<(i64, i64), i32>(&mut store).unwrap(); + /// let sum_typed = sum.typed::<(i64, i64), i32>(&mut store).unwrap(); /// ``` /// /// If the `Rets` generic parameter does not match the exported function @@ -435,9 +480,9 @@ impl Function { /// let sum = instance.exports.get_function("sum").unwrap(); /// /// // This results in an error: `RuntimeError` - /// let sum_native = sum.native::<(i32, i32), i64>(&mut store).unwrap(); + /// let sum_typed = sum.typed::<(i32, i32), i64>(&mut store).unwrap(); /// ``` - pub fn native( + pub fn typed( &self, store: &impl AsStoreRef, ) -> Result, RuntimeError> diff --git a/lib/api/src/js/imports.rs b/lib/api/src/js/imports.rs index 94866e668..95a993099 100644 --- a/lib/api/src/js/imports.rs +++ b/lib/api/src/js/imports.rs @@ -22,7 +22,7 @@ use std::fmt; /// use wasmer::{Exports, Module, Store, Instance, imports, Imports, Function}; /// # fn foo_test(module: Module, store: Store) { /// -/// let host_fn = Function::new_native(foo); +/// let host_fn = Function::new_typed(foo); /// let import_object: Imports = imports! { /// "env" => { /// "foo" => host_fn, @@ -103,7 +103,7 @@ impl Imports { /// n /// } /// let mut import_object = Imports::new(); - /// import_object.define("env", "foo", Function::new_native(foo)); + /// import_object.define("env", "foo", Function::new_typed(&store, foo)); /// ``` pub fn define(&mut self, ns: &str, name: &str, val: impl Into) { self.map @@ -240,7 +240,7 @@ impl fmt::Debug for Imports { /// /// let import_object = imports! { /// "env" => { -/// "foo" => Function::new_native(&store, foo) +/// "foo" => Function::new_typed(&store, foo) /// }, /// }; /// @@ -331,42 +331,42 @@ mod test { let _ = imports! { "env" => { - "func" => Function::new_native(&store, func), + "func" => Function::new_typed(&store, func), }, }; let _ = imports! { "env" => { - "func" => Function::new_native(&store, func), + "func" => Function::new_typed(&store, func), } }; let _ = imports! { "env" => { - "func" => Function::new_native(&store, func), + "func" => Function::new_typed(&store, func), }, "abc" => { - "def" => Function::new_native(&store, func), + "def" => Function::new_typed(&store, func), } }; let _ = imports! { "env" => { - "func" => Function::new_native(&store, func) + "func" => Function::new_typed(&store, func) }, }; let _ = imports! { "env" => { - "func" => Function::new_native(&store, func) + "func" => Function::new_typed(&store, func) } }; let _ = imports! { "env" => { - "func1" => Function::new_native(&store, func), - "func2" => Function::new_native(&store, func) + "func1" => Function::new_typed(&store, func), + "func2" => Function::new_typed(&store, func) } }; let _ = imports! { "env" => { - "func1" => Function::new_native(&store, func), - "func2" => Function::new_native(&store, func), + "func1" => Function::new_typed(&store, func), + "func2" => Function::new_typed(&store, func), } }; } diff --git a/lib/api/src/lib.rs b/lib/api/src/lib.rs index 7592337e8..777ace970 100644 --- a/lib/api/src/lib.rs +++ b/lib/api/src/lib.rs @@ -147,11 +147,11 @@ //! //! ``` //! # use wasmer::{imports, Function, FunctionEnv, FunctionEnvMut, Memory, MemoryType, Store, Imports}; -//! # fn imports_example(mut env: FunctionEnv<()>, mut store: &mut Store) -> Imports { +//! # fn imports_example(mut store: &mut Store) -> Imports { //! let memory = Memory::new(&mut store, MemoryType::new(1, None, false)).unwrap(); //! imports! { //! "env" => { -//! "my_function" => Function::new_native(&mut store, &env, |_env: FunctionEnvMut<()>| println!("Hello")), +//! "my_function" => Function::new_typed(&mut store, |_env: FunctionEnvMut<()>| println!("Hello")), //! "memory" => memory, //! } //! } diff --git a/lib/api/src/sys/exports.rs b/lib/api/src/sys/exports.rs index 11536b994..f744a21c6 100644 --- a/lib/api/src/sys/exports.rs +++ b/lib/api/src/sys/exports.rs @@ -166,7 +166,7 @@ impl Exports { Rets: WasmTypeList, { self.get_function(name)? - .native(store) + .typed(store) .map_err(|_| ExportError::IncompatibleType) } diff --git a/lib/api/src/sys/externals/function.rs b/lib/api/src/sys/externals/function.rs index 3a0bedd14..6e4381752 100644 --- a/lib/api/src/sys/externals/function.rs +++ b/lib/api/src/sys/externals/function.rs @@ -42,11 +42,31 @@ pub struct Function { } impl Function { + /// Creates a new host `Function` (dynamic) with the provided signature. + /// + /// If you know the signature of the host function at compile time, + /// consider using [`Function::new_typed`] for less runtime overhead. + #[cfg(feature = "compiler")] + pub fn new(store: &mut impl AsStoreMut, ty: FT, func: F) -> Self + where + FT: Into, + F: Fn(FunctionEnvMut<()>, &[Value]) -> Result, RuntimeError> + + 'static + + Send + + Sync, + { + let env = FunctionEnv::new(&mut store.as_store_mut(), ()); + Self::new_with_env(store, &env, ty, func) + } + #[cfg(feature = "compiler")] /// Creates a new host `Function` (dynamic) with the provided signature. /// /// If you know the signature of the host function at compile time, - /// consider using [`Function::new_native`] for less runtime overhead. + /// consider using [`Function::new_typed_with_env`] for less runtime overhead. + /// + /// Takes a [`FunctionEnv`] that is passed into func. If that is not required, + /// [`Function::new`] might be an option as well. /// /// # Examples /// @@ -57,7 +77,7 @@ impl Function { /// # /// let signature = FunctionType::new(vec![Type::I32, Type::I32], vec![Type::I32]); /// - /// let f = Function::new(&mut store, &env, &signature, |_env, args| { + /// let f = Function::new_with_env(&mut store, &env, &signature, |_env, args| { /// let sum = args[0].unwrap_i32() + args[1].unwrap_i32(); /// Ok(vec![Value::I32(sum)]) /// }); @@ -72,12 +92,12 @@ impl Function { /// # /// const I32_I32_TO_I32: ([Type; 2], [Type; 1]) = ([Type::I32, Type::I32], [Type::I32]); /// - /// let f = Function::new(&mut store, &env, I32_I32_TO_I32, |_env, args| { + /// let f = Function::new_with_env(&mut store, &env, I32_I32_TO_I32, |_env, args| { /// let sum = args[0].unwrap_i32() + args[1].unwrap_i32(); /// Ok(vec![Value::I32(sum)]) /// }); /// ``` - pub fn new( + pub fn new_with_env( store: &mut impl AsStoreMut, env: &FunctionEnv, ty: FT, @@ -161,7 +181,53 @@ impl Function { } #[cfg(feature = "compiler")] + #[deprecated( + since = "3.0.0", + note = "new_native() has been renamed to new_typed()." + )] /// Creates a new host `Function` from a native function. + pub fn new_native(store: &mut impl AsStoreMut, func: F) -> Self + where + F: HostFunction<(), Args, Rets> + 'static + Send + Sync, + Args: WasmTypeList, + Rets: WasmTypeList, + { + Self::new_typed(store, func) + } + + #[cfg(feature = "compiler")] + /// Creates a new host `Function` from a native function. + pub fn new_typed(store: &mut impl AsStoreMut, func: F) -> Self + where + F: HostFunction<(), Args, Rets> + 'static + Send + Sync, + Args: WasmTypeList, + Rets: WasmTypeList, + { + let env = FunctionEnv::new(store, ()); + Self::new_typed_with_env(store, &env, func) + } + + #[cfg(feature = "compiler")] + #[deprecated( + since = "3.0.0", + note = "new_native_with_env() has been renamed to new_typed_with_env()." + )] + /// Creates a new host `Function` with an environment from a native function. + pub fn new_native_with_env( + store: &mut impl AsStoreMut, + env: &FunctionEnv, + func: F, + ) -> Self + where + F: HostFunction + 'static + Send + Sync, + Args: WasmTypeList, + Rets: WasmTypeList, + { + Self::new_typed_with_env(store, env, func) + } + + #[cfg(feature = "compiler")] + /// Creates a new host `Function` with an environment from a typed function. /// /// The function signature is automatically retrieved using the /// Rust typing system. @@ -177,9 +243,9 @@ impl Function { /// a + b /// } /// - /// let f = Function::new_native(&mut store, &env, sum); + /// let f = Function::new_typed_with_env(&mut store, &env, sum); /// ``` - pub fn new_native( + pub fn new_typed_with_env( store: &mut impl AsStoreMut, env: &FunctionEnv, func: F, @@ -238,7 +304,7 @@ impl Function { /// a + b /// } /// - /// let f = Function::new_native(&mut store, &env, sum); + /// let f = Function::new_typed_with_env(&mut store, &env, sum); /// /// assert_eq!(f.ty(&mut store).params(), vec![Type::I32, Type::I32]); /// assert_eq!(f.ty(&mut store).results(), vec![Type::I32]); @@ -339,7 +405,7 @@ impl Function { /// a + b /// } /// - /// let f = Function::new_native(&mut store, &env, sum); + /// let f = Function::new_typed_with_env(&mut store, &env, sum); /// /// assert_eq!(f.param_arity(&mut store), 2); /// ``` @@ -360,7 +426,7 @@ impl Function { /// a + b /// } /// - /// let f = Function::new_native(&mut store, &env, sum); + /// let f = Function::new_typed_with_env(&mut store, &env, sum); /// /// assert_eq!(f.result_arity(&mut store), 1); /// ``` @@ -446,8 +512,23 @@ impl Function { } } - /// Transform this WebAssembly function into a function with the - /// native ABI. See [`TypedFunction`] to learn more. + /// Transform this WebAssembly function into a native function. + /// See [`TypedFunction`] to learn more. + #[cfg(feature = "compiler")] + #[deprecated(since = "3.0.0", note = "native() has been renamed to typed().")] + pub fn native( + &self, + store: &impl AsStoreRef, + ) -> Result, RuntimeError> + where + Args: WasmTypeList, + Rets: WasmTypeList, + { + self.typed(store) + } + + /// Transform this WebAssembly function into a typed function. + /// See [`TypedFunction`] to learn more. /// /// # Examples /// @@ -469,9 +550,9 @@ impl Function { /// # let instance = Instance::new(&mut store, &module, &import_object).unwrap(); /// # /// let sum = instance.exports.get_function("sum").unwrap(); - /// let sum_native: TypedFunction<(i32, i32), i32> = sum.native(&mut store).unwrap(); + /// let sum_typed: TypedFunction<(i32, i32), i32> = sum.typed(&mut store).unwrap(); /// - /// assert_eq!(sum_native.call(&mut store, 1, 2).unwrap(), 3); + /// assert_eq!(sum_typed.call(&mut store, 1, 2).unwrap(), 3); /// ``` /// /// # Errors @@ -499,7 +580,7 @@ impl Function { /// let sum = instance.exports.get_function("sum").unwrap(); /// /// // This results in an error: `RuntimeError` - /// let sum_native : TypedFunction<(i64, i64), i32> = sum.native(&mut store).unwrap(); + /// let sum_typed : TypedFunction<(i64, i64), i32> = sum.typed(&mut store).unwrap(); /// ``` /// /// If the `Rets` generic parameter does not match the exported function @@ -525,9 +606,9 @@ impl Function { /// let sum = instance.exports.get_function("sum").unwrap(); /// /// // This results in an error: `RuntimeError` - /// let sum_native: TypedFunction<(i32, i32), i64> = sum.native(&mut store).unwrap(); + /// let sum_typed: TypedFunction<(i32, i32), i64> = sum.typed(&mut store).unwrap(); /// ``` - pub fn native( + pub fn typed( &self, store: &impl AsStoreRef, ) -> Result, RuntimeError> @@ -984,7 +1065,8 @@ mod inner { } /// Represents a low-level Wasm static host function. See - /// `super::Function::new_native` to learn more. + /// [`super::Function::new_typed`] and + /// [`super::Function::new_typed_with_env`] to learn more. pub(crate) struct StaticFunction { pub(crate) raw_store: *mut u8, pub(crate) env: FunctionEnv, diff --git a/lib/api/src/sys/imports.rs b/lib/api/src/sys/imports.rs index 98fdc848c..c6e279bf5 100644 --- a/lib/api/src/sys/imports.rs +++ b/lib/api/src/sys/imports.rs @@ -16,10 +16,10 @@ use wasmer_types::ImportError; /// /// # Usage: /// ```no_run -/// use wasmer::{Store, Exports, Module, Instance, imports, Imports, Function, FunctionEnv, FunctionEnvMut}; -/// # fn foo_test(mut env: FunctionEnv<()>, mut store: &mut Store, module: Module) { +/// use wasmer::{Store, Exports, Module, Instance, imports, Imports, Function, FunctionEnvMut}; +/// # fn foo_test(mut store: &mut Store, module: Module) { /// -/// let host_fn = Function::new_native(&mut store, &env, foo); +/// let host_fn = Function::new_typed(&mut store, foo); /// let import_object: Imports = imports! { /// "env" => { /// "foo" => host_fn, @@ -99,13 +99,12 @@ impl Imports { /// ```no_run /// # use wasmer::{FunctionEnv, Store}; /// # let mut store: Store = Default::default(); - /// # let env = FunctionEnv::new(&mut store, ()); /// use wasmer::{StoreMut, Imports, Function, FunctionEnvMut}; /// fn foo(_env: FunctionEnvMut<()>, n: i32) -> i32 { /// n /// } /// let mut import_object = Imports::new(); - /// import_object.define("env", "foo", Function::new_native(&mut store, &env, foo)); + /// import_object.define("env", "foo", Function::new_typed(&mut store, foo)); /// ``` pub fn define(&mut self, ns: &str, name: &str, val: impl Into) { self.map @@ -210,14 +209,13 @@ impl fmt::Debug for Imports { /// # Usage /// /// ``` -/// # use wasmer::{StoreMut, Function, Store, FunctionEnv, FunctionEnvMut}; +/// # use wasmer::{StoreMut, Function, FunctionEnvMut, Store}; /// # let mut store = Store::default(); -/// # let env = FunctionEnv::new(&mut store, ()); /// use wasmer::imports; /// /// let import_object = imports! { /// "env" => { -/// "foo" => Function::new_native(&mut store, &env, foo) +/// "foo" => Function::new_typed(&mut store, foo) /// }, /// }; /// @@ -270,7 +268,6 @@ macro_rules! import_namespace { #[cfg(test)] mod test { - use crate::sys::FunctionEnv; use crate::sys::{AsStoreMut, Global, Store, Value}; use wasmer_types::Type; use wasmer_vm::VMExtern; @@ -303,7 +300,6 @@ mod test { use crate::sys::FunctionEnvMut; let mut store: Store = Default::default(); - let env = FunctionEnv::new(&mut store, ()); fn func(_env: FunctionEnvMut<()>, arg: i32) -> i32 { arg + 1 @@ -311,42 +307,42 @@ mod test { let _ = imports! { "env" => { - "func" => Function::new_native(&mut store, &env, func), + "func" => Function::new_typed(&mut store, func), }, }; let _ = imports! { "env" => { - "func" => Function::new_native(&mut store, &env, func), + "func" => Function::new_typed(&mut store, func), } }; let _ = imports! { "env" => { - "func" => Function::new_native(&mut store, &env, func), + "func" => Function::new_typed(&mut store, func), }, "abc" => { - "def" => Function::new_native(&mut store, &env, func), + "def" => Function::new_typed(&mut store, func), } }; let _ = imports! { "env" => { - "func" => Function::new_native(&mut store, &env, func) + "func" => Function::new_typed(&mut store, func) }, }; let _ = imports! { "env" => { - "func" => Function::new_native(&mut store, &env, func) + "func" => Function::new_typed(&mut store, func) } }; let _ = imports! { "env" => { - "func1" => Function::new_native(&mut store, &env, func), - "func2" => Function::new_native(&mut store, &env, func) + "func1" => Function::new_typed(&mut store, func), + "func2" => Function::new_typed(&mut store, func) } }; let _ = imports! { "env" => { - "func1" => Function::new_native(&mut store, &env, func), - "func2" => Function::new_native(&mut store, &env, func), + "func1" => Function::new_typed(&mut store, func), + "func2" => Function::new_typed(&mut store, func), } }; } diff --git a/lib/api/tests/js_externals.rs b/lib/api/tests/js_externals.rs index 4f8401232..980e85aad 100644 --- a/lib/api/tests/js_externals.rs +++ b/lib/api/tests/js_externals.rs @@ -60,13 +60,12 @@ mod js { #[wasm_bindgen_test] fn table_new() { let mut store = Store::default(); - let env = FunctionEnv::new(&mut store, ()); let table_type = TableType { ty: Type::FuncRef, minimum: 0, maximum: None, }; - let f = Function::new_native(&mut store, &env, |_: FunctionEnvMut<'_, ()>| {}); + let f = Function::new_typed(&mut store, || {}); let table = Table::new(&mut store, table_type, Value::FuncRef(Some(f))).unwrap(); assert_eq!(table.ty(&store), table_type); @@ -177,40 +176,28 @@ mod js { #[wasm_bindgen_test] fn function_new() { let mut store = Store::default(); - let env = FunctionEnv::new(&mut store, ()); - let function = Function::new_native(&mut store, &env, |_env: FunctionEnvMut<'_, ()>| {}); + let function = Function::new_typed(&mut store, || {}); assert_eq!( function.ty(&store).clone(), FunctionType::new(vec![], vec![]) ); - let function = - Function::new_native(&mut store, &env, |_env: FunctionEnvMut<'_, ()>, _a: i32| {}); + let function = Function::new_typed(&mut store, |_a: i32| {}); assert_eq!( function.ty(&store).clone(), FunctionType::new(vec![Type::I32], vec![]) ); - let function = Function::new_native( - &mut store, - &env, - |_env: FunctionEnvMut<'_, ()>, _a: i32, _b: i64, _c: f32, _d: f64| {}, - ); + let function = Function::new_typed(&mut store, |_a: i32, _b: i64, _c: f32, _d: f64| {}); assert_eq!( function.ty(&store).clone(), FunctionType::new(vec![Type::I32, Type::I64, Type::F32, Type::F64], vec![]) ); - let function = - Function::new_native(&mut store, &env, |_env: FunctionEnvMut<'_, ()>| -> i32 { - 1 - }); + let function = Function::new_typed(&mut store, || -> i32 { 1 }); assert_eq!( function.ty(&store).clone(), FunctionType::new(vec![], vec![Type::I32]) ); - let function = Function::new_native( - &mut store, - &env, - |_env: FunctionEnvMut<'_, ()>| -> (i32, i64, f32, f64) { (1, 2, 3.0, 4.0) }, - ); + let function = + Function::new_typed(&mut store, || -> (i32, i64, f32, f64) { (1, 2, 3.0, 4.0) }); assert_eq!( function.ty(&store).clone(), FunctionType::new(vec![], vec![Type::I32, Type::I64, Type::F32, Type::F64]) @@ -226,18 +213,22 @@ mod js { let my_env = MyEnv {}; let env = FunctionEnv::new(&mut store, my_env); - let function = Function::new_native(&mut store, &env, |_: FunctionEnvMut<'_, MyEnv>| {}); + let function = + Function::new_typed_with_env(&mut store, &env, |_: FunctionEnvMut<'_, MyEnv>| {}); assert_eq!( function.ty(&store).clone(), FunctionType::new(vec![], vec![]) ); - let function = - Function::new_native(&mut store, &env, |_: FunctionEnvMut<'_, MyEnv>, _a: i32| {}); + let function = Function::new_typed_with_env( + &mut store, + &env, + |_: FunctionEnvMut<'_, MyEnv>, _a: i32| {}, + ); assert_eq!( function.ty(&store).clone(), FunctionType::new(vec![Type::I32], vec![]) ); - let function = Function::new_native( + let function = Function::new_typed_with_env( &mut store, &env, |_: FunctionEnvMut<'_, MyEnv>, _a: i32, _b: i64, _c: f32, _d: f64| {}, @@ -247,14 +238,14 @@ mod js { FunctionType::new(vec![Type::I32, Type::I64, Type::F32, Type::F64], vec![]) ); let function = - Function::new_native(&mut store, &env, |_: FunctionEnvMut<'_, MyEnv>| -> i32 { + Function::new_typed_with_env(&mut store, &env, |_: FunctionEnvMut<'_, MyEnv>| -> i32 { 1 }); assert_eq!( function.ty(&store).clone(), FunctionType::new(vec![], vec![Type::I32]) ); - let function = Function::new_native( + let function = Function::new_typed_with_env( &mut store, &env, |_: FunctionEnvMut<'_, MyEnv>| -> (i32, i64, f32, f64) { (1, 2, 3.0, 4.0) }, @@ -400,18 +391,14 @@ mod js { #[wasm_bindgen_test] fn native_function_works() { let mut store = Store::default(); - let env = FunctionEnv::new(&mut store, ()); - let function = Function::new_native(&mut store, &env, |_: FunctionEnvMut<'_, ()>| {}); - let typed_function: TypedFunction<(), ()> = function.native(&mut store).unwrap(); + let mut env = FunctionEnv::new(&mut store, ()); + let function = Function::new_typed(&mut store, || {}); + let typed_function: TypedFunction<(), ()> = function.typed(&mut store).unwrap(); let result = typed_function.call(&mut store); assert!(result.is_ok()); - let function = Function::new_native( - &mut store, - &env, - |_: FunctionEnvMut<'_, ()>, a: i32| -> i32 { a + 1 }, - ); - let typed_function: TypedFunction = function.native(&mut store).unwrap(); + let function = Function::new_typed(&mut store, |a: i32| -> i32 { a + 1 }); + let typed_function: TypedFunction = function.typed(&mut store).unwrap(); assert_eq!(typed_function.call(&mut store, 3).unwrap(), 4); // fn rust_abi(a: i32, b: i64, c: f32, d: f64) -> u64 { @@ -421,14 +408,12 @@ mod js { // let typed_function: TypedFunction<(i32, i64, f32, f64), u64> = function.native(&mut store).unwrap(); // assert_eq!(typed_function.call(8, 4, 1.5, 5.).unwrap(), 8415); - let function = - Function::new_native(&mut store, &env, |_: FunctionEnvMut<'_, ()>| -> i32 { 1 }); - let typed_function: TypedFunction<(), i32> = function.native(&mut store).unwrap(); + let function = Function::new_typed(&mut store, || -> i32 { 1 }); + let typed_function: TypedFunction<(), i32> = function.typed(&mut store).unwrap(); assert_eq!(typed_function.call(&mut store).unwrap(), 1); - let function = - Function::new_native(&mut store, &env, |_: FunctionEnvMut<'_, ()>, _a: i32| {}); - let typed_function: TypedFunction = function.native(&mut store).unwrap(); + let function = Function::new_typed(&mut store, |_a: i32| {}); + let typed_function: TypedFunction = function.typed(&mut store).unwrap(); assert!(typed_function.call(&mut store, 4).is_ok()); // let function = Function::new(&mut store, &env, || -> (i32, i64, f32, f64) { (1, 2, 3.0, 4.0) }); diff --git a/lib/api/tests/js_instance.rs b/lib/api/tests/js_instance.rs index 18e185dfc..c61519801 100644 --- a/lib/api/tests/js_instance.rs +++ b/lib/api/tests/js_instance.rs @@ -291,8 +291,7 @@ mod js { return arg + 1; } - let env = FunctionEnv::new(&mut store, ()); - let imported = Function::new_native(&mut store, &env, imported_fn); + let imported = Function::new_typed(&mut store, imported_fn); let import_object = imports! { "env" => { @@ -348,7 +347,7 @@ mod js { let env = FunctionEnv::new(&mut store, Env { multiplier: 3 }); - let imported = Function::new_native(&mut store, &env, imported_fn); + let imported = Function::new_typed_with_env(&mut store, &env, imported_fn); let import_object = imports! { "env" => { @@ -412,7 +411,7 @@ mod js { memory: None, }, ); - let imported = Function::new_native(&mut store, &env, imported_fn); + let imported = Function::new_typed_with_env(&mut store, &env, imported_fn); let import_object = imports! { "env" => { @@ -630,11 +629,9 @@ mod js { a + b } - let env = FunctionEnv::new(&mut store, ()); - let import_object = imports! { "env" => { - "sum" => Function::new_native(&mut store, &env, sum), + "sum" => Function::new_typed(&mut store, sum), } }; @@ -670,11 +667,10 @@ mod js { fn early_exit(_: FunctionEnvMut<'_, ()>) { panic!("Do panic") } - let env = FunctionEnv::new(&mut store, ()); let import_object = imports! { "env" => { - "early_exit" => Function::new_native(&mut store, &env, early_exit), + "early_exit" => Function::new_typed(&mut store, early_exit), } }; let instance = Instance::new(&mut store, &module, &import_object).unwrap(); @@ -718,8 +714,6 @@ mod js { ) .unwrap(); - let env = FunctionEnv::new(&mut store, ()); - use std::fmt; #[derive(Debug, Clone, Copy)] @@ -739,7 +733,7 @@ mod js { let import_object = imports! { "env" => { - "early_exit" => Function::new_native(&mut store, &env, early_exit), + "early_exit" => Function::new_typed(&mut store, early_exit), } }; diff --git a/lib/api/tests/js_module.rs b/lib/api/tests/js_module.rs index 4a1b36f36..44b525f1a 100644 --- a/lib/api/tests/js_module.rs +++ b/lib/api/tests/js_module.rs @@ -212,35 +212,35 @@ mod js { // let module = Module::new(&store, wat).unwrap(); // let imports = imports! { // "host" => { - // "host_func1" => Function::new_native(&store, |p: u64| { + // "host_func1" => Function::new_typed(&store, |p: u64| { // println!("host_func1: Found number {}", p); // assert_eq!(p, u64::max_value()); // }), - // "host_func2" => Function::new_native(&store, |p: u32| { + // "host_func2" => Function::new_typed(&store, |p: u32| { // println!("host_func2: Found number {}", p); // assert_eq!(p, u32::max_value()); // }), - // "host_func3" => Function::new_native(&store, |p: i64| { + // "host_func3" => Function::new_typed(&store, |p: i64| { // println!("host_func3: Found number {}", p); // assert_eq!(p, -1); // }), - // "host_func4" => Function::new_native(&store, |p: i32| { + // "host_func4" => Function::new_typed(&store, |p: i32| { // println!("host_func4: Found number {}", p); // assert_eq!(p, -1); // }), - // "host_func5" => Function::new_native(&store, |p: i16| { + // "host_func5" => Function::new_typed(&store, |p: i16| { // println!("host_func5: Found number {}", p); // assert_eq!(p, -1); // }), - // "host_func6" => Function::new_native(&store, |p: u16| { + // "host_func6" => Function::new_typed(&store, |p: u16| { // println!("host_func6: Found number {}", p); // assert_eq!(p, u16::max_value()); // }), - // "host_func7" => Function::new_native(&store, |p: i8| { + // "host_func7" => Function::new_typed(&store, |p: i8| { // println!("host_func7: Found number {}", p); // assert_eq!(p, -1); // }), - // "host_func8" => Function::new_native(&store, |p: u8| { + // "host_func8" => Function::new_typed(&store, |p: u8| { // println!("host_func8: Found number {}", p); // assert_eq!(p, u8::max_value()); // }), diff --git a/lib/api/tests/sys_externals.rs b/lib/api/tests/sys_externals.rs index a888d4e49..710c1bb88 100644 --- a/lib/api/tests/sys_externals.rs +++ b/lib/api/tests/sys_externals.rs @@ -69,8 +69,7 @@ mod sys { minimum: 0, maximum: None, }; - let env = FunctionEnv::new(&mut store, ()); - let f = Function::new_native(&mut store, &env, |_env: FunctionEnvMut<()>| {}); + let f = Function::new_typed(&mut store, |_env: FunctionEnvMut<()>| {}); let table = Table::new(&mut store, table_type, Value::FuncRef(Some(f)))?; assert_eq!(table.ty(&mut store), table_type); @@ -90,15 +89,12 @@ mod sys { #[ignore] fn table_get() -> Result<()> { let mut store = Store::default(); - let env = FunctionEnv::new(&mut store, ()); let table_type = TableType { ty: Type::FuncRef, minimum: 0, maximum: Some(1), }; - let f = Function::new_native(&mut store, &env, |_env: FunctionEnvMut<()>, num: i32| { - num + 1 - }); + let f = Function::new_typed(&mut store, |_env: FunctionEnvMut<()>, num: i32| num + 1); let table = Table::new(&mut store, table_type, Value::FuncRef(Some(f)))?; assert_eq!(table.ty(&mut store), table_type); let _elem = table.get(&mut store, 0).unwrap(); @@ -116,15 +112,12 @@ mod sys { #[test] fn table_grow() -> Result<()> { let mut store = Store::default(); - let env = FunctionEnv::new(&mut store, ()); let table_type = TableType { ty: Type::FuncRef, minimum: 0, maximum: Some(10), }; - let f = Function::new_native(&mut store, &env, |_env: FunctionEnvMut<()>, num: i32| { - num + 1 - }); + let f = Function::new_typed(&mut store, |_env: FunctionEnvMut<()>, num: i32| num + 1); let table = Table::new(&mut store, table_type, Value::FuncRef(Some(f.clone())))?; // Growing to a bigger maximum should return None let old_len = table.grow(&mut store, 12, Value::FuncRef(Some(f.clone()))); @@ -189,36 +182,31 @@ mod sys { #[test] fn function_new() -> Result<()> { let mut store = Store::default(); - let env = FunctionEnv::new(&mut store, ()); - let function = Function::new_native(&mut store, &env, |_env: FunctionEnvMut<()>| {}); + let function = Function::new_typed(&mut store, |_env: FunctionEnvMut<()>| {}); assert_eq!( function.ty(&mut store).clone(), FunctionType::new(vec![], vec![]) ); - let function = - Function::new_native(&mut store, &env, |_env: FunctionEnvMut<()>, _a: i32| {}); + let function = Function::new_typed(&mut store, |_env: FunctionEnvMut<()>, _a: i32| {}); assert_eq!( function.ty(&mut store).clone(), FunctionType::new(vec![Type::I32], vec![]) ); - let function = Function::new_native( + let function = Function::new_typed( &mut store, - &env, |_env: FunctionEnvMut<()>, _a: i32, _b: i64, _c: f32, _d: f64| {}, ); assert_eq!( function.ty(&mut store).clone(), FunctionType::new(vec![Type::I32, Type::I64, Type::F32, Type::F64], vec![]) ); - let function = - Function::new_native(&mut store, &env, |_env: FunctionEnvMut<()>| -> i32 { 1 }); + let function = Function::new_typed(&mut store, |_env: FunctionEnvMut<()>| -> i32 { 1 }); assert_eq!( function.ty(&mut store).clone(), FunctionType::new(vec![], vec![Type::I32]) ); - let function = Function::new_native( + let function = Function::new_typed( &mut store, - &env, |_env: FunctionEnvMut<()>| -> (i32, i64, f32, f64) { (1, 2, 3.0, 4.0) }, ); assert_eq!( @@ -236,18 +224,22 @@ mod sys { let my_env = MyEnv {}; let env = FunctionEnv::new(&mut store, my_env); - let function = Function::new_native(&mut store, &env, |_env: FunctionEnvMut| {}); + let function = + Function::new_typed_with_env(&mut store, &env, |_env: FunctionEnvMut| {}); assert_eq!( function.ty(&mut store).clone(), FunctionType::new(vec![], vec![]) ); - let function = - Function::new_native(&mut store, &env, |_env: FunctionEnvMut, _a: i32| {}); + let function = Function::new_typed_with_env( + &mut store, + &env, + |_env: FunctionEnvMut, _a: i32| {}, + ); assert_eq!( function.ty(&mut store).clone(), FunctionType::new(vec![Type::I32], vec![]) ); - let function = Function::new_native( + let function = Function::new_typed_with_env( &mut store, &env, |_env: FunctionEnvMut, _a: i32, _b: i64, _c: f32, _d: f64| {}, @@ -257,12 +249,14 @@ mod sys { FunctionType::new(vec![Type::I32, Type::I64, Type::F32, Type::F64], vec![]) ); let function = - Function::new_native(&mut store, &env, |_env: FunctionEnvMut| -> i32 { 1 }); + Function::new_typed_with_env(&mut store, &env, |_env: FunctionEnvMut| -> i32 { + 1 + }); assert_eq!( function.ty(&mut store).clone(), FunctionType::new(vec![], vec![Type::I32]) ); - let function = Function::new_native( + let function = Function::new_typed_with_env( &mut store, &env, |_env: FunctionEnvMut| -> (i32, i64, f32, f64) { (1, 2, 3.0, 4.0) }, @@ -277,13 +271,11 @@ mod sys { #[test] fn function_new_dynamic() -> Result<()> { let mut store = Store::default(); - let env = FunctionEnv::new(&mut store, ()); // Using &FunctionType signature let function_type = FunctionType::new(vec![], vec![]); let function = Function::new( &mut store, - &env, &function_type, |_env: FunctionEnvMut<()>, _values: &[Value]| unimplemented!(), ); @@ -291,7 +283,6 @@ mod sys { let function_type = FunctionType::new(vec![Type::I32], vec![]); let function = Function::new( &mut store, - &env, &function_type, |_env: FunctionEnvMut<()>, _values: &[Value]| unimplemented!(), ); @@ -300,7 +291,6 @@ mod sys { FunctionType::new(vec![Type::I32, Type::I64, Type::F32, Type::F64], vec![]); let function = Function::new( &mut store, - &env, &function_type, |_env: FunctionEnvMut<()>, _values: &[Value]| unimplemented!(), ); @@ -308,7 +298,6 @@ mod sys { let function_type = FunctionType::new(vec![], vec![Type::I32]); let function = Function::new( &mut store, - &env, &function_type, |_env: FunctionEnvMut<()>, _values: &[Value]| unimplemented!(), ); @@ -317,7 +306,6 @@ mod sys { FunctionType::new(vec![], vec![Type::I32, Type::I64, Type::F32, Type::F64]); let function = Function::new( &mut store, - &env, &function_type, |_env: FunctionEnvMut<()>, _values: &[Value]| unimplemented!(), ); @@ -327,7 +315,6 @@ mod sys { let function_type = ([Type::V128], [Type::I32, Type::F32, Type::F64]); let function = Function::new( &mut store, - &env, function_type, |_env: FunctionEnvMut<()>, _values: &[Value]| unimplemented!(), ); @@ -350,7 +337,7 @@ mod sys { // Using &FunctionType signature let function_type = FunctionType::new(vec![], vec![]); - let function = Function::new( + let function = Function::new_with_env( &mut store, &env, &function_type, @@ -358,7 +345,7 @@ mod sys { ); assert_eq!(function.ty(&mut store).clone(), function_type); let function_type = FunctionType::new(vec![Type::I32], vec![]); - let function = Function::new( + let function = Function::new_with_env( &mut store, &env, &function_type, @@ -367,7 +354,7 @@ mod sys { assert_eq!(function.ty(&mut store).clone(), function_type); let function_type = FunctionType::new(vec![Type::I32, Type::I64, Type::F32, Type::F64], vec![]); - let function = Function::new( + let function = Function::new_with_env( &mut store, &env, &function_type, @@ -375,7 +362,7 @@ mod sys { ); assert_eq!(function.ty(&mut store).clone(), function_type); let function_type = FunctionType::new(vec![], vec![Type::I32]); - let function = Function::new( + let function = Function::new_with_env( &mut store, &env, &function_type, @@ -384,7 +371,7 @@ mod sys { assert_eq!(function.ty(&mut store).clone(), function_type); let function_type = FunctionType::new(vec![], vec![Type::I32, Type::I64, Type::F32, Type::F64]); - let function = Function::new( + let function = Function::new_with_env( &mut store, &env, &function_type, @@ -394,7 +381,7 @@ mod sys { // Using array signature let function_type = ([Type::V128], [Type::I32, Type::F32, Type::F64]); - let function = Function::new( + let function = Function::new_with_env( &mut store, &env, function_type, @@ -412,40 +399,39 @@ mod sys { // #[test] // fn native_function_works() -> Result<()> { // let mut store = Store::default(); - // let env = FunctionEnv::new(&mut store, ()); - // let function = Function::new_native(&mut store, &env, |_env: FunctionEnvMut<()>| {}); - // let native_function: TypedFunction<(), ()> = function.native(&mut store).unwrap(); - // let result = native_function.call(&mut store); + // let function = Function::new_typed(&mut store, || {}); + // let typed_function: TypedFunction<(), ()> = function.typed(&mut store).unwrap(); + // let result = typed_function.call(&mut store); // assert!(result.is_ok()); // let function = - // Function::new_native(&mut store, &env, |_env: FunctionEnvMut<()>, a: i32| -> i32 { a + 1 }); - // let native_function: TypedFunction = function.native(&mut store).unwrap(); - // assert_eq!(native_function.call(&mut store, 3).unwrap(), 4); + // Function::new_typed(&mut store, |a: i32| -> i32 { a + 1 }); + // let typed_function: TypedFunction = function.typed(&mut store).unwrap(); + // assert_eq!(typed_function.call(&mut store, 3).unwrap(), 4); - // fn rust_abi(_env: FunctionEnvMut<()>, 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) // } - // let function = Function::new_native(&mut store, &env, rust_abi); - // let native_function: TypedFunction<(i32, i64, f32, f64), u64> = - // function.native(&mut store).unwrap(); - // assert_eq!(native_function.call(&mut store, 8, 4, 1.5, 5.).unwrap(), 8415); + // let function = Function::new_typed(&mut store, rust_abi); + // let typed_function: TypedFunction<(i32, i64, f32, f64), u64> = + // function.typed(&mut store).unwrap(); + // assert_eq!(typed_function.call(&mut store, 8, 4, 1.5, 5.).unwrap(), 8415); - // let function = Function::new_native(&mut store, &env, |_env: FunctionEnvMut<()>| -> i32 { 1 }); - // let native_function: TypedFunction<(), i32> = function.native(&mut store).unwrap(); - // assert_eq!(native_function.call(&mut store).unwrap(), 1); + // let function = Function::new_typed(&mut store, || -> i32 { 1 }); + // let typed_function: TypedFunction<(), i32> = function.typed(&mut store).unwrap(); + // assert_eq!(typed_function.call(&mut store).unwrap(), 1); - // let function = Function::new_native(&mut store, &env, |_env: FunctionEnvMut<()>, _a: i32| {}); - // let native_function: TypedFunction = function.native(&mut store).unwrap(); - // assert!(native_function.call(&mut store, 4).is_ok()); + // let function = Function::new_typed(&mut store, |_a: i32| {}); + // let typed_function: TypedFunction = function.typed(&mut store).unwrap(); + // assert!(typed_function.call(&mut store, 4).is_ok()); // let function = - // Function::new_native(&mut store, &env, |_env: FunctionEnvMut<()>| -> (i32, i64, f32, f64) { + // Function::new_typed(&mut store, || -> (i32, i64, f32, f64) { // (1, 2, 3.0, 4.0) // }); - // let native_function: TypedFunction<(), (i32, i64, f32, f64)> = - // function.native(&mut store).unwrap(); - // assert_eq!(native_function.call(&mut store).unwrap(), (1, 2, 3.0, 4.0)); + // let typed_function: TypedFunction<(), (i32, i64, f32, f64)> = + // function.typed(&mut store).unwrap(); + // assert_eq!(typed_function.call(&mut store).unwrap(), (1, 2, 3.0, 4.0)); // Ok(()) // } @@ -453,7 +439,6 @@ mod sys { // #[test] // fn function_outlives_instance() -> Result<()> { // let mut store = Store::default(); - // let env = FunctionEnv::new(&mut store, ()); // let wat = r#"(module // (type $sum_t (func (param i32 i32) (result i32))) // (func $sum_f (type $sum_t) (param $x i32) (param $y i32) (result i32) @@ -481,7 +466,6 @@ mod sys { // #[test] // fn weak_instance_ref_externs_after_instance() -> Result<()> { // let mut store = Store::default(); - // let env = FunctionEnv::new(&mut store, ()); // let wat = r#"(module // (memory (export "mem") 1) // (type $sum_t (func (param i32 i32) (result i32))) diff --git a/lib/api/tests/sys_instance.rs b/lib/api/tests/sys_instance.rs index d5b942972..c1f51ed65 100644 --- a/lib/api/tests/sys_instance.rs +++ b/lib/api/tests/sys_instance.rs @@ -65,7 +65,7 @@ mod sys { let env = FunctionEnv::new(&mut store, env); let imported_signature = FunctionType::new(vec![Type::I32], vec![Type::I32]); - let imported = Function::new(&mut store, &env, imported_signature, imported_fn); + let imported = Function::new_with_env(&mut store, &env, imported_signature, imported_fn); let expected = vec![Value::I32(12)].into_boxed_slice(); let result = imported.call(&mut store, &[Value::I32(4)])?; diff --git a/lib/api/tests/sys_module.rs b/lib/api/tests/sys_module.rs index 3d1834639..521ad3207 100644 --- a/lib/api/tests/sys_module.rs +++ b/lib/api/tests/sys_module.rs @@ -1,7 +1,6 @@ #[cfg(feature = "sys")] mod sys { use anyhow::Result; - use wasmer::FunctionEnv; use wasmer::*; #[test] @@ -191,38 +190,37 @@ mod sys { (call 7 (i32.const -1))) )"#; let module = Module::new(&store, wat)?; - let env = FunctionEnv::new(&mut store, ()); let imports = imports! { "host" => { - "host_func1" => Function::new_native(&mut store, &env,|_env: FunctionEnvMut<()>, p: u64| { + "host_func1" => Function::new_typed(&mut store, |_env: FunctionEnvMut<()>, p: u64| { println!("host_func1: Found number {}", p); assert_eq!(p, u64::max_value()); }), - "host_func2" => Function::new_native(&mut store, &env,|_env: FunctionEnvMut<()>, p: u32| { + "host_func2" => Function::new_typed(&mut store, |_env: FunctionEnvMut<()>, p: u32| { println!("host_func2: Found number {}", p); assert_eq!(p, u32::max_value()); }), - "host_func3" => Function::new_native(&mut store, &env,|_env: FunctionEnvMut<()>, p: i64| { + "host_func3" => Function::new_typed(&mut store, |_env: FunctionEnvMut<()>, p: i64| { println!("host_func3: Found number {}", p); assert_eq!(p, -1); }), - "host_func4" => Function::new_native(&mut store, &env,|_env: FunctionEnvMut<()>, p: i32| { + "host_func4" => Function::new_typed(&mut store, |_env: FunctionEnvMut<()>, p: i32| { println!("host_func4: Found number {}", p); assert_eq!(p, -1); }), - "host_func5" => Function::new_native(&mut store, &env,|_env: FunctionEnvMut<()>, p: i16| { + "host_func5" => Function::new_typed(&mut store, |_env: FunctionEnvMut<()>, p: i16| { println!("host_func5: Found number {}", p); assert_eq!(p, -1); }), - "host_func6" => Function::new_native(&mut store, &env,|_env: FunctionEnvMut<()>, p: u16| { + "host_func6" => Function::new_typed(&mut store, |_env: FunctionEnvMut<()>, p: u16| { println!("host_func6: Found number {}", p); assert_eq!(p, u16::max_value()); }), - "host_func7" => Function::new_native(&mut store, &env,|_env: FunctionEnvMut<()>, p: i8| { + "host_func7" => Function::new_typed(&mut store, |_env: FunctionEnvMut<()>, p: i8| { println!("host_func7: Found number {}", p); assert_eq!(p, -1); }), - "host_func8" => Function::new_native(&mut store, &env,|_env: FunctionEnvMut<()>, p: u8| { + "host_func8" => Function::new_typed(&mut store, |_env: FunctionEnvMut<()>, p: u8| { println!("host_func8: Found number {}", p); assert_eq!(p, u8::max_value()); }), diff --git a/lib/api/tests/sys_reference_types.rs b/lib/api/tests/sys_reference_types.rs index 24eb03f11..f2cf89b3a 100644 --- a/lib/api/tests/sys_reference_types.rs +++ b/lib/api/tests/sys_reference_types.rs @@ -27,7 +27,7 @@ mod sys { let env = FunctionEnv::new(&mut store, env); let imports = imports! { "env" => { - "func_ref_identity" => Function::new(&mut store, &env, FunctionType::new([Type::FuncRef], [Type::FuncRef]), |_env: FunctionEnvMut, values: &[Value]| -> Result, _> { + "func_ref_identity" => Function::new_with_env(&mut store, &env, FunctionType::new([Type::FuncRef], [Type::FuncRef]), |_env: FunctionEnvMut, values: &[Value]| -> Result, _> { Ok(vec![values[0].clone()]) }) }, @@ -44,7 +44,7 @@ mod sys { } let func_to_call = - Function::new_native(&mut store, &env, |mut env: FunctionEnvMut| -> i32 { + Function::new_typed_with_env(&mut store, &env, |mut env: FunctionEnvMut| -> i32 { env.data_mut().0.store(true, Ordering::SeqCst); 343 }); @@ -88,20 +88,20 @@ mod sys { ) -> Result, RuntimeError> { // TODO: look into `Box<[Value]>` being returned breakage let f = values[0].unwrap_funcref().as_ref().unwrap(); - let f: TypedFunction<(i32, i32), i32> = f.native(&mut env)?; + let f: TypedFunction<(i32, i32), i32> = f.typed(&mut env)?; Ok(vec![Value::I32(f.call(&mut env, 7, 9)?)]) } let imports = imports! { "env" => { - "func_ref_call" => Function::new( + "func_ref_call" => Function::new_with_env( &mut store, &env, FunctionType::new([Type::FuncRef], [Type::I32]), func_ref_call ), - // "func_ref_call_native" => Function::new_native(&mut store, &env, |_env: FunctionEnvMut<()>, f: Function| -> Result { - // let f: TypedFunction::<(i32, i32), i32> = f.native(&mut store)?; + // "func_ref_call_native" => Function::new_native(&mut store, |f: Function| -> Result { + // let f: TypedFunction::<(i32, i32), i32> = f.typed(&mut store)?; // f.call(&mut store, 7, 9) // }) }, @@ -112,7 +112,7 @@ mod sys { fn sum(_env: FunctionEnvMut<()>, a: i32, b: i32) -> i32 { a + b } - let sum_func = Function::new_native(&mut store, &env, sum); + let sum_func = Function::new_typed(&mut store, sum); let call_func: &Function = instance.exports.get_function("call_func")?; let result = call_func.call(&mut store, &[Value::FuncRef(Some(sum_func))])?; @@ -157,7 +157,7 @@ mod sys { "extern_ref_identity" => Function::new(&mut store, &env, FunctionType::new([Type::ExternRef], [Type::ExternRef]), |_env, values| -> Result, _> { Ok(vec![values[0].clone()]) }), - "extern_ref_identity_native" => Function::new_native(&mut store, &env, |_env: FunctionEnvMut<()>, er: ExternRef| -> ExternRef { + "extern_ref_identity_native" => Function::new_typed(&mut store, |er: ExternRef| -> ExternRef { er }), "get_new_extern_ref" => Function::new(&mut store, &env, FunctionType::new([], [Type::ExternRef]), |_env, _| -> Result, _> { @@ -170,7 +170,7 @@ mod sys { let new_extern_ref = ExternRef::new(&mut env, inner); Ok(vec![Value::ExternRef(new_extern_ref)]) }), - "get_new_extern_ref_native" => Function::new_native(&mut store, &env,|_env| -> ExternRef { + "get_new_extern_ref_native" => Function::new_native(&mut store, || -> ExternRef { let inner = [("hello".to_string(), "world".to_string()), ("color".to_string(), "orange".to_string())] @@ -292,7 +292,7 @@ mod sys { panic!("Did not find a null func ref in the global"); } - let f = Function::new_native(&store, |arg1: i32, arg2: i32| -> i32 { arg1 + arg2 }); + let f = Function::new_typed(&store, |arg1: i32, arg2: i32| -> i32 { arg1 + arg2 }); fr_global.set(Value::FuncRef(Some(f)))?; diff --git a/lib/c-api/src/wasm_c_api/externals/function.rs b/lib/c-api/src/wasm_c_api/externals/function.rs index 7ed8fa1df..e72c277ed 100644 --- a/lib/c-api/src/wasm_c_api/externals/function.rs +++ b/lib/c-api/src/wasm_c_api/externals/function.rs @@ -55,7 +55,7 @@ pub unsafe extern "C" fn wasm_func_new( let func_sig = &function_type.inner().function_type; let num_rets = func_sig.results().len(); - let inner_callback = move |mut _ctx: FunctionEnvMut<'_, FunctionCEnv>, + let inner_callback = move |mut _env: FunctionEnvMut<'_, FunctionCEnv>, args: &[Value]| -> Result, RuntimeError> { let processed_args: wasm_val_vec_t = args @@ -90,7 +90,7 @@ pub unsafe extern "C" fn wasm_func_new( Ok(processed_results) }; let env = FunctionEnv::new(&mut store_mut, FunctionCEnv::default()); - let function = Function::new(&mut store_mut, &env, func_sig, inner_callback); + let function = Function::new_with_env(&mut store_mut, &env, func_sig, inner_callback); Some(Box::new(wasm_func_t { extern_: wasm_extern_t::new(store.inner.clone(), function.into()), })) @@ -179,7 +179,7 @@ pub unsafe extern "C" fn wasm_func_new_with_env( env_finalizer: Arc::new(Mutex::new(env_finalizer)), }, ); - let function = Function::new(&mut store_mut, &env, func_sig, inner_callback); + let function = Function::new_with_env(&mut store_mut, &env, func_sig, inner_callback); Some(Box::new(wasm_func_t { extern_: wasm_extern_t::new(store.inner.clone(), function.into()), })) diff --git a/lib/emscripten/src/lib.rs b/lib/emscripten/src/lib.rs index 69cf30686..01d74db7d 100644 --- a/lib/emscripten/src/lib.rs +++ b/lib/emscripten/src/lib.rs @@ -23,9 +23,9 @@ use std::f64; use std::path::PathBuf; use std::sync::{Arc, Mutex, RwLock}; use wasmer::{ - imports, namespace, AsStoreMut, ExportError, Exports, Function, FunctionEnv, FunctionEnvMut, - FunctionType, Global, Imports, Instance, Memory, MemoryType, Module, Pages, RuntimeError, - Table, TableType, TypedFunction, Value, WasmPtr, AsStoreRef, MemoryView, + imports, namespace, AsStoreMut, AsStoreRef, ExportError, Exports, Function, FunctionEnv, + FunctionEnvMut, FunctionType, Global, Imports, Instance, Memory, MemoryType, MemoryView, + Module, Pages, RuntimeError, Table, TableType, TypedFunction, Value, WasmPtr, }; use wasmer_types::Type as ValType; @@ -553,7 +553,7 @@ pub fn emscripten_get_main_func_name<'a>( pub fn emscripten_call_main( instance: &mut Instance, function_name: &str, - mut ctx: FunctionEnvMut, + mut env: FunctionEnvMut, path: &str, args: &[&str], ) -> Result<(), RuntimeError> { @@ -561,18 +561,18 @@ pub fn emscripten_call_main( .exports .get::(function_name) .map_err(|e| RuntimeError::new(e.to_string()))?; - let num_params = main_func.ty(&ctx).params().len(); + let num_params = main_func.ty(&env).params().len(); let _result = match num_params { 2 => { let mut new_args = vec![path]; new_args.extend(args); - let (argc, argv) = store_module_arguments(&mut ctx, new_args); + let (argc, argv) = store_module_arguments(&mut env, new_args); let func: &Function = instance .exports .get(function_name) .map_err(|e| RuntimeError::new(e.to_string()))?; func.call( - &mut ctx, + &mut env, &[Value::I32(argc as i32), Value::I32(argv as i32)], )?; } @@ -581,7 +581,7 @@ pub fn emscripten_call_main( .exports .get(function_name) .map_err(|e| RuntimeError::new(e.to_string()))?; - func.call(&mut ctx, &[])?; + func.call(&mut env, &[])?; } _ => { todo!("Update error type to be able to express this"); @@ -597,247 +597,247 @@ pub fn emscripten_call_main( /// Top level function to execute emscripten pub fn run_emscripten_instance( instance: &mut Instance, - mut ctx: FunctionEnvMut, + mut env: FunctionEnvMut, globals: &mut EmscriptenGlobals, path: &str, args: Vec<&str>, entrypoint: Option, ) -> Result<(), RuntimeError> { - let env = &mut ctx.data_mut(); - env.set_memory(globals.memory.clone()); + env.data_mut().set_memory(globals.memory.clone()); + // get emscripten export let mut emfuncs = EmscriptenFunctions::new(); - if let Ok(func) = instance.exports.get_typed_function(&ctx, "malloc") { + if let Ok(func) = instance.exports.get_typed_function(&env, "malloc") { emfuncs.malloc = Some(func); - } else if let Ok(func) = instance.exports.get_typed_function(&ctx, "_malloc") { + } else if let Ok(func) = instance.exports.get_typed_function(&env, "_malloc") { emfuncs.malloc = Some(func); } - if let Ok(func) = instance.exports.get_typed_function(&ctx, "free") { + if let Ok(func) = instance.exports.get_typed_function(&env, "free") { emfuncs.free = Some(func); - } else if let Ok(func) = instance.exports.get_typed_function(&ctx, "_free") { + } else if let Ok(func) = instance.exports.get_typed_function(&env, "_free") { emfuncs.free = Some(func); } - if let Ok(func) = instance.exports.get_typed_function(&ctx, "memalign") { + if let Ok(func) = instance.exports.get_typed_function(&env, "memalign") { emfuncs.memalign = Some(func); - } else if let Ok(func) = instance.exports.get_typed_function(&ctx, "_memalign") { + } else if let Ok(func) = instance.exports.get_typed_function(&env, "_memalign") { emfuncs.memalign = Some(func); } - if let Ok(func) = instance.exports.get_typed_function(&ctx, "memset") { + if let Ok(func) = instance.exports.get_typed_function(&env, "memset") { emfuncs.memset = Some(func); - } else if let Ok(func) = instance.exports.get_typed_function(&ctx, "_memset") { + } else if let Ok(func) = instance.exports.get_typed_function(&env, "_memset") { emfuncs.memset = Some(func); } - if let Ok(func) = instance.exports.get_typed_function(&ctx, "stackAlloc") { + if let Ok(func) = instance.exports.get_typed_function(&env, "stackAlloc") { emfuncs.stack_alloc = Some(func); } - if let Ok(func) = instance.exports.get_typed_function(&ctx, "dynCall_i") { + if let Ok(func) = instance.exports.get_typed_function(&env, "dynCall_i") { emfuncs.dyn_call_i = Some(func); } - if let Ok(func) = instance.exports.get_typed_function(&ctx, "dynCall_ii") { + if let Ok(func) = instance.exports.get_typed_function(&env, "dynCall_ii") { emfuncs.dyn_call_ii = Some(func); } - if let Ok(func) = instance.exports.get_typed_function(&ctx, "dynCall_iii") { + if let Ok(func) = instance.exports.get_typed_function(&env, "dynCall_iii") { emfuncs.dyn_call_iii = Some(func); } - if let Ok(func) = instance.exports.get_typed_function(&ctx, "dynCall_iiii") { + if let Ok(func) = instance.exports.get_typed_function(&env, "dynCall_iiii") { emfuncs.dyn_call_iiii = Some(func); } - if let Ok(func) = instance.exports.get_typed_function(&ctx, "dynCall_iifi") { + if let Ok(func) = instance.exports.get_typed_function(&env, "dynCall_iifi") { emfuncs.dyn_call_iifi = Some(func); } - if let Ok(func) = instance.exports.get_typed_function(&ctx, "dynCall_v") { + if let Ok(func) = instance.exports.get_typed_function(&env, "dynCall_v") { emfuncs.dyn_call_v = Some(func); } - if let Ok(func) = instance.exports.get_typed_function(&ctx, "dynCall_vi") { + if let Ok(func) = instance.exports.get_typed_function(&env, "dynCall_vi") { emfuncs.dyn_call_vi = Some(func); } - if let Ok(func) = instance.exports.get_typed_function(&ctx, "dynCall_vii") { + if let Ok(func) = instance.exports.get_typed_function(&env, "dynCall_vii") { emfuncs.dyn_call_vii = Some(func); } - if let Ok(func) = instance.exports.get_typed_function(&ctx, "dynCall_viii") { + if let Ok(func) = instance.exports.get_typed_function(&env, "dynCall_viii") { emfuncs.dyn_call_viii = Some(func); } - if let Ok(func) = instance.exports.get_typed_function(&ctx, "dynCall_viiii") { + if let Ok(func) = instance.exports.get_typed_function(&env, "dynCall_viiii") { emfuncs.dyn_call_viiii = Some(func); } - if let Ok(func) = instance.exports.get_typed_function(&ctx, "dynCall_dii") { + if let Ok(func) = instance.exports.get_typed_function(&env, "dynCall_dii") { emfuncs.dyn_call_dii = Some(func); } - if let Ok(func) = instance.exports.get_typed_function(&ctx, "dynCall_diiii") { + if let Ok(func) = instance.exports.get_typed_function(&env, "dynCall_diiii") { emfuncs.dyn_call_diiii = Some(func); } - if let Ok(func) = instance.exports.get_typed_function(&ctx, "dynCall_iiiii") { + if let Ok(func) = instance.exports.get_typed_function(&env, "dynCall_iiiii") { emfuncs.dyn_call_iiiii = Some(func); } - if let Ok(func) = instance.exports.get_typed_function(&ctx, "dynCall_iiiiii") { + if let Ok(func) = instance.exports.get_typed_function(&env, "dynCall_iiiiii") { emfuncs.dyn_call_iiiiii = Some(func); } - if let Ok(func) = instance.exports.get_typed_function(&ctx, "dynCall_iiiiiii") { + if let Ok(func) = instance.exports.get_typed_function(&env, "dynCall_iiiiiii") { emfuncs.dyn_call_iiiiiii = Some(func); } if let Ok(func) = instance .exports - .get_typed_function(&ctx, "dynCall_iiiiiiii") + .get_typed_function(&env, "dynCall_iiiiiiii") { emfuncs.dyn_call_iiiiiiii = Some(func); } if let Ok(func) = instance .exports - .get_typed_function(&ctx, "dynCall_iiiiiiiii") + .get_typed_function(&env, "dynCall_iiiiiiiii") { emfuncs.dyn_call_iiiiiiiii = Some(func); } if let Ok(func) = instance .exports - .get_typed_function(&ctx, "dynCall_iiiiiiiiii") + .get_typed_function(&env, "dynCall_iiiiiiiiii") { emfuncs.dyn_call_iiiiiiiiii = Some(func); } if let Ok(func) = instance .exports - .get_typed_function(&ctx, "dynCall_iiiiiiiiiii") + .get_typed_function(&env, "dynCall_iiiiiiiiiii") { emfuncs.dyn_call_iiiiiiiiiii = Some(func); } - if let Ok(func) = instance.exports.get_typed_function(&ctx, "dynCall_vd") { + if let Ok(func) = instance.exports.get_typed_function(&env, "dynCall_vd") { emfuncs.dyn_call_vd = Some(func); } - if let Ok(func) = instance.exports.get_typed_function(&ctx, "dynCall_viiiii") { + if let Ok(func) = instance.exports.get_typed_function(&env, "dynCall_viiiii") { emfuncs.dyn_call_viiiii = Some(func); } - if let Ok(func) = instance.exports.get_typed_function(&ctx, "dynCall_viiiiii") { + if let Ok(func) = instance.exports.get_typed_function(&env, "dynCall_viiiiii") { emfuncs.dyn_call_viiiiii = Some(func); } if let Ok(func) = instance .exports - .get_typed_function(&ctx, "dynCall_viiiiiii") + .get_typed_function(&env, "dynCall_viiiiiii") { emfuncs.dyn_call_viiiiiii = Some(func); } if let Ok(func) = instance .exports - .get_typed_function(&ctx, "dynCall_viiiiiiii") + .get_typed_function(&env, "dynCall_viiiiiiii") { emfuncs.dyn_call_viiiiiiii = Some(func); } if let Ok(func) = instance .exports - .get_typed_function(&ctx, "dynCall_viiiiiiiii") + .get_typed_function(&env, "dynCall_viiiiiiiii") { emfuncs.dyn_call_viiiiiiiii = Some(func); } if let Ok(func) = instance .exports - .get_typed_function(&ctx, "dynCall_viiiiiiiiii") + .get_typed_function(&env, "dynCall_viiiiiiiiii") { emfuncs.dyn_call_viiiiiiiiii = Some(func); } - if let Ok(func) = instance.exports.get_typed_function(&ctx, "dynCall_iij") { + if let Ok(func) = instance.exports.get_typed_function(&env, "dynCall_iij") { emfuncs.dyn_call_iij = Some(func); } - if let Ok(func) = instance.exports.get_typed_function(&ctx, "dynCall_iji") { + if let Ok(func) = instance.exports.get_typed_function(&env, "dynCall_iji") { emfuncs.dyn_call_iji = Some(func); } - if let Ok(func) = instance.exports.get_typed_function(&ctx, "dynCall_iiji") { + if let Ok(func) = instance.exports.get_typed_function(&env, "dynCall_iiji") { emfuncs.dyn_call_iiji = Some(func); } - if let Ok(func) = instance.exports.get_typed_function(&ctx, "dynCall_iiijj") { + if let Ok(func) = instance.exports.get_typed_function(&env, "dynCall_iiijj") { emfuncs.dyn_call_iiijj = Some(func); } - if let Ok(func) = instance.exports.get_typed_function(&ctx, "dynCall_j") { + if let Ok(func) = instance.exports.get_typed_function(&env, "dynCall_j") { emfuncs.dyn_call_j = Some(func); } - if let Ok(func) = instance.exports.get_typed_function(&ctx, "dynCall_ji") { + if let Ok(func) = instance.exports.get_typed_function(&env, "dynCall_ji") { emfuncs.dyn_call_ji = Some(func); } - if let Ok(func) = instance.exports.get_typed_function(&ctx, "dynCall_jii") { + if let Ok(func) = instance.exports.get_typed_function(&env, "dynCall_jii") { emfuncs.dyn_call_jii = Some(func); } - if let Ok(func) = instance.exports.get_typed_function(&ctx, "dynCall_jij") { + if let Ok(func) = instance.exports.get_typed_function(&env, "dynCall_jij") { emfuncs.dyn_call_jij = Some(func); } - if let Ok(func) = instance.exports.get_typed_function(&ctx, "dynCall_jjj") { + if let Ok(func) = instance.exports.get_typed_function(&env, "dynCall_jjj") { emfuncs.dyn_call_jjj = Some(func); } - if let Ok(func) = instance.exports.get_typed_function(&ctx, "dynCall_viiij") { + if let Ok(func) = instance.exports.get_typed_function(&env, "dynCall_viiij") { emfuncs.dyn_call_viiij = Some(func); } if let Ok(func) = instance .exports - .get_typed_function(&ctx, "dynCall_viiijiiii") + .get_typed_function(&env, "dynCall_viiijiiii") { emfuncs.dyn_call_viiijiiii = Some(func); } if let Ok(func) = instance .exports - .get_typed_function(&ctx, "dynCall_viiijiiiiii") + .get_typed_function(&env, "dynCall_viiijiiiiii") { emfuncs.dyn_call_viiijiiiiii = Some(func); } - if let Ok(func) = instance.exports.get_typed_function(&ctx, "dynCall_viij") { + if let Ok(func) = instance.exports.get_typed_function(&env, "dynCall_viij") { emfuncs.dyn_call_viij = Some(func); } - if let Ok(func) = instance.exports.get_typed_function(&ctx, "dynCall_viiji") { + if let Ok(func) = instance.exports.get_typed_function(&env, "dynCall_viiji") { emfuncs.dyn_call_viiji = Some(func); } - if let Ok(func) = instance.exports.get_typed_function(&ctx, "dynCall_viijiii") { + if let Ok(func) = instance.exports.get_typed_function(&env, "dynCall_viijiii") { emfuncs.dyn_call_viijiii = Some(func); } - if let Ok(func) = instance.exports.get_typed_function(&ctx, "dynCall_viijj") { + if let Ok(func) = instance.exports.get_typed_function(&env, "dynCall_viijj") { emfuncs.dyn_call_viijj = Some(func); } - if let Ok(func) = instance.exports.get_typed_function(&ctx, "dynCall_vj") { + if let Ok(func) = instance.exports.get_typed_function(&env, "dynCall_vj") { emfuncs.dyn_call_vj = Some(func); } - if let Ok(func) = instance.exports.get_typed_function(&ctx, "dynCall_vjji") { + if let Ok(func) = instance.exports.get_typed_function(&env, "dynCall_vjji") { emfuncs.dyn_call_vjji = Some(func); } - if let Ok(func) = instance.exports.get_typed_function(&ctx, "dynCall_vij") { + if let Ok(func) = instance.exports.get_typed_function(&env, "dynCall_vij") { emfuncs.dyn_call_vij = Some(func); } - if let Ok(func) = instance.exports.get_typed_function(&ctx, "dynCall_viji") { + if let Ok(func) = instance.exports.get_typed_function(&env, "dynCall_viji") { emfuncs.dyn_call_viji = Some(func); } - if let Ok(func) = instance.exports.get_typed_function(&ctx, "dynCall_vijiii") { + if let Ok(func) = instance.exports.get_typed_function(&env, "dynCall_vijiii") { emfuncs.dyn_call_vijiii = Some(func); } - if let Ok(func) = instance.exports.get_typed_function(&ctx, "dynCall_vijj") { + if let Ok(func) = instance.exports.get_typed_function(&env, "dynCall_vijj") { emfuncs.dyn_call_vijj = Some(func); } - if let Ok(func) = instance.exports.get_typed_function(&ctx, "dynCall_viid") { + if let Ok(func) = instance.exports.get_typed_function(&env, "dynCall_viid") { emfuncs.dyn_call_viid = Some(func); } - if let Ok(func) = instance.exports.get_typed_function(&ctx, "dynCall_vidd") { + if let Ok(func) = instance.exports.get_typed_function(&env, "dynCall_vidd") { emfuncs.dyn_call_vidd = Some(func); } - if let Ok(func) = instance.exports.get_typed_function(&ctx, "dynCall_viidii") { + if let Ok(func) = instance.exports.get_typed_function(&env, "dynCall_viidii") { emfuncs.dyn_call_viidii = Some(func); } if let Ok(func) = instance .exports - .get_typed_function(&ctx, "dynCall_viidddddddd") + .get_typed_function(&env, "dynCall_viidddddddd") { emfuncs.dyn_call_viidddddddd = Some(func); } - if let Ok(func) = instance.exports.get_typed_function(&ctx, "stackSave") { + if let Ok(func) = instance.exports.get_typed_function(&env, "stackSave") { emfuncs.stack_save = Some(func); } - if let Ok(func) = instance.exports.get_typed_function(&ctx, "stackRe&mut ctx") { + if let Ok(func) = instance.exports.get_typed_function(&env, "stackRestore") { emfuncs.stack_restore = Some(func); } - if let Ok(func) = instance.exports.get_typed_function(&ctx, "setThrew") { + if let Ok(func) = instance.exports.get_typed_function(&env, "setThrew") { emfuncs.set_threw = Some(func); } - ctx.data_mut().set_functions(emfuncs); + env.data_mut().set_functions(emfuncs); - set_up_emscripten(&mut ctx, instance)?; + set_up_emscripten(&mut env, instance)?; let main_func_names = ["_main", "main"]; if let Some(ep) = entrypoint.as_ref() { debug!("Running entry point: {}", ep); - emscripten_call_main(instance, ep, ctx, path, &args)?; + emscripten_call_main(instance, ep, env, path, &args)?; } else if let Ok(name) = emscripten_get_main_func_name(instance, &main_func_names) { - emscripten_call_main(instance, name, ctx, path, &args)?; + emscripten_call_main(instance, name, env, path, &args)?; } else { return Err(RuntimeError::new(format!( "No main function found (searched: {main_func_names:?}) and no entrypoint specified" @@ -849,16 +849,16 @@ pub fn run_emscripten_instance( Ok(()) } -fn store_module_arguments(ctx: &mut FunctionEnvMut, args: Vec<&str>) -> (u32, u32) { +fn store_module_arguments(env: &mut FunctionEnvMut, args: Vec<&str>) -> (u32, u32) { let argc = args.len() + 1; let mut args_slice = vec![0; argc]; for (slot, arg) in args_slice[0..argc].iter_mut().zip(args.iter()) { - *slot = unsafe { allocate_cstr_on_stack(&mut ctx.as_mut(), arg).0 }; + *slot = unsafe { allocate_cstr_on_stack(&mut env.as_mut(), arg).0 }; } let (argv_offset, argv_slice): (_, &mut [u32]) = - unsafe { allocate_on_stack(&mut ctx.as_mut(), ((argc) * 4) as u32) }; + unsafe { allocate_on_stack(&mut env.as_mut(), ((argc) * 4) as u32) }; assert!(!argv_slice.is_empty()); for (slot, arg) in argv_slice[0..argc].iter_mut().zip(args_slice.iter()) { *slot = *arg @@ -870,11 +870,11 @@ fn store_module_arguments(ctx: &mut FunctionEnvMut, args: Vec<&str>) -> ( pub fn emscripten_set_up_memory( store: &mut impl AsStoreMut, - ctx: &FunctionEnv, + env: &FunctionEnv, memory: &Memory, globals: &EmscriptenGlobalsData, ) -> Result<(), String> { - ctx.as_mut(store).set_memory(memory.clone()); + env.as_mut(store).set_memory(memory.clone()); let memory = memory.view(store); let dynamictop_ptr = WasmPtr::::new(globals.dynamictop_ptr).deref(&memory); let dynamic_base = globals.dynamic_base; @@ -914,7 +914,7 @@ pub struct EmscriptenGlobals { impl EmscriptenGlobals { pub fn new( mut store: &mut impl AsStoreMut, - ctx: &FunctionEnv, + env: &FunctionEnv, module: &Module, /*, static_bump: u32 */ ) -> Result { let mut use_old_abort_on_cannot_grow_memory = false; @@ -977,7 +977,7 @@ impl EmscriptenGlobals { } }; - emscripten_set_up_memory(store, ctx, &memory, &data)?; + emscripten_set_up_memory(store, env, &memory, &data)?; let mut null_function_names = vec![]; for import in module.imports().functions() { @@ -1002,17 +1002,17 @@ impl EmscriptenGlobals { pub fn generate_emscripten_env( mut store: &mut impl AsStoreMut, - ctx: &FunctionEnv, + env: &FunctionEnv, globals: &mut EmscriptenGlobals, ) -> Imports { let abort_on_cannot_grow_memory_export = if globals.data.use_old_abort_on_cannot_grow_memory { - Function::new_native( + Function::new_typed_with_env( &mut store, - ctx, + env, crate::memory::abort_on_cannot_grow_memory_old, ) } else { - Function::new_native(&mut store, ctx, crate::memory::abort_on_cannot_grow_memory) + Function::new_typed_with_env(&mut store, env, crate::memory::abort_on_cannot_grow_memory) }; let mut env_ns: Exports = namespace! { @@ -1033,427 +1033,427 @@ pub fn generate_emscripten_env( "tempDoublePtr" => Global::new(&mut store, Value::I32(globals.data.temp_double_ptr as i32)), // inet - "_inet_addr" => Function::new_native(&mut store, ctx, crate::inet::addr), + "_inet_addr" => Function::new_typed_with_env(&mut store, env, crate::inet::addr), // IO - "printf" => Function::new_native(&mut store, ctx, crate::io::printf), - "putchar" => Function::new_native(&mut store, ctx, crate::io::putchar), - "___lock" => Function::new_native(&mut store, ctx, crate::lock::___lock), - "___unlock" => Function::new_native(&mut store, ctx, crate::lock::___unlock), - "___wait" => Function::new_native(&mut store, ctx, crate::lock::___wait), - "_flock" => Function::new_native(&mut store, ctx, crate::lock::_flock), - "_chroot" => Function::new_native(&mut store, ctx, crate::io::chroot), - "_getprotobyname" => Function::new_native(&mut store, ctx, crate::io::getprotobyname), - "_getprotobynumber" => Function::new_native(&mut store, ctx, crate::io::getprotobynumber), - "_getpwuid" => Function::new_native(&mut store, ctx, crate::io::getpwuid), - "_sigdelset" => Function::new_native(&mut store, ctx, crate::io::sigdelset), - "_sigfillset" => Function::new_native(&mut store, ctx, crate::io::sigfillset), - "_tzset" => Function::new_native(&mut store, ctx, crate::io::tzset), - "_strptime" => Function::new_native(&mut store, ctx, crate::io::strptime), + "printf" => Function::new_typed_with_env(&mut store, env, crate::io::printf), + "putchar" => Function::new_typed_with_env(&mut store, env, crate::io::putchar), + "___lock" => Function::new_typed_with_env(&mut store, env, crate::lock::___lock), + "___unlock" => Function::new_typed_with_env(&mut store, env, crate::lock::___unlock), + "___wait" => Function::new_typed_with_env(&mut store, env, crate::lock::___wait), + "_flock" => Function::new_typed_with_env(&mut store, env, crate::lock::_flock), + "_chroot" => Function::new_typed_with_env(&mut store, env, crate::io::chroot), + "_getprotobyname" => Function::new_typed_with_env(&mut store, env, crate::io::getprotobyname), + "_getprotobynumber" => Function::new_typed_with_env(&mut store, env, crate::io::getprotobynumber), + "_getpwuid" => Function::new_typed_with_env(&mut store, env, crate::io::getpwuid), + "_sigdelset" => Function::new_typed_with_env(&mut store, env, crate::io::sigdelset), + "_sigfillset" => Function::new_typed_with_env(&mut store, env, crate::io::sigfillset), + "_tzset" => Function::new_typed_with_env(&mut store, env, crate::io::tzset), + "_strptime" => Function::new_typed_with_env(&mut store, env, crate::io::strptime), // exec - "_execvp" => Function::new_native(&mut store, ctx, crate::exec::execvp), - "_execl" => Function::new_native(&mut store, ctx, crate::exec::execl), - "_execle" => Function::new_native(&mut store, ctx, crate::exec::execle), + "_execvp" => Function::new_typed_with_env(&mut store, env, crate::exec::execvp), + "_execl" => Function::new_typed_with_env(&mut store, env, crate::exec::execl), + "_execle" => Function::new_typed_with_env(&mut store, env, crate::exec::execle), // exit - "__exit" => Function::new_native(&mut store, ctx, crate::exit::exit), + "__exit" => Function::new_typed_with_env(&mut store, env, crate::exit::exit), // Env - "___assert_fail" => Function::new_native(&mut store, ctx, crate::env::___assert_fail), - "_getenv" => Function::new_native(&mut store, ctx, crate::env::_getenv), - "_setenv" => Function::new_native(&mut store, ctx, crate::env::_setenv), - "_putenv" => Function::new_native(&mut store, ctx, crate::env::_putenv), - "_unsetenv" => Function::new_native(&mut store, ctx, crate::env::_unsetenv), - "_getpwnam" => Function::new_native(&mut store, ctx, crate::env::_getpwnam), - "_getgrnam" => Function::new_native(&mut store, ctx, crate::env::_getgrnam), - "___buildEnvironment" => Function::new_native(&mut store, ctx, crate::env::___build_environment), - "___setErrNo" => Function::new_native(&mut store, ctx, crate::errno::___seterrno), - "_getpagesize" => Function::new_native(&mut store, ctx, crate::env::_getpagesize), - "_sysconf" => Function::new_native(&mut store, ctx, crate::env::_sysconf), - "_getaddrinfo" => Function::new_native(&mut store, ctx, crate::env::_getaddrinfo), - "_times" => Function::new_native(&mut store, ctx, crate::env::_times), - "_pathconf" => Function::new_native(&mut store, ctx, crate::env::_pathconf), - "_fpathconf" => Function::new_native(&mut store, ctx, crate::env::_fpathconf), + "___assert_fail" => Function::new_typed_with_env(&mut store, env, crate::env::___assert_fail), + "_getenv" => Function::new_typed_with_env(&mut store, env, crate::env::_getenv), + "_setenv" => Function::new_typed_with_env(&mut store, env, crate::env::_setenv), + "_putenv" => Function::new_typed_with_env(&mut store, env, crate::env::_putenv), + "_unsetenv" => Function::new_typed_with_env(&mut store, env, crate::env::_unsetenv), + "_getpwnam" => Function::new_typed_with_env(&mut store, env, crate::env::_getpwnam), + "_getgrnam" => Function::new_typed_with_env(&mut store, env, crate::env::_getgrnam), + "___buildEnvironment" => Function::new_typed_with_env(&mut store, env, crate::env::___build_environment), + "___setErrNo" => Function::new_typed_with_env(&mut store, env, crate::errno::___seterrno), + "_getpagesize" => Function::new_typed_with_env(&mut store, env, crate::env::_getpagesize), + "_sysconf" => Function::new_typed_with_env(&mut store, env, crate::env::_sysconf), + "_getaddrinfo" => Function::new_typed_with_env(&mut store, env, crate::env::_getaddrinfo), + "_times" => Function::new_typed_with_env(&mut store, env, crate::env::_times), + "_pathconf" => Function::new_typed_with_env(&mut store, env, crate::env::_pathconf), + "_fpathconf" => Function::new_typed_with_env(&mut store, env, crate::env::_fpathconf), // Syscalls - "___syscall1" => Function::new_native(&mut store, ctx, crate::syscalls::___syscall1), - "___syscall3" => Function::new_native(&mut store, ctx, crate::syscalls::___syscall3), - "___syscall4" => Function::new_native(&mut store, ctx, crate::syscalls::___syscall4), - "___syscall5" => Function::new_native(&mut store, ctx, crate::syscalls::___syscall5), - "___syscall6" => Function::new_native(&mut store, ctx, crate::syscalls::___syscall6), - "___syscall9" => Function::new_native(&mut store, ctx, crate::syscalls::___syscall9), - "___syscall10" => Function::new_native(&mut store, ctx, crate::syscalls::___syscall10), - "___syscall12" => Function::new_native(&mut store, ctx, crate::syscalls::___syscall12), - "___syscall14" => Function::new_native(&mut store, ctx, crate::syscalls::___syscall14), - "___syscall15" => Function::new_native(&mut store, ctx, crate::syscalls::___syscall15), - "___syscall20" => Function::new_native(&mut store, ctx, crate::syscalls::___syscall20), - "___syscall21" => Function::new_native(&mut store, ctx, crate::syscalls::___syscall21), - "___syscall25" => Function::new_native(&mut store, ctx, crate::syscalls::___syscall25), - "___syscall29" => Function::new_native(&mut store, ctx, crate::syscalls::___syscall29), - "___syscall32" => Function::new_native(&mut store, ctx, crate::syscalls::___syscall32), - "___syscall33" => Function::new_native(&mut store, ctx, crate::syscalls::___syscall33), - "___syscall34" => Function::new_native(&mut store, ctx, crate::syscalls::___syscall34), - "___syscall36" => Function::new_native(&mut store, ctx, crate::syscalls::___syscall36), - "___syscall39" => Function::new_native(&mut store, ctx, crate::syscalls::___syscall39), - "___syscall38" => Function::new_native(&mut store, ctx, crate::syscalls::___syscall38), - "___syscall40" => Function::new_native(&mut store, ctx, crate::syscalls::___syscall40), - "___syscall41" => Function::new_native(&mut store, ctx, crate::syscalls::___syscall41), - "___syscall42" => Function::new_native(&mut store, ctx, crate::syscalls::___syscall42), - "___syscall51" => Function::new_native(&mut store, ctx, crate::syscalls::___syscall51), - "___syscall52" => Function::new_native(&mut store, ctx, crate::syscalls::___syscall52), - "___syscall53" => Function::new_native(&mut store, ctx, crate::syscalls::___syscall53), - "___syscall54" => Function::new_native(&mut store, ctx, crate::syscalls::___syscall54), - "___syscall57" => Function::new_native(&mut store, ctx, crate::syscalls::___syscall57), - "___syscall60" => Function::new_native(&mut store, ctx, crate::syscalls::___syscall60), - "___syscall63" => Function::new_native(&mut store, ctx, crate::syscalls::___syscall63), - "___syscall64" => Function::new_native(&mut store, ctx, crate::syscalls::___syscall64), - "___syscall66" => Function::new_native(&mut store, ctx, crate::syscalls::___syscall66), - "___syscall75" => Function::new_native(&mut store, ctx, crate::syscalls::___syscall75), - "___syscall77" => Function::new_native(&mut store, ctx, crate::syscalls::___syscall77), - "___syscall83" => Function::new_native(&mut store, ctx, crate::syscalls::___syscall83), - "___syscall85" => Function::new_native(&mut store, ctx, crate::syscalls::___syscall85), - "___syscall91" => Function::new_native(&mut store, ctx, crate::syscalls::___syscall91), - "___syscall94" => Function::new_native(&mut store, ctx, crate::syscalls::___syscall94), - "___syscall96" => Function::new_native(&mut store, ctx, crate::syscalls::___syscall96), - "___syscall97" => Function::new_native(&mut store, ctx, crate::syscalls::___syscall97), - "___syscall102" => Function::new_native(&mut store, ctx, crate::syscalls::___syscall102), - "___syscall110" => Function::new_native(&mut store, ctx, crate::syscalls::___syscall110), - "___syscall114" => Function::new_native(&mut store, ctx, crate::syscalls::___syscall114), - "___syscall118" => Function::new_native(&mut store, ctx, crate::syscalls::___syscall118), - "___syscall121" => Function::new_native(&mut store, ctx, crate::syscalls::___syscall121), - "___syscall122" => Function::new_native(&mut store, ctx, crate::syscalls::___syscall122), - "___syscall125" => Function::new_native(&mut store, ctx, crate::syscalls::___syscall125), - "___syscall132" => Function::new_native(&mut store, ctx, crate::syscalls::___syscall132), - "___syscall133" => Function::new_native(&mut store, ctx, crate::syscalls::___syscall133), - "___syscall140" => Function::new_native(&mut store, ctx, crate::syscalls::___syscall140), - "___syscall142" => Function::new_native(&mut store, ctx, crate::syscalls::___syscall142), - "___syscall144" => Function::new_native(&mut store, ctx, crate::syscalls::___syscall144), - "___syscall145" => Function::new_native(&mut store, ctx, crate::syscalls::___syscall145), - "___syscall146" => Function::new_native(&mut store, ctx, crate::syscalls::___syscall146), - "___syscall147" => Function::new_native(&mut store, ctx, crate::syscalls::___syscall147), - "___syscall148" => Function::new_native(&mut store, ctx, crate::syscalls::___syscall148), - "___syscall150" => Function::new_native(&mut store, ctx, crate::syscalls::___syscall150), - "___syscall151" => Function::new_native(&mut store, ctx, crate::syscalls::___syscall151), - "___syscall152" => Function::new_native(&mut store, ctx, crate::syscalls::___syscall152), - "___syscall153" => Function::new_native(&mut store, ctx, crate::syscalls::___syscall153), - "___syscall163" => Function::new_native(&mut store, ctx, crate::syscalls::___syscall163), - "___syscall168" => Function::new_native(&mut store, ctx, crate::syscalls::___syscall168), - "___syscall180" => Function::new_native(&mut store, ctx, crate::syscalls::___syscall180), - "___syscall181" => Function::new_native(&mut store, ctx, crate::syscalls::___syscall181), - "___syscall183" => Function::new_native(&mut store, ctx, crate::syscalls::___syscall183), - "___syscall191" => Function::new_native(&mut store, ctx, crate::syscalls::___syscall191), - "___syscall192" => Function::new_native(&mut store, ctx, crate::syscalls::___syscall192), - "___syscall193" => Function::new_native(&mut store, ctx, crate::syscalls::___syscall193), - "___syscall194" => Function::new_native(&mut store, ctx, crate::syscalls::___syscall194), - "___syscall195" => Function::new_native(&mut store, ctx, crate::syscalls::___syscall195), - "___syscall196" => Function::new_native(&mut store, ctx, crate::syscalls::___syscall196), - "___syscall197" => Function::new_native(&mut store, ctx, crate::syscalls::___syscall197), - "___syscall198" => Function::new_native(&mut store, ctx, crate::syscalls::___syscall198), - "___syscall199" => Function::new_native(&mut store, ctx, crate::syscalls::___syscall199), - "___syscall200" => Function::new_native(&mut store, ctx, crate::syscalls::___syscall200), - "___syscall201" => Function::new_native(&mut store, ctx, crate::syscalls::___syscall201), - "___syscall202" => Function::new_native(&mut store, ctx, crate::syscalls::___syscall202), - "___syscall205" => Function::new_native(&mut store, ctx, crate::syscalls::___syscall205), - "___syscall207" => Function::new_native(&mut store, ctx, crate::syscalls::___syscall207), - "___syscall209" => Function::new_native(&mut store, ctx, crate::syscalls::___syscall209), - "___syscall211" => Function::new_native(&mut store, ctx, crate::syscalls::___syscall211), - "___syscall212" => Function::new_native(&mut store, ctx, crate::syscalls::___syscall212), - "___syscall218" => Function::new_native(&mut store, ctx, crate::syscalls::___syscall218), - "___syscall219" => Function::new_native(&mut store, ctx, crate::syscalls::___syscall219), - "___syscall220" => Function::new_native(&mut store, ctx, crate::syscalls::___syscall220), - "___syscall221" => Function::new_native(&mut store, ctx, crate::syscalls::___syscall221), - "___syscall268" => Function::new_native(&mut store, ctx, crate::syscalls::___syscall268), - "___syscall269" => Function::new_native(&mut store, ctx, crate::syscalls::___syscall269), - "___syscall272" => Function::new_native(&mut store, ctx, crate::syscalls::___syscall272), - "___syscall295" => Function::new_native(&mut store, ctx, crate::syscalls::___syscall295), - "___syscall296" => Function::new_native(&mut store, ctx, crate::syscalls::___syscall296), - "___syscall297" => Function::new_native(&mut store, ctx, crate::syscalls::___syscall297), - "___syscall298" => Function::new_native(&mut store, ctx, crate::syscalls::___syscall298), - "___syscall300" => Function::new_native(&mut store, ctx, crate::syscalls::___syscall300), - "___syscall301" => Function::new_native(&mut store, ctx, crate::syscalls::___syscall301), - "___syscall302" => Function::new_native(&mut store, ctx, crate::syscalls::___syscall302), - "___syscall303" => Function::new_native(&mut store, ctx, crate::syscalls::___syscall303), - "___syscall304" => Function::new_native(&mut store, ctx, crate::syscalls::___syscall304), - "___syscall305" => Function::new_native(&mut store, ctx, crate::syscalls::___syscall305), - "___syscall306" => Function::new_native(&mut store, ctx, crate::syscalls::___syscall306), - "___syscall307" => Function::new_native(&mut store, ctx, crate::syscalls::___syscall307), - "___syscall308" => Function::new_native(&mut store, ctx, crate::syscalls::___syscall308), - "___syscall320" => Function::new_native(&mut store, ctx, crate::syscalls::___syscall320), - "___syscall324" => Function::new_native(&mut store, ctx, crate::syscalls::___syscall324), - "___syscall330" => Function::new_native(&mut store, ctx, crate::syscalls::___syscall330), - "___syscall331" => Function::new_native(&mut store, ctx, crate::syscalls::___syscall331), - "___syscall333" => Function::new_native(&mut store, ctx, crate::syscalls::___syscall333), - "___syscall334" => Function::new_native(&mut store, ctx, crate::syscalls::___syscall334), - "___syscall337" => Function::new_native(&mut store, ctx, crate::syscalls::___syscall337), - "___syscall340" => Function::new_native(&mut store, ctx, crate::syscalls::___syscall340), - "___syscall345" => Function::new_native(&mut store, ctx, crate::syscalls::___syscall345), + "___syscall1" => Function::new_typed_with_env(&mut store, env, crate::syscalls::___syscall1), + "___syscall3" => Function::new_typed_with_env(&mut store, env, crate::syscalls::___syscall3), + "___syscall4" => Function::new_typed_with_env(&mut store, env, crate::syscalls::___syscall4), + "___syscall5" => Function::new_typed_with_env(&mut store, env, crate::syscalls::___syscall5), + "___syscall6" => Function::new_typed_with_env(&mut store, env, crate::syscalls::___syscall6), + "___syscall9" => Function::new_typed_with_env(&mut store, env, crate::syscalls::___syscall9), + "___syscall10" => Function::new_typed_with_env(&mut store, env, crate::syscalls::___syscall10), + "___syscall12" => Function::new_typed_with_env(&mut store, env, crate::syscalls::___syscall12), + "___syscall14" => Function::new_typed_with_env(&mut store, env, crate::syscalls::___syscall14), + "___syscall15" => Function::new_typed_with_env(&mut store, env, crate::syscalls::___syscall15), + "___syscall20" => Function::new_typed_with_env(&mut store, env, crate::syscalls::___syscall20), + "___syscall21" => Function::new_typed_with_env(&mut store, env, crate::syscalls::___syscall21), + "___syscall25" => Function::new_typed_with_env(&mut store, env, crate::syscalls::___syscall25), + "___syscall29" => Function::new_typed_with_env(&mut store, env, crate::syscalls::___syscall29), + "___syscall32" => Function::new_typed_with_env(&mut store, env, crate::syscalls::___syscall32), + "___syscall33" => Function::new_typed_with_env(&mut store, env, crate::syscalls::___syscall33), + "___syscall34" => Function::new_typed_with_env(&mut store, env, crate::syscalls::___syscall34), + "___syscall36" => Function::new_typed_with_env(&mut store, env, crate::syscalls::___syscall36), + "___syscall39" => Function::new_typed_with_env(&mut store, env, crate::syscalls::___syscall39), + "___syscall38" => Function::new_typed_with_env(&mut store, env, crate::syscalls::___syscall38), + "___syscall40" => Function::new_typed_with_env(&mut store, env, crate::syscalls::___syscall40), + "___syscall41" => Function::new_typed_with_env(&mut store, env, crate::syscalls::___syscall41), + "___syscall42" => Function::new_typed_with_env(&mut store, env, crate::syscalls::___syscall42), + "___syscall51" => Function::new_typed_with_env(&mut store, env, crate::syscalls::___syscall51), + "___syscall52" => Function::new_typed_with_env(&mut store, env, crate::syscalls::___syscall52), + "___syscall53" => Function::new_typed_with_env(&mut store, env, crate::syscalls::___syscall53), + "___syscall54" => Function::new_typed_with_env(&mut store, env, crate::syscalls::___syscall54), + "___syscall57" => Function::new_typed_with_env(&mut store, env, crate::syscalls::___syscall57), + "___syscall60" => Function::new_typed_with_env(&mut store, env, crate::syscalls::___syscall60), + "___syscall63" => Function::new_typed_with_env(&mut store, env, crate::syscalls::___syscall63), + "___syscall64" => Function::new_typed_with_env(&mut store, env, crate::syscalls::___syscall64), + "___syscall66" => Function::new_typed_with_env(&mut store, env, crate::syscalls::___syscall66), + "___syscall75" => Function::new_typed_with_env(&mut store, env, crate::syscalls::___syscall75), + "___syscall77" => Function::new_typed_with_env(&mut store, env, crate::syscalls::___syscall77), + "___syscall83" => Function::new_typed_with_env(&mut store, env, crate::syscalls::___syscall83), + "___syscall85" => Function::new_typed_with_env(&mut store, env, crate::syscalls::___syscall85), + "___syscall91" => Function::new_typed_with_env(&mut store, env, crate::syscalls::___syscall91), + "___syscall94" => Function::new_typed_with_env(&mut store, env, crate::syscalls::___syscall94), + "___syscall96" => Function::new_typed_with_env(&mut store, env, crate::syscalls::___syscall96), + "___syscall97" => Function::new_typed_with_env(&mut store, env, crate::syscalls::___syscall97), + "___syscall102" => Function::new_typed_with_env(&mut store, env, crate::syscalls::___syscall102), + "___syscall110" => Function::new_typed_with_env(&mut store, env, crate::syscalls::___syscall110), + "___syscall114" => Function::new_typed_with_env(&mut store, env, crate::syscalls::___syscall114), + "___syscall118" => Function::new_typed_with_env(&mut store, env, crate::syscalls::___syscall118), + "___syscall121" => Function::new_typed_with_env(&mut store, env, crate::syscalls::___syscall121), + "___syscall122" => Function::new_typed_with_env(&mut store, env, crate::syscalls::___syscall122), + "___syscall125" => Function::new_typed_with_env(&mut store, env, crate::syscalls::___syscall125), + "___syscall132" => Function::new_typed_with_env(&mut store, env, crate::syscalls::___syscall132), + "___syscall133" => Function::new_typed_with_env(&mut store, env, crate::syscalls::___syscall133), + "___syscall140" => Function::new_typed_with_env(&mut store, env, crate::syscalls::___syscall140), + "___syscall142" => Function::new_typed_with_env(&mut store, env, crate::syscalls::___syscall142), + "___syscall144" => Function::new_typed_with_env(&mut store, env, crate::syscalls::___syscall144), + "___syscall145" => Function::new_typed_with_env(&mut store, env, crate::syscalls::___syscall145), + "___syscall146" => Function::new_typed_with_env(&mut store, env, crate::syscalls::___syscall146), + "___syscall147" => Function::new_typed_with_env(&mut store, env, crate::syscalls::___syscall147), + "___syscall148" => Function::new_typed_with_env(&mut store, env, crate::syscalls::___syscall148), + "___syscall150" => Function::new_typed_with_env(&mut store, env, crate::syscalls::___syscall150), + "___syscall151" => Function::new_typed_with_env(&mut store, env, crate::syscalls::___syscall151), + "___syscall152" => Function::new_typed_with_env(&mut store, env, crate::syscalls::___syscall152), + "___syscall153" => Function::new_typed_with_env(&mut store, env, crate::syscalls::___syscall153), + "___syscall163" => Function::new_typed_with_env(&mut store, env, crate::syscalls::___syscall163), + "___syscall168" => Function::new_typed_with_env(&mut store, env, crate::syscalls::___syscall168), + "___syscall180" => Function::new_typed_with_env(&mut store, env, crate::syscalls::___syscall180), + "___syscall181" => Function::new_typed_with_env(&mut store, env, crate::syscalls::___syscall181), + "___syscall183" => Function::new_typed_with_env(&mut store, env, crate::syscalls::___syscall183), + "___syscall191" => Function::new_typed_with_env(&mut store, env, crate::syscalls::___syscall191), + "___syscall192" => Function::new_typed_with_env(&mut store, env, crate::syscalls::___syscall192), + "___syscall193" => Function::new_typed_with_env(&mut store, env, crate::syscalls::___syscall193), + "___syscall194" => Function::new_typed_with_env(&mut store, env, crate::syscalls::___syscall194), + "___syscall195" => Function::new_typed_with_env(&mut store, env, crate::syscalls::___syscall195), + "___syscall196" => Function::new_typed_with_env(&mut store, env, crate::syscalls::___syscall196), + "___syscall197" => Function::new_typed_with_env(&mut store, env, crate::syscalls::___syscall197), + "___syscall198" => Function::new_typed_with_env(&mut store, env, crate::syscalls::___syscall198), + "___syscall199" => Function::new_typed_with_env(&mut store, env, crate::syscalls::___syscall199), + "___syscall200" => Function::new_typed_with_env(&mut store, env, crate::syscalls::___syscall200), + "___syscall201" => Function::new_typed_with_env(&mut store, env, crate::syscalls::___syscall201), + "___syscall202" => Function::new_typed_with_env(&mut store, env, crate::syscalls::___syscall202), + "___syscall205" => Function::new_typed_with_env(&mut store, env, crate::syscalls::___syscall205), + "___syscall207" => Function::new_typed_with_env(&mut store, env, crate::syscalls::___syscall207), + "___syscall209" => Function::new_typed_with_env(&mut store, env, crate::syscalls::___syscall209), + "___syscall211" => Function::new_typed_with_env(&mut store, env, crate::syscalls::___syscall211), + "___syscall212" => Function::new_typed_with_env(&mut store, env, crate::syscalls::___syscall212), + "___syscall218" => Function::new_typed_with_env(&mut store, env, crate::syscalls::___syscall218), + "___syscall219" => Function::new_typed_with_env(&mut store, env, crate::syscalls::___syscall219), + "___syscall220" => Function::new_typed_with_env(&mut store, env, crate::syscalls::___syscall220), + "___syscall221" => Function::new_typed_with_env(&mut store, env, crate::syscalls::___syscall221), + "___syscall268" => Function::new_typed_with_env(&mut store, env, crate::syscalls::___syscall268), + "___syscall269" => Function::new_typed_with_env(&mut store, env, crate::syscalls::___syscall269), + "___syscall272" => Function::new_typed_with_env(&mut store, env, crate::syscalls::___syscall272), + "___syscall295" => Function::new_typed_with_env(&mut store, env, crate::syscalls::___syscall295), + "___syscall296" => Function::new_typed_with_env(&mut store, env, crate::syscalls::___syscall296), + "___syscall297" => Function::new_typed_with_env(&mut store, env, crate::syscalls::___syscall297), + "___syscall298" => Function::new_typed_with_env(&mut store, env, crate::syscalls::___syscall298), + "___syscall300" => Function::new_typed_with_env(&mut store, env, crate::syscalls::___syscall300), + "___syscall301" => Function::new_typed_with_env(&mut store, env, crate::syscalls::___syscall301), + "___syscall302" => Function::new_typed_with_env(&mut store, env, crate::syscalls::___syscall302), + "___syscall303" => Function::new_typed_with_env(&mut store, env, crate::syscalls::___syscall303), + "___syscall304" => Function::new_typed_with_env(&mut store, env, crate::syscalls::___syscall304), + "___syscall305" => Function::new_typed_with_env(&mut store, env, crate::syscalls::___syscall305), + "___syscall306" => Function::new_typed_with_env(&mut store, env, crate::syscalls::___syscall306), + "___syscall307" => Function::new_typed_with_env(&mut store, env, crate::syscalls::___syscall307), + "___syscall308" => Function::new_typed_with_env(&mut store, env, crate::syscalls::___syscall308), + "___syscall320" => Function::new_typed_with_env(&mut store, env, crate::syscalls::___syscall320), + "___syscall324" => Function::new_typed_with_env(&mut store, env, crate::syscalls::___syscall324), + "___syscall330" => Function::new_typed_with_env(&mut store, env, crate::syscalls::___syscall330), + "___syscall331" => Function::new_typed_with_env(&mut store, env, crate::syscalls::___syscall331), + "___syscall333" => Function::new_typed_with_env(&mut store, env, crate::syscalls::___syscall333), + "___syscall334" => Function::new_typed_with_env(&mut store, env, crate::syscalls::___syscall334), + "___syscall337" => Function::new_typed_with_env(&mut store, env, crate::syscalls::___syscall337), + "___syscall340" => Function::new_typed_with_env(&mut store, env, crate::syscalls::___syscall340), + "___syscall345" => Function::new_typed_with_env(&mut store, env, crate::syscalls::___syscall345), // Process - "abort" => Function::new_native(&mut store, ctx, crate::process::em_abort), - "_abort" => Function::new_native(&mut store, ctx, crate::process::_abort), - "_prctl" => Function::new_native(&mut store, ctx, crate::process::_prctl), - "abortStackOverflow" => Function::new_native(&mut store, ctx, crate::process::abort_stack_overflow), - "_llvm_trap" => Function::new_native(&mut store, ctx, crate::process::_llvm_trap), - "_fork" => Function::new_native(&mut store, ctx, crate::process::_fork), - "_exit" => Function::new_native(&mut store, ctx, crate::process::_exit), - "_system" => Function::new_native(&mut store, ctx, crate::process::_system), - "_popen" => Function::new_native(&mut store, ctx, crate::process::_popen), - "_endgrent" => Function::new_native(&mut store, ctx, crate::process::_endgrent), - "_execve" => Function::new_native(&mut store, ctx, crate::process::_execve), - "_kill" => Function::new_native(&mut store, ctx, crate::process::_kill), - "_llvm_stackrestore" => Function::new_native(&mut store, ctx, crate::process::_llvm_stackrestore), - "_llvm_stacksave" => Function::new_native(&mut store, ctx, crate::process::_llvm_stacksave), - "_llvm_eh_typeid_for" => Function::new_native(&mut store, ctx, crate::process::_llvm_eh_typeid_for), - "_raise" => Function::new_native(&mut store, ctx, crate::process::_raise), - "_sem_init" => Function::new_native(&mut store, ctx, crate::process::_sem_init), - "_sem_destroy" => Function::new_native(&mut store, ctx, crate::process::_sem_destroy), - "_sem_post" => Function::new_native(&mut store, ctx, crate::process::_sem_post), - "_sem_wait" => Function::new_native(&mut store, ctx, crate::process::_sem_wait), - "_getgrent" => Function::new_native(&mut store, ctx, crate::process::_getgrent), - "_sched_yield" => Function::new_native(&mut store, ctx, crate::process::_sched_yield), - "_setgrent" => Function::new_native(&mut store, ctx, crate::process::_setgrent), - "_setgroups" => Function::new_native(&mut store, ctx, crate::process::_setgroups), - "_setitimer" => Function::new_native(&mut store, ctx, crate::process::_setitimer), - "_usleep" => Function::new_native(&mut store, ctx, crate::process::_usleep), - "_nanosleep" => Function::new_native(&mut store, ctx, crate::process::_nanosleep), - "_utime" => Function::new_native(&mut store, ctx, crate::process::_utime), - "_utimes" => Function::new_native(&mut store, ctx, crate::process::_utimes), - "_wait" => Function::new_native(&mut store, ctx, crate::process::_wait), - "_wait3" => Function::new_native(&mut store, ctx, crate::process::_wait3), - "_wait4" => Function::new_native(&mut store, ctx, crate::process::_wait4), - "_waitid" => Function::new_native(&mut store, ctx, crate::process::_waitid), - "_waitpid" => Function::new_native(&mut store, ctx, crate::process::_waitpid), + "abort" => Function::new_typed_with_env(&mut store, env, crate::process::em_abort), + "_abort" => Function::new_typed_with_env(&mut store, env, crate::process::_abort), + "_prctl" => Function::new_typed_with_env(&mut store, env, crate::process::_prctl), + "abortStackOverflow" => Function::new_typed_with_env(&mut store, env, crate::process::abort_stack_overflow), + "_llvm_trap" => Function::new_typed_with_env(&mut store, env, crate::process::_llvm_trap), + "_fork" => Function::new_typed_with_env(&mut store, env, crate::process::_fork), + "_exit" => Function::new_typed_with_env(&mut store, env, crate::process::_exit), + "_system" => Function::new_typed_with_env(&mut store, env, crate::process::_system), + "_popen" => Function::new_typed_with_env(&mut store, env, crate::process::_popen), + "_endgrent" => Function::new_typed_with_env(&mut store, env, crate::process::_endgrent), + "_execve" => Function::new_typed_with_env(&mut store, env, crate::process::_execve), + "_kill" => Function::new_typed_with_env(&mut store, env, crate::process::_kill), + "_llvm_stackrestore" => Function::new_typed_with_env(&mut store, env, crate::process::_llvm_stackrestore), + "_llvm_stacksave" => Function::new_typed_with_env(&mut store, env, crate::process::_llvm_stacksave), + "_llvm_eh_typeid_for" => Function::new_typed_with_env(&mut store, env, crate::process::_llvm_eh_typeid_for), + "_raise" => Function::new_typed_with_env(&mut store, env, crate::process::_raise), + "_sem_init" => Function::new_typed_with_env(&mut store, env, crate::process::_sem_init), + "_sem_destroy" => Function::new_typed_with_env(&mut store, env, crate::process::_sem_destroy), + "_sem_post" => Function::new_typed_with_env(&mut store, env, crate::process::_sem_post), + "_sem_wait" => Function::new_typed_with_env(&mut store, env, crate::process::_sem_wait), + "_getgrent" => Function::new_typed_with_env(&mut store, env, crate::process::_getgrent), + "_sched_yield" => Function::new_typed_with_env(&mut store, env, crate::process::_sched_yield), + "_setgrent" => Function::new_typed_with_env(&mut store, env, crate::process::_setgrent), + "_setgroups" => Function::new_typed_with_env(&mut store, env, crate::process::_setgroups), + "_setitimer" => Function::new_typed_with_env(&mut store, env, crate::process::_setitimer), + "_usleep" => Function::new_typed_with_env(&mut store, env, crate::process::_usleep), + "_nanosleep" => Function::new_typed_with_env(&mut store, env, crate::process::_nanosleep), + "_utime" => Function::new_typed_with_env(&mut store, env, crate::process::_utime), + "_utimes" => Function::new_typed_with_env(&mut store, env, crate::process::_utimes), + "_wait" => Function::new_typed_with_env(&mut store, env, crate::process::_wait), + "_wait3" => Function::new_typed_with_env(&mut store, env, crate::process::_wait3), + "_wait4" => Function::new_typed_with_env(&mut store, env, crate::process::_wait4), + "_waitid" => Function::new_typed_with_env(&mut store, env, crate::process::_waitid), + "_waitpid" => Function::new_typed_with_env(&mut store, env, crate::process::_waitpid), // Emscripten - "_emscripten_asm_const_i" => Function::new_native(&mut store, ctx, crate::emscripten_target::asm_const_i), - "_emscripten_exit_with_live_runtime" => Function::new_native(&mut store, ctx, crate::emscripten_target::exit_with_live_runtime), + "_emscripten_asm_const_i" => Function::new_typed_with_env(&mut store, env, crate::emscripten_target::asm_const_i), + "_emscripten_exit_with_live_runtime" => Function::new_typed_with_env(&mut store, env, crate::emscripten_target::exit_with_live_runtime), // Signal - "_sigemptyset" => Function::new_native(&mut store, ctx, crate::signal::_sigemptyset), - "_sigaddset" => Function::new_native(&mut store, ctx, crate::signal::_sigaddset), - "_sigprocmask" => Function::new_native(&mut store, ctx, crate::signal::_sigprocmask), - "_sigaction" => Function::new_native(&mut store, ctx, crate::signal::_sigaction), - "_signal" => Function::new_native(&mut store, ctx, crate::signal::_signal), - "_sigsuspend" => Function::new_native(&mut store, ctx, crate::signal::_sigsuspend), + "_sigemptyset" => Function::new_typed_with_env(&mut store, env, crate::signal::_sigemptyset), + "_sigaddset" => Function::new_typed_with_env(&mut store, env, crate::signal::_sigaddset), + "_sigprocmask" => Function::new_typed_with_env(&mut store, env, crate::signal::_sigprocmask), + "_sigaction" => Function::new_typed_with_env(&mut store, env, crate::signal::_sigaction), + "_signal" => Function::new_typed_with_env(&mut store, env, crate::signal::_signal), + "_sigsuspend" => Function::new_typed_with_env(&mut store, env, crate::signal::_sigsuspend), // Memory "abortOnCannotGrowMemory" => abort_on_cannot_grow_memory_export, - "_emscripten_memcpy_big" => Function::new_native(&mut store, ctx, crate::memory::_emscripten_memcpy_big), - "_emscripten_get_heap_size" => Function::new_native(&mut store, ctx, crate::memory::_emscripten_get_heap_size), - "_emscripten_resize_heap" => Function::new_native(&mut store, ctx, crate::memory::_emscripten_resize_heap), - "enlargeMemory" => Function::new_native(&mut store, ctx, crate::memory::enlarge_memory), - "segfault" => Function::new_native(&mut store, ctx, crate::memory::segfault), - "alignfault" => Function::new_native(&mut store, ctx, crate::memory::alignfault), - "ftfault" => Function::new_native(&mut store, ctx, crate::memory::ftfault), - "getTotalMemory" => Function::new_native(&mut store, ctx, crate::memory::get_total_memory), - "_sbrk" => Function::new_native(&mut store, ctx, crate::memory::sbrk), - "___map_file" => Function::new_native(&mut store, ctx, crate::memory::___map_file), + "_emscripten_memcpy_big" => Function::new_typed_with_env(&mut store, env, crate::memory::_emscripten_memcpy_big), + "_emscripten_get_heap_size" => Function::new_typed_with_env(&mut store, env, crate::memory::_emscripten_get_heap_size), + "_emscripten_resize_heap" => Function::new_typed_with_env(&mut store, env, crate::memory::_emscripten_resize_heap), + "enlargeMemory" => Function::new_typed_with_env(&mut store, env, crate::memory::enlarge_memory), + "segfault" => Function::new_typed_with_env(&mut store, env, crate::memory::segfault), + "alignfault" => Function::new_typed_with_env(&mut store, env, crate::memory::alignfault), + "ftfault" => Function::new_typed_with_env(&mut store, env, crate::memory::ftfault), + "getTotalMemory" => Function::new_typed_with_env(&mut store, env, crate::memory::get_total_memory), + "_sbrk" => Function::new_typed_with_env(&mut store, env, crate::memory::sbrk), + "___map_file" => Function::new_typed_with_env(&mut store, env, crate::memory::___map_file), // Exception - "___cxa_allocate_exception" => Function::new_native(&mut store, ctx, crate::exception::___cxa_allocate_exception), - "___cxa_current_primary_exception" => Function::new_native(&mut store, ctx, crate::exception::___cxa_current_primary_exception), - "___cxa_decrement_exception_refcount" => Function::new_native(&mut store, ctx, crate::exception::___cxa_decrement_exception_refcount), - "___cxa_increment_exception_refcount" => Function::new_native(&mut store, ctx, crate::exception::___cxa_increment_exception_refcount), - "___cxa_rethrow_primary_exception" => Function::new_native(&mut store, ctx, crate::exception::___cxa_rethrow_primary_exception), - "___cxa_throw" => Function::new_native(&mut store, ctx, crate::exception::___cxa_throw), - "___cxa_begin_catch" => Function::new_native(&mut store, ctx, crate::exception::___cxa_begin_catch), - "___cxa_end_catch" => Function::new_native(&mut store, ctx, crate::exception::___cxa_end_catch), - "___cxa_uncaught_exception" => Function::new_native(&mut store, ctx, crate::exception::___cxa_uncaught_exception), - "___cxa_pure_virtual" => Function::new_native(&mut store, ctx, crate::exception::___cxa_pure_virtual), + "___cxa_allocate_exception" => Function::new_typed_with_env(&mut store, env, crate::exception::___cxa_allocate_exception), + "___cxa_current_primary_exception" => Function::new_typed_with_env(&mut store, env, crate::exception::___cxa_current_primary_exception), + "___cxa_decrement_exception_refcount" => Function::new_typed_with_env(&mut store, env, crate::exception::___cxa_decrement_exception_refcount), + "___cxa_increment_exception_refcount" => Function::new_typed_with_env(&mut store, env, crate::exception::___cxa_increment_exception_refcount), + "___cxa_rethrow_primary_exception" => Function::new_typed_with_env(&mut store, env, crate::exception::___cxa_rethrow_primary_exception), + "___cxa_throw" => Function::new_typed_with_env(&mut store, env, crate::exception::___cxa_throw), + "___cxa_begin_catch" => Function::new_typed_with_env(&mut store, env, crate::exception::___cxa_begin_catch), + "___cxa_end_catch" => Function::new_typed_with_env(&mut store, env, crate::exception::___cxa_end_catch), + "___cxa_uncaught_exception" => Function::new_typed_with_env(&mut store, env, crate::exception::___cxa_uncaught_exception), + "___cxa_pure_virtual" => Function::new_typed_with_env(&mut store, env, crate::exception::___cxa_pure_virtual), // Time - "_gettimeofday" => Function::new_native(&mut store, ctx, crate::time::_gettimeofday), - "_clock_getres" => Function::new_native(&mut store, ctx, crate::time::_clock_getres), - "_clock_gettime" => Function::new_native(&mut store, ctx, crate::time::_clock_gettime), - "_clock_settime" => Function::new_native(&mut store, ctx, crate::time::_clock_settime), - "___clock_gettime" => Function::new_native(&mut store, ctx, crate::time::_clock_gettime), - "_clock" => Function::new_native(&mut store, ctx, crate::time::_clock), - "_difftime" => Function::new_native(&mut store, ctx, crate::time::_difftime), - "_asctime" => Function::new_native(&mut store, ctx, crate::time::_asctime), - "_asctime_r" => Function::new_native(&mut store, ctx, crate::time::_asctime_r), - "_localtime" => Function::new_native(&mut store, ctx, crate::time::_localtime), - "_time" => Function::new_native(&mut store, ctx, crate::time::_time), - "_timegm" => Function::new_native(&mut store, ctx, crate::time::_timegm), - "_strftime" => Function::new_native(&mut store, ctx, crate::time::_strftime), - "_strftime_l" => Function::new_native(&mut store, ctx, crate::time::_strftime_l), - "_localtime_r" => Function::new_native(&mut store, ctx, crate::time::_localtime_r), - "_gmtime_r" => Function::new_native(&mut store, ctx, crate::time::_gmtime_r), - "_ctime" => Function::new_native(&mut store, ctx, crate::time::_ctime), - "_ctime_r" => Function::new_native(&mut store, ctx, crate::time::_ctime_r), - "_mktime" => Function::new_native(&mut store, ctx, crate::time::_mktime), - "_gmtime" => Function::new_native(&mut store, ctx, crate::time::_gmtime), + "_gettimeofday" => Function::new_typed_with_env(&mut store, env, crate::time::_gettimeofday), + "_clock_getres" => Function::new_typed_with_env(&mut store, env, crate::time::_clock_getres), + "_clock_gettime" => Function::new_typed_with_env(&mut store, env, crate::time::_clock_gettime), + "_clock_settime" => Function::new_typed_with_env(&mut store, env, crate::time::_clock_settime), + "___clock_gettime" => Function::new_typed_with_env(&mut store, env, crate::time::_clock_gettime), + "_clock" => Function::new_typed_with_env(&mut store, env, crate::time::_clock), + "_difftime" => Function::new_typed_with_env(&mut store, env, crate::time::_difftime), + "_asctime" => Function::new_typed_with_env(&mut store, env, crate::time::_asctime), + "_asctime_r" => Function::new_typed_with_env(&mut store, env, crate::time::_asctime_r), + "_localtime" => Function::new_typed_with_env(&mut store, env, crate::time::_localtime), + "_time" => Function::new_typed_with_env(&mut store, env, crate::time::_time), + "_timegm" => Function::new_typed_with_env(&mut store, env, crate::time::_timegm), + "_strftime" => Function::new_typed_with_env(&mut store, env, crate::time::_strftime), + "_strftime_l" => Function::new_typed_with_env(&mut store, env, crate::time::_strftime_l), + "_localtime_r" => Function::new_typed_with_env(&mut store, env, crate::time::_localtime_r), + "_gmtime_r" => Function::new_typed_with_env(&mut store, env, crate::time::_gmtime_r), + "_ctime" => Function::new_typed_with_env(&mut store, env, crate::time::_ctime), + "_ctime_r" => Function::new_typed_with_env(&mut store, env, crate::time::_ctime_r), + "_mktime" => Function::new_typed_with_env(&mut store, env, crate::time::_mktime), + "_gmtime" => Function::new_typed_with_env(&mut store, env, crate::time::_gmtime), // Math - "sqrt" => Function::new_native(&mut store, ctx, crate::math::sqrt), - "floor" => Function::new_native(&mut store, ctx, crate::math::floor), - "fabs" => Function::new_native(&mut store, ctx, crate::math::fabs), - "f64-rem" => Function::new_native(&mut store, ctx, crate::math::f64_rem), - "_llvm_copysign_f32" => Function::new_native(&mut store, ctx, crate::math::_llvm_copysign_f32), - "_llvm_copysign_f64" => Function::new_native(&mut store, ctx, crate::math::_llvm_copysign_f64), - "_llvm_log10_f64" => Function::new_native(&mut store, ctx, crate::math::_llvm_log10_f64), - "_llvm_log2_f64" => Function::new_native(&mut store, ctx, crate::math::_llvm_log2_f64), - "_llvm_log10_f32" => Function::new_native(&mut store, ctx, crate::math::_llvm_log10_f32), - "_llvm_log2_f32" => Function::new_native(&mut store, ctx, crate::math::_llvm_log2_f64), - "_llvm_sin_f64" => Function::new_native(&mut store, ctx, crate::math::_llvm_sin_f64), - "_llvm_cos_f64" => Function::new_native(&mut store, ctx, crate::math::_llvm_cos_f64), - "_llvm_exp2_f32" => Function::new_native(&mut store, ctx, crate::math::_llvm_exp2_f32), - "_llvm_exp2_f64" => Function::new_native(&mut store, ctx, crate::math::_llvm_exp2_f64), - "_llvm_trunc_f64" => Function::new_native(&mut store, ctx, crate::math::_llvm_trunc_f64), - "_llvm_fma_f64" => Function::new_native(&mut store, ctx, crate::math::_llvm_fma_f64), - "_emscripten_random" => Function::new_native(&mut store, ctx, crate::math::_emscripten_random), + "sqrt" => Function::new_typed_with_env(&mut store, env, crate::math::sqrt), + "floor" => Function::new_typed_with_env(&mut store, env, crate::math::floor), + "fabs" => Function::new_typed_with_env(&mut store, env, crate::math::fabs), + "f64-rem" => Function::new_typed_with_env(&mut store, env, crate::math::f64_rem), + "_llvm_copysign_f32" => Function::new_typed_with_env(&mut store, env, crate::math::_llvm_copysign_f32), + "_llvm_copysign_f64" => Function::new_typed_with_env(&mut store, env, crate::math::_llvm_copysign_f64), + "_llvm_log10_f64" => Function::new_typed_with_env(&mut store, env, crate::math::_llvm_log10_f64), + "_llvm_log2_f64" => Function::new_typed_with_env(&mut store, env, crate::math::_llvm_log2_f64), + "_llvm_log10_f32" => Function::new_typed_with_env(&mut store, env, crate::math::_llvm_log10_f32), + "_llvm_log2_f32" => Function::new_typed_with_env(&mut store, env, crate::math::_llvm_log2_f64), + "_llvm_sin_f64" => Function::new_typed_with_env(&mut store, env, crate::math::_llvm_sin_f64), + "_llvm_cos_f64" => Function::new_typed_with_env(&mut store, env, crate::math::_llvm_cos_f64), + "_llvm_exp2_f32" => Function::new_typed_with_env(&mut store, env, crate::math::_llvm_exp2_f32), + "_llvm_exp2_f64" => Function::new_typed_with_env(&mut store, env, crate::math::_llvm_exp2_f64), + "_llvm_trunc_f64" => Function::new_typed_with_env(&mut store, env, crate::math::_llvm_trunc_f64), + "_llvm_fma_f64" => Function::new_typed_with_env(&mut store, env, crate::math::_llvm_fma_f64), + "_emscripten_random" => Function::new_typed_with_env(&mut store, env, crate::math::_emscripten_random), // Jump - "__setjmp" => Function::new_native(&mut store, ctx, crate::jmp::__setjmp), - "__longjmp" => Function::new_native(&mut store, ctx, crate::jmp::__longjmp), - "_longjmp" => Function::new_native(&mut store, ctx, crate::jmp::_longjmp), - "_emscripten_longjmp" => Function::new_native(&mut store, ctx, crate::jmp::_longjmp), + "__setjmp" => Function::new_typed_with_env(&mut store, env, crate::jmp::__setjmp), + "__longjmp" => Function::new_typed_with_env(&mut store, env, crate::jmp::__longjmp), + "_longjmp" => Function::new_typed_with_env(&mut store, env, crate::jmp::_longjmp), + "_emscripten_longjmp" => Function::new_typed_with_env(&mut store, env, crate::jmp::_longjmp), // Bitwise - "_llvm_bswap_i64" => Function::new_native(&mut store, ctx, crate::bitwise::_llvm_bswap_i64), + "_llvm_bswap_i64" => Function::new_typed_with_env(&mut store, env, crate::bitwise::_llvm_bswap_i64), // libc - "_execv" => Function::new_native(&mut store, ctx, crate::libc::execv), - "_endpwent" => Function::new_native(&mut store, ctx, crate::libc::endpwent), - "_fexecve" => Function::new_native(&mut store, ctx, crate::libc::fexecve), - "_fpathconf" => Function::new_native(&mut store, ctx, crate::libc::fpathconf), - "_getitimer" => Function::new_native(&mut store, ctx, crate::libc::getitimer), - "_getpwent" => Function::new_native(&mut store, ctx, crate::libc::getpwent), - "_killpg" => Function::new_native(&mut store, ctx, crate::libc::killpg), - "_pathconf" => Function::new_native(&mut store, ctx, crate::libc::pathconf), - "_siginterrupt" => Function::new_native(&mut store, ctx, crate::signal::_siginterrupt), - "_setpwent" => Function::new_native(&mut store, ctx, crate::libc::setpwent), - "_sigismember" => Function::new_native(&mut store, ctx, crate::libc::sigismember), - "_sigpending" => Function::new_native(&mut store, ctx, crate::libc::sigpending), - "___libc_current_sigrtmax" => Function::new_native(&mut store, ctx, crate::libc::current_sigrtmax), - "___libc_current_sigrtmin" => Function::new_native(&mut store, ctx, crate::libc::current_sigrtmin), + "_execv" => Function::new_typed_with_env(&mut store, env, crate::libc::execv), + "_endpwent" => Function::new_typed_with_env(&mut store, env, crate::libc::endpwent), + "_fexecve" => Function::new_typed_with_env(&mut store, env, crate::libc::fexecve), + "_fpathconf" => Function::new_typed_with_env(&mut store, env, crate::libc::fpathconf), + "_getitimer" => Function::new_typed_with_env(&mut store, env, crate::libc::getitimer), + "_getpwent" => Function::new_typed_with_env(&mut store, env, crate::libc::getpwent), + "_killpg" => Function::new_typed_with_env(&mut store, env, crate::libc::killpg), + "_pathconf" => Function::new_typed_with_env(&mut store, env, crate::libc::pathconf), + "_siginterrupt" => Function::new_typed_with_env(&mut store, env, crate::signal::_siginterrupt), + "_setpwent" => Function::new_typed_with_env(&mut store, env, crate::libc::setpwent), + "_sigismember" => Function::new_typed_with_env(&mut store, env, crate::libc::sigismember), + "_sigpending" => Function::new_typed_with_env(&mut store, env, crate::libc::sigpending), + "___libc_current_sigrtmax" => Function::new_typed_with_env(&mut store, env, crate::libc::current_sigrtmax), + "___libc_current_sigrtmin" => Function::new_typed_with_env(&mut store, env, crate::libc::current_sigrtmin), // Linking - "_dlclose" => Function::new_native(&mut store, ctx, crate::linking::_dlclose), - "_dlerror" => Function::new_native(&mut store, ctx, crate::linking::_dlerror), - "_dlopen" => Function::new_native(&mut store, ctx, crate::linking::_dlopen), - "_dlsym" => Function::new_native(&mut store, ctx, crate::linking::_dlsym), + "_dlclose" => Function::new_typed_with_env(&mut store, env, crate::linking::_dlclose), + "_dlerror" => Function::new_typed_with_env(&mut store, env, crate::linking::_dlerror), + "_dlopen" => Function::new_typed_with_env(&mut store, env, crate::linking::_dlopen), + "_dlsym" => Function::new_typed_with_env(&mut store, env, crate::linking::_dlsym), // wasm32-unknown-emscripten - "_alarm" => Function::new_native(&mut store, ctx, crate::emscripten_target::_alarm), - "_atexit" => Function::new_native(&mut store, ctx, crate::emscripten_target::_atexit), - "setTempRet0" => Function::new_native(&mut store, ctx, crate::emscripten_target::setTempRet0), - "getTempRet0" => Function::new_native(&mut store, ctx, crate::emscripten_target::getTempRet0), - "invoke_i" => Function::new_native(&mut store, ctx, crate::emscripten_target::invoke_i), - "invoke_ii" => Function::new_native(&mut store, ctx, crate::emscripten_target::invoke_ii), - "invoke_iii" => Function::new_native(&mut store, ctx, crate::emscripten_target::invoke_iii), - "invoke_iiii" => Function::new_native(&mut store, ctx, crate::emscripten_target::invoke_iiii), - "invoke_iifi" => Function::new_native(&mut store, ctx, crate::emscripten_target::invoke_iifi), - "invoke_v" => Function::new_native(&mut store, ctx, crate::emscripten_target::invoke_v), - "invoke_vi" => Function::new_native(&mut store, ctx, crate::emscripten_target::invoke_vi), - "invoke_vj" => Function::new_native(&mut store, ctx, crate::emscripten_target::invoke_vj), - "invoke_vjji" => Function::new_native(&mut store, ctx, crate::emscripten_target::invoke_vjji), - "invoke_vii" => Function::new_native(&mut store, ctx, crate::emscripten_target::invoke_vii), - "invoke_viii" => Function::new_native(&mut store, ctx, crate::emscripten_target::invoke_viii), - "invoke_viiii" => Function::new_native(&mut store, ctx, crate::emscripten_target::invoke_viiii), - "__Unwind_Backtrace" => Function::new_native(&mut store, ctx, crate::emscripten_target::__Unwind_Backtrace), - "__Unwind_FindEnclosingFunction" => Function::new_native(&mut store, ctx, crate::emscripten_target::__Unwind_FindEnclosingFunction), - "__Unwind_GetIPInfo" => Function::new_native(&mut store, ctx, crate::emscripten_target::__Unwind_GetIPInfo), - "___cxa_find_matching_catch_2" => Function::new_native(&mut store, ctx, crate::emscripten_target::___cxa_find_matching_catch_2), - "___cxa_find_matching_catch_3" => Function::new_native(&mut store, ctx, crate::emscripten_target::___cxa_find_matching_catch_3), - "___cxa_free_exception" => Function::new_native(&mut store, ctx, crate::emscripten_target::___cxa_free_exception), - "___resumeException" => Function::new_native(&mut store, ctx, crate::emscripten_target::___resumeException), - "_dladdr" => Function::new_native(&mut store, ctx, crate::emscripten_target::_dladdr), - "_pthread_attr_destroy" => Function::new_native(&mut store, ctx, crate::pthread::_pthread_attr_destroy), - "_pthread_attr_getstack" => Function::new_native(&mut store, ctx, crate::pthread::_pthread_attr_getstack), - "_pthread_attr_init" => Function::new_native(&mut store, ctx, crate::pthread::_pthread_attr_init), - "_pthread_attr_setstacksize" => Function::new_native(&mut store, ctx, crate::pthread::_pthread_attr_setstacksize), - "_pthread_cleanup_pop" => Function::new_native(&mut store, ctx, crate::pthread::_pthread_cleanup_pop), - "_pthread_cleanup_push" => Function::new_native(&mut store, ctx, crate::pthread::_pthread_cleanup_push), - "_pthread_cond_destroy" => Function::new_native(&mut store, ctx, crate::pthread::_pthread_cond_destroy), - "_pthread_cond_init" => Function::new_native(&mut store, ctx, crate::pthread::_pthread_cond_init), - "_pthread_cond_signal" => Function::new_native(&mut store, ctx, crate::pthread::_pthread_cond_signal), - "_pthread_cond_timedwait" => Function::new_native(&mut store, ctx, crate::pthread::_pthread_cond_timedwait), - "_pthread_cond_wait" => Function::new_native(&mut store, ctx, crate::pthread::_pthread_cond_wait), - "_pthread_condattr_destroy" => Function::new_native(&mut store, ctx, crate::pthread::_pthread_condattr_destroy), - "_pthread_condattr_init" => Function::new_native(&mut store, ctx, crate::pthread::_pthread_condattr_init), - "_pthread_condattr_setclock" => Function::new_native(&mut store, ctx, crate::pthread::_pthread_condattr_setclock), - "_pthread_create" => Function::new_native(&mut store, ctx, crate::pthread::_pthread_create), - "_pthread_detach" => Function::new_native(&mut store, ctx, crate::pthread::_pthread_detach), - "_pthread_equal" => Function::new_native(&mut store, ctx, crate::pthread::_pthread_equal), - "_pthread_exit" => Function::new_native(&mut store, ctx, crate::pthread::_pthread_exit), - "_pthread_self" => Function::new_native(&mut store, ctx, crate::pthread::_pthread_self), - "_pthread_getattr_np" => Function::new_native(&mut store, ctx, crate::pthread::_pthread_getattr_np), - "_pthread_getspecific" => Function::new_native(&mut store, ctx, crate::pthread::_pthread_getspecific), - "_pthread_join" => Function::new_native(&mut store, ctx, crate::pthread::_pthread_join), - "_pthread_key_create" => Function::new_native(&mut store, ctx, crate::pthread::_pthread_key_create), - "_pthread_mutex_destroy" => Function::new_native(&mut store, ctx, crate::pthread::_pthread_mutex_destroy), - "_pthread_mutex_init" => Function::new_native(&mut store, ctx, crate::pthread::_pthread_mutex_init), - "_pthread_mutexattr_destroy" => Function::new_native(&mut store, ctx, crate::pthread::_pthread_mutexattr_destroy), - "_pthread_mutexattr_init" => Function::new_native(&mut store, ctx, crate::pthread::_pthread_mutexattr_init), - "_pthread_mutexattr_settype" => Function::new_native(&mut store, ctx, crate::pthread::_pthread_mutexattr_settype), - "_pthread_once" => Function::new_native(&mut store, ctx, crate::pthread::_pthread_once), - "_pthread_rwlock_destroy" => Function::new_native(&mut store, ctx, crate::pthread::_pthread_rwlock_destroy), - "_pthread_rwlock_init" => Function::new_native(&mut store, ctx, crate::pthread::_pthread_rwlock_init), - "_pthread_rwlock_rdlock" => Function::new_native(&mut store, ctx, crate::pthread::_pthread_rwlock_rdlock), - "_pthread_rwlock_unlock" => Function::new_native(&mut store, ctx, crate::pthread::_pthread_rwlock_unlock), - "_pthread_rwlock_wrlock" => Function::new_native(&mut store, ctx, crate::pthread::_pthread_rwlock_wrlock), - "_pthread_setcancelstate" => Function::new_native(&mut store, ctx, crate::pthread::_pthread_setcancelstate), - "_pthread_setspecific" => Function::new_native(&mut store, ctx, crate::pthread::_pthread_setspecific), - "_pthread_sigmask" => Function::new_native(&mut store, ctx, crate::pthread::_pthread_sigmask), - "___gxx_personality_v0" => Function::new_native(&mut store, ctx, crate::emscripten_target::___gxx_personality_v0), - "_gai_strerror" => Function::new_native(&mut store, ctx, crate::env::_gai_strerror), - "_getdtablesize" => Function::new_native(&mut store, ctx, crate::emscripten_target::_getdtablesize), - "_gethostbyaddr" => Function::new_native(&mut store, ctx, crate::emscripten_target::_gethostbyaddr), - "_gethostbyname" => Function::new_native(&mut store, ctx, crate::emscripten_target::_gethostbyname), - "_gethostbyname_r" => Function::new_native(&mut store, ctx, crate::emscripten_target::_gethostbyname_r), - "_getloadavg" => Function::new_native(&mut store, ctx, crate::emscripten_target::_getloadavg), - "_getnameinfo" => Function::new_native(&mut store, ctx, crate::emscripten_target::_getnameinfo), - "invoke_dii" => Function::new_native(&mut store, ctx, crate::emscripten_target::invoke_dii), - "invoke_diiii" => Function::new_native(&mut store, ctx, crate::emscripten_target::invoke_diiii), - "invoke_iiiii" => Function::new_native(&mut store, ctx, crate::emscripten_target::invoke_iiiii), - "invoke_iiiiii" => Function::new_native(&mut store, ctx, crate::emscripten_target::invoke_iiiiii), - "invoke_iiiiiii" => Function::new_native(&mut store, ctx, crate::emscripten_target::invoke_iiiiiii), - "invoke_iiiiiiii" => Function::new_native(&mut store, ctx, crate::emscripten_target::invoke_iiiiiiii), - "invoke_iiiiiiiii" => Function::new_native(&mut store, ctx, crate::emscripten_target::invoke_iiiiiiiii), - "invoke_iiiiiiiiii" => Function::new_native(&mut store, ctx, crate::emscripten_target::invoke_iiiiiiiiii), - "invoke_iiiiiiiiiii" => Function::new_native(&mut store, ctx, crate::emscripten_target::invoke_iiiiiiiiiii), - "invoke_vd" => Function::new_native(&mut store, ctx, crate::emscripten_target::invoke_vd), - "invoke_viiiii" => Function::new_native(&mut store, ctx, crate::emscripten_target::invoke_viiiii), - "invoke_viiiiii" => Function::new_native(&mut store, ctx, crate::emscripten_target::invoke_viiiiii), - "invoke_viiiiiii" => Function::new_native(&mut store, ctx, crate::emscripten_target::invoke_viiiiiii), - "invoke_viiiiiiii" => Function::new_native(&mut store, ctx, crate::emscripten_target::invoke_viiiiiiii), - "invoke_viiiiiiiii" => Function::new_native(&mut store, ctx, crate::emscripten_target::invoke_viiiiiiiii), - "invoke_viiiiiiiii" => Function::new_native(&mut store, ctx, crate::emscripten_target::invoke_viiiiiiiii), - "invoke_viiiiiiiiii" => Function::new_native(&mut store, ctx, crate::emscripten_target::invoke_viiiiiiiiii), - "invoke_iij" => Function::new_native(&mut store, ctx, crate::emscripten_target::invoke_iij), - "invoke_iji" => Function::new_native(&mut store, ctx, crate::emscripten_target::invoke_iji), - "invoke_iiji" => Function::new_native(&mut store, ctx, crate::emscripten_target::invoke_iiji), - "invoke_iiijj" => Function::new_native(&mut store, ctx, crate::emscripten_target::invoke_iiijj), - "invoke_j" => Function::new_native(&mut store, ctx, crate::emscripten_target::invoke_j), - "invoke_ji" => Function::new_native(&mut store, ctx, crate::emscripten_target::invoke_ji), - "invoke_jii" => Function::new_native(&mut store, ctx, crate::emscripten_target::invoke_jii), - "invoke_jij" => Function::new_native(&mut store, ctx, crate::emscripten_target::invoke_jij), - "invoke_jjj" => Function::new_native(&mut store, ctx, crate::emscripten_target::invoke_jjj), - "invoke_viiij" => Function::new_native(&mut store, ctx, crate::emscripten_target::invoke_viiij), - "invoke_viiijiiii" => Function::new_native(&mut store, ctx, crate::emscripten_target::invoke_viiijiiii), - "invoke_viiijiiiiii" => Function::new_native(&mut store, ctx, crate::emscripten_target::invoke_viiijiiiiii), - "invoke_viij" => Function::new_native(&mut store, ctx, crate::emscripten_target::invoke_viij), - "invoke_viiji" => Function::new_native(&mut store, ctx, crate::emscripten_target::invoke_viiji), - "invoke_viijiii" => Function::new_native(&mut store, ctx, crate::emscripten_target::invoke_viijiii), - "invoke_viijj" => Function::new_native(&mut store, ctx, crate::emscripten_target::invoke_viijj), - "invoke_vij" => Function::new_native(&mut store, ctx, crate::emscripten_target::invoke_vij), - "invoke_viji" => Function::new_native(&mut store, ctx, crate::emscripten_target::invoke_viji), - "invoke_vijiii" => Function::new_native(&mut store, ctx, crate::emscripten_target::invoke_vijiii), - "invoke_vijj" => Function::new_native(&mut store, ctx, crate::emscripten_target::invoke_vijj), - "invoke_vidd" => Function::new_native(&mut store, ctx, crate::emscripten_target::invoke_vidd), - "invoke_viid" => Function::new_native(&mut store, ctx, crate::emscripten_target::invoke_viid), - "invoke_viidii" => Function::new_native(&mut store, ctx, crate::emscripten_target::invoke_viidii), - "invoke_viidddddddd" => Function::new_native(&mut store, ctx, crate::emscripten_target::invoke_viidddddddd), + "_alarm" => Function::new_typed_with_env(&mut store, env, crate::emscripten_target::_alarm), + "_atexit" => Function::new_typed_with_env(&mut store, env, crate::emscripten_target::_atexit), + "setTempRet0" => Function::new_typed_with_env(&mut store, env, crate::emscripten_target::setTempRet0), + "getTempRet0" => Function::new_typed_with_env(&mut store, env, crate::emscripten_target::getTempRet0), + "invoke_i" => Function::new_typed_with_env(&mut store, env, crate::emscripten_target::invoke_i), + "invoke_ii" => Function::new_typed_with_env(&mut store, env, crate::emscripten_target::invoke_ii), + "invoke_iii" => Function::new_typed_with_env(&mut store, env, crate::emscripten_target::invoke_iii), + "invoke_iiii" => Function::new_typed_with_env(&mut store, env, crate::emscripten_target::invoke_iiii), + "invoke_iifi" => Function::new_typed_with_env(&mut store, env, crate::emscripten_target::invoke_iifi), + "invoke_v" => Function::new_typed_with_env(&mut store, env, crate::emscripten_target::invoke_v), + "invoke_vi" => Function::new_typed_with_env(&mut store, env, crate::emscripten_target::invoke_vi), + "invoke_vj" => Function::new_typed_with_env(&mut store, env, crate::emscripten_target::invoke_vj), + "invoke_vjji" => Function::new_typed_with_env(&mut store, env, crate::emscripten_target::invoke_vjji), + "invoke_vii" => Function::new_typed_with_env(&mut store, env, crate::emscripten_target::invoke_vii), + "invoke_viii" => Function::new_typed_with_env(&mut store, env, crate::emscripten_target::invoke_viii), + "invoke_viiii" => Function::new_typed_with_env(&mut store, env, crate::emscripten_target::invoke_viiii), + "__Unwind_Backtrace" => Function::new_typed_with_env(&mut store, env, crate::emscripten_target::__Unwind_Backtrace), + "__Unwind_FindEnclosingFunction" => Function::new_typed_with_env(&mut store, env, crate::emscripten_target::__Unwind_FindEnclosingFunction), + "__Unwind_GetIPInfo" => Function::new_typed_with_env(&mut store, env, crate::emscripten_target::__Unwind_GetIPInfo), + "___cxa_find_matching_catch_2" => Function::new_typed_with_env(&mut store, env, crate::emscripten_target::___cxa_find_matching_catch_2), + "___cxa_find_matching_catch_3" => Function::new_typed_with_env(&mut store, env, crate::emscripten_target::___cxa_find_matching_catch_3), + "___cxa_free_exception" => Function::new_typed_with_env(&mut store, env, crate::emscripten_target::___cxa_free_exception), + "___resumeException" => Function::new_typed_with_env(&mut store, env, crate::emscripten_target::___resumeException), + "_dladdr" => Function::new_typed_with_env(&mut store, env, crate::emscripten_target::_dladdr), + "_pthread_attr_destroy" => Function::new_typed_with_env(&mut store, env, crate::pthread::_pthread_attr_destroy), + "_pthread_attr_getstack" => Function::new_typed_with_env(&mut store, env, crate::pthread::_pthread_attr_getstack), + "_pthread_attr_init" => Function::new_typed_with_env(&mut store, env, crate::pthread::_pthread_attr_init), + "_pthread_attr_setstacksize" => Function::new_typed_with_env(&mut store, env, crate::pthread::_pthread_attr_setstacksize), + "_pthread_cleanup_pop" => Function::new_typed_with_env(&mut store, env, crate::pthread::_pthread_cleanup_pop), + "_pthread_cleanup_push" => Function::new_typed_with_env(&mut store, env, crate::pthread::_pthread_cleanup_push), + "_pthread_cond_destroy" => Function::new_typed_with_env(&mut store, env, crate::pthread::_pthread_cond_destroy), + "_pthread_cond_init" => Function::new_typed_with_env(&mut store, env, crate::pthread::_pthread_cond_init), + "_pthread_cond_signal" => Function::new_typed_with_env(&mut store, env, crate::pthread::_pthread_cond_signal), + "_pthread_cond_timedwait" => Function::new_typed_with_env(&mut store, env, crate::pthread::_pthread_cond_timedwait), + "_pthread_cond_wait" => Function::new_typed_with_env(&mut store, env, crate::pthread::_pthread_cond_wait), + "_pthread_condattr_destroy" => Function::new_typed_with_env(&mut store, env, crate::pthread::_pthread_condattr_destroy), + "_pthread_condattr_init" => Function::new_typed_with_env(&mut store, env, crate::pthread::_pthread_condattr_init), + "_pthread_condattr_setclock" => Function::new_typed_with_env(&mut store, env, crate::pthread::_pthread_condattr_setclock), + "_pthread_create" => Function::new_typed_with_env(&mut store, env, crate::pthread::_pthread_create), + "_pthread_detach" => Function::new_typed_with_env(&mut store, env, crate::pthread::_pthread_detach), + "_pthread_equal" => Function::new_typed_with_env(&mut store, env, crate::pthread::_pthread_equal), + "_pthread_exit" => Function::new_typed_with_env(&mut store, env, crate::pthread::_pthread_exit), + "_pthread_self" => Function::new_typed_with_env(&mut store, env, crate::pthread::_pthread_self), + "_pthread_getattr_np" => Function::new_typed_with_env(&mut store, env, crate::pthread::_pthread_getattr_np), + "_pthread_getspecific" => Function::new_typed_with_env(&mut store, env, crate::pthread::_pthread_getspecific), + "_pthread_join" => Function::new_typed_with_env(&mut store, env, crate::pthread::_pthread_join), + "_pthread_key_create" => Function::new_typed_with_env(&mut store, env, crate::pthread::_pthread_key_create), + "_pthread_mutex_destroy" => Function::new_typed_with_env(&mut store, env, crate::pthread::_pthread_mutex_destroy), + "_pthread_mutex_init" => Function::new_typed_with_env(&mut store, env, crate::pthread::_pthread_mutex_init), + "_pthread_mutexattr_destroy" => Function::new_typed_with_env(&mut store, env, crate::pthread::_pthread_mutexattr_destroy), + "_pthread_mutexattr_init" => Function::new_typed_with_env(&mut store, env, crate::pthread::_pthread_mutexattr_init), + "_pthread_mutexattr_settype" => Function::new_typed_with_env(&mut store, env, crate::pthread::_pthread_mutexattr_settype), + "_pthread_once" => Function::new_typed_with_env(&mut store, env, crate::pthread::_pthread_once), + "_pthread_rwlock_destroy" => Function::new_typed_with_env(&mut store, env, crate::pthread::_pthread_rwlock_destroy), + "_pthread_rwlock_init" => Function::new_typed_with_env(&mut store, env, crate::pthread::_pthread_rwlock_init), + "_pthread_rwlock_rdlock" => Function::new_typed_with_env(&mut store, env, crate::pthread::_pthread_rwlock_rdlock), + "_pthread_rwlock_unlock" => Function::new_typed_with_env(&mut store, env, crate::pthread::_pthread_rwlock_unlock), + "_pthread_rwlock_wrlock" => Function::new_typed_with_env(&mut store, env, crate::pthread::_pthread_rwlock_wrlock), + "_pthread_setcancelstate" => Function::new_typed_with_env(&mut store, env, crate::pthread::_pthread_setcancelstate), + "_pthread_setspecific" => Function::new_typed_with_env(&mut store, env, crate::pthread::_pthread_setspecific), + "_pthread_sigmask" => Function::new_typed_with_env(&mut store, env, crate::pthread::_pthread_sigmask), + "___gxx_personality_v0" => Function::new_typed_with_env(&mut store, env, crate::emscripten_target::___gxx_personality_v0), + "_gai_strerror" => Function::new_typed_with_env(&mut store, env, crate::env::_gai_strerror), + "_getdtablesize" => Function::new_typed_with_env(&mut store, env, crate::emscripten_target::_getdtablesize), + "_gethostbyaddr" => Function::new_typed_with_env(&mut store, env, crate::emscripten_target::_gethostbyaddr), + "_gethostbyname" => Function::new_typed_with_env(&mut store, env, crate::emscripten_target::_gethostbyname), + "_gethostbyname_r" => Function::new_typed_with_env(&mut store, env, crate::emscripten_target::_gethostbyname_r), + "_getloadavg" => Function::new_typed_with_env(&mut store, env, crate::emscripten_target::_getloadavg), + "_getnameinfo" => Function::new_typed_with_env(&mut store, env, crate::emscripten_target::_getnameinfo), + "invoke_dii" => Function::new_typed_with_env(&mut store, env, crate::emscripten_target::invoke_dii), + "invoke_diiii" => Function::new_typed_with_env(&mut store, env, crate::emscripten_target::invoke_diiii), + "invoke_iiiii" => Function::new_typed_with_env(&mut store, env, crate::emscripten_target::invoke_iiiii), + "invoke_iiiiii" => Function::new_typed_with_env(&mut store, env, crate::emscripten_target::invoke_iiiiii), + "invoke_iiiiiii" => Function::new_typed_with_env(&mut store, env, crate::emscripten_target::invoke_iiiiiii), + "invoke_iiiiiiii" => Function::new_typed_with_env(&mut store, env, crate::emscripten_target::invoke_iiiiiiii), + "invoke_iiiiiiiii" => Function::new_typed_with_env(&mut store, env, crate::emscripten_target::invoke_iiiiiiiii), + "invoke_iiiiiiiiii" => Function::new_typed_with_env(&mut store, env, crate::emscripten_target::invoke_iiiiiiiiii), + "invoke_iiiiiiiiiii" => Function::new_typed_with_env(&mut store, env, crate::emscripten_target::invoke_iiiiiiiiiii), + "invoke_vd" => Function::new_typed_with_env(&mut store, env, crate::emscripten_target::invoke_vd), + "invoke_viiiii" => Function::new_typed_with_env(&mut store, env, crate::emscripten_target::invoke_viiiii), + "invoke_viiiiii" => Function::new_typed_with_env(&mut store, env, crate::emscripten_target::invoke_viiiiii), + "invoke_viiiiiii" => Function::new_typed_with_env(&mut store, env, crate::emscripten_target::invoke_viiiiiii), + "invoke_viiiiiiii" => Function::new_typed_with_env(&mut store, env, crate::emscripten_target::invoke_viiiiiiii), + "invoke_viiiiiiiii" => Function::new_typed_with_env(&mut store, env, crate::emscripten_target::invoke_viiiiiiiii), + "invoke_viiiiiiiii" => Function::new_typed_with_env(&mut store, env, crate::emscripten_target::invoke_viiiiiiiii), + "invoke_viiiiiiiiii" => Function::new_typed_with_env(&mut store, env, crate::emscripten_target::invoke_viiiiiiiiii), + "invoke_iij" => Function::new_typed_with_env(&mut store, env, crate::emscripten_target::invoke_iij), + "invoke_iji" => Function::new_typed_with_env(&mut store, env, crate::emscripten_target::invoke_iji), + "invoke_iiji" => Function::new_typed_with_env(&mut store, env, crate::emscripten_target::invoke_iiji), + "invoke_iiijj" => Function::new_typed_with_env(&mut store, env, crate::emscripten_target::invoke_iiijj), + "invoke_j" => Function::new_typed_with_env(&mut store, env, crate::emscripten_target::invoke_j), + "invoke_ji" => Function::new_typed_with_env(&mut store, env, crate::emscripten_target::invoke_ji), + "invoke_jii" => Function::new_typed_with_env(&mut store, env, crate::emscripten_target::invoke_jii), + "invoke_jij" => Function::new_typed_with_env(&mut store, env, crate::emscripten_target::invoke_jij), + "invoke_jjj" => Function::new_typed_with_env(&mut store, env, crate::emscripten_target::invoke_jjj), + "invoke_viiij" => Function::new_typed_with_env(&mut store, env, crate::emscripten_target::invoke_viiij), + "invoke_viiijiiii" => Function::new_typed_with_env(&mut store, env, crate::emscripten_target::invoke_viiijiiii), + "invoke_viiijiiiiii" => Function::new_typed_with_env(&mut store, env, crate::emscripten_target::invoke_viiijiiiiii), + "invoke_viij" => Function::new_typed_with_env(&mut store, env, crate::emscripten_target::invoke_viij), + "invoke_viiji" => Function::new_typed_with_env(&mut store, env, crate::emscripten_target::invoke_viiji), + "invoke_viijiii" => Function::new_typed_with_env(&mut store, env, crate::emscripten_target::invoke_viijiii), + "invoke_viijj" => Function::new_typed_with_env(&mut store, env, crate::emscripten_target::invoke_viijj), + "invoke_vij" => Function::new_typed_with_env(&mut store, env, crate::emscripten_target::invoke_vij), + "invoke_viji" => Function::new_typed_with_env(&mut store, env, crate::emscripten_target::invoke_viji), + "invoke_vijiii" => Function::new_typed_with_env(&mut store, env, crate::emscripten_target::invoke_vijiii), + "invoke_vijj" => Function::new_typed_with_env(&mut store, env, crate::emscripten_target::invoke_vijj), + "invoke_vidd" => Function::new_typed_with_env(&mut store, env, crate::emscripten_target::invoke_vidd), + "invoke_viid" => Function::new_typed_with_env(&mut store, env, crate::emscripten_target::invoke_viid), + "invoke_viidii" => Function::new_typed_with_env(&mut store, env, crate::emscripten_target::invoke_viidii), + "invoke_viidddddddd" => Function::new_typed_with_env(&mut store, env, crate::emscripten_target::invoke_viidddddddd), // ucontext - "_getcontext" => Function::new_native(&mut store, ctx, crate::ucontext::_getcontext), - "_makecontext" => Function::new_native(&mut store, ctx, crate::ucontext::_makecontext), - "_setcontext" => Function::new_native(&mut store, ctx, crate::ucontext::_setcontext), - "_swapcontext" => Function::new_native(&mut store, ctx, crate::ucontext::_swapcontext), + "_getcontext" => Function::new_typed_with_env(&mut store, env, crate::ucontext::_getcontext), + "_makecontext" => Function::new_typed_with_env(&mut store, env, crate::ucontext::_makecontext), + "_setcontext" => Function::new_typed_with_env(&mut store, env, crate::ucontext::_setcontext), + "_swapcontext" => Function::new_typed_with_env(&mut store, env, crate::ucontext::_swapcontext), // unistd - "_confstr" => Function::new_native(&mut store, ctx, crate::unistd::confstr), + "_confstr" => Function::new_typed_with_env(&mut store, env, crate::unistd::confstr), }; // Compatibility with newer versions of Emscripten @@ -1473,7 +1473,7 @@ pub fn generate_emscripten_env( for null_function_name in globals.null_function_names.iter() { env_ns.insert( null_function_name.as_str(), - Function::new_native(&mut store, ctx, nullfunc), + Function::new_typed_with_env(&mut store, env, nullfunc), ); } @@ -1484,24 +1484,24 @@ pub fn generate_emscripten_env( "Infinity" => Global::new(&mut store, Value::F64(f64::INFINITY)), }, "global.Math" => { - "pow" => Function::new_native(&mut store, ctx, crate::math::pow), - "exp" => Function::new_native(&mut store, ctx, crate::math::exp), - "log" => Function::new_native(&mut store, ctx, crate::math::log), + "pow" => Function::new_typed_with_env(&mut store, env, crate::math::pow), + "exp" => Function::new_typed_with_env(&mut store, env, crate::math::exp), + "log" => Function::new_typed_with_env(&mut store, env, crate::math::log), }, "asm2wasm" => { - "f64-rem" => Function::new_native(&mut store, ctx, crate::math::f64_rem), - "f64-to-int" => Function::new_native(&mut store, ctx, crate::math::f64_to_int), + "f64-rem" => Function::new_typed_with_env(&mut store, env, crate::math::f64_rem), + "f64-to-int" => Function::new_typed_with_env(&mut store, env, crate::math::f64_to_int), }, }; import_object } -pub fn nullfunc(ctx: FunctionEnvMut, _x: u32) { +pub fn nullfunc(env: FunctionEnvMut, _x: u32) { use crate::process::abort_with_message; debug!("emscripten::nullfunc_i {}", _x); abort_with_message( - ctx, + env, "Invalid function pointer. Perhaps this is an invalid value \ (e.g. caused by calling a virtual method on a NULL pointer)? Or calling a function with an \ incorrect type, which will fail? (it is worth building your source files with -Werror (\ diff --git a/lib/middlewares/src/metering.rs b/lib/middlewares/src/metering.rs index 3e786777f..eea3efb14 100644 --- a/lib/middlewares/src/metering.rs +++ b/lib/middlewares/src/metering.rs @@ -406,7 +406,7 @@ mod tests { .exports .get_function("add_one") .unwrap() - .native(&store) + .typed(&store) .unwrap(); add_one.call(&mut store, 1).unwrap(); assert_eq!( @@ -447,7 +447,7 @@ mod tests { .exports .get_function("add_one") .unwrap() - .native(&store) + .typed(&store) .unwrap(); // Increase a bit to have enough for 3 calls diff --git a/lib/wasi/src/lib.rs b/lib/wasi/src/lib.rs index 2fa44e0f8..ea2915378 100644 --- a/lib/wasi/src/lib.rs +++ b/lib/wasi/src/lib.rs @@ -381,129 +381,129 @@ impl WasiEnv { /// Create an [`Imports`] from a [`Context`] pub fn generate_import_object_from_env( store: &mut impl AsStoreMut, - ctx: &FunctionEnv, + env: &FunctionEnv, version: WasiVersion, ) -> Imports { match version { - WasiVersion::Snapshot0 => generate_import_object_snapshot0(store, ctx), + WasiVersion::Snapshot0 => generate_import_object_snapshot0(store, env), WasiVersion::Snapshot1 | WasiVersion::Latest => { - generate_import_object_snapshot1(store, ctx) + generate_import_object_snapshot1(store, env) } - WasiVersion::Wasix32v1 => generate_import_object_wasix32_v1(store, ctx), - WasiVersion::Wasix64v1 => generate_import_object_wasix64_v1(store, ctx), + WasiVersion::Wasix32v1 => generate_import_object_wasix32_v1(store, env), + WasiVersion::Wasix64v1 => generate_import_object_wasix64_v1(store, env), } } -fn wasi_unstable_exports(mut store: &mut impl AsStoreMut, ctx: &FunctionEnv) -> Exports { +fn wasi_unstable_exports(mut store: &mut impl AsStoreMut, env: &FunctionEnv) -> Exports { let namespace = namespace! { - "args_get" => Function::new_native(&mut store, ctx, args_get::), - "args_sizes_get" => Function::new_native(&mut store, ctx, args_sizes_get::), - "clock_res_get" => Function::new_native(&mut store, ctx, clock_res_get::), - "clock_time_get" => Function::new_native(&mut store, ctx, clock_time_get::), - "environ_get" => Function::new_native(&mut store, ctx, environ_get::), - "environ_sizes_get" => Function::new_native(&mut store, ctx, environ_sizes_get::), - "fd_advise" => Function::new_native(&mut store, ctx, fd_advise), - "fd_allocate" => Function::new_native(&mut store, ctx, fd_allocate), - "fd_close" => Function::new_native(&mut store, ctx, fd_close), - "fd_datasync" => Function::new_native(&mut store, ctx, fd_datasync), - "fd_fdstat_get" => Function::new_native(&mut store, ctx, fd_fdstat_get::), - "fd_fdstat_set_flags" => Function::new_native(&mut store, ctx, fd_fdstat_set_flags), - "fd_fdstat_set_rights" => Function::new_native(&mut store, ctx, fd_fdstat_set_rights), - "fd_filestat_get" => Function::new_native(&mut store, ctx, legacy::snapshot0::fd_filestat_get), - "fd_filestat_set_size" => Function::new_native(&mut store, ctx, fd_filestat_set_size), - "fd_filestat_set_times" => Function::new_native(&mut store, ctx, fd_filestat_set_times), - "fd_pread" => Function::new_native(&mut store, ctx, fd_pread::), - "fd_prestat_get" => Function::new_native(&mut store, ctx, fd_prestat_get::), - "fd_prestat_dir_name" => Function::new_native(&mut store, ctx, fd_prestat_dir_name::), - "fd_pwrite" => Function::new_native(&mut store, ctx, fd_pwrite::), - "fd_read" => Function::new_native(&mut store, ctx, fd_read::), - "fd_readdir" => Function::new_native(&mut store, ctx, fd_readdir::), - "fd_renumber" => Function::new_native(&mut store, ctx, fd_renumber), - "fd_seek" => Function::new_native(&mut store, ctx, legacy::snapshot0::fd_seek), - "fd_sync" => Function::new_native(&mut store, ctx, fd_sync), - "fd_tell" => Function::new_native(&mut store, ctx, fd_tell::), - "fd_write" => Function::new_native(&mut store, ctx, fd_write::), - "path_create_directory" => Function::new_native(&mut store, ctx, path_create_directory::), - "path_filestat_get" => Function::new_native(&mut store, ctx, legacy::snapshot0::path_filestat_get), - "path_filestat_set_times" => Function::new_native(&mut store, ctx, path_filestat_set_times::), - "path_link" => Function::new_native(&mut store, ctx, path_link::), - "path_open" => Function::new_native(&mut store, ctx, path_open::), - "path_readlink" => Function::new_native(&mut store, ctx, path_readlink::), - "path_remove_directory" => Function::new_native(&mut store, ctx, path_remove_directory::), - "path_rename" => Function::new_native(&mut store, ctx, path_rename::), - "path_symlink" => Function::new_native(&mut store, ctx, path_symlink::), - "path_unlink_file" => Function::new_native(&mut store, ctx, path_unlink_file::), - "poll_oneoff" => Function::new_native(&mut store, ctx, legacy::snapshot0::poll_oneoff), - "proc_exit" => Function::new_native(&mut store, ctx, proc_exit), - "proc_raise" => Function::new_native(&mut store, ctx, proc_raise), - "random_get" => Function::new_native(&mut store, ctx, random_get::), - "sched_yield" => Function::new_native(&mut store, ctx, sched_yield), - "sock_recv" => Function::new_native(&mut store, ctx, sock_recv::), - "sock_send" => Function::new_native(&mut store, ctx, sock_send::), - "sock_shutdown" => Function::new_native(&mut store, ctx, sock_shutdown), + "args_get" => Function::new_typed_with_env(&mut store, env, args_get::), + "args_sizes_get" => Function::new_typed_with_env(&mut store, env, args_sizes_get::), + "clock_res_get" => Function::new_typed_with_env(&mut store, env, clock_res_get::), + "clock_time_get" => Function::new_typed_with_env(&mut store, env, clock_time_get::), + "environ_get" => Function::new_typed_with_env(&mut store, env, environ_get::), + "environ_sizes_get" => Function::new_typed_with_env(&mut store, env, environ_sizes_get::), + "fd_advise" => Function::new_typed_with_env(&mut store, env, fd_advise), + "fd_allocate" => Function::new_typed_with_env(&mut store, env, fd_allocate), + "fd_close" => Function::new_typed_with_env(&mut store, env, fd_close), + "fd_datasync" => Function::new_typed_with_env(&mut store, env, fd_datasync), + "fd_fdstat_get" => Function::new_typed_with_env(&mut store, env, fd_fdstat_get::), + "fd_fdstat_set_flags" => Function::new_typed_with_env(&mut store, env, fd_fdstat_set_flags), + "fd_fdstat_set_rights" => Function::new_typed_with_env(&mut store, env, fd_fdstat_set_rights), + "fd_filestat_get" => Function::new_typed_with_env(&mut store, env, legacy::snapshot0::fd_filestat_get), + "fd_filestat_set_size" => Function::new_typed_with_env(&mut store, env, fd_filestat_set_size), + "fd_filestat_set_times" => Function::new_typed_with_env(&mut store, env, fd_filestat_set_times), + "fd_pread" => Function::new_typed_with_env(&mut store, env, fd_pread::), + "fd_prestat_get" => Function::new_typed_with_env(&mut store, env, fd_prestat_get::), + "fd_prestat_dir_name" => Function::new_typed_with_env(&mut store, env, fd_prestat_dir_name::), + "fd_pwrite" => Function::new_typed_with_env(&mut store, env, fd_pwrite::), + "fd_read" => Function::new_typed_with_env(&mut store, env, fd_read::), + "fd_readdir" => Function::new_typed_with_env(&mut store, env, fd_readdir::), + "fd_renumber" => Function::new_typed_with_env(&mut store, env, fd_renumber), + "fd_seek" => Function::new_typed_with_env(&mut store, env, legacy::snapshot0::fd_seek), + "fd_sync" => Function::new_typed_with_env(&mut store, env, fd_sync), + "fd_tell" => Function::new_typed_with_env(&mut store, env, fd_tell::), + "fd_write" => Function::new_typed_with_env(&mut store, env, fd_write::), + "path_create_directory" => Function::new_typed_with_env(&mut store, env, path_create_directory::), + "path_filestat_get" => Function::new_typed_with_env(&mut store, env, legacy::snapshot0::path_filestat_get), + "path_filestat_set_times" => Function::new_typed_with_env(&mut store, env, path_filestat_set_times::), + "path_link" => Function::new_typed_with_env(&mut store, env, path_link::), + "path_open" => Function::new_typed_with_env(&mut store, env, path_open::), + "path_readlink" => Function::new_typed_with_env(&mut store, env, path_readlink::), + "path_remove_directory" => Function::new_typed_with_env(&mut store, env, path_remove_directory::), + "path_rename" => Function::new_typed_with_env(&mut store, env, path_rename::), + "path_symlink" => Function::new_typed_with_env(&mut store, env, path_symlink::), + "path_unlink_file" => Function::new_typed_with_env(&mut store, env, path_unlink_file::), + "poll_oneoff" => Function::new_typed_with_env(&mut store, env, legacy::snapshot0::poll_oneoff), + "proc_exit" => Function::new_typed_with_env(&mut store, env, proc_exit), + "proc_raise" => Function::new_typed_with_env(&mut store, env, proc_raise), + "random_get" => Function::new_typed_with_env(&mut store, env, random_get::), + "sched_yield" => Function::new_typed_with_env(&mut store, env, sched_yield), + "sock_recv" => Function::new_typed_with_env(&mut store, env, sock_recv::), + "sock_send" => Function::new_typed_with_env(&mut store, env, sock_send::), + "sock_shutdown" => Function::new_typed_with_env(&mut store, env, sock_shutdown), }; namespace } fn wasi_snapshot_preview1_exports( mut store: &mut impl AsStoreMut, - ctx: &FunctionEnv, + env: &FunctionEnv, ) -> Exports { let namespace = namespace! { - "args_get" => Function::new_native(&mut store, ctx, args_get::), - "args_sizes_get" => Function::new_native(&mut store, ctx, args_sizes_get::), - "clock_res_get" => Function::new_native(&mut store, ctx, clock_res_get::), - "clock_time_get" => Function::new_native(&mut store, ctx, clock_time_get::), - "environ_get" => Function::new_native(&mut store, ctx, environ_get::), - "environ_sizes_get" => Function::new_native(&mut store, ctx, environ_sizes_get::), - "fd_advise" => Function::new_native(&mut store, ctx, fd_advise), - "fd_allocate" => Function::new_native(&mut store, ctx, fd_allocate), - "fd_close" => Function::new_native(&mut store, ctx, fd_close), - "fd_datasync" => Function::new_native(&mut store, ctx, fd_datasync), - "fd_fdstat_get" => Function::new_native(&mut store, ctx, fd_fdstat_get::), - "fd_fdstat_set_flags" => Function::new_native(&mut store, ctx, fd_fdstat_set_flags), - "fd_fdstat_set_rights" => Function::new_native(&mut store, ctx, fd_fdstat_set_rights), - "fd_filestat_get" => Function::new_native(&mut store, ctx, fd_filestat_get::), - "fd_filestat_set_size" => Function::new_native(&mut store, ctx, fd_filestat_set_size), - "fd_filestat_set_times" => Function::new_native(&mut store, ctx, fd_filestat_set_times), - "fd_pread" => Function::new_native(&mut store, ctx, fd_pread::), - "fd_prestat_get" => Function::new_native(&mut store, ctx, fd_prestat_get::), - "fd_prestat_dir_name" => Function::new_native(&mut store, ctx, fd_prestat_dir_name::), - "fd_pwrite" => Function::new_native(&mut store, ctx, fd_pwrite::), - "fd_read" => Function::new_native(&mut store, ctx, fd_read::), - "fd_readdir" => Function::new_native(&mut store, ctx, fd_readdir::), - "fd_renumber" => Function::new_native(&mut store, ctx, fd_renumber), - "fd_seek" => Function::new_native(&mut store, ctx, fd_seek::), - "fd_sync" => Function::new_native(&mut store, ctx, fd_sync), - "fd_tell" => Function::new_native(&mut store, ctx, fd_tell::), - "fd_write" => Function::new_native(&mut store, ctx, fd_write::), - "path_create_directory" => Function::new_native(&mut store, ctx, path_create_directory::), - "path_filestat_get" => Function::new_native(&mut store, ctx, path_filestat_get::), - "path_filestat_set_times" => Function::new_native(&mut store, ctx, path_filestat_set_times::), - "path_link" => Function::new_native(&mut store, ctx, path_link::), - "path_open" => Function::new_native(&mut store, ctx, path_open::), - "path_readlink" => Function::new_native(&mut store, ctx, path_readlink::), - "path_remove_directory" => Function::new_native(&mut store, ctx, path_remove_directory::), - "path_rename" => Function::new_native(&mut store, ctx, path_rename::), - "path_symlink" => Function::new_native(&mut store, ctx, path_symlink::), - "path_unlink_file" => Function::new_native(&mut store, ctx, path_unlink_file::), - "poll_oneoff" => Function::new_native(&mut store, ctx, poll_oneoff::), - "proc_exit" => Function::new_native(&mut store, ctx, proc_exit), - "proc_raise" => Function::new_native(&mut store, ctx, proc_raise), - "random_get" => Function::new_native(&mut store, ctx, random_get::), - "sched_yield" => Function::new_native(&mut store, ctx, sched_yield), - "sock_recv" => Function::new_native(&mut store, ctx, sock_recv::), - "sock_send" => Function::new_native(&mut store, ctx, sock_send::), - "sock_shutdown" => Function::new_native(&mut store, ctx, sock_shutdown), + "args_get" => Function::new_typed_with_env(&mut store, env, args_get::), + "args_sizes_get" => Function::new_typed_with_env(&mut store, env, args_sizes_get::), + "clock_res_get" => Function::new_typed_with_env(&mut store, env, clock_res_get::), + "clock_time_get" => Function::new_typed_with_env(&mut store, env, clock_time_get::), + "environ_get" => Function::new_typed_with_env(&mut store, env, environ_get::), + "environ_sizes_get" => Function::new_typed_with_env(&mut store, env, environ_sizes_get::), + "fd_advise" => Function::new_typed_with_env(&mut store, env, fd_advise), + "fd_allocate" => Function::new_typed_with_env(&mut store, env, fd_allocate), + "fd_close" => Function::new_typed_with_env(&mut store, env, fd_close), + "fd_datasync" => Function::new_typed_with_env(&mut store, env, fd_datasync), + "fd_fdstat_get" => Function::new_typed_with_env(&mut store, env, fd_fdstat_get::), + "fd_fdstat_set_flags" => Function::new_typed_with_env(&mut store, env, fd_fdstat_set_flags), + "fd_fdstat_set_rights" => Function::new_typed_with_env(&mut store, env, fd_fdstat_set_rights), + "fd_filestat_get" => Function::new_typed_with_env(&mut store, env, fd_filestat_get::), + "fd_filestat_set_size" => Function::new_typed_with_env(&mut store, env, fd_filestat_set_size), + "fd_filestat_set_times" => Function::new_typed_with_env(&mut store, env, fd_filestat_set_times), + "fd_pread" => Function::new_typed_with_env(&mut store, env, fd_pread::), + "fd_prestat_get" => Function::new_typed_with_env(&mut store, env, fd_prestat_get::), + "fd_prestat_dir_name" => Function::new_typed_with_env(&mut store, env, fd_prestat_dir_name::), + "fd_pwrite" => Function::new_typed_with_env(&mut store, env, fd_pwrite::), + "fd_read" => Function::new_typed_with_env(&mut store, env, fd_read::), + "fd_readdir" => Function::new_typed_with_env(&mut store, env, fd_readdir::), + "fd_renumber" => Function::new_typed_with_env(&mut store, env, fd_renumber), + "fd_seek" => Function::new_typed_with_env(&mut store, env, fd_seek::), + "fd_sync" => Function::new_typed_with_env(&mut store, env, fd_sync), + "fd_tell" => Function::new_typed_with_env(&mut store, env, fd_tell::), + "fd_write" => Function::new_typed_with_env(&mut store, env, fd_write::), + "path_create_directory" => Function::new_typed_with_env(&mut store, env, path_create_directory::), + "path_filestat_get" => Function::new_typed_with_env(&mut store, env, path_filestat_get::), + "path_filestat_set_times" => Function::new_typed_with_env(&mut store, env, path_filestat_set_times::), + "path_link" => Function::new_typed_with_env(&mut store, env, path_link::), + "path_open" => Function::new_typed_with_env(&mut store, env, path_open::), + "path_readlink" => Function::new_typed_with_env(&mut store, env, path_readlink::), + "path_remove_directory" => Function::new_typed_with_env(&mut store, env, path_remove_directory::), + "path_rename" => Function::new_typed_with_env(&mut store, env, path_rename::), + "path_symlink" => Function::new_typed_with_env(&mut store, env, path_symlink::), + "path_unlink_file" => Function::new_typed_with_env(&mut store, env, path_unlink_file::), + "poll_oneoff" => Function::new_typed_with_env(&mut store, env, poll_oneoff::), + "proc_exit" => Function::new_typed_with_env(&mut store, env, proc_exit), + "proc_raise" => Function::new_typed_with_env(&mut store, env, proc_raise), + "random_get" => Function::new_typed_with_env(&mut store, env, random_get::), + "sched_yield" => Function::new_typed_with_env(&mut store, env, sched_yield), + "sock_recv" => Function::new_typed_with_env(&mut store, env, sock_recv::), + "sock_send" => Function::new_typed_with_env(&mut store, env, sock_send::), + "sock_shutdown" => Function::new_typed_with_env(&mut store, env, sock_shutdown), }; namespace } pub fn import_object_for_all_wasi_versions( store: &mut impl AsStoreMut, - ctx: &FunctionEnv, + env: &FunctionEnv, ) -> Imports { - let wasi_unstable_exports = wasi_unstable_exports(store, ctx); - let wasi_snapshot_preview1_exports = wasi_snapshot_preview1_exports(store, ctx); + let wasi_unstable_exports = wasi_unstable_exports(store, env); + let wasi_snapshot_preview1_exports = wasi_snapshot_preview1_exports(store, env); imports! { "wasi_unstable" => wasi_unstable_exports, "wasi_snapshot_preview1" => wasi_snapshot_preview1_exports, @@ -513,9 +513,9 @@ pub fn import_object_for_all_wasi_versions( /// Combines a state generating function with the import list for legacy WASI fn generate_import_object_snapshot0( store: &mut impl AsStoreMut, - ctx: &FunctionEnv, + env: &FunctionEnv, ) -> Imports { - let wasi_unstable_exports = wasi_unstable_exports(store, ctx); + let wasi_unstable_exports = wasi_unstable_exports(store, env); imports! { "wasi_unstable" => wasi_unstable_exports } @@ -523,9 +523,9 @@ fn generate_import_object_snapshot0( fn generate_import_object_snapshot1( store: &mut impl AsStoreMut, - ctx: &FunctionEnv, + env: &FunctionEnv, ) -> Imports { - let wasi_snapshot_preview1_exports = wasi_snapshot_preview1_exports(store, ctx); + let wasi_snapshot_preview1_exports = wasi_snapshot_preview1_exports(store, env); imports! { "wasi_snapshot_preview1" => wasi_snapshot_preview1_exports } @@ -534,236 +534,236 @@ fn generate_import_object_snapshot1( /// Combines a state generating function with the import list for snapshot 1 fn generate_import_object_wasix32_v1( mut store: &mut impl AsStoreMut, - ctx: &FunctionEnv, + env: &FunctionEnv, ) -> Imports { use self::wasix32::*; imports! { "wasix_32v1" => { - "args_get" => Function::new_native(&mut store, ctx, args_get), - "args_sizes_get" => Function::new_native(&mut store, ctx, args_sizes_get), - "clock_res_get" => Function::new_native(&mut store, ctx, clock_res_get), - "clock_time_get" => Function::new_native(&mut store, ctx, clock_time_get), - "environ_get" => Function::new_native(&mut store, ctx, environ_get), - "environ_sizes_get" => Function::new_native(&mut store, ctx, environ_sizes_get), - "fd_advise" => Function::new_native(&mut store, ctx, fd_advise), - "fd_allocate" => Function::new_native(&mut store, ctx, fd_allocate), - "fd_close" => Function::new_native(&mut store, ctx, fd_close), - "fd_datasync" => Function::new_native(&mut store, ctx, fd_datasync), - "fd_fdstat_get" => Function::new_native(&mut store, ctx, fd_fdstat_get), - "fd_fdstat_set_flags" => Function::new_native(&mut store, ctx, fd_fdstat_set_flags), - "fd_fdstat_set_rights" => Function::new_native(&mut store, ctx, fd_fdstat_set_rights), - "fd_filestat_get" => Function::new_native(&mut store, ctx, fd_filestat_get), - "fd_filestat_set_size" => Function::new_native(&mut store, ctx, fd_filestat_set_size), - "fd_filestat_set_times" => Function::new_native(&mut store, ctx, fd_filestat_set_times), - "fd_pread" => Function::new_native(&mut store, ctx, fd_pread), - "fd_prestat_get" => Function::new_native(&mut store, ctx, fd_prestat_get), - "fd_prestat_dir_name" => Function::new_native(&mut store, ctx, fd_prestat_dir_name), - "fd_pwrite" => Function::new_native(&mut store, ctx, fd_pwrite), - "fd_read" => Function::new_native(&mut store, ctx, fd_read), - "fd_readdir" => Function::new_native(&mut store, ctx, fd_readdir), - "fd_renumber" => Function::new_native(&mut store, ctx, fd_renumber), - "fd_dup" => Function::new_native(&mut store, ctx, fd_dup), - "fd_event" => Function::new_native(&mut store, ctx, fd_event), - "fd_seek" => Function::new_native(&mut store, ctx, fd_seek), - "fd_sync" => Function::new_native(&mut store, ctx, fd_sync), - "fd_tell" => Function::new_native(&mut store, ctx, fd_tell), - "fd_write" => Function::new_native(&mut store, ctx, fd_write), - "fd_pipe" => Function::new_native(&mut store, ctx, fd_pipe), - "path_create_directory" => Function::new_native(&mut store, ctx, path_create_directory), - "path_filestat_get" => Function::new_native(&mut store, ctx, path_filestat_get), - "path_filestat_set_times" => Function::new_native(&mut store, ctx, path_filestat_set_times), - "path_link" => Function::new_native(&mut store, ctx, path_link), - "path_open" => Function::new_native(&mut store, ctx, path_open), - "path_readlink" => Function::new_native(&mut store, ctx, path_readlink), - "path_remove_directory" => Function::new_native(&mut store, ctx, path_remove_directory), - "path_rename" => Function::new_native(&mut store, ctx, path_rename), - "path_symlink" => Function::new_native(&mut store, ctx, path_symlink), - "path_unlink_file" => Function::new_native(&mut store, ctx, path_unlink_file), - "poll_oneoff" => Function::new_native(&mut store, ctx, poll_oneoff), - "proc_exit" => Function::new_native(&mut store, ctx, proc_exit), - "proc_raise" => Function::new_native(&mut store, ctx, proc_raise), - "random_get" => Function::new_native(&mut store, ctx, random_get), - "tty_get" => Function::new_native(&mut store, ctx, tty_get), - "tty_set" => Function::new_native(&mut store, ctx, tty_set), - "getcwd" => Function::new_native(&mut store, ctx, getcwd), - "chdir" => Function::new_native(&mut store, ctx, chdir), - "thread_spawn" => Function::new_native(&mut store, ctx, thread_spawn), - "thread_sleep" => Function::new_native(&mut store, ctx, thread_sleep), - "thread_id" => Function::new_native(&mut store, ctx, thread_id), - "thread_join" => Function::new_native(&mut store, ctx, thread_join), - "thread_parallelism" => Function::new_native(&mut store, ctx, thread_parallelism), - "thread_exit" => Function::new_native(&mut store, ctx, thread_exit), - "sched_yield" => Function::new_native(&mut store, ctx, sched_yield), - "getpid" => Function::new_native(&mut store, ctx, getpid), - "process_spawn" => Function::new_native(&mut store, ctx, process_spawn), - "bus_open_local" => Function::new_native(&mut store, ctx, bus_open_local), - "bus_open_remote" => Function::new_native(&mut store, ctx, bus_open_remote), - "bus_close" => Function::new_native(&mut store, ctx, bus_close), - "bus_call" => Function::new_native(&mut store, ctx, bus_call), - "bus_subcall" => Function::new_native(&mut store, ctx, bus_subcall), - "bus_poll" => Function::new_native(&mut store, ctx, bus_poll), - "call_reply" => Function::new_native(&mut store, ctx, call_reply), - "call_fault" => Function::new_native(&mut store, ctx, call_fault), - "call_close" => Function::new_native(&mut store, ctx, call_close), - "ws_connect" => Function::new_native(&mut store, ctx, ws_connect), - "http_request" => Function::new_native(&mut store, ctx, http_request), - "http_status" => Function::new_native(&mut store, ctx, http_status), - "port_bridge" => Function::new_native(&mut store, ctx, port_bridge), - "port_unbridge" => Function::new_native(&mut store, ctx, port_unbridge), - "port_dhcp_acquire" => Function::new_native(&mut store, ctx, port_dhcp_acquire), - "port_addr_add" => Function::new_native(&mut store, ctx, port_addr_add), - "port_addr_remove" => Function::new_native(&mut store, ctx, port_addr_remove), - "port_addr_clear" => Function::new_native(&mut store, ctx, port_addr_clear), - "port_addr_list" => Function::new_native(&mut store, ctx, port_addr_list), - "port_mac" => Function::new_native(&mut store, ctx, port_mac), - "port_gateway_set" => Function::new_native(&mut store, ctx, port_gateway_set), - "port_route_add" => Function::new_native(&mut store, ctx, port_route_add), - "port_route_remove" => Function::new_native(&mut store, ctx, port_route_remove), - "port_route_clear" => Function::new_native(&mut store, ctx, port_route_clear), - "port_route_list" => Function::new_native(&mut store, ctx, port_route_list), - "sock_status" => Function::new_native(&mut store, ctx, sock_status), - "sock_addr_local" => Function::new_native(&mut store, ctx, sock_addr_local), - "sock_addr_peer" => Function::new_native(&mut store, ctx, sock_addr_peer), - "sock_open" => Function::new_native(&mut store, ctx, sock_open), - "sock_set_opt_flag" => Function::new_native(&mut store, ctx, sock_set_opt_flag), - "sock_get_opt_flag" => Function::new_native(&mut store, ctx, sock_get_opt_flag), - "sock_set_opt_time" => Function::new_native(&mut store, ctx, sock_set_opt_time), - "sock_get_opt_time" => Function::new_native(&mut store, ctx, sock_get_opt_time), - "sock_set_opt_size" => Function::new_native(&mut store, ctx, sock_set_opt_size), - "sock_get_opt_size" => Function::new_native(&mut store, ctx, sock_get_opt_size), - "sock_join_multicast_v4" => Function::new_native(&mut store, ctx, sock_join_multicast_v4), - "sock_leave_multicast_v4" => Function::new_native(&mut store, ctx, sock_leave_multicast_v4), - "sock_join_multicast_v6" => Function::new_native(&mut store, ctx, sock_join_multicast_v6), - "sock_leave_multicast_v6" => Function::new_native(&mut store, ctx, sock_leave_multicast_v6), - "sock_bind" => Function::new_native(&mut store, ctx, sock_bind), - "sock_listen" => Function::new_native(&mut store, ctx, sock_listen), - "sock_accept" => Function::new_native(&mut store, ctx, sock_accept), - "sock_connect" => Function::new_native(&mut store, ctx, sock_connect), - "sock_recv" => Function::new_native(&mut store, ctx, sock_recv), - "sock_recv_from" => Function::new_native(&mut store, ctx, sock_recv_from), - "sock_send" => Function::new_native(&mut store, ctx, sock_send), - "sock_send_to" => Function::new_native(&mut store, ctx, sock_send_to), - "sock_send_file" => Function::new_native(&mut store, ctx, sock_send_file), - "sock_shutdown" => Function::new_native(&mut store, ctx, sock_shutdown), - "resolve" => Function::new_native(&mut store, ctx, resolve), + "args_get" => Function::new_typed_with_env(&mut store, env, args_get), + "args_sizes_get" => Function::new_typed_with_env(&mut store, env, args_sizes_get), + "clock_res_get" => Function::new_typed_with_env(&mut store, env, clock_res_get), + "clock_time_get" => Function::new_typed_with_env(&mut store, env, clock_time_get), + "environ_get" => Function::new_typed_with_env(&mut store, env, environ_get), + "environ_sizes_get" => Function::new_typed_with_env(&mut store, env, environ_sizes_get), + "fd_advise" => Function::new_typed_with_env(&mut store, env, fd_advise), + "fd_allocate" => Function::new_typed_with_env(&mut store, env, fd_allocate), + "fd_close" => Function::new_typed_with_env(&mut store, env, fd_close), + "fd_datasync" => Function::new_typed_with_env(&mut store, env, fd_datasync), + "fd_fdstat_get" => Function::new_typed_with_env(&mut store, env, fd_fdstat_get), + "fd_fdstat_set_flags" => Function::new_typed_with_env(&mut store, env, fd_fdstat_set_flags), + "fd_fdstat_set_rights" => Function::new_typed_with_env(&mut store, env, fd_fdstat_set_rights), + "fd_filestat_get" => Function::new_typed_with_env(&mut store, env, fd_filestat_get), + "fd_filestat_set_size" => Function::new_typed_with_env(&mut store, env, fd_filestat_set_size), + "fd_filestat_set_times" => Function::new_typed_with_env(&mut store, env, fd_filestat_set_times), + "fd_pread" => Function::new_typed_with_env(&mut store, env, fd_pread), + "fd_prestat_get" => Function::new_typed_with_env(&mut store, env, fd_prestat_get), + "fd_prestat_dir_name" => Function::new_typed_with_env(&mut store, env, fd_prestat_dir_name), + "fd_pwrite" => Function::new_typed_with_env(&mut store, env, fd_pwrite), + "fd_read" => Function::new_typed_with_env(&mut store, env, fd_read), + "fd_readdir" => Function::new_typed_with_env(&mut store, env, fd_readdir), + "fd_renumber" => Function::new_typed_with_env(&mut store, env, fd_renumber), + "fd_dup" => Function::new_typed_with_env(&mut store, env, fd_dup), + "fd_event" => Function::new_typed_with_env(&mut store, env, fd_event), + "fd_seek" => Function::new_typed_with_env(&mut store, env, fd_seek), + "fd_sync" => Function::new_typed_with_env(&mut store, env, fd_sync), + "fd_tell" => Function::new_typed_with_env(&mut store, env, fd_tell), + "fd_write" => Function::new_typed_with_env(&mut store, env, fd_write), + "fd_pipe" => Function::new_typed_with_env(&mut store, env, fd_pipe), + "path_create_directory" => Function::new_typed_with_env(&mut store, env, path_create_directory), + "path_filestat_get" => Function::new_typed_with_env(&mut store, env, path_filestat_get), + "path_filestat_set_times" => Function::new_typed_with_env(&mut store, env, path_filestat_set_times), + "path_link" => Function::new_typed_with_env(&mut store, env, path_link), + "path_open" => Function::new_typed_with_env(&mut store, env, path_open), + "path_readlink" => Function::new_typed_with_env(&mut store, env, path_readlink), + "path_remove_directory" => Function::new_typed_with_env(&mut store, env, path_remove_directory), + "path_rename" => Function::new_typed_with_env(&mut store, env, path_rename), + "path_symlink" => Function::new_typed_with_env(&mut store, env, path_symlink), + "path_unlink_file" => Function::new_typed_with_env(&mut store, env, path_unlink_file), + "poll_oneoff" => Function::new_typed_with_env(&mut store, env, poll_oneoff), + "proc_exit" => Function::new_typed_with_env(&mut store, env, proc_exit), + "proc_raise" => Function::new_typed_with_env(&mut store, env, proc_raise), + "random_get" => Function::new_typed_with_env(&mut store, env, random_get), + "tty_get" => Function::new_typed_with_env(&mut store, env, tty_get), + "tty_set" => Function::new_typed_with_env(&mut store, env, tty_set), + "getcwd" => Function::new_typed_with_env(&mut store, env, getcwd), + "chdir" => Function::new_typed_with_env(&mut store, env, chdir), + "thread_spawn" => Function::new_typed_with_env(&mut store, env, thread_spawn), + "thread_sleep" => Function::new_typed_with_env(&mut store, env, thread_sleep), + "thread_id" => Function::new_typed_with_env(&mut store, env, thread_id), + "thread_join" => Function::new_typed_with_env(&mut store, env, thread_join), + "thread_parallelism" => Function::new_typed_with_env(&mut store, env, thread_parallelism), + "thread_exit" => Function::new_typed_with_env(&mut store, env, thread_exit), + "sched_yield" => Function::new_typed_with_env(&mut store, env, sched_yield), + "getpid" => Function::new_typed_with_env(&mut store, env, getpid), + "process_spawn" => Function::new_typed_with_env(&mut store, env, process_spawn), + "bus_open_local" => Function::new_typed_with_env(&mut store, env, bus_open_local), + "bus_open_remote" => Function::new_typed_with_env(&mut store, env, bus_open_remote), + "bus_close" => Function::new_typed_with_env(&mut store, env, bus_close), + "bus_call" => Function::new_typed_with_env(&mut store, env, bus_call), + "bus_subcall" => Function::new_typed_with_env(&mut store, env, bus_subcall), + "bus_poll" => Function::new_typed_with_env(&mut store, env, bus_poll), + "call_reply" => Function::new_typed_with_env(&mut store, env, call_reply), + "call_fault" => Function::new_typed_with_env(&mut store, env, call_fault), + "call_close" => Function::new_typed_with_env(&mut store, env, call_close), + "ws_connect" => Function::new_typed_with_env(&mut store, env, ws_connect), + "http_request" => Function::new_typed_with_env(&mut store, env, http_request), + "http_status" => Function::new_typed_with_env(&mut store, env, http_status), + "port_bridge" => Function::new_typed_with_env(&mut store, env, port_bridge), + "port_unbridge" => Function::new_typed_with_env(&mut store, env, port_unbridge), + "port_dhcp_acquire" => Function::new_typed_with_env(&mut store, env, port_dhcp_acquire), + "port_addr_add" => Function::new_typed_with_env(&mut store, env, port_addr_add), + "port_addr_remove" => Function::new_typed_with_env(&mut store, env, port_addr_remove), + "port_addr_clear" => Function::new_typed_with_env(&mut store, env, port_addr_clear), + "port_addr_list" => Function::new_typed_with_env(&mut store, env, port_addr_list), + "port_mac" => Function::new_typed_with_env(&mut store, env, port_mac), + "port_gateway_set" => Function::new_typed_with_env(&mut store, env, port_gateway_set), + "port_route_add" => Function::new_typed_with_env(&mut store, env, port_route_add), + "port_route_remove" => Function::new_typed_with_env(&mut store, env, port_route_remove), + "port_route_clear" => Function::new_typed_with_env(&mut store, env, port_route_clear), + "port_route_list" => Function::new_typed_with_env(&mut store, env, port_route_list), + "sock_status" => Function::new_typed_with_env(&mut store, env, sock_status), + "sock_addr_local" => Function::new_typed_with_env(&mut store, env, sock_addr_local), + "sock_addr_peer" => Function::new_typed_with_env(&mut store, env, sock_addr_peer), + "sock_open" => Function::new_typed_with_env(&mut store, env, sock_open), + "sock_set_opt_flag" => Function::new_typed_with_env(&mut store, env, sock_set_opt_flag), + "sock_get_opt_flag" => Function::new_typed_with_env(&mut store, env, sock_get_opt_flag), + "sock_set_opt_time" => Function::new_typed_with_env(&mut store, env, sock_set_opt_time), + "sock_get_opt_time" => Function::new_typed_with_env(&mut store, env, sock_get_opt_time), + "sock_set_opt_size" => Function::new_typed_with_env(&mut store, env, sock_set_opt_size), + "sock_get_opt_size" => Function::new_typed_with_env(&mut store, env, sock_get_opt_size), + "sock_join_multicast_v4" => Function::new_typed_with_env(&mut store, env, sock_join_multicast_v4), + "sock_leave_multicast_v4" => Function::new_typed_with_env(&mut store, env, sock_leave_multicast_v4), + "sock_join_multicast_v6" => Function::new_typed_with_env(&mut store, env, sock_join_multicast_v6), + "sock_leave_multicast_v6" => Function::new_typed_with_env(&mut store, env, sock_leave_multicast_v6), + "sock_bind" => Function::new_typed_with_env(&mut store, env, sock_bind), + "sock_listen" => Function::new_typed_with_env(&mut store, env, sock_listen), + "sock_accept" => Function::new_typed_with_env(&mut store, env, sock_accept), + "sock_connect" => Function::new_typed_with_env(&mut store, env, sock_connect), + "sock_recv" => Function::new_typed_with_env(&mut store, env, sock_recv), + "sock_recv_from" => Function::new_typed_with_env(&mut store, env, sock_recv_from), + "sock_send" => Function::new_typed_with_env(&mut store, env, sock_send), + "sock_send_to" => Function::new_typed_with_env(&mut store, env, sock_send_to), + "sock_send_file" => Function::new_typed_with_env(&mut store, env, sock_send_file), + "sock_shutdown" => Function::new_typed_with_env(&mut store, env, sock_shutdown), + "resolve" => Function::new_typed_with_env(&mut store, env, resolve), } } } fn generate_import_object_wasix64_v1( mut store: &mut impl AsStoreMut, - ctx: &FunctionEnv, + env: &FunctionEnv, ) -> Imports { use self::wasix64::*; imports! { "wasix_64v1" => { - "args_get" => Function::new_native(&mut store, ctx, args_get), - "args_sizes_get" => Function::new_native(&mut store, ctx, args_sizes_get), - "clock_res_get" => Function::new_native(&mut store, ctx, clock_res_get), - "clock_time_get" => Function::new_native(&mut store, ctx, clock_time_get), - "environ_get" => Function::new_native(&mut store, ctx, environ_get), - "environ_sizes_get" => Function::new_native(&mut store, ctx, environ_sizes_get), - "fd_advise" => Function::new_native(&mut store, ctx, fd_advise), - "fd_allocate" => Function::new_native(&mut store, ctx, fd_allocate), - "fd_close" => Function::new_native(&mut store, ctx, fd_close), - "fd_datasync" => Function::new_native(&mut store, ctx, fd_datasync), - "fd_fdstat_get" => Function::new_native(&mut store, ctx, fd_fdstat_get), - "fd_fdstat_set_flags" => Function::new_native(&mut store, ctx, fd_fdstat_set_flags), - "fd_fdstat_set_rights" => Function::new_native(&mut store, ctx, fd_fdstat_set_rights), - "fd_filestat_get" => Function::new_native(&mut store, ctx, fd_filestat_get), - "fd_filestat_set_size" => Function::new_native(&mut store, ctx, fd_filestat_set_size), - "fd_filestat_set_times" => Function::new_native(&mut store, ctx, fd_filestat_set_times), - "fd_pread" => Function::new_native(&mut store, ctx, fd_pread), - "fd_prestat_get" => Function::new_native(&mut store, ctx, fd_prestat_get), - "fd_prestat_dir_name" => Function::new_native(&mut store, ctx, fd_prestat_dir_name), - "fd_pwrite" => Function::new_native(&mut store, ctx, fd_pwrite), - "fd_read" => Function::new_native(&mut store, ctx, fd_read), - "fd_readdir" => Function::new_native(&mut store, ctx, fd_readdir), - "fd_renumber" => Function::new_native(&mut store, ctx, fd_renumber), - "fd_dup" => Function::new_native(&mut store, ctx, fd_dup), - "fd_event" => Function::new_native(&mut store, ctx, fd_event), - "fd_seek" => Function::new_native(&mut store, ctx, fd_seek), - "fd_sync" => Function::new_native(&mut store, ctx, fd_sync), - "fd_tell" => Function::new_native(&mut store, ctx, fd_tell), - "fd_write" => Function::new_native(&mut store, ctx, fd_write), - "fd_pipe" => Function::new_native(&mut store, ctx, fd_pipe), - "path_create_directory" => Function::new_native(&mut store, ctx, path_create_directory), - "path_filestat_get" => Function::new_native(&mut store, ctx, path_filestat_get), - "path_filestat_set_times" => Function::new_native(&mut store, ctx, path_filestat_set_times), - "path_link" => Function::new_native(&mut store, ctx, path_link), - "path_open" => Function::new_native(&mut store, ctx, path_open), - "path_readlink" => Function::new_native(&mut store, ctx, path_readlink), - "path_remove_directory" => Function::new_native(&mut store, ctx, path_remove_directory), - "path_rename" => Function::new_native(&mut store, ctx, path_rename), - "path_symlink" => Function::new_native(&mut store, ctx, path_symlink), - "path_unlink_file" => Function::new_native(&mut store, ctx, path_unlink_file), - "poll_oneoff" => Function::new_native(&mut store, ctx, poll_oneoff), - "proc_exit" => Function::new_native(&mut store, ctx, proc_exit), - "proc_raise" => Function::new_native(&mut store, ctx, proc_raise), - "random_get" => Function::new_native(&mut store, ctx, random_get), - "tty_get" => Function::new_native(&mut store, ctx, tty_get), - "tty_set" => Function::new_native(&mut store, ctx, tty_set), - "getcwd" => Function::new_native(&mut store, ctx, getcwd), - "chdir" => Function::new_native(&mut store, ctx, chdir), - "thread_spawn" => Function::new_native(&mut store, ctx, thread_spawn), - "thread_sleep" => Function::new_native(&mut store, ctx, thread_sleep), - "thread_id" => Function::new_native(&mut store, ctx, thread_id), - "thread_join" => Function::new_native(&mut store, ctx, thread_join), - "thread_parallelism" => Function::new_native(&mut store, ctx, thread_parallelism), - "thread_exit" => Function::new_native(&mut store, ctx, thread_exit), - "sched_yield" => Function::new_native(&mut store, ctx, sched_yield), - "getpid" => Function::new_native(&mut store, ctx, getpid), - "process_spawn" => Function::new_native(&mut store, ctx, process_spawn), - "bus_open_local" => Function::new_native(&mut store, ctx, bus_open_local), - "bus_open_remote" => Function::new_native(&mut store, ctx, bus_open_remote), - "bus_close" => Function::new_native(&mut store, ctx, bus_close), - "bus_call" => Function::new_native(&mut store, ctx, bus_call), - "bus_subcall" => Function::new_native(&mut store, ctx, bus_subcall), - "bus_poll" => Function::new_native(&mut store, ctx, bus_poll), - "call_reply" => Function::new_native(&mut store, ctx, call_reply), - "call_fault" => Function::new_native(&mut store, ctx, call_fault), - "call_close" => Function::new_native(&mut store, ctx, call_close), - "ws_connect" => Function::new_native(&mut store, ctx, ws_connect), - "http_request" => Function::new_native(&mut store, ctx, http_request), - "http_status" => Function::new_native(&mut store, ctx, http_status), - "port_bridge" => Function::new_native(&mut store, ctx, port_bridge), - "port_unbridge" => Function::new_native(&mut store, ctx, port_unbridge), - "port_dhcp_acquire" => Function::new_native(&mut store, ctx, port_dhcp_acquire), - "port_addr_add" => Function::new_native(&mut store, ctx, port_addr_add), - "port_addr_remove" => Function::new_native(&mut store, ctx, port_addr_remove), - "port_addr_clear" => Function::new_native(&mut store, ctx, port_addr_clear), - "port_addr_list" => Function::new_native(&mut store, ctx, port_addr_list), - "port_mac" => Function::new_native(&mut store, ctx, port_mac), - "port_gateway_set" => Function::new_native(&mut store, ctx, port_gateway_set), - "port_route_add" => Function::new_native(&mut store, ctx, port_route_add), - "port_route_remove" => Function::new_native(&mut store, ctx, port_route_remove), - "port_route_clear" => Function::new_native(&mut store, ctx, port_route_clear), - "port_route_list" => Function::new_native(&mut store, ctx, port_route_list), - "sock_status" => Function::new_native(&mut store, ctx, sock_status), - "sock_addr_local" => Function::new_native(&mut store, ctx, sock_addr_local), - "sock_addr_peer" => Function::new_native(&mut store, ctx, sock_addr_peer), - "sock_open" => Function::new_native(&mut store, ctx, sock_open), - "sock_set_opt_flag" => Function::new_native(&mut store, ctx, sock_set_opt_flag), - "sock_get_opt_flag" => Function::new_native(&mut store, ctx, sock_get_opt_flag), - "sock_set_opt_time" => Function::new_native(&mut store, ctx, sock_set_opt_time), - "sock_get_opt_time" => Function::new_native(&mut store, ctx, sock_get_opt_time), - "sock_set_opt_size" => Function::new_native(&mut store, ctx, sock_set_opt_size), - "sock_get_opt_size" => Function::new_native(&mut store, ctx, sock_get_opt_size), - "sock_join_multicast_v4" => Function::new_native(&mut store, ctx, sock_join_multicast_v4), - "sock_leave_multicast_v4" => Function::new_native(&mut store, ctx, sock_leave_multicast_v4), - "sock_join_multicast_v6" => Function::new_native(&mut store, ctx, sock_join_multicast_v6), - "sock_leave_multicast_v6" => Function::new_native(&mut store, ctx, sock_leave_multicast_v6), - "sock_bind" => Function::new_native(&mut store, ctx, sock_bind), - "sock_listen" => Function::new_native(&mut store, ctx, sock_listen), - "sock_accept" => Function::new_native(&mut store, ctx, sock_accept), - "sock_connect" => Function::new_native(&mut store, ctx, sock_connect), - "sock_recv" => Function::new_native(&mut store, ctx, sock_recv), - "sock_recv_from" => Function::new_native(&mut store, ctx, sock_recv_from), - "sock_send" => Function::new_native(&mut store, ctx, sock_send), - "sock_send_to" => Function::new_native(&mut store, ctx, sock_send_to), - "sock_send_file" => Function::new_native(&mut store, ctx, sock_send_file), - "sock_shutdown" => Function::new_native(&mut store, ctx, sock_shutdown), - "resolve" => Function::new_native(&mut store, ctx, resolve), + "args_get" => Function::new_typed_with_env(&mut store, env, args_get), + "args_sizes_get" => Function::new_typed_with_env(&mut store, env, args_sizes_get), + "clock_res_get" => Function::new_typed_with_env(&mut store, env, clock_res_get), + "clock_time_get" => Function::new_typed_with_env(&mut store, env, clock_time_get), + "environ_get" => Function::new_typed_with_env(&mut store, env, environ_get), + "environ_sizes_get" => Function::new_typed_with_env(&mut store, env, environ_sizes_get), + "fd_advise" => Function::new_typed_with_env(&mut store, env, fd_advise), + "fd_allocate" => Function::new_typed_with_env(&mut store, env, fd_allocate), + "fd_close" => Function::new_typed_with_env(&mut store, env, fd_close), + "fd_datasync" => Function::new_typed_with_env(&mut store, env, fd_datasync), + "fd_fdstat_get" => Function::new_typed_with_env(&mut store, env, fd_fdstat_get), + "fd_fdstat_set_flags" => Function::new_typed_with_env(&mut store, env, fd_fdstat_set_flags), + "fd_fdstat_set_rights" => Function::new_typed_with_env(&mut store, env, fd_fdstat_set_rights), + "fd_filestat_get" => Function::new_typed_with_env(&mut store, env, fd_filestat_get), + "fd_filestat_set_size" => Function::new_typed_with_env(&mut store, env, fd_filestat_set_size), + "fd_filestat_set_times" => Function::new_typed_with_env(&mut store, env, fd_filestat_set_times), + "fd_pread" => Function::new_typed_with_env(&mut store, env, fd_pread), + "fd_prestat_get" => Function::new_typed_with_env(&mut store, env, fd_prestat_get), + "fd_prestat_dir_name" => Function::new_typed_with_env(&mut store, env, fd_prestat_dir_name), + "fd_pwrite" => Function::new_typed_with_env(&mut store, env, fd_pwrite), + "fd_read" => Function::new_typed_with_env(&mut store, env, fd_read), + "fd_readdir" => Function::new_typed_with_env(&mut store, env, fd_readdir), + "fd_renumber" => Function::new_typed_with_env(&mut store, env, fd_renumber), + "fd_dup" => Function::new_typed_with_env(&mut store, env, fd_dup), + "fd_event" => Function::new_typed_with_env(&mut store, env, fd_event), + "fd_seek" => Function::new_typed_with_env(&mut store, env, fd_seek), + "fd_sync" => Function::new_typed_with_env(&mut store, env, fd_sync), + "fd_tell" => Function::new_typed_with_env(&mut store, env, fd_tell), + "fd_write" => Function::new_typed_with_env(&mut store, env, fd_write), + "fd_pipe" => Function::new_typed_with_env(&mut store, env, fd_pipe), + "path_create_directory" => Function::new_typed_with_env(&mut store, env, path_create_directory), + "path_filestat_get" => Function::new_typed_with_env(&mut store, env, path_filestat_get), + "path_filestat_set_times" => Function::new_typed_with_env(&mut store, env, path_filestat_set_times), + "path_link" => Function::new_typed_with_env(&mut store, env, path_link), + "path_open" => Function::new_typed_with_env(&mut store, env, path_open), + "path_readlink" => Function::new_typed_with_env(&mut store, env, path_readlink), + "path_remove_directory" => Function::new_typed_with_env(&mut store, env, path_remove_directory), + "path_rename" => Function::new_typed_with_env(&mut store, env, path_rename), + "path_symlink" => Function::new_typed_with_env(&mut store, env, path_symlink), + "path_unlink_file" => Function::new_typed_with_env(&mut store, env, path_unlink_file), + "poll_oneoff" => Function::new_typed_with_env(&mut store, env, poll_oneoff), + "proc_exit" => Function::new_typed_with_env(&mut store, env, proc_exit), + "proc_raise" => Function::new_typed_with_env(&mut store, env, proc_raise), + "random_get" => Function::new_typed_with_env(&mut store, env, random_get), + "tty_get" => Function::new_typed_with_env(&mut store, env, tty_get), + "tty_set" => Function::new_typed_with_env(&mut store, env, tty_set), + "getcwd" => Function::new_typed_with_env(&mut store, env, getcwd), + "chdir" => Function::new_typed_with_env(&mut store, env, chdir), + "thread_spawn" => Function::new_typed_with_env(&mut store, env, thread_spawn), + "thread_sleep" => Function::new_typed_with_env(&mut store, env, thread_sleep), + "thread_id" => Function::new_typed_with_env(&mut store, env, thread_id), + "thread_join" => Function::new_typed_with_env(&mut store, env, thread_join), + "thread_parallelism" => Function::new_typed_with_env(&mut store, env, thread_parallelism), + "thread_exit" => Function::new_typed_with_env(&mut store, env, thread_exit), + "sched_yield" => Function::new_typed_with_env(&mut store, env, sched_yield), + "getpid" => Function::new_typed_with_env(&mut store, env, getpid), + "process_spawn" => Function::new_typed_with_env(&mut store, env, process_spawn), + "bus_open_local" => Function::new_typed_with_env(&mut store, env, bus_open_local), + "bus_open_remote" => Function::new_typed_with_env(&mut store, env, bus_open_remote), + "bus_close" => Function::new_typed_with_env(&mut store, env, bus_close), + "bus_call" => Function::new_typed_with_env(&mut store, env, bus_call), + "bus_subcall" => Function::new_typed_with_env(&mut store, env, bus_subcall), + "bus_poll" => Function::new_typed_with_env(&mut store, env, bus_poll), + "call_reply" => Function::new_typed_with_env(&mut store, env, call_reply), + "call_fault" => Function::new_typed_with_env(&mut store, env, call_fault), + "call_close" => Function::new_typed_with_env(&mut store, env, call_close), + "ws_connect" => Function::new_typed_with_env(&mut store, env, ws_connect), + "http_request" => Function::new_typed_with_env(&mut store, env, http_request), + "http_status" => Function::new_typed_with_env(&mut store, env, http_status), + "port_bridge" => Function::new_typed_with_env(&mut store, env, port_bridge), + "port_unbridge" => Function::new_typed_with_env(&mut store, env, port_unbridge), + "port_dhcp_acquire" => Function::new_typed_with_env(&mut store, env, port_dhcp_acquire), + "port_addr_add" => Function::new_typed_with_env(&mut store, env, port_addr_add), + "port_addr_remove" => Function::new_typed_with_env(&mut store, env, port_addr_remove), + "port_addr_clear" => Function::new_typed_with_env(&mut store, env, port_addr_clear), + "port_addr_list" => Function::new_typed_with_env(&mut store, env, port_addr_list), + "port_mac" => Function::new_typed_with_env(&mut store, env, port_mac), + "port_gateway_set" => Function::new_typed_with_env(&mut store, env, port_gateway_set), + "port_route_add" => Function::new_typed_with_env(&mut store, env, port_route_add), + "port_route_remove" => Function::new_typed_with_env(&mut store, env, port_route_remove), + "port_route_clear" => Function::new_typed_with_env(&mut store, env, port_route_clear), + "port_route_list" => Function::new_typed_with_env(&mut store, env, port_route_list), + "sock_status" => Function::new_typed_with_env(&mut store, env, sock_status), + "sock_addr_local" => Function::new_typed_with_env(&mut store, env, sock_addr_local), + "sock_addr_peer" => Function::new_typed_with_env(&mut store, env, sock_addr_peer), + "sock_open" => Function::new_typed_with_env(&mut store, env, sock_open), + "sock_set_opt_flag" => Function::new_typed_with_env(&mut store, env, sock_set_opt_flag), + "sock_get_opt_flag" => Function::new_typed_with_env(&mut store, env, sock_get_opt_flag), + "sock_set_opt_time" => Function::new_typed_with_env(&mut store, env, sock_set_opt_time), + "sock_get_opt_time" => Function::new_typed_with_env(&mut store, env, sock_get_opt_time), + "sock_set_opt_size" => Function::new_typed_with_env(&mut store, env, sock_set_opt_size), + "sock_get_opt_size" => Function::new_typed_with_env(&mut store, env, sock_get_opt_size), + "sock_join_multicast_v4" => Function::new_typed_with_env(&mut store, env, sock_join_multicast_v4), + "sock_leave_multicast_v4" => Function::new_typed_with_env(&mut store, env, sock_leave_multicast_v4), + "sock_join_multicast_v6" => Function::new_typed_with_env(&mut store, env, sock_join_multicast_v6), + "sock_leave_multicast_v6" => Function::new_typed_with_env(&mut store, env, sock_leave_multicast_v6), + "sock_bind" => Function::new_typed_with_env(&mut store, env, sock_bind), + "sock_listen" => Function::new_typed_with_env(&mut store, env, sock_listen), + "sock_accept" => Function::new_typed_with_env(&mut store, env, sock_accept), + "sock_connect" => Function::new_typed_with_env(&mut store, env, sock_connect), + "sock_recv" => Function::new_typed_with_env(&mut store, env, sock_recv), + "sock_recv_from" => Function::new_typed_with_env(&mut store, env, sock_recv_from), + "sock_send" => Function::new_typed_with_env(&mut store, env, sock_send), + "sock_send_to" => Function::new_typed_with_env(&mut store, env, sock_send_to), + "sock_send_file" => Function::new_typed_with_env(&mut store, env, sock_send_file), + "sock_shutdown" => Function::new_typed_with_env(&mut store, env, sock_shutdown), + "resolve" => Function::new_typed_with_env(&mut store, env, resolve), } } } diff --git a/tests/compilers/imports.rs b/tests/compilers/imports.rs index 558e4fa51..fafcaa6f1 100644 --- a/tests/compilers/imports.rs +++ b/tests/compilers/imports.rs @@ -49,26 +49,25 @@ fn get_module(store: &Store) -> Result { fn dynamic_function(config: crate::Config) -> Result<()> { let mut store = config.store(); let module = get_module(&store)?; - let mut env = FunctionEnv::new(&mut store, ()); static HITS: AtomicUsize = AtomicUsize::new(0); let imports = imports! { "host" => { - "0" => Function::new(&mut store, &env, FunctionType::new(vec![], vec![]), |_ctx, _values| { + "0" => Function::new(&mut store, FunctionType::new(vec![], vec![]), |_env, _values| { assert_eq!(HITS.fetch_add(1, SeqCst), 0); Ok(vec![]) }), - "1" => Function::new(&mut store, &env, FunctionType::new(vec![ValueType::I32], vec![ValueType::I32]), |_ctx, values| { + "1" => Function::new(&mut store, FunctionType::new(vec![ValueType::I32], vec![ValueType::I32]), |_env, values| { assert_eq!(values[0], Value::I32(0)); assert_eq!(HITS.fetch_add(1, SeqCst), 1); Ok(vec![Value::I32(1)]) }), - "2" => Function::new(&mut store, &env, FunctionType::new(vec![ValueType::I32, ValueType::I64], vec![]), |_ctx, values| { + "2" => Function::new(&mut store, FunctionType::new(vec![ValueType::I32, ValueType::I64], vec![]), |_env, values| { assert_eq!(values[0], Value::I32(2)); assert_eq!(values[1], Value::I64(3)); assert_eq!(HITS.fetch_add(1, SeqCst), 2); Ok(vec![]) }), - "3" => Function::new(&mut store, &env, FunctionType::new(vec![ValueType::I32, ValueType::I64, ValueType::I32, ValueType::F32, ValueType::F64], vec![]), |_ctx, values| { + "3" => Function::new(&mut store, FunctionType::new(vec![ValueType::I32, ValueType::I64, ValueType::I32, ValueType::F32, ValueType::F64], vec![]), |_env, values| { assert_eq!(values[0], Value::I32(100)); assert_eq!(values[1], Value::I64(200)); assert_eq!(values[2], Value::I32(300)); @@ -105,37 +104,37 @@ fn dynamic_function_with_env(config: crate::Config) -> Result<()> { counter: Arc::new(AtomicUsize::new(0)), }; let mut env = FunctionEnv::new(&mut store, env); - let f0 = Function::new( + let f0 = Function::new_with_env( &mut store, &env, FunctionType::new(vec![], vec![]), - |ctx, _values| { - assert_eq!(ctx.data().fetch_add(1, SeqCst), 0); + |env, _values| { + assert_eq!(env.data().fetch_add(1, SeqCst), 0); Ok(vec![]) }, ); - let f1 = Function::new( + let f1 = Function::new_with_env( &mut store, &env, FunctionType::new(vec![ValueType::I32], vec![ValueType::I32]), - |ctx, values| { + |env, values| { assert_eq!(values[0], Value::I32(0)); - assert_eq!(ctx.data().fetch_add(1, SeqCst), 1); + assert_eq!(env.data().fetch_add(1, SeqCst), 1); Ok(vec![Value::I32(1)]) }, ); - let f2 = Function::new( + let f2 = Function::new_with_env( &mut store, &env, FunctionType::new(vec![ValueType::I32, ValueType::I64], vec![]), - |ctx, values| { + |env, values| { assert_eq!(values[0], Value::I32(2)); assert_eq!(values[1], Value::I64(3)); - assert_eq!(ctx.data().fetch_add(1, SeqCst), 2); + assert_eq!(env.data().fetch_add(1, SeqCst), 2); Ok(vec![]) }, ); - let f3 = Function::new( + let f3 = Function::new_with_env( &mut store, &env, FunctionType::new( @@ -148,13 +147,13 @@ fn dynamic_function_with_env(config: crate::Config) -> Result<()> { ], vec![], ), - |ctx, values| { + |env, values| { assert_eq!(values[0], Value::I32(100)); assert_eq!(values[1], Value::I64(200)); assert_eq!(values[2], Value::I32(300)); assert_eq!(values[3], Value::F32(400.0)); assert_eq!(values[4], Value::F64(500.0)); - assert_eq!(ctx.data().fetch_add(1, SeqCst), 3); + assert_eq!(env.data().fetch_add(1, SeqCst), 3); Ok(vec![]) }, ); @@ -181,28 +180,22 @@ fn static_function(config: crate::Config) -> Result<()> { let module = get_module(&store)?; static HITS: AtomicUsize = AtomicUsize::new(0); - let mut env = FunctionEnv::new(&mut store, ()); - let f0 = Function::new_native(&mut store, &env, |_ctx: FunctionEnvMut<_>| { + let f0 = Function::new_typed(&mut store, |_env: FunctionEnvMut<_>| { assert_eq!(HITS.fetch_add(1, SeqCst), 0); }); - let f1 = Function::new_native(&mut store, &env, |_ctx: FunctionEnvMut<_>, x: i32| -> i32 { + let f1 = Function::new_typed(&mut store, |_env: FunctionEnvMut<_>, x: i32| -> i32 { assert_eq!(x, 0); assert_eq!(HITS.fetch_add(1, SeqCst), 1); 1 }); - let f2 = Function::new_native( + let f2 = Function::new_typed(&mut store, |_env: FunctionEnvMut<_>, x: i32, y: i64| { + assert_eq!(x, 2); + assert_eq!(y, 3); + assert_eq!(HITS.fetch_add(1, SeqCst), 2); + }); + let f3 = Function::new_typed( &mut store, - &env, - |_ctx: FunctionEnvMut<_>, x: i32, y: i64| { - assert_eq!(x, 2); - assert_eq!(y, 3); - assert_eq!(HITS.fetch_add(1, SeqCst), 2); - }, - ); - let f3 = Function::new_native( - &mut store, - &env, - |_ctx: FunctionEnvMut<_>, a: i32, b: i64, c: i32, d: f32, e: f64| { + |_env: FunctionEnvMut<_>, a: i32, b: i64, c: i32, d: f32, e: f64| { assert_eq!(a, 100); assert_eq!(b, 200); assert_eq!(c, 300); @@ -234,32 +227,25 @@ fn static_function_with_results(config: crate::Config) -> Result<()> { let module = get_module(&store)?; static HITS: AtomicUsize = AtomicUsize::new(0); - let mut env = FunctionEnv::new(&mut store, ()); - let f0 = Function::new_native(&mut store, &env, |_ctx: FunctionEnvMut<_>| { + let f0 = Function::new_typed(&mut store, |_env: FunctionEnvMut<_>| { assert_eq!(HITS.fetch_add(1, SeqCst), 0); }); - let f1 = Function::new_native( + let f1 = Function::new_typed( &mut store, - &env, - |_ctx: FunctionEnvMut<_>, x: i32| -> Result { + |_env: FunctionEnvMut<_>, x: i32| -> Result { assert_eq!(x, 0); assert_eq!(HITS.fetch_add(1, SeqCst), 1); Ok(1) }, ); - let f2 = Function::new_native( + let f2 = Function::new_typed(&mut store, |_env: FunctionEnvMut<_>, x: i32, y: i64| { + assert_eq!(x, 2); + assert_eq!(y, 3); + assert_eq!(HITS.fetch_add(1, SeqCst), 2); + }); + let f3 = Function::new_typed( &mut store, - &env, - |_ctx: FunctionEnvMut<_>, x: i32, y: i64| { - assert_eq!(x, 2); - assert_eq!(y, 3); - assert_eq!(HITS.fetch_add(1, SeqCst), 2); - }, - ); - let f3 = Function::new_native( - &mut store, - &env, - |_ctx: FunctionEnvMut<_>, a: i32, b: i64, c: i32, d: f32, e: f64| { + |_env: FunctionEnvMut<_>, a: i32, b: i64, c: i32, d: f32, e: f64| { assert_eq!(a, 100); assert_eq!(b, 200); assert_eq!(c, 300); @@ -301,37 +287,37 @@ fn static_function_with_env(config: crate::Config) -> Result<()> { let env: Env = Env(Arc::new(AtomicUsize::new(0))); let mut env = FunctionEnv::new(&mut store, env); - let f0 = Function::new_native(&mut store, &env, |ctx: FunctionEnvMut| { - assert_eq!(ctx.data().fetch_add(1, SeqCst), 0); + let f0 = Function::new_typed_with_env(&mut store, &env, |env: FunctionEnvMut| { + assert_eq!(env.data().fetch_add(1, SeqCst), 0); }); - let f1 = Function::new_native( + let f1 = Function::new_typed_with_env( &mut store, &env, - |ctx: FunctionEnvMut, x: i32| -> i32 { + |env: FunctionEnvMut, x: i32| -> i32 { assert_eq!(x, 0); - assert_eq!(ctx.data().fetch_add(1, SeqCst), 1); + assert_eq!(env.data().fetch_add(1, SeqCst), 1); 1 }, ); - let f2 = Function::new_native( + let f2 = Function::new_typed_with_env( &mut store, &env, - |ctx: FunctionEnvMut, x: i32, y: i64| { + |env: FunctionEnvMut, x: i32, y: i64| { assert_eq!(x, 2); assert_eq!(y, 3); - assert_eq!(ctx.data().fetch_add(1, SeqCst), 2); + assert_eq!(env.data().fetch_add(1, SeqCst), 2); }, ); - let f3 = Function::new_native( + let f3 = Function::new_typed_with_env( &mut store, &env, - |ctx: FunctionEnvMut, a: i32, b: i64, c: i32, d: f32, e: f64| { + |env: FunctionEnvMut, a: i32, b: i64, c: i32, d: f32, e: f64| { assert_eq!(a, 100); assert_eq!(b, 200); assert_eq!(c, 300); assert_eq!(d, 400.0); assert_eq!(e, 500.0); - assert_eq!(ctx.data().fetch_add(1, SeqCst), 3); + assert_eq!(env.data().fetch_add(1, SeqCst), 3); }, ); Instance::new( @@ -364,10 +350,10 @@ fn static_function_that_fails(config: crate::Config) -> Result<()> { let module = Module::new(&store, &wat)?; let mut env = FunctionEnv::new(&mut store, ()); - let f0 = Function::new_native( + let f0 = Function::new_typed_with_env( &mut store, &env, - |_ctx: FunctionEnvMut<_>| -> Result { + |_env: FunctionEnvMut<_>| -> Result { Err(RuntimeError::new("oops")) }, ); @@ -420,12 +406,12 @@ fn dynamic_function_with_env_wasmer_env_init_works(config: crate::Config) -> Res let env: Env = Env { memory: None }; let mut env = FunctionEnv::new(&mut store, env); - let f0 = Function::new( + let f0 = Function::new_with_env( &mut store, &env, FunctionType::new(vec![], vec![]), - |ctx, _values| { - assert!(ctx.data().memory.as_ref().is_some()); + |env, _values| { + assert!(env.data().memory.as_ref().is_some()); Ok(vec![]) }, ); @@ -466,13 +452,13 @@ fn multi_use_host_fn_manages_memory_correctly(config: crate::Config) -> Result<( let env: Env = Env { memory: None }; let mut env = FunctionEnv::new(&mut store, env); - fn host_fn(ctx: FunctionEnvMut) { - assert!(ctx.data().memory.is_some()); + fn host_fn(env: FunctionEnvMut) { + assert!(env.data().memory.is_some()); println!("Hello, world!"); } let imports = imports! { "host" => { - "fn" => Function::new_native(&mut store, &env, host_fn), + "fn" => Function::new_typed_with_env(&mut store, &env, host_fn), }, }; let instance1 = Instance::new(&mut store, &module, &imports)?; diff --git a/tests/compilers/issues.rs b/tests/compilers/issues.rs index 6fed2c724..e8d5dfb56 100644 --- a/tests/compilers/issues.rs +++ b/tests/compilers/issues.rs @@ -64,7 +64,7 @@ fn issue_2329(mut config: crate::Config) -> Result<()> { let mut env = FunctionEnv::new(&mut store, env); let imports: Imports = imports! { "env" => { - "__read_memory" => Function::new_native( + "__read_memory" => Function::new_typed_with_env( &mut store, &env, read_memory @@ -197,14 +197,23 @@ fn call_with_static_data_pointers(mut config: crate::Config) -> Result<()> { env.as_mut(&mut store).memory = Some(memory.clone()); let mut exports = Exports::new(); exports.insert("memory", memory); - exports.insert("banana", Function::new_native(&mut store, &env, banana)); - exports.insert("peach", Function::new_native(&mut store, &env, peach)); + exports.insert( + "banana", + Function::new_typed_with_env(&mut store, &env, banana), + ); + exports.insert( + "peach", + Function::new_typed_with_env(&mut store, &env, peach), + ); exports.insert( "chaenomeles", - Function::new_native(&mut store, &env, chaenomeles), + Function::new_typed_with_env(&mut store, &env, chaenomeles), ); - exports.insert("mango", Function::new_native(&mut store, &env, mango)); - exports.insert("gas", Function::new_native(&mut store, &env, gas)); + exports.insert( + "mango", + Function::new_typed_with_env(&mut store, &env, mango), + ); + exports.insert("gas", Function::new_typed_with_env(&mut store, &env, gas)); let mut imports = Imports::new(); imports.register_namespace("env", exports); let instance = Instance::new(&mut store, &module, &imports)?; diff --git a/tests/compilers/main.rs b/tests/compilers/main.rs index 67606398e..541032c65 100644 --- a/tests/compilers/main.rs +++ b/tests/compilers/main.rs @@ -12,9 +12,9 @@ mod issues; mod metering; mod middlewares; // mod multi_value_imports; -mod native_functions; mod serialize; mod traps; +mod typed_functions; mod wasi; mod wast; diff --git a/tests/compilers/serialize.rs b/tests/compilers/serialize.rs index 1b796bf58..23b62716e 100644 --- a/tests/compilers/serialize.rs +++ b/tests/compilers/serialize.rs @@ -1,5 +1,4 @@ use anyhow::Result; -use wasmer::FunctionEnv; use wasmer::*; #[compiler_test(serialize)] @@ -54,8 +53,7 @@ fn test_deserialize(config: crate::Config) -> Result<()> { vec![Type::I32, Type::I64, Type::I32, Type::F32, Type::F64], vec![Type::I64], ); - let mut env = FunctionEnv::new(&mut store, ()); - let f0 = Function::new(&mut store, &env, &func_type, |_ctx, params| { + let f0 = Function::new(&mut store, &func_type, |_ctx, params| { let param_0: i64 = params[0].unwrap_i32() as i64; let param_1: i64 = params[1].unwrap_i64() as i64; let param_2: i64 = params[2].unwrap_i32() as i64; diff --git a/tests/compilers/traps.rs b/tests/compilers/traps.rs index fff22c69e..ace95080e 100644 --- a/tests/compilers/traps.rs +++ b/tests/compilers/traps.rs @@ -1,6 +1,5 @@ use anyhow::Result; use std::panic::{self, AssertUnwindSafe}; -use wasmer::FunctionEnv; use wasmer::*; #[compiler_test(traps)] @@ -14,9 +13,8 @@ fn test_trap_return(config: crate::Config) -> Result<()> { "#; let module = Module::new(&store, wat)?; - let mut env = FunctionEnv::new(&mut store, ()); let hello_type = FunctionType::new(vec![], vec![]); - let hello_func = Function::new(&mut store, &env, &hello_type, |_ctx, _| { + let hello_func = Function::new(&mut store, &hello_type, |_ctx, _| { Err(RuntimeError::new("test 123")) }); @@ -55,7 +53,6 @@ fn test_trap_trace(config: crate::Config) -> Result<()> { ) "#; - let mut env = FunctionEnv::new(&mut store, ()); let module = Module::new(&store, wat)?; let instance = Instance::new(&mut store, &module, &imports! {})?; let run_func = instance @@ -96,9 +93,8 @@ fn test_trap_trace_cb(config: crate::Config) -> Result<()> { ) "#; - let mut env = FunctionEnv::new(&mut store, ()); let fn_type = FunctionType::new(vec![], vec![]); - let fn_func = Function::new(&mut store, &env, &fn_type, |_ctx, _| { + let fn_func = Function::new(&mut store, &fn_type, |_ctx, _| { Err(RuntimeError::new("cb throw")) }); @@ -146,7 +142,6 @@ fn test_trap_stack_overflow(config: crate::Config) -> Result<()> { "#; let module = Module::new(&store, wat)?; - let mut env = FunctionEnv::new(&mut store, ()); let instance = Instance::new(&mut store, &module, &imports! {})?; let run_func = instance .exports @@ -180,7 +175,6 @@ fn trap_display_pretty(config: crate::Config) -> Result<()> { "#; let module = Module::new(&store, wat)?; - let mut env = FunctionEnv::new(&mut store, ()); let instance = Instance::new(&mut store, &module, &imports! {})?; let run_func = instance .exports @@ -217,7 +211,6 @@ fn trap_display_multi_module(config: crate::Config) -> Result<()> { "#; let module = Module::new(&store, wat)?; - let mut env = FunctionEnv::new(&mut store, ()); let instance = Instance::new(&mut store, &module, &imports! {})?; let bar = instance.exports.get_function("bar")?.clone(); @@ -272,9 +265,8 @@ fn trap_start_function_import(config: crate::Config) -> Result<()> { "#; let module = Module::new(&store, &binary)?; - let mut env = FunctionEnv::new(&mut store, ()); let sig = FunctionType::new(vec![], vec![]); - let func = Function::new(&mut store, &env, &sig, |_ctx, _| { + let func = Function::new(&mut store, &sig, |_env, _| { Err(RuntimeError::new("user trap")) }); let err = Instance::new( @@ -315,10 +307,9 @@ fn rust_panic_import(config: crate::Config) -> Result<()> { "#; let module = Module::new(&store, &binary)?; - let mut env = FunctionEnv::new(&mut store, ()); let sig = FunctionType::new(vec![], vec![]); - let func = Function::new(&mut store, &env, &sig, |_ctx, _| panic!("this is a panic")); - let f0 = Function::new_native(&mut store, &env, |_ctx: FunctionEnvMut<_>| { + let func = Function::new(&mut store, &sig, |_env, _| panic!("this is a panic")); + let f0 = Function::new_typed(&mut store, |_env: FunctionEnvMut<_>| { panic!("this is another panic") }); let instance = Instance::new( @@ -363,9 +354,8 @@ fn rust_panic_start_function(config: crate::Config) -> Result<()> { "#; let module = Module::new(&store, &binary)?; - let mut env = FunctionEnv::new(&mut store, ()); let sig = FunctionType::new(vec![], vec![]); - let func = Function::new(&mut store, &env, &sig, |_ctx, _| panic!("this is a panic")); + let func = Function::new(&mut store, &sig, |_env, _| panic!("this is a panic")); let err = panic::catch_unwind(AssertUnwindSafe(|| { drop(Instance::new( &mut store, @@ -380,7 +370,7 @@ fn rust_panic_start_function(config: crate::Config) -> Result<()> { .unwrap_err(); assert_eq!(err.downcast_ref::<&'static str>(), Some(&"this is a panic")); - let func = Function::new_native(&mut store, &env, |_ctx: FunctionEnvMut<_>| { + let func = Function::new_typed(&mut store, |_env: FunctionEnvMut<_>| { panic!("this is another panic") }); let err = panic::catch_unwind(AssertUnwindSafe(|| { @@ -412,7 +402,6 @@ fn mismatched_arguments(config: crate::Config) -> Result<()> { "#; let module = Module::new(&store, &binary)?; - let mut env = FunctionEnv::new(&mut store, ()); let instance = Instance::new(&mut store, &module, &imports! {})?; let func: &Function = instance.exports.get("foo")?; assert_eq!( @@ -452,7 +441,6 @@ fn call_signature_mismatch(config: crate::Config) -> Result<()> { "#; let module = Module::new(&store, &binary)?; - let mut env = FunctionEnv::new(&mut store, ()); let err = Instance::new(&mut store, &module, &imports! {}) .err() .expect("expected error"); @@ -481,7 +469,6 @@ fn start_trap_pretty(config: crate::Config) -> Result<()> { "#; let module = Module::new(&store, wat)?; - let mut env = FunctionEnv::new(&mut store, ()); let err = Instance::new(&mut store, &module, &imports! {}) .err() .expect("expected error"); @@ -503,7 +490,6 @@ RuntimeError: unreachable fn present_after_module_drop(config: crate::Config) -> Result<()> { let mut store = config.store(); let module = Module::new(&store, r#"(func (export "foo") unreachable)"#)?; - let mut env = FunctionEnv::new(&mut store, ()); let instance = Instance::new(&mut store, &module, &imports! {})?; let func: Function = instance.exports.get_function("foo")?.clone(); diff --git a/tests/compilers/native_functions.rs b/tests/compilers/typed_functions.rs similarity index 72% rename from tests/compilers/native_functions.rs rename to tests/compilers/typed_functions.rs index 3f6ecac79..a1a8068f1 100644 --- a/tests/compilers/native_functions.rs +++ b/tests/compilers/typed_functions.rs @@ -7,7 +7,7 @@ use wasmer::Type as ValueType; use wasmer::*; fn long_f( - _ctx: FunctionEnvMut<()>, + _env: FunctionEnvMut<()>, a: u32, b: u32, c: u32, @@ -31,7 +31,7 @@ fn long_f( + a as u64 * 1000000000 } -fn long_f_dynamic(_ctx: FunctionEnvMut<()>, values: &[Value]) -> Result, RuntimeError> { +fn long_f_dynamic(_env: FunctionEnvMut<()>, values: &[Value]) -> Result, RuntimeError> { Ok(vec![Value::I64( values[9].unwrap_i32() as i64 + values[8].unwrap_i32() as i64 * 10 @@ -46,8 +46,8 @@ fn long_f_dynamic(_ctx: FunctionEnvMut<()>, values: &[Value]) -> Result anyhow::Result<()> { +#[compiler_test(typed_functions)] +fn typed_function_works_for_wasm(config: crate::Config) -> anyhow::Result<()> { let mut store = config.store(); let wat = r#"(module (func $multiply (import "env" "multiply") (param i32 i32) (result i32)) @@ -63,7 +63,7 @@ fn native_function_works_for_wasm(config: crate::Config) -> anyhow::Result<()> { let import_object = imports! { "env" => { - "multiply" => Function::new_native(&mut store, &env, |_ctx: FunctionEnvMut<_>, a: i32, b: i32| a * b), + "multiply" => Function::new_typed_with_env(&mut store, &env, |_env: FunctionEnvMut<_>, a: i32, b: i32| a * b), }, }; let instance = Instance::new(&mut store, &module, &import_object)?; @@ -83,7 +83,7 @@ fn native_function_works_for_wasm(config: crate::Config) -> anyhow::Result<()> { { let dyn_f: &Function = instance.exports.get("double_then_add")?; - let f: TypedFunction<(i32, i32), i32> = dyn_f.native(&mut store).unwrap(); + let f: TypedFunction<(i32, i32), i32> = dyn_f.typed(&mut store).unwrap(); let result = f.call(&mut store, 4, 6)?; assert_eq!(result, 20); } @@ -91,33 +91,32 @@ fn native_function_works_for_wasm(config: crate::Config) -> anyhow::Result<()> { Ok(()) } -#[compiler_test(native_functions)] -fn native_host_function_closure_panics(config: crate::Config) { +#[compiler_test(typed_functions)] +fn typed_host_function_closure_panics(config: crate::Config) { let mut store = config.store(); - let mut env = FunctionEnv::new(&mut store, ()); let state = 3; - Function::new_native(&mut store, &env, move |_ctx: FunctionEnvMut<_>, _: i32| { + Function::new_typed(&mut store, move |_env: FunctionEnvMut<_>, _: i32| { println!("{}", state); }); } -#[compiler_test(native_functions)] -fn native_with_env_host_function_closure_panics(config: crate::Config) { +#[compiler_test(typed_functions)] +fn typed_with_env_host_function_closure_panics(config: crate::Config) { let mut store = config.store(); let env: i32 = 4; let mut env = FunctionEnv::new(&mut store, env); let state = 3; - Function::new_native( + Function::new_typed_with_env( &mut store, &env, - move |_ctx: FunctionEnvMut, _: i32| { + move |_env: FunctionEnvMut, _: i32| { println!("{}", state); }, ); } -#[compiler_test(native_functions)] -fn non_native_functions_and_closures_with_no_env_work(config: crate::Config) -> anyhow::Result<()> { +#[compiler_test(typed_functions)] +fn non_typed_functions_and_closures_with_no_env_work(config: crate::Config) -> anyhow::Result<()> { let mut store = config.store(); let wat = r#"(module (func $multiply1 (import "env" "multiply1") (param i32 i32) (result i32)) @@ -143,24 +142,24 @@ fn non_native_functions_and_closures_with_no_env_work(config: crate::Config) -> let captured_by_closure = 20; let import_object = imports! { "env" => { - "multiply1" => Function::new(&mut store, &env, &ty, move |_ctx, args| { + "multiply1" => Function::new_with_env(&mut store, &env, &ty, move |_env, args| { if let (Value::I32(v1), Value::I32(v2)) = (&args[0], &args[1]) { Ok(vec![Value::I32(v1 * v2 * captured_by_closure)]) } else { panic!("Invalid arguments"); } }), - "multiply2" => Function::new(&mut store, &env, &ty, move |ctx, args| { + "multiply2" => Function::new_with_env(&mut store, &env, &ty, move |env, args| { if let (Value::I32(v1), Value::I32(v2)) = (&args[0], &args[1]) { - Ok(vec![Value::I32(v1 * v2 * captured_by_closure * ctx.data())]) + Ok(vec![Value::I32(v1 * v2 * captured_by_closure * env.data())]) } else { panic!("Invalid arguments"); } }), - "multiply3" => Function::new_native(&mut store, &env, |_ctx: FunctionEnvMut<_>, arg1: i32, arg2: i32| -> i32 + "multiply3" => Function::new_typed_with_env(&mut store, &env, |_env: FunctionEnvMut<_>, arg1: i32, arg2: i32| -> i32 {arg1 * arg2 }), - "multiply4" => Function::new_native(&mut store, &env, |ctx: FunctionEnvMut, arg1: i32, arg2: i32| -> i32 - {arg1 * arg2 * ctx.data() }), + "multiply4" => Function::new_typed_with_env(&mut store, &env, |env: FunctionEnvMut, arg1: i32, arg2: i32| -> i32 + {arg1 * arg2 * env.data() }), }, }; @@ -175,8 +174,8 @@ fn non_native_functions_and_closures_with_no_env_work(config: crate::Config) -> Ok(()) } -#[compiler_test(native_functions)] -fn native_function_works_for_wasm_function_manyparams(config: crate::Config) -> anyhow::Result<()> { +#[compiler_test(typed_functions)] +fn typed_function_works_for_wasm_function_manyparams(config: crate::Config) -> anyhow::Result<()> { let mut store = config.store(); let wat = r#"(module (func $longf (import "env" "longf") (param i32 i32 i32 i32 i32 i32 i64 i64 i32 i32) (result i64)) @@ -186,10 +185,9 @@ fn native_function_works_for_wasm_function_manyparams(config: crate::Config) -> (call $longf (i32.const 1) (i32.const 2) (i32.const 3) (i32.const 4) (i32.const 5) (i32.const 6) (i64.const 7) (i64.const 8) (i32.const 9) (i32.const 0))) )"#; let module = Module::new(&store, wat).unwrap(); - let mut env = FunctionEnv::new(&mut store, ()); let import_object = imports! { "env" => { - "longf" => Function::new_native(&mut store, &env, long_f), + "longf" => Function::new_typed(&mut store, long_f), }, }; @@ -197,7 +195,7 @@ fn native_function_works_for_wasm_function_manyparams(config: crate::Config) -> { let dyn_f: &Function = instance.exports.get("longf")?; - let f: TypedFunction<(), i64> = dyn_f.native(&mut store).unwrap(); + let f: TypedFunction<(), i64> = dyn_f.typed(&mut store).unwrap(); let result = f.call(&mut store)?; assert_eq!(result, 1234567890); } @@ -205,7 +203,7 @@ fn native_function_works_for_wasm_function_manyparams(config: crate::Config) -> { let dyn_f: &Function = instance.exports.get("longf_pure")?; let f: TypedFunction<(u32, u32, u32, u32, u32, u16, u64, u64, u16, u32), i64> = - dyn_f.native(&mut store).unwrap(); + dyn_f.typed(&mut store).unwrap(); let result = f.call(&mut store, 1, 2, 3, 4, 5, 6, 7, 8, 9, 0)?; assert_eq!(result, 1234567890); } @@ -213,12 +211,11 @@ fn native_function_works_for_wasm_function_manyparams(config: crate::Config) -> Ok(()) } -#[compiler_test(native_functions)] -fn native_function_works_for_wasm_function_manyparams_dynamic( +#[compiler_test(typed_functions)] +fn typed_function_works_for_wasm_function_manyparams_dynamic( config: crate::Config, ) -> anyhow::Result<()> { let mut store = config.store(); - let mut env = FunctionEnv::new(&mut store, ()); let wat = r#"(module (func $longf (import "env" "longf") (param i32 i32 i32 i32 i32 i32 i64 i64 i32 i32) (result i64)) (func (export "longf_pure") (param i32 i32 i32 i32 i32 i32 i64 i64 i32 i32) (result i64) @@ -230,7 +227,7 @@ fn native_function_works_for_wasm_function_manyparams_dynamic( let import_object = imports! { "env" => { - "longf" => Function::new(&mut store, &env, FunctionType::new(vec![ValueType::I32, ValueType::I32, ValueType::I32, ValueType::I32, ValueType::I32, ValueType::I32, ValueType::I64 , ValueType::I64 ,ValueType::I32, ValueType::I32], vec![ValueType::I64]), long_f_dynamic), + "longf" => Function::new(&mut store, FunctionType::new(vec![ValueType::I32, ValueType::I32, ValueType::I32, ValueType::I32, ValueType::I32, ValueType::I32, ValueType::I64 , ValueType::I64 ,ValueType::I32, ValueType::I32], vec![ValueType::I64]), long_f_dynamic), }, }; @@ -238,7 +235,7 @@ fn native_function_works_for_wasm_function_manyparams_dynamic( { let dyn_f: &Function = instance.exports.get("longf")?; - let f: TypedFunction<(), i64> = dyn_f.native(&mut store).unwrap(); + let f: TypedFunction<(), i64> = dyn_f.typed(&mut store).unwrap(); let result = f.call(&mut store)?; assert_eq!(result, 1234567890); } @@ -246,7 +243,7 @@ fn native_function_works_for_wasm_function_manyparams_dynamic( { let dyn_f: &Function = instance.exports.get("longf_pure")?; let f: TypedFunction<(u32, u32, u32, u32, u32, u16, u64, u64, u16, u32), i64> = - dyn_f.native(&mut store).unwrap(); + dyn_f.typed(&mut store).unwrap(); let result = f.call(&mut store, 1, 2, 3, 4, 5, 6, 7, 8, 9, 0)?; assert_eq!(result, 1234567890); } @@ -254,17 +251,16 @@ fn native_function_works_for_wasm_function_manyparams_dynamic( Ok(()) } -#[compiler_test(native_functions)] +#[compiler_test(typed_functions)] fn static_host_function_without_env(config: crate::Config) -> anyhow::Result<()> { let mut store = config.store(); - let mut env = FunctionEnv::new(&mut store, ()); - fn f(_ctx: FunctionEnvMut<()>, a: i32, b: i64, c: f32, d: f64) -> (f64, f32, i64, i32) { + fn f(_env: FunctionEnvMut<()>, a: i32, b: i64, c: f32, d: f64) -> (f64, f32, i64, i32) { (d * 4.0, c * 3.0, b * 2, a * 1) } fn f_ok( - _ctx: FunctionEnvMut<()>, + _env: FunctionEnvMut<()>, a: i32, b: i64, c: f32, @@ -274,7 +270,7 @@ fn static_host_function_without_env(config: crate::Config) -> anyhow::Result<()> } fn long_f( - _ctx: FunctionEnvMut<()>, + _env: FunctionEnvMut<()>, a: u32, b: u32, c: u32, @@ -295,42 +291,42 @@ fn static_host_function_without_env(config: crate::Config) -> anyhow::Result<()> // Native static host function that returns a tuple. { - let f = Function::new_native(&mut store, &env, f); - let f_native: TypedFunction<(i32, i64, f32, f64), (f64, f32, i64, i32)> = - f.native(&mut store).unwrap(); - let result = f_native.call(&mut store, 1, 3, 5.0, 7.0)?; + let f = Function::new_typed(&mut store, f); + let f_typed: TypedFunction<(i32, i64, f32, f64), (f64, f32, i64, i32)> = + f.typed(&mut store).unwrap(); + let result = f_typed.call(&mut store, 1, 3, 5.0, 7.0)?; assert_eq!(result, (28.0, 15.0, 6, 1)); } // Native static host function that returns a tuple. { - let long_f = Function::new_native(&mut store, &env, long_f); - let long_f_native: TypedFunction< + let long_f = Function::new_typed(&mut store, long_f); + let long_f_typed: TypedFunction< (u32, u32, u32, u32, u32, u16, u64, u64, u16, u32), (u32, u64, u32), - > = long_f.native(&mut store).unwrap(); - let result = long_f_native.call(&mut store, 1, 2, 3, 4, 5, 6, 7, 8, 9, 0)?; + > = long_f.typed(&mut store).unwrap(); + let result = long_f_typed.call(&mut store, 1, 2, 3, 4, 5, 6, 7, 8, 9, 0)?; assert_eq!(result, (654321, 87, 09)); } // Native static host function that returns a result of a tuple. { - let f = Function::new_native(&mut store, &env, f_ok); - let f_native: TypedFunction<(i32, i64, f32, f64), (f64, f32, i64, i32)> = - f.native(&mut store).unwrap(); - let result = f_native.call(&mut store, 1, 3, 5.0, 7.0)?; + let f = Function::new_typed(&mut store, f_ok); + let f_typed: TypedFunction<(i32, i64, f32, f64), (f64, f32, i64, i32)> = + f.typed(&mut store).unwrap(); + let result = f_typed.call(&mut store, 1, 3, 5.0, 7.0)?; assert_eq!(result, (28.0, 15.0, 6, 1)); } Ok(()) } -#[compiler_test(native_functions)] +#[compiler_test(typed_functions)] fn static_host_function_with_env(config: crate::Config) -> anyhow::Result<()> { let mut store = config.store(); - fn f(mut ctx: FunctionEnvMut, a: i32, b: i64, c: f32, d: f64) -> (f64, f32, i64, i32) { - let mut guard = ctx.data_mut().0.lock().unwrap(); + fn f(mut env: FunctionEnvMut, a: i32, b: i64, c: f32, d: f64) -> (f64, f32, i64, i32) { + let mut guard = env.data_mut().0.lock().unwrap(); assert_eq!(*guard, 100); *guard = 101; @@ -338,13 +334,13 @@ fn static_host_function_with_env(config: crate::Config) -> anyhow::Result<()> { } fn f_ok( - mut ctx: FunctionEnvMut, + mut env: FunctionEnvMut, a: i32, b: i64, c: f32, d: f64, ) -> Result<(f64, f32, i64, i32), Infallible> { - let mut guard = ctx.data_mut().0.lock().unwrap(); + let mut guard = env.data_mut().0.lock().unwrap(); assert_eq!(*guard, 100); *guard = 101; @@ -366,13 +362,13 @@ fn static_host_function_with_env(config: crate::Config) -> anyhow::Result<()> { let env = Env(Arc::new(Mutex::new(100))); let mut env = FunctionEnv::new(&mut store, env); - let f = Function::new_native(&mut store, &env, f); - let f_native: TypedFunction<(i32, i64, f32, f64), (f64, f32, i64, i32)> = - f.native(&mut store).unwrap(); + let f = Function::new_typed_with_env(&mut store, &env, f); + let f_typed: TypedFunction<(i32, i64, f32, f64), (f64, f32, i64, i32)> = + f.typed(&mut store).unwrap(); assert_eq!(*env.as_mut(&mut store).0.lock().unwrap(), 100); - let result = f_native.call(&mut store, 1, 3, 5.0, 7.0)?; + let result = f_typed.call(&mut store, 1, 3, 5.0, 7.0)?; assert_eq!(result, (28.0, 15.0, 6, 1)); assert_eq!(*env.as_mut(&mut store).0.lock().unwrap(), 101); @@ -383,13 +379,13 @@ fn static_host_function_with_env(config: crate::Config) -> anyhow::Result<()> { let env = Env(Arc::new(Mutex::new(100))); let mut env = FunctionEnv::new(&mut store, env); - let f = Function::new_native(&mut store, &env, f_ok); - let f_native: TypedFunction<(i32, i64, f32, f64), (f64, f32, i64, i32)> = - f.native(&mut store).unwrap(); + let f = Function::new_typed_with_env(&mut store, &env, f_ok); + let f_typed: TypedFunction<(i32, i64, f32, f64), (f64, f32, i64, i32)> = + f.typed(&mut store).unwrap(); assert_eq!(*env.as_mut(&mut store).0.lock().unwrap(), 100); - let result = f_native.call(&mut store, 1, 3, 5.0, 7.0)?; + let result = f_typed.call(&mut store, 1, 3, 5.0, 7.0)?; assert_eq!(result, (28.0, 15.0, 6, 1)); assert_eq!(*env.as_mut(&mut store).0.lock().unwrap(), 101); @@ -398,13 +394,11 @@ fn static_host_function_with_env(config: crate::Config) -> anyhow::Result<()> { Ok(()) } -#[compiler_test(native_functions)] +#[compiler_test(typed_functions)] fn dynamic_host_function_without_env(config: crate::Config) -> anyhow::Result<()> { let mut store = config.store(); - let mut env = FunctionEnv::new(&mut store, ()); let f = Function::new( &mut store, - &env, FunctionType::new( vec![ ValueType::I32, @@ -419,7 +413,7 @@ fn dynamic_host_function_without_env(config: crate::Config) -> anyhow::Result<() ValueType::I32, ], ), - |_ctx: FunctionEnvMut<_>, values| { + |_env: FunctionEnvMut<_>, values| { Ok(vec![ Value::F64(values[3].unwrap_f64() * 4.0), Value::F32(values[2].unwrap_f32() * 3.0), @@ -428,16 +422,16 @@ fn dynamic_host_function_without_env(config: crate::Config) -> anyhow::Result<() ]) }, ); - let f_native: TypedFunction<(i32, i64, f32, f64), (f64, f32, i64, i32)> = - f.native(&mut store).unwrap(); - let result = f_native.call(&mut store, 1, 3, 5.0, 7.0)?; + let f_typed: TypedFunction<(i32, i64, f32, f64), (f64, f32, i64, i32)> = + f.typed(&mut store).unwrap(); + let result = f_typed.call(&mut store, 1, 3, 5.0, 7.0)?; assert_eq!(result, (28.0, 15.0, 6, 1)); Ok(()) } -#[compiler_test(native_functions)] +#[compiler_test(typed_functions)] fn dynamic_host_function_with_env(config: crate::Config) -> anyhow::Result<()> { let mut store = config.store(); @@ -453,7 +447,7 @@ fn dynamic_host_function_with_env(config: crate::Config) -> anyhow::Result<()> { let env = Env(Arc::new(Mutex::new(100))); let mut env = FunctionEnv::new(&mut store, env); - let f = Function::new( + let f = Function::new_with_env( &mut store, &env, FunctionType::new( @@ -470,8 +464,8 @@ fn dynamic_host_function_with_env(config: crate::Config) -> anyhow::Result<()> { ValueType::I32, ], ), - |mut ctx, values| { - let mut guard = ctx.data_mut().0.lock().unwrap(); + |mut env, values| { + let mut guard = env.data_mut().0.lock().unwrap(); assert_eq!(*guard, 100); *guard = 101; @@ -485,12 +479,12 @@ fn dynamic_host_function_with_env(config: crate::Config) -> anyhow::Result<()> { }, ); - let f_native: TypedFunction<(i32, i64, f32, f64), (f64, f32, i64, i32)> = - f.native(&mut store).unwrap(); + let f_typed: TypedFunction<(i32, i64, f32, f64), (f64, f32, i64, i32)> = + f.typed(&mut store).unwrap(); assert_eq!(*env.as_mut(&mut store).0.lock().unwrap(), 100); - let result = f_native.call(&mut store, 1, 3, 5.0, 7.0)?; + let result = f_typed.call(&mut store, 1, 3, 5.0, 7.0)?; assert_eq!(result, (28.0, 15.0, 6, 1)); assert_eq!(*env.as_mut(&mut store).0.lock().unwrap(), 101); diff --git a/tests/lib/wast/src/spectest.rs b/tests/lib/wast/src/spectest.rs index 389a5c4e1..16e3aea21 100644 --- a/tests/lib/wast/src/spectest.rs +++ b/tests/lib/wast/src/spectest.rs @@ -2,30 +2,28 @@ use wasmer::*; /// Return an instance implementing the "spectest" interface used in the /// spec testsuite. -pub fn spectest_importobject(store: &mut Store, context: &FunctionEnv<()>) -> Imports { - let print = Function::new_native(store, context, |_: FunctionEnvMut<()>| {}); - let print_i32 = Function::new_native(store, context, |_: FunctionEnvMut<()>, val: i32| { +pub fn spectest_importobject(store: &mut Store) -> Imports { + let print = Function::new_typed(store, |_: FunctionEnvMut<()>| {}); + let print_i32 = Function::new_typed(store, |_: FunctionEnvMut<()>, val: i32| { println!("{}: i32", val) }); - let print_i64 = Function::new_native(store, context, |_: FunctionEnvMut<()>, val: i64| { + let print_i64 = Function::new_typed(store, |_: FunctionEnvMut<()>, val: i64| { println!("{}: i64", val) }); - let print_f32 = Function::new_native(store, context, |_: FunctionEnvMut<()>, val: f32| { + let print_f32 = Function::new_typed(store, |_: FunctionEnvMut<()>, val: f32| { println!("{}: f32", val) }); - let print_f64 = Function::new_native(store, context, |_: FunctionEnvMut<()>, val: f64| { + let print_f64 = Function::new_typed(store, |_: FunctionEnvMut<()>, val: f64| { println!("{}: f64", val) }); - let print_i32_f32 = - Function::new_native(store, context, |_: FunctionEnvMut<()>, i: i32, f: f32| { - println!("{}: i32", i); - println!("{}: f32", f); - }); - let print_f64_f64 = - Function::new_native(store, context, |_: FunctionEnvMut<()>, f1: f64, f2: f64| { - println!("{}: f64", f1); - println!("{}: f64", f2); - }); + let print_i32_f32 = Function::new_typed(store, |_: FunctionEnvMut<()>, i: i32, f: f32| { + println!("{}: i32", i); + println!("{}: f32", f); + }); + let print_f64_f64 = Function::new_typed(store, |_: FunctionEnvMut<()>, f1: f64, f2: f64| { + println!("{}: f64", f1); + println!("{}: f64", f2); + }); let global_i32 = Global::new(store, Value::I32(666)); let global_i64 = Global::new(store, Value::I64(666)); diff --git a/tests/lib/wast/src/wast.rs b/tests/lib/wast/src/wast.rs index 89fb7e083..50bc02b38 100644 --- a/tests/lib/wast/src/wast.rs +++ b/tests/lib/wast/src/wast.rs @@ -26,8 +26,6 @@ pub struct Wast { current_is_allowed_failure: bool, /// The store in which the tests are executing. store: Store, - /// The context in which the tests are executing. - context: FunctionEnv<()>, /// A flag indicating if Wast tests should stop as soon as one test fails. pub fail_fast: bool, /// A flag indicating that assert_trap and assert_exhaustion should be skipped. @@ -37,11 +35,10 @@ pub struct Wast { impl Wast { /// Construct a new instance of `Wast` with a given imports. - pub fn new(store: Store, context: FunctionEnv<()>, import_object: Imports) -> Self { + pub fn new(store: Store, import_object: Imports) -> Self { Self { current: None, store, - context, import_object, allowed_instantiation_failures: HashSet::new(), match_trap_messages: HashMap::new(), @@ -73,9 +70,8 @@ impl Wast { /// Construct a new instance of `Wast` with the spectests imports. pub fn new_with_spectest(mut store: Store) -> Self { - let context = FunctionEnv::new(&mut store, ()); - let import_object = spectest_importobject(&mut store, &context); - Self::new(store, context, import_object) + let import_object = spectest_importobject(&mut store); + Self::new(store, import_object) } fn get_instance(&self, instance_name: Option<&str>) -> Result {