Skip to content

Commit

Permalink
Initialize with std
Browse files Browse the repository at this point in the history
  • Loading branch information
WilliamRagstad committed Nov 7, 2024
1 parent 0a56486 commit 9601343
Show file tree
Hide file tree
Showing 3 changed files with 14 additions and 2 deletions.
5 changes: 5 additions & 0 deletions src/commands/eval.rs
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ use lento_core::{
value::Value,
},
parser::parser::{from_string, Parser},
stdlib::init::stdlib,
type_checker::{checker::TypeChecker, types::GetType},
};

Expand All @@ -24,9 +25,13 @@ pub fn handle_command_eval(args: &ArgMatches, _arg_parser: &mut Command) {
}
let expr = args.get_one::<String>("expr").unwrap().to_owned();

let std = stdlib();
let mut parser = from_string(expr);
std.init_parser(&mut parser);
let mut checker = TypeChecker::default();
std.init_type_checker(&mut checker);
let mut env = global_env();
std.init_environment(&mut env);
eval_all(&mut parser, &mut checker, &mut env, false, false);
}

Expand Down
10 changes: 8 additions & 2 deletions src/commands/files.rs
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@ use lento_core::{
value::Value,
},
parser::{ast::Module, parser::parse_path_all},
stdlib::init::stdlib,
type_checker::checker::TypeChecker,
util::failable::Failable,
};
Expand Down Expand Up @@ -57,9 +58,10 @@ fn validate_files(files: &Vec<&Path>, arg_parser: &mut Command) {
fn parse_files<'a>(files: &Vec<&'a Path>) -> Vec<(&'a Path, Module)> {
// Parallelize this parse-map operation to optimize detecting errors in multiple files (pre-execution)

let std = stdlib();
let results: Vec<(&'a Path, Module)> = files
.par_iter()
.filter_map(|f| match parse_path_all(f) {
.filter_map(|f| match parse_path_all(f, Some(&std)) {
Ok(module) => Some((*f, module)),
Err(err) => {
print_error(format!(
Expand All @@ -84,7 +86,11 @@ fn parse_files<'a>(files: &Vec<&'a Path>) -> Vec<(&'a Path, Module)> {
fn interpret_parse_results(parse_results: Vec<(&Path, Module)>) -> Failable<Vec<RuntimeError>> {
// Interpret all files in order. Unwrap is safe because we already checked for errors in the parse_results function
let mut errors: Vec<RuntimeError> = vec![];
let std = stdlib();
let mut checker = TypeChecker::default();
std.init_type_checker(&mut checker);
let mut env = global_env();
std.init_environment(&mut env);
for (file_path, module) in parse_results {
println!(
"{} '{}'...",
Expand All @@ -98,7 +104,7 @@ fn interpret_parse_results(parse_results: Vec<(&Path, Module)>) -> Failable<Vec<
continue;
}
};
match interpret_module(&checked_module, &mut global_env()) {
match interpret_module(&checked_module, &mut env) {
Ok(val) => {
println!("{} executed program!", "Successfully".light_green());
if val != Value::Unit {
Expand Down
1 change: 1 addition & 0 deletions src/commands/repl.rs
Original file line number Diff line number Diff line change
Expand Up @@ -47,6 +47,7 @@ pub fn handle_command_repl(args: &ArgMatches, _arg_parser: &mut Command) {
let mut checker = TypeChecker::default();
std.init_type_checker(&mut checker);
let mut env = global_env();
std.init_environment(&mut env);
loop {
print!("> ");
std::io::stdout().flush().unwrap();
Expand Down

0 comments on commit 9601343

Please sign in to comment.