brainfuck interpreter
brainfuck cli rust
5

Configure Feed

Select the types of activity you want to include in your feed.

feat: added tracing

prints the current cell on tape, the value within, the current
instruction the interpreter is on, and where in the instructions the
VM::run function is at*

* although as of right now its just an integer pointing at the tokenized
string, not very useful if you have line breaks and such... still, its
a start!

digi.rip (Jun 3, 2026, 10:23 AM EDT) acf7eb25 9f3db16c

+24 -12
+24 -12
src/evaluator.rs
··· 1 1 use clap::ValueEnum; 2 2 use std::fmt; 3 + use std::io::Write; 3 4 4 5 #[derive(Debug)] 5 6 pub enum RuntimeError { ··· 271 272 ) -> Result<(), RuntimeError> { 272 273 while self.inst_pointer < tokens.len() { 273 274 let current = tokens[self.inst_pointer]; 275 + 276 + if self.tracing { 277 + std::io::stdout().flush().ok(); 278 + print!( 279 + "\nTape: {}[{}] ", 280 + self.data_pointer, self.tape[self.data_pointer] 281 + ); 282 + print!("\nInst: '{}' @ {}", current as char, self.inst_pointer); 283 + } 284 + 274 285 match current { 275 286 b'>' => { 276 287 self.move_right()?; ··· 286 297 } 287 298 288 299 b',' => { 300 + if self.tracing { 301 + // std::io::stdout().flush().ok(); 302 + print!("\nInput: "); 303 + std::io::stdout().flush().ok(); 304 + } 305 + 289 306 if self.input_type == IOFormat::Ascii { 290 307 self.read_ascii(&mut reader)?; 291 308 } else if self.input_type == IOFormat::Raw { ··· 294 311 } 295 312 296 313 b'.' => { 314 + if self.tracing { 315 + print!("\nOutput: ") 316 + } 317 + 297 318 if self.output_type == IOFormat::Ascii { 298 319 self.write_ascii(&mut writer)?; 299 320 } else if self.output_type == IOFormat::Raw { ··· 316 337 _ => Err(RuntimeError::InvalidToken(self.inst_pointer))?, 317 338 } 318 339 319 - // two types of tracing - instruction tracing and tape tracing 320 - // instruction tracing: prints current instruction being parsed and position its at 321 - // tape tracing: prints state of tape at that cycle. doesnt print cells containing 0 322 - // *unless* they've been manipulated before 323 - 324 - // Cell: 0[24] 1[76] 4[41] 325 - // Inst: '>' @ char 3 326 - 327 - // Very long tape? shouldnt print all cells at once, would clog screen 328 - // perhaps a user option? 329 - // Cell: ... 13[245] 25[98] 26[41] 31[45] ... 330 - // Inst: '>' @ char 48 340 + if self.tracing { 341 + println!(); 342 + } 331 343 332 344 self.inst_pointer += 1; 333 345 }