cgen: fix mutable receivers

pull/3954/head
Alexander Medvednikov 2020-03-07 22:37:03 +01:00
parent 783dee1f48
commit d9854f2abd
3 changed files with 24 additions and 29 deletions

View File

@ -317,7 +317,11 @@ fn (g mut Gen) gen_fn_decl(it ast.FnDecl) {
} }
// Receiver is the first argument // Receiver is the first argument
if it.is_method { if it.is_method {
styp := g.typ(it.receiver.typ) mut styp := g.typ(it.receiver.typ)
// if table.type_nr_muls(it.receiver.typ) > 0 {
if it.rec_mut {
styp += '*'
}
g.write('$styp $it.receiver.name') g.write('$styp $it.receiver.name')
// TODO mut // TODO mut
g.definitions.write('$styp $it.receiver.name') g.definitions.write('$styp $it.receiver.name')
@ -415,15 +419,6 @@ fn (g mut Gen) expr(node ast.Expr) {
g.call_args(it.args) g.call_args(it.args)
g.write(')') g.write(')')
g.is_c_call = false g.is_c_call = false
/*
for i, expr in it.args {
g.expr(expr)
if i != it.args.len - 1 {
g.write(', ')
}
}
*/
} }
ast.CastExpr { ast.CastExpr {
if it.typ == table.string_type_idx { if it.typ == table.string_type_idx {

View File

@ -17,7 +17,7 @@ typedef struct {
// end of definitions #endif // end of definitions #endif
int pi2; // inited later int pi2; // inited later
void foo(int a); void foo(int a);
void User_inc_age(User u, int n); void User_inc_age(User* u, int n);
int get_int(string a); int get_int(string a);
bool get_bool(); bool get_bool();
int get_int2(); int get_int2();
@ -93,7 +93,7 @@ i < 10; i++) {
println(string_add(s, d)); println(string_add(s, d));
} }
void User_inc_age(User u, int n) { void User_inc_age(User* u, int n) {
u.age += n; u.age += n;
} }