Refactor lambda binding and parameter handling

Introduce `BoundKind::Parameter` to represent function parameters.
Modify `Binder` to correctly handle parameters within lambda
definitions, ensuring they are only defined within function scopes.
Update `LambdaCollector` to register the body of lambdas as templates
for global definitions.
Adjust `Dumper` to accurately represent lambda parameters.
Update `Specializer` and `TCO` to handle the new `BoundKind::Parameter`.
Refactor `Call` and `TailCall` to use a single `args` node, often a
tuple.
Adjust type signatures in RTL to use `StaticType::Tuple` for function
parameters.
This commit is contained in:
Michael Schimmel
2026-02-20 12:14:22 +01:00
parent 8d6d3be5c2
commit e2279f214b
17 changed files with 497 additions and 247 deletions
+9 -9
View File
@@ -23,9 +23,10 @@ impl<'a> LambdaCollector<'a> {
}
BoundKind::DefGlobal { global_index, value, .. } => {
// If we define a global that is a lambda, register it as a template.
if let BoundKind::Lambda { .. } = &value.kind {
self.registry.insert(*global_index, (**value).clone());
// If we define a global that is a lambda, register its BODY as the template.
// This allows the VM to skip the Lambda/Parameter nodes during execution.
if let BoundKind::Lambda { body, .. } = &value.kind {
self.registry.insert(*global_index, (**body).clone());
}
self.visit(value);
}
@@ -33,9 +34,9 @@ impl<'a> LambdaCollector<'a> {
BoundKind::Set { addr, value } => {
// Also track assignments to globals if they hold lambdas.
if let Address::Global(global_index) = addr
&& let BoundKind::Lambda { .. } = &value.kind
&& let BoundKind::Lambda { body, .. } = &value.kind
{
self.registry.insert(*global_index, (**value).clone());
self.registry.insert(*global_index, (**body).clone());
}
self.visit(value);
}
@@ -48,7 +49,8 @@ impl<'a> LambdaCollector<'a> {
}
}
BoundKind::Lambda { body, .. } => {
BoundKind::Lambda { params, body, .. } => {
self.visit(params);
self.visit(body);
}
@@ -58,9 +60,7 @@ impl<'a> LambdaCollector<'a> {
BoundKind::Call { callee, args } | BoundKind::TailCall { callee, args } => {
self.visit(callee);
for arg in args {
self.visit(arg);
}
self.visit(args);
}
BoundKind::Tuple { elements } => {