harec

Unnamed repository; edit this file 'description' to name the repository.
Log | Files | Refs | README | LICENSE

commit 25eb10d89a174842c937e1466417da01cae8b1cd
parent e094dece2c7113a1eab85fc45f7a6a46d5d03659
Author: Umar Getagazov <umar@handlerug.me>
Date:   Mon, 30 Aug 2021 03:26:35 +0700

gen: stop generating after terminating expression

This commit makes gen_expr_compound_with return early if the current
expression is terminating (which roughly translates to being a jump or
return QBE instruction that concludes a block), making early returns,
breaks or other control statements in compound expressions possible.

Signed-off-by: Umar Getagazov <umar@handlerug.me>

Diffstat:
Msrc/gen.c | 2+-
1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/src/gen.c b/src/gen.c @@ -1332,7 +1332,7 @@ gen_expr_compound_with(struct gen_context *ctx, push_scope(ctx, expr->compound.scope); for (const struct expressions *exprs = &expr->compound.exprs; exprs; exprs = exprs->next) { - if (!exprs->next) { + if (!exprs->next || exprs->expr->terminates) { struct gen_value gv = gen_expr_with( ctx, exprs->expr, out); pop_scope(ctx, !exprs->expr->terminates);