Fix bug with scopes
This commit is contained in:
parent
50d3d60a7f
commit
340de3c984
2 changed files with 5 additions and 3 deletions
|
@ -236,9 +236,9 @@ impl Locals {
|
||||||
}
|
}
|
||||||
|
|
||||||
pub fn get_ref(&self, var: &IrVar) -> &str {
|
pub fn get_ref(&self, var: &IrVar) -> &str {
|
||||||
self.var_to_location.get(var).expect(&format!(
|
self.var_to_location.get(var).unwrap_or_else(|| {
|
||||||
"Tried to use non-existant var '{var}' in assembly generation!"
|
panic!("Tried to use non-existant var '{var}' in assembly generation!")
|
||||||
))
|
})
|
||||||
}
|
}
|
||||||
|
|
||||||
pub fn stack_used(&self) -> i64 {
|
pub fn stack_used(&self) -> i64 {
|
||||||
|
|
|
@ -333,9 +333,11 @@ fn visit_ast_node<'source>(
|
||||||
}
|
}
|
||||||
Block(expressions) => {
|
Block(expressions) => {
|
||||||
let mut result_var = add_var(&Type::Unit, types);
|
let mut result_var = add_var(&Type::Unit, types);
|
||||||
|
symbols.push_level();
|
||||||
for expression in expressions {
|
for expression in expressions {
|
||||||
result_var = visit_ast_node(expression, types, symbols, instructions, labels);
|
result_var = visit_ast_node(expression, types, symbols, instructions, labels);
|
||||||
}
|
}
|
||||||
|
symbols.remove_level();
|
||||||
result_var
|
result_var
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
Reference in a new issue