Remove all checked in *.wasm files to the repo (#563)
* Tidy up the `hello` example for `wasmtime` * Remove the `*.wat` and `*.wasm` files and instead just inline the `*.wat` into the example. * Touch up comments so they're not just a repeat of the `println!` below. * Move `*.wat` for `memory` example inline No need to handle auxiliary files with the ability to parse it inline! * Move `multi.wasm` inline into `multi.rs` example * Move `*.wasm` for gcd example inline * Move `*.wat` inline with `import_calling_export` test * Remove checked in `lightbeam/test.wasm` Instead move the `*.wat` into the source and parse it into wasm there. * Run rustfmt
This commit is contained in:
@@ -1,34 +1,16 @@
|
||||
use lightbeam::translate;
|
||||
use std::fs::File;
|
||||
use std::io;
|
||||
use std::io::Read;
|
||||
use std::path::Path;
|
||||
|
||||
fn read_to_end<P: AsRef<Path>>(path: P) -> io::Result<Vec<u8>> {
|
||||
let mut buffer = Vec::new();
|
||||
if path.as_ref() == Path::new("-") {
|
||||
let stdin = io::stdin();
|
||||
let mut stdin = stdin.lock();
|
||||
stdin.read_to_end(&mut buffer)?;
|
||||
} else {
|
||||
let mut file = File::open(path)?;
|
||||
file.read_to_end(&mut buffer)?;
|
||||
}
|
||||
Ok(buffer)
|
||||
}
|
||||
const WAT: &str = r#"
|
||||
(module
|
||||
(func (param i32) (param i32) (result i32) (i32.add (get_local 0) (get_local 1)))
|
||||
)
|
||||
"#;
|
||||
|
||||
fn maybe_main() -> Result<(), String> {
|
||||
let data = read_to_end("test.wasm").map_err(|e| e.to_string())?;
|
||||
let translated = translate(&data).map_err(|e| e.to_string())?;
|
||||
let result: u32 = translated.execute_func(0, (5u32, 3u32)).unwrap();
|
||||
fn main() -> anyhow::Result<()> {
|
||||
let data = wat::parse_str(WAT)?;
|
||||
let translated = translate(&data)?;
|
||||
let result: u32 = translated.execute_func(0, (5u32, 3u32))?;
|
||||
println!("f(5, 3) = {}", result);
|
||||
|
||||
Ok(())
|
||||
}
|
||||
|
||||
fn main() {
|
||||
match maybe_main() {
|
||||
Ok(()) => (),
|
||||
Err(e) => eprintln!("error: {}", e),
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user