@@ -0,0 +1,5 @@
|
||||
use wasmtime::*;
|
||||
|
||||
pub fn say_hi (_caller : Caller<'_, u32>) {
|
||||
println! ("hiiii~")
|
||||
}
|
||||
@@ -0,0 +1,35 @@
|
||||
mod gyehoek;
|
||||
|
||||
use std::io;
|
||||
use std::io::Read;
|
||||
use clio::*;
|
||||
use clap::Parser;
|
||||
use wasmtime::*;
|
||||
|
||||
/// A runtime for Gyehoek scheme.
|
||||
#[derive(Parser, Debug)]
|
||||
#[command(name = "gyehoek", version, about, long_about = None)]
|
||||
struct Args {
|
||||
/// Path to Wasm binary or textual source
|
||||
#[clap(value_parser)]
|
||||
wasm: Input,
|
||||
}
|
||||
|
||||
fn read<R : Read> (mut rdr : R) -> io::Result<Vec<u8>> {
|
||||
let mut buf = vec! [];
|
||||
rdr.read_to_end (&mut buf)?;
|
||||
Ok (buf)
|
||||
}
|
||||
|
||||
pub fn main () -> wasmtime::Result<()> {
|
||||
let args = Args::parse ();
|
||||
let engine = Engine::default ();
|
||||
let module = Module::new (&engine, read (args.wasm)?)?;
|
||||
let mut linker = Linker::new (&engine);
|
||||
linker.func_wrap ("gyehoek", "say-hi", gyehoek::say_hi)?;
|
||||
let mut store : Store<u32> = Store::new (&engine, 4);
|
||||
let instance = linker.instantiate (&mut store, &module)?;
|
||||
let main = instance.get_typed_func::<(),()> (&mut store, "main")?;
|
||||
main.call (&mut store, ())?;
|
||||
Ok (())
|
||||
}
|
||||
Reference in New Issue
Block a user