Refactor: Rename TCO module to lowering

The TCO (Tail Call Optimization) module has been renamed to `lowering`.
This change better reflects the module's broader responsibility, which
includes not only TCO but also general AST transformations and
preparation for VM execution.

The `optimize` function has been renamed to `lower` to align with the
module's new name.
This commit is contained in:
Michael Schimmel
2026-03-11 10:49:24 +01:00
parent db26719cad
commit bb77caf1af
4 changed files with 298 additions and 299 deletions
+7 -8
View File
@@ -15,10 +15,10 @@ use crate::ast::compiler::bound_nodes::{
};
use crate::ast::compiler::dumper::Dumper;
use crate::ast::compiler::lambda_collector::LambdaCollector;
use crate::ast::compiler::lowering::{ExecNode, Lowering};
use crate::ast::compiler::macros::{MacroEvaluator, MacroExpander, MacroRegistry};
use crate::ast::compiler::optimizer::Optimizer;
use crate::ast::compiler::specializer::{FunctionRegistry, MonoCache, Specializer};
use crate::ast::compiler::tco::{ExecNode, TCO};
use crate::ast::rtl::intrinsics;
use crate::ast::types::{
Identity, NodeIdentity, Object, Purity, SourceLocation, StaticType, Value,
@@ -141,7 +141,7 @@ impl MacroEvaluator for RuntimeMacroEvaluator {
.join("\n"));
}
let exec_ast = TCO::optimize(Analyzer::analyze(&typed_ast, &HashMap::new())); // Minimal analysis for macro eval
let exec_ast = Lowering::lower(Analyzer::analyze(&typed_ast, &HashMap::new())); // Minimal analysis for macro eval
let mut vm = VM::new(self.global_values.clone());
vm.run(&exec_ast)
@@ -586,8 +586,8 @@ impl Environment {
.with_registry(self.typed_function_registry.clone());
let optimized = optimizer.optimize(specialized);
// 5. TCO
TCO::optimize(optimized)
// 5. Lowering
Lowering::lower(optimized)
}
pub fn instantiate(&self, node: ExecNode) -> Rc<crate::ast::types::NativeFunction> {
@@ -705,14 +705,14 @@ impl Environment {
.with_purity(global_purity.clone());
let optimized_ast = optimizer.optimize(specialized_ast);
let tco_ast = TCO::optimize(optimized_ast);
let exec_ast = Lowering::lower(optimized_ast);
let mut vm = VM::new(global_values.clone());
let compiled_val = match vm.run(&tco_ast) {
let compiled_val = match vm.run(&exec_ast) {
Ok(v) => v,
Err(e) => return Err(format!("VM Error during specialization: {}", e)),
};
let ret_type = tco_ast.ty.ty.clone();
let ret_type = exec_ast.ty.ty.clone();
Ok((compiled_val, ret_type))
},
);
@@ -774,4 +774,3 @@ impl Environment {
Ok((final_result, observer.logs))
}
}