Trying to implement variable lookup and failing hard
* I'll probably have to rewrite environments as a Vec<HashMap> to make things simpler
This commit is contained in:
parent
c97ad0ad7e
commit
bd156e619f
2 changed files with 26 additions and 0 deletions
src/interpreter
|
@ -48,6 +48,13 @@ impl<'a> InterpreterState<'a> {
|
|||
variables: parent.variables,
|
||||
}
|
||||
}
|
||||
|
||||
fn lookup_var(&self, name: &Token, expr : &ast::ExprNode) -> SloxResult<Value> {
|
||||
match self.variables.get(&(expr as *const ast::ExprNode)) {
|
||||
Some(distance) => Ok(self.environment.borrow().get_at(*distance, name)),
|
||||
None => self.environment.borrow().get(name),
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/// Interpreter flow control, which may be either a value, a loop break or a
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue