use std::io::{Read, Write}; use bedrock_asm::*; fn main() { // Read source code from standard input let mut source_code = String::new(); if let Err(err) = std::io::stdin().read_to_string(&mut source_code) { eprintln!("Could not read from standard input, quitting."); eprintln!("({err:?})"); std::process::exit(1); }; let (bytecode, tokens) = assemble(&source_code); let mut is_error = false; for token in &tokens { if token.print_error(&source_code) { is_error = true }; } eprintln!("Assembled program in {} bytes.", bytecode.len()); if is_error { std::process::exit(1) } // Write bytecode to standard output if let Err(err) = std::io::stdout().write_all(&bytecode) { eprintln!("Could not write to standard output, quitting."); eprintln!("({err:?})"); std::process::exit(1); } }