diff --git a/example.ox b/example.ox index 1f75d53..35b543d 100644 --- a/example.ox +++ b/example.ox @@ -1,2 +1 @@ print("examp"); -print(to_string(100)); diff --git a/src/lib.rs b/src/lib.rs index 2626117..a508305 100644 --- a/src/lib.rs +++ b/src/lib.rs @@ -1,3 +1,5 @@ +use crate::helpers::destructive_loop; + pub mod tokenizer; pub mod parser; pub mod interpreter; @@ -12,18 +14,35 @@ pub mod errors; pub mod helpers; pub struct Config { - pub source_file: String + pub source_file: String, + pub std_file: Option } impl Config { pub fn new(args: &mut impl Iterator) -> Config { args.next(); - let source_file = args.next() - .expect("source_file not specified"); + let mut std_file = None; + + loop { + match args.next() { + Some(arg) => { + + match &arg[..] { + "--std" => { + std_file = Some(args.next().expect("std file not specified")) + }, + _ => { + return Config { + source_file: arg, + std_file + } + } + } - Config { - source_file + }, + None => panic!("source file not specified") + } } } } diff --git a/src/main.rs b/src/main.rs index 3d9c609..f770a51 100644 --- a/src/main.rs +++ b/src/main.rs @@ -34,7 +34,9 @@ fn main() -> ExitCode { let mut memory = Memory::new(); BuiltinFn::populate_memory(&mut memory); - execute_file("std.ox", &mut sim_memory, &mut memory); + let std_file = config.std_file + .unwrap_or(String::from("std.ox")); + execute_file(&std_file[..], &mut sim_memory, &mut memory); execute_file(&config.source_file[..], &mut sim_memory, &mut memory); 0.into()