From a565b195097032548f09f86d93552d244f86238b Mon Sep 17 00:00:00 2001 From: Marco Thomas Date: Tue, 22 Apr 2025 10:33:23 +0900 Subject: [PATCH] chore: add some comments --- src/interpret.rs | 11 ++++++----- 1 file changed, 6 insertions(+), 5 deletions(-) diff --git a/src/interpret.rs b/src/interpret.rs index 4c557ab..54acefd 100644 --- a/src/interpret.rs +++ b/src/interpret.rs @@ -29,11 +29,11 @@ pub fn interpret(code: &str) -> Vec { log::debug!("Read user input: {}", input_buf[0]); } '[' => { - // loop start + // skip loop if memory[head] == 0 { + // skip nested brackets and increment pc until the matching + // closing bracket is found let mut count_brackets = 1; - - // find nested brackets while count_brackets > 0 { pc += 1; if pc >= code_bytes.len() { @@ -48,6 +48,7 @@ pub fn interpret(code: &str) -> Vec { _ => {} } } + // execute loop } else { // save pc to jump back to log::info!("Pushing location {} onto loop stack", pc); @@ -55,7 +56,7 @@ pub fn interpret(code: &str) -> Vec { } } ']' => { - // loop terminator + // loop back if memory[head] != 0 { // jump back to loop beginning if let Some(start_pc) = loop_stack.last() { @@ -63,8 +64,8 @@ pub fn interpret(code: &str) -> Vec { } else { panic!("Loop stack empty, but still called!") } + // loop done, continue normally } else { - // loop done, continue normally let location = loop_stack.pop(); log::info!("Done with loop at location {}", location.unwrap()); }