| 63 | } |
| 64 | |
| 65 | pub fn run_file(&mut self, path: PathBuf) { |
| 66 | match fs::read_to_string(&path) { |
| 67 | Ok(source) => { |
| 68 | let source: &'static str = Box::leak(source.into_boxed_str()); |
| 69 | if let Err(VmError::CompileError) = self.compile(source) { |
| 70 | std::process::exit(65); |
| 71 | } |
| 72 | if let Err(VmError::RuntimeError(err)) = self.interpret() { |
| 73 | eprintln!("{err}"); |
| 74 | std::process::exit(70); |
| 75 | } |
| 76 | } |
| 77 | Err(err) => { |
| 78 | eprintln!("Failed to read file '{}': {}", path.display(), err); |
| 79 | std::process::exit(1); |
| 80 | } |
| 81 | } |
| 82 | } |
| 83 | |
| 84 | fn init_stdlib(&mut self) { |
| 85 | self.arena.mutate_root(|_mc, state| { |