harec

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

commit 28b1bf07c3bb293527d0df31f34074b2e025a417
parent 55a08bbcb2a7170ae3fba45bddadb371ff96b81f
Author: Drew DeVault <sir@cmpwn.com>
Date:   Wed,  1 Sep 2021 12:58:05 +0200

gen: gen defers after yield value

Signed-off-by: Drew DeVault <sir@cmpwn.com>

Diffstat:
Msrc/gen.c | 14++++++++------
1 file changed, 8 insertions(+), 6 deletions(-)

diff --git a/src/gen.c b/src/gen.c @@ -878,6 +878,13 @@ gen_expr_control(struct gen_context *ctx, const struct expression *expr) { struct gen_scope *scope = gen_scope_lookup(ctx, expr->control.scope); + if (expr->control.value) { + struct gen_value result = gen_expr_with(ctx, + expr->control.value, scope->out); + branch_copyresult(ctx, result, + scope->result, scope->out); + } + struct gen_scope *deferred = ctx->scope; while (deferred != NULL) { gen_defers(ctx, deferred); @@ -886,6 +893,7 @@ gen_expr_control(struct gen_context *ctx, const struct expression *expr) } deferred = deferred->parent; } + switch (expr->type) { case EXPR_BREAK: assert(scope->scope->class == SCOPE_LOOP); @@ -897,12 +905,6 @@ gen_expr_control(struct gen_context *ctx, const struct expression *expr) break; case EXPR_YIELD: assert(scope->scope->class == SCOPE_COMPOUND); - if (expr->control.value) { - struct gen_value result = gen_expr_with(ctx, - expr->control.value, scope->out); - branch_copyresult(ctx, result, - scope->result, scope->out); - } pushi(ctx->current, NULL, Q_JMP, scope->end, NULL); break; default: abort(); // Invariant