commit 4ee9ef26147c6f117cc7902abd2690f7ea41ee4a
parent 0c21ffb1f23afa642395895a5e32036d7962aa05
Author: Drew DeVault <sir@cmpwn.com>
Date: Wed, 4 Aug 2021 10:55:18 +0200
gen: implement indirect assign
Signed-off-by: Drew DeVault <sir@cmpwn.com>
Diffstat:
1 file changed, 7 insertions(+), 2 deletions(-)
diff --git a/src/gen.c b/src/gen.c
@@ -309,10 +309,15 @@ gen_expr_assign(struct gen_context *ctx, const struct expression *expr)
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);
+ struct gen_value obj;
+ if (expr->assign.indirect) {
+ obj = gen_expr(ctx, object);
+ obj.type = type_dealias(object->result)->pointer.referent;
+ } else {
+ obj = gen_expr_access_addr(ctx, object);
+ }
gen_store(ctx, obj, gen_expr(ctx, value));
return gv_void;