| 25 | use std::process; |
| 26 | |
| 27 | fn safe_main() -> i32 { |
| 28 | let args: Vec<String> = env::args().collect(); |
| 29 | let path = match args.as_slice() { |
| 30 | [_, path] => path, |
| 31 | _ => { |
| 32 | eprintln!("Usage error: expected a file name"); |
| 33 | process::exit(1); |
| 34 | } |
| 35 | }; |
| 36 | |
| 37 | let mut machine = endbasic_std::MachineBuilder::default().build(); |
| 38 | |
| 39 | let mut input = match fs::File::open(path) { |
| 40 | Ok(file) => file, |
| 41 | Err(e) => { |
| 42 | eprintln!("ERROR: {}", e); |
| 43 | process::exit(1); |
| 44 | } |
| 45 | }; |
| 46 | |
| 47 | match machine.compile(&mut input) { |
| 48 | Ok(()) => match block_on(machine.exec()) { |
| 49 | Ok(None) => 0, |
| 50 | Ok(Some(code)) => code, |
| 51 | Err(e) => { |
| 52 | eprintln!("ERROR: {}", e); |
| 53 | 1 |
| 54 | } |
| 55 | }, |
| 56 | Err(e) => { |
| 57 | eprintln!("ERROR: {}", e); |
| 58 | 1 |
| 59 | } |
| 60 | } |
| 61 | } |
| 62 | |
| 63 | fn main() { |
| 64 | // We must ensure that all destructors run (in particular, the console's destructor) before |