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:
Michael Schimmel
2026-02-19 16:25:17 +01:00
parent 98668cc683
commit e7628e5cdf
7 changed files with 52 additions and 37 deletions
+10 -5
View File
@@ -1,6 +1,6 @@
use std::rc::Rc;
use crate::ast::types::{Value, StaticType, Identity};
use crate::ast::nodes::Node;
use crate::ast::nodes::{Node, Symbol};
#[derive(Debug, Clone, Copy, PartialEq, Eq, Hash)]
pub enum Address {
@@ -27,7 +27,10 @@ pub enum BoundKind<T = ()> {
Constant(Value),
// Variable Access (Resolved)
Get(Address),
Get {
addr: Address,
name: Symbol,
},
// Variable Update (Assignment)
Set {
@@ -37,6 +40,7 @@ pub enum BoundKind<T = ()> {
// Variable Declaration (Local)
DefLocal {
name: Symbol,
slot: u32,
value: Box<Node<BoundKind<T>, T>>,
captured_by: Vec<Identity>,
@@ -50,6 +54,7 @@ pub enum BoundKind<T = ()> {
// Global Definition (Locals are implicit by stack position)
DefGlobal {
name: Symbol,
global_index: u32,
value: Box<Node<BoundKind<T>, T>>,
},
@@ -109,11 +114,11 @@ impl<T> BoundKind<T> {
match self {
BoundKind::Nop => "NOP".to_string(),
BoundKind::Constant(v) => format!("CONST({})", v),
BoundKind::Get(addr) => format!("GET({:?})", addr),
BoundKind::Get { addr, name } => format!("GET({}, {:?})", name.name, addr),
BoundKind::Set { addr, .. } => format!("SET({:?})", addr),
BoundKind::DefLocal { slot, .. } => format!("DEF_LOCAL(Slot:{})", slot),
BoundKind::DefLocal { name, slot, .. } => format!("DEF_LOCAL({}, Slot:{})", name.name, slot),
BoundKind::If { .. } => "IF".to_string(),
BoundKind::DefGlobal { global_index, .. } => format!("DEF_GLOBAL(Idx:{})", global_index),
BoundKind::DefGlobal { name, global_index, .. } => format!("DEF_GLOBAL({}, Idx:{})", name.name, global_index),
BoundKind::Lambda { upvalues, .. } => format!("LAMBDA(Captures:{})", upvalues.len()),
BoundKind::Call { .. } => "CALL".to_string(),
BoundKind::TailCall { .. } => "T-CALL".to_string(),