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() {
// 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;
}

View File

@@ -28,13 +28,17 @@ fn main() {
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<Box<dyn Read>> = BufReader::new(Box::new(stdin()));
let mut writer: BufWriter<Box<dyn Write>> = 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();
}

View File

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

1
test.bf Normal file
View File

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