Refactor map and record representation
Replaces the use of `BTreeMap` and `HashMap` for maps and records with `Vec<(Keyword, Value)>` and `Vec<(Keyword, StaticType)>`. This simplifies the data structure and allows for ordered iteration, which is important for serialization and comparison. Also updates the `unpack` function in `vm.rs` to handle records as well as lists when destructuring.
This commit is contained in:
@@ -309,13 +309,13 @@ impl TypeChecker {
|
||||
|
||||
BoundKind::Map { entries } => {
|
||||
let mut typed_entries = Vec::new();
|
||||
let mut fields = std::collections::BTreeMap::new();
|
||||
let mut fields = Vec::new();
|
||||
for (k, v) in entries {
|
||||
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.insert(*kw, vt.ty.clone());
|
||||
fields.push((*kw, vt.ty.clone()));
|
||||
}
|
||||
|
||||
typed_entries.push((kt, vt));
|
||||
@@ -484,8 +484,8 @@ mod tests {
|
||||
let ty = get_ret_type(&typed);
|
||||
if let StaticType::Record(fields) = ty {
|
||||
assert_eq!(fields.len(), 2);
|
||||
assert_eq!(fields.get(&Keyword::intern("x")), Some(&StaticType::Int));
|
||||
assert_eq!(fields.get(&Keyword::intern("y")), Some(&StaticType::Float));
|
||||
assert_eq!(fields[0], (Keyword::intern("x"), StaticType::Int));
|
||||
assert_eq!(fields[1], (Keyword::intern("y"), StaticType::Float));
|
||||
} else {
|
||||
panic!("Expected Record, got {:?}", ty);
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user