diff options
| author | Graydon Hoare <[email protected]> | 2011-04-04 15:44:15 -0700 |
|---|---|---|
| committer | Graydon Hoare <[email protected]> | 2011-04-04 15:44:15 -0700 |
| commit | 70e5457d7c99d3b273c3ef9edaebee1324be85c7 (patch) | |
| tree | 215db03e8e982504f4b182b833140f2a6dcc6c0b /src | |
| parent | Begin comparing vectors from the correct address (diff) | |
| download | rust-70e5457d7c99d3b273c3ef9edaebee1324be85c7.tar.xz rust-70e5457d7c99d3b273c3ef9edaebee1324be85c7.zip | |
Make box prefix operator and box type carry mutability flag.
Diffstat (limited to 'src')
| -rw-r--r-- | src/comp/front/ast.rs | 7 | ||||
| -rw-r--r-- | src/comp/front/parser.rs | 3 | ||||
| -rw-r--r-- | src/comp/middle/trans.rs | 10 | ||||
| -rw-r--r-- | src/comp/middle/ty.rs | 4 | ||||
| -rw-r--r-- | src/comp/middle/typeck.rs | 7 |
5 files changed, 17 insertions, 14 deletions
diff --git a/src/comp/front/ast.rs b/src/comp/front/ast.rs index 46666a34..61450a1b 100644 --- a/src/comp/front/ast.rs +++ b/src/comp/front/ast.rs @@ -188,7 +188,7 @@ fn binop_to_str(binop op) -> str { tag unop { - box; + box(mutability); deref; bitnot; not; @@ -197,7 +197,10 @@ tag unop { fn unop_to_str(unop op) -> str { alt (op) { - case (box) {ret "@";} + case (box(?mt)) { + if (mt == mut) { ret "@mutable"; } + ret "@"; + } case (deref) {ret "*";} case (bitnot) {ret "~";} case (not) {ret "!";} diff --git a/src/comp/front/parser.rs b/src/comp/front/parser.rs index 4c3e6cf0..1e0a9042 100644 --- a/src/comp/front/parser.rs +++ b/src/comp/front/parser.rs @@ -1074,9 +1074,10 @@ impure fn parse_prefix_expr(parser p) -> @ast.expr { case (token.AT) { p.bump(); + auto m = parse_mutability(p); auto e = parse_prefix_expr(p); hi = e.span; - ex = ast.expr_unary(ast.box, e, ast.ann_none); + ex = ast.expr_unary(ast.box(m), e, ast.ann_none); } case (_) { diff --git a/src/comp/middle/trans.rs b/src/comp/middle/trans.rs index 590b3ee8..aeeff169 100644 --- a/src/comp/middle/trans.rs +++ b/src/comp/middle/trans.rs @@ -1424,7 +1424,7 @@ fn trans_malloc_boxed(@block_ctxt cx, @ty.t t) -> result { // Synthesize a fake box type structurally so we have something // to measure the size of. auto boxed_body = ty.plain_tup_ty(vec(plain_ty(ty.ty_int), t)); - auto box_ptr = ty.plain_box_ty(t); + auto box_ptr = ty.plain_box_ty(t, ast.imm); auto sz = size_of(cx, boxed_body); auto llty = type_of(cx.fcx.ccx, box_ptr); ret trans_raw_malloc(sz.bcx, llty, sz.val); @@ -2005,7 +2005,7 @@ fn iter_structural_ty_full(@block_ctxt cx, auto box_a_ptr = cx.build.Load(box_a_cell); auto box_b_ptr = cx.build.Load(box_b_cell); auto tnil = plain_ty(ty.ty_nil); - auto tbox = ty.plain_box_ty(tnil); + auto tbox = ty.plain_box_ty(tnil, ast.imm); auto inner_cx = new_sub_block_ctxt(cx, "iter box"); auto next_cx = new_sub_block_ctxt(cx, "next"); @@ -2557,7 +2557,7 @@ fn trans_unary(@block_ctxt cx, ast.unop op, ret res(sub.bcx, sub.bcx.build.Neg(sub.val)); } } - case (ast.box) { + case (ast.box(_)) { auto e_ty = ty.expr_ty(e); auto e_val = sub.val; auto box_ty = node_ann_type(sub.bcx.fcx.ccx, a); @@ -3943,7 +3943,7 @@ fn trans_bind_thunk(@crate_ctxt cx, auto bcx = new_top_block_ctxt(fcx); auto lltop = bcx.llbb; - auto llclosure_ptr_ty = type_of(cx, ty.plain_box_ty(closure_ty)); + auto llclosure_ptr_ty = type_of(cx, ty.plain_box_ty(closure_ty, ast.imm)); auto llclosure = bcx.build.PointerCast(fcx.llenv, llclosure_ptr_ty); 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, let @ty.t body_ty = ty.plain_tup_ty(vec(tydesc_ty, typarams_ty, fields_ty)); - let @ty.t boxed_body_ty = ty.plain_box_ty(body_ty); + let @ty.t boxed_body_ty = ty.plain_box_ty(body_ty, ast.imm); // Malloc a box for the body. auto box = trans_malloc_boxed(bcx, body_ty); diff --git a/src/comp/middle/ty.rs b/src/comp/middle/ty.rs index d0b5fe10..24bd647f 100644 --- a/src/comp/middle/ty.rs +++ b/src/comp/middle/ty.rs @@ -564,8 +564,8 @@ fn plain_ty(&sty st) -> @t { ret @rec(struct=st, cname=none[str]); } -fn plain_box_ty(@t subty) -> @t { - ret plain_ty(ty_box(rec(ty=subty, mut=ast.imm))); +fn plain_box_ty(@t subty, ast.mutability mut) -> @t { + ret plain_ty(ty_box(rec(ty=subty, mut=mut))); } fn plain_tup_ty(vec[@t] elem_tys) -> @t { diff --git a/src/comp/middle/typeck.rs b/src/comp/middle/typeck.rs index f726ae58..10cbd6d5 100644 --- a/src/comp/middle/typeck.rs +++ b/src/comp/middle/typeck.rs @@ -959,7 +959,7 @@ fn strip_boxes(@ty.t t) -> @ty.t { fn add_boxes(uint n, @ty.t t) -> @ty.t { auto t1 = t; while (n != 0u) { - t1 = ty.plain_box_ty(t1); + t1 = ty.plain_box_ty(t1, ast.imm); n -= 1u; } ret t1; @@ -1728,9 +1728,8 @@ fn check_expr(&@fn_ctxt fcx, @ast.expr expr) -> @ast.expr { auto oper_1 = check_expr(fcx, oper); auto oper_t = expr_ty(oper_1); alt (unop) { - case (ast.box) { - // TODO: mutable - oper_t = ty.plain_box_ty(oper_t); + case (ast.box(?mut)) { + oper_t = ty.plain_box_ty(oper_t, mut); } case (ast.deref) { alt (oper_t.struct) { |