diff options
Diffstat (limited to 'tvix/eval/src/compiler.rs')
-rw-r--r-- | tvix/eval/src/compiler.rs | 21 |
1 files changed, 20 insertions, 1 deletions
diff --git a/tvix/eval/src/compiler.rs b/tvix/eval/src/compiler.rs index c0e895b7be5b..ac630360d403 100644 --- a/tvix/eval/src/compiler.rs +++ b/tvix/eval/src/compiler.rs @@ -331,7 +331,14 @@ impl Compiler { "false" => self.chunk.push_op(OpCode::OpFalse), "null" => self.chunk.push_op(OpCode::OpNull), - _ => todo!("identifier access"), + name => { + // Note: `with` and some other special scoping + // features are not yet implemented. + match self.resolve_local(name) { + Some(idx) => self.chunk.push_op(OpCode::OpGetLocal(idx)), + None => return Err(Error::UnknownStaticVariable(node)), + } + } }; Ok(()) @@ -727,6 +734,18 @@ impl Compiler { self.chunk.push_op(OpCode::OpCloseScope(pops)); } } + + fn resolve_local(&mut self, name: &str) -> Option<usize> { + let scope = &self.locals; + + for (idx, local) in scope.locals.iter().enumerate().rev() { + if local.name == name { + return Some(idx); + } + } + + None + } } /// Convert a single identifier path fragment to a string if possible, |