2019-03-01 23:48:43 +00:00
|
|
|
use wasmer_runtime::{compile, error, imports, Func, Value};
|
2019-02-28 21:18:00 +00:00
|
|
|
|
|
|
|
use wabt::wat2wasm;
|
|
|
|
|
|
|
|
static WAT: &'static str = r#"
|
|
|
|
(module
|
2019-03-01 23:48:43 +00:00
|
|
|
(type (;0;) (func (result i32)))
|
|
|
|
(func (;0;) (type 0) (result i32)
|
|
|
|
block (result i32) ;; label = @1
|
|
|
|
i32.const 1
|
|
|
|
end
|
|
|
|
return)
|
|
|
|
(export "as-return-value" (func 0))
|
2019-02-28 21:18:00 +00:00
|
|
|
)
|
|
|
|
"#;
|
|
|
|
|
|
|
|
fn get_wasm() -> Vec<u8> {
|
|
|
|
wat2wasm(WAT).unwrap()
|
|
|
|
}
|
|
|
|
|
|
|
|
fn main() -> Result<(), error::Error> {
|
|
|
|
let wasm = get_wasm();
|
|
|
|
|
|
|
|
let module = compile(&wasm)?;
|
|
|
|
|
|
|
|
let imports = imports! {};
|
|
|
|
|
2019-03-01 23:48:43 +00:00
|
|
|
println!("instantiating");
|
2019-02-28 21:18:00 +00:00
|
|
|
let instance = module.instantiate(&imports)?;
|
|
|
|
|
2019-03-01 23:48:43 +00:00
|
|
|
let foo = instance.dyn_func("as-call-value")?;
|
2019-02-28 21:18:00 +00:00
|
|
|
|
2019-03-01 23:48:43 +00:00
|
|
|
let result = foo.call(&[]);
|
2019-02-28 21:18:00 +00:00
|
|
|
|
|
|
|
println!("result: {:?}", result);
|
|
|
|
|
|
|
|
Ok(())
|
|
|
|
}
|