chore: add some comments

This commit is contained in:
2025-04-22 10:33:23 +09:00
parent d1d06e5cc2
commit a565b19509

View File

@@ -29,11 +29,11 @@ pub fn interpret(code: &str) -> Vec<u8> {
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<u8> {
_ => {}
}
}
// 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<u8> {
}
}
']' => {
// 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<u8> {
} else {
panic!("Loop stack empty, but still called!")
}
} else {
// loop done, continue normally
} else {
let location = loop_stack.pop();
log::info!("Done with loop at location {}", location.unwrap());
}