bug fixes

This commit is contained in:
2024-05-25 13:12:09 +02:00
parent 4cbf46da53
commit 5fafd054b1
4 changed files with 31 additions and 50 deletions
+10 -9
View File
@@ -24,33 +24,34 @@ fn main() {
let args = Args::parse();
let file_content = fs::read_to_string(&args.file)
.expect("Error reading file");
if Path::new("wyst_tmp").exists() {
fs::remove_dir_all("wyst_tmp").expect("err rm wyst_tmp");
if Path::new("build").exists() {
fs::remove_dir_all("build").expect("err rm build");
}
fs::create_dir("wyst_tmp").expect("error making wyst_tmp");
fs::create_dir("build").expect("error making build");
let transpiled_code = transpiler::transpile(file_content, 0, LexerState { line: 1, column: 0 }, &mut Options::default());
match args.rust {
Some(ref rust_file_name) => {
// Write transpiled code to Rust file
compile::write_to_rust_file(&transpiled_code, rust_file_name)
compile::write_to_rust_file(&transpiled_code, ("build/".to_string()+rust_file_name).as_str())
.expect("Error writing to Rust file");
println!("Transpiled code written to {}", rust_file_name);
}
None => {
// No Rust file specified, print transpiled code
println!("{}", transpiled_code);
if !args.compile.is_some() {
println!("{}", transpiled_code);
}
}
}
match args.compile {
Some(ref exe_name) => {
// Compile transpiled Rust code into executable
compile::write_to_rust_file(&transpiled_code, "wyst_tmp/temp.rs")
compile::write_to_rust_file(&transpiled_code, "build/temp.rs")
.expect("Error writing to temporary Rust file");
compile::compile_to_executable("wyst_tmp/temp.rs", exe_name)
compile::compile_to_executable("build/temp.rs", exe_name)
.expect("Error compiling to executable");
fs::remove_dir_all("wyst_tmp").expect("err rm wyst_tmp");
fs::remove_dir_all("build").expect("err rm build");
}
None => {}
}