Counting actual instructions

master
Wynd 2024-10-20 13:56:40 +03:00
parent 7f53e13f4f
commit b416a32ee7
1 changed files with 20 additions and 6 deletions

View File

@ -33,38 +33,52 @@ fn main() {
}; };
match instruction { match instruction {
b'+' => tape[cell_index] = tape[cell_index].wrapping_add(1), b'+' => {
b'-' => tape[cell_index] = tape[cell_index].wrapping_sub(1), tape[cell_index] = tape[cell_index].wrapping_add(1);
icount += 1;
}
b'-' => {
tape[cell_index] = tape[cell_index].wrapping_sub(1);
icount += 1;
}
b'>' => { b'>' => {
cell_index = cell_index.wrapping_add(1); cell_index = cell_index.wrapping_add(1);
if tape.len() <= cell_index { if tape.len() <= cell_index {
tape.push(0); tape.push(0);
} }
icount += 1;
}
b'<' => {
cell_index = cell_index.wrapping_sub(1);
icount += 1;
}
b'.' => {
print!("{}", tape[cell_index] as char);
icount += 1;
} }
b'<' => cell_index = cell_index.wrapping_sub(1),
b'.' => print!("{}", tape[cell_index] as char),
b',' => { b',' => {
if user_input.is_empty() { if user_input.is_empty() {
user_input = input(); user_input = input();
} }
tape[cell_index] = user_input.remove(0); tape[cell_index] = user_input.remove(0);
icount += 1;
} }
b'[' => { b'[' => {
if tape[cell_index] == 0 { if tape[cell_index] == 0 {
ip = *table.get(&ip).unwrap(); ip = *table.get(&ip).unwrap();
} }
icount += 1;
} }
b']' => { b']' => {
if tape[cell_index] != 0 { if tape[cell_index] != 0 {
ip = *table.get(&ip).unwrap(); ip = *table.get(&ip).unwrap();
} }
icount += 1;
} }
_ => {} _ => {}
} }
ip += 1; ip += 1;
icount += 1;
} }
println!(); println!();