A WebAssembly Interpreter used in my os (https://github.com/neri/maystorm)
- Support for
no_std
- A subset of WebAssembly 2.0
- This library by itself does not support execution environments such as WASI.
Proposals | Status |
---|---|
Sign extension instructions | ✅ |
Non-trapping float-to-int conversions | ✅ |
Multiple values | - |
Reference types | - |
Table instructions | - |
Multiple tables | - |
Bulk memory and table instructions | memory.fill , memory.copy |
Vector instructions | - |
- Rust nightly
# cargo test
- The actual sample can be found in
/example/hello
. - First there is WebAssembly like this.
(module
(import "env" "println" (func $println (param i32) (param i32)))
(memory 1)
(data (i32.const 16) "hello world!")
(func $main (export "main")
i32.const 12
i32.const 16
call $println
)
)
- To run this, we create the following Rust code.
use wami::prelude::*;
fn main() {
let env = Env {};
let instance = WebAssembly::instantiate(include_bytes!("../hello.wasm"), &env).unwrap();
instance.exports().main().unwrap();
}
struct Env;
#[wasm_env]
impl Env {
pub fn println(s: &str) {
println!("{}", s)
}
}
#[wasm_exports]
trait Hello {
fn main();
}
MIT License
(C) 2020 Nerry