Skip to content

Commit

Permalink
allow user to modify std path
Browse files Browse the repository at this point in the history
  • Loading branch information
ludverse committed Mar 16, 2024
1 parent 5cb78a0 commit 174b6a1
Show file tree
Hide file tree
Showing 3 changed files with 27 additions and 7 deletions.
1 change: 0 additions & 1 deletion example.ox
Original file line number Diff line number Diff line change
@@ -1,2 +1 @@
print("examp");
print(to_string(100));
29 changes: 24 additions & 5 deletions src/lib.rs
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
use crate::helpers::destructive_loop;

pub mod tokenizer;
pub mod parser;
pub mod interpreter;
Expand All @@ -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<String>
}

impl Config {
pub fn new(args: &mut impl Iterator<Item = String>) -> 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")
}
}
}
}
Expand Down
4 changes: 3 additions & 1 deletion src/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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()
Expand Down

0 comments on commit 174b6a1

Please sign in to comment.