@@ -1351,6 +1351,10 @@ fn trans_field(@block_ctxt cx, &ast.span sp, @ast.expr base,
1351
1351
fail;
1352
1352
}
1353
1353
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
+
1354
1358
fn trans_lval( @block_ctxt cx, @ast. expr e) -> tup( result, bool) {
1355
1359
alt ( e. node) {
1356
1360
case ( ast. expr_name( ?n, ?dopt, _) ) {
@@ -1396,20 +1400,56 @@ impure fn trans_cast(@block_ctxt cx, @ast.expr e, &ast.ann ann) -> result {
1396
1400
}
1397
1401
1398
1402
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 )
1400
1404
-> tup( @block_ctxt, vec[ ValueRef ] ) {
1401
1405
let vec[ ValueRef ] vs = vec( cx. fcx. lltaskptr) ;
1402
1406
let @block_ctxt bcx = cx;
1403
1407
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 = 0 u;
1404
1415
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 ;
1408
1419
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
+ }
1410
1447
}
1411
- vs += res. val;
1412
- bcx = res. bcx;
1448
+
1449
+ vs += re. val;
1450
+ bcx = re. bcx;
1451
+
1452
+ i += 1 u;
1413
1453
}
1414
1454
1415
1455
ret tup( bcx, vs) ;
@@ -1419,7 +1459,8 @@ impure fn trans_call(@block_ctxt cx, @ast.expr f,
1419
1459
vec[ @ast. expr] args) -> result {
1420
1460
auto f_res = trans_lval( cx, f) ;
1421
1461
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) ;
1423
1464
ret res( args_res. _0,
1424
1465
args_res. _0. build. FastCall ( f_res. _0. val, args_res. _1) ) ;
1425
1466
}
0 commit comments