mirror of
https://github.com/fluencelabs/wasmer
synced 2024-12-13 14:25:32 +00:00
59 lines
1.4 KiB
Rust
59 lines
1.4 KiB
Rust
use wasmer_runtime::{compile, error, imports, Ctx, Func, Value};
|
|
|
|
use wabt::wat2wasm;
|
|
|
|
static WAT: &'static str = r#"
|
|
(module
|
|
(type (;0;) (func (result i32)))
|
|
(func $dbz (result i32)
|
|
i32.const 42
|
|
i32.const 0
|
|
i32.div_u
|
|
)
|
|
(export "dbz" (func $dbz))
|
|
)
|
|
"#;
|
|
|
|
// static WAT2: &'static str = r#"
|
|
// (module
|
|
// (type $t0 (func (param i32)))
|
|
// (type $t1 (func))
|
|
// (func $print_i32 (export "print_i32") (type $t0) (param $lhs i32))
|
|
// (func $print (export "print") (type $t1))
|
|
// (table $table (export "table") 10 20 anyfunc)
|
|
// (memory $memory (export "memory") 1 2)
|
|
// (global $global_i32 (export "global_i32") i32 (i32.const 666)))
|
|
// "#;
|
|
|
|
fn get_wasm() -> Vec<u8> {
|
|
wat2wasm(WAT).unwrap()
|
|
}
|
|
|
|
fn foobar(ctx: &mut Ctx) -> i32 {
|
|
42
|
|
}
|
|
|
|
fn main() -> Result<(), error::Error> {
|
|
let wasm = get_wasm();
|
|
|
|
let module = compile(&wasm)?;
|
|
|
|
// let import_module = compile(&wat2wasm(WAT2).unwrap())?;
|
|
// let import_instance = import_module.instantiate(&imports! {})?;
|
|
|
|
// let imports = imports! {
|
|
// "spectest" => import_instance,
|
|
// };
|
|
|
|
println!("instantiating");
|
|
let instance = module.instantiate(&imports! {})?;
|
|
|
|
let foo = instance.dyn_func("dbz")?;
|
|
|
|
let result = foo.call(&[]);
|
|
|
|
println!("result: {:?}", result);
|
|
|
|
Ok(())
|
|
}
|