forked from wasmerio/wasmer
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge branch 'master' into ventuzelo/fix-653-panic-memorydescriptor
- Loading branch information
Showing
56 changed files
with
850 additions
and
517 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Large diffs are not rendered by default.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,26 @@ | ||
# Feature Table | ||
|
||
## Compiler Backend | ||
|
||
| | Singlepass | Cranelift | LLVM | | ||
| - | - | - | - | | ||
| Caching | ❌ | ✅ | ✅ | | ||
| Emscripten | ✅ | ✅ | ✅ | | ||
| Metering | ✅ | ❌ | ✅ | | ||
| Multi-value return | ❌ | ❌ | ❌ | | ||
| OSR | 🚧 | ❓ | ❓ | | ||
| SIMD | ❌ | ❌ | ✅ | | ||
| WASI | ✅ | ✅ | ✅ | | ||
|
||
|
||
## Language integration | ||
|
||
TODO: define a set of features that are relevant and mark them here | ||
|
||
Current ideas: | ||
|
||
- WASI FS API | ||
- Callbacks | ||
- Exiting early in hostcall | ||
- Metering | ||
- Caching |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,5 @@ | ||
# Call back guest | ||
|
||
This is part of the `callback` example. This Wasm module passes host imports and its own functions to the Wasm host to execute. | ||
|
||
See `examples/callback.rs` for the host |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,24 @@ | ||
extern "C" { | ||
fn call_guest_fn(f: u32) -> u32; | ||
fn call_guest_fn2(f: u32) -> u32; | ||
fn host_callback() -> u32; | ||
} | ||
|
||
#[no_mangle] | ||
fn test_callback() -> u32 { | ||
42 | ||
} | ||
|
||
#[no_mangle] | ||
fn test_callback2() -> u32 { | ||
45 | ||
} | ||
|
||
fn main() { | ||
unsafe { call_guest_fn(test_callback as usize as u32) }; | ||
unsafe { call_guest_fn(host_callback as usize as u32) }; | ||
unsafe { call_guest_fn(test_callback2 as usize as u32) }; | ||
unsafe { call_guest_fn2(test_callback2 as usize as u32) }; | ||
unsafe { call_guest_fn2(test_callback as usize as u32) }; | ||
unsafe { call_guest_fn2(host_callback as usize as u32) }; | ||
} |
Binary file not shown.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,46 @@ | ||
/// This example demonstrates the use of callbacks: calling functions (Host and Wasm) | ||
/// passed to us from the Wasm via hostcall | ||
use wasmer_runtime::{compile_with, compiler_for_backend, func, imports, Backend, Ctx}; | ||
use wasmer_runtime_core::{structures::TypedIndex, types::TableIndex}; | ||
|
||
static WASM: &'static str = "examples/callback-guest/callback-guest.wasm"; | ||
|
||
/// This function matches our arbitrarily decided callback signature | ||
/// in this example we'll only call functions that take no arguments and return one value | ||
fn host_callback(_ctx: &mut Ctx) -> u32 { | ||
55 | ||
} | ||
|
||
fn call_guest_fn(ctx: &mut Ctx, guest_fn: u32) -> u32 { | ||
// We get a TableIndex from our raw value passed in | ||
let guest_fn_typed = TableIndex::new(guest_fn as usize); | ||
// and use it to call the corresponding function | ||
let result = ctx.call_with_table_index(guest_fn_typed, &[]).unwrap(); | ||
|
||
println!("Guest fn {} returned {:?}", guest_fn, result); | ||
|
||
0 | ||
} | ||
|
||
fn main() { | ||
let wasm_bytes = | ||
std::fs::read(WASM).expect(&format!("Could not read in WASM plugin at {}", WASM)); | ||
|
||
let imports = imports! { | ||
"env" => { | ||
"call_guest_fn" => func!(call_guest_fn), | ||
"call_guest_fn2" => func!(call_guest_fn), | ||
"host_callback" => func!(host_callback), | ||
}, | ||
}; | ||
|
||
let compiler = compiler_for_backend(Backend::default()).unwrap(); | ||
let module = compile_with(&wasm_bytes[..], compiler.as_ref()).unwrap(); | ||
let instance = module | ||
.instantiate(&imports) | ||
.expect("failed to instantiate wasm module"); | ||
|
||
let entry_point = instance.func::<(u32, u32), u32>("main").unwrap(); | ||
|
||
entry_point.call(0, 0).expect("START"); | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.