diff options
-rw-r--r-- | cgen.c | 31 | ||||
-rw-r--r-- | decls_cgen.c | 2 |
2 files changed, 17 insertions, 16 deletions
@@ -28,8 +28,9 @@ static void cgen_type_pre(CGenerator *g, Type *t); static void cgen_type_post(CGenerator *g, Type *t); static void cgen_decl(CGenerator *g, Declaration *d); static void cgen_ret(CGenerator *g, Expression *ret); -static void cgen_val(CGenerator *g, Value v, Type *t); -static void cgen_val_pre(CGenerator *g, Value v, Type *t); +/* yes, these do need to take pointers, and furthermore they must be the same pointer (because of slices) */ +static void cgen_val(CGenerator *g, Value *v, Type *t); +static void cgen_val_pre(CGenerator *g, Value *v, Type *t); static void cgen_val_ptr(CGenerator *g, void *v, Type *t); static void cgen_defs_block(CGenerator *g, Block *b); static void cgen_defs_decl(CGenerator *g, Declaration *d); @@ -538,13 +539,13 @@ static void cgen_val_ptr(CGenerator *g, void *v, Type *t) { } } -static void cgen_val_pre(CGenerator *g, Value v, Type *t) { - cgen_val_ptr_pre(g, val_get_ptr(&v, t), t); +static void cgen_val_pre(CGenerator *g, Value *v, Type *t) { + cgen_val_ptr_pre(g, val_get_ptr(v, t), t); } /* generates a value fit for use as an initializer */ -static void cgen_val(CGenerator *g, Value v, Type *t) { - cgen_val_ptr(g, val_get_ptr(&v, t), t); +static void cgen_val(CGenerator *g, Value *v, Type *t) { + cgen_val_ptr(g, val_get_ptr(v, t), t); } /* can the value generated by cgen_val for this type be used directly (as opposed to being stored in a variable)? */ @@ -1046,7 +1047,7 @@ static void cgen_expr_pre(CGenerator *g, Expression *e) { cgen_write(g, "; "); if (is_range) { if (fo->range.stepval) { - cgen_val_pre(g, *fo->range.stepval, &fo->type); + cgen_val_pre(g, fo->range.stepval, &fo->type); } if (fo->value) cgen_ident(g, fo->value); @@ -1054,7 +1055,7 @@ static void cgen_expr_pre(CGenerator *g, Expression *e) { cgen_write(g, "val_"); cgen_write(g, " += "); if (fo->range.stepval) { - cgen_val(g, *fo->range.stepval, &fo->type); + cgen_val(g, fo->range.stepval, &fo->type); } else { cgen_write(g, "1"); } @@ -1271,14 +1272,14 @@ static void cgen_expr_pre(CGenerator *g, Expression *e) { if (type_is_compileonly(&e->type)) break; if (!cgen_is_type_simple(&e->type)) { - cgen_val_pre(g, e->val, &e->type); + cgen_val_pre(g, &e->val, &e->type); cgen_type_pre(g, &e->type); e->cgen.id = ++g->ident_counter; cgen_write(g, " "); cgen_ident_id(g, e->cgen.id); cgen_type_post(g, &e->type); cgen_write(g, " = "); - cgen_val(g, e->val, &e->type); + cgen_val(g, &e->val, &e->type); cgen_writeln(g, ";"); } break; @@ -1662,7 +1663,7 @@ static void cgen_expr(CGenerator *g, Expression *e) { case EXPR_VAL: { Type *t = &e->type; if (cgen_is_type_simple(t)) { - cgen_val(g, e->val, t); + cgen_val(g, &e->val, t); } else { cgen_ident_id(g, e->cgen.id); } @@ -1756,7 +1757,7 @@ static void cgen_fn(CGenerator *g, FnExpr *f, Value *compile_time_args) { size_t nvarargs = arr_len(vararg); for (size_t v = 0; v < nvarargs; ++v, ++vararg) { Type *type = vararg->type; - Value arg = vararg->val; + Value *arg = &vararg->val; if (!type_is_compileonly(type)) { cgen_val_pre(g, arg, type); cgen_type_pre(g, type); @@ -1773,7 +1774,7 @@ static void cgen_fn(CGenerator *g, FnExpr *f, Value *compile_time_args) { } else { arr_foreach(param->idents, Identifier, ident) { Type *type = decl_type_at_index(param, i); - Value arg = *decl_val_at_index(param, i); + Value *arg = decl_val_at_index(param, i); if (!type_is_compileonly(type)) { cgen_val_pre(g, arg, type); cgen_type_pre(g, type); @@ -1826,7 +1827,7 @@ static void cgen_decl(CGenerator *g, Declaration *d) { } Value *val = decl_val_at_index(d, idx); if (has_expr) { - cgen_val_pre(g, *val, type); + cgen_val_pre(g, val, type); } cgen_type_pre(g, type); cgen_write(g, " "); @@ -1834,7 +1835,7 @@ static void cgen_decl(CGenerator *g, Declaration *d) { cgen_type_post(g, type); if (has_expr) { cgen_write(g, " = "); - cgen_val(g, *val, type); + cgen_val(g, val, type); } else { cgen_write(g, " = "); cgen_zero_value(g, type); diff --git a/decls_cgen.c b/decls_cgen.c index 8ebf051..844db46 100644 --- a/decls_cgen.c +++ b/decls_cgen.c @@ -234,7 +234,7 @@ static void cgen_decls_decl(CGenerator *g, Declaration *d) { if (d->flags & DECL_HAS_EXPR) { Value *val = decl_val_at_index(d, i); cgen_write(g, " = "); - cgen_val(g, *val, type); + cgen_val(g, val, type); } else { cgen_write(g, " = "); cgen_zero_value(g, type); |