Change the ivec type syntax to [T].
This preserves the old syntax for now.
This commit is contained in:
parent
bf7b516bdb
commit
a37e00ed1f
18 changed files with 62 additions and 50 deletions
|
@ -554,6 +554,11 @@ fn parse_ty(p: &parser) -> @ast::ty {
|
|||
t = ast::ty_vec(parse_mt(p));
|
||||
hi = p.get_hi_pos();
|
||||
expect(p, token::RBRACKET);
|
||||
} else if (p.peek() == token::LBRACKET) {
|
||||
expect(p, token::LBRACKET);
|
||||
t = ast::ty_ivec(parse_mt(p));
|
||||
hi = p.get_hi_pos();
|
||||
expect(p, token::RBRACKET);
|
||||
} else if (eat_word(p, "fn")) {
|
||||
let flo = p.get_last_lo_pos();
|
||||
t = parse_ty_fn(ast::proto_fn, p, flo);
|
||||
|
|
|
@ -287,24 +287,13 @@ fn print_type(s: &ps, ty: &ast::ty) {
|
|||
ast::ty_box(mt) { word(s.s, "@"); print_mt(s, mt); }
|
||||
ast::ty_vec(mt) { word(s.s, "vec["); print_mt(s, mt); word(s.s, "]"); }
|
||||
ast::ty_ivec(mt) {
|
||||
let parens =
|
||||
alt mt.ty.node {
|
||||
ast::ty_box(_) | ast::ty_vec(_) | ast::ty_ptr(_) |
|
||||
ast::ty_port(_) | ast::ty_chan(_) {
|
||||
true
|
||||
}
|
||||
ast::ty_path(pt, _) { ivec::len(pt.node.types) > 0u }
|
||||
_ { false }
|
||||
};
|
||||
if parens { popen(s); }
|
||||
print_type(s, *mt.ty);
|
||||
if parens { pclose(s); }
|
||||
word(s.s, "[");
|
||||
alt mt.mut {
|
||||
ast::mut. { word(s.s, "mutable"); }
|
||||
ast::maybe_mut. { word(s.s, "mutable?"); }
|
||||
ast::mut. { word_space(s, "mutable"); }
|
||||
ast::maybe_mut. { word_space(s, "mutable?"); }
|
||||
ast::imm. {}
|
||||
}
|
||||
print_type(s, *mt.ty);
|
||||
word(s.s, "]");
|
||||
}
|
||||
ast::ty_ptr(mt) { word(s.s, "*"); print_mt(s, mt); }
|
||||
|
|
|
@ -73,13 +73,13 @@ mod map_reduce {
|
|||
type reducer = fn(str, getter) ;
|
||||
|
||||
tag ctrl_proto {
|
||||
find_reducer(u8[], chan[chan[reduce_proto]]);
|
||||
find_reducer([u8], chan[chan[reduce_proto]]);
|
||||
mapper_done;
|
||||
}
|
||||
|
||||
tag reduce_proto { emit_val(int); done; ref; release; }
|
||||
|
||||
fn start_mappers(ctrl: chan[ctrl_proto], inputs: vec[str]) -> task[] {
|
||||
fn start_mappers(ctrl: chan[ctrl_proto], inputs: vec[str]) -> [task] {
|
||||
let tasks = ~[];
|
||||
// log_err "starting mappers";
|
||||
for i: str in inputs {
|
||||
|
|
|
@ -25,7 +25,7 @@ fn main(args: vec[str]) {
|
|||
run_tests(config);
|
||||
}
|
||||
|
||||
fn parse_config(args: &str[]) -> config {
|
||||
fn parse_config(args: &[str]) -> config {
|
||||
let opts =
|
||||
~[getopts::reqopt("compile-lib-path"),
|
||||
getopts::reqopt("run-lib-path"), getopts::reqopt("rustc-path"),
|
||||
|
@ -117,7 +117,7 @@ fn test_opts(config: &config) -> test::test_opts {
|
|||
}
|
||||
|
||||
type tests_and_conv_fn =
|
||||
{tests: test::test_desc[], to_task: fn(&fn() ) -> task };
|
||||
{tests: [test::test_desc], to_task: fn(&fn() ) -> task };
|
||||
|
||||
fn make_tests(cx: &cx) -> tests_and_conv_fn {
|
||||
log #fmt("making tests from %s", cx.config.src_base);
|
||||
|
|
|
@ -11,7 +11,7 @@ export is_test_ignored;
|
|||
|
||||
type test_props = {
|
||||
// Lines that should be expected, in order, on standard out
|
||||
error_patterns: str[],
|
||||
error_patterns: [str],
|
||||
// Extra flags to pass to the compiler
|
||||
compile_flags: option::t[str],
|
||||
// If present, the name of a file that this test should match when
|
||||
|
|
|
@ -27,7 +27,7 @@ type reqchan = chan[request];
|
|||
type handle = {task: option::t[task], chan: reqchan};
|
||||
|
||||
tag request {
|
||||
exec(str, str, str[], chan[response]);
|
||||
exec(str, str, [str], chan[response]);
|
||||
stop;
|
||||
}
|
||||
|
||||
|
@ -189,7 +189,7 @@ fn clone_str(s: &str) -> str {
|
|||
new
|
||||
}
|
||||
|
||||
fn clone_ivecstr(v: &str[]) -> str[] {
|
||||
fn clone_ivecstr(v: &[str]) -> [str] {
|
||||
let r = ~[];
|
||||
for t: str in ivec::slice(v, 0u, ivec::len(v)) {
|
||||
r += ~[clone_str(t)];
|
||||
|
|
9
src/test/pretty/ivec-type.pp
Normal file
9
src/test/pretty/ivec-type.pp
Normal file
|
@ -0,0 +1,9 @@
|
|||
// pp-exact:ivec-type.pp
|
||||
|
||||
fn f1(x: [int]) { }
|
||||
|
||||
fn g1() { f1(~[1, 2, 3]); }
|
||||
|
||||
fn f2(x: [int]) { }
|
||||
|
||||
fn g2() { f2(~[1, 2, 3]); }
|
9
src/test/pretty/ivec-type.rs
Normal file
9
src/test/pretty/ivec-type.rs
Normal file
|
@ -0,0 +1,9 @@
|
|||
// pp-exact:ivec-type.pp
|
||||
|
||||
fn f1(x: int[]) { }
|
||||
|
||||
fn g1() { f1(~[1, 2, 3]); }
|
||||
|
||||
fn f2(x: [int]) { }
|
||||
|
||||
fn g2() { f2(~[1, 2, 3]); }
|
|
@ -2,6 +2,6 @@ tag option[T] { some(T); none; }
|
|||
|
||||
type r[T] = {mutable v: (option[T])[]};
|
||||
|
||||
fn f[T]() -> T[] { ret ~[]; }
|
||||
fn f[T]() -> [T] { ret ~[]; }
|
||||
|
||||
fn main() { let r: r[int] = {mutable v: ~[]}; r.v = f(); }
|
||||
fn main() { let r: r[int] = {mutable v: ~[]}; r.v = f(); }
|
||||
|
|
|
@ -1,9 +1,9 @@
|
|||
fn f[T](x: &T[]) -> T { ret x.(0); }
|
||||
fn f[T](x: &[T]) -> T { ret x.(0); }
|
||||
|
||||
fn g(act: fn(&int[]) -> int ) -> int { ret act(~[1, 2, 3]); }
|
||||
fn g(act: fn(&[int]) -> int ) -> int { ret act(~[1, 2, 3]); }
|
||||
|
||||
fn main() {
|
||||
assert (g(f) == 1);
|
||||
let f1: fn(&str[]) -> str = f;
|
||||
let f1: fn(&[str]) -> str = f;
|
||||
assert (f1(~["x", "y", "z"]) == "x");
|
||||
}
|
||||
}
|
||||
|
|
|
@ -1,5 +1,5 @@
|
|||
// issue #680
|
||||
|
||||
fn f() -> int[] { ~[] }
|
||||
fn f() -> [int] { ~[] }
|
||||
|
||||
fn main() { }
|
||||
fn main() { }
|
||||
|
|
|
@ -3,11 +3,11 @@
|
|||
import rusti::ivec_len;
|
||||
|
||||
native "rust-intrinsic" mod rusti {
|
||||
fn ivec_len[T](v: &T[]) -> uint;
|
||||
fn ivec_len[T](v: &[T]) -> uint;
|
||||
}
|
||||
|
||||
fn main() {
|
||||
let v: int[] = ~[];
|
||||
let v: [int] = ~[];
|
||||
assert (ivec_len(v) == 0u); // zero-length
|
||||
let x = ~[1, 2];
|
||||
assert (ivec_len(x) == 2u); // on stack
|
||||
|
|
|
@ -1,20 +1,20 @@
|
|||
use std;
|
||||
import std::ivec;
|
||||
|
||||
tag msg { closed; received(u8[]); }
|
||||
tag msg { closed; received([u8]); }
|
||||
|
||||
fn producer(c: chan[u8[]]) {
|
||||
fn producer(c: chan[[u8]]) {
|
||||
c <| ~[1u8, 2u8, 3u8, 4u8];
|
||||
let empty: u8[] = ~[];
|
||||
let empty: [u8] = ~[];
|
||||
c <| empty;
|
||||
}
|
||||
|
||||
fn packager(cb: chan[chan[u8[]]], msg: chan[msg]) {
|
||||
let p: port[u8[]] = port();
|
||||
fn packager(cb: chan[chan[[u8]]], msg: chan[msg]) {
|
||||
let p: port[[u8]] = port();
|
||||
cb <| chan(p);
|
||||
while true {
|
||||
log "waiting for bytes";
|
||||
let data: u8[];
|
||||
let data: [u8];
|
||||
p |> data;
|
||||
log "got bytes";
|
||||
if ivec::len[u8](data) == 0u {
|
||||
|
@ -33,10 +33,10 @@ fn packager(cb: chan[chan[u8[]]], msg: chan[msg]) {
|
|||
|
||||
fn main() {
|
||||
let p: port[msg] = port();
|
||||
let recv_reader: port[chan[u8[]]] = port();
|
||||
let recv_reader: port[chan[[u8]]] = port();
|
||||
let pack = spawn packager(chan(recv_reader), chan(p));
|
||||
|
||||
let source_chan: chan[u8[]];
|
||||
let source_chan: chan[[u8]];
|
||||
recv_reader |> source_chan;
|
||||
let prod: task = spawn producer(source_chan);
|
||||
|
||||
|
@ -52,4 +52,4 @@ fn main() {
|
|||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
@ -1,6 +1,6 @@
|
|||
fn double[T](a: &T) -> T[] { ret ~[a] + ~[a]; }
|
||||
fn double[T](a: &T) -> [T] { ret ~[a] + ~[a]; }
|
||||
|
||||
fn double_int(a: int) -> int[] { ret ~[a] + ~[a]; }
|
||||
fn double_int(a: int) -> [int] { ret ~[a] + ~[a]; }
|
||||
|
||||
fn main() {
|
||||
let d = double(1);
|
||||
|
|
|
@ -1,3 +1,3 @@
|
|||
fn f(a: int[]) { }
|
||||
fn f(a: [int]) { }
|
||||
fn main() { f(~[1, 2, 3, 4, 5]); }
|
||||
|
||||
|
|
|
@ -22,9 +22,9 @@ fn test_rec() {
|
|||
fn test_vec() {
|
||||
let po = comm::mk_port();
|
||||
let ch = po.mk_chan();
|
||||
let v0: int[] = ~[0, 1, 2];
|
||||
let v0: [int] = ~[0, 1, 2];
|
||||
ch.send(v0);
|
||||
let v1: int[];
|
||||
let v1: [int];
|
||||
v1 = po.recv();
|
||||
assert (v1.(0) == 0);
|
||||
assert (v1.(1) == 1);
|
||||
|
@ -84,4 +84,4 @@ fn main() {
|
|||
test_str();
|
||||
test_tag();
|
||||
test_chan();
|
||||
}
|
||||
}
|
||||
|
|
|
@ -19,7 +19,7 @@ fn add(x: &uint, y: &uint) -> uint { ret x + y; }
|
|||
|
||||
#[test]
|
||||
fn test_reserve_and_on_heap() {
|
||||
let v: int[] = ~[1, 2];
|
||||
let v: [int] = ~[1, 2];
|
||||
assert (!ivec::on_heap(v));
|
||||
ivec::reserve(v, 8u);
|
||||
assert (ivec::on_heap(v));
|
||||
|
|
|
@ -1,7 +1,7 @@
|
|||
|
||||
use std;
|
||||
|
||||
fn check_sort(v1: &int[], v2: &int[]) {
|
||||
fn check_sort(v1: &[int], v2: &[int]) {
|
||||
let len = std::ivec::len[int](v1);
|
||||
fn lteq(a: &int, b: &int) -> bool { ret a <= b; }
|
||||
let f = lteq;
|
||||
|
@ -18,11 +18,11 @@ fn test() {
|
|||
check_sort(v1, v2);
|
||||
}
|
||||
{ let v1 = ~[1, 1, 1]; let v2 = ~[1, 1, 1]; check_sort(v1, v2); }
|
||||
{ let v1: int[] = ~[]; let v2: int[] = ~[]; check_sort(v1, v2); }
|
||||
{ let v1: [int] = ~[]; let v2: [int] = ~[]; check_sort(v1, v2); }
|
||||
{ let v1 = ~[9]; let v2 = ~[9]; check_sort(v1, v2); }
|
||||
{
|
||||
let v1 = ~[9, 3, 3, 3, 9];
|
||||
let v2 = ~[3, 3, 3, 9, 9];
|
||||
check_sort(v1, v2);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue