Fix variable lookup order

Evaluator uses frames as a stack, so to find the most-recent variable
binding we have to iterate through it the reverse way. This fixes a bug
manifested by:

fn a(x)
 x + 20
end

fn b(x)
 a(x) + 20
end
This commit is contained in:
greg 2016-01-25 01:36:59 -08:00
parent 231de69084
commit f33cfdadfe
1 changed files with 1 additions and 1 deletions

View File

@ -51,7 +51,7 @@ impl Evaluator {
}
fn lookup_binding(&mut self, var: String) -> Option<Expression> {
for frame in self.frames.iter() {
for frame in self.frames.iter().rev() {
match frame.map.get(&var) {
None => (),
Some(expr) => return Some(expr.clone()),