diff options
| author | Graydon Hoare <[email protected]> | 2010-12-22 16:09:59 -0800 |
|---|---|---|
| committer | Graydon Hoare <[email protected]> | 2010-12-22 16:09:59 -0800 |
| commit | 3f3a121043f72a1662f0b0ad24ca2fd09f4b4f27 (patch) | |
| tree | 883baa23bb356abaa659d59d85cbe35e92bff836 /src/comp | |
| parent | Correct bug in typechecking ctor arguments to nonempty objects. (diff) | |
| download | rust-3f3a121043f72a1662f0b0ad24ca2fd09f4b4f27.tar.xz rust-3f3a121043f72a1662f0b0ad24ca2fd09f4b4f27.zip | |
Copy body tydesc and args into obj bodies.
Diffstat (limited to 'src/comp')
| -rw-r--r-- | src/comp/middle/trans.rs | 33 |
1 files changed, 30 insertions, 3 deletions
diff --git a/src/comp/middle/trans.rs b/src/comp/middle/trans.rs index 1ed9370c..25eb1512 100644 --- a/src/comp/middle/trans.rs +++ b/src/comp/middle/trans.rs @@ -2485,12 +2485,15 @@ impure fn trans_obj(@crate_ctxt cx, &ast._obj ob, ast.def_id oid, for (ty.arg a in arg_tys) { append[@ty.t](obj_fields, a.ty); } - // Synthesize an obj body: + + // Synthesize an obj body type. let @ty.t fields_ty = ty.plain_ty(ty.ty_tup(obj_fields)); let TypeRef llfields_ty = type_of(bcx.fcx.ccx, fields_ty); let TypeRef llobj_body_ty = - T_ptr(T_box(T_struct(vec(T_tydesc(), + T_ptr(T_box(T_struct(vec(T_ptr(T_tydesc()), llfields_ty)))); + + // Malloc a box for the body. auto r = trans_malloc_inner(bcx, llobj_body_ty); auto box = r.val; 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, C_int(abi.box_rc_field_body))); r.bcx.build.Store(C_int(1), rc); - // FIXME: Copy args into body + // Store body tydesc. + auto body_tydesc = + r.bcx.build.GEP(body, + vec(C_int(0), + C_int(abi.obj_body_elt_tydesc))); + + auto fields_tydesc = get_tydesc(r.bcx, fields_ty); + r.bcx.build.Store(fields_tydesc, body_tydesc); + + // Copy args into body fields. + auto body_fields = + r.bcx.build.GEP(body, + vec(C_int(0), + C_int(abi.obj_body_elt_fields))); + + let int i = 0; + for (ast.obj_field f in ob.fields) { + auto arg = r.bcx.fcx.llargs.get(f.id); + arg = r.bcx.build.Load(arg); + auto field = r.bcx.build.GEP(body_fields, + vec(C_int(0),C_int(i))); + r = copy_ty(r.bcx, true, field, arg, arg_tys.(i).ty); + i += 1; + } + // Store box ptr in outer pair. auto p = r.bcx.build.PointerCast(box, llbox_ty); r.bcx.build.Store(p, pair_box); } |