feat(tazjin/rlox): Implement variable depth resolver

Implements the first part of the resolver from
https://craftinginterpreters.com/resolving-and-binding.html

This is wired up to the execution paths in main, but not yet in the
tests. The resolved depth is also not actually used for variable
lookups (yet).

Change-Id: I3a8615252b7b9b12d5a290c5ddf85988f61b9184
Reviewed-on: https://cl.tvl.fyi/c/depot/+/2403
Reviewed-by: tazjin <mail@tazj.in>
Tested-by: BuildkiteCI
This commit is contained in:
Vincent Ambo 2021-01-16 15:11:36 +03:00 committed by tazjin
parent f472c82427
commit 29335a8b63
5 changed files with 217 additions and 16 deletions

View file

@ -107,13 +107,13 @@ impl Environment {
}
fn get(&self, name: &parser::Variable) -> Result<Value, Error> {
let ident = identifier_str(&name.0)?;
let ident = identifier_str(&name.name)?;
self.values
.get(ident)
.map(Clone::clone)
.ok_or_else(|| Error {
line: name.0.line,
line: name.name.line,
kind: ErrorKind::UndefinedVariable(ident.into()),
})
.or_else(|err| {