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
+3 -6
View File
@@ -27,8 +27,7 @@ pub fn run_functional_tests_with_optimization(enabled: bool) -> Vec<TestResult>
let output_re = Regex::new(r";; Output: (.*)").unwrap();
for entry in entries.filter_map(|e| e.ok()) {
let mut env = Environment::new(); // Fresh environment per test file
env.add_search_path(".");
let mut env = Environment::new().with_cwd(); // Fresh environment per test file
env.optimization = enabled;
let path = entry.path();
if path.extension().is_some_and(|ext| ext == "myc") {
@@ -121,8 +120,7 @@ pub fn run_benchmarks(update: bool, filter: Option<&str>) -> Vec<BenchmarkResult
.unwrap_or(1);
// Compile once for this file (symbols/types are compatible with all fresh environments)
let initial_env = Environment::new();
initial_env.add_search_path(".");
let initial_env = Environment::new().with_cwd();
if let Err(e) = initial_env.preload_dependencies(&content, Some(&path)) {
results.push(BenchmarkResult {
@@ -152,8 +150,7 @@ pub fn run_benchmarks(update: bool, filter: Option<&str>) -> Vec<BenchmarkResult
// Helper to measure sum of VM execution times over N executions in one environment
let measure_sum =
|n: u32, node: &crate::ast::compiler::TypedNode| -> Result<Duration, String> {
let env = Environment::new();
env.add_search_path(".");
let env = Environment::new().with_cwd();
if let Err(e) = env.preload_dependencies(&content, Some(&path)) {
return Err(format!("Dependency Error in measurement: {}", e));
}