mirror of
https://tildegit.org/karx/sandwich.git
synced 2024-05-19 05:25:48 -05:00
Add basic support for running external programs
This commit is contained in:
parent
f197b1f493
commit
da5958a125
2
.gitignore
vendored
2
.gitignore
vendored
|
@ -1,2 +1,2 @@
|
||||||
/target
|
/target
|
||||||
inp.txt
|
*.txt
|
||||||
|
|
|
@ -140,6 +140,13 @@ impl Program {
|
||||||
builder
|
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) {
|
fn parse(&mut self, instruction: &String) {
|
||||||
// Opcode is the first character, arguments are everything after the first char
|
// Opcode is the first character, arguments are everything after the first char
|
||||||
let opcode = instruction.chars().collect::<Vec<char>>()[0];
|
let opcode = instruction.chars().collect::<Vec<char>>()[0];
|
||||||
|
@ -154,6 +161,7 @@ impl Program {
|
||||||
'd' => println!("{}", eval::do_math(self.args_or_vars(&arguments), '/')),
|
'd' => println!("{}", eval::do_math(self.args_or_vars(&arguments), '/')),
|
||||||
'l' => self.add_var(&arguments),
|
'l' => self.add_var(&arguments),
|
||||||
'f' => self.add_func(&arguments),
|
'f' => self.add_func(&arguments),
|
||||||
|
'i' => self.run_external(arguments),
|
||||||
_ => panic!("SyntaxError at opcode {}: Unknown opcode {}", self.pc, opcode),
|
_ => panic!("SyntaxError at opcode {}: Unknown opcode {}", self.pc, opcode),
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in a new issue