This commit is contained in:
viridian 2024-05-09 19:10:31 +02:00
parent 620db0e5d1
commit 87d554f8e8
Signed by: viridian
GPG key ID: DCD4DF95CE23FE8C

View file

@ -11,7 +11,7 @@ fn main() {
let program = std::fs::read_to_string(args.get(1).unwrap()).unwrap();
let mut machine = Machine::new(program);
if let Some(_) = args.get(2) {
if args.get(2).is_some() {
loop {
let mut input = String::new();
std::io::stdin().read_line(&mut input).unwrap();
@ -63,6 +63,8 @@ struct Machine {
data: Vec<Cell>,
instructions: Vec<Instruction>,
}
#[derive(Debug, Default, Clone, Copy, PartialEq)]
struct Cell {
value: u8,
@ -170,7 +172,7 @@ impl Machine {
.get(self.data_pointer)
.unwrap_or(&Cell { value: 0 })
.value;
let c: char = (value as u8).into();
let c: char = value.into();
print!("{c}");
}
@ -178,7 +180,7 @@ impl Machine {
let mut input = String::new();
std::io::stdin().read_line(&mut input).unwrap();
let value = *input.into_bytes().first().unwrap() as u8;
let value = *input.into_bytes().first().unwrap();
let cell = Cell { value };
@ -229,7 +231,7 @@ impl Machine {
let repetitions: usize = input.trim().parse().unwrap();
let mut bar = indicatif::ProgressBar::new(repetitions as u64);
let bar = indicatif::ProgressBar::new(repetitions as u64);
bar.set_style(
ProgressStyle::with_template(
"{bar:40} | {human_pos}/{human_len} | {eta_precise} | {elapsed_precise}",
@ -363,9 +365,7 @@ fn locate_jmp_target_jiz(
let mut data_pointer = index + 1;
let mut searched_jinz = 1;
let mut instruction_index = instruction_index;
if instruction_index != 0 {
instruction_index -= 1;
}
instruction_index = instruction_index.saturating_sub(1);
while searched_jinz != 0 {
if data_pointer == program_vector.len() {