about summary refs log tree commit diff
path: root/tvix/eval
diff options
context:
space:
mode:
authorVincent Ambo <mail@tazj.in>2022-08-14T20·14+0300
committertazjin <tazjin@tvl.su>2022-08-31T22·10+0000
commitec7db0235ffb1bca006e21a2ae51bbfc29382132 (patch)
tree323dcdfe4c485ed967362dbf9f2c74eb86ab41be /tvix/eval
parentf173161f4c0fc754df2b6daeca302d3e65bbf77d (diff)
refactor(tvix/eval): rename `Locals` to `Scope` r/4550
This name is much more sensible actually; its more than just a
collection of locals as it tracks additional scope information in the
case of Nix.

Change-Id: Ia2739bbd39aab222b1c4355e9248828973b0db43
Reviewed-on: https://cl.tvl.fyi/c/depot/+/6216
Reviewed-by: sterni <sternenseemann@systemli.org>
Reviewed-by: grfn <grfn@gws.fyi>
Tested-by: BuildkiteCI
Diffstat (limited to 'tvix/eval')
-rw-r--r--tvix/eval/src/compiler.rs22
1 files changed, 11 insertions, 11 deletions
diff --git a/tvix/eval/src/compiler.rs b/tvix/eval/src/compiler.rs
index 2f48a1cea8af..c5516d199add 100644
--- a/tvix/eval/src/compiler.rs
+++ b/tvix/eval/src/compiler.rs
@@ -42,14 +42,14 @@ struct Local {
     depth: usize,
 }
 
-/// Represents locals known during compilation, which can be resolved
+/// Represents a scope known during compilation, which can be resolved
 /// directly to stack indices.
 ///
 /// TODO(tazjin): `with`-stack
 /// TODO(tazjin): flag "specials" (e.g. note depth if builtins are
 /// overridden)
 #[derive(Default)]
-struct Locals {
+struct Scope {
     locals: Vec<Local>,
 
     // How many scopes "deep" are these locals?
@@ -58,7 +58,7 @@ struct Locals {
 
 struct Compiler {
     chunk: Chunk,
-    locals: Locals,
+    scope: Scope,
 
     warnings: Vec<EvalWarning>,
     root_dir: PathBuf,
@@ -709,9 +709,9 @@ impl Compiler {
 
                 Some(_) => {
                     for ident in inherit.idents() {
-                        self.locals.locals.push(Local {
+                        self.scope.locals.push(Local {
                             name: ident.as_str().to_string(),
-                            depth: self.locals.scope_depth,
+                            depth: self.scope.scope_depth,
                         });
                     }
                     from_inherits.push(inherit);
@@ -733,9 +733,9 @@ impl Compiler {
 
             entries.push(entry.value().unwrap());
 
-            self.locals.locals.push(Local {
+            self.scope.locals.push(Local {
                 name: path.pop().unwrap(),
-                depth: self.locals.scope_depth,
+                depth: self.scope.scope_depth,
             });
         }
 
@@ -792,11 +792,11 @@ impl Compiler {
     }
 
     fn begin_scope(&mut self) {
-        self.locals.scope_depth += 1;
+        self.scope.scope_depth += 1;
     }
 
     fn end_scope(&mut self) {
-        let mut scope = &mut self.locals;
+        let mut scope = &mut self.scope;
         debug_assert!(scope.scope_depth != 0, "can not end top scope");
         scope.scope_depth -= 1;
 
@@ -820,7 +820,7 @@ impl Compiler {
     }
 
     fn resolve_local(&mut self, name: &str) -> Option<usize> {
-        let scope = &self.locals;
+        let scope = &self.scope;
 
         for (idx, local) in scope.locals.iter().enumerate().rev() {
             if local.name == name {
@@ -892,7 +892,7 @@ pub fn compile(ast: rnix::AST, location: Option<PathBuf>) -> EvalResult<Compilat
         root_dir,
         chunk: Chunk::default(),
         warnings: vec![],
-        locals: Default::default(),
+        scope: Default::default(),
     };
 
     c.compile(ast.node())?;