Restructure and compartmentalize the project

This commit is contained in:
Rerumu
2022-06-23 20:14:04 -04:00
parent 59a5a3219f
commit 223895e617
34 changed files with 105 additions and 93 deletions
+38
View File
@@ -0,0 +1,38 @@
use std::io::{Result, Write};
use parity_wasm::{deserialize_file, elements::Module};
fn load_module(name: &str) -> Module {
deserialize_file(name)
.expect("Failed to parse WebAssembly file")
.parse_names()
.unwrap_or_else(|v| v.1)
}
fn do_runtime(lock: &mut dyn Write) -> Result<()> {
let runtime = codegen_luau::RUNTIME;
let numeric = codegen_luau::NUMERIC;
writeln!(lock, "local rt = (function()")?;
writeln!(lock, "local I64 = (function()")?;
writeln!(lock, "{numeric}")?;
writeln!(lock, "end)()")?;
writeln!(lock, "{runtime}")?;
writeln!(lock, "end)()")
}
fn main() -> Result<()> {
let wasm = match std::env::args().nth(1) {
Some(name) => load_module(&name),
None => {
eprintln!("usage: wasm2luau <file>");
return Ok(());
}
};
let lock = &mut std::io::stdout().lock();
do_runtime(lock)?;
codegen_luau::from_module_untyped(&wasm, lock)
}