Created
July 14, 2020 15:24
-
-
Save alexcrichton/49d60787351aa04434044ff3e49d94fc to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
fn main() { | |
let n = 42; | |
println!("fib({}) = {}", n, fib(n)); | |
} | |
fn fib(n: u32) -> u32 { | |
if n <= 2 { | |
1 | |
} else { | |
fib(n - 1) + fib(n - 2) | |
} | |
} |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
use wasmtime::*; | |
fn main() -> Result<(), Box<dyn std::error::Error>> { | |
let mut config = Config::new(); | |
config.profiler(ProfilingStrategy::JitDump)?; | |
let engine = Engine::new(&config); | |
let store = Store::new(&engine); | |
let module = Module::from_file(&engine, "./fib.wasm")?; | |
let instance = Instance::new(&store, &module, &[])?; | |
let start = instance.get_func("main").unwrap(); | |
let start = start.get2::<i32, i32, i32>()?; | |
let f = if false { | |
Func::wrap(&store, move || { | |
start(0, 0)?; | |
Ok(()) | |
}) | |
} else { | |
let ty = FuncType::new(Box::new([]), Box::new([])); | |
Func::new(&store, ty, move |_, _, _| { | |
start(0, 0)?; | |
Ok(()) | |
}) | |
}; | |
f.call(&[]).unwrap(); | |
Ok(()) | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment