Make box prefix operator and box type carry mutability flag.

This commit is contained in:
Graydon Hoare 2011-04-04 15:44:15 -07:00
parent bd9f45446a
commit 70e5457d7c
5 changed files with 17 additions and 14 deletions

View file

@ -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 "!";}

View file

@ -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 (_) {

View file

@ -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);

View file

@ -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 {

View file

@ -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) {