1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
//! Safe, ergonomic Rust bindings for the [Fizzy] WebAssembly interpreter.
//!
//! Fizzy is a small, fast, deterministic interpreter for the WebAssembly 1.0
//! (MVP) specification. This crate wraps its C API with an interface inspired by
//! [`wasmi`] and [`wasmtime`].
//!
//! # Example
//!
//! ```
//! use fizzyx::{Engine, Linker, Module, Val};
//!
//! # fn main() -> Result<(), Box<dyn std::error::Error>> {
//! let wat = r#"(module (func (export "add") (param i32 i32) (result i32)
//! local.get 0
//! local.get 1
//! i32.add))"#;
//! let wasm = wat::parse_str(wat)?;
//!
//! let engine = Engine::default();
//! let module = Module::new(&wasm)?;
//! let linker = Linker::new(&engine);
//! let mut instance = linker.instantiate(&module)?;
//!
//! let add = instance.get_func("add").expect("missing export");
//! let mut results = [Val::I32(0)];
//! add.call(&mut instance, &[Val::I32(1), Val::I32(2)], &mut results)?;
//! assert_eq!(results[0], Val::I32(3));
//! # Ok(())
//! # }
//! ```
//!
//! # Relationship to `wasmi`/`wasmtime`
//!
//! The API deliberately follows Fizzy's own model rather than forcing a perfect
//! match:
//!
//! - Fizzy targets WebAssembly 1.0, so a function returns **at most one** result.
//! - Instances are self-contained (they own their memory and globals), so there
//! is **no `Store`** type. Methods that mutate an instance take `&mut Instance`
//! directly.
//! - Imports are resolved by `module::name` at instantiation time via a
//! [`Linker`]. Only **function imports** are currently supported.
//!
//! [Fizzy]: https://github.com/wasmx/fizzy
//! [`wasmi`]: https://docs.rs/wasmi
//! [`wasmtime`]: https://docs.rs/wasmtime
pub use ;
pub use ;
pub use Func;
pub use Global;
pub use Instance;
pub use Linker;
pub use ;
pub use ;
pub use ;