diff options
| author | Bruce Hill <bruce@bruce-hill.com> | 2024-11-30 15:33:54 -0500 |
|---|---|---|
| committer | Bruce Hill <bruce@bruce-hill.com> | 2024-11-30 15:33:54 -0500 |
| commit | 357c9faa40e97e28aba25d7cf576cf4343f744dd (patch) | |
| tree | 2696f4e1e0a5c2d8963ce263855e7592305ea0a9 | |
| parent | e38ecde989fe378c49a61d6975784ccfb703cfee (diff) | |
Fix for update assignments
| -rw-r--r-- | compile.c | 4 | ||||
| -rw-r--r-- | typecheck.c | 1 |
2 files changed, 3 insertions, 2 deletions
@@ -359,7 +359,7 @@ static CORD compile_lvalue(env_t *env, ast_t *ast) } else { code_err(ast, "I don't know how to assign to this target"); } - } else if (ast->tag == Var || ast->tag == FieldAccess) { + } else if (ast->tag == Var || ast->tag == FieldAccess || ast->tag == InlineCCode) { return compile(env, ast); } else { code_err(ast, "I don't know how to assign to this"); @@ -610,7 +610,7 @@ CORD compile_statement(env_t *env, ast_t *ast) type_t *lhs_t = get_type(env, Match(test->expr, UpdateAssign)->lhs); auto update = Match(test->expr, UpdateAssign); ast_t *update_var = WrapAST(ast, UpdateAssign, - .lhs=WrapAST(update->lhs, Index, .indexed=WrapAST(update->lhs, InlineCCode, .code="expr", .type=Type(PointerType, lhs_t))), + .lhs=WrapAST(update->lhs, InlineCCode, .code="(*expr)", .type=lhs_t), .op=update->op, .rhs=update->rhs); return CORD_asprintf( "test(({%r = &(%r); %r; *expr;}), %r, %r, %ld, %ld);", diff --git a/typecheck.c b/typecheck.c index 82c1f84a..eb186dff 100644 --- a/typecheck.c +++ b/typecheck.c @@ -1292,6 +1292,7 @@ PUREFUNC bool can_be_mutated(env_t *env, ast_t *ast) { switch (ast->tag) { case Var: return true; + case InlineCCode: return true; case FieldAccess: { auto access = Match(ast, FieldAccess); type_t *fielded_type = get_type(env, access->fielded); |
