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

@ -1,3 +1,4 @@
use echse::instructions::ExecuteInstructionError;
use echse::machine::{Machine, MachineBuilder};
use echse::parser::EiParser;
use std::collections::HashSet;
@ -129,7 +130,10 @@ impl App {
"{:03}: {}\n",
self.machine.ip, self.machine.instructions[self.machine.ip]
);
self.machine.step();
match self.machine.step() {
Ok(_) => {}
Err(e) => Self::print_exec_err(e),
}
} else {
println!("reached end of program\n");
}
@ -153,7 +157,12 @@ impl App {
}
DebugCommand::Continue => {
let mut count = 0;
while self.machine.step() {
loop {
match self.machine.step() {
Ok(_) => {}
Err(e) => eprintln!("{e}"),
}
count += 1;
if self.breakpoints.contains(&self.machine.ip) {
println!(
@ -163,6 +172,7 @@ impl App {
break;
}
}
println!(
"stepped {count} instructions, ip now at {}\n",
self.machine.ip
@ -188,7 +198,7 @@ impl App {
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) => {