#wasm-interpreter #interpreter

sys fizzy

Bindings to Fizzy, a fast, deterministic, and pedantic WebAssembly interpreter

4 releases (2 breaking)

0.8.0 Jun 28, 2022
0.7.0 Mar 1, 2021
0.6.0 Dec 24, 2020
0.6.0-dev Oct 7, 2020

#992 in WebAssembly

Apache-2.0

235KB
5.5K SLoC

C++ 4.5K SLoC // 0.1% comments Rust 1K SLoC // 0.1% comments Shell 7 SLoC // 0.4% comments

Fizzy

This is a Rust interface to Fizzy, a WebAssembly virtual machine.

Please refer to the upstream repository for more information.


lib.rs:

This is a Rust interface to Fizzy, a fast, deterministic, and pedantic WebAssembly interpreter.

Examples

This is a generic example for parsing and instantiating a module, and executing a simple function with inputs and an output.

extern crate fizzy;

fn main() {
    // This wasm binary exports a single sum(u32, u32) -> u32 function.
    let wasm = [
        0x00, 0x61, 0x73, 0x6d, 0x01, 0x00, 0x00, 0x00, 0x01, 0x07, 0x01, 0x60, 0x02, 0x7f,
        0x7f, 0x01, 0x7f, 0x03, 0x02, 0x01, 0x00, 0x07, 0x07, 0x01, 0x03, 0x73, 0x75, 0x6d,
        0x00, 0x00, 0x0a, 0x09, 0x01, 0x07, 0x00, 0x20, 0x00, 0x20, 0x01, 0x6a, 0x0b,
    ];
    let module = fizzy::parse(&wasm).expect("parsing failed");
    let mut instance = module.instantiate().expect("instantiation failed");
    let result = instance
        .execute(
            "sum",
            &[fizzy::TypedValue::U32(42), fizzy::TypedValue::U32(24)],
        )
        .expect("execution failed");
    let result = result
        .expect("return value expected")
        .as_u32()
        .expect("u32 expected as a return type");
    assert_eq!(result, 66);
}

No runtime deps

~0–2MB
~38K SLoC