test stuff
This commit is contained in:
@@ -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;
|
||||
}
|
||||
|
||||
@@ -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<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();
|
||||
}
|
||||
|
||||
@@ -35,7 +35,6 @@ impl Parser {
|
||||
']' => self.load_instruction(JumpIfNotZero, 1),
|
||||
_ => (),
|
||||
}
|
||||
|
||||
self.position += 1;
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user