use std::io::{Read, Write}; use bedrock_asm::*; fn main() { // Read source code from standard input let mut source_code = String::new(); let mut stdin = std::io::stdin().lock(); if let Err(err) = 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); for token in &tokens { token.print_error(&source_code); } eprintln!("Assembled program in {} bytes.", bytecode.len()); let bytecode_len = bytecode.len(); // Write bytecode to standard output let mut stdout = std::io::stdout().lock(); match stdout.write(&bytecode) { Ok(len) => if len != bytecode_len { eprintln!("Only wrote {len} of {bytecode_len} bytes") } Err(err) => { eprintln!("Could not write to standard output, quitting."); eprintln!("({err:?})"); std::process::exit(1); } } }