diff options
author | Vincent Ambo <mail@tazj.in> | 2022-08-16T12·16+0300 |
---|---|---|
committer | tazjin <tazjin@tvl.su> | 2022-09-01T12·50+0000 |
commit | f153a163a692215aa754218e18f6809f1ab0eb48 (patch) | |
tree | 5850b79e74e6936d636f3570d3afb0a90ab21d97 /tvix/eval/src | |
parent | 0f739cd94424c3cbad62bc69de72ee4fff2b6f58 (diff) |
refactor(tvix/eval): improve naming for locals manipulator methods r/4562
`push_local`/`push_phantom` were worse names because they sound like the value itself is being pushed, where in actuality it is just being declared to the compiler. Change-Id: Ibfda5c4c8e47d5d3262bfe005b0f1f84908a117e Reviewed-on: https://cl.tvl.fyi/c/depot/+/6228 Tested-by: BuildkiteCI Reviewed-by: sterni <sternenseemann@systemli.org>
Diffstat (limited to 'tvix/eval/src')
-rw-r--r-- | tvix/eval/src/compiler.rs | 14 |
1 files changed, 9 insertions, 5 deletions
diff --git a/tvix/eval/src/compiler.rs b/tvix/eval/src/compiler.rs index 3b33961d26d9..193b4a0f33ed 100644 --- a/tvix/eval/src/compiler.rs +++ b/tvix/eval/src/compiler.rs @@ -751,7 +751,7 @@ impl Compiler { self.compile(from.inner().unwrap())?; self.emit_literal_ident(&ident); self.chunk.push_op(OpCode::OpAttrsSelect); - self.push_local(ident.as_str()); + self.declare_local(ident.as_str()); } } } @@ -766,7 +766,7 @@ impl Compiler { } self.compile(entry.value().unwrap())?; - self.push_local(path.pop().unwrap()); + self.declare_local(path.pop().unwrap()); } // Deal with the body, then clean up the locals afterwards. @@ -784,7 +784,7 @@ impl Compiler { // stack). self.compile(node.namespace().unwrap())?; - self.push_phantom(); + self.declare_phantom(); self.scope.with_stack.push(With { depth: self.scope.scope_depth, }); @@ -868,7 +868,10 @@ impl Compiler { } } - fn push_local<S: Into<String>>(&mut self, name: S) { + /// Declare a local variable known in the scope that is being + /// compiled by pushing it to the locals. This is used to + /// determine the stack offset of variables. + fn declare_local<S: Into<String>>(&mut self, name: S) { // Set up scope poisoning if required. let name = name.into(); match name.as_str() { @@ -886,6 +889,7 @@ impl Compiler { _ => {} }; + self.scope.locals.push(Local { name: name.into(), depth: self.scope.scope_depth, @@ -893,7 +897,7 @@ impl Compiler { }); } - fn push_phantom(&mut self) { + fn declare_phantom(&mut self) { self.scope.locals.push(Local { name: "".into(), depth: self.scope.scope_depth, |