improve error handling

This commit is contained in:
Vinzenz Schroeter 2024-12-15 00:43:59 +01:00
parent 5ad6baa30d
commit a4a027b448
24 changed files with 238 additions and 112 deletions

View file

@ -14,7 +14,7 @@ struct Cli {
fn main() {
let args: Cli = clap::Parser::parse();
let parser = EiParser::from_file(&args.ei_file).unwrap();
let parser = EiParser::from_file(&args.ei_file).expect("failed to parse input file");
let instructions = match parser.parse() {
Ok(i) => i,
Err(e) => {
@ -33,11 +33,19 @@ fn main() {
println!("done building machine: \n{machine}");
while machine.step() {
if args.verbose {
println!("executed instruction: {machine:?}");
loop {
match machine.step() {
Ok(_) => {
if args.verbose {
println!("executed instruction: {machine:?}");
}
}
Err(e) => {
eprintln!("{e}");
break;
}
}
}
println!("final state: \n{machine}");
println!("final state: \n{}", machine.registers);
}