mirror of
https://github.com/rust-lang/rust.git
synced 2025-01-18 02:34:37 +00:00
Get evec slices and unique-evec slice-borrowing working.
This commit is contained in:
parent
b0074c5a92
commit
f641dce852
@ -102,6 +102,7 @@ fn trans_evec(bcx: block, args: [@ast::expr],
|
||||
let vec_ty = node_id_type(bcx, id);
|
||||
let unit_ty = ty::sequence_element_type(bcx.tcx(), vec_ty);
|
||||
let llunitty = type_of::type_of(ccx, unit_ty);
|
||||
let unit_sz = llsize_of(ccx, llunitty);
|
||||
|
||||
let mut {bcx, val, dataptr} =
|
||||
alt vst {
|
||||
@ -122,8 +123,14 @@ fn trans_evec(bcx: block, args: [@ast::expr],
|
||||
let n = vec::len(args);
|
||||
let n = C_uint(ccx, n);
|
||||
let vp = base::arrayalloca(bcx, llunitty, n);
|
||||
let v = C_struct([vp, n]);
|
||||
{bcx: bcx, val: v, dataptr: vp}
|
||||
let len = Mul(bcx, n, unit_sz);
|
||||
|
||||
let p = base::alloca(bcx, T_struct([T_ptr(llunitty),
|
||||
ccx.int_type]));
|
||||
Store(bcx, vp, GEPi(bcx, p, [0, abi::slice_elt_base]));
|
||||
Store(bcx, len, GEPi(bcx, p, [0, abi::slice_elt_len]));
|
||||
|
||||
{bcx: bcx, val: p, dataptr: vp}
|
||||
}
|
||||
ast::vstore_uniq {
|
||||
let {bcx, val} = alloc_uniq(bcx, llunitty, args.len());
|
||||
@ -157,6 +164,9 @@ fn trans_evec(bcx: block, args: [@ast::expr],
|
||||
// We wrote into the destination in the fixed case.
|
||||
ret bcx;
|
||||
}
|
||||
ast::vstore_slice(_) {
|
||||
ret base::store_in_dest(bcx, Load(bcx, val), dest);
|
||||
}
|
||||
_ {
|
||||
ret base::store_in_dest(bcx, val, dest);
|
||||
}
|
||||
|
7
src/test/run-pass/evec-slice.rs
Normal file
7
src/test/run-pass/evec-slice.rs
Normal file
@ -0,0 +1,7 @@
|
||||
fn main() {
|
||||
let x : [int]/& = [1,2,3,4,5]/&;
|
||||
let mut z = [1,2,3,4,5]/&;
|
||||
z = x;
|
||||
assert z[0] == 1;
|
||||
assert z[4] == 5;
|
||||
}
|
@ -6,4 +6,8 @@ fn main() {
|
||||
let p = "hello"/~;
|
||||
let r = foo(p);
|
||||
assert r == 'h' as u8;
|
||||
|
||||
let p = "hello";
|
||||
let r = foo(p);
|
||||
assert r == 'h' as u8;
|
||||
}
|
||||
|
13
src/test/run-pass/regions-borrow-evec-uniq.rs
Normal file
13
src/test/run-pass/regions-borrow-evec-uniq.rs
Normal file
@ -0,0 +1,13 @@
|
||||
fn foo(x: [int]/&) -> int {
|
||||
x[0]
|
||||
}
|
||||
|
||||
fn main() {
|
||||
let p = [1,2,3,4,5]/~;
|
||||
let r = foo(p);
|
||||
assert r == 1;
|
||||
|
||||
let p = [5,4,3,2,1];
|
||||
let r = foo(p);
|
||||
assert r == 5;
|
||||
}
|
@ -1,6 +1,3 @@
|
||||
|
||||
|
||||
|
||||
// -*- rust -*-
|
||||
fn main() {
|
||||
let a: [int] = [1, 2, 3, 4, 5];
|
||||
|
Loading…
Reference in New Issue
Block a user