Remove the not neded filed from the interpreter struct 🗑
This commit is contained in:
parent
d58b3e07d6
commit
639c39c9f6
1 changed files with 3 additions and 5 deletions
|
@ -6,7 +6,6 @@ use std::{char, usize, vec};
|
||||||
pub struct Interpreter<'a> {
|
pub struct Interpreter<'a> {
|
||||||
pub cells: Vec<u8>,
|
pub cells: Vec<u8>,
|
||||||
pub pointer: usize,
|
pub pointer: usize,
|
||||||
pub array_size: usize,
|
|
||||||
pub bf_commands: Vec<BfCommand>,
|
pub bf_commands: Vec<BfCommand>,
|
||||||
brackets: Vec<BfCommand>,
|
brackets: Vec<BfCommand>,
|
||||||
pub input: &'a Box<dyn Read>,
|
pub input: &'a Box<dyn Read>,
|
||||||
|
@ -24,7 +23,6 @@ impl<'a> Interpreter<'a> {
|
||||||
Self {
|
Self {
|
||||||
cells: vec![0; array_size],
|
cells: vec![0; array_size],
|
||||||
pointer: 0,
|
pointer: 0,
|
||||||
array_size,
|
|
||||||
bf_commands: vec![],
|
bf_commands: vec![],
|
||||||
brackets: Vec::new(),
|
brackets: Vec::new(),
|
||||||
input,
|
input,
|
||||||
|
@ -71,7 +69,7 @@ impl<'a> Interpreter<'a> {
|
||||||
fn increment_pointer(&mut self) -> Result<(), InterpreterError> {
|
fn increment_pointer(&mut self) -> Result<(), InterpreterError> {
|
||||||
trace!("Increment pointer");
|
trace!("Increment pointer");
|
||||||
self.pointer += 1;
|
self.pointer += 1;
|
||||||
if self.pointer >= self.array_size {
|
if self.pointer >= self.cells.len() {
|
||||||
if self.features.contains(&arguments::Feature::ReversePointer) {
|
if self.features.contains(&arguments::Feature::ReversePointer) {
|
||||||
self.pointer = 0;
|
self.pointer = 0;
|
||||||
} else {
|
} else {
|
||||||
|
@ -85,7 +83,7 @@ impl<'a> Interpreter<'a> {
|
||||||
trace!("Decrement pointer");
|
trace!("Decrement pointer");
|
||||||
if self.pointer == 0 {
|
if self.pointer == 0 {
|
||||||
if self.features.contains(&arguments::Feature::ReversePointer) {
|
if self.features.contains(&arguments::Feature::ReversePointer) {
|
||||||
self.pointer = self.array_size - 1;
|
self.pointer = self.cells.len() - 1;
|
||||||
} else {
|
} else {
|
||||||
return Err(InterpreterErrorKind::PointerOutOfBounds(self.pointer).to_error());
|
return Err(InterpreterErrorKind::PointerOutOfBounds(self.pointer).to_error());
|
||||||
}
|
}
|
||||||
|
@ -154,7 +152,7 @@ impl<'a> Interpreter<'a> {
|
||||||
}
|
}
|
||||||
|
|
||||||
pub fn reset(&mut self) {
|
pub fn reset(&mut self) {
|
||||||
self.cells = vec![0; self.array_size];
|
self.cells = vec![0; self.cells.len()];
|
||||||
self.pointer = 0;
|
self.pointer = 0;
|
||||||
self.brackets = Vec::new();
|
self.brackets = Vec::new();
|
||||||
self.bf_commands = Vec::new();
|
self.bf_commands = Vec::new();
|
||||||
|
|
Loading…
Reference in a new issue