Rewrite everything to use [] instead of vec() in value position.

This commit is contained in:
Graydon Hoare 2011-05-16 18:21:22 -07:00
parent ae030c5bf2
commit fbbc1a77d2
87 changed files with 1137 additions and 1134 deletions

View file

@ -141,7 +141,7 @@ fn unsafe_from_bytes(vec[mutable? u8] v) -> str {
}
fn unsafe_from_byte(u8 u) -> str {
ret rustrt::str_from_vec(vec(u));
ret rustrt::str_from_vec([u]);
}
fn str_from_cstr(sbuf cstr) -> str {
@ -248,7 +248,7 @@ fn char_len(str s) -> uint {
}
fn to_chars(str s) -> vec[char] {
let vec[char] buf = vec();
let vec[char] buf = [];
auto i = 0u;
auto len = byte_len(s);
while (i < len) {
@ -419,12 +419,12 @@ fn unshift_byte(&mutable str s, u8 b) {
}
fn split(str s, u8 sep) -> vec[str] {
let vec[str] v = vec();
let vec[str] v = [];
let str accum = "";
let bool ends_with_sep = false;
for (u8 c in s) {
if (c == sep) {
v += vec(accum);
v += [accum];
accum = "";
ends_with_sep = true;
} else {
@ -434,7 +434,7 @@ fn split(str s, u8 sep) -> vec[str] {
}
if (_str::byte_len(accum) != 0u ||
ends_with_sep) {
v += vec(accum);
v += [accum];
}
ret v;
}
@ -486,5 +486,5 @@ fn to_upper(str s) -> str {
// indent-tabs-mode: nil
// c-basic-offset: 4
// buffer-file-coding-system: utf-8-unix
// compile-command: "make -k -C .. 2>&1 | sed -e 's/\\/x\\//x:\\//g'";
// compile-command: "make -k -C $RBUILD 2>&1 | sed -e 's/\\/x\\//x:\\//g'";
// End:

View file

@ -75,7 +75,7 @@ fn init_fn[T](&init_op[T] op, uint n_elts) -> vec[T] {
let vec[T] v = alloc[T](n_elts);
let uint i = 0u;
while (i < n_elts) {
v += vec(op(i));
v += [op(i)];
i += 1u;
}
ret v;
@ -85,7 +85,7 @@ fn init_fn_mut[T](&init_op[T] op, uint n_elts) -> vec[mutable T] {
let vec[mutable T] v = alloc_mut[T](n_elts);
let uint i = 0u;
while (i < n_elts) {
v += vec(mutable op(i));
v += [mutable op(i)];
i += 1u;
}
ret v;
@ -103,7 +103,7 @@ fn init_elt[T](&T t, uint n_elts) -> vec[T] {
let uint i = n_elts;
while (i > 0u) {
i -= 1u;
v += vec(t);
v += [t];
}
ret v;
}
@ -113,7 +113,7 @@ fn init_elt_mut[T](&T t, uint n_elts) -> vec[mutable T] {
let uint i = n_elts;
while (i > 0u) {
i -= 1u;
v += vec(mutable t);
v += [mutable t];
}
ret v;
}
@ -156,7 +156,7 @@ fn slice[T](array[T] v, uint start, uint end) -> vec[T] {
auto result = alloc[T](end - start);
let uint i = start;
while (i < end) {
result += vec(v.(i));
result += [v.(i)];
i += 1u;
}
ret result;
@ -180,12 +180,12 @@ fn pop[T](&mutable array[T] v) -> T {
}
fn push[T](&mutable array[T] v, &T t) {
v += vec(t);
v += [t];
}
fn unshift[T](&mutable array[T] v, &T t) {
auto res = alloc[T](len[T](v) + 1u);
res += vec(t);
res += [t];
res += v;
v = res;
}
@ -194,7 +194,7 @@ fn grow[T](&array[T] v, uint n, &T initval) {
let uint i = n;
while (i > 0u) {
i -= 1u;
v += vec(initval);
v += [initval];
}
}
@ -209,7 +209,7 @@ fn grow_set[T](&vec[mutable T] v, uint index, &T initval, &T val) {
fn map[T, U](&option::operator[T,U] f, &array[T] v) -> vec[U] {
let vec[U] u = alloc[U](len[T](v));
for (T ve in v) {
u += vec(f(ve));
u += [f(ve)];
}
ret u;
}
@ -223,7 +223,7 @@ fn map2[T,U,V](&operator2[T,U,V] f, &array[T] v0, &array[U] v1) -> vec[V] {
let vec[V] u = alloc[V](v0_len);
auto i = 0u;
while (i < v0_len) {
u += vec(f(v0.(i), v1.(i)));
u += [f(v0.(i), v1.(i))];
i += 1u;
}
@ -262,8 +262,8 @@ fn unzip[T, U](&vec[tup(T, U)] v) -> tup(vec[T], vec[U]) {
else {
auto rest = slice[tup(T, U)](v, 1u, sz);
auto tl = unzip[T, U](rest);
auto a = vec(v.(0)._0);
auto b = vec(v.(0)._1);
auto a = [v.(0)._0];
auto b = [v.(0)._1];
ret tup(a + tl._0, b + tl._1);
}
}
@ -280,18 +280,18 @@ fn clone[T](&vec[T] v) -> vec[T] {
fn plus_option[T](&vec[T] v, &option::t[T] o) -> () {
alt (o) {
case (none[T]) {}
case (some[T](?x)) { v += vec(x); }
case (some[T](?x)) { v += [x]; }
}
}
fn cat_options[T](&vec[option::t[T]] v) -> vec[T] {
let vec[T] res = vec();
let vec[T] res = [];
for (option::t[T] o in v) {
alt (o) {
case (none[T]) { }
case (some[T](?t)) {
res += vec(t);
res += [t];
}
}
}
@ -301,9 +301,9 @@ fn cat_options[T](&vec[option::t[T]] v) -> vec[T] {
// TODO: Remove in favor of built-in "freeze" operation when it's implemented.
fn freeze[T](vec[mutable T] v) -> vec[T] {
let vec[T] result = vec();
let vec[T] result = [];
for (T elem in v) {
result += vec(elem);
result += [elem];
}
ret result;
}

View file

@ -217,6 +217,6 @@ fn eq_vec(&t v0, &vec[uint] v1) -> bool {
// indent-tabs-mode: nil
// c-basic-offset: 4
// buffer-file-coding-system: utf-8-unix
// compile-command: "make -k -C .. 2>&1 | sed -e 's/\\/x\\//x:\\//g'";
// compile-command: "make -k -C $RBUILD 2>&1 | sed -e 's/\\/x\\//x:\\//g'";
// End:
//

View file

@ -122,22 +122,22 @@ fn write_sized_vint(&io::buf_writer w, uint n, uint size) {
let vec[u8] buf;
alt (size) {
case (1u) {
buf = vec(0x80u8 | (n as u8));
buf = [0x80u8 | (n as u8)];
}
case (2u) {
buf = vec(0x40u8 | ((n >> 8u) as u8),
(n & 0xffu) as u8);
buf = [0x40u8 | ((n >> 8u) as u8),
(n & 0xffu) as u8];
}
case (3u) {
buf = vec(0x20u8 | ((n >> 16u) as u8),
buf = [0x20u8 | ((n >> 16u) as u8),
((n >> 8u) & 0xffu) as u8,
(n & 0xffu) as u8);
(n & 0xffu) as u8];
}
case (4u) {
buf = vec(0x10u8 | ((n >> 24u) as u8),
buf = [0x10u8 | ((n >> 24u) as u8),
((n >> 16u) & 0xffu) as u8,
((n >> 8u) & 0xffu) as u8,
(n & 0xffu) as u8);
(n & 0xffu) as u8];
}
case (_) {
log_err "vint to write too big";
@ -158,7 +158,7 @@ fn write_vint(&io::buf_writer w, uint n) {
}
fn create_writer(&io::buf_writer w) -> writer {
let vec[uint] size_positions = vec();
let vec[uint] size_positions = [];
ret rec(writer=w, mutable size_positions=size_positions);
}
@ -169,8 +169,8 @@ fn start_tag(&writer w, uint tag_id) {
write_vint(w.writer, tag_id);
// Write a placeholder four-byte size.
w.size_positions += vec(w.writer.tell());
let vec[u8] zeroes = vec(0u8, 0u8, 0u8, 0u8);
w.size_positions += [w.writer.tell()];
let vec[u8] zeroes = [0u8, 0u8, 0u8, 0u8];
w.writer.write(zeroes);
}

View file

@ -79,14 +79,14 @@ mod ct {
}
fn parse_fmt_string(str s) -> vec[piece] {
let vec[piece] pieces = vec();
let vec[piece] pieces = [];
auto lim = _str::byte_len(s);
auto buf = "";
fn flush_buf(str buf, &vec[piece] pieces) -> str {
if (_str::byte_len(buf) > 0u) {
auto piece = piece_string(buf);
pieces += vec(piece);
pieces += [piece];
}
ret "";
}
@ -106,7 +106,7 @@ mod ct {
} else {
buf = flush_buf(buf, pieces);
auto res = parse_conversion(s, i, lim);
pieces += vec(res._0);
pieces += [res._0];
i = res._1;
}
} else {
@ -180,7 +180,7 @@ mod ct {
}
fn parse_flags(str s, uint i, uint lim) -> tup(vec[flag], uint) {
let vec[flag] noflags = vec();
let vec[flag] noflags = [];
if (i >= lim) {
ret tup(noflags, i);
@ -190,7 +190,7 @@ mod ct {
auto next = parse_flags(s, i + 1u, lim);
auto rest = next._0;
auto j = next._1;
let vec[flag] curr = vec(f);
let vec[flag] curr = [f];
ret tup(curr + rest, j);
}
@ -539,7 +539,7 @@ mod rt {
|| head == '-' as u8
|| head == ' ' as u8) {
auto headstr = _str::unsafe_from_bytes(vec(head));
auto headstr = _str::unsafe_from_bytes([head]);
auto bytelen = _str::byte_len(s);
auto numpart = _str::substr(s, 1u, bytelen - 1u);
ret headstr + padstr + numpart;
@ -793,7 +793,7 @@ mod RT {
|| head == '-' as u8
|| head == ' ' as u8) {
auto headstr = _str::unsafe_from_bytes(vec(head));
auto headstr = _str::unsafe_from_bytes([head]);
auto bytelen = _str::byte_len(s);
auto numpart = _str::substr(s, 1u, bytelen - 1u);
ret headstr + padstr + numpart;

View file

@ -36,7 +36,7 @@ fn list_dir(path p) -> vec[str] {
if (pl == 0u || p.(pl - 1u) as char != os_fs::path_sep) {
p += path_sep();
}
let vec[str] full_paths = vec();
let vec[str] full_paths = [];
for (str filename in os_fs::list_dir(p)) {
if (!_str::eq(filename, ".")) {if (!_str::eq(filename, "..")) {
_vec::push[str](full_paths, p + filename);

View file

@ -106,7 +106,7 @@ fn getopts(vec[str] args, vec[opt] opts) -> result {
fn empty_(uint x) -> vec[optval]{ret _vec::empty[optval]();}
auto f = empty_;
auto vals = _vec::init_fn_mut[vec[optval]](f, n_opts);
let vec[str] free = vec();
let vec[str] free = [];
auto l = _vec::len[str](args);
auto i = 0u;
@ -125,15 +125,15 @@ fn getopts(vec[str] args, vec[opt] opts) -> result {
auto tail = _str::slice(cur, 2u, curlen);
auto eq = _str::index(tail, '=' as u8);
if (eq == -1) {
names = vec(long(tail));
names = [long(tail)];
} else {
names = vec(long(_str::slice(tail, 0u, eq as uint)));
names = [long(_str::slice(tail, 0u, eq as uint))];
i_arg = option::some[str]
(_str::slice(tail, (eq as uint) + 1u, curlen - 2u));
}
} else {
auto j = 1u;
names = vec();
names = [];
while (j < curlen) {
auto range = _str::char_range_at(cur, j);
_vec::push[name](names, short(range._0));
@ -221,7 +221,7 @@ fn opt_str(match m, str nm) -> str {
}
}
fn opt_strs(match m, str nm) -> vec[str] {
let vec[str] acc = vec();
let vec[str] acc = [];
for (optval v in opt_vals(m, nm)) {
alt (v) {
case (val(?s)) { _vec::push[str](acc, s); }

View file

@ -120,7 +120,7 @@ state obj new_reader(buf_reader rdr) {
ret rdr.eof();
}
fn read_line() -> str {
let vec[u8] buf = vec();
let vec[u8] buf = [];
// No break yet in rustc
auto go_on = true;
while (go_on) {
@ -131,7 +131,7 @@ state obj new_reader(buf_reader rdr) {
ret _str::unsafe_from_bytes(buf);
}
fn read_c_str() -> str {
let vec[u8] buf = vec();
let vec[u8] buf = [];
auto go_on = true;
while (go_on) {
auto ch = rdr.read_byte();
@ -172,7 +172,7 @@ state obj new_reader(buf_reader rdr) {
ret val;
}
fn read_whole_stream() -> vec[u8] {
let vec[u8] buf = vec();
let vec[u8] buf = [];
while (!rdr.eof()) {
buf += rdr.read(2048u);
}
@ -366,9 +366,9 @@ type writer =
};
fn uint_to_le_bytes(uint n, uint size) -> vec[u8] {
let vec[u8] bytes = vec();
let vec[u8] bytes = [];
while (size > 0u) {
bytes += vec((n & 255u) as u8);
bytes += [(n & 255u) as u8];
n >>= 8u;
size -= 1u;
}
@ -376,10 +376,10 @@ fn uint_to_le_bytes(uint n, uint size) -> vec[u8] {
}
fn uint_to_be_bytes(uint n, uint size) -> vec[u8] {
let vec[u8] bytes = vec();
let vec[u8] bytes = [];
auto i = (size - 1u) as int;
while (i >= 0) {
bytes += vec(((n >> ((i * 8) as uint)) & 255u) as u8);
bytes += [((n >> ((i * 8) as uint)) & 255u) as u8];
i -= 1;
}
ret bytes;
@ -466,7 +466,7 @@ state obj byte_buf_writer(mutable_byte_buf buf) {
while (vpos < vlen) {
auto b = v.(vpos);
if (buf.pos == _vec::len(buf.buf)) {
buf.buf += vec(mutable b);
buf.buf += [mutable b];
} else {
buf.buf.(buf.pos) = b;
}
@ -486,7 +486,7 @@ state obj byte_buf_writer(mutable_byte_buf buf) {
fn string_writer() -> str_writer {
// FIXME: yikes, this is bad. Needs fixing of mutable syntax.
let vec[mutable u8] b = vec(mutable 0u8);
let vec[mutable u8] b = [mutable 0u8];
_vec::pop(b);
let mutable_byte_buf buf = @rec(mutable buf = b, mutable pos = 0u);

View file

@ -65,7 +65,7 @@ fn dylib_filename(str base) -> str {
}
fn pipe() -> tup(int, int) {
let vec[mutable int] fds = vec(mutable 0, 0);
let vec[mutable int] fds = [mutable 0, 0];
assert (os::libc::pipe(_vec::buf(fds)) == 0);
ret tup(fds.(0), fds.(1));
}
@ -75,7 +75,7 @@ fn fd_FILE(int fd) -> libc::FILE {
}
fn waitpid(int pid) -> int {
let vec[mutable int] status = vec(mutable 0);
let vec[mutable int] status = [mutable 0];
assert (os::libc::waitpid(pid, _vec::buf(status), 0) != -1);
ret status.(0);
}

View file

@ -62,7 +62,7 @@ fn dylib_filename(str base) -> str {
}
fn pipe() -> tup(int, int) {
let vec[mutable int] fds = vec(mutable 0, 0);
let vec[mutable int] fds = [mutable 0, 0];
assert (os::libc::pipe(_vec::buf(fds)) == 0);
ret tup(fds.(0), fds.(1));
}
@ -72,7 +72,7 @@ fn fd_FILE(int fd) -> libc::FILE {
}
fn waitpid(int pid) -> int {
let vec[mutable int] status = vec(mutable 0);
let vec[mutable int] status = [mutable 0];
assert (os::libc::waitpid(pid, _vec::buf(status), 0) != -1);
ret status.(0);
}

View file

@ -6,7 +6,7 @@ fn list_dir(str path) -> vec[str] {
// TODO ensure this is always closed
auto dir = os::libc::opendir(_str::buf(path));
assert (dir as uint != 0u);
let vec[str] result = vec();
let vec[str] result = [];
while (true) {
auto ent = os::libc::readdir(dir);
if (ent as int == 0) {

View file

@ -5,8 +5,8 @@ native "rust" mod rustrt {
fn rust_run_program(vbuf argv, int in_fd, int out_fd, int err_fd) -> int;
}
fn argvec(str prog, vec[str] args) -> vec[sbuf] {
auto argptrs = vec(_str::buf(prog));
fn arg_vec(str prog, vec[str] args) -> vec[sbuf] {
auto argptrs = [_str::buf(prog)];
for (str arg in args) {
_vec::push[sbuf](argptrs, _str::buf(arg));
}
@ -15,7 +15,7 @@ fn argvec(str prog, vec[str] args) -> vec[sbuf] {
}
fn run_program(str prog, vec[str] args) -> int {
auto pid = rustrt::rust_run_program(_vec::buf[sbuf](argvec(prog, args)),
auto pid = rustrt::rust_run_program(_vec::buf[sbuf](arg_vec(prog, args)),
0, 0, 0);
ret os::waitpid(pid);
}
@ -33,7 +33,7 @@ fn start_program(str prog, vec[str] args) -> @program {
auto pipe_input = os::pipe();
auto pipe_output = os::pipe();
auto pid = rustrt::rust_run_program
(_vec::buf[sbuf](argvec(prog, args)),
(_vec::buf[sbuf](arg_vec(prog, args)),
pipe_input._0, pipe_output._1, 0);
if (pid == -1) {fail;}
os::libc::close(pipe_input._0);
@ -92,5 +92,5 @@ fn program_output(str prog, vec[str] args)
// indent-tabs-mode: nil
// c-basic-offset: 4
// buffer-file-coding-system: utf-8-unix
// compile-command: "make -k -C .. 2>&1 | sed -e 's/\\/x\\//x:\\//g'";
// compile-command: "make -k -C $RBUILD 2>&1 | sed -e 's/\\/x\\//x:\\//g'";
// End:

View file

@ -174,13 +174,13 @@ fn mk_sha1() -> sha1 {
st.computed = true;
}
let vec[u8] res = vec();
let vec[u8] res = [];
for (u32 hpart in st.h) {
auto a = (hpart >> 24u32) & 0xFFu32 as u8;
auto b = (hpart >> 16u32) & 0xFFu32 as u8;
auto c = (hpart >> 8u32) & 0xFFu32 as u8;
auto d = (hpart & 0xFFu32 as u8);
res += vec(a,b,c,d);
res += [a,b,c,d];
}
ret res;
}

View file

@ -6,17 +6,17 @@ type lteq[T] = fn(&T a, &T b) -> bool;
fn merge_sort[T](lteq[T] le, vec[T] v) -> vec[T] {
fn merge[T](lteq[T] le, vec[T] a, vec[T] b) -> vec[T] {
let vec[T] res = vec();
let vec[T] res = [];
let uint a_len = len[T](a);
let uint a_ix = 0u;
let uint b_len = len[T](b);
let uint b_ix = 0u;
while (a_ix < a_len && b_ix < b_len) {
if (le(a.(a_ix), b.(b_ix))) {
res += vec(a.(a_ix));
res += [a.(a_ix)];
a_ix += 1u;
} else {
res += vec(b.(b_ix));
res += [b.(b_ix)];
b_ix += 1u;
}
}

View file

@ -22,12 +22,12 @@ const u8 color_bright_cyan = 14u8;
const u8 color_bright_white = 15u8;
fn esc(io::buf_writer writer) {
writer.write(vec(0x1bu8, '[' as u8));
writer.write([0x1bu8, '[' as u8]);
}
fn reset(io::buf_writer writer) {
esc(writer);
writer.write(vec('0' as u8, 'm' as u8));
writer.write(['0' as u8, 'm' as u8]);
}
fn color_supported() -> bool {
@ -39,10 +39,10 @@ fn set_color(io::buf_writer writer, u8 first_char, u8 color) {
esc(writer);
if (color >= 8u8) {
writer.write(vec('1' as u8, ';' as u8));
writer.write(['1' as u8, ';' as u8]);
color -= 8u8;
}
writer.write(vec(first_char, ('0' as u8) + color, 'm' as u8));
writer.write([first_char, ('0' as u8) + color, 'm' as u8]);
}
fn fg(io::buf_writer writer, u8 color) {

View file

@ -7,14 +7,14 @@ type node = option::t[uint];
type ufind = rec(mutable vec[mutable node] nodes);
fn make() -> ufind {
let vec[mutable node] v = vec(mutable none[uint]);
let vec[mutable node] v = [mutable none[uint]];
_vec::pop(v); // FIXME: botch
ret rec(mutable nodes=v);
}
fn make_set(&ufind ufnd) -> uint {
auto idx = _vec::len(ufnd.nodes);
ufnd.nodes += vec(mutable none[uint]);
ufnd.nodes += [mutable none[uint]];
ret idx;
}

View file

@ -52,7 +52,7 @@ fn dylib_filename(str base) -> str {
}
fn pipe() -> tup(int, int) {
let vec[mutable int] fds = vec(mutable 0, 0);
let vec[mutable int] fds = [mutable 0, 0];
assert (os::libc::_pipe(_vec::buf(fds), 1024u,
libc_constants::O_BINARY()) == 0);
ret tup(fds.(0), fds.(1));