summaryrefslogtreecommitdiff
path: root/examples/simple2.rs
blob: a3124f86d392ddd42afc41f07a3d2ba9daa2731b (plain)
use eyre::Result;
use tinywasm::{Module, Store};

const WASM: &str = r#"
(module
  (func $return (param $lhs i32) (param $rhs i64) (result i32 i64)
    local.get $lhs
    local.get $rhs)
  (export "return" (func $return)))
"#;

fn main() -> Result<()> {
    let wasm = wat::parse_str(WASM).expect("failed to parse wat");
    let module = Module::parse_bytes(&wasm)?;
    let mut store = Store::default();
    let instance = module.instantiate(&mut store, None)?;
    let add = instance.exported_func::<(i32, i64), (i32, i64)>(&store, "return")?;

    assert_eq!(add.call(&mut store, (1, 2))?, (1, 2));
    Ok(())
}