1
0
Fork 0

Fix bug with scopes

This commit is contained in:
Vili Sinervä 2025-02-26 19:43:43 +02:00
parent 50d3d60a7f
commit 340de3c984
No known key found for this signature in database
GPG key ID: DF8FEAF54EFAC996
2 changed files with 5 additions and 3 deletions

View file

@ -236,9 +236,9 @@ impl Locals {
}
pub fn get_ref(&self, var: &IrVar) -> &str {
self.var_to_location.get(var).expect(&format!(
"Tried to use non-existant var '{var}' in assembly generation!"
))
self.var_to_location.get(var).unwrap_or_else(|| {
panic!("Tried to use non-existant var '{var}' in assembly generation!")
})
}
pub fn stack_used(&self) -> i64 {

View file

@ -333,9 +333,11 @@ fn visit_ast_node<'source>(
}
Block(expressions) => {
let mut result_var = add_var(&Type::Unit, types);
symbols.push_level();
for expression in expressions {
result_var = visit_ast_node(expression, types, symbols, instructions, labels);
}
symbols.remove_level();
result_var
}
}