mirror of
https://github.com/mii443/wasmer.git
synced 2025-08-23 16:59:27 +00:00
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:
committed by
Manos Pitsidianakis
parent
b5ae6399ce
commit
a419ccdf52
@ -10,7 +10,7 @@
|
||||
//!
|
||||
//! Ready?
|
||||
|
||||
use wasmer::{imports, wat2wasm, Context, Instance, Module, Store, Value};
|
||||
use wasmer::{imports, wat2wasm, Instance, Module, Store, Value};
|
||||
use wasmer_compiler::Universal;
|
||||
use wasmer_compiler_llvm::LLVM;
|
||||
|
||||
@ -33,8 +33,7 @@ fn main() -> Result<(), Box<dyn std::error::Error>> {
|
||||
let compiler = LLVM::default();
|
||||
|
||||
// Create the store
|
||||
let store = Store::new_with_engine(&Universal::new(compiler).engine());
|
||||
let mut ctx = Context::new(&store, ());
|
||||
let mut store = Store::new_with_engine(&Universal::new(compiler).engine());
|
||||
|
||||
println!("Compiling module...");
|
||||
// Let's compile the Wasm module.
|
||||
@ -45,14 +44,14 @@ 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)?;
|
||||
|
||||
let sum = instance.exports.get_function("sum")?;
|
||||
|
||||
println!("Calling `sum` function...");
|
||||
// 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 results = sum.call(&mut ctx, &[Value::I32(1), Value::I32(2)])?;
|
||||
let results = sum.call(&mut store, &[Value::I32(1), Value::I32(2)])?;
|
||||
|
||||
println!("Results: {:?}", results);
|
||||
assert_eq!(results.to_vec(), vec![Value::I32(3)]);
|
||||
|
Reference in New Issue
Block a user