Add a pass-by-copy parameter passing convention
This is intended to solve the problem of how to pass arguments to constructor functions -- you want to move in rvalues, but not have to explicitly copy stuff that is not an rvalue. The by-copy passing convention will ensure the callee gets its own copy of the value. For rvalues, it'll just pass off the value. For lvalues, it'll make a copy. Issue #1177
This commit is contained in:
parent
6297fc979e
commit
4e03112141
9 changed files with 36 additions and 10 deletions
|
|
@ -144,7 +144,7 @@ tag unop {
|
|||
deref; not; neg;
|
||||
}
|
||||
|
||||
tag mode { by_ref; by_val; by_mut_ref; by_move; mode_infer; }
|
||||
tag mode { by_ref; by_val; by_mut_ref; by_move; by_copy; mode_infer; }
|
||||
|
||||
type stmt = spanned<stmt_>;
|
||||
|
||||
|
|
|
|||
|
|
@ -573,7 +573,10 @@ fn parse_arg_mode(p: parser) -> ast::mode {
|
|||
if eat(p, token::BINOP(token::AND)) { ast::by_mut_ref }
|
||||
else if eat(p, token::BINOP(token::MINUS)) { ast::by_move }
|
||||
else if eat(p, token::ANDAND) { ast::by_ref }
|
||||
else if eat(p, token::BINOP(token::PLUS)) { ast::by_val }
|
||||
else if eat(p, token::BINOP(token::PLUS)) {
|
||||
if eat(p, token::BINOP(token::PLUS)) { ast::by_val }
|
||||
else { ast::by_copy }
|
||||
}
|
||||
else { ast::mode_infer }
|
||||
}
|
||||
|
||||
|
|
|
|||
|
|
@ -1161,7 +1161,8 @@ fn print_arg_mode(s: ps, m: ast::mode) {
|
|||
ast::by_mut_ref. { word(s.s, "&"); }
|
||||
ast::by_move. { word(s.s, "-"); }
|
||||
ast::by_ref. { word(s.s, "&&"); }
|
||||
ast::by_val. { word(s.s, "+"); }
|
||||
ast::by_val. { word(s.s, "++"); }
|
||||
ast::by_copy. { word(s.s, "+"); }
|
||||
ast::mode_infer. {}
|
||||
}
|
||||
}
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue