Refactor Binder to use simpler types

The Binder has been refactored to simplify its internal types and reduce
redundancy.
Key changes include:
- Removed StaticType from LocalInfo, as it's not strictly needed for the
  binder.
- Simplified `define` in CompilerScope to not take a StaticType.
- Removed StaticType from upvalues in FunctionCompiler.
- Adjusted global mappings to store only the index, not the type.
- Updated BoundKind to use a generic type parameter `T` for metadata,
  defaulting to `()` for untyped bound nodes.
- Introduced `BoundNode` and `TypedNode` type aliases for clarity.
- Minor adjustments to dumper and VM to accommodate the new generic
  BoundKind.
This commit is contained in:
Michael Schimmel
2026-02-19 12:07:28 +01:00
parent c49561255e
commit 4673ea78b9
7 changed files with 130 additions and 176 deletions
+2 -5
View File
@@ -1,19 +1,18 @@
use std::rc::Rc;
use crate::ast::nodes::Node;
use crate::ast::compiler::bound_nodes::BoundKind;
use crate::ast::types::StaticType;
pub struct TCO;
impl TCO {
pub fn optimize(node: Node<BoundKind, StaticType>) -> Node<BoundKind, StaticType> {
pub fn optimize<T: Clone>(node: Node<BoundKind<T>, T>) -> Node<BoundKind<T>, T> {
// Top-level starts NOT in tail position usually, unless the script result is returned immediately
// which implies tail position for the script body if viewed as a function.
// Let's assume standard execution context (not tail call) for the script root.
Self::transform(node, false)
}
fn transform(node: Node<BoundKind, StaticType>, is_tail_position: bool) -> Node<BoundKind, StaticType> {
fn transform<T: Clone>(node: Node<BoundKind<T>, T>, is_tail_position: bool) -> Node<BoundKind<T>, T> {
match node.kind {
BoundKind::Call { callee, args } => {
let new_callee = Box::new(Self::transform(*callee, false));
@@ -78,8 +77,6 @@ impl TCO {
BoundKind::Lambda { param_count, upvalues, body } => {
// The body of a lambda is implicitly in tail position when the lambda is called.
// However, we process the lambda definition here.
// The body node inside needs to be transformed assuming it IS in tail position relative to the function.
let new_body = Rc::new(Self::transform((*body).clone(), true));
Node {