Skip to content

Commit 219e923

Browse files
committed
---
yaml --- r: 1021 b: refs/heads/master c: 7f85945 h: refs/heads/master i: 1019: e2f22ad v: v3
1 parent ff51cf0 commit 219e923

File tree

2 files changed

+50
-9
lines changed

2 files changed

+50
-9
lines changed

[refs]

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,2 +1,2 @@
11
---
2-
refs/heads/master: 15a614acb4dcb94181609add10bc58a4156d4d4d
2+
refs/heads/master: 7f85945b054ff5b991ae1be021882ba15f56d416

trunk/src/comp/middle/trans.rs

Lines changed: 49 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1351,6 +1351,10 @@ fn trans_field(@block_ctxt cx, &ast.span sp, @ast.expr base,
13511351
fail;
13521352
}
13531353

1354+
// The additional bool returned indicates whether it's mem (that is
1355+
// represented as an alloca or heap, hence needs a 'load' to be used as an
1356+
// immediate).
1357+
13541358
fn trans_lval(@block_ctxt cx, @ast.expr e) -> tup(result, bool) {
13551359
alt (e.node) {
13561360
case (ast.expr_name(?n, ?dopt, _)) {
@@ -1396,20 +1400,56 @@ impure fn trans_cast(@block_ctxt cx, @ast.expr e, &ast.ann ann) -> result {
13961400
}
13971401

13981402

1399-
impure fn trans_args(@block_ctxt cx, &vec[@ast.expr] es)
1403+
impure fn trans_args(@block_ctxt cx, &vec[@ast.expr] es, @typeck.ty fn_ty)
14001404
-> tup(@block_ctxt, vec[ValueRef]) {
14011405
let vec[ValueRef] vs = vec(cx.fcx.lltaskptr);
14021406
let @block_ctxt bcx = cx;
14031407

1408+
let vec[typeck.arg] args = vec(); // FIXME: typestate bug
1409+
alt (fn_ty.struct) {
1410+
case (typeck.ty_fn(?a, _)) { args = a; }
1411+
case (_) { fail; }
1412+
}
1413+
1414+
auto i = 0u;
14041415
for (@ast.expr e in es) {
1405-
auto res = trans_expr(bcx, e);
1406-
// Until here we've been treating structures by pointer;
1407-
// we are now passing it as an arg, so need to load it.
1416+
auto mode = args.(i).mode;
1417+
1418+
auto re;
14081419
if (typeck.type_is_structural(typeck.expr_ty(e))) {
1409-
res.val = res.bcx.build.Load(res.val);
1420+
re = trans_expr(bcx, e);
1421+
if (mode == ast.val) {
1422+
// Until here we've been treating structures by pointer;
1423+
// we are now passing it as an arg, so need to load it.
1424+
re.val = re.bcx.build.Load(re.val);
1425+
}
1426+
} else {
1427+
if (mode == ast.alias) {
1428+
let tup(result, bool /* is a pointer? */) pair;
1429+
if (typeck.is_lval(e)) {
1430+
pair = trans_lval(bcx, e);
1431+
} else {
1432+
pair = tup(trans_expr(bcx, e), false);
1433+
}
1434+
1435+
if (!pair._1) {
1436+
// Have to synthesize a pointer here...
1437+
auto llty = val_ty(pair._0.val);
1438+
auto llptr = pair._0.bcx.build.Alloca(llty);
1439+
pair._0.bcx.build.Store(pair._0.val, llptr);
1440+
re = res(pair._0.bcx, llptr);
1441+
} else {
1442+
re = pair._0;
1443+
}
1444+
} else {
1445+
re = trans_expr(bcx, e);
1446+
}
14101447
}
1411-
vs += res.val;
1412-
bcx = res.bcx;
1448+
1449+
vs += re.val;
1450+
bcx = re.bcx;
1451+
1452+
i += 1u;
14131453
}
14141454

14151455
ret tup(bcx, vs);
@@ -1419,7 +1459,8 @@ impure fn trans_call(@block_ctxt cx, @ast.expr f,
14191459
vec[@ast.expr] args) -> result {
14201460
auto f_res = trans_lval(cx, f);
14211461
check (! f_res._1);
1422-
auto args_res = trans_args(f_res._0.bcx, args);
1462+
auto fn_ty = typeck.expr_ty(f);
1463+
auto args_res = trans_args(f_res._0.bcx, args, fn_ty);
14231464
ret res(args_res._0,
14241465
args_res._0.build.FastCall(f_res._0.val, args_res._1));
14251466
}

0 commit comments

Comments
 (0)