Add basic support for running external programs
This commit is contained in:
parent
f197b1f493
commit
da5958a125
|
@ -1,2 +1,2 @@
|
|||
/target
|
||||
inp.txt
|
||||
*.txt
|
||||
|
|
|
@ -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),
|
||||
}
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue