diff options
Diffstat (limited to 'tvix/eval/src/compiler')
-rw-r--r-- | tvix/eval/src/compiler/mod.rs | 33 |
1 files changed, 18 insertions, 15 deletions
diff --git a/tvix/eval/src/compiler/mod.rs b/tvix/eval/src/compiler/mod.rs index 3160c68c6e3c..7b92b8a099c2 100644 --- a/tvix/eval/src/compiler/mod.rs +++ b/tvix/eval/src/compiler/mod.rs @@ -114,6 +114,18 @@ impl Scope { self.poisoned_tokens .retain(|_, poisoned_at| *poisoned_at != depth); } + + /// Resolve the stack index of a statically known local. + fn resolve_local(&mut self, name: &str) -> Option<usize> { + for (idx, local) in self.locals.iter_mut().enumerate().rev() { + if !local.phantom && local.name == name { + local.used = true; + return Some(idx); + } + } + + None + } } /// Represents the lambda currently being compiled. @@ -500,7 +512,10 @@ impl Compiler { count += 1; self.emit_literal_ident(&ident); - match self.resolve_local(ident.ident_token().unwrap().text()) { + match self + .scope_mut() + .resolve_local(ident.ident_token().unwrap().text()) + { Some(idx) => self.chunk().push_op(OpCode::OpGetLocal(idx)), None => { self.emit_error( @@ -674,6 +689,7 @@ impl Compiler { // has precedence over dynamic bindings, and // the inherit is useless. if self + .scope_mut() .resolve_local(ident.ident_token().unwrap().text()) .is_some() { @@ -751,7 +767,7 @@ impl Compiler { } } - match self.resolve_local(ident.text()) { + match self.scope_mut().resolve_local(ident.text()) { Some(idx) => self.chunk().push_op(OpCode::OpGetLocal(idx)), None => { if self.scope().with_stack.is_empty() { @@ -952,19 +968,6 @@ impl Compiler { }); } - fn resolve_local(&mut self, name: &str) -> Option<usize> { - let scope = self.scope_mut(); - - for (idx, local) in scope.locals.iter_mut().enumerate().rev() { - if !local.phantom && local.name == name { - local.used = true; - return Some(idx); - } - } - - None - } - fn emit_warning(&mut self, node: rnix::SyntaxNode, kind: WarningKind) { self.warnings.push(EvalWarning { node, kind }) } |