Skip to content

Commit 216082d

Browse files
committed
Translate ast.box unary expressions and support extraction of TypeRefs from AST annotations.
1 parent ffb3861 commit 216082d

File tree

1 file changed

+25
-3
lines changed

1 file changed

+25
-3
lines changed

src/comp/middle/trans.rs

Lines changed: 25 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -451,7 +451,20 @@ impure fn trans_lit(@block_ctxt cx, &ast.lit lit) -> result {
451451
}
452452
}
453453

454-
impure fn trans_unary(@block_ctxt cx, ast.unop op, &ast.expr e) -> result {
454+
fn node_type(@trans_ctxt cx, &ast.ann a) -> TypeRef {
455+
alt (a) {
456+
case (ast.ann_none) {
457+
log "missing type annotation";
458+
fail;
459+
}
460+
case (ast.ann_type(?t)) {
461+
ret type_of(cx, t);
462+
}
463+
}
464+
}
465+
466+
impure fn trans_unary(@block_ctxt cx, ast.unop op,
467+
&ast.expr e, &ast.ann a) -> result {
455468

456469
auto sub = trans_expr(cx, e);
457470

@@ -469,6 +482,15 @@ impure fn trans_unary(@block_ctxt cx, ast.unop op, &ast.expr e) -> result {
469482
sub.val = cx.build.Neg(sub.val);
470483
ret sub;
471484
}
485+
case (ast.box) {
486+
auto e_ty = node_type(cx.fcx.tcx, a);
487+
auto box_ty = T_box(e_ty);
488+
sub.val = cx.build.Malloc(box_ty);
489+
auto rc = sub.bcx.build.GEP(sub.val,
490+
vec(C_int(0),
491+
C_int(abi.box_rc_field_refcnt)));
492+
ret res(sub.bcx, cx.build.Store(C_int(1), rc));
493+
}
472494
}
473495
cx.fcx.tcx.sess.unimpl("expr variant in trans_unary");
474496
fail;
@@ -759,8 +781,8 @@ impure fn trans_expr(@block_ctxt cx, &ast.expr e) -> result {
759781
ret trans_lit(cx, *lit);
760782
}
761783

762-
case (ast.expr_unary(?op, ?x, _)) {
763-
ret trans_unary(cx, op, *x);
784+
case (ast.expr_unary(?op, ?x, ?ann)) {
785+
ret trans_unary(cx, op, *x, ann);
764786
}
765787

766788
case (ast.expr_binary(?op, ?x, ?y, _)) {

0 commit comments

Comments
 (0)