feat: Enhance #use directive for directories and cwd

The `#use` directive now supports referencing entire directories,
automatically including all `.myc` files within them. Additionally,
environments are now initialized with the current working directory as a
default search path, simplifying module resolution.
This commit is contained in:
Michael Schimmel
2026-03-06 21:07:27 +01:00
parent a59367ba61
commit 84ef3f9aed
7 changed files with 94 additions and 55 deletions
+5 -3
View File
@@ -61,6 +61,8 @@ impl Default for CompilerApp {
})
.unwrap_or_default();
let env = Environment::new().with_cwd();
Self {
source_code: String::from(
r#"
@@ -81,7 +83,7 @@ impl Default for CompilerApp {
trace_logs: Vec::new(),
active_tab: AppTab::Output,
debug_enabled: false,
env: Environment::new(),
env,
is_first_frame: true,
examples,
}
@@ -94,7 +96,7 @@ impl CompilerApp {
self.trace_logs.clear();
// Reset environment for a fresh run
self.env = Environment::new();
self.env = Environment::new().with_cwd();
self.env.optimization = true;
let res = (|| -> Result<(myc::ast::types::Value, std::time::Duration), String> {
@@ -160,7 +162,7 @@ impl CompilerApp {
}
fn dump_ast(&mut self) {
self.env = Environment::new();
self.env = Environment::new().with_cwd();
self.env.optimization = true; // Enable optimization for AST dump
if let Err(e) = self.env.preload_dependencies(&self.source_code, self.current_example_path.as_deref()) {