fix branches inside if

This commit is contained in:
2021-11-02 00:03:34 +01:00
parent b47f1ef2bc
commit 2d901e4c61
2 changed files with 3 additions and 0 deletions

1
.gitignore vendored
View File

@@ -1,4 +1,5 @@
/target /target
.cargo/ .cargo/
*.wasm *.wasm
*.uw8
*.lua* *.lua*

View File

@@ -475,6 +475,7 @@ fn emit_expression<'a>(ctx: &mut FunctionContext<'a>, expr: &'a ast::Expression)
emit_expression(ctx, condition); emit_expression(ctx, condition);
ctx.function ctx.function
.instruction(&Instruction::If(map_block_type(expr.type_))); .instruction(&Instruction::If(map_block_type(expr.type_)));
ctx.labels.push(String::new());
emit_expression(ctx, if_true); emit_expression(ctx, if_true);
if if_true.type_.is_some() && if_true.type_ != expr.type_ { if if_true.type_.is_some() && if_true.type_ != expr.type_ {
ctx.function.instruction(&Instruction::Drop); ctx.function.instruction(&Instruction::Drop);
@@ -486,6 +487,7 @@ fn emit_expression<'a>(ctx: &mut FunctionContext<'a>, expr: &'a ast::Expression)
ctx.function.instruction(&Instruction::Drop); ctx.function.instruction(&Instruction::Drop);
} }
} }
ctx.labels.pop();
ctx.function.instruction(&Instruction::End); ctx.function.instruction(&Instruction::End);
} }
ast::Expr::Return { value } => { ast::Expr::Return { value } => {