updated assembler to write to binary files correctly 🤦

This commit is contained in:
2026-02-06 15:15:10 +00:00
parent 1fcfb3120b
commit bbcef7178f
3 changed files with 34 additions and 65 deletions
+11 -6
View File
@@ -24,7 +24,7 @@ pub mod prelude {
pub use crate::tooling::project;
}
use std::path::Path;
use std::{fs, path::Path};
use num_cpus as _;
use threadpool as _;
@@ -35,11 +35,16 @@ pub fn assemble_file(input: &str, output: &str) -> Result<(), std::io::Error> {
let mut engine = CompilerEngine::new();
engine.start_compilation(Path::new(input));
let result = engine.wait_for_result().unwrap();
for instruction in result {
if let Err(e) = std::fs::write(output, instruction.encode().to_be_bytes()) {
eprintln!("Failed to write to output file: {e}");
std::process::exit(1);
}
let buffer: Vec<u8> = result
.iter()
.flat_map(|instruction| instruction.encode().to_be_bytes())
.collect();
if let Err(e) = fs::write(output, buffer) {
eprintln!("Failed to write to output file: {e}");
std::process::exit(1);
}
Ok(())
}
+2 -15
View File
@@ -3,6 +3,7 @@ use num_cpus as _;
use threadpool as _;
use assembler::{
assemble_file,
prelude::*,
tooling::{brainf, project},
};
@@ -46,19 +47,5 @@ fn main() {
let input_path = &args[2];
let output_path = &args[4];
let src = PathBuf::from(input_path);
// Initialize the compiler engine
let mut compiler = CompilerEngine::new();
compiler.start_compilation(&src);
// Or block until done
let result = compiler.wait_for_result().unwrap();
for instruction in result {
if let Err(e) = fs::write(output_path, instruction.encode().to_be_bytes()) {
eprintln!("Failed to write to output file: {e}");
std::process::exit(1);
}
}
assemble_file(input_path, output_path).unwrap();
}