From e9dc8a7e32f7f61b667a302101103534f8f2b6d0 Mon Sep 17 00:00:00 2001 From: John Date: Wed, 28 Feb 2024 06:02:00 -0600 Subject: [PATCH] cl-repl: hack together some temporary file loading, to aid in standard library development --- cl-repl/src/lib.rs | 12 ++++++++++++ 1 file changed, 12 insertions(+) diff --git a/cl-repl/src/lib.rs b/cl-repl/src/lib.rs index 294c33f..d58b6d2 100644 --- a/cl-repl/src/lib.rs +++ b/cl-repl/src/lib.rs @@ -225,6 +225,18 @@ pub mod cli { fn from(value: Args) -> Self { let Args { path, repl, mode } = value; match (repl, path) { + (true, Some(path)) => { + let prog = std::fs::read_to_string(path).unwrap(); + let code = conlang::parser::Parser::new(conlang::lexer::Lexer::new(&prog)) + .file() + .unwrap(); + let mut env = conlang::interpreter::env::Environment::new(); + env.eval(&code).unwrap(); + env.call("dump", &[]) + .expect("calling dump in the environment shouldn't fail"); + + Self::Repl(Repl { mode, env, ..Default::default() }) + } (_, Some(path)) => Self::File { mode, path }, (true, None) => Self::Repl(Repl { mode, ..Default::default() }), (false, None) => Self::Stdin { mode },