Add symbol name to bound kinds
The `Get`, `DefLocal`, and `DefGlobal` bound kinds now store the symbol name associated with the variable. This information is useful for debugging and provides more context in the compiled output.
This commit is contained in:
@@ -69,13 +69,13 @@ impl Specializer {
|
||||
let body = Rc::new(self.visit_node((*body).clone()));
|
||||
(BoundKind::Lambda { param_count, upvalues, body }, node.ty)
|
||||
},
|
||||
BoundKind::DefLocal { slot, value, captured_by } => {
|
||||
BoundKind::DefLocal { name, slot, value, captured_by } => {
|
||||
let value = Box::new(self.visit_node(*value));
|
||||
(BoundKind::DefLocal { slot, value, captured_by }, node.ty)
|
||||
(BoundKind::DefLocal { name, slot, value, captured_by }, node.ty)
|
||||
},
|
||||
BoundKind::DefGlobal { global_index, value } => {
|
||||
BoundKind::DefGlobal { name, global_index, value } => {
|
||||
let value = Box::new(self.visit_node(*value));
|
||||
(BoundKind::DefGlobal { global_index, value }, node.ty)
|
||||
(BoundKind::DefGlobal { name, global_index, value }, node.ty)
|
||||
},
|
||||
BoundKind::Set { addr, value } => {
|
||||
let value = Box::new(self.visit_node(*value));
|
||||
@@ -111,7 +111,7 @@ impl Specializer {
|
||||
let new_args: Vec<TypedNode> = args.into_iter().map(|a| self.visit_node(a)).collect();
|
||||
|
||||
// 2. Check if this call is a candidate (Callee is Get(Address))
|
||||
let address = if let BoundKind::Get(addr) = &new_callee.kind {
|
||||
let address = if let BoundKind::Get { addr, .. } = &new_callee.kind {
|
||||
*addr
|
||||
} else {
|
||||
// Not a direct call to a named function/variable
|
||||
@@ -195,6 +195,7 @@ mod tests {
|
||||
use super::*;
|
||||
use crate::ast::types::{Identity, NodeIdentity, SourceLocation, StaticType, Value, Signature};
|
||||
use crate::ast::compiler::bound_nodes::{BoundKind, Address, BoundNode, TypedNode};
|
||||
use crate::ast::nodes::Symbol;
|
||||
use std::rc::Rc;
|
||||
|
||||
fn make_identity() -> Identity {
|
||||
@@ -235,6 +236,7 @@ mod tests {
|
||||
// Setup Registry with a function definition
|
||||
let mut registry = MockRegistry::new();
|
||||
let addr = Address::Local(0);
|
||||
let name = Symbol::from("test_func");
|
||||
|
||||
// Def: (fn [x] x) -- generic identity
|
||||
let func_node = BoundNode {
|
||||
@@ -257,7 +259,7 @@ mod tests {
|
||||
let spec = Specializer::new(Some(Rc::new(registry)), Some(compiler), None);
|
||||
|
||||
// Call(Get(Local(0)), [Arg(Int)])
|
||||
let callee = make_typed_node(BoundKind::Get(addr), StaticType::Any);
|
||||
let callee = make_typed_node(BoundKind::Get { addr, name: name.clone() }, StaticType::Any);
|
||||
let arg = make_typed_node(BoundKind::Constant(Value::Int(1)), StaticType::Int);
|
||||
|
||||
let call_node = make_typed_node(
|
||||
@@ -285,10 +287,12 @@ mod tests {
|
||||
#[test]
|
||||
fn test_specialize_skips_unknown_types() {
|
||||
let spec = Specializer::new(None, None, None);
|
||||
let name0 = Symbol::from("f");
|
||||
let name1 = Symbol::from("x");
|
||||
|
||||
// Call(Get(Local(0)), [Get(Local(1))]) where arg is Any
|
||||
let callee = make_typed_node(BoundKind::Get(Address::Local(0)), StaticType::Function(Box::new(Signature { params: vec![StaticType::Any], ret: StaticType::Void })));
|
||||
let arg = make_typed_node(BoundKind::Get(Address::Local(1)), StaticType::Any);
|
||||
let callee = make_typed_node(BoundKind::Get { addr: Address::Local(0), name: name0 }, StaticType::Function(Box::new(Signature { params: vec![StaticType::Any], ret: StaticType::Void })));
|
||||
let arg = make_typed_node(BoundKind::Get { addr: Address::Local(1), name: name1 }, StaticType::Any);
|
||||
|
||||
let call_node = make_typed_node(
|
||||
BoundKind::Call { callee: Box::new(callee), args: vec![arg] },
|
||||
@@ -299,7 +303,7 @@ mod tests {
|
||||
|
||||
// Should remain a generic Call because arg type is Any
|
||||
if let BoundKind::Call { callee, .. } = result.kind {
|
||||
if let BoundKind::Get(_) = callee.kind {
|
||||
if let BoundKind::Get { .. } = callee.kind {
|
||||
// Correct: Still a Get, not a Constant(Function)
|
||||
} else {
|
||||
panic!("Expected generic Call to Get, got {:?}", callee.kind);
|
||||
@@ -315,6 +319,7 @@ mod tests {
|
||||
let spec = Specializer::new(None, None, None);
|
||||
|
||||
let addr = Address::Local(0);
|
||||
let name = Symbol::from("cached_func");
|
||||
let arg_types = vec![StaticType::Int];
|
||||
let key = MonoCacheKey { address: addr, arg_types: arg_types.clone() };
|
||||
|
||||
@@ -325,7 +330,7 @@ mod tests {
|
||||
spec.cache.borrow_mut().insert(key, (specialized_val.clone(), ret_ty.clone()));
|
||||
|
||||
// Create the call node: Call(Get(0), [Arg(Int)])
|
||||
let callee = make_typed_node(BoundKind::Get(addr), StaticType::Any);
|
||||
let callee = make_typed_node(BoundKind::Get { addr, name }, StaticType::Any);
|
||||
let arg = make_typed_node(BoundKind::Constant(Value::Int(1)), StaticType::Int);
|
||||
|
||||
let call_node = make_typed_node(
|
||||
|
||||
Reference in New Issue
Block a user