diff options
| author | Graydon Hoare <[email protected]> | 2010-12-20 17:28:07 -0800 |
|---|---|---|
| committer | Graydon Hoare <[email protected]> | 2010-12-20 17:28:07 -0800 |
| commit | ed1dddc33f2dfb6f9247ae877e64fead5642f360 (patch) | |
| tree | 9d27aea4f61664d0443eece452c2a27bc137e2dd /src/comp/middle | |
| parent | Support ty_obj in trans_field; simple-obj.rs compiles (but crashes). (diff) | |
| download | rust-ed1dddc33f2dfb6f9247ae877e64fead5642f360.tar.xz rust-ed1dddc33f2dfb6f9247ae877e64fead5642f360.zip | |
Null-check on obj box ptr, init to null. Un-XFAIL simple-obj.rs.
Diffstat (limited to 'src/comp/middle')
| -rw-r--r-- | src/comp/middle/trans.rs | 34 |
1 files changed, 26 insertions, 8 deletions
diff --git a/src/comp/middle/trans.rs b/src/comp/middle/trans.rs index d0c13005..752c9e0e 100644 --- a/src/comp/middle/trans.rs +++ b/src/comp/middle/trans.rs @@ -812,6 +812,23 @@ fn iter_structural_ty(@block_ctxt cx, -> result { let result r = res(cx, C_nil()); + fn iter_boxpp(@block_ctxt cx, + ValueRef box_cell, + val_and_ty_fn f) -> result { + auto box_ptr = cx.build.Load(box_cell); + auto tnil = typeck.plain_ty(typeck.ty_nil); + auto tbox = typeck.plain_ty(typeck.ty_box(tnil)); + + auto inner_cx = new_sub_block_ctxt(cx, "iter box"); + auto next_cx = new_sub_block_ctxt(cx, "next"); + auto null_test = cx.build.IsNull(box_ptr); + cx.build.CondBr(null_test, next_cx.llbb, inner_cx.llbb); + + auto r = f(inner_cx, box_ptr, tbox); + r.bcx.build.Br(next_cx.llbb); + ret res(next_cx, r.val); + } + alt (t.struct) { case (typeck.ty_tup(?args)) { let int i = 0; @@ -919,20 +936,14 @@ fn iter_structural_ty(@block_ctxt cx, cx.build.GEP(v, vec(C_int(0), C_int(abi.fn_field_box))); - auto box_ptr = cx.build.Load(box_cell); - auto tnil = typeck.plain_ty(typeck.ty_nil); - auto tbox = typeck.plain_ty(typeck.ty_box(tnil)); - ret f(cx, box_ptr, tbox); + ret iter_boxpp(cx, box_cell, f); } case (typeck.ty_obj(_)) { auto box_cell = cx.build.GEP(v, vec(C_int(0), C_int(abi.obj_field_box))); - auto box_ptr = cx.build.Load(box_cell); - auto tnil = typeck.plain_ty(typeck.ty_nil); - auto tbox = typeck.plain_ty(typeck.ty_box(tnil)); - ret f(cx, box_ptr, tbox); + ret iter_boxpp(cx, box_cell, f); } case (_) { cx.fcx.ccx.sess.unimpl("type in iter_structural_ty"); @@ -2447,7 +2458,14 @@ impure fn trans_obj(@crate_ctxt cx, &ast._obj ob, ast.def_id oid, auto pair_vtbl = bcx.build.GEP(pair, vec(C_int(0), C_int(abi.obj_field_vtbl))); + auto pair_box = bcx.build.GEP(pair, + vec(C_int(0), + C_int(abi.obj_field_box))); bcx.build.Store(vtbl, pair_vtbl); + + // FIXME: allocate the object body, copy the args in, etc. + bcx.build.Store(C_null(T_ptr(T_box(T_nil()))), pair_box); + bcx.build.Ret(bcx.build.Load(pair)); } |