提交 d730bb73 编写于 作者: M Marijn Haverbeke

Make it possible to use * to dereference a resource

上级 b3443eb0
...@@ -544,10 +544,14 @@ fn maybe_push_auto_unbox(&option::t[deref] d, &mutable vec[deref] ds) { ...@@ -544,10 +544,14 @@ fn maybe_push_auto_unbox(&option::t[deref] d, &mutable vec[deref] ds) {
auto base_t = ty::expr_ty(*cx.tcx, base); auto base_t = ty::expr_ty(*cx.tcx, base);
alt (ty::struct(*cx.tcx, base_t)) { alt (ty::struct(*cx.tcx, base_t)) {
case (ty::ty_box(?mt)) { case (ty::ty_box(?mt)) {
vec::push(ds, vec::push(ds, rec(mut=mt.mut != ast::imm,
rec(mut=mt.mut != ast::imm, kind=unbox,
kind=unbox, outer_t=base_t));
outer_t=base_t)); }
case (ty::ty_res(_, ?inner)) {
vec::push(ds, rec(mut=false,
kind=unbox,
outer_t=base_t));
} }
} }
ex = base; ex = base;
......
...@@ -4511,8 +4511,7 @@ fn trans_for_each(&@block_ctxt cx, &@ast::local local, &@ast::expr seq, ...@@ -4511,8 +4511,7 @@ fn trans_for_each(&@block_ctxt cx, &@ast::local local, &@ast::expr seq,
cx.build.Store(llenvblobptr, env_cell); cx.build.Store(llenvblobptr, env_cell);
// log "lliterbody: " + val_str(lcx.ccx.tn, lliterbody); // log "lliterbody: " + val_str(lcx.ccx.tn, lliterbody);
r = r = trans_call(cx, f, some[ValueRef](cx.build.Load(pair)), args,
trans_call(cx, f, some[ValueRef](cx.build.Load(pair)), args,
seq.id); seq.id);
ret rslt(r.bcx, C_nil()); ret rslt(r.bcx, C_nil());
} }
...@@ -4993,9 +4992,12 @@ fn trans_lval(&@block_ctxt cx, &@ast::expr e) -> lval_result { ...@@ -4993,9 +4992,12 @@ fn trans_lval(&@block_ctxt cx, &@ast::expr e) -> lval_result {
case (ast::expr_unary(?unop, ?base)) { case (ast::expr_unary(?unop, ?base)) {
assert (unop == ast::deref); assert (unop == ast::deref);
auto sub = trans_expr(cx, base); auto sub = trans_expr(cx, base);
auto val = auto t = ty::expr_ty(cx.fcx.lcx.ccx.tcx, base);
sub.bcx.build.GEP(sub.val, auto offset = alt (ty::struct(cx.fcx.lcx.ccx.tcx, t)) {
[C_int(0), C_int(abi::box_rc_field_body)]); case (ty::ty_box(_)) { abi::box_rc_field_body }
case (ty::ty_res(_, _)) { 1 }
};
auto val = sub.bcx.build.GEP(sub.val, [C_int(0), C_int(offset)]);
ret lval_mem(sub.bcx, val); ret lval_mem(sub.bcx, val);
} }
case (ast::expr_self_method(?ident)) { case (ast::expr_self_method(?ident)) {
......
...@@ -1526,6 +1526,7 @@ fn check_binop_type_compat(&@fn_ctxt fcx, common::span span, ...@@ -1526,6 +1526,7 @@ fn check_binop_type_compat(&@fn_ctxt fcx, common::span span,
case (ast::deref) { case (ast::deref) {
alt (structure_of(fcx, expr.span, oper_t)) { alt (structure_of(fcx, expr.span, oper_t)) {
case (ty::ty_box(?inner)) { oper_t = inner.ty; } case (ty::ty_box(?inner)) { oper_t = inner.ty; }
case (ty::ty_res(_, ?inner)) { oper_t = inner; }
case (_) { case (_) {
auto s = "dereferencing non-box type: " + auto s = "dereferencing non-box type: " +
ty_to_str(fcx.ccx.tcx, oper_t); ty_to_str(fcx.ccx.tcx, oper_t);
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册