[fine] Fix block compilation
This commit is contained in:
parent
1eb7da77fc
commit
40d611ae37
3 changed files with 83 additions and 30 deletions
|
|
@ -477,6 +477,11 @@ fn compile_call_expression(c: &mut Compiler, tree: &Tree) -> CR {
|
|||
}
|
||||
|
||||
fn compile_block_expression(c: &mut Compiler, tree: &Tree) -> CR {
|
||||
if tree.children.len() == 2 {
|
||||
c.push(Instruction::PushNothing);
|
||||
return OK;
|
||||
}
|
||||
|
||||
let last_is_brace = tree.nth_token(tree.children.len() - 1).is_some();
|
||||
let last_index = tree.children.len() - if last_is_brace { 2 } else { 1 };
|
||||
|
||||
|
|
@ -499,6 +504,7 @@ fn compile_statement(c: &mut Compiler, t: TreeRef, gen_value: bool) {
|
|||
TreeKind::LetStatement => compile_let_statement(c, t, tree, gen_value),
|
||||
TreeKind::ExpressionStatement => compile_expression_statement(c, tree, gen_value),
|
||||
TreeKind::IfStatement => compile_if_statement(c, tree, gen_value),
|
||||
TreeKind::Block => compile_block_statement(c, t, gen_value),
|
||||
_ => ice!(c, t, "unsupported tree kind {:?}", tree.kind),
|
||||
};
|
||||
if matches!(cr, None) {
|
||||
|
|
@ -607,3 +613,12 @@ fn compile_function_declaration(c: &mut Compiler, t: TreeRef, tree: &Tree, gen_v
|
|||
|
||||
OK
|
||||
}
|
||||
|
||||
fn compile_block_statement(c: &mut Compiler, t: TreeRef, gen_value: bool) -> CR {
|
||||
compile_expression(c, t);
|
||||
if !gen_value {
|
||||
c.push(Instruction::Discard);
|
||||
}
|
||||
|
||||
OK
|
||||
}
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue