Add basic support for running external programs

This commit is contained in:
~karx 2021-02-16 18:42:06 +00:00
parent f197b1f493
commit da5958a125
2 changed files with 9 additions and 1 deletions

2
.gitignore vendored
View File

@ -1,2 +1,2 @@
/target
inp.txt
*.txt

View File

@ -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::<Vec<char>>()[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),
}
}