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

@@ -49,7 +49,7 @@ TODO
You need a Store to create a context. Simple context is created using:
```rust
let ctx = Context::new(&store, ());
let ctx = FunctionEnv::new(&mut store, ());
```
For a Context with a custom Env, it will be similar:
@@ -59,7 +59,7 @@ For a Context with a custom Env, it will be similar:
struct Env {
counter: i32,
}
let ctx = Context::new(&store, Env{counter: 0});
let ctx = FunctionEnv::new(&mut store, Env{counter: 0});
```
### Managing imports
@@ -72,7 +72,7 @@ let import_object: Imports = imports! {
"host_function" => host_function,
},
};
let instance = Instance::new(&mut ctx, &module, &import_object).expect("Could not instantiate module.");
let instance = Instance::new(&mut store, &module, &import_object).expect("Could not instantiate module.");
```
You can also build the `Imports` object manually:
@@ -80,18 +80,17 @@ You can also build the `Imports` object manually:
```rust
let mut import_object: Imports = Imports::new();
import_object.define("env", "host_function", host_function);
let instance = Instance::new(&mut ctx, &module, &import_object).expect("Could not instantiate module.");
let instance = Instance::new(&mut store, &module, &import_object).expect("Could not instantiate module.");
```
For WASI, don't forget to import memory to `WasiEnv`
```rust
let mut wasi_env = WasiState::new("hello").finalize()?;
let mut ctx = Context::new(&store, wasi_env.clone());
let import_object = wasi_env.import_object(&mut ctx.as_context_mut(), &module)?;
let instance = Instance::new(&mut ctx, &module, &import_object).expect("Could not instantiate module.");
let import_object = wasi_env.import_object(&mut store, &module)?;
let instance = Instance::new(&mut store, &module, &import_object).expect("Could not instantiate module.");
let memory = instance.exports.get_memory("memory")?;
ctx.data_mut().set_memory(memory.clone());
wasi_env.data_mut(&mut store).set_memory(memory.clone());
```
#### `ChainableNamedResolver` is removed
@@ -122,7 +121,7 @@ let wasm_bytes = wat2wasm(
let compiler_config = Cranelift::default();
let engine = Universal::new(compiler_config).engine();
let store = Store::new(&engine);
let mut store = Store::new(&engine);
let module = Module::new(&store, wasm_bytes)?;
let instance = Instance::new(&module, &imports! {})?;
```
@@ -137,7 +136,7 @@ let wasm_bytes = wat2wasm(
)?;
let compiler_config = Cranelift::default();
let store = Store::new(&compiler_config);
let mut store = Store::new(&compiler_config);
let module = Module::new(&store, wasm_bytes)?;
let instance = Instance::new(&module, &imports! {})?;
```