@@ -0,0 +1 @@
|
||||
target/
|
||||
Generated
+1865
File diff suppressed because it is too large
Load Diff
@@ -0,0 +1,9 @@
|
||||
[package]
|
||||
name = "gyehoek-runtime"
|
||||
version = "0.1.0"
|
||||
edition = "2024"
|
||||
|
||||
[dependencies]
|
||||
clap = { version = "4.6.1", features = ["derive"] }
|
||||
clio = { version = "0.3.5", features = ["clap-parse"] }
|
||||
wasmtime = "46.0.1"
|
||||
@@ -0,0 +1,12 @@
|
||||
{ rustPlatform
|
||||
}:
|
||||
|
||||
rustPlatform.buildRustPackage (finalAttrs: {
|
||||
pname = "gyehoek-runtime";
|
||||
version = "0.1.0";
|
||||
src = ./.;
|
||||
cargoLock = {
|
||||
lockFile = ./Cargo.lock;
|
||||
};
|
||||
doCheck = true;
|
||||
})
|
||||
@@ -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 {
|
||||
/// Input file
|
||||
#[clap(value_parser)]
|
||||
input: 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.input)?)?;
|
||||
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 (())
|
||||
}
|
||||
@@ -0,0 +1,6 @@
|
||||
(module
|
||||
(import "gyehoek" "say-hi" (func $say-hi))
|
||||
(func (export "main")
|
||||
(call $say-hi)
|
||||
(call $say-hi)
|
||||
(call $say-hi)))
|
||||
Reference in New Issue
Block a user