From 0eaf38ead0551ea9ab42f37cc7232cf389a4f6d0 Mon Sep 17 00:00:00 2001 From: Anas Elgarhy Date: Sat, 8 Oct 2022 01:11:22 +0200 Subject: [PATCH] =?UTF-8?q?Improve=20the=20code=20=F0=9F=92=99?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/interpreter.rs | 12 ++++++------ .../{print_hi_yooo.brainfuck => print_hi_yooo.bf} | 0 ..._print_hi.brainfuck => read_name_and_print_hi.bf} | 0 3 files changed, 6 insertions(+), 6 deletions(-) rename test_code/{print_hi_yooo.brainfuck => print_hi_yooo.bf} (100%) rename test_code/{read_name_and_print_hi.brainfuck => read_name_and_print_hi.bf} (100%) diff --git a/src/interpreter.rs b/src/interpreter.rs index 6ff00c0..0252624 100644 --- a/src/interpreter.rs +++ b/src/interpreter.rs @@ -51,7 +51,7 @@ impl Interpreter { Ok(()) } - fn run_brainfuck_code(&mut self, bf_code: &str) -> Result<(), error::InterpreterError> { + fn run_brainfuck_code(&mut self, bf_code: &str) -> Result<(), InterpreterError> { for (i, ch) in bf_code.chars().enumerate() { match BfCommand::from_char(ch, i) { Some(cmd) => { @@ -66,7 +66,7 @@ impl Interpreter { Ok(()) } - fn execute(&mut self, cmd: BfCommand) -> Result<(), error::InterpreterError> { + fn execute(&mut self, cmd: BfCommand) -> Result<(), InterpreterError> { match cmd { BfCommand::IncPtr => { self.pointer += 1; @@ -74,7 +74,7 @@ impl Interpreter { if self.features.contains(&arguments::Feature::ReversePointer) { self.pointer = 0; } else { - return Err(error::InterpreterError::new( + return Err(InterpreterError::new( format!("Pointer out of bounds {}", self.pointer), 11, )); @@ -86,7 +86,7 @@ impl Interpreter { if self.features.contains(&arguments::Feature::ReversePointer) { self.pointer = self.array_size - 1; } else { - return Err(error::InterpreterError::new( + return Err(InterpreterError::new( format!("Pointer out of bounds {}", self.pointer), 11, )); @@ -109,7 +109,7 @@ impl Interpreter { self.cells[self.pointer] = match std::io::stdin().bytes().next() { Some(Ok(byte)) => byte, Some(Err(e)) => { - return Err(error::InterpreterError::new( + return Err(InterpreterError::new( format!("Failed to read byte from stdin: {}", e), 12, )); @@ -135,7 +135,7 @@ impl Interpreter { } } _ => { - return Err(error::InterpreterError::new( + return Err(InterpreterError::new( format!("Unmatched closing bracket at position {}", i), 14, )); diff --git a/test_code/print_hi_yooo.brainfuck b/test_code/print_hi_yooo.bf similarity index 100% rename from test_code/print_hi_yooo.brainfuck rename to test_code/print_hi_yooo.bf diff --git a/test_code/read_name_and_print_hi.brainfuck b/test_code/read_name_and_print_hi.bf similarity index 100% rename from test_code/read_name_and_print_hi.brainfuck rename to test_code/read_name_and_print_hi.bf