harec

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

commit 0c21ffb1f23afa642395895a5e32036d7962aa05
parent dc6f41925e1f731357817ad326920a9b670c7e39
Author: Drew DeVault <sir@cmpwn.com>
Date:   Wed,  4 Aug 2021 10:53:30 +0200

gen: implement basic assignment

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

Diffstat:
Msrc/gen.c | 18+++++++++++++++++-
1 file changed, 17 insertions(+), 1 deletion(-)

diff --git a/src/gen.c b/src/gen.c @@ -303,6 +303,22 @@ gen_expr_assert(struct gen_context *ctx, const struct expression *expr) } static struct gen_value +gen_expr_assign(struct gen_context *ctx, const struct expression *expr) +{ + struct expression *object = expr->assign.object; + struct expression *value = expr->assign.value; + assert(object->type == EXPR_ACCESS || expr->assign.indirect); // Invariant + assert(object->type != EXPR_SLICE); // TODO + assert(!expr->assign.indirect); // TODO + assert(expr->assign.op == BIN_LEQUAL); // TODO + + struct gen_value obj = gen_expr_access_addr(ctx, object); + gen_store(ctx, obj, gen_expr(ctx, value)); + + return gv_void; +} + +static struct gen_value gen_expr_binarithm(struct gen_context *ctx, const struct expression *expr) { struct gen_value lvalue = gen_expr(ctx, expr->binarithm.lvalue); @@ -633,7 +649,7 @@ gen_expr(struct gen_context *ctx, const struct expression *expr) case EXPR_ASSERT: return gen_expr_assert(ctx, expr); case EXPR_ASSIGN: - assert(0); // TODO + return gen_expr_assign(ctx, expr); case EXPR_BINARITHM: return gen_expr_binarithm(ctx, expr); case EXPR_BINDING: