From fd1029e6dd3ec685cc496a0f129e39590a61830d Mon Sep 17 00:00:00 2001 From: Michael Sullivan Date: Tue, 31 May 2011 15:41:08 -0700 Subject: [PATCH] Support move as an initializer. --- src/comp/front/ast.rs | 1 + src/comp/front/parser.rs | 5 +++++ src/comp/middle/trans.rs | 5 +++++ src/comp/middle/typeck.rs | 3 +++ src/comp/pretty/pprust.rs | 5 ++++- 5 files changed, 18 insertions(+), 1 deletion(-) diff --git a/src/comp/front/ast.rs b/src/comp/front/ast.rs index abfea16b2ad..0d97a09bfc7 100644 --- a/src/comp/front/ast.rs +++ b/src/comp/front/ast.rs @@ -208,6 +208,7 @@ fn unop_to_str(unop op) -> str { tag init_op { init_assign; init_recv; + init_move; } type initializer = rec(init_op op, diff --git a/src/comp/front/parser.rs b/src/comp/front/parser.rs index 01cf64f3739..2dea137f3ae 100644 --- a/src/comp/front/parser.rs +++ b/src/comp/front/parser.rs @@ -1449,6 +1449,11 @@ fn parse_initializer(&parser p) -> option::t[ast::initializer] { ret some(rec(op = ast::init_assign, expr = parse_expr(p))); } + case (token::LARROW) { + p.bump(); + ret some(rec(op = ast::init_move, + expr = parse_expr(p))); + } // Now that the the channel is the first argument to receive, // combining it with an initializer doesn't really make sense. // case (token::RECV) { diff --git a/src/comp/middle/trans.rs b/src/comp/middle/trans.rs index 072e4aaf373..b5803606d58 100644 --- a/src/comp/middle/trans.rs +++ b/src/comp/middle/trans.rs @@ -6375,6 +6375,11 @@ fn init_local(&@block_ctxt cx, &@ast::local local) -> result { auto sub = trans_expr(bcx, init.expr); bcx = copy_val(sub.bcx, INIT, llptr, sub.val, ty).bcx; } + case (ast::init_move) { + auto sub = trans_lval(bcx, init.expr); + bcx = move_val(sub.res.bcx, INIT, llptr, + sub.res.val, ty).bcx; + } case (ast::init_recv) { bcx = recv_val(bcx, llptr, init.expr, ty, INIT).bcx; } diff --git a/src/comp/middle/typeck.rs b/src/comp/middle/typeck.rs index 13d7204a714..a705d84df52 100644 --- a/src/comp/middle/typeck.rs +++ b/src/comp/middle/typeck.rs @@ -2723,6 +2723,9 @@ fn check_decl_initializer(&@stmt_ctxt scx, &ast::def_id lid, case (ast::init_assign) { pushdown::pushdown_expr(scx, lty, init.expr); } + case (ast::init_move) { + pushdown::pushdown_expr(scx, lty, init.expr); + } case (ast::init_recv) { auto port_ty = ty::mk_port(scx.fcx.ccx.tcx, lty); pushdown::pushdown_expr(scx, port_ty, init.expr); diff --git a/src/comp/pretty/pprust.rs b/src/comp/pretty/pprust.rs index af6896fd96f..0888880ae78 100644 --- a/src/comp/pretty/pprust.rs +++ b/src/comp/pretty/pprust.rs @@ -865,9 +865,12 @@ fn print_decl(&ps s, &@ast::decl decl) { case (ast::init_assign) { word_space(s, "="); } - case (ast::init_recv) { + case (ast::init_move) { word_space(s, "<-"); } + case (ast::init_recv) { + word_space(s, "|>"); + } } print_expr(s, init.expr); }