Implement #use directive for dependency management
Introduces the `#use` preprocessor directive, allowing Myc scripts to explicitly declare dependencies on other Myc libraries. This change moves dependency management from a command-line argument to an in-script declaration, ensuring scripts are self-contained and can correctly resolve macros and other symbols. Key features include: - Declarations at the beginning of a file, evaluated before parsing. - Support for relative paths and a new `->` separator. - Automatic resolution of dependencies from specified search paths. - Idempotent loading to prevent duplicate parsing and evaluation. - No AST pollution; dependency management is a compile-time concern. The compiler's lexer has been updated to recognize `#` as a comment character, and the environment now manages search paths and loaded modules. This lays the groundwork for more complex library structures and improved code organization.
This commit is contained in:
+10
@@ -98,6 +98,10 @@ impl CompilerApp {
|
||||
self.env.optimization = true;
|
||||
|
||||
let res = (|| -> Result<(myc::ast::types::Value, std::time::Duration), String> {
|
||||
if let Err(e) = self.env.preload_dependencies(&self.source_code, self.current_example_path.as_deref()) {
|
||||
return Err(format!("Dependency Error: {}", e));
|
||||
}
|
||||
|
||||
let start_run = std::time::Instant::now();
|
||||
let result = if self.debug_enabled {
|
||||
let (res, logs) = self.env.run_debug(&self.source_code)?;
|
||||
@@ -158,6 +162,12 @@ impl CompilerApp {
|
||||
fn dump_ast(&mut self) {
|
||||
self.env = Environment::new();
|
||||
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()) {
|
||||
self.output_log = format!("Dependency Error: {}", e);
|
||||
return;
|
||||
}
|
||||
|
||||
match self.env.dump_ast(&self.source_code) {
|
||||
Ok(dump) => {
|
||||
self.output_log = format!("--- BOUND AST DUMP ---\n\n{}", dump);
|
||||
|
||||
Reference in New Issue
Block a user