https://github.com/neri/wami
A WebAssembly Interpreter used in my os
https://github.com/neri/wami
rust wasm webassembly
Last synced: over 1 year ago
JSON representation
A WebAssembly Interpreter used in my os
- Host: GitHub
- URL: https://github.com/neri/wami
- Owner: neri
- License: mit
- Created: 2023-12-20T18:06:23.000Z (over 2 years ago)
- Default Branch: canary
- Last Pushed: 2024-08-22T17:58:53.000Z (almost 2 years ago)
- Last Synced: 2024-08-22T20:09:42.908Z (almost 2 years ago)
- Topics: rust, wasm, webassembly
- Language: Rust
- Homepage: https://github.com/neri/maystorm
- Size: 767 KB
- Stars: 4
- Watchers: 2
- Forks: 0
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
- License: LICENSE
Awesome Lists containing this project
README
# WAMI
A WebAssembly Interpreter used in my os (https://github.com/neri/maystorm)
## Features
- Support for `no_std`
- A subset of WebAssembly 2.0
- This library by itself does not support execution environments such as WASI.
## Supported WebAssembly 2.0 Features
|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|-|
## Requirements
- Rust nightly
## Test
```
# cargo test
```
## Example of use
* The actual sample can be found in `/example/hello`.
* First there is WebAssembly like this.
```wat
(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.
```rust
use wa_asm::WasmAssembler;
use wami::prelude::*;
fn main() {
let src = r#"
(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
)
)
"#;
let bin = WebAssembly::wat2wasm("hello.wat", src.as_bytes().to_vec()).unwrap();
let instance = WebAssembly::instantiate(&bin, &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();
}
```
## License
MIT License
(C) 2020 Nerry