@@ -2485,12 +2485,15 @@ impure fn trans_obj(@crate_ctxt cx, &ast._obj ob, ast.def_id oid,
2485
2485
for ( ty. arg a in arg_tys) {
2486
2486
append[ @ty. t] ( obj_fields, a. ty) ;
2487
2487
}
2488
- // Synthesize an obj body:
2488
+
2489
+ // Synthesize an obj body type.
2489
2490
let @ty. t fields_ty = ty. plain_ty( ty. ty_tup( obj_fields) ) ;
2490
2491
let TypeRef llfields_ty = type_of( bcx. fcx. ccx, fields_ty) ;
2491
2492
let TypeRef llobj_body_ty =
2492
- T_ptr ( T_box ( T_struct ( vec( T_tydesc ( ) ,
2493
+ T_ptr ( T_box ( T_struct ( vec( T_ptr ( T_tydesc ( ) ) ,
2493
2494
llfields_ty) ) ) ) ;
2495
+
2496
+ // Malloc a box for the body.
2494
2497
auto r = trans_malloc_inner( bcx, llobj_body_ty) ;
2495
2498
auto box = r. val;
2496
2499
auto rc = r. bcx. build. GEP ( box,
@@ -2501,8 +2504,32 @@ impure fn trans_obj(@crate_ctxt cx, &ast._obj ob, ast.def_id oid,
2501
2504
C_int ( abi. box_rc_field_body) ) ) ;
2502
2505
r. bcx. build. Store ( C_int ( 1 ) , rc) ;
2503
2506
2504
- // FIXME: Copy args into body
2507
+ // Store body tydesc.
2508
+ auto body_tydesc =
2509
+ r. bcx. build. GEP ( body,
2510
+ vec( C_int ( 0 ) ,
2511
+ C_int ( abi. obj_body_elt_tydesc) ) ) ;
2512
+
2513
+ auto fields_tydesc = get_tydesc( r. bcx, fields_ty) ;
2514
+ r. bcx. build. Store ( fields_tydesc, body_tydesc) ;
2515
+
2516
+ // Copy args into body fields.
2517
+ auto body_fields =
2518
+ r. bcx. build. GEP ( body,
2519
+ vec( C_int ( 0 ) ,
2520
+ C_int ( abi. obj_body_elt_fields) ) ) ;
2521
+
2522
+ let int i = 0 ;
2523
+ for ( ast. obj_field f in ob. fields) {
2524
+ auto arg = r. bcx. fcx. llargs. get( f. id) ;
2525
+ arg = r. bcx. build. Load ( arg) ;
2526
+ auto field = r. bcx. build. GEP ( body_fields,
2527
+ vec( C_int ( 0 ) , C_int ( i) ) ) ;
2528
+ r = copy_ty( r. bcx, true , field, arg, arg_tys. ( i) . ty) ;
2529
+ i += 1 ;
2530
+ }
2505
2531
2532
+ // Store box ptr in outer pair.
2506
2533
auto p = r. bcx. build. PointerCast ( box, llbox_ty) ;
2507
2534
r. bcx. build. Store ( p, pair_box) ;
2508
2535
}
0 commit comments