harec

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

commit 38301183b6108808d3b5b1804311f8d52131bce2
parent f4fea315b612524493833607d463b47019f50c64
Author: Drew DeVault <sir@cmpwn.com>
Date:   Mon,  2 Aug 2021 12:07:20 +0200

gen: add gen_expr_with helper

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

Diffstat:
Msrc/gen.c | 25++++++++++++++++++-------
1 file changed, 18 insertions(+), 7 deletions(-)

diff --git a/src/gen.c b/src/gen.c @@ -103,6 +103,9 @@ static struct gen_value gen_expr(struct gen_context *ctx, static void gen_expr_at(struct gen_context *ctx, const struct expression *expr, struct gen_value out); +static struct gen_value gen_expr_with(struct gen_context *ctx, + const struct expression *expr, + struct gen_value *out); static struct gen_value gen_access_ident(struct gen_context *ctx, const struct expression *expr) @@ -215,14 +218,10 @@ gen_expr_list_with(struct gen_context *ctx, // TODO: Set up defer scope for (const struct expressions *exprs = &expr->list.exprs; exprs; exprs = exprs->next) { - if (!exprs->next && out) { - gen_expr_at(ctx, exprs->expr, *out); - return *out; - } else if (!exprs->next && !out) { - return gen_expr(ctx, exprs->expr); - } else { - gen_expr(ctx, exprs->expr); + if (!exprs->next) { + return gen_expr_with(ctx, exprs->expr, out); } + gen_expr(ctx, exprs->expr); } abort(); // Unreachable } @@ -351,6 +350,18 @@ gen_expr_at(struct gen_context *ctx, gen_store(ctx, out, gen_expr(ctx, expr)); } +static struct gen_value +gen_expr_with(struct gen_context *ctx, + const struct expression *expr, + struct gen_value *out) +{ + if (out) { + gen_expr_at(ctx, expr, *out); + return *out; + } + return gen_expr(ctx, expr); +} + static void gen_function_decl(struct gen_context *ctx, const struct declaration *decl) {