Skip to content

Commit 70e5457

Browse files
committed
Make box prefix operator and box type carry mutability flag.
1 parent bd9f454 commit 70e5457

File tree

5 files changed

+17
-14
lines changed

5 files changed

+17
-14
lines changed

src/comp/front/ast.rs

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -188,7 +188,7 @@ fn binop_to_str(binop op) -> str {
188188
189189
190190
tag unop {
191-
box;
191+
box(mutability);
192192
deref;
193193
bitnot;
194194
not;
@@ -197,7 +197,10 @@ tag unop {
197197
198198
fn unop_to_str(unop op) -> str {
199199
alt (op) {
200-
case (box) {ret "@";}
200+
case (box(?mt)) {
201+
if (mt == mut) { ret "@mutable"; }
202+
ret "@";
203+
}
201204
case (deref) {ret "*";}
202205
case (bitnot) {ret "~";}
203206
case (not) {ret "!";}

src/comp/front/parser.rs

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1074,9 +1074,10 @@ impure fn parse_prefix_expr(parser p) -> @ast.expr {
10741074

10751075
case (token.AT) {
10761076
p.bump();
1077+
auto m = parse_mutability(p);
10771078
auto e = parse_prefix_expr(p);
10781079
hi = e.span;
1079-
ex = ast.expr_unary(ast.box, e, ast.ann_none);
1080+
ex = ast.expr_unary(ast.box(m), e, ast.ann_none);
10801081
}
10811082

10821083
case (_) {

src/comp/middle/trans.rs

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1424,7 +1424,7 @@ fn trans_malloc_boxed(@block_ctxt cx, @ty.t t) -> result {
14241424
// Synthesize a fake box type structurally so we have something
14251425
// to measure the size of.
14261426
auto boxed_body = ty.plain_tup_ty(vec(plain_ty(ty.ty_int), t));
1427-
auto box_ptr = ty.plain_box_ty(t);
1427+
auto box_ptr = ty.plain_box_ty(t, ast.imm);
14281428
auto sz = size_of(cx, boxed_body);
14291429
auto llty = type_of(cx.fcx.ccx, box_ptr);
14301430
ret trans_raw_malloc(sz.bcx, llty, sz.val);
@@ -2005,7 +2005,7 @@ fn iter_structural_ty_full(@block_ctxt cx,
20052005
auto box_a_ptr = cx.build.Load(box_a_cell);
20062006
auto box_b_ptr = cx.build.Load(box_b_cell);
20072007
auto tnil = plain_ty(ty.ty_nil);
2008-
auto tbox = ty.plain_box_ty(tnil);
2008+
auto tbox = ty.plain_box_ty(tnil, ast.imm);
20092009

20102010
auto inner_cx = new_sub_block_ctxt(cx, "iter box");
20112011
auto next_cx = new_sub_block_ctxt(cx, "next");
@@ -2557,7 +2557,7 @@ fn trans_unary(@block_ctxt cx, ast.unop op,
25572557
ret res(sub.bcx, sub.bcx.build.Neg(sub.val));
25582558
}
25592559
}
2560-
case (ast.box) {
2560+
case (ast.box(_)) {
25612561
auto e_ty = ty.expr_ty(e);
25622562
auto e_val = sub.val;
25632563
auto box_ty = node_ann_type(sub.bcx.fcx.ccx, a);
@@ -3943,7 +3943,7 @@ fn trans_bind_thunk(@crate_ctxt cx,
39433943
auto bcx = new_top_block_ctxt(fcx);
39443944
auto lltop = bcx.llbb;
39453945

3946-
auto llclosure_ptr_ty = type_of(cx, ty.plain_box_ty(closure_ty));
3946+
auto llclosure_ptr_ty = type_of(cx, ty.plain_box_ty(closure_ty, ast.imm));
39473947
auto llclosure = bcx.build.PointerCast(fcx.llenv, llclosure_ptr_ty);
39483948

39493949
auto lltarget = GEP_tup_like(bcx, closure_ty, llclosure,
@@ -5819,7 +5819,7 @@ fn trans_obj(@crate_ctxt cx, &ast._obj ob, ast.def_id oid,
58195819
let @ty.t body_ty = ty.plain_tup_ty(vec(tydesc_ty,
58205820
typarams_ty,
58215821
fields_ty));
5822-
let @ty.t boxed_body_ty = ty.plain_box_ty(body_ty);
5822+
let @ty.t boxed_body_ty = ty.plain_box_ty(body_ty, ast.imm);
58235823

58245824
// Malloc a box for the body.
58255825
auto box = trans_malloc_boxed(bcx, body_ty);

src/comp/middle/ty.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -564,8 +564,8 @@ fn plain_ty(&sty st) -> @t {
564564
ret @rec(struct=st, cname=none[str]);
565565
}
566566

567-
fn plain_box_ty(@t subty) -> @t {
568-
ret plain_ty(ty_box(rec(ty=subty, mut=ast.imm)));
567+
fn plain_box_ty(@t subty, ast.mutability mut) -> @t {
568+
ret plain_ty(ty_box(rec(ty=subty, mut=mut)));
569569
}
570570

571571
fn plain_tup_ty(vec[@t] elem_tys) -> @t {

src/comp/middle/typeck.rs

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -959,7 +959,7 @@ fn strip_boxes(@ty.t t) -> @ty.t {
959959
fn add_boxes(uint n, @ty.t t) -> @ty.t {
960960
auto t1 = t;
961961
while (n != 0u) {
962-
t1 = ty.plain_box_ty(t1);
962+
t1 = ty.plain_box_ty(t1, ast.imm);
963963
n -= 1u;
964964
}
965965
ret t1;
@@ -1728,9 +1728,8 @@ fn check_expr(&@fn_ctxt fcx, @ast.expr expr) -> @ast.expr {
17281728
auto oper_1 = check_expr(fcx, oper);
17291729
auto oper_t = expr_ty(oper_1);
17301730
alt (unop) {
1731-
case (ast.box) {
1732-
// TODO: mutable
1733-
oper_t = ty.plain_box_ty(oper_t);
1731+
case (ast.box(?mut)) {
1732+
oper_t = ty.plain_box_ty(oper_t, mut);
17341733
}
17351734
case (ast.deref) {
17361735
alt (oper_t.struct) {

0 commit comments

Comments
 (0)