mirror of
https://github.com/rust-lang/rust.git
synced 2025-01-24 13:43:04 +00:00
Adding move_val and move_val_init intrinsics.
This commit is contained in:
parent
1642df8efa
commit
74d2f56f21
@ -812,6 +812,26 @@ fn trans_intrinsic(ccx: @crate_ctxt, decl: ValueRef, item: @ast::native_item,
|
|||||||
Store(bcx, C_uint(ccx, shape::llsize_of_real(ccx, lltp_ty)),
|
Store(bcx, C_uint(ccx, shape::llsize_of_real(ccx, lltp_ty)),
|
||||||
fcx.llretptr);
|
fcx.llretptr);
|
||||||
}
|
}
|
||||||
|
"move_val" {
|
||||||
|
let tp_ty = substs.tys[0];
|
||||||
|
let src = {bcx: bcx,
|
||||||
|
val: get_param(decl, first_real_arg + 1u),
|
||||||
|
kind: owned };
|
||||||
|
bcx = move_val(bcx, DROP_EXISTING,
|
||||||
|
get_param(decl, first_real_arg),
|
||||||
|
src,
|
||||||
|
tp_ty);
|
||||||
|
}
|
||||||
|
"move_val_init" {
|
||||||
|
let tp_ty = substs.tys[0];
|
||||||
|
let src = {bcx: bcx,
|
||||||
|
val: get_param(decl, first_real_arg + 1u),
|
||||||
|
kind: owned };
|
||||||
|
bcx = move_val(bcx, INIT,
|
||||||
|
get_param(decl, first_real_arg),
|
||||||
|
src,
|
||||||
|
tp_ty);
|
||||||
|
}
|
||||||
"min_align_of" {
|
"min_align_of" {
|
||||||
let tp_ty = substs.tys[0];
|
let tp_ty = substs.tys[0];
|
||||||
let lltp_ty = type_of::type_of(ccx, tp_ty);
|
let lltp_ty = type_of::type_of(ccx, tp_ty);
|
||||||
|
@ -79,7 +79,9 @@ fn type_uses_for(ccx: @crate_ctxt, fn_id: def_id, n_tps: uint)
|
|||||||
let flags = alt check *i.ident {
|
let flags = alt check *i.ident {
|
||||||
"visit_ty" { 3u }
|
"visit_ty" { 3u }
|
||||||
"size_of" | "pref_align_of" | "min_align_of" |
|
"size_of" | "pref_align_of" | "min_align_of" |
|
||||||
"init" | "reinterpret_cast" { use_repr }
|
"init" | "reinterpret_cast" | "move_val" | "move_val_init" {
|
||||||
|
use_repr
|
||||||
|
}
|
||||||
"get_tydesc" | "needs_drop" { use_tydesc }
|
"get_tydesc" | "needs_drop" { use_tydesc }
|
||||||
"forget" | "addr_of" { 0u }
|
"forget" | "addr_of" { 0u }
|
||||||
};
|
};
|
||||||
|
@ -456,6 +456,7 @@ impl methods for @fn_ctxt {
|
|||||||
none { result::err("no block is in scope here") }
|
none { result::err("no block is in scope here") }
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
#[inline(always)]
|
||||||
fn write_ty(node_id: ast::node_id, ty: ty::t) {
|
fn write_ty(node_id: ast::node_id, ty: ty::t) {
|
||||||
#debug["write_ty(%d, %s) in fcx %s",
|
#debug["write_ty(%d, %s) in fcx %s",
|
||||||
node_id, ty_to_str(self.tcx(), ty), self.tag()];
|
node_id, ty_to_str(self.tcx(), ty), self.tag()];
|
||||||
@ -2310,6 +2311,11 @@ fn check_intrinsic_type(ccx: @crate_ctxt, it: @ast::native_item) {
|
|||||||
param(ccx, 1u)) }
|
param(ccx, 1u)) }
|
||||||
"addr_of" { (1u, [arg(ast::by_ref, param(ccx, 0u))],
|
"addr_of" { (1u, [arg(ast::by_ref, param(ccx, 0u))],
|
||||||
ty::mk_imm_ptr(tcx, param(ccx, 0u))) }
|
ty::mk_imm_ptr(tcx, param(ccx, 0u))) }
|
||||||
|
"move_val" | "move_val_init" {
|
||||||
|
(1u, [arg(ast::by_mutbl_ref, param(ccx, 0u)),
|
||||||
|
arg(ast::by_move, param(ccx, 0u))],
|
||||||
|
ty::mk_nil(tcx))
|
||||||
|
}
|
||||||
"needs_drop" { (1u, [], ty::mk_bool(tcx)) }
|
"needs_drop" { (1u, [], ty::mk_bool(tcx)) }
|
||||||
|
|
||||||
"visit_ty" {
|
"visit_ty" {
|
||||||
|
12
src/test/run-pass/intrinsic-move-val.rs
Normal file
12
src/test/run-pass/intrinsic-move-val.rs
Normal file
@ -0,0 +1,12 @@
|
|||||||
|
#[abi = "rust-intrinsic"]
|
||||||
|
native mod rusti {
|
||||||
|
fn move_val_init<T>(&dst: T, -src: T);
|
||||||
|
fn move_val<T>(&dst: T, -src: T);
|
||||||
|
}
|
||||||
|
|
||||||
|
fn main() {
|
||||||
|
let mut x = @1;
|
||||||
|
let mut y = @2;
|
||||||
|
rusti::move_val(y, x);
|
||||||
|
assert *y == 1;
|
||||||
|
}
|
Loading…
Reference in New Issue
Block a user