Get evec slices and unique-evec slice-borrowing working.

This commit is contained in:
Graydon Hoare 2012-04-19 16:37:06 -07:00
parent b0074c5a92
commit f641dce852
5 changed files with 36 additions and 5 deletions

View File

@ -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);
}

View 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;
}

View File

@ -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;
}

View 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;
}

View File

@ -1,6 +1,3 @@
// -*- rust -*-
fn main() {
let a: [int] = [1, 2, 3, 4, 5];