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