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

@ -10,15 +10,15 @@ import (
pub type TypeDecl = AliasTypeDecl | SumTypeDecl
pub type Expr = InfixExpr | IfExpr | StringLiteral | IntegerLiteral | CharLiteral |
FloatLiteral | Ident | CallExpr | BoolLiteral | StructInit | ArrayInit | SelectorExpr | PostfixExpr |
AssignExpr | PrefixExpr | MethodCallExpr | IndexExpr | RangeExpr | MatchExpr |
CastExpr | EnumVal | Assoc | SizeOf | None | MapInit | IfGuardExpr | ParExpr | OrExpr |
pub type Expr = InfixExpr | IfExpr | StringLiteral | IntegerLiteral | CharLiteral |
FloatLiteral | Ident | CallExpr | BoolLiteral | StructInit | ArrayInit | SelectorExpr | PostfixExpr |
AssignExpr | PrefixExpr | MethodCallExpr | IndexExpr | RangeExpr | MatchExpr |
CastExpr | EnumVal | Assoc | SizeOf | None | MapInit | IfGuardExpr | ParExpr | OrExpr |
ConcatExpr | Type | AsCast
pub type Stmt = VarDecl | GlobalDecl | FnDecl | Return | Module | Import | ExprStmt |
ForStmt | StructDecl | ForCStmt | ForInStmt | CompIf | ConstDecl | Attr | BranchStmt |
HashStmt | AssignStmt | EnumDecl | TypeDecl | DeferStmt | GotoLabel | GotoStmt |
pub type Stmt = VarDecl | GlobalDecl | FnDecl | Return | Module | Import | ExprStmt |
ForStmt | StructDecl | ForCStmt | ForInStmt | CompIf | ConstDecl | Attr | BranchStmt |
HashStmt | AssignStmt | EnumDecl | TypeDecl | DeferStmt | GotoLabel | GotoStmt |
LineComment | MultiLineComment | AssertStmt | UnsafeStmt
// pub type Type = StructType | ArrayType
// pub struct StructType {
@ -443,15 +443,15 @@ pub:
pub struct AliasTypeDecl {
pub:
name string
is_pub bool
name string
is_pub bool
parent_type table.Type
}
pub struct SumTypeDecl {
pub:
name string
is_pub bool
name string
is_pub bool
sub_types []table.Type
}
@ -473,12 +473,12 @@ pub:
pub struct AssignExpr {
pub:
op token.Kind
pos token.Position
left Expr
val Expr
//mut:
//left_type table.Type
op token.Kind
pos token.Position
left Expr
val Expr
// mut:
// left_type table.Type
}
pub struct GotoLabel {

View File

@ -317,7 +317,11 @@ fn (g mut Gen) gen_fn_decl(it ast.FnDecl) {
}
// Receiver is the first argument
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')
// TODO mut
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.write(')')
g.is_c_call = false
/*
for i, expr in it.args {
g.expr(expr)
if i != it.args.len - 1 {
g.write(', ')
}
}
*/
}
ast.CastExpr {
if it.typ == table.string_type_idx {

View File

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