add breakpoints on !

This commit is contained in:
Crispy 2023-12-29 11:22:34 +01:00
parent 6b4b49142d
commit 91f3d32b2b

View file

@ -29,6 +29,7 @@ enum State {
TooFarLeft, TooFarLeft,
EndOfProgram, EndOfProgram,
StoppedOnMemoryValue, StoppedOnMemoryValue,
BreakPointHit,
} }
#[derive(Debug)] #[derive(Debug)]
@ -48,6 +49,7 @@ enum Command {
Write, Write,
BeginLoop(usize), BeginLoop(usize),
EndLoop(usize), EndLoop(usize),
Break,
End, End,
} }
@ -229,6 +231,7 @@ impl BFInterpreter {
self.program_ptr = start_of_loop; self.program_ptr = start_of_loop;
} }
} }
Command::Break => self.state = State::BreakPointHit,
Command::End => (), Command::End => (),
} }
@ -275,6 +278,7 @@ fn parse(source_text: &str) -> Vec<DebugCommand> {
Command::EndLoop(last_loop_start) Command::EndLoop(last_loop_start)
} }
'!' => Command::Break,
_ => continue, _ => continue,
}; };
out.push(DebugCommand { out.push(DebugCommand {
@ -314,7 +318,8 @@ impl Display for Command {
Command::Write => '.', Command::Write => '.',
Command::BeginLoop(_) => '[', Command::BeginLoop(_) => '[',
Command::EndLoop(_) => ']', Command::EndLoop(_) => ']',
Command::End => '_', Command::Break => '!',
Command::End => ' ',
} }
) )
} }