Branch local scoping

This commit is contained in:
mars 2022-03-26 22:30:58 -06:00
parent eacd907c3b
commit 2098fef856
2 changed files with 10 additions and 4 deletions

View File

@ -160,8 +160,8 @@ mod tests {
d
} else {
// Test 2 only
// let d = (a - b); // 4
// c = (c * d); // 40
let d = (a - b); // 4
c = (c * d); // 40
d
};

View File

@ -161,15 +161,21 @@ impl<'a> FunctionTranslator<'a> {
}
pub fn translate_branch_body(&mut self, branch_body: &ast::BranchBody) -> Option<Value> {
let scope_size = self.locals.len();
for stmt in branch_body.statements.iter() {
self.translate_statement(stmt);
}
if let Some(tail_expr) = &branch_body.tail_expr {
let tail_val = if let Some(tail_expr) = &branch_body.tail_expr {
Some(self.translate_expr(tail_expr))
} else {
None
}
};
self.locals.truncate(scope_size);
tail_val
}
pub fn translate_binary_op(