Skip to content

Commit 69325f8

Browse files
committed
More comments.
1 parent dcf7fbf commit 69325f8

File tree

1 file changed

+17
-0
lines changed

1 file changed

+17
-0
lines changed

src/comp/middle/trans.rs

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1641,6 +1641,8 @@ fn GEP_tag(@block_ctxt cx,
16411641
}
16421642

16431643

1644+
// trans_raw_malloc: expects a type indicating which pointer type we want and
1645+
// a size indicating how much space we want malloc'd.
16441646
fn trans_raw_malloc(&@block_ctxt cx, TypeRef llptr_ty, ValueRef llsize)
16451647
-> result {
16461648
// FIXME: need a table to collect tydesc globals.
@@ -1650,14 +1652,29 @@ fn trans_raw_malloc(&@block_ctxt cx, TypeRef llptr_ty, ValueRef llsize)
16501652
ret res(cx, cx.build.PointerCast(rval, llptr_ty));
16511653
}
16521654

1655+
1656+
// trans_malloc_boxed: expects an unboxed type and returns a pointer to enough
1657+
// space for something of that type, along with space for a reference count;
1658+
// in other words, it allocates a box for something of that type.
16531659
fn trans_malloc_boxed(&@block_ctxt cx, ty::t t) -> result {
16541660
// Synthesize a fake box type structurally so we have something
16551661
// to measure the size of.
1662+
1663+
// We synthesize two types here because we want both the type of the
1664+
// pointer and the pointee. boxed_body is the type that we measure the
1665+
// size of; box_ptr is the type that's converted to a TypeRef and used as
1666+
// the pointer cast target in trans_raw_malloc.
16561667
auto boxed_body = ty::mk_imm_tup(cx.fcx.lcx.ccx.tcx,
1668+
// The mk_int here is the space being
1669+
// reserved for the refcount.
16571670
[ty::mk_int(cx.fcx.lcx.ccx.tcx), t]);
16581671
auto box_ptr = ty::mk_imm_box(cx.fcx.lcx.ccx.tcx, t);
16591672
auto sz = size_of(cx, boxed_body);
1673+
1674+
// Grab the TypeRef type of box_ptr, because that's what trans_raw_malloc
1675+
// wants.
16601676
auto llty = type_of(cx.fcx.lcx.ccx, cx.sp, box_ptr);
1677+
16611678
ret trans_raw_malloc(sz.bcx, llty, sz.val);
16621679
}
16631680

0 commit comments

Comments
 (0)