feat: Add lambda collection and specialization

Introduces `LambdaCollector` to gather lambda functions and populate the
function registry. This enables the `Specializer` to work with
user-defined functions.

The `Environment` struct is updated to manage the `function_registry`
and `monomorph_cache`, which are essential for the specialization
process.

The `link` method in `Environment` now incorporates lambda collection
and node specialization before applying TCO optimization. This ensures
that lambdas are properly processed and specialized for potential
performance gains.

The `Specializer`'s `new` constructor has been modified to accept and
initialize the `MonoCache` through an `Rc<RefCell<MonoCache>>`. This
allows the cache to be shared across different specialized functions.

Also includes minor refactoring and type adjustments in `specializer.rs`
for better clarity and consistency.
This commit is contained in:
Michael Schimmel
2026-02-19 22:26:24 +01:00
parent 55502cbb69
commit 1b49719d31
5 changed files with 148 additions and 22 deletions
+22 -2
View File
@@ -22,6 +22,10 @@ struct Cli {
/// Update the benchmark baseline (Only allowed in Release mode)
#[arg(short, long)]
update_bench: bool,
/// Dump the compiled AST
#[arg(short, long)]
dump: bool,
}
fn main() {
@@ -45,10 +49,26 @@ fn main() {
}
if let Some(script_str) = cli.eval {
execute(&env, &script_str);
if cli.dump {
match env.dump_ast(&script_str) {
Ok(dump) => println!("{}", dump),
Err(e) => eprintln!("Error dumping AST: {}", e),
}
} else {
execute(&env, &script_str);
}
} else if let Some(file_path) = cli.file {
match fs::read_to_string(&file_path) {
Ok(content) => execute(&env, &content),
Ok(content) => {
if cli.dump {
match env.dump_ast(&content) {
Ok(dump) => println!("{}", dump),
Err(e) => eprintln!("Error dumping AST: {}", e),
}
} else {
execute(&env, &content);
}
},
Err(e) => {
eprintln!("Error reading file {:?}: {}", file_path, e);
std::process::exit(1);