checkpoint in reconstruction

This commit is contained in:
2023-12-26 21:08:01 -08:00
parent 2c2268925a
commit e5db6640f2
21 changed files with 759 additions and 153 deletions

View File

@@ -1,4 +1,6 @@
use std::{borrow::Borrow, collections::HashMap, hash::Hash};
use std::borrow::Borrow;
use std::collections::HashMap;
use std::hash::Hash;
/// A version of [`std::collections::HashMap`] with a built-in notion of scope.
#[derive(Clone)]
@@ -105,4 +107,28 @@ impl<K: Eq + Hash + PartialEq, V> ScopedMap<K, V> {
ScopedMap { scopes }
}
/// Returns true if this map is completely empty, at every level of
/// scope.
pub fn is_empty(&self) -> bool {
self.scopes.iter().all(|x| x.is_empty())
}
}
impl<K: Clone + Eq + Hash, V: Clone> ScopedMap<K, V> {
/// Returns the set of all variables bound at this time, with shadowed
/// variables hidden.
pub fn bindings(&self) -> HashMap<K, V> {
let mut result = HashMap::new();
for scope in self.scopes.iter().rev() {
for (key, value) in scope.iter() {
if !result.contains_key(key) {
result.insert(key.clone(), value.clone());
}
}
}
result
}
}