Skip to content

Commit 3f3a121

Browse files
committed
Copy body tydesc and args into obj bodies.
1 parent a2a642c commit 3f3a121

File tree

1 file changed

+30
-3
lines changed

1 file changed

+30
-3
lines changed

src/comp/middle/trans.rs

Lines changed: 30 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -2485,12 +2485,15 @@ impure fn trans_obj(@crate_ctxt cx, &ast._obj ob, ast.def_id oid,
24852485
for (ty.arg a in arg_tys) {
24862486
append[@ty.t](obj_fields, a.ty);
24872487
}
2488-
// Synthesize an obj body:
2488+
2489+
// Synthesize an obj body type.
24892490
let @ty.t fields_ty = ty.plain_ty(ty.ty_tup(obj_fields));
24902491
let TypeRef llfields_ty = type_of(bcx.fcx.ccx, fields_ty);
24912492
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()),
24932494
llfields_ty))));
2495+
2496+
// Malloc a box for the body.
24942497
auto r = trans_malloc_inner(bcx, llobj_body_ty);
24952498
auto box = r.val;
24962499
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,
25012504
C_int(abi.box_rc_field_body)));
25022505
r.bcx.build.Store(C_int(1), rc);
25032506

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+
}
25052531

2532+
// Store box ptr in outer pair.
25062533
auto p = r.bcx.build.PointerCast(box, llbox_ty);
25072534
r.bcx.build.Store(p, pair_box);
25082535
}

0 commit comments

Comments
 (0)