mirror of
https://github.com/mii443/wasmer.git
synced 2025-12-07 21:28:21 +00:00
Rename {native,typed} functions, reintroduce *_with_env variants
This commit is contained in:
@@ -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),
|
||||
}
|
||||
};
|
||||
|
||||
|
||||
@@ -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<dyn std::error::Error>> {
|
||||
|
||||
@@ -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<dyn std::error::Error>> {
|
||||
@@ -61,7 +61,7 @@ fn main() -> Result<(), Box<dyn std::error::Error>> {
|
||||
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.
|
||||
|
||||
@@ -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<dyn std::error::Error>> {
|
||||
@@ -81,17 +81,17 @@ fn main() -> Result<(), Box<dyn std::error::Error>> {
|
||||
// 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);
|
||||
|
||||
@@ -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<dyn std::error::Error>> {
|
||||
@@ -92,7 +90,7 @@ fn main() -> Result<(), Box<dyn std::error::Error>> {
|
||||
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<dyn std::error::Error>> {
|
||||
let set_some: TypedFunction<f32, ()> = 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);
|
||||
|
||||
@@ -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<dyn std::error::Error>> {
|
||||
|
||||
@@ -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<()> {
|
||||
|
||||
@@ -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),
|
||||
}
|
||||
};
|
||||
|
||||
|
||||
@@ -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<dyn std::error::Error>> {
|
||||
// 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<dyn std::error::Error>> {
|
||||
// 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)])
|
||||
});
|
||||
|
||||
|
||||
@@ -29,12 +29,12 @@ fn main() -> Result<(), Box<dyn std::error::Error>> {
|
||||
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<dyn std::error::Error>> {
|
||||
// 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,11 +54,7 @@ fn main() -> Result<(), Box<dyn std::error::Error>> {
|
||||
|
||||
// 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| {
|
||||
let multiply_dynamic = Function::new(&mut store, &multiply_dynamic_signature, |_env, args| {
|
||||
println!("Calling `multiply_dynamic`...");
|
||||
|
||||
let result = args[0].unwrap_i32() * 2;
|
||||
@@ -67,24 +62,23 @@ fn main() -> Result<(), Box<dyn std::error::Error>> {
|
||||
println!("Result of `multiply_dynamic`: {:?}", result);
|
||||
|
||||
Ok(vec![Value::I32(result)])
|
||||
},
|
||||
);
|
||||
});
|
||||
|
||||
fn multiply(_env: FunctionEnvMut<MyEnv>, 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<dyn std::error::Error>> {
|
||||
//
|
||||
// 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
|
||||
|
||||
@@ -97,8 +97,8 @@ fn main() -> Result<(), Box<dyn std::error::Error>> {
|
||||
// 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<dyn std::error::Error>> {
|
||||
let increment_counter_loop: TypedFunction<i32, i32> = 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);
|
||||
|
||||
@@ -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<dyn std::error::Error>> {
|
||||
@@ -69,11 +67,11 @@ fn main() -> Result<(), Box<dyn std::error::Error>> {
|
||||
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<dyn std::error::Error>> {
|
||||
let set_other: TypedFunction<f32, ()> = 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));
|
||||
|
||||
@@ -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<dyn std::error::Error>> {
|
||||
@@ -62,7 +62,7 @@ fn main() -> Result<(), Box<dyn std::error::Error>> {
|
||||
let add_one: TypedFunction<i32, i32> = 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)?;
|
||||
|
||||
@@ -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:
|
||||
|
||||
@@ -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<i32, i32> = instance
|
||||
.exports
|
||||
.get_function("add_one")?
|
||||
.native(&mut store)?;
|
||||
.typed(&mut store)?;
|
||||
|
||||
println!("Calling `add_one` function once...");
|
||||
add_one.call(&mut store, 1)?;
|
||||
|
||||
@@ -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)?;
|
||||
|
||||
@@ -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;
|
||||
|
||||
|
||||
87
lib/api/src/js/externals/function.rs
vendored
87
lib/api/src/js/externals/function.rs
vendored
@@ -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<FT, F>(store: &mut impl AsStoreMut, ty: FT, func: F) -> Self
|
||||
where
|
||||
FT: Into<FunctionType>,
|
||||
F: Fn(&[Value]) -> Result<Vec<Value>, RuntimeError> + 'static + Send + Sync,
|
||||
{
|
||||
let env = FunctionEnv::new(&mut store.as_store_mut(), ());
|
||||
let wrapped_func = move |_env: FunctionEnvMut<()>,
|
||||
args: &[Value]|
|
||||
-> Result<Vec<Value>, 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<FT, F, T: Send + 'static>(
|
||||
pub fn new_with_env<FT, F, T: Send + 'static>(
|
||||
store: &mut impl AsStoreMut,
|
||||
env: &FunctionEnv<T>,
|
||||
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<T, F, Args, Rets>(
|
||||
store: &mut impl AsStoreMut,
|
||||
env: &FunctionEnv<T>,
|
||||
func: F,
|
||||
) -> Self
|
||||
where
|
||||
F: HostFunction<T, Args, Rets>,
|
||||
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<T, F, Args, Rets>(
|
||||
pub fn new_typed_with_env<T, F, Args, Rets>(
|
||||
store: &mut impl AsStoreMut,
|
||||
env: &FunctionEnv<T>,
|
||||
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<Args, Rets>(
|
||||
&self,
|
||||
store: &impl AsStoreRef,
|
||||
) -> Result<TypedFunction<Args, Rets>, 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<Args, Rets>(
|
||||
pub fn typed<Args, Rets>(
|
||||
&self,
|
||||
store: &impl AsStoreRef,
|
||||
) -> Result<TypedFunction<Args, Rets>, RuntimeError>
|
||||
|
||||
@@ -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<Extern>) {
|
||||
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),
|
||||
}
|
||||
};
|
||||
}
|
||||
|
||||
@@ -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,
|
||||
//! }
|
||||
//! }
|
||||
|
||||
@@ -166,7 +166,7 @@ impl Exports {
|
||||
Rets: WasmTypeList,
|
||||
{
|
||||
self.get_function(name)?
|
||||
.native(store)
|
||||
.typed(store)
|
||||
.map_err(|_| ExportError::IncompatibleType)
|
||||
}
|
||||
|
||||
|
||||
116
lib/api/src/sys/externals/function.rs
vendored
116
lib/api/src/sys/externals/function.rs
vendored
@@ -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<FT, F>(store: &mut impl AsStoreMut, ty: FT, func: F) -> Self
|
||||
where
|
||||
FT: Into<FunctionType>,
|
||||
F: Fn(FunctionEnvMut<()>, &[Value]) -> Result<Vec<Value>, 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<FT, F, T: Send + 'static>(
|
||||
pub fn new_with_env<FT, F, T: Send + 'static>(
|
||||
store: &mut impl AsStoreMut,
|
||||
env: &FunctionEnv<T>,
|
||||
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<F, Args, Rets>(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<F, Args, Rets>(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<T: Send + 'static, F, Args, Rets>(
|
||||
store: &mut impl AsStoreMut,
|
||||
env: &FunctionEnv<T>,
|
||||
func: F,
|
||||
) -> Self
|
||||
where
|
||||
F: HostFunction<T, Args, Rets> + '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<T: Send + 'static, F, Args, Rets>(
|
||||
pub fn new_typed_with_env<T: Send + 'static, F, Args, Rets>(
|
||||
store: &mut impl AsStoreMut,
|
||||
env: &FunctionEnv<T>,
|
||||
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<Args, Rets>(
|
||||
&self,
|
||||
store: &impl AsStoreRef,
|
||||
) -> Result<TypedFunction<Args, Rets>, 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<Args, Rets>(
|
||||
pub fn typed<Args, Rets>(
|
||||
&self,
|
||||
store: &impl AsStoreRef,
|
||||
) -> Result<TypedFunction<Args, Rets>, 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<F, T> {
|
||||
pub(crate) raw_store: *mut u8,
|
||||
pub(crate) env: FunctionEnv<T>,
|
||||
|
||||
@@ -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<Extern>) {
|
||||
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),
|
||||
}
|
||||
};
|
||||
}
|
||||
|
||||
@@ -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<i32, i32> = function.native(&mut store).unwrap();
|
||||
let function = Function::new_typed(&mut store, |a: i32| -> i32 { a + 1 });
|
||||
let typed_function: TypedFunction<i32, i32> = 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<i32, ()> = function.native(&mut store).unwrap();
|
||||
let function = Function::new_typed(&mut store, |_a: i32| {});
|
||||
let typed_function: TypedFunction<i32, ()> = 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) });
|
||||
|
||||
@@ -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),
|
||||
}
|
||||
};
|
||||
|
||||
|
||||
@@ -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());
|
||||
// }),
|
||||
|
||||
@@ -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<MyEnv>| {});
|
||||
let function =
|
||||
Function::new_typed_with_env(&mut store, &env, |_env: FunctionEnvMut<MyEnv>| {});
|
||||
assert_eq!(
|
||||
function.ty(&mut store).clone(),
|
||||
FunctionType::new(vec![], vec![])
|
||||
);
|
||||
let function =
|
||||
Function::new_native(&mut store, &env, |_env: FunctionEnvMut<MyEnv>, _a: i32| {});
|
||||
let function = Function::new_typed_with_env(
|
||||
&mut store,
|
||||
&env,
|
||||
|_env: FunctionEnvMut<MyEnv>, _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<MyEnv>, _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<MyEnv>| -> i32 { 1 });
|
||||
Function::new_typed_with_env(&mut store, &env, |_env: FunctionEnvMut<MyEnv>| -> 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<MyEnv>| -> (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<i32, i32> = 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<i32, i32> = 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<i32, ()> = 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<i32, ()> = 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)))
|
||||
|
||||
@@ -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)])?;
|
||||
|
||||
@@ -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());
|
||||
}),
|
||||
|
||||
@@ -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<Env>, values: &[Value]| -> Result<Vec<_>, _> {
|
||||
"func_ref_identity" => Function::new_with_env(&mut store, &env, FunctionType::new([Type::FuncRef], [Type::FuncRef]), |_env: FunctionEnvMut<Env>, values: &[Value]| -> Result<Vec<_>, _> {
|
||||
Ok(vec![values[0].clone()])
|
||||
})
|
||||
},
|
||||
@@ -44,7 +44,7 @@ mod sys {
|
||||
}
|
||||
|
||||
let func_to_call =
|
||||
Function::new_native(&mut store, &env, |mut env: FunctionEnvMut<Env>| -> i32 {
|
||||
Function::new_typed_with_env(&mut store, &env, |mut env: FunctionEnvMut<Env>| -> i32 {
|
||||
env.data_mut().0.store(true, Ordering::SeqCst);
|
||||
343
|
||||
});
|
||||
@@ -88,20 +88,20 @@ mod sys {
|
||||
) -> Result<Vec<Value>, 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<i32, RuntimeError> {
|
||||
// let f: TypedFunction::<(i32, i32), i32> = f.native(&mut store)?;
|
||||
// "func_ref_call_native" => Function::new_native(&mut store, |f: Function| -> Result<i32, RuntimeError> {
|
||||
// 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<Vec<_>, _> {
|
||||
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<Vec<_>, _> {
|
||||
@@ -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)))?;
|
||||
|
||||
|
||||
@@ -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<Vec<Value>, 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()),
|
||||
}))
|
||||
|
||||
File diff suppressed because it is too large
Load Diff
@@ -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
|
||||
|
||||
@@ -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<WasiEnv>,
|
||||
env: &FunctionEnv<WasiEnv>,
|
||||
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<WasiEnv>) -> Exports {
|
||||
fn wasi_unstable_exports(mut store: &mut impl AsStoreMut, env: &FunctionEnv<WasiEnv>) -> Exports {
|
||||
let namespace = namespace! {
|
||||
"args_get" => Function::new_native(&mut store, ctx, args_get::<Memory32>),
|
||||
"args_sizes_get" => Function::new_native(&mut store, ctx, args_sizes_get::<Memory32>),
|
||||
"clock_res_get" => Function::new_native(&mut store, ctx, clock_res_get::<Memory32>),
|
||||
"clock_time_get" => Function::new_native(&mut store, ctx, clock_time_get::<Memory32>),
|
||||
"environ_get" => Function::new_native(&mut store, ctx, environ_get::<Memory32>),
|
||||
"environ_sizes_get" => Function::new_native(&mut store, ctx, environ_sizes_get::<Memory32>),
|
||||
"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::<Memory32>),
|
||||
"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::<Memory32>),
|
||||
"fd_prestat_get" => Function::new_native(&mut store, ctx, fd_prestat_get::<Memory32>),
|
||||
"fd_prestat_dir_name" => Function::new_native(&mut store, ctx, fd_prestat_dir_name::<Memory32>),
|
||||
"fd_pwrite" => Function::new_native(&mut store, ctx, fd_pwrite::<Memory32>),
|
||||
"fd_read" => Function::new_native(&mut store, ctx, fd_read::<Memory32>),
|
||||
"fd_readdir" => Function::new_native(&mut store, ctx, fd_readdir::<Memory32>),
|
||||
"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::<Memory32>),
|
||||
"fd_write" => Function::new_native(&mut store, ctx, fd_write::<Memory32>),
|
||||
"path_create_directory" => Function::new_native(&mut store, ctx, path_create_directory::<Memory32>),
|
||||
"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::<Memory32>),
|
||||
"path_link" => Function::new_native(&mut store, ctx, path_link::<Memory32>),
|
||||
"path_open" => Function::new_native(&mut store, ctx, path_open::<Memory32>),
|
||||
"path_readlink" => Function::new_native(&mut store, ctx, path_readlink::<Memory32>),
|
||||
"path_remove_directory" => Function::new_native(&mut store, ctx, path_remove_directory::<Memory32>),
|
||||
"path_rename" => Function::new_native(&mut store, ctx, path_rename::<Memory32>),
|
||||
"path_symlink" => Function::new_native(&mut store, ctx, path_symlink::<Memory32>),
|
||||
"path_unlink_file" => Function::new_native(&mut store, ctx, path_unlink_file::<Memory32>),
|
||||
"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::<Memory32>),
|
||||
"sched_yield" => Function::new_native(&mut store, ctx, sched_yield),
|
||||
"sock_recv" => Function::new_native(&mut store, ctx, sock_recv::<Memory32>),
|
||||
"sock_send" => Function::new_native(&mut store, ctx, sock_send::<Memory32>),
|
||||
"sock_shutdown" => Function::new_native(&mut store, ctx, sock_shutdown),
|
||||
"args_get" => Function::new_typed_with_env(&mut store, env, args_get::<Memory32>),
|
||||
"args_sizes_get" => Function::new_typed_with_env(&mut store, env, args_sizes_get::<Memory32>),
|
||||
"clock_res_get" => Function::new_typed_with_env(&mut store, env, clock_res_get::<Memory32>),
|
||||
"clock_time_get" => Function::new_typed_with_env(&mut store, env, clock_time_get::<Memory32>),
|
||||
"environ_get" => Function::new_typed_with_env(&mut store, env, environ_get::<Memory32>),
|
||||
"environ_sizes_get" => Function::new_typed_with_env(&mut store, env, environ_sizes_get::<Memory32>),
|
||||
"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::<Memory32>),
|
||||
"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::<Memory32>),
|
||||
"fd_prestat_get" => Function::new_typed_with_env(&mut store, env, fd_prestat_get::<Memory32>),
|
||||
"fd_prestat_dir_name" => Function::new_typed_with_env(&mut store, env, fd_prestat_dir_name::<Memory32>),
|
||||
"fd_pwrite" => Function::new_typed_with_env(&mut store, env, fd_pwrite::<Memory32>),
|
||||
"fd_read" => Function::new_typed_with_env(&mut store, env, fd_read::<Memory32>),
|
||||
"fd_readdir" => Function::new_typed_with_env(&mut store, env, fd_readdir::<Memory32>),
|
||||
"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::<Memory32>),
|
||||
"fd_write" => Function::new_typed_with_env(&mut store, env, fd_write::<Memory32>),
|
||||
"path_create_directory" => Function::new_typed_with_env(&mut store, env, path_create_directory::<Memory32>),
|
||||
"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::<Memory32>),
|
||||
"path_link" => Function::new_typed_with_env(&mut store, env, path_link::<Memory32>),
|
||||
"path_open" => Function::new_typed_with_env(&mut store, env, path_open::<Memory32>),
|
||||
"path_readlink" => Function::new_typed_with_env(&mut store, env, path_readlink::<Memory32>),
|
||||
"path_remove_directory" => Function::new_typed_with_env(&mut store, env, path_remove_directory::<Memory32>),
|
||||
"path_rename" => Function::new_typed_with_env(&mut store, env, path_rename::<Memory32>),
|
||||
"path_symlink" => Function::new_typed_with_env(&mut store, env, path_symlink::<Memory32>),
|
||||
"path_unlink_file" => Function::new_typed_with_env(&mut store, env, path_unlink_file::<Memory32>),
|
||||
"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::<Memory32>),
|
||||
"sched_yield" => Function::new_typed_with_env(&mut store, env, sched_yield),
|
||||
"sock_recv" => Function::new_typed_with_env(&mut store, env, sock_recv::<Memory32>),
|
||||
"sock_send" => Function::new_typed_with_env(&mut store, env, sock_send::<Memory32>),
|
||||
"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<WasiEnv>,
|
||||
env: &FunctionEnv<WasiEnv>,
|
||||
) -> Exports {
|
||||
let namespace = namespace! {
|
||||
"args_get" => Function::new_native(&mut store, ctx, args_get::<Memory32>),
|
||||
"args_sizes_get" => Function::new_native(&mut store, ctx, args_sizes_get::<Memory32>),
|
||||
"clock_res_get" => Function::new_native(&mut store, ctx, clock_res_get::<Memory32>),
|
||||
"clock_time_get" => Function::new_native(&mut store, ctx, clock_time_get::<Memory32>),
|
||||
"environ_get" => Function::new_native(&mut store, ctx, environ_get::<Memory32>),
|
||||
"environ_sizes_get" => Function::new_native(&mut store, ctx, environ_sizes_get::<Memory32>),
|
||||
"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::<Memory32>),
|
||||
"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::<Memory32>),
|
||||
"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::<Memory32>),
|
||||
"fd_prestat_get" => Function::new_native(&mut store, ctx, fd_prestat_get::<Memory32>),
|
||||
"fd_prestat_dir_name" => Function::new_native(&mut store, ctx, fd_prestat_dir_name::<Memory32>),
|
||||
"fd_pwrite" => Function::new_native(&mut store, ctx, fd_pwrite::<Memory32>),
|
||||
"fd_read" => Function::new_native(&mut store, ctx, fd_read::<Memory32>),
|
||||
"fd_readdir" => Function::new_native(&mut store, ctx, fd_readdir::<Memory32>),
|
||||
"fd_renumber" => Function::new_native(&mut store, ctx, fd_renumber),
|
||||
"fd_seek" => Function::new_native(&mut store, ctx, fd_seek::<Memory32>),
|
||||
"fd_sync" => Function::new_native(&mut store, ctx, fd_sync),
|
||||
"fd_tell" => Function::new_native(&mut store, ctx, fd_tell::<Memory32>),
|
||||
"fd_write" => Function::new_native(&mut store, ctx, fd_write::<Memory32>),
|
||||
"path_create_directory" => Function::new_native(&mut store, ctx, path_create_directory::<Memory32>),
|
||||
"path_filestat_get" => Function::new_native(&mut store, ctx, path_filestat_get::<Memory32>),
|
||||
"path_filestat_set_times" => Function::new_native(&mut store, ctx, path_filestat_set_times::<Memory32>),
|
||||
"path_link" => Function::new_native(&mut store, ctx, path_link::<Memory32>),
|
||||
"path_open" => Function::new_native(&mut store, ctx, path_open::<Memory32>),
|
||||
"path_readlink" => Function::new_native(&mut store, ctx, path_readlink::<Memory32>),
|
||||
"path_remove_directory" => Function::new_native(&mut store, ctx, path_remove_directory::<Memory32>),
|
||||
"path_rename" => Function::new_native(&mut store, ctx, path_rename::<Memory32>),
|
||||
"path_symlink" => Function::new_native(&mut store, ctx, path_symlink::<Memory32>),
|
||||
"path_unlink_file" => Function::new_native(&mut store, ctx, path_unlink_file::<Memory32>),
|
||||
"poll_oneoff" => Function::new_native(&mut store, ctx, poll_oneoff::<Memory32>),
|
||||
"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::<Memory32>),
|
||||
"sched_yield" => Function::new_native(&mut store, ctx, sched_yield),
|
||||
"sock_recv" => Function::new_native(&mut store, ctx, sock_recv::<Memory32>),
|
||||
"sock_send" => Function::new_native(&mut store, ctx, sock_send::<Memory32>),
|
||||
"sock_shutdown" => Function::new_native(&mut store, ctx, sock_shutdown),
|
||||
"args_get" => Function::new_typed_with_env(&mut store, env, args_get::<Memory32>),
|
||||
"args_sizes_get" => Function::new_typed_with_env(&mut store, env, args_sizes_get::<Memory32>),
|
||||
"clock_res_get" => Function::new_typed_with_env(&mut store, env, clock_res_get::<Memory32>),
|
||||
"clock_time_get" => Function::new_typed_with_env(&mut store, env, clock_time_get::<Memory32>),
|
||||
"environ_get" => Function::new_typed_with_env(&mut store, env, environ_get::<Memory32>),
|
||||
"environ_sizes_get" => Function::new_typed_with_env(&mut store, env, environ_sizes_get::<Memory32>),
|
||||
"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::<Memory32>),
|
||||
"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::<Memory32>),
|
||||
"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::<Memory32>),
|
||||
"fd_prestat_get" => Function::new_typed_with_env(&mut store, env, fd_prestat_get::<Memory32>),
|
||||
"fd_prestat_dir_name" => Function::new_typed_with_env(&mut store, env, fd_prestat_dir_name::<Memory32>),
|
||||
"fd_pwrite" => Function::new_typed_with_env(&mut store, env, fd_pwrite::<Memory32>),
|
||||
"fd_read" => Function::new_typed_with_env(&mut store, env, fd_read::<Memory32>),
|
||||
"fd_readdir" => Function::new_typed_with_env(&mut store, env, fd_readdir::<Memory32>),
|
||||
"fd_renumber" => Function::new_typed_with_env(&mut store, env, fd_renumber),
|
||||
"fd_seek" => Function::new_typed_with_env(&mut store, env, fd_seek::<Memory32>),
|
||||
"fd_sync" => Function::new_typed_with_env(&mut store, env, fd_sync),
|
||||
"fd_tell" => Function::new_typed_with_env(&mut store, env, fd_tell::<Memory32>),
|
||||
"fd_write" => Function::new_typed_with_env(&mut store, env, fd_write::<Memory32>),
|
||||
"path_create_directory" => Function::new_typed_with_env(&mut store, env, path_create_directory::<Memory32>),
|
||||
"path_filestat_get" => Function::new_typed_with_env(&mut store, env, path_filestat_get::<Memory32>),
|
||||
"path_filestat_set_times" => Function::new_typed_with_env(&mut store, env, path_filestat_set_times::<Memory32>),
|
||||
"path_link" => Function::new_typed_with_env(&mut store, env, path_link::<Memory32>),
|
||||
"path_open" => Function::new_typed_with_env(&mut store, env, path_open::<Memory32>),
|
||||
"path_readlink" => Function::new_typed_with_env(&mut store, env, path_readlink::<Memory32>),
|
||||
"path_remove_directory" => Function::new_typed_with_env(&mut store, env, path_remove_directory::<Memory32>),
|
||||
"path_rename" => Function::new_typed_with_env(&mut store, env, path_rename::<Memory32>),
|
||||
"path_symlink" => Function::new_typed_with_env(&mut store, env, path_symlink::<Memory32>),
|
||||
"path_unlink_file" => Function::new_typed_with_env(&mut store, env, path_unlink_file::<Memory32>),
|
||||
"poll_oneoff" => Function::new_typed_with_env(&mut store, env, poll_oneoff::<Memory32>),
|
||||
"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::<Memory32>),
|
||||
"sched_yield" => Function::new_typed_with_env(&mut store, env, sched_yield),
|
||||
"sock_recv" => Function::new_typed_with_env(&mut store, env, sock_recv::<Memory32>),
|
||||
"sock_send" => Function::new_typed_with_env(&mut store, env, sock_send::<Memory32>),
|
||||
"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<WasiEnv>,
|
||||
env: &FunctionEnv<WasiEnv>,
|
||||
) -> 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<WasiEnv>,
|
||||
env: &FunctionEnv<WasiEnv>,
|
||||
) -> 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<WasiEnv>,
|
||||
env: &FunctionEnv<WasiEnv>,
|
||||
) -> 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<WasiEnv>,
|
||||
env: &FunctionEnv<WasiEnv>,
|
||||
) -> 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<WasiEnv>,
|
||||
env: &FunctionEnv<WasiEnv>,
|
||||
) -> 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),
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -49,26 +49,25 @@ fn get_module(store: &Store) -> Result<Module> {
|
||||
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(
|
||||
&mut store,
|
||||
&env,
|
||||
|_ctx: FunctionEnvMut<_>, x: i32, y: i64| {
|
||||
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_native(
|
||||
});
|
||||
let f3 = Function::new_typed(
|
||||
&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<i32, Infallible> {
|
||||
|_env: FunctionEnvMut<_>, x: i32| -> Result<i32, Infallible> {
|
||||
assert_eq!(x, 0);
|
||||
assert_eq!(HITS.fetch_add(1, SeqCst), 1);
|
||||
Ok(1)
|
||||
},
|
||||
);
|
||||
let f2 = Function::new_native(
|
||||
&mut store,
|
||||
&env,
|
||||
|_ctx: FunctionEnvMut<_>, x: i32, y: i64| {
|
||||
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_native(
|
||||
});
|
||||
let f3 = Function::new_typed(
|
||||
&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<Env>| {
|
||||
assert_eq!(ctx.data().fetch_add(1, SeqCst), 0);
|
||||
let f0 = Function::new_typed_with_env(&mut store, &env, |env: FunctionEnvMut<Env>| {
|
||||
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<Env>, x: i32| -> i32 {
|
||||
|env: FunctionEnvMut<Env>, 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<Env>, x: i32, y: i64| {
|
||||
|env: FunctionEnvMut<Env>, 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<Env>, a: i32, b: i64, c: i32, d: f32, e: f64| {
|
||||
|env: FunctionEnvMut<Env>, 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<Infallible, RuntimeError> {
|
||||
|_env: FunctionEnvMut<_>| -> Result<Infallible, RuntimeError> {
|
||||
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<Env>) {
|
||||
assert!(ctx.data().memory.is_some());
|
||||
fn host_fn(env: FunctionEnvMut<Env>) {
|
||||
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)?;
|
||||
|
||||
@@ -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)?;
|
||||
|
||||
@@ -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;
|
||||
|
||||
|
||||
@@ -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;
|
||||
|
||||
@@ -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();
|
||||
|
||||
|
||||
@@ -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<Vec<Value>, RuntimeError> {
|
||||
fn long_f_dynamic(_env: FunctionEnvMut<()>, values: &[Value]) -> Result<Vec<Value>, 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<Vec<Valu
|
||||
)])
|
||||
}
|
||||
|
||||
#[compiler_test(native_functions)]
|
||||
fn native_function_works_for_wasm(config: crate::Config) -> 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>, _: i32| {
|
||||
move |_env: FunctionEnvMut<i32>, _: 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<i32>, arg1: i32, arg2: i32| -> i32
|
||||
{arg1 * arg2 * ctx.data() }),
|
||||
"multiply4" => Function::new_typed_with_env(&mut store, &env, |env: FunctionEnvMut<i32>, 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<Env>, 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<Env>, 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<Env>,
|
||||
mut env: FunctionEnvMut<Env>,
|
||||
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);
|
||||
@@ -2,27 +2,25 @@ 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| {
|
||||
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_native(store, context, |_: FunctionEnvMut<()>, f1: f64, f2: f64| {
|
||||
let print_f64_f64 = Function::new_typed(store, |_: FunctionEnvMut<()>, f1: f64, f2: f64| {
|
||||
println!("{}: f64", f1);
|
||||
println!("{}: f64", f2);
|
||||
});
|
||||
|
||||
@@ -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<Instance> {
|
||||
|
||||
Reference in New Issue
Block a user