diff options
| author | Laurenz <laurmaedje@gmail.com> | 2021-05-29 15:45:57 +0200 |
|---|---|---|
| committer | Laurenz <laurmaedje@gmail.com> | 2021-05-31 22:33:40 +0200 |
| commit | e023bf2ac9f5796355d9485afc16781196bf212b (patch) | |
| tree | 26d4487de0c4e2d0f69182483301de867cb5fa34 /src/eval/scope.rs | |
| parent | 9f77f09aacd1fb0fd6138a6d16ed2755f6bfae3f (diff) | |
Module loading system
Detects cyclic imports and loads each module only once per compilation.
Diffstat (limited to 'src/eval/scope.rs')
| -rw-r--r-- | src/eval/scope.rs | 13 |
1 files changed, 7 insertions, 6 deletions
diff --git a/src/eval/scope.rs b/src/eval/scope.rs index a3c9234b..cfa2bccd 100644 --- a/src/eval/scope.rs +++ b/src/eval/scope.rs @@ -31,12 +31,8 @@ impl<'a> Scopes<'a> { } /// Create a new hierarchy of scopes with a base scope. - pub fn with_base(base: &'a Scope) -> Self { - Self { - top: Scope::new(), - scopes: vec![], - base: Some(base), - } + pub fn with_base(base: Option<&'a Scope>) -> Self { + Self { top: Scope::new(), scopes: vec![], base } } /// Enter a new scope. @@ -131,6 +127,11 @@ impl Scope { pub fn get(&self, var: &str) -> Option<&Slot> { self.values.get(var) } + + /// Iterate over all definitions. + pub fn iter(&self) -> impl Iterator<Item = (&str, &Slot)> { + self.values.iter().map(|(k, v)| (k.as_str(), v)) + } } impl Debug for Scope { |
