test stuff

This commit is contained in:
2021-09-27 00:35:10 +02:00
parent 32a9e03680
commit d3cdf1dbdc
4 changed files with 10 additions and 4 deletions

View File

@@ -34,7 +34,8 @@ impl<'a> Machine<'a> {
while self.ip < self.code.len() { while self.ip < self.code.len() {
// get current instruction // get current instruction
let instruction = &self.code[self.ip]; 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 type and execute
match instruction.itype { match instruction.itype {
InstructionType::Increment => self.do_increment(instruction.argument), InstructionType::Increment => self.do_increment(instruction.argument),
@@ -55,6 +56,7 @@ impl<'a> Machine<'a> {
continue; continue;
} }
} }
_ => panic!("Unknown instruction!"),
} }
self.ip += 1; self.ip += 1;
} }

View File

@@ -27,14 +27,18 @@ fn main() {
// create brainfuck parser and turn the code into instructions // create brainfuck parser and turn the code into instructions
let mut parser = Parser::new(code); let mut parser = Parser::new(code);
parser.parse(); parser.parse();
for elem in parser.instructions {
println!("{:?} {}", elem.itype, elem.argument);
}
// create reader and writer objects // create reader and writer objects
let mut reader: BufReader<Box<dyn Read>> = BufReader::new(Box::new(stdin())); let mut reader: BufReader<Box<dyn Read>> = BufReader::new(Box::new(stdin()));
let mut writer: BufWriter<Box<dyn Write>> = BufWriter::new(Box::new(stdout())); let mut writer: BufWriter<Box<dyn Write>> = BufWriter::new(Box::new(stdout()));
// create machine and load instructions // 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 // execute code
machine.execute(); //machine.execute();
} }

View File

@@ -35,7 +35,6 @@ impl Parser {
']' => self.load_instruction(JumpIfNotZero, 1), ']' => self.load_instruction(JumpIfNotZero, 1),
_ => (), _ => (),
} }
self.position += 1; self.position += 1;
} }
} }

1
test.bf Normal file
View File

@@ -0,0 +1 @@
----[---->+<]>++.