@@ -398,18 +398,16 @@ fn malloc_general_dyn(bcx: block, t: ty::t, heap: heap, size: ValueRef) ->
398
398
ret { box : box, body : body} ;
399
399
}
400
400
401
- fn malloc_boxed ( bcx : block , t : ty:: t ) -> { box : ValueRef , body : ValueRef } {
402
- malloc_general_dyn ( bcx, t, heap_shared,
401
+ fn malloc_general ( bcx : block , t : ty:: t , heap : heap ) ->
402
+ { box : ValueRef , body : ValueRef } {
403
+ malloc_general_dyn ( bcx, t, heap,
403
404
llsize_of ( bcx. ccx ( ) , type_of ( bcx. ccx ( ) , t) ) )
404
405
}
405
- fn malloc_unique ( bcx : block , t : ty:: t ) -> { box : ValueRef , body : ValueRef } {
406
- malloc_general_dyn ( bcx, t, heap_exchange,
407
- llsize_of ( bcx. ccx ( ) , type_of ( bcx. ccx ( ) , t) ) )
406
+ fn malloc_boxed ( bcx : block , t : ty:: t ) -> { box : ValueRef , body : ValueRef } {
407
+ malloc_general ( bcx, t, heap_shared)
408
408
}
409
-
410
- fn malloc_unique_dyn ( bcx : block , t : ty:: t , size : ValueRef
411
- ) -> { box : ValueRef , body : ValueRef } {
412
- malloc_general_dyn ( bcx, t, heap_exchange, size)
409
+ fn malloc_unique ( bcx : block , t : ty:: t ) -> { box : ValueRef , body : ValueRef } {
410
+ malloc_general ( bcx, t, heap_exchange)
413
411
}
414
412
415
413
// Type descriptor and type glue stuff
@@ -1487,6 +1485,19 @@ fn trans_lit(cx: block, e: @ast::expr, lit: ast::lit, dest: dest) -> block {
1487
1485
}
1488
1486
}
1489
1487
1488
+
1489
+ fn trans_boxed_expr ( bcx : block , contents : @ast:: expr ,
1490
+ t : ty:: t , heap : heap ,
1491
+ dest : dest ) -> block {
1492
+ let _icx = bcx. insn_ctxt ( "trans_boxed_expr" ) ;
1493
+ let { box, body} = malloc_general ( bcx, t, heap) ;
1494
+ add_clean_free ( bcx, box, true ) ;
1495
+ let bcx = trans_expr_save_in ( bcx, contents, body) ;
1496
+ revoke_clean ( bcx, box) ;
1497
+ ret store_in_dest ( bcx, box, dest) ;
1498
+ }
1499
+
1500
+
1490
1501
fn trans_unary ( bcx : block , op : ast:: unop , e : @ast:: expr ,
1491
1502
un_expr : @ast:: expr , dest : dest ) -> block {
1492
1503
let _icx = bcx. insn_ctxt ( "trans_unary" ) ;
@@ -1509,35 +1520,25 @@ fn trans_unary(bcx: block, op: ast::unop, e: @ast::expr,
1509
1520
alt op {
1510
1521
ast : : not {
1511
1522
let { bcx, val} = trans_temp_expr ( bcx, e) ;
1512
- ret store_in_dest ( bcx, Not ( bcx, val) , dest) ;
1523
+ store_in_dest ( bcx, Not ( bcx, val) , dest)
1513
1524
}
1514
1525
ast:: neg {
1515
1526
let { bcx, val} = trans_temp_expr ( bcx, e) ;
1516
1527
let neg = if ty:: type_is_fp ( e_ty) {
1517
1528
FNeg ( bcx, val)
1518
1529
} else { Neg ( bcx, val) } ;
1519
- ret store_in_dest ( bcx, neg, dest) ;
1530
+ store_in_dest ( bcx, neg, dest)
1520
1531
}
1521
1532
ast:: box ( _) {
1522
- let mut { box, body} = malloc_boxed ( bcx, e_ty) ;
1523
- add_clean_free ( bcx, box, false ) ;
1524
- // Cast the body type to the type of the value. This is needed to
1525
- // make enums work, since enums have a different LLVM type depending
1526
- // on whether they're boxed or not
1527
- let ccx = bcx. ccx ( ) ;
1528
- let llety = T_ptr ( type_of ( ccx, e_ty) ) ;
1529
- body = PointerCast ( bcx, body, llety) ;
1530
- let bcx = trans_expr_save_in ( bcx, e, body) ;
1531
- revoke_clean ( bcx, box) ;
1532
- ret store_in_dest ( bcx, box, dest) ;
1533
+ trans_boxed_expr ( bcx, e, e_ty, heap_shared, dest)
1533
1534
}
1534
1535
ast:: uniq ( _) {
1535
- ret uniq :: trans_uniq ( bcx, e, un_expr . id , dest) ;
1536
+ trans_boxed_expr ( bcx, e, e_ty , heap_exchange , dest)
1536
1537
}
1537
1538
ast:: deref {
1538
1539
bcx. sess ( ) . bug ( "deref expressions should have been \
1539
1540
translated using trans_lval(), not \
1540
- trans_unary()") ;
1541
+ trans_unary()")
1541
1542
}
1542
1543
}
1543
1544
}
0 commit comments