Move Webassembly objects to Store and remove Context

Co-authored-by: ptitSeb <sebastien.chev@gmail.com>
Co-authored-by: Manos Pitsidianakis <manos@wasmer.io>
This commit is contained in:
Syrus Akbary
2022-07-08 15:33:29 -07:00
committed by Manos Pitsidianakis
parent b5ae6399ce
commit a419ccdf52
214 changed files with 5800 additions and 5759 deletions

View File

@ -17,7 +17,7 @@
//!
//! Ready?
use wasmer::{imports, wat2wasm, Context, Instance, Module, Store, TypedFunction, Value};
use wasmer::{imports, wat2wasm, FunctionEnv, Instance, Module, Store, TypedFunction, Value};
use wasmer_compiler::Universal;
use wasmer_compiler_cranelift::Cranelift;
@ -40,8 +40,8 @@ fn main() -> Result<(), Box<dyn std::error::Error>> {
// Note that we don't need to specify the engine/compiler if we want to use
// the default provided by Wasmer.
// You can use `Store::default()` for that.
let store = Store::new_with_engine(&Universal::new(Cranelift::default()).engine());
let mut ctx = Context::new(&store, ());
let mut store = Store::new_with_engine(&Universal::new(Cranelift::default()).engine());
let mut env = FunctionEnv::new(&mut store, ());
println!("Compiling module...");
// Let's compile the Wasm module.
@ -52,7 +52,7 @@ fn main() -> Result<(), Box<dyn std::error::Error>> {
println!("Instantiating module...");
// Let's instantiate the Wasm module.
let instance = Instance::new(&mut ctx, &module, &import_object)?;
let instance = Instance::new(&mut store, &module, &import_object)?;
// Here we go.
//
@ -74,7 +74,7 @@ fn main() -> Result<(), Box<dyn std::error::Error>> {
// Let's call the `sum` exported function. The parameters are a
// slice of `Value`s. The results are a boxed slice of `Value`s.
let args = [Value::I32(1), Value::I32(2)];
let result = sum.call(&mut ctx, &args)?;
let result = sum.call(&mut store, &args)?;
println!("Results: {:?}", result);
assert_eq!(result.to_vec(), vec![Value::I32(3)]);
@ -87,13 +87,13 @@ fn main() -> Result<(), Box<dyn std::error::Error>> {
// `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 ctx)?;
let sum_native: TypedFunction<(i32, i32), i32> = sum.native(&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 ctx, 3, 4)?;
let result = sum_native.call(&mut store, 3, 4)?;
println!("Results: {:?}", result);
assert_eq!(result, 7);