Refactor: Rename map to record
This commit renames `Map` to `Record` and updates all related AST nodes, binders, type checkers, and runtime values to reflect this change. This is a semantic change to better align with common programming language terminology.
This commit is contained in:
@@ -253,12 +253,12 @@ impl Binder {
|
||||
Ok(self.make_node(node.identity.clone(), BoundKind::Tuple { elements: bound_elems }))
|
||||
},
|
||||
|
||||
UntypedKind::Map { entries } => {
|
||||
let mut bound_entries = Vec::new();
|
||||
for (k, v) in entries {
|
||||
bound_entries.push((self.bind(k)?, self.bind(v)?));
|
||||
UntypedKind::Record { fields } => {
|
||||
let mut bound_fields = Vec::new();
|
||||
for (k, v) in fields {
|
||||
bound_fields.push((self.bind(k)?, self.bind(v)?));
|
||||
}
|
||||
Ok(self.make_node(node.identity.clone(), BoundKind::Map { entries: bound_entries }))
|
||||
Ok(self.make_node(node.identity.clone(), BoundKind::Record { fields: bound_fields }))
|
||||
},
|
||||
|
||||
UntypedKind::Expansion { call, expanded } => {
|
||||
|
||||
@@ -98,8 +98,8 @@ pub enum BoundKind<T = ()> {
|
||||
elements: Vec<BoundNode<T>>,
|
||||
},
|
||||
|
||||
Map {
|
||||
entries: Vec<MapEntry<T>>,
|
||||
Record {
|
||||
fields: Vec<RecordField<T>>,
|
||||
},
|
||||
|
||||
/// An expanded macro call, preserving the original call for debugging and UI.
|
||||
@@ -114,8 +114,8 @@ pub enum BoundKind<T = ()> {
|
||||
Extension(Box<dyn BoundExtension<T>>),
|
||||
}
|
||||
|
||||
/// A single entry in a Map literal (Key-Value pair)
|
||||
pub type MapEntry<T> = (BoundNode<T>, BoundNode<T>);
|
||||
/// A single field in a Record literal (Key-Value pair)
|
||||
pub type RecordField<T> = (BoundNode<T>, BoundNode<T>);
|
||||
|
||||
impl<T> BoundKind<T> {
|
||||
pub fn display_name(&self) -> String {
|
||||
@@ -139,7 +139,7 @@ impl<T> BoundKind<T> {
|
||||
BoundKind::TailCall { .. } => "T-CALL".to_string(),
|
||||
BoundKind::Block { .. } => "BLOCK".to_string(),
|
||||
BoundKind::Tuple { elements } => format!("TUPLE({})", elements.len()),
|
||||
BoundKind::Map { entries } => format!("MAP({})", entries.len()),
|
||||
BoundKind::Record { fields } => format!("RECORD({})", fields.len()),
|
||||
BoundKind::Expansion { .. } => "EXPANSION".to_string(),
|
||||
BoundKind::Extension(ext) => ext.display_name(),
|
||||
}
|
||||
|
||||
@@ -185,10 +185,10 @@ impl Dumper {
|
||||
self.indent -= 1;
|
||||
}
|
||||
|
||||
BoundKind::Map { entries } => {
|
||||
self.log("Map", node);
|
||||
BoundKind::Record { fields } => {
|
||||
self.log("Record", node);
|
||||
self.indent += 1;
|
||||
for (k, v) in entries {
|
||||
for (k, v) in fields {
|
||||
self.visit(k);
|
||||
self.visit(v);
|
||||
}
|
||||
|
||||
@@ -69,8 +69,8 @@ impl<'a> LambdaCollector<'a> {
|
||||
}
|
||||
}
|
||||
|
||||
BoundKind::Map { entries } => {
|
||||
for (k, v) in entries {
|
||||
BoundKind::Record { fields } => {
|
||||
for (k, v) in fields {
|
||||
self.visit(k);
|
||||
self.visit(v);
|
||||
}
|
||||
|
||||
+10
-10
@@ -193,14 +193,14 @@ impl<E: MacroEvaluator> MacroExpander<E> {
|
||||
})
|
||||
}
|
||||
|
||||
UntypedKind::Map { entries } => {
|
||||
let mut expanded_entries = Vec::new();
|
||||
for (k, v) in entries {
|
||||
expanded_entries.push((self.expand_recursive(k)?, self.expand_recursive(v)?));
|
||||
UntypedKind::Record { fields } => {
|
||||
let mut expanded_fields = Vec::new();
|
||||
for (k, v) in fields {
|
||||
expanded_fields.push((self.expand_recursive(k)?, self.expand_recursive(v)?));
|
||||
}
|
||||
Ok(Node {
|
||||
identity: node.identity,
|
||||
kind: UntypedKind::Map { entries: expanded_entries },
|
||||
kind: UntypedKind::Record { fields: expanded_fields },
|
||||
ty: (),
|
||||
})
|
||||
}
|
||||
@@ -368,14 +368,14 @@ impl<E: MacroEvaluator> MacroExpander<E> {
|
||||
})
|
||||
}
|
||||
|
||||
UntypedKind::Map { entries } => {
|
||||
let mut new_entries = Vec::new();
|
||||
for (k, v) in entries {
|
||||
new_entries.push((self.expand_template(k, state)?, self.expand_template(v, state)?));
|
||||
UntypedKind::Record { fields } => {
|
||||
let mut new_fields = Vec::new();
|
||||
for (k, v) in fields {
|
||||
new_fields.push((self.expand_template(k, state)?, self.expand_template(v, state)?));
|
||||
}
|
||||
Ok(Node {
|
||||
identity: node.identity,
|
||||
kind: UntypedKind::Map { entries: new_entries },
|
||||
kind: UntypedKind::Record { fields: new_fields },
|
||||
ty: (),
|
||||
})
|
||||
}
|
||||
|
||||
@@ -90,10 +90,11 @@ impl Specializer {
|
||||
let elements = elements.into_iter().map(|e| self.visit_node(e)).collect();
|
||||
(BoundKind::Tuple { elements }, node.ty)
|
||||
},
|
||||
BoundKind::Map { entries } => {
|
||||
let entries = entries.into_iter().map(|(k, v)| (self.visit_node(k), self.visit_node(v))).collect();
|
||||
(BoundKind::Map { entries }, node.ty)
|
||||
},
|
||||
BoundKind::Record { fields } => {
|
||||
let fields = fields.into_iter().map(|(k, v)| (self.visit_node(k), self.visit_node(v))).collect();
|
||||
(BoundKind::Record { fields }, node.ty)
|
||||
}
|
||||
,
|
||||
BoundKind::Expansion { original_call, bound_expanded } => {
|
||||
let bound_expanded = Box::new(self.visit_node(*bound_expanded));
|
||||
(BoundKind::Expansion { original_call, bound_expanded }, node.ty)
|
||||
|
||||
@@ -108,12 +108,12 @@ impl TCO {
|
||||
..node
|
||||
}
|
||||
},
|
||||
BoundKind::Map { entries } => {
|
||||
let new_entries = entries.into_iter().map(|(k, v)| {
|
||||
BoundKind::Record { fields } => {
|
||||
let new_fields = fields.into_iter().map(|(k, v)| {
|
||||
(Self::transform(k, false), Self::transform(v, false))
|
||||
}).collect();
|
||||
Node {
|
||||
kind: BoundKind::Map { entries: new_entries },
|
||||
kind: BoundKind::Record { fields: new_fields },
|
||||
..node
|
||||
}
|
||||
},
|
||||
|
||||
@@ -307,20 +307,20 @@ impl TypeChecker {
|
||||
(BoundKind::Tuple { elements: typed_elements }, ty)
|
||||
},
|
||||
|
||||
BoundKind::Map { entries } => {
|
||||
let mut typed_entries = Vec::new();
|
||||
let mut fields = Vec::new();
|
||||
for (k, v) in entries {
|
||||
BoundKind::Record { fields } => {
|
||||
let mut typed_fields = Vec::with_capacity(fields.len());
|
||||
let mut fields_ty = Vec::with_capacity(fields.len());
|
||||
for (k, v) in fields {
|
||||
let kt = self.check_node(k, ctx)?;
|
||||
let vt = self.check_node(v, ctx)?;
|
||||
|
||||
if let BoundKind::Constant(crate::ast::types::Value::Keyword(kw)) = &kt.kind {
|
||||
fields.push((*kw, vt.ty.clone()));
|
||||
fields_ty.push((*kw, vt.ty.clone()));
|
||||
}
|
||||
|
||||
typed_entries.push((kt, vt));
|
||||
typed_fields.push((kt, vt));
|
||||
}
|
||||
(BoundKind::Map { entries: typed_entries }, StaticType::Record(Rc::new(fields)))
|
||||
(BoundKind::Record { fields: typed_fields }, StaticType::Record(Rc::new(fields_ty)))
|
||||
},
|
||||
|
||||
BoundKind::Expansion { original_call, bound_expanded } => {
|
||||
|
||||
@@ -103,8 +103,8 @@ impl UpvalueAnalyzer {
|
||||
Self::visit(el, scopes, capture_map, current_lambda.clone());
|
||||
}
|
||||
}
|
||||
UntypedKind::Map { entries } => {
|
||||
for (k, v) in entries {
|
||||
UntypedKind::Record { fields } => {
|
||||
for (k, v) in fields {
|
||||
Self::visit(k, scopes, capture_map, current_lambda.clone());
|
||||
Self::visit(v, scopes, capture_map, current_lambda.clone());
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user