Add new arg-passing mode 'move' denoted with '-T'. Translate as pass-by-value, doesn't deinit source yet nor get proper analysis in typestate, alias passes.
This commit is contained in:
parent
3dda9aabf2
commit
b54e7e4506
10 changed files with 39 additions and 6 deletions
|
@ -381,6 +381,9 @@ fn parse_ty_fn(st: @pstate, sd: str_def) ->
|
|||
mode = ty::mo_alias(true);
|
||||
st.pos += 1u;
|
||||
}
|
||||
} else if peek(st) as char == '-' {
|
||||
mode = ty::mo_move;
|
||||
st.pos += 1u;
|
||||
}
|
||||
inputs += ~[{mode: mode, ty: parse_ty(st, sd)}];
|
||||
}
|
||||
|
|
|
@ -208,6 +208,9 @@ fn enc_ty_fn(w: &ioivec::writer, cx: &@ctxt, args: &ty::arg[], out: &ty::t,
|
|||
w.write_char('&');
|
||||
if mut { w.write_char('m'); }
|
||||
}
|
||||
ty::mo_move. {
|
||||
w.write_char('-');
|
||||
}
|
||||
ty::mo_val. { }
|
||||
}
|
||||
enc_ty(w, cx, arg.ty);
|
||||
|
|
|
@ -95,6 +95,7 @@ fn type_of_explicit_args(cx: &@crate_ctxt, sp: &span, inputs: &ty::arg[]) ->
|
|||
let t: TypeRef = type_of_inner(cx, sp, arg.ty);
|
||||
t = alt arg.mode {
|
||||
ty::mo_alias(_) { T_ptr(t) }
|
||||
ty::mo_move. { T_ptr(t) }
|
||||
_ { t }
|
||||
};
|
||||
atys += ~[t];
|
||||
|
|
|
@ -95,6 +95,7 @@ export mk_iter_body_fn;
|
|||
export mode;
|
||||
export mo_val;
|
||||
export mo_alias;
|
||||
export mo_move;
|
||||
export mt;
|
||||
export node_type_table;
|
||||
export pat_ty;
|
||||
|
@ -187,7 +188,7 @@ export walk_ty;
|
|||
export occurs_check_fails;
|
||||
|
||||
// Data types
|
||||
tag mode { mo_val; mo_alias(bool); }
|
||||
tag mode { mo_val; mo_alias(bool); mo_move; }
|
||||
|
||||
type arg = {mode: mode, ty: t};
|
||||
|
||||
|
|
|
@ -21,6 +21,7 @@ import middle::ty::field;
|
|||
import middle::ty::method;
|
||||
import middle::ty::mo_val;
|
||||
import middle::ty::mo_alias;
|
||||
import middle::ty::mo_move;
|
||||
import middle::ty::node_type_table;
|
||||
import middle::ty::pat_ty;
|
||||
import middle::ty::ty_param_substs_opt_and_ty;
|
||||
|
@ -204,12 +205,11 @@ fn instantiate_path(fcx: &@fn_ctxt, pth: &ast::path,
|
|||
}
|
||||
|
||||
fn ast_mode_to_mode(mode: ast::mode) -> ty::mode {
|
||||
let ty_mode;
|
||||
alt mode {
|
||||
ast::val. { ty_mode = mo_val; }
|
||||
ast::alias(mut) { ty_mode = mo_alias(mut); }
|
||||
ast::val. { mo_val }
|
||||
ast::alias(mut) { mo_alias(mut) }
|
||||
ast::move. { mo_move }
|
||||
}
|
||||
ret ty_mode;
|
||||
}
|
||||
|
||||
|
||||
|
|
|
@ -249,7 +249,7 @@ fn unop_to_str(op: unop) -> str {
|
|||
}
|
||||
}
|
||||
|
||||
tag mode { val; alias(bool); }
|
||||
tag mode { val; alias(bool); move; }
|
||||
|
||||
type stmt = spanned[stmt_];
|
||||
|
||||
|
|
|
@ -597,6 +597,8 @@ fn parse_arg(p: &parser) -> ast::arg {
|
|||
expect(p, token::COLON);
|
||||
if eat(p, token::BINOP(token::AND)) {
|
||||
m = ast::alias(eat_word(p, "mutable"));
|
||||
} else if eat(p, token::BINOP(token::MINUS)) {
|
||||
m = ast::move;
|
||||
}
|
||||
let t: @ast::ty = parse_ty(p);
|
||||
ret {mode: m, ty: t, ident: i, id: p.get_id()};
|
||||
|
|
|
@ -1191,6 +1191,7 @@ fn print_alias(s: &ps, m: ast::mode) {
|
|||
alt m {
|
||||
ast::alias(true) { word_space(s, "&mutable"); }
|
||||
ast::alias(false) { word(s.s, "&"); }
|
||||
ast::move. { word(s.s, "-"); }
|
||||
ast::val. { }
|
||||
}
|
||||
}
|
||||
|
|
14
src/test/compile-fail/move-arg.rs
Normal file
14
src/test/compile-fail/move-arg.rs
Normal file
|
@ -0,0 +1,14 @@
|
|||
// xfail-stage0
|
||||
// xfail-stage1
|
||||
// xfail-stage2
|
||||
// xfail-stage3
|
||||
// error-pattern: Unsatisfied precondition constraint
|
||||
fn test(foo: -int) {
|
||||
assert (foo == 10);
|
||||
}
|
||||
|
||||
fn main() {
|
||||
let x = 10;
|
||||
test(x);
|
||||
log x;
|
||||
}
|
8
src/test/run-pass/move-arg.rs
Normal file
8
src/test/run-pass/move-arg.rs
Normal file
|
@ -0,0 +1,8 @@
|
|||
fn test(foo: -int) {
|
||||
assert (foo == 10);
|
||||
}
|
||||
|
||||
fn main() {
|
||||
let x = 10;
|
||||
test(x);
|
||||
}
|
Loading…
Add table
Add a link
Reference in a new issue