diff --git a/.gitignore b/.gitignore index 5f36a74..eed3cc5 100644 --- a/.gitignore +++ b/.gitignore @@ -1,2 +1,2 @@ /target -inp.txt +*.txt diff --git a/src/main.rs b/src/main.rs index 9788513..268f7e2 100644 --- a/src/main.rs +++ b/src/main.rs @@ -140,6 +140,13 @@ impl Program { builder } + fn run_external(&mut self, filename: String) { + // Read contents of the provided file and construct a symbolic Program from it + let contents = fs::read_to_string(filename).expect("Something went wrong reading the file"); + let mut prog = Program::from_string(contents); + prog.run(); + } + fn parse(&mut self, instruction: &String) { // Opcode is the first character, arguments are everything after the first char let opcode = instruction.chars().collect::>()[0]; @@ -154,6 +161,7 @@ impl Program { 'd' => println!("{}", eval::do_math(self.args_or_vars(&arguments), '/')), 'l' => self.add_var(&arguments), 'f' => self.add_func(&arguments), + 'i' => self.run_external(arguments), _ => panic!("SyntaxError at opcode {}: Unknown opcode {}", self.pc, opcode), } }