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:
parent
231de69084
commit
f33cfdadfe
@ -51,7 +51,7 @@ impl Evaluator {
|
|||||||
}
|
}
|
||||||
|
|
||||||
fn lookup_binding(&mut self, var: String) -> Option<Expression> {
|
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) {
|
match frame.map.get(&var) {
|
||||||
None => (),
|
None => (),
|
||||||
Some(expr) => return Some(expr.clone()),
|
Some(expr) => return Some(expr.clone()),
|
||||||
|
Loading…
Reference in New Issue
Block a user