@@ -451,7 +451,20 @@ impure fn trans_lit(@block_ctxt cx, &ast.lit lit) -> result {
451
451
}
452
452
}
453
453
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 {
455
468
456
469
auto sub = trans_expr ( cx, e) ;
457
470
@@ -469,6 +482,15 @@ impure fn trans_unary(@block_ctxt cx, ast.unop op, &ast.expr e) -> result {
469
482
sub. val = cx. build . Neg ( sub. val ) ;
470
483
ret sub;
471
484
}
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
+ }
472
494
}
473
495
cx. fcx . tcx . sess . unimpl ( "expr variant in trans_unary" ) ;
474
496
fail;
@@ -759,8 +781,8 @@ impure fn trans_expr(@block_ctxt cx, &ast.expr e) -> result {
759
781
ret trans_lit ( cx, * lit) ;
760
782
}
761
783
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 ) ;
764
786
}
765
787
766
788
case ( ast. expr_binary ( ?op, ?x, ?y, _) ) {
0 commit comments