diff --git a/src/machine.rs b/src/machine.rs index 558f936..9c2adb3 100644 --- a/src/machine.rs +++ b/src/machine.rs @@ -34,7 +34,8 @@ impl<'a> Machine<'a> { while self.ip < self.code.len() { // get current instruction let instruction = &self.code[self.ip]; - println!("{:?} ; {}", instruction, self.mp); + //println!("{}/{}", self.ip, self.code.len()); + //println!("{:?} ; {}", instruction, self.mp); // match type and execute match instruction.itype { InstructionType::Increment => self.do_increment(instruction.argument), @@ -55,6 +56,7 @@ impl<'a> Machine<'a> { continue; } } + _ => panic!("Unknown instruction!"), } self.ip += 1; } diff --git a/src/main.rs b/src/main.rs index 31cbadf..9168465 100644 --- a/src/main.rs +++ b/src/main.rs @@ -27,14 +27,18 @@ fn main() { // create brainfuck parser and turn the code into instructions let mut parser = Parser::new(code); parser.parse(); + + for elem in parser.instructions { + println!("{:?} {}", elem.itype, elem.argument); + } // create reader and writer objects let mut reader: BufReader> = BufReader::new(Box::new(stdin())); let mut writer: BufWriter> = BufWriter::new(Box::new(stdout())); // create machine and load instructions - let mut machine = Machine::new(parser.instructions, &mut reader, &mut writer); + //let mut machine = Machine::new(parser.instructions, &mut reader, &mut writer); // execute code - machine.execute(); + //machine.execute(); } diff --git a/src/parser.rs b/src/parser.rs index a003fff..f9dd343 100644 --- a/src/parser.rs +++ b/src/parser.rs @@ -35,7 +35,6 @@ impl Parser { ']' => self.load_instruction(JumpIfNotZero, 1), _ => (), } - self.position += 1; } } diff --git a/test.bf b/test.bf new file mode 100644 index 0000000..c09bfeb --- /dev/null +++ b/test.bf @@ -0,0 +1 @@ +----[---->+<]>++.