Reformat for new mode syntax, step 1
Long lines were fixed in a very crude way, as I'll be following up with another reformat in a bit.
This commit is contained in:
parent
64a6376da5
commit
fc6b7c8b38
209 changed files with 3358 additions and 3353 deletions
|
|
@ -14,11 +14,11 @@ native "rust" mod rustrt {
|
|||
fn aio_init();
|
||||
fn aio_run();
|
||||
fn aio_stop();
|
||||
fn aio_connect(host: *u8, port: int, connected: &chan<socket>);
|
||||
fn aio_serve(host: *u8, port: int, acceptChan: &chan<socket>) -> server;
|
||||
fn aio_writedata(s: socket, buf: *u8, size: uint, status: &chan<bool>);
|
||||
fn aio_read(s: socket, reader: &chan<[u8]>);
|
||||
fn aio_close_server(s: server, status: &chan<bool>);
|
||||
fn aio_connect(host: *u8, port: int, connected: chan<socket>);
|
||||
fn aio_serve(host: *u8, port: int, acceptChan: chan<socket>) -> server;
|
||||
fn aio_writedata(s: socket, buf: *u8, size: uint, status: chan<bool>);
|
||||
fn aio_read(s: socket, reader: chan<[u8]>);
|
||||
fn aio_close_server(s: server, status: chan<bool>);
|
||||
fn aio_close_socket(s: socket);
|
||||
fn aio_is_null_client(s: socket) -> bool;
|
||||
}
|
||||
|
|
|
|||
|
|
@ -35,7 +35,7 @@ fn create(nbits: uint, init: bool) -> t {
|
|||
ret @{storage: storage, nbits: nbits};
|
||||
}
|
||||
|
||||
fn process(op: &block(uint, uint) -> uint, v0: &t, v1: &t) -> bool {
|
||||
fn process(op: block(uint, uint) -> uint, v0: t, v1: t) -> bool {
|
||||
let len = vec::len(v1.storage);
|
||||
assert (vec::len(v0.storage) == len);
|
||||
assert (v0.nbits == v1.nbits);
|
||||
|
|
@ -51,21 +51,18 @@ fn process(op: &block(uint, uint) -> uint, v0: &t, v1: &t) -> bool {
|
|||
|
||||
fn lor(w0: uint, w1: uint) -> uint { ret w0 | w1; }
|
||||
|
||||
fn union(v0: &t, v1: &t) -> bool { let sub = lor; ret process(sub, v0, v1); }
|
||||
fn union(v0: t, v1: t) -> bool { let sub = lor; ret process(sub, v0, v1); }
|
||||
|
||||
fn land(w0: uint, w1: uint) -> uint { ret w0 & w1; }
|
||||
|
||||
fn intersect(v0: &t, v1: &t) -> bool {
|
||||
fn intersect(v0: t, v1: t) -> bool {
|
||||
let sub = land;
|
||||
ret process(sub, v0, v1);
|
||||
}
|
||||
|
||||
fn right(_w0: uint, w1: uint) -> uint { ret w1; }
|
||||
|
||||
fn assign(v0: &t, v1: t) -> bool {
|
||||
let sub = right;
|
||||
ret process(sub, v0, v1);
|
||||
}
|
||||
fn assign(v0: t, v1: t) -> bool { let sub = right; ret process(sub, v0, v1); }
|
||||
|
||||
fn clone(v: t) -> t {
|
||||
let storage = vec::init_elt_mut::<uint>(0u, v.nbits / uint_bits() + 1u);
|
||||
|
|
@ -74,7 +71,7 @@ fn clone(v: t) -> t {
|
|||
ret @{storage: storage, nbits: v.nbits};
|
||||
}
|
||||
|
||||
fn get(v: &t, i: uint) -> bool {
|
||||
fn get(v: t, i: uint) -> bool {
|
||||
assert (i < v.nbits);
|
||||
let bits = uint_bits();
|
||||
let w = i / bits;
|
||||
|
|
@ -83,7 +80,7 @@ fn get(v: &t, i: uint) -> bool {
|
|||
ret x == 1u;
|
||||
}
|
||||
|
||||
fn equal(v0: &t, v1: &t) -> bool {
|
||||
fn equal(v0: t, v1: t) -> bool {
|
||||
// FIXME: when we can break or return from inside an iterator loop,
|
||||
// we can eliminate this painful while-loop
|
||||
|
||||
|
|
@ -96,17 +93,17 @@ fn equal(v0: &t, v1: &t) -> bool {
|
|||
ret true;
|
||||
}
|
||||
|
||||
fn clear(v: &t) {
|
||||
fn clear(v: t) {
|
||||
for each i: uint in uint::range(0u, vec::len(v.storage)) {
|
||||
v.storage[i] = 0u;
|
||||
}
|
||||
}
|
||||
|
||||
fn set_all(v: &t) {
|
||||
fn set_all(v: t) {
|
||||
for each i: uint in uint::range(0u, v.nbits) { set(v, i, true); }
|
||||
}
|
||||
|
||||
fn invert(v: &t) {
|
||||
fn invert(v: t) {
|
||||
for each i: uint in uint::range(0u, vec::len(v.storage)) {
|
||||
v.storage[i] = !v.storage[i];
|
||||
}
|
||||
|
|
@ -114,14 +111,14 @@ fn invert(v: &t) {
|
|||
|
||||
|
||||
/* v0 = v0 - v1 */
|
||||
fn difference(v0: &t, v1: &t) -> bool {
|
||||
fn difference(v0: t, v1: t) -> bool {
|
||||
invert(v1);
|
||||
let b = intersect(v0, v1);
|
||||
invert(v1);
|
||||
ret b;
|
||||
}
|
||||
|
||||
fn set(v: &t, i: uint, x: bool) {
|
||||
fn set(v: t, i: uint, x: bool) {
|
||||
assert (i < v.nbits);
|
||||
let bits = uint_bits();
|
||||
let w = i / bits;
|
||||
|
|
@ -132,32 +129,32 @@ fn set(v: &t, i: uint, x: bool) {
|
|||
|
||||
|
||||
/* true if all bits are 1 */
|
||||
fn is_true(v: &t) -> bool {
|
||||
fn is_true(v: t) -> bool {
|
||||
for i: uint in to_vec(v) { if i != 1u { ret false; } }
|
||||
ret true;
|
||||
}
|
||||
|
||||
|
||||
/* true if all bits are non-1 */
|
||||
fn is_false(v: &t) -> bool {
|
||||
fn is_false(v: t) -> bool {
|
||||
for i: uint in to_vec(v) { if i == 1u { ret false; } }
|
||||
ret true;
|
||||
}
|
||||
|
||||
fn init_to_vec(v: t, i: uint) -> uint { ret if get(v, i) { 1u } else { 0u }; }
|
||||
|
||||
fn to_vec(v: &t) -> [uint] {
|
||||
fn to_vec(v: t) -> [uint] {
|
||||
let sub = bind init_to_vec(v, _);
|
||||
ret vec::init_fn::<uint>(sub, v.nbits);
|
||||
}
|
||||
|
||||
fn to_str(v: &t) -> str {
|
||||
fn to_str(v: t) -> str {
|
||||
let rs = "";
|
||||
for i: uint in to_vec(v) { if i == 1u { rs += "1"; } else { rs += "0"; } }
|
||||
ret rs;
|
||||
}
|
||||
|
||||
fn eq_vec(v0: &t, v1: &[uint]) -> bool {
|
||||
fn eq_vec(v0: t, v1: [uint]) -> bool {
|
||||
assert (v0.nbits == vec::len::<uint>(v1));
|
||||
let len = v0.nbits;
|
||||
let i = 0u;
|
||||
|
|
|
|||
|
|
@ -1,7 +1,7 @@
|
|||
|
||||
export ptr_eq;
|
||||
|
||||
fn ptr_eq<T>(a: &@T, b: &@T) -> bool {
|
||||
fn ptr_eq<T>(a: @T, b: @T) -> bool {
|
||||
let a_ptr: uint = unsafe::reinterpret_cast(a);
|
||||
let b_ptr: uint = unsafe::reinterpret_cast(b);
|
||||
ret a_ptr == b_ptr;
|
||||
|
|
|
|||
|
|
@ -38,7 +38,7 @@ resource port_ptr(po: *rustrt::rust_port) {
|
|||
|
||||
tag port<~T> { port_t(@port_ptr); }
|
||||
|
||||
fn send<~T>(ch: &chan<T>, data: -T) {
|
||||
fn send<~T>(ch: chan<T>, data: -T) {
|
||||
let chan_t(t, p) = ch;
|
||||
rustrt::chan_id_send(t, p, data);
|
||||
}
|
||||
|
|
@ -47,8 +47,8 @@ fn port<~T>() -> port<T> {
|
|||
port_t(@port_ptr(rustrt::new_port(sys::size_of::<T>())))
|
||||
}
|
||||
|
||||
fn recv<~T>(p: &port<T>) -> T { ret rusti::recv(***p) }
|
||||
fn recv<~T>(p: port<T>) -> T { ret rusti::recv(***p) }
|
||||
|
||||
fn chan<~T>(p: &port<T>) -> chan<T> {
|
||||
fn chan<~T>(p: port<T>) -> chan<T> {
|
||||
chan_t(task::get_task_id(), rustrt::get_port_id(***p))
|
||||
}
|
||||
|
|
|
|||
|
|
@ -10,21 +10,21 @@
|
|||
|
||||
native "rust" mod rustrt {
|
||||
fn debug_tydesc<T>();
|
||||
fn debug_opaque<T>(x: &T);
|
||||
fn debug_opaque<T>(x: T);
|
||||
fn debug_box<T>(x: @T);
|
||||
fn debug_tag<T>(x: &T);
|
||||
fn debug_obj<T>(x: &T, nmethods: uint, nbytes: uint);
|
||||
fn debug_fn<T>(x: &T);
|
||||
fn debug_tag<T>(x: T);
|
||||
fn debug_obj<T>(x: T, nmethods: uint, nbytes: uint);
|
||||
fn debug_fn<T>(x: T);
|
||||
fn debug_ptrcast<T, U>(x: @T) -> @U;
|
||||
}
|
||||
|
||||
fn debug_tydesc<T>() { rustrt::debug_tydesc::<T>(); }
|
||||
|
||||
fn debug_opaque<T>(x: &T) { rustrt::debug_opaque::<T>(x); }
|
||||
fn debug_opaque<T>(x: T) { rustrt::debug_opaque::<T>(x); }
|
||||
|
||||
fn debug_box<T>(x: @T) { rustrt::debug_box::<T>(x); }
|
||||
|
||||
fn debug_tag<T>(x: &T) { rustrt::debug_tag::<T>(x); }
|
||||
fn debug_tag<T>(x: T) { rustrt::debug_tag::<T>(x); }
|
||||
|
||||
|
||||
/**
|
||||
|
|
@ -36,15 +36,15 @@ fn debug_tag<T>(x: &T) { rustrt::debug_tag::<T>(x); }
|
|||
* this to at least be 4u, since an implicit captured tydesc pointer sits in
|
||||
* the front of any obj's data tuple.x
|
||||
*/
|
||||
fn debug_obj<T>(x: &T, nmethods: uint, nbytes: uint) {
|
||||
fn debug_obj<T>(x: T, nmethods: uint, nbytes: uint) {
|
||||
rustrt::debug_obj::<T>(x, nmethods, nbytes);
|
||||
}
|
||||
|
||||
fn debug_fn<T>(x: &T) { rustrt::debug_fn::<T>(x); }
|
||||
fn debug_fn<T>(x: T) { rustrt::debug_fn::<T>(x); }
|
||||
|
||||
fn ptr_cast<T, U>(x: @T) -> @U { ret rustrt::debug_ptrcast::<T, U>(x); }
|
||||
|
||||
fn refcount<T>(a: &@T) -> uint {
|
||||
fn refcount<T>(a: @T) -> uint {
|
||||
let p: *uint = unsafe::reinterpret_cast(a);
|
||||
ret *p;
|
||||
}
|
||||
|
|
|
|||
|
|
@ -7,8 +7,8 @@
|
|||
type t<T> =
|
||||
obj {
|
||||
fn size() -> uint;
|
||||
fn add_front(&T);
|
||||
fn add_back(&T);
|
||||
fn add_front(T);
|
||||
fn add_back(T);
|
||||
fn pop_front() -> T;
|
||||
fn pop_back() -> T;
|
||||
fn peek_front() -> T;
|
||||
|
|
@ -28,7 +28,8 @@ fn create<@T>() -> t<T> {
|
|||
|
||||
|
||||
|
||||
fn grow<@T>(nelts: uint, lo: uint, elts: &[mutable cell<T>]) ->
|
||||
|
||||
fn grow<@T>(nelts: uint, lo: uint, elts: [mutable cell<T>]) ->
|
||||
[mutable cell<T>] {
|
||||
assert (nelts == vec::len(elts));
|
||||
let rv = [mutable];
|
||||
|
|
@ -44,7 +45,7 @@ fn create<@T>() -> t<T> {
|
|||
|
||||
ret rv;
|
||||
}
|
||||
fn get<@T>(elts: &[mutable cell<T>], i: uint) -> T {
|
||||
fn get<@T>(elts: [mutable cell<T>], i: uint) -> T {
|
||||
ret alt elts[i] { option::some(t) { t } _ { fail } };
|
||||
}
|
||||
obj deque<@T>(mutable nelts: uint,
|
||||
|
|
@ -52,7 +53,7 @@ fn create<@T>() -> t<T> {
|
|||
mutable hi: uint,
|
||||
mutable elts: [mutable cell<T>]) {
|
||||
fn size() -> uint { ret nelts; }
|
||||
fn add_front(t: &T) {
|
||||
fn add_front(t: T) {
|
||||
let oldlo: uint = lo;
|
||||
if lo == 0u {
|
||||
lo = vec::len::<cell<T>>(elts) - 1u;
|
||||
|
|
@ -65,7 +66,7 @@ fn create<@T>() -> t<T> {
|
|||
elts[lo] = option::some::<T>(t);
|
||||
nelts += 1u;
|
||||
}
|
||||
fn add_back(t: &T) {
|
||||
fn add_back(t: T) {
|
||||
if lo == hi && nelts != 0u {
|
||||
elts = grow::<T>(nelts, lo, elts);
|
||||
lo = 0u;
|
||||
|
|
|
|||
|
|
@ -17,7 +17,7 @@ type ebml_state = {ebml_tag: ebml_tag, tag_pos: uint, data_pos: uint};
|
|||
// ebml reading
|
||||
type doc = {data: @[u8], start: uint, end: uint};
|
||||
|
||||
fn vint_at(data: &[u8], start: uint) -> {val: uint, next: uint} {
|
||||
fn vint_at(data: [u8], start: uint) -> {val: uint, next: uint} {
|
||||
let a = data[start];
|
||||
if a & 0x80u8 != 0u8 { ret {val: a & 0x7fu8 as uint, next: start + 1u}; }
|
||||
if a & 0x40u8 != 0u8 {
|
||||
|
|
@ -39,11 +39,11 @@ fn vint_at(data: &[u8], start: uint) -> {val: uint, next: uint} {
|
|||
} else { log_err "vint too big"; fail; }
|
||||
}
|
||||
|
||||
fn new_doc(data: &@[u8]) -> doc {
|
||||
fn new_doc(data: @[u8]) -> doc {
|
||||
ret {data: data, start: 0u, end: vec::len::<u8>(*data)};
|
||||
}
|
||||
|
||||
fn doc_at(data: &@[u8], start: uint) -> doc {
|
||||
fn doc_at(data: @[u8], start: uint) -> doc {
|
||||
let elt_tag = vint_at(*data, start);
|
||||
let elt_size = vint_at(*data, elt_tag.next);
|
||||
let end = elt_size.next + elt_size.val;
|
||||
|
|
@ -98,7 +98,7 @@ iter tagged_docs(d: doc, tg: uint) -> doc {
|
|||
|
||||
fn doc_data(d: doc) -> [u8] { ret vec::slice::<u8>(*d.data, d.start, d.end); }
|
||||
|
||||
fn be_uint_from_bytes(data: &@[u8], start: uint, size: uint) -> uint {
|
||||
fn be_uint_from_bytes(data: @[u8], start: uint, size: uint) -> uint {
|
||||
let sz = size;
|
||||
assert (sz <= 4u);
|
||||
let val = 0u;
|
||||
|
|
@ -119,7 +119,7 @@ fn doc_as_uint(d: doc) -> uint {
|
|||
// ebml writing
|
||||
type writer = {writer: io::buf_writer, mutable size_positions: [uint]};
|
||||
|
||||
fn write_sized_vint(w: &io::buf_writer, n: uint, size: uint) {
|
||||
fn write_sized_vint(w: io::buf_writer, n: uint, size: uint) {
|
||||
let buf: [u8];
|
||||
alt size {
|
||||
1u { buf = [0x80u8 | (n as u8)]; }
|
||||
|
|
@ -139,7 +139,7 @@ fn write_sized_vint(w: &io::buf_writer, n: uint, size: uint) {
|
|||
w.write(buf);
|
||||
}
|
||||
|
||||
fn write_vint(w: &io::buf_writer, n: uint) {
|
||||
fn write_vint(w: io::buf_writer, n: uint) {
|
||||
if n < 0x7fu { write_sized_vint(w, n, 1u); ret; }
|
||||
if n < 0x4000u { write_sized_vint(w, n, 2u); ret; }
|
||||
if n < 0x200000u { write_sized_vint(w, n, 3u); ret; }
|
||||
|
|
@ -148,14 +148,14 @@ fn write_vint(w: &io::buf_writer, n: uint) {
|
|||
fail;
|
||||
}
|
||||
|
||||
fn create_writer(w: &io::buf_writer) -> writer {
|
||||
fn create_writer(w: io::buf_writer) -> writer {
|
||||
let size_positions: [uint] = [];
|
||||
ret {writer: w, mutable size_positions: size_positions};
|
||||
}
|
||||
|
||||
|
||||
// TODO: Provide a function to write the standard ebml header.
|
||||
fn start_tag(w: &writer, tag_id: uint) {
|
||||
fn start_tag(w: writer, tag_id: uint) {
|
||||
// Write the tag ID:
|
||||
|
||||
write_vint(w.writer, tag_id);
|
||||
|
|
@ -166,7 +166,7 @@ fn start_tag(w: &writer, tag_id: uint) {
|
|||
w.writer.write(zeroes);
|
||||
}
|
||||
|
||||
fn end_tag(w: &writer) {
|
||||
fn end_tag(w: writer) {
|
||||
let last_size_pos = vec::pop::<uint>(w.size_positions);
|
||||
let cur_pos = w.writer.tell();
|
||||
w.writer.seek(last_size_pos as int, io::seek_set);
|
||||
|
|
|
|||
|
|
@ -6,12 +6,12 @@ import option::none;
|
|||
tag t<T, U> { left(T); right(U); }
|
||||
|
||||
fn either<T, U,
|
||||
V>(f_left: &block(&T) -> V, f_right: &block(&U) -> V,
|
||||
value: &t<T, U>) -> V {
|
||||
V>(f_left: block(T) -> V, f_right: block(U) -> V, value: t<T, U>) ->
|
||||
V {
|
||||
alt value { left(l) { f_left(l) } right(r) { f_right(r) } }
|
||||
}
|
||||
|
||||
fn lefts<T, U>(eithers: &[t<T, U>]) -> [T] {
|
||||
fn lefts<T, U>(eithers: [t<T, U>]) -> [T] {
|
||||
let result: [T] = [];
|
||||
for elt: t<T, U> in eithers {
|
||||
alt elt { left(l) { result += [l] } _ {/* fallthrough */ } }
|
||||
|
|
@ -19,7 +19,7 @@ fn lefts<T, U>(eithers: &[t<T, U>]) -> [T] {
|
|||
ret result;
|
||||
}
|
||||
|
||||
fn rights<T, U>(eithers: &[t<T, U>]) -> [U] {
|
||||
fn rights<T, U>(eithers: [t<T, U>]) -> [U] {
|
||||
let result: [U] = [];
|
||||
for elt: t<T, U> in eithers {
|
||||
alt elt { right(r) { result += [r] } _ {/* fallthrough */ } }
|
||||
|
|
@ -27,7 +27,7 @@ fn rights<T, U>(eithers: &[t<T, U>]) -> [U] {
|
|||
ret result;
|
||||
}
|
||||
|
||||
fn partition<T, U>(eithers: &[t<T, U>]) -> {lefts: [T], rights: [U]} {
|
||||
fn partition<T, U>(eithers: [t<T, U>]) -> {lefts: [T], rights: [U]} {
|
||||
let lefts: [T] = [];
|
||||
let rights: [U] = [];
|
||||
for elt: t<T, U> in eithers {
|
||||
|
|
|
|||
|
|
@ -68,13 +68,13 @@ mod ct {
|
|||
|
||||
// A fragment of the output sequence
|
||||
tag piece { piece_string(str); piece_conv(conv); }
|
||||
type error_fn = fn(&str) -> ! ;
|
||||
type error_fn = fn(str) -> ! ;
|
||||
|
||||
fn parse_fmt_string(s: &str, error: error_fn) -> [piece] {
|
||||
fn parse_fmt_string(s: str, error: error_fn) -> [piece] {
|
||||
let pieces: [piece] = [];
|
||||
let lim = str::byte_len(s);
|
||||
let buf = "";
|
||||
fn flush_buf(buf: &str, pieces: &mutable [piece]) -> str {
|
||||
fn flush_buf(buf: str, pieces: &mutable [piece]) -> str {
|
||||
if str::byte_len(buf) > 0u {
|
||||
let piece = piece_string(buf);
|
||||
pieces += [piece];
|
||||
|
|
@ -103,7 +103,7 @@ mod ct {
|
|||
buf = flush_buf(buf, pieces);
|
||||
ret pieces;
|
||||
}
|
||||
fn peek_num(s: &str, i: uint, lim: uint) ->
|
||||
fn peek_num(s: str, i: uint, lim: uint) ->
|
||||
option::t<{num: uint, next: uint}> {
|
||||
if i >= lim { ret none; }
|
||||
let c = s[i];
|
||||
|
|
@ -118,7 +118,7 @@ mod ct {
|
|||
}
|
||||
};
|
||||
}
|
||||
fn parse_conversion(s: &str, i: uint, lim: uint, error: error_fn) ->
|
||||
fn parse_conversion(s: str, i: uint, lim: uint, error: error_fn) ->
|
||||
{piece: piece, next: uint} {
|
||||
let parm = parse_parameter(s, i, lim);
|
||||
let flags = parse_flags(s, parm.next, lim);
|
||||
|
|
@ -133,7 +133,7 @@ mod ct {
|
|||
ty: ty.ty}),
|
||||
next: ty.next};
|
||||
}
|
||||
fn parse_parameter(s: &str, i: uint, lim: uint) ->
|
||||
fn parse_parameter(s: str, i: uint, lim: uint) ->
|
||||
{param: option::t<int>, next: uint} {
|
||||
if i >= lim { ret {param: none, next: i}; }
|
||||
let num = peek_num(s, i, lim);
|
||||
|
|
@ -148,14 +148,14 @@ mod ct {
|
|||
}
|
||||
};
|
||||
}
|
||||
fn parse_flags(s: &str, i: uint, lim: uint) ->
|
||||
fn parse_flags(s: str, i: uint, lim: uint) ->
|
||||
{flags: [flag], next: uint} {
|
||||
let noflags: [flag] = [];
|
||||
if i >= lim { ret {flags: noflags, next: i}; }
|
||||
|
||||
// FIXME: This recursion generates illegal instructions if the return
|
||||
// value isn't boxed. Only started happening after the ivec conversion
|
||||
fn more_(f: flag, s: &str, i: uint, lim: uint) ->
|
||||
fn more_(f: flag, s: str, i: uint, lim: uint) ->
|
||||
@{flags: [flag], next: uint} {
|
||||
let next = parse_flags(s, i + 1u, lim);
|
||||
let rest = next.flags;
|
||||
|
|
@ -177,8 +177,7 @@ mod ct {
|
|||
*more(flag_alternate)
|
||||
} else { {flags: noflags, next: i} };
|
||||
}
|
||||
fn parse_count(s: &str, i: uint, lim: uint) ->
|
||||
{count: count, next: uint} {
|
||||
fn parse_count(s: str, i: uint, lim: uint) -> {count: count, next: uint} {
|
||||
ret if i >= lim {
|
||||
{count: count_implied, next: i}
|
||||
} else if s[i] == '*' as u8 {
|
||||
|
|
@ -198,7 +197,7 @@ mod ct {
|
|||
}
|
||||
};
|
||||
}
|
||||
fn parse_precision(s: &str, i: uint, lim: uint) ->
|
||||
fn parse_precision(s: str, i: uint, lim: uint) ->
|
||||
{count: count, next: uint} {
|
||||
ret if i >= lim {
|
||||
{count: count_implied, next: i}
|
||||
|
|
@ -214,7 +213,7 @@ mod ct {
|
|||
}
|
||||
} else { {count: count_implied, next: i} };
|
||||
}
|
||||
fn parse_type(s: &str, i: uint, lim: uint, error: error_fn) ->
|
||||
fn parse_type(s: str, i: uint, lim: uint, error: error_fn) ->
|
||||
{ty: ty, next: uint} {
|
||||
if i >= lim { error("missing type in conversion"); }
|
||||
let tstr = str::substr(s, i, 1u);
|
||||
|
|
@ -270,7 +269,7 @@ mod rt {
|
|||
// instead just use a bool per flag
|
||||
type conv = {flags: [flag], width: count, precision: count, ty: ty};
|
||||
|
||||
fn conv_int(cv: &conv, i: int) -> str {
|
||||
fn conv_int(cv: conv, i: int) -> str {
|
||||
let radix = 10u;
|
||||
let prec = get_int_precision(cv);
|
||||
let s = int_to_str_prec(i, radix, prec);
|
||||
|
|
@ -283,7 +282,7 @@ mod rt {
|
|||
}
|
||||
ret pad(cv, s, pad_signed);
|
||||
}
|
||||
fn conv_uint(cv: &conv, u: uint) -> str {
|
||||
fn conv_uint(cv: conv, u: uint) -> str {
|
||||
let prec = get_int_precision(cv);
|
||||
let rs =
|
||||
alt cv.ty {
|
||||
|
|
@ -295,17 +294,17 @@ mod rt {
|
|||
};
|
||||
ret pad(cv, rs, pad_unsigned);
|
||||
}
|
||||
fn conv_bool(cv: &conv, b: bool) -> str {
|
||||
fn conv_bool(cv: conv, b: bool) -> str {
|
||||
let s = if b { "true" } else { "false" };
|
||||
// run the boolean conversion through the string conversion logic,
|
||||
// giving it the same rules for precision, etc.
|
||||
|
||||
ret conv_str(cv, s);
|
||||
}
|
||||
fn conv_char(cv: &conv, c: char) -> str {
|
||||
fn conv_char(cv: conv, c: char) -> str {
|
||||
ret pad(cv, str::from_char(c), pad_nozero);
|
||||
}
|
||||
fn conv_str(cv: &conv, s: &str) -> str {
|
||||
fn conv_str(cv: conv, s: str) -> str {
|
||||
// For strings, precision is the maximum characters
|
||||
// displayed
|
||||
|
||||
|
|
@ -346,7 +345,7 @@ mod rt {
|
|||
} else { s }
|
||||
};
|
||||
}
|
||||
fn get_int_precision(cv: &conv) -> uint {
|
||||
fn get_int_precision(cv: conv) -> uint {
|
||||
ret alt cv.precision {
|
||||
count_is(c) { c as uint }
|
||||
count_implied. { 1u }
|
||||
|
|
@ -360,7 +359,7 @@ mod rt {
|
|||
ret str::unsafe_from_bytes(svec);
|
||||
}
|
||||
tag pad_mode { pad_signed; pad_unsigned; pad_nozero; }
|
||||
fn pad(cv: &conv, s: &str, mode: pad_mode) -> str {
|
||||
fn pad(cv: conv, s: str, mode: pad_mode) -> str {
|
||||
let uwidth;
|
||||
alt cv.width {
|
||||
count_implied. { ret s; }
|
||||
|
|
@ -388,7 +387,7 @@ mod rt {
|
|||
pad_signed. { might_zero_pad = true; signed = true; }
|
||||
pad_unsigned. { might_zero_pad = true; }
|
||||
}
|
||||
fn have_precision(cv: &conv) -> bool {
|
||||
fn have_precision(cv: conv) -> bool {
|
||||
ret alt cv.precision { count_implied. { false } _ { true } };
|
||||
}
|
||||
let zero_padding = false;
|
||||
|
|
@ -414,7 +413,7 @@ mod rt {
|
|||
}
|
||||
ret padstr + s;
|
||||
}
|
||||
fn have_flag(flags: &[flag], f: flag) -> bool {
|
||||
fn have_flag(flags: [flag], f: flag) -> bool {
|
||||
for candidate: flag in flags { if candidate == f { ret true; } }
|
||||
ret false;
|
||||
}
|
||||
|
|
|
|||
|
|
@ -10,7 +10,7 @@ fn path_sep() -> str { ret str::from_char(os_fs::path_sep); }
|
|||
|
||||
type path = str;
|
||||
|
||||
fn dirname(p: &path) -> path {
|
||||
fn dirname(p: path) -> path {
|
||||
let i: int = str::rindex(p, os_fs::path_sep as u8);
|
||||
if i == -1 {
|
||||
i = str::rindex(p, os_fs::alt_path_sep as u8);
|
||||
|
|
@ -19,7 +19,7 @@ fn dirname(p: &path) -> path {
|
|||
ret str::substr(p, 0u, i as uint);
|
||||
}
|
||||
|
||||
fn basename(p: &path) -> path {
|
||||
fn basename(p: path) -> path {
|
||||
let i: int = str::rindex(p, os_fs::path_sep as u8);
|
||||
if i == -1 {
|
||||
i = str::rindex(p, os_fs::alt_path_sep as u8);
|
||||
|
|
@ -32,7 +32,7 @@ fn basename(p: &path) -> path {
|
|||
|
||||
|
||||
// FIXME: Need some typestate to avoid bounds check when len(pre) == 0
|
||||
fn connect(pre: &path, post: &path) -> path {
|
||||
fn connect(pre: path, post: path) -> path {
|
||||
let len = str::byte_len(pre);
|
||||
ret if pre[len - 1u] == os_fs::path_sep as u8 {
|
||||
|
||||
|
|
@ -41,11 +41,11 @@ fn connect(pre: &path, post: &path) -> path {
|
|||
} else { pre + path_sep() + post };
|
||||
}
|
||||
|
||||
fn file_is_dir(p: &path) -> bool {
|
||||
fn file_is_dir(p: path) -> bool {
|
||||
ret str::as_buf(p, {|buf| rustrt::rust_file_is_dir(buf) != 0 });
|
||||
}
|
||||
|
||||
fn list_dir(p: &path) -> [str] {
|
||||
fn list_dir(p: path) -> [str] {
|
||||
let p = p;
|
||||
let pl = str::byte_len(p);
|
||||
if pl == 0u || p[pl - 1u] as char != os_fs::path_sep { p += path_sep(); }
|
||||
|
|
@ -58,11 +58,11 @@ fn list_dir(p: &path) -> [str] {
|
|||
ret full_paths;
|
||||
}
|
||||
|
||||
fn path_is_absolute(p: &path) -> bool { ret os_fs::path_is_absolute(p); }
|
||||
fn path_is_absolute(p: path) -> bool { ret os_fs::path_is_absolute(p); }
|
||||
|
||||
// FIXME: under Windows, we should prepend the current drive letter to paths
|
||||
// that start with a slash.
|
||||
fn make_absolute(p: &path) -> path {
|
||||
fn make_absolute(p: path) -> path {
|
||||
if path_is_absolute(p) { ret p; } else { ret connect(getcwd(), p); }
|
||||
}
|
||||
|
||||
|
|
|
|||
|
|
@ -29,7 +29,7 @@ type treemap<@K, @V> = @tree_node<K, V>;
|
|||
|
||||
fn init<@K, @V>() -> treemap<K, V> { @empty }
|
||||
|
||||
fn insert<@K, @V>(m: &treemap<K, V>, k: &K, v: &V) -> treemap<K, V> {
|
||||
fn insert<@K, @V>(m: treemap<K, V>, k: K, v: V) -> treemap<K, V> {
|
||||
@alt m {
|
||||
@empty. { node(@k, @v, @empty, @empty) }
|
||||
@node(@kk, vv, left, right) {
|
||||
|
|
@ -42,7 +42,7 @@ fn insert<@K, @V>(m: &treemap<K, V>, k: &K, v: &V) -> treemap<K, V> {
|
|||
}
|
||||
}
|
||||
|
||||
fn find<@K, @V>(m: &treemap<K, V>, k: &K) -> option<V> {
|
||||
fn find<@K, @V>(m: treemap<K, V>, k: K) -> option<V> {
|
||||
alt *m {
|
||||
empty. { none }
|
||||
node(@kk, @v, left, right) {
|
||||
|
|
@ -55,7 +55,7 @@ fn find<@K, @V>(m: &treemap<K, V>, k: &K) -> option<V> {
|
|||
|
||||
|
||||
// Performs an in-order traversal
|
||||
fn traverse<@K, @V>(m: &treemap<K, V>, f: fn(&K, &V)) {
|
||||
fn traverse<@K, @V>(m: treemap<K, V>, f: fn(K, V)) {
|
||||
alt *m {
|
||||
empty. { }
|
||||
node(@k, @v, _, _) {
|
||||
|
|
|
|||
|
|
@ -3,7 +3,7 @@ import str::sbuf;
|
|||
|
||||
#[cfg(target_os = "linux")]
|
||||
#[cfg(target_os = "macos")]
|
||||
fn getenv(n: &str) -> option::t<str> {
|
||||
fn getenv(n: str) -> option::t<str> {
|
||||
let s = str::as_buf(n, {|buf| os::libc::getenv(buf) });
|
||||
ret if unsafe::reinterpret_cast(s) == 0 {
|
||||
option::none::<str>
|
||||
|
|
@ -15,7 +15,7 @@ fn getenv(n: &str) -> option::t<str> {
|
|||
|
||||
#[cfg(target_os = "linux")]
|
||||
#[cfg(target_os = "macos")]
|
||||
fn setenv(n: &str, v: &str) {
|
||||
fn setenv(n: str, v: str) {
|
||||
// FIXME (868)
|
||||
let _: () =
|
||||
str::as_buf(n,
|
||||
|
|
@ -30,7 +30,7 @@ fn setenv(n: &str, v: &str) {
|
|||
}
|
||||
|
||||
#[cfg(target_os = "win32")]
|
||||
fn getenv(n: &str) -> option::t<str> {
|
||||
fn getenv(n: str) -> option::t<str> {
|
||||
let nsize = 256u;
|
||||
while true {
|
||||
let v: [u8] = [];
|
||||
|
|
@ -53,13 +53,18 @@ fn getenv(n: &str) -> option::t<str> {
|
|||
}
|
||||
|
||||
#[cfg(target_os = "win32")]
|
||||
fn setenv(n: &str, v: &str) {
|
||||
fn setenv(n: str, v: str) {
|
||||
// FIXME (868)
|
||||
let _: () = str::as_buf(n, {|nbuf|
|
||||
let _: () = str::as_buf(v, {|vbuf|
|
||||
os::kernel32::SetEnvironmentVariableA(nbuf, vbuf);
|
||||
});
|
||||
});
|
||||
let _: () =
|
||||
str::as_buf(n,
|
||||
{|nbuf|
|
||||
let _: () =
|
||||
str::as_buf(v,
|
||||
{|vbuf|
|
||||
os::kernel32::SetEnvironmentVariableA(nbuf,
|
||||
vbuf);
|
||||
});
|
||||
});
|
||||
}
|
||||
|
||||
// Local Variables:
|
||||
|
|
|
|||
|
|
@ -37,29 +37,29 @@ tag occur { req; optional; multi; }
|
|||
|
||||
type opt = {name: name, hasarg: hasarg, occur: occur};
|
||||
|
||||
fn mkname(nm: &str) -> name {
|
||||
fn mkname(nm: str) -> name {
|
||||
ret if str::char_len(nm) == 1u {
|
||||
short(str::char_at(nm, 0u))
|
||||
} else { long(nm) };
|
||||
}
|
||||
|
||||
fn reqopt(name: &str) -> opt {
|
||||
fn reqopt(name: str) -> opt {
|
||||
ret {name: mkname(name), hasarg: yes, occur: req};
|
||||
}
|
||||
|
||||
fn optopt(name: &str) -> opt {
|
||||
fn optopt(name: str) -> opt {
|
||||
ret {name: mkname(name), hasarg: yes, occur: optional};
|
||||
}
|
||||
|
||||
fn optflag(name: &str) -> opt {
|
||||
fn optflag(name: str) -> opt {
|
||||
ret {name: mkname(name), hasarg: no, occur: optional};
|
||||
}
|
||||
|
||||
fn optflagopt(name: &str) -> opt {
|
||||
fn optflagopt(name: str) -> opt {
|
||||
ret {name: mkname(name), hasarg: maybe, occur: optional};
|
||||
}
|
||||
|
||||
fn optmulti(name: &str) -> opt {
|
||||
fn optmulti(name: str) -> opt {
|
||||
ret {name: mkname(name), hasarg: yes, occur: multi};
|
||||
}
|
||||
|
||||
|
|
@ -67,15 +67,15 @@ tag optval { val(str); given; }
|
|||
|
||||
type match = {opts: [opt], vals: [mutable [optval]], free: [str]};
|
||||
|
||||
fn is_arg(arg: &str) -> bool {
|
||||
fn is_arg(arg: str) -> bool {
|
||||
ret str::byte_len(arg) > 1u && arg[0] == '-' as u8;
|
||||
}
|
||||
|
||||
fn name_str(nm: &name) -> str {
|
||||
fn name_str(nm: name) -> str {
|
||||
ret alt nm { short(ch) { str::from_char(ch) } long(s) { s } };
|
||||
}
|
||||
|
||||
fn find_opt(opts: &[opt], nm: &name) -> option::t<uint> {
|
||||
fn find_opt(opts: [opt], nm: name) -> option::t<uint> {
|
||||
let i = 0u;
|
||||
let l = vec::len::<opt>(opts);
|
||||
while i < l { if opts[i].name == nm { ret some::<uint>(i); } i += 1u; }
|
||||
|
|
@ -90,7 +90,7 @@ tag fail_ {
|
|||
unexpected_argument(str);
|
||||
}
|
||||
|
||||
fn fail_str(f: &fail_) -> str {
|
||||
fn fail_str(f: fail_) -> str {
|
||||
ret alt f {
|
||||
argument_missing(nm) { "Argument to option '" + nm + "' missing." }
|
||||
unrecognized_option(nm) { "Unrecognized option: '" + nm + "'." }
|
||||
|
|
@ -106,7 +106,7 @@ fn fail_str(f: &fail_) -> str {
|
|||
|
||||
tag result { success(match); failure(fail_); }
|
||||
|
||||
fn getopts(args: &[str], opts: &[opt]) -> result {
|
||||
fn getopts(args: [str], opts: [opt]) -> result {
|
||||
let n_opts = vec::len::<opt>(opts);
|
||||
fn f(_x: uint) -> [optval] { ret []; }
|
||||
let vals = vec::init_fn_mut::<[optval]>(f, n_opts);
|
||||
|
|
@ -200,24 +200,24 @@ fn getopts(args: &[str], opts: &[opt]) -> result {
|
|||
ret success({opts: opts, vals: vals, free: free});
|
||||
}
|
||||
|
||||
fn opt_vals(m: &match, nm: &str) -> [optval] {
|
||||
fn opt_vals(m: match, nm: str) -> [optval] {
|
||||
ret alt find_opt(m.opts, mkname(nm)) {
|
||||
some(id) { m.vals[id] }
|
||||
none. { log_err "No option '" + nm + "' defined."; fail }
|
||||
};
|
||||
}
|
||||
|
||||
fn opt_val(m: &match, nm: &str) -> optval { ret opt_vals(m, nm)[0]; }
|
||||
fn opt_val(m: match, nm: str) -> optval { ret opt_vals(m, nm)[0]; }
|
||||
|
||||
fn opt_present(m: &match, nm: &str) -> bool {
|
||||
fn opt_present(m: match, nm: str) -> bool {
|
||||
ret vec::len::<optval>(opt_vals(m, nm)) > 0u;
|
||||
}
|
||||
|
||||
fn opt_str(m: &match, nm: &str) -> str {
|
||||
fn opt_str(m: match, nm: str) -> str {
|
||||
ret alt opt_val(m, nm) { val(s) { s } _ { fail } };
|
||||
}
|
||||
|
||||
fn opt_strs(m: &match, nm: &str) -> [str] {
|
||||
fn opt_strs(m: match, nm: str) -> [str] {
|
||||
let acc: [str] = [];
|
||||
for v: optval in opt_vals(m, nm) {
|
||||
alt v { val(s) { acc += [s]; } _ { } }
|
||||
|
|
@ -225,7 +225,7 @@ fn opt_strs(m: &match, nm: &str) -> [str] {
|
|||
ret acc;
|
||||
}
|
||||
|
||||
fn opt_maybe_str(m: &match, nm: &str) -> option::t<str> {
|
||||
fn opt_maybe_str(m: match, nm: str) -> option::t<str> {
|
||||
let vals = opt_vals(m, nm);
|
||||
if vec::len::<optval>(vals) == 0u { ret none::<str>; }
|
||||
ret alt vals[0] { val(s) { some::<str>(s) } _ { none::<str> } };
|
||||
|
|
@ -235,7 +235,7 @@ fn opt_maybe_str(m: &match, nm: &str) -> option::t<str> {
|
|||
/// Returns none if the option was not present, `def` if the option was
|
||||
/// present but no argument was provided, and the argument if the option was
|
||||
/// present and an argument was provided.
|
||||
fn opt_default(m: &match, nm: &str, def: &str) -> option::t<str> {
|
||||
fn opt_default(m: match, nm: str, def: str) -> option::t<str> {
|
||||
let vals = opt_vals(m, nm);
|
||||
if vec::len::<optval>(vals) == 0u { ret none::<str>; }
|
||||
ret alt vals[0] { val(s) { some::<str>(s) } _ { some::<str>(def) } }
|
||||
|
|
|
|||
|
|
@ -32,9 +32,9 @@ pure fn nonnegative(x: int) -> bool { ret x >= 0; }
|
|||
|
||||
|
||||
// FIXME: Make sure this works with negative integers.
|
||||
fn hash(x: &int) -> uint { ret x as uint; }
|
||||
fn hash(x: int) -> uint { ret x as uint; }
|
||||
|
||||
fn eq_alias(x: &int, y: &int) -> bool { ret x == y; }
|
||||
fn eq_alias(x: int, y: int) -> bool { ret x == y; }
|
||||
|
||||
iter range(lo: int, hi: int) -> int {
|
||||
let lo_: int = lo;
|
||||
|
|
|
|||
|
|
@ -174,7 +174,7 @@ fn stdin() -> reader {
|
|||
ret new_reader(FILE_buf_reader(rustrt::rust_get_stdin(), option::none));
|
||||
}
|
||||
|
||||
fn file_reader(path: &str) -> reader {
|
||||
fn file_reader(path: str) -> reader {
|
||||
let f =
|
||||
str::as_buf(path,
|
||||
{|pathbuf|
|
||||
|
|
@ -218,11 +218,11 @@ obj byte_buf_reader(bbuf: byte_buf) {
|
|||
fn tell() -> uint { ret bbuf.pos; }
|
||||
}
|
||||
|
||||
fn new_byte_buf_reader(buf: &[u8]) -> buf_reader {
|
||||
fn new_byte_buf_reader(buf: [u8]) -> buf_reader {
|
||||
ret byte_buf_reader(@{buf: buf, mutable pos: 0u});
|
||||
}
|
||||
|
||||
fn string_reader(s: &str) -> reader {
|
||||
fn string_reader(s: str) -> reader {
|
||||
ret new_reader(new_byte_buf_reader(str::bytes(s)));
|
||||
}
|
||||
|
||||
|
|
@ -236,13 +236,13 @@ type buf_writer =
|
|||
// FIXME: eventually u64
|
||||
|
||||
obj {
|
||||
fn write(&[u8]);
|
||||
fn write([u8]);
|
||||
fn seek(int, seek_style);
|
||||
fn tell() -> uint;
|
||||
};
|
||||
|
||||
obj FILE_writer(f: os::libc::FILE, res: option::t<@FILE_res>) {
|
||||
fn write(v: &[u8]) {
|
||||
fn write(v: [u8]) {
|
||||
let len = vec::len::<u8>(v);
|
||||
let vbuf = vec::unsafe::to_ptr::<u8>(v);
|
||||
let nout = os::libc::fwrite(vbuf, len, 1u, f);
|
||||
|
|
@ -257,7 +257,7 @@ obj FILE_writer(f: os::libc::FILE, res: option::t<@FILE_res>) {
|
|||
resource fd_res(fd: int) { os::libc::close(fd); }
|
||||
|
||||
obj fd_buf_writer(fd: int, res: option::t<@fd_res>) {
|
||||
fn write(v: &[u8]) {
|
||||
fn write(v: [u8]) {
|
||||
let len = vec::len::<u8>(v);
|
||||
let count = 0u;
|
||||
let vbuf;
|
||||
|
|
@ -282,7 +282,7 @@ obj fd_buf_writer(fd: int, res: option::t<@fd_res>) {
|
|||
}
|
||||
}
|
||||
|
||||
fn file_buf_writer(path: &str, flags: &[fileflag]) -> buf_writer {
|
||||
fn file_buf_writer(path: str, flags: [fileflag]) -> buf_writer {
|
||||
let fflags: int =
|
||||
os::libc_constants::O_WRONLY() | os::libc_constants::O_BINARY();
|
||||
for f: fileflag in flags {
|
||||
|
|
@ -313,12 +313,12 @@ type writer =
|
|||
// function will be provided for general encoded string output
|
||||
obj {
|
||||
fn get_buf_writer() -> buf_writer;
|
||||
fn write_str(&str);
|
||||
fn write_line(&str);
|
||||
fn write_str(str);
|
||||
fn write_line(str);
|
||||
fn write_char(char);
|
||||
fn write_int(int);
|
||||
fn write_uint(uint);
|
||||
fn write_bytes(&[u8]);
|
||||
fn write_bytes([u8]);
|
||||
fn write_le_uint(uint, uint);
|
||||
fn write_le_int(int, uint);
|
||||
fn write_be_uint(uint, uint);
|
||||
|
|
@ -339,8 +339,8 @@ fn uint_to_be_bytes(n: uint, size: uint) -> [u8] {
|
|||
|
||||
obj new_writer(out: buf_writer) {
|
||||
fn get_buf_writer() -> buf_writer { ret out; }
|
||||
fn write_str(s: &str) { out.write(str::bytes(s)); }
|
||||
fn write_line(s: &str) {
|
||||
fn write_str(s: str) { out.write(str::bytes(s)); }
|
||||
fn write_line(s: str) {
|
||||
out.write(str::bytes(s));
|
||||
out.write(str::bytes("\n"));
|
||||
}
|
||||
|
|
@ -351,7 +351,7 @@ obj new_writer(out: buf_writer) {
|
|||
}
|
||||
fn write_int(n: int) { out.write(str::bytes(int::to_str(n, 10u))); }
|
||||
fn write_uint(n: uint) { out.write(str::bytes(uint::to_str(n, 10u))); }
|
||||
fn write_bytes(bytes: &[u8]) { out.write(bytes); }
|
||||
fn write_bytes(bytes: [u8]) { out.write(bytes); }
|
||||
fn write_le_uint(n: uint, size: uint) {
|
||||
out.write(uint_to_le_bytes(n, size));
|
||||
}
|
||||
|
|
@ -363,13 +363,13 @@ obj new_writer(out: buf_writer) {
|
|||
}
|
||||
}
|
||||
|
||||
fn file_writer(path: &str, flags: &[fileflag]) -> writer {
|
||||
fn file_writer(path: str, flags: [fileflag]) -> writer {
|
||||
ret new_writer(file_buf_writer(path, flags));
|
||||
}
|
||||
|
||||
|
||||
// FIXME: fileflags
|
||||
fn buffered_file_buf_writer(path: &str) -> buf_writer {
|
||||
fn buffered_file_buf_writer(path: str) -> buf_writer {
|
||||
let f =
|
||||
str::as_buf(path,
|
||||
{|pathbuf|
|
||||
|
|
@ -396,7 +396,7 @@ type str_writer =
|
|||
type mutable_byte_buf = @{mutable buf: [mutable u8], mutable pos: uint};
|
||||
|
||||
obj byte_buf_writer(buf: mutable_byte_buf) {
|
||||
fn write(v: &[u8]) {
|
||||
fn write(v: [u8]) {
|
||||
// Fast path.
|
||||
|
||||
if buf.pos == vec::len(buf.buf) {
|
||||
|
|
@ -453,11 +453,11 @@ fn seek_in_buf(offset: int, pos: uint, len: uint, whence: seek_style) ->
|
|||
ret bpos as uint;
|
||||
}
|
||||
|
||||
fn read_whole_file_str(file: &str) -> str {
|
||||
fn read_whole_file_str(file: str) -> str {
|
||||
str::unsafe_from_bytes(read_whole_file(file))
|
||||
}
|
||||
|
||||
fn read_whole_file(file: &str) -> [u8] {
|
||||
fn read_whole_file(file: str) -> [u8] {
|
||||
|
||||
// FIXME: There's a lot of copying here
|
||||
file_reader(file).read_whole_stream()
|
||||
|
|
|
|||
|
|
@ -54,7 +54,7 @@ fn exec_suffix() -> str { ret ""; }
|
|||
|
||||
fn target_os() -> str { ret "linux"; }
|
||||
|
||||
fn dylib_filename(base: &str) -> str { ret "lib" + base + ".so"; }
|
||||
fn dylib_filename(base: str) -> str { ret "lib" + base + ".so"; }
|
||||
|
||||
fn pipe() -> {in: int, out: int} {
|
||||
let fds = {mutable in: 0, mutable out: 0};
|
||||
|
|
|
|||
|
|
@ -3,7 +3,7 @@ import option::none;
|
|||
|
||||
tag list<T> { cons(T, @list<T>); nil; }
|
||||
|
||||
fn from_vec<@T>(v: &[T]) -> list<T> {
|
||||
fn from_vec<@T>(v: [T]) -> list<T> {
|
||||
let l = nil::<T>;
|
||||
// FIXME: This would be faster and more space efficient if it looped over
|
||||
// a reverse vector iterator. Unfortunately generic iterators seem not to
|
||||
|
|
@ -13,7 +13,7 @@ fn from_vec<@T>(v: &[T]) -> list<T> {
|
|||
ret l;
|
||||
}
|
||||
|
||||
fn foldl<@T, @U>(ls_: &list<T>, u: &U, f: &block(&T, &U) -> U) -> U {
|
||||
fn foldl<@T, @U>(ls_: list<T>, u: U, f: block(T, U) -> U) -> U {
|
||||
let accum: U = u;
|
||||
let ls = ls_;
|
||||
while true {
|
||||
|
|
@ -25,8 +25,7 @@ fn foldl<@T, @U>(ls_: &list<T>, u: &U, f: &block(&T, &U) -> U) -> U {
|
|||
ret accum;
|
||||
}
|
||||
|
||||
fn find<@T, @U>(ls_: &list<T>, f: &block(&T) -> option::t<U>) ->
|
||||
option::t<U> {
|
||||
fn find<@T, @U>(ls_: list<T>, f: block(T) -> option::t<U>) -> option::t<U> {
|
||||
let ls = ls_;
|
||||
while true {
|
||||
alt ls {
|
||||
|
|
@ -39,7 +38,7 @@ fn find<@T, @U>(ls_: &list<T>, f: &block(&T) -> option::t<U>) ->
|
|||
ret none;
|
||||
}
|
||||
|
||||
fn has<@T>(ls_: &list<T>, elt: &T) -> bool {
|
||||
fn has<@T>(ls_: list<T>, elt: T) -> bool {
|
||||
let ls = ls_;
|
||||
while true {
|
||||
alt ls {
|
||||
|
|
@ -50,20 +49,20 @@ fn has<@T>(ls_: &list<T>, elt: &T) -> bool {
|
|||
ret false;
|
||||
}
|
||||
|
||||
fn length<@T>(ls: &list<T>) -> uint {
|
||||
fn count<T>(_t: &T, u: &uint) -> uint { ret u + 1u; }
|
||||
fn length<@T>(ls: list<T>) -> uint {
|
||||
fn count<T>(_t: T, u: uint) -> uint { ret u + 1u; }
|
||||
ret foldl(ls, 0u, count);
|
||||
}
|
||||
|
||||
fn cdr<@T>(ls: &list<T>) -> list<T> {
|
||||
fn cdr<@T>(ls: list<T>) -> list<T> {
|
||||
alt ls { cons(_, tl) { ret *tl; } nil. { fail "list empty" } }
|
||||
}
|
||||
|
||||
fn car<@T>(ls: &list<T>) -> T {
|
||||
fn car<@T>(ls: list<T>) -> T {
|
||||
alt ls { cons(hd, _) { ret hd; } nil. { fail "list empty" } }
|
||||
}
|
||||
|
||||
fn append<@T>(l: &list<T>, m: &list<T>) -> list<T> {
|
||||
fn append<@T>(l: list<T>, m: list<T>) -> list<T> {
|
||||
alt l {
|
||||
nil. { ret m; }
|
||||
cons(x, xs) { let rest = append(*xs, m); ret cons(x, @rest); }
|
||||
|
|
|
|||
|
|
@ -51,7 +51,7 @@ fn exec_suffix() -> str { ret ""; }
|
|||
|
||||
fn target_os() -> str { ret "macos"; }
|
||||
|
||||
fn dylib_filename(base: &str) -> str { ret "lib" + base + ".dylib"; }
|
||||
fn dylib_filename(base: str) -> str { ret "lib" + base + ".dylib"; }
|
||||
|
||||
fn pipe() -> {in: int, out: int} {
|
||||
let fds = {mutable in: 0, mutable out: 0};
|
||||
|
|
|
|||
|
|
@ -1,27 +1,27 @@
|
|||
/**
|
||||
* Hashmap implementation.
|
||||
*/
|
||||
type hashfn<K> = fn(&K) -> uint;
|
||||
type hashfn<K> = fn(K) -> uint;
|
||||
|
||||
type eqfn<K> = fn(&K, &K) -> bool;
|
||||
type eqfn<K> = fn(K, K) -> bool;
|
||||
|
||||
type hashmap<K, V> =
|
||||
obj {
|
||||
fn size() -> uint;
|
||||
fn insert(&K, &V) -> bool;
|
||||
fn contains_key(&K) -> bool;
|
||||
fn get(&K) -> V;
|
||||
fn find(&K) -> option::t<V>;
|
||||
fn remove(&K) -> option::t<V>;
|
||||
fn insert(K, V) -> bool;
|
||||
fn contains_key(K) -> bool;
|
||||
fn get(K) -> V;
|
||||
fn find(K) -> option::t<V>;
|
||||
fn remove(K) -> option::t<V>;
|
||||
fn rehash();
|
||||
iter items() -> @{key: K, val: V};
|
||||
iter keys() -> K;
|
||||
};
|
||||
type hashset<K> = hashmap<K, ()>;
|
||||
|
||||
fn set_add<@K>(set: hashset<K>, key: &K) -> bool { ret set.insert(key, ()); }
|
||||
fn set_add<@K>(set: hashset<K>, key: K) -> bool { ret set.insert(key, ()); }
|
||||
|
||||
fn mk_hashmap<@K, @V>(hasher: &hashfn<K>, eqer: &eqfn<K>) -> hashmap<K, V> {
|
||||
fn mk_hashmap<@K, @V>(hasher: hashfn<K>, eqer: eqfn<K>) -> hashmap<K, V> {
|
||||
let initial_capacity: uint = 32u; // 2^5
|
||||
|
||||
let load_factor: util::rational = {num: 3, den: 4};
|
||||
|
|
@ -54,9 +54,9 @@ fn mk_hashmap<@K, @V>(hasher: &hashfn<K>, eqer: &eqfn<K>) -> hashmap<K, V> {
|
|||
*/
|
||||
|
||||
fn insert_common<@K,
|
||||
@V>(hasher: &hashfn<K>, eqer: &eqfn<K>,
|
||||
bkts: &[mutable bucket<K, V>], nbkts: uint, key: &K,
|
||||
val: &V) -> bool {
|
||||
@V>(hasher: hashfn<K>, eqer: eqfn<K>,
|
||||
bkts: [mutable bucket<K, V>], nbkts: uint, key: K,
|
||||
val: V) -> bool {
|
||||
let i: uint = 0u;
|
||||
let h: uint = hasher(key);
|
||||
while i < nbkts {
|
||||
|
|
@ -75,8 +75,8 @@ fn mk_hashmap<@K, @V>(hasher: &hashfn<K>, eqer: &eqfn<K>) -> hashmap<K, V> {
|
|||
fail; // full table
|
||||
}
|
||||
fn find_common<@K,
|
||||
@V>(hasher: &hashfn<K>, eqer: &eqfn<K>,
|
||||
bkts: &[mutable bucket<K, V>], nbkts: uint, key: &K) ->
|
||||
@V>(hasher: hashfn<K>, eqer: eqfn<K>,
|
||||
bkts: [mutable bucket<K, V>], nbkts: uint, key: K) ->
|
||||
option::t<V> {
|
||||
let i: uint = 0u;
|
||||
let h: uint = hasher(key);
|
||||
|
|
@ -97,9 +97,9 @@ fn mk_hashmap<@K, @V>(hasher: &hashfn<K>, eqer: &eqfn<K>) -> hashmap<K, V> {
|
|||
ret option::none;
|
||||
}
|
||||
fn rehash<@K,
|
||||
@V>(hasher: &hashfn<K>, eqer: &eqfn<K>,
|
||||
oldbkts: &[mutable bucket<K, V>], _noldbkts: uint,
|
||||
newbkts: &[mutable bucket<K, V>], nnewbkts: uint) {
|
||||
@V>(hasher: hashfn<K>, eqer: eqfn<K>,
|
||||
oldbkts: [mutable bucket<K, V>], _noldbkts: uint,
|
||||
newbkts: [mutable bucket<K, V>], nnewbkts: uint) {
|
||||
for b: bucket<K, V> in oldbkts {
|
||||
alt b {
|
||||
some(k_, v_) {
|
||||
|
|
@ -119,7 +119,7 @@ fn mk_hashmap<@K, @V>(hasher: &hashfn<K>, eqer: &eqfn<K>) -> hashmap<K, V> {
|
|||
mutable nelts: uint,
|
||||
lf: util::rational) {
|
||||
fn size() -> uint { ret nelts; }
|
||||
fn insert(key: &K, val: &V) -> bool {
|
||||
fn insert(key: K, val: V) -> bool {
|
||||
let load: util::rational =
|
||||
{num: nelts + 1u as int, den: nbkts as int};
|
||||
if !util::rational_leq(load, lf) {
|
||||
|
|
@ -135,22 +135,22 @@ fn mk_hashmap<@K, @V>(hasher: &hashfn<K>, eqer: &eqfn<K>) -> hashmap<K, V> {
|
|||
}
|
||||
ret false;
|
||||
}
|
||||
fn contains_key(key: &K) -> bool {
|
||||
fn contains_key(key: K) -> bool {
|
||||
ret alt find_common(hasher, eqer, bkts, nbkts, key) {
|
||||
option::some(_) { true }
|
||||
_ { false }
|
||||
};
|
||||
}
|
||||
fn get(key: &K) -> V {
|
||||
fn get(key: K) -> V {
|
||||
ret alt find_common(hasher, eqer, bkts, nbkts, key) {
|
||||
option::some(val) { val }
|
||||
_ { fail }
|
||||
};
|
||||
}
|
||||
fn find(key: &K) -> option::t<V> {
|
||||
fn find(key: K) -> option::t<V> {
|
||||
be find_common(hasher, eqer, bkts, nbkts, key);
|
||||
}
|
||||
fn remove(key: &K) -> option::t<V> {
|
||||
fn remove(key: K) -> option::t<V> {
|
||||
let i: uint = 0u;
|
||||
let h: uint = hasher(key);
|
||||
while i < nbkts {
|
||||
|
|
@ -199,14 +199,14 @@ fn new_str_hash<@V>() -> hashmap<str, V> {
|
|||
}
|
||||
|
||||
fn new_int_hash<@V>() -> hashmap<int, V> {
|
||||
fn hash_int(x: &int) -> uint { ret x as uint; }
|
||||
fn eq_int(a: &int, b: &int) -> bool { ret a == b; }
|
||||
fn hash_int(x: int) -> uint { ret x as uint; }
|
||||
fn eq_int(a: int, b: int) -> bool { ret a == b; }
|
||||
ret mk_hashmap(hash_int, eq_int);
|
||||
}
|
||||
|
||||
fn new_uint_hash<@V>() -> hashmap<uint, V> {
|
||||
fn hash_uint(x: &uint) -> uint { ret x; }
|
||||
fn eq_uint(a: &uint, b: &uint) -> bool { ret a == b; }
|
||||
fn hash_uint(x: uint) -> uint { ret x; }
|
||||
fn eq_uint(a: uint, b: uint) -> bool { ret a == b; }
|
||||
ret mk_hashmap(hash_uint, eq_uint);
|
||||
}
|
||||
|
||||
|
|
|
|||
|
|
@ -12,8 +12,8 @@ fn format_addr(ip: ip_addr) -> str {
|
|||
}
|
||||
}
|
||||
|
||||
fn parse_addr(ip: &str) -> ip_addr {
|
||||
let parts = vec::map({|&s| uint::from_str(s) }, str::split(ip, "."[0]));
|
||||
fn parse_addr(ip: str) -> ip_addr {
|
||||
let parts = vec::map({|s| uint::from_str(s) }, str::split(ip, "."[0]));
|
||||
if vec::len(parts) != 4u { fail "Too many dots in IP address"; }
|
||||
for i in parts { if i > 255u { fail "Invalid IP Address part."; } }
|
||||
ipv4(parts[0] as u8, parts[1] as u8, parts[2] as u8, parts[3] as u8)
|
||||
|
|
|
|||
|
|
@ -2,30 +2,30 @@
|
|||
|
||||
tag t<@T> { none; some(T); }
|
||||
|
||||
fn get<@T>(opt: &t<T>) -> T {
|
||||
fn get<@T>(opt: t<T>) -> T {
|
||||
alt opt { some(x) { x } none. { fail "option none" } }
|
||||
}
|
||||
|
||||
fn map<@T, @U>(f: &block(&T) -> U, opt: &t<T>) -> t<U> {
|
||||
fn map<@T, @U>(f: block(T) -> U, opt: t<T>) -> t<U> {
|
||||
alt opt { some(x) { some(f(x)) } none. { none } }
|
||||
}
|
||||
|
||||
fn is_none<@T>(opt: &t<T>) -> bool {
|
||||
fn is_none<@T>(opt: t<T>) -> bool {
|
||||
alt opt { none. { true } some(_) { false } }
|
||||
}
|
||||
|
||||
fn is_some<@T>(opt: &t<T>) -> bool { !is_none(opt) }
|
||||
fn is_some<@T>(opt: t<T>) -> bool { !is_none(opt) }
|
||||
|
||||
fn from_maybe<@T>(def: &T, opt: &t<T>) -> T {
|
||||
fn from_maybe<@T>(def: T, opt: t<T>) -> T {
|
||||
alt opt { some(x) { x } none. { def } }
|
||||
}
|
||||
|
||||
fn maybe<@T, @U>(def: &U, f: &block(&T) -> U, opt: &t<T>) -> U {
|
||||
fn maybe<@T, @U>(def: U, f: block(T) -> U, opt: t<T>) -> U {
|
||||
alt opt { none. { def } some(t) { f(t) } }
|
||||
}
|
||||
|
||||
// Can be defined in terms of the above when/if we have const bind.
|
||||
fn may<@T>(f: &block(&T), opt: &t<T>) {
|
||||
fn may<@T>(f: block(T), opt: t<T>) {
|
||||
alt opt { none. {/* nothing */ } some(t) { f(t); } }
|
||||
}
|
||||
|
||||
|
|
|
|||
|
|
@ -1,9 +1,9 @@
|
|||
|
||||
native "rust" mod rustrt {
|
||||
fn rust_list_files(path: &str) -> [str];
|
||||
fn rust_list_files(path: str) -> [str];
|
||||
}
|
||||
|
||||
fn list_dir(path: &str) -> [str] {
|
||||
fn list_dir(path: str) -> [str] {
|
||||
ret rustrt::rust_list_files(path);
|
||||
|
||||
// FIXME: No idea why, but this appears to corrupt memory on OSX. I
|
||||
|
|
@ -30,7 +30,7 @@ fn list_dir(path: &str) -> [str] {
|
|||
|
||||
}
|
||||
|
||||
fn path_is_absolute(p: &str) -> bool { ret str::char_at(p, 0u) == '/'; }
|
||||
fn path_is_absolute(p: str) -> bool { ret str::char_at(p, 0u) == '/'; }
|
||||
|
||||
const path_sep: char = '/';
|
||||
|
||||
|
|
|
|||
|
|
@ -1,11 +1,11 @@
|
|||
// Unsafe pointer utility functions.
|
||||
|
||||
native "rust-intrinsic" mod rusti {
|
||||
fn addr_of<T>(val: &T) -> *mutable T;
|
||||
fn addr_of<T>(val: T) -> *mutable T;
|
||||
fn ptr_offset<T>(ptr: *T, count: uint) -> *T;
|
||||
}
|
||||
|
||||
fn addr_of<T>(val: &T) -> *mutable T { ret rusti::addr_of(val); }
|
||||
fn addr_of<T>(val: T) -> *mutable T { ret rusti::addr_of(val); }
|
||||
fn offset<T>(ptr: *T, count: uint) -> *T {
|
||||
ret rusti::ptr_offset(ptr, count);
|
||||
}
|
||||
|
|
|
|||
|
|
@ -12,19 +12,19 @@ native "rust" mod rustrt {
|
|||
int;
|
||||
}
|
||||
|
||||
fn arg_vec(prog: &str, args: &[@str]) -> [sbuf] {
|
||||
fn arg_vec(prog: str, args: [@str]) -> [sbuf] {
|
||||
let argptrs = str::as_buf(prog, {|buf| [buf] });
|
||||
for arg in args { argptrs += str::as_buf(*arg, {|buf| [buf] }); }
|
||||
argptrs += [unsafe::reinterpret_cast(0)];
|
||||
ret argptrs;
|
||||
}
|
||||
|
||||
fn spawn_process(prog: &str, args: &[str], in_fd: int, out_fd: int,
|
||||
err_fd: int) -> int {
|
||||
fn spawn_process(prog: str, args: [str], in_fd: int, out_fd: int, err_fd: int)
|
||||
-> int {
|
||||
// Note: we have to hold on to these vector references while we hold a
|
||||
// pointer to their buffers
|
||||
let prog = prog;
|
||||
let args = vec::map({|&arg| @arg }, args);
|
||||
let args = vec::map({|arg| @arg }, args);
|
||||
let argv = arg_vec(prog, args);
|
||||
let pid =
|
||||
rustrt::rust_run_program(vec::unsafe::to_ptr(argv), in_fd, out_fd,
|
||||
|
|
@ -32,7 +32,7 @@ fn spawn_process(prog: &str, args: &[str], in_fd: int, out_fd: int,
|
|||
ret pid;
|
||||
}
|
||||
|
||||
fn run_program(prog: &str, args: &[str]) -> int {
|
||||
fn run_program(prog: str, args: [str]) -> int {
|
||||
ret os::waitpid(spawn_process(prog, args, 0, 0, 0));
|
||||
}
|
||||
|
||||
|
|
@ -49,7 +49,7 @@ type program =
|
|||
|
||||
resource program_res(p: program) { p.destroy(); }
|
||||
|
||||
fn start_program(prog: &str, args: &[str]) -> @program_res {
|
||||
fn start_program(prog: str, args: [str]) -> @program_res {
|
||||
let pipe_input = os::pipe();
|
||||
let pipe_output = os::pipe();
|
||||
let pipe_err = os::pipe();
|
||||
|
|
@ -100,7 +100,7 @@ fn start_program(prog: &str, args: &[str]) -> @program_res {
|
|||
os::fd_FILE(pipe_err.in), false));
|
||||
}
|
||||
|
||||
fn read_all(rd: &io::reader) -> str {
|
||||
fn read_all(rd: io::reader) -> str {
|
||||
let buf = "";
|
||||
while !rd.eof() {
|
||||
let bytes = rd.read_bytes(4096u);
|
||||
|
|
@ -109,7 +109,7 @@ fn read_all(rd: &io::reader) -> str {
|
|||
ret buf;
|
||||
}
|
||||
|
||||
fn program_output(prog: &str, args: &[str]) ->
|
||||
fn program_output(prog: str, args: [str]) ->
|
||||
{status: int, out: str, err: str} {
|
||||
let pr = start_program(prog, args);
|
||||
pr.close_input();
|
||||
|
|
|
|||
|
|
@ -15,8 +15,8 @@ type sha1 =
|
|||
// Reset the sha1 state for reuse. This is called
|
||||
// automatically during construction
|
||||
obj {
|
||||
fn input(&[u8]);
|
||||
fn input_str(&str);
|
||||
fn input([u8]);
|
||||
fn input_str(str);
|
||||
fn result() -> [u8];
|
||||
fn result_str() -> str;
|
||||
fn reset();
|
||||
|
|
@ -44,7 +44,7 @@ fn mk_sha1() -> sha1 {
|
|||
mutable computed: bool,
|
||||
work_buf: [mutable u32]};
|
||||
|
||||
fn add_input(st: &sha1state, msg: &[u8]) {
|
||||
fn add_input(st: sha1state, msg: [u8]) {
|
||||
// FIXME: Should be typestate precondition
|
||||
assert (!st.computed);
|
||||
for element: u8 in msg {
|
||||
|
|
@ -62,7 +62,7 @@ fn mk_sha1() -> sha1 {
|
|||
if st.msg_block_idx == msg_block_len { process_msg_block(st); }
|
||||
}
|
||||
}
|
||||
fn process_msg_block(st: &sha1state) {
|
||||
fn process_msg_block(st: sha1state) {
|
||||
// FIXME: Make precondition
|
||||
assert (vec::len(st.h) == digest_buf_len);
|
||||
assert (vec::len(st.work_buf) == work_buf_len);
|
||||
|
|
@ -142,7 +142,7 @@ fn mk_sha1() -> sha1 {
|
|||
fn circular_shift(bits: u32, word: u32) -> u32 {
|
||||
ret word << bits | word >> 32u32 - bits;
|
||||
}
|
||||
fn mk_result(st: &sha1state) -> [u8] {
|
||||
fn mk_result(st: sha1state) -> [u8] {
|
||||
if !st.computed { pad_msg(st); st.computed = true; }
|
||||
let rs: [u8] = [];
|
||||
for hpart: u32 in st.h {
|
||||
|
|
@ -164,7 +164,7 @@ fn mk_sha1() -> sha1 {
|
|||
* call process_msg_block() appropriately. When it returns, it
|
||||
* can be assumed that the message digest has been computed.
|
||||
*/
|
||||
fn pad_msg(st: &sha1state) {
|
||||
fn pad_msg(st: sha1state) {
|
||||
// FIXME: Should be a precondition
|
||||
assert (vec::len(st.msg_block) == msg_block_len);
|
||||
|
||||
|
|
@ -215,8 +215,8 @@ fn mk_sha1() -> sha1 {
|
|||
st.h[4] = 0xC3D2E1F0u32;
|
||||
st.computed = false;
|
||||
}
|
||||
fn input(msg: &[u8]) { add_input(st, msg); }
|
||||
fn input_str(msg: &str) { add_input(st, str::bytes(msg)); }
|
||||
fn input(msg: [u8]) { add_input(st, msg); }
|
||||
fn input_str(msg: str) { add_input(st, str::bytes(msg)); }
|
||||
fn result() -> [u8] { ret mk_result(st); }
|
||||
fn result_str() -> str {
|
||||
let r = mk_result(st);
|
||||
|
|
|
|||
|
|
@ -14,31 +14,31 @@ fn mk<@T>() -> smallintmap<T> {
|
|||
ret @{mutable v: v};
|
||||
}
|
||||
|
||||
fn insert<@T>(m: &smallintmap<T>, key: uint, val: &T) {
|
||||
fn insert<@T>(m: smallintmap<T>, key: uint, val: T) {
|
||||
vec::grow_set::<option::t<T>>(m.v, key, none::<T>, some::<T>(val));
|
||||
}
|
||||
|
||||
fn find<@T>(m: &smallintmap<T>, key: uint) -> option::t<T> {
|
||||
fn find<@T>(m: smallintmap<T>, key: uint) -> option::t<T> {
|
||||
if key < vec::len::<option::t<T>>(m.v) { ret m.v[key]; }
|
||||
ret none::<T>;
|
||||
}
|
||||
|
||||
fn get<@T>(m: &smallintmap<T>, key: uint) -> T {
|
||||
fn get<@T>(m: smallintmap<T>, key: uint) -> T {
|
||||
alt find::<T>(m, key) {
|
||||
none::<T>. { log_err "smallintmap::get(): key not present"; fail; }
|
||||
some::<T>(v) { ret v; }
|
||||
}
|
||||
}
|
||||
|
||||
fn contains_key<@T>(m: &smallintmap<T>, key: uint) -> bool {
|
||||
fn contains_key<@T>(m: smallintmap<T>, key: uint) -> bool {
|
||||
ret !option::is_none(find::<T>(m, key));
|
||||
}
|
||||
|
||||
fn truncate<@T>(m: &smallintmap<T>, len: uint) {
|
||||
fn truncate<@T>(m: smallintmap<T>, len: uint) {
|
||||
m.v = vec::slice_mut::<option::t<T>>(m.v, 0u, len);
|
||||
}
|
||||
|
||||
fn max_key<T>(m: &smallintmap<T>) -> uint {
|
||||
fn max_key<T>(m: smallintmap<T>) -> uint {
|
||||
ret vec::len::<option::t<T>>(m.v);
|
||||
}
|
||||
|
||||
|
|
|
|||
|
|
@ -6,10 +6,10 @@ export merge_sort;
|
|||
export quick_sort;
|
||||
export quick_sort3;
|
||||
|
||||
type lteq<T> = block(&T, &T) -> bool;
|
||||
type lteq<T> = block(T, T) -> bool;
|
||||
|
||||
fn merge_sort<@T>(le: <eq<T>, v: &[T]) -> [T] {
|
||||
fn merge<@T>(le: <eq<T>, a: &[T], b: &[T]) -> [T] {
|
||||
fn merge_sort<@T>(le: lteq<T>, v: [T]) -> [T] {
|
||||
fn merge<@T>(le: lteq<T>, a: [T], b: [T]) -> [T] {
|
||||
let rs: [T] = [];
|
||||
let a_len: uint = len::<T>(a);
|
||||
let a_ix: uint = 0u;
|
||||
|
|
@ -33,14 +33,14 @@ fn merge_sort<@T>(le: <eq<T>, v: &[T]) -> [T] {
|
|||
ret merge::<T>(le, merge_sort::<T>(le, a), merge_sort::<T>(le, b));
|
||||
}
|
||||
|
||||
fn swap<@T>(arr: &[mutable T], x: uint, y: uint) {
|
||||
fn swap<@T>(arr: [mutable T], x: uint, y: uint) {
|
||||
let a = arr[x];
|
||||
arr[x] = arr[y];
|
||||
arr[y] = a;
|
||||
}
|
||||
|
||||
fn part<@T>(compare_func: <eq<T>, arr: &[mutable T], left: uint,
|
||||
right: uint, pivot: uint) -> uint {
|
||||
fn part<@T>(compare_func: lteq<T>, arr: [mutable T], left: uint, right: uint,
|
||||
pivot: uint) -> uint {
|
||||
let pivot_value = arr[pivot];
|
||||
swap::<T>(arr, pivot, right);
|
||||
let storage_index: uint = left;
|
||||
|
|
@ -56,7 +56,7 @@ fn part<@T>(compare_func: <eq<T>, arr: &[mutable T], left: uint,
|
|||
ret storage_index;
|
||||
}
|
||||
|
||||
fn qsort<@T>(compare_func: <eq<T>, arr: &[mutable T], left: uint,
|
||||
fn qsort<@T>(compare_func: lteq<T>, arr: [mutable T], left: uint,
|
||||
right: uint) {
|
||||
if right > left {
|
||||
let pivot = (left + right) / 2u;
|
||||
|
|
@ -69,7 +69,7 @@ fn qsort<@T>(compare_func: <eq<T>, arr: &[mutable T], left: uint,
|
|||
}
|
||||
}
|
||||
|
||||
fn quick_sort<@T>(compare_func: <eq<T>, arr: &[mutable T]) {
|
||||
fn quick_sort<@T>(compare_func: lteq<T>, arr: [mutable T]) {
|
||||
if len::<T>(arr) == 0u { ret; }
|
||||
qsort::<T>(compare_func, arr, 0u, len::<T>(arr) - 1u);
|
||||
}
|
||||
|
|
@ -79,8 +79,8 @@ fn quick_sort<@T>(compare_func: <eq<T>, arr: &[mutable T]) {
|
|||
// http://www.cs.princeton.edu/~rs/talks/QuicksortIsOptimal.pdf
|
||||
// According to these slides this is the algorithm of choice for
|
||||
// 'randomly ordered keys, abstract compare' & 'small number of key values'
|
||||
fn qsort3<@T>(compare_func_lt: <eq<T>, compare_func_eq: <eq<T>,
|
||||
arr: &[mutable T], left: int, right: int) {
|
||||
fn qsort3<@T>(compare_func_lt: lteq<T>, compare_func_eq: lteq<T>,
|
||||
arr: [mutable T], left: int, right: int) {
|
||||
if right <= left { ret; }
|
||||
let v: T = arr[right];
|
||||
let i: int = left - 1;
|
||||
|
|
@ -127,8 +127,8 @@ fn qsort3<@T>(compare_func_lt: <eq<T>, compare_func_eq: <eq<T>,
|
|||
qsort3::<T>(compare_func_lt, compare_func_eq, arr, i, right);
|
||||
}
|
||||
|
||||
fn quick_sort3<@T>(compare_func_lt: <eq<T>, compare_func_eq: <eq<T>,
|
||||
arr: &[mutable T]) {
|
||||
fn quick_sort3<@T>(compare_func_lt: lteq<T>, compare_func_eq: lteq<T>,
|
||||
arr: [mutable T]) {
|
||||
if len::<T>(arr) == 0u { ret; }
|
||||
qsort3::<T>(compare_func_lt, compare_func_eq, arr, 0,
|
||||
(len::<T>(arr) as int) - 1);
|
||||
|
|
|
|||
|
|
@ -10,11 +10,11 @@ native "rust" mod rustrt {
|
|||
fn rust_str_push(s: &mutable str, ch: u8);
|
||||
}
|
||||
|
||||
fn eq(a: &str, b: &str) -> bool { a == b }
|
||||
fn eq(a: str, b: str) -> bool { a == b }
|
||||
|
||||
fn lteq(a: &str, b: &str) -> bool { a <= b }
|
||||
fn lteq(a: str, b: str) -> bool { a <= b }
|
||||
|
||||
fn hash(s: &str) -> uint {
|
||||
fn hash(s: str) -> uint {
|
||||
// djb hash.
|
||||
// FIXME: replace with murmur.
|
||||
|
||||
|
|
@ -37,7 +37,7 @@ const tag_five_b: uint = 248u;
|
|||
const max_five_b: uint = 67108864u;
|
||||
const tag_six_b: uint = 252u;
|
||||
|
||||
fn is_utf8(v: &[u8]) -> bool {
|
||||
fn is_utf8(v: [u8]) -> bool {
|
||||
let i = 0u;
|
||||
let total = vec::len::<u8>(v);
|
||||
while i < total {
|
||||
|
|
@ -54,19 +54,19 @@ fn is_utf8(v: &[u8]) -> bool {
|
|||
ret true;
|
||||
}
|
||||
|
||||
fn is_ascii(s: &str) -> bool {
|
||||
fn is_ascii(s: str) -> bool {
|
||||
let i: uint = byte_len(s);
|
||||
while i > 0u { i -= 1u; if s[i] & 128u8 != 0u8 { ret false; } }
|
||||
ret true;
|
||||
}
|
||||
|
||||
/// Returns true if the string has length 0
|
||||
pure fn is_empty(s: &str) -> bool { for c: u8 in s { ret false; } ret true; }
|
||||
pure fn is_empty(s: str) -> bool { for c: u8 in s { ret false; } ret true; }
|
||||
|
||||
/// Returns true if the string has length greater than 0
|
||||
pure fn is_not_empty(s: &str) -> bool { !is_empty(s) }
|
||||
pure fn is_not_empty(s: str) -> bool { !is_empty(s) }
|
||||
|
||||
fn is_whitespace(s: &str) -> bool {
|
||||
fn is_whitespace(s: str) -> bool {
|
||||
let i = 0u;
|
||||
let len = char_len(s);
|
||||
while i < len {
|
||||
|
|
@ -76,7 +76,7 @@ fn is_whitespace(s: &str) -> bool {
|
|||
ret true;
|
||||
}
|
||||
|
||||
fn byte_len(s: &str) -> uint {
|
||||
fn byte_len(s: str) -> uint {
|
||||
let v: [u8] = unsafe::reinterpret_cast(s);
|
||||
let vlen = vec::len(v);
|
||||
unsafe::leak(v);
|
||||
|
|
@ -85,14 +85,14 @@ fn byte_len(s: &str) -> uint {
|
|||
ret vlen - 1u;
|
||||
}
|
||||
|
||||
fn bytes(s: &str) -> [u8] {
|
||||
fn bytes(s: str) -> [u8] {
|
||||
let v = unsafe::reinterpret_cast(s);
|
||||
let vcopy = vec::slice(v, 0u, vec::len(v) - 1u);
|
||||
unsafe::leak(v);
|
||||
ret vcopy;
|
||||
}
|
||||
|
||||
fn unsafe_from_bytes(v: &[mutable? u8]) -> str {
|
||||
fn unsafe_from_bytes(v: [mutable? u8]) -> str {
|
||||
let vcopy: [u8] = v + [0u8];
|
||||
let scopy: str = unsafe::reinterpret_cast(vcopy);
|
||||
unsafe::leak(vcopy);
|
||||
|
|
@ -136,7 +136,7 @@ fn from_char(ch: char) -> str {
|
|||
ret buf;
|
||||
}
|
||||
|
||||
fn from_chars(chs: &[char]) -> str {
|
||||
fn from_chars(chs: [char]) -> str {
|
||||
let buf = "";
|
||||
for ch: char in chs { push_utf8_bytes(buf, ch); }
|
||||
ret buf;
|
||||
|
|
@ -156,7 +156,7 @@ fn utf8_char_width(b: u8) -> uint {
|
|||
ret 6u;
|
||||
}
|
||||
|
||||
fn char_range_at(s: &str, i: uint) -> {ch: char, next: uint} {
|
||||
fn char_range_at(s: str, i: uint) -> {ch: char, next: uint} {
|
||||
let b0 = s[i];
|
||||
let w = utf8_char_width(b0);
|
||||
assert (w != 0u);
|
||||
|
|
@ -178,9 +178,9 @@ fn char_range_at(s: &str, i: uint) -> {ch: char, next: uint} {
|
|||
ret {ch: val as char, next: i};
|
||||
}
|
||||
|
||||
fn char_at(s: &str, i: uint) -> char { ret char_range_at(s, i).ch; }
|
||||
fn char_at(s: str, i: uint) -> char { ret char_range_at(s, i).ch; }
|
||||
|
||||
fn char_len(s: &str) -> uint {
|
||||
fn char_len(s: str) -> uint {
|
||||
let i = 0u;
|
||||
let len = 0u;
|
||||
let total = byte_len(s);
|
||||
|
|
@ -194,7 +194,7 @@ fn char_len(s: &str) -> uint {
|
|||
ret len;
|
||||
}
|
||||
|
||||
fn to_chars(s: &str) -> [char] {
|
||||
fn to_chars(s: str) -> [char] {
|
||||
let buf: [char] = [];
|
||||
let i = 0u;
|
||||
let len = byte_len(s);
|
||||
|
|
@ -225,23 +225,23 @@ fn shift_char(s: &mutable str) -> char {
|
|||
|
||||
fn unshift_char(s: &mutable str, ch: char) { s = from_char(ch) + s; }
|
||||
|
||||
fn index(s: &str, c: u8) -> int {
|
||||
fn index(s: str, c: u8) -> int {
|
||||
let i: int = 0;
|
||||
for k: u8 in s { if k == c { ret i; } i += 1; }
|
||||
ret -1;
|
||||
}
|
||||
|
||||
fn rindex(s: &str, c: u8) -> int {
|
||||
fn rindex(s: str, c: u8) -> int {
|
||||
let n: int = byte_len(s) as int;
|
||||
while n >= 0 { if s[n] == c { ret n; } n -= 1; }
|
||||
ret n;
|
||||
}
|
||||
|
||||
fn find(haystack: &str, needle: &str) -> int {
|
||||
fn find(haystack: str, needle: str) -> int {
|
||||
let haystack_len: int = byte_len(haystack) as int;
|
||||
let needle_len: int = byte_len(needle) as int;
|
||||
if needle_len == 0 { ret 0; }
|
||||
fn match_at(haystack: &str, needle: &str, i: int) -> bool {
|
||||
fn match_at(haystack: str, needle: str, i: int) -> bool {
|
||||
let j: int = i;
|
||||
for c: u8 in needle { if haystack[j] != c { ret false; } j += 1; }
|
||||
ret true;
|
||||
|
|
@ -254,7 +254,7 @@ fn find(haystack: &str, needle: &str) -> int {
|
|||
ret -1;
|
||||
}
|
||||
|
||||
fn starts_with(haystack: &str, needle: &str) -> bool {
|
||||
fn starts_with(haystack: str, needle: str) -> bool {
|
||||
let haystack_len: uint = byte_len(haystack);
|
||||
let needle_len: uint = byte_len(needle);
|
||||
if needle_len == 0u { ret true; }
|
||||
|
|
@ -262,7 +262,7 @@ fn starts_with(haystack: &str, needle: &str) -> bool {
|
|||
ret eq(substr(haystack, 0u, needle_len), needle);
|
||||
}
|
||||
|
||||
fn ends_with(haystack: &str, needle: &str) -> bool {
|
||||
fn ends_with(haystack: str, needle: str) -> bool {
|
||||
let haystack_len: uint = byte_len(haystack);
|
||||
let needle_len: uint = byte_len(needle);
|
||||
ret if needle_len == 0u {
|
||||
|
|
@ -275,11 +275,11 @@ fn ends_with(haystack: &str, needle: &str) -> bool {
|
|||
};
|
||||
}
|
||||
|
||||
fn substr(s: &str, begin: uint, len: uint) -> str {
|
||||
fn substr(s: str, begin: uint, len: uint) -> str {
|
||||
ret slice(s, begin, begin + len);
|
||||
}
|
||||
|
||||
fn slice(s: &str, begin: uint, end: uint) -> str {
|
||||
fn slice(s: str, begin: uint, end: uint) -> str {
|
||||
// FIXME: Typestate precondition
|
||||
assert (begin <= end);
|
||||
assert (end <= byte_len(s));
|
||||
|
|
@ -293,7 +293,7 @@ fn slice(s: &str, begin: uint, end: uint) -> str {
|
|||
ret s2;
|
||||
}
|
||||
|
||||
fn safe_slice(s: &str, begin: uint, end: uint) : uint::le(begin, end) -> str {
|
||||
fn safe_slice(s: str, begin: uint, end: uint) : uint::le(begin, end) -> str {
|
||||
// would need some magic to make this a precondition
|
||||
assert (end <= byte_len(s));
|
||||
ret slice(s, begin, end);
|
||||
|
|
@ -317,11 +317,11 @@ fn pop_byte(s: &mutable str) -> u8 {
|
|||
|
||||
fn push_byte(s: &mutable str, b: u8) { rustrt::rust_str_push(s, b); }
|
||||
|
||||
fn push_bytes(s: &mutable str, bytes: &[u8]) {
|
||||
fn push_bytes(s: &mutable str, bytes: [u8]) {
|
||||
for byte in bytes { rustrt::rust_str_push(s, byte); }
|
||||
}
|
||||
|
||||
fn split(s: &str, sep: u8) -> [str] {
|
||||
fn split(s: str, sep: u8) -> [str] {
|
||||
let v: [str] = [];
|
||||
let accum: str = "";
|
||||
let ends_with_sep: bool = false;
|
||||
|
|
@ -336,13 +336,13 @@ fn split(s: &str, sep: u8) -> [str] {
|
|||
ret v;
|
||||
}
|
||||
|
||||
fn concat(v: &[str]) -> str {
|
||||
fn concat(v: [str]) -> str {
|
||||
let s: str = "";
|
||||
for ss: str in v { s += ss; }
|
||||
ret s;
|
||||
}
|
||||
|
||||
fn connect(v: &[str], sep: &str) -> str {
|
||||
fn connect(v: [str], sep: str) -> str {
|
||||
let s: str = "";
|
||||
let first: bool = true;
|
||||
for ss: str in v {
|
||||
|
|
@ -353,7 +353,7 @@ fn connect(v: &[str], sep: &str) -> str {
|
|||
}
|
||||
|
||||
// FIXME: This only handles ASCII
|
||||
fn to_upper(s: &str) -> str {
|
||||
fn to_upper(s: str) -> str {
|
||||
let outstr = "";
|
||||
let ascii_a = 'a' as u8;
|
||||
let ascii_z = 'z' as u8;
|
||||
|
|
@ -369,7 +369,7 @@ fn to_upper(s: &str) -> str {
|
|||
}
|
||||
|
||||
// FIXME: This is super-inefficient
|
||||
fn replace(s: &str, from: &str, to: &str) : is_not_empty(from) -> str {
|
||||
fn replace(s: str, from: str, to: str) : is_not_empty(from) -> str {
|
||||
// FIXME (694): Shouldn't have to check this
|
||||
check (is_not_empty(from));
|
||||
if byte_len(s) == 0u {
|
||||
|
|
@ -383,12 +383,12 @@ fn replace(s: &str, from: &str, to: &str) : is_not_empty(from) -> str {
|
|||
}
|
||||
|
||||
// FIXME: Also not efficient
|
||||
fn char_slice(s: &str, begin: uint, end: uint) -> str {
|
||||
fn char_slice(s: str, begin: uint, end: uint) -> str {
|
||||
from_chars(vec::slice(to_chars(s), begin, end))
|
||||
}
|
||||
|
||||
fn trim_left(s: &str) -> str {
|
||||
fn count_whities(s: &[char]) -> uint {
|
||||
fn trim_left(s: str) -> str {
|
||||
fn count_whities(s: [char]) -> uint {
|
||||
let i = 0u;
|
||||
while i < vec::len(s) {
|
||||
if !char::is_whitespace(s[i]) { break; }
|
||||
|
|
@ -401,8 +401,8 @@ fn trim_left(s: &str) -> str {
|
|||
ret from_chars(vec::slice(chars, whities, vec::len(chars)));
|
||||
}
|
||||
|
||||
fn trim_right(s: &str) -> str {
|
||||
fn count_whities(s: &[char]) -> uint {
|
||||
fn trim_right(s: str) -> str {
|
||||
fn count_whities(s: [char]) -> uint {
|
||||
let i = vec::len(s);
|
||||
while 0u < i {
|
||||
if !char::is_whitespace(s[i - 1u]) { break; }
|
||||
|
|
@ -415,18 +415,18 @@ fn trim_right(s: &str) -> str {
|
|||
ret from_chars(vec::slice(chars, 0u, whities));
|
||||
}
|
||||
|
||||
fn trim(s: &str) -> str { trim_left(trim_right(s)) }
|
||||
fn trim(s: str) -> str { trim_left(trim_right(s)) }
|
||||
|
||||
type sbuf = *u8;
|
||||
|
||||
fn buf(s: &str) -> sbuf {
|
||||
fn buf(s: str) -> sbuf {
|
||||
let saddr = ptr::addr_of(s);
|
||||
let vaddr: *[u8] = unsafe::reinterpret_cast(saddr);
|
||||
let buf = vec::to_ptr(*vaddr);
|
||||
ret buf;
|
||||
}
|
||||
|
||||
fn as_buf<T>(s: &str, f: &block(sbuf) -> T) -> T { let buf = buf(s); f(buf) }
|
||||
fn as_buf<T>(s: str, f: block(sbuf) -> T) -> T { let buf = buf(s); f(buf) }
|
||||
|
||||
fn str_from_cstr(cstr: sbuf) -> str {
|
||||
let res = "";
|
||||
|
|
|
|||
|
|
@ -124,8 +124,8 @@ fn spawn_inner(thunk: -fn(), notify: option<comm::chan<task_notification>>) ->
|
|||
let ptrsize = sys::size_of::<*u8>();
|
||||
let thunkfn: *mutable uint = cast(sp - ptrsize * 2u);
|
||||
let thunkenv: *mutable uint = cast(sp - ptrsize);
|
||||
*thunkfn = cast(raw_thunk.code);
|
||||
*thunkenv = cast(raw_thunk.env);
|
||||
*thunkfn = cast(raw_thunk.code);;
|
||||
*thunkenv = cast(raw_thunk.env);;
|
||||
// align the stack to 16 bytes
|
||||
(**task_ptr).stack_ptr = cast(sp - ptrsize * 4u);
|
||||
|
||||
|
|
@ -136,7 +136,7 @@ fn spawn_inner(thunk: -fn(), notify: option<comm::chan<task_notification>>) ->
|
|||
(**task_ptr).notify_chan = c;
|
||||
}
|
||||
none { }
|
||||
};
|
||||
}
|
||||
|
||||
// give the thunk environment's allocation to the new task
|
||||
rustrt::migrate_alloc(cast(raw_thunk.env), id);
|
||||
|
|
|
|||
|
|
@ -49,7 +49,7 @@ type test_desc = {name: test_name, fn: test_fn, ignore: bool};
|
|||
|
||||
// The default console test runner. It accepts the command line
|
||||
// arguments and a vector of test_descs (generated at compile time).
|
||||
fn test_main(args: &[str], tests: &[test_desc]) {
|
||||
fn test_main(args: [str], tests: [test_desc]) {
|
||||
check (vec::is_not_empty(args));
|
||||
let opts =
|
||||
alt parse_opts(args) {
|
||||
|
|
@ -64,7 +64,7 @@ type test_opts = {filter: option::t<str>, run_ignored: bool};
|
|||
type opt_res = either::t<test_opts, str>;
|
||||
|
||||
// Parses command line arguments into test options
|
||||
fn parse_opts(args: &[str]) : vec::is_not_empty(args) -> opt_res {
|
||||
fn parse_opts(args: [str]) : vec::is_not_empty(args) -> opt_res {
|
||||
|
||||
let args_ = vec::tail(args);
|
||||
let opts = [getopts::optflag("ignored")];
|
||||
|
|
@ -94,15 +94,15 @@ type joinable = (task, comm::port<task::task_notification>);
|
|||
// In cases where test functions and closures it is not ok to just dump them
|
||||
// into a task and run them, so this transformation gives the caller a chance
|
||||
// to create the test task.
|
||||
type test_to_task = fn(&fn()) -> joinable;
|
||||
type test_to_task = fn(fn()) -> joinable;
|
||||
|
||||
// A simple console test runner
|
||||
fn run_tests_console(opts: &test_opts, tests: &[test_desc]) -> bool {
|
||||
fn run_tests_console(opts: test_opts, tests: [test_desc]) -> bool {
|
||||
run_tests_console_(opts, tests, default_test_to_task)
|
||||
}
|
||||
|
||||
fn run_tests_console_(opts: &test_opts, tests: &[test_desc],
|
||||
to_task: &test_to_task) -> bool {
|
||||
fn run_tests_console_(opts: test_opts, tests: [test_desc],
|
||||
to_task: test_to_task) -> bool {
|
||||
|
||||
type test_state =
|
||||
@{out: io::writer,
|
||||
|
|
@ -175,20 +175,19 @@ fn run_tests_console_(opts: &test_opts, tests: &[test_desc],
|
|||
|
||||
ret success;
|
||||
|
||||
fn write_ok(out: &io::writer, use_color: bool) {
|
||||
fn write_ok(out: io::writer, use_color: bool) {
|
||||
write_pretty(out, "ok", term::color_green, use_color);
|
||||
}
|
||||
|
||||
fn write_failed(out: &io::writer, use_color: bool) {
|
||||
fn write_failed(out: io::writer, use_color: bool) {
|
||||
write_pretty(out, "FAILED", term::color_red, use_color);
|
||||
}
|
||||
|
||||
fn write_ignored(out: &io::writer, use_color: bool) {
|
||||
fn write_ignored(out: io::writer, use_color: bool) {
|
||||
write_pretty(out, "ignored", term::color_yellow, use_color);
|
||||
}
|
||||
|
||||
fn write_pretty(out: &io::writer, word: &str, color: u8,
|
||||
use_color: bool) {
|
||||
fn write_pretty(out: io::writer, word: str, color: u8, use_color: bool) {
|
||||
if use_color && term::color_supported() {
|
||||
term::fg(out.get_buf_writer(), color);
|
||||
}
|
||||
|
|
@ -207,7 +206,7 @@ tag testevent {
|
|||
te_result(test_desc, test_result);
|
||||
}
|
||||
|
||||
fn run_tests(opts: &test_opts, tests: &[test_desc], to_task: &test_to_task,
|
||||
fn run_tests(opts: test_opts, tests: [test_desc], to_task: test_to_task,
|
||||
callback: fn(testevent)) {
|
||||
|
||||
let filtered_tests = filter_tests(opts, tests);
|
||||
|
|
@ -241,7 +240,7 @@ fn run_tests(opts: &test_opts, tests: &[test_desc], to_task: &test_to_task,
|
|||
|
||||
fn get_concurrency() -> uint { rustrt::sched_threads() }
|
||||
|
||||
fn filter_tests(opts: &test_opts, tests: &[test_desc]) -> [test_desc] {
|
||||
fn filter_tests(opts: test_opts, tests: [test_desc]) -> [test_desc] {
|
||||
let filtered = tests;
|
||||
|
||||
// Remove tests that don't match the test filter
|
||||
|
|
@ -256,7 +255,7 @@ fn filter_tests(opts: &test_opts, tests: &[test_desc]) -> [test_desc] {
|
|||
};
|
||||
|
||||
let filter =
|
||||
bind fn (test: &test_desc, filter_str: &str) ->
|
||||
bind fn (test: test_desc, filter_str: str) ->
|
||||
option::t<test_desc> {
|
||||
if str::find(test.name, filter_str) >= 0 {
|
||||
ret option::some(test);
|
||||
|
|
@ -273,7 +272,7 @@ fn filter_tests(opts: &test_opts, tests: &[test_desc]) -> [test_desc] {
|
|||
filtered
|
||||
} else {
|
||||
let filter =
|
||||
fn (test: &test_desc) -> option::t<test_desc> {
|
||||
fn (test: test_desc) -> option::t<test_desc> {
|
||||
if test.ignore {
|
||||
ret option::some({name: test.name,
|
||||
fn: test.fn,
|
||||
|
|
@ -288,7 +287,7 @@ fn filter_tests(opts: &test_opts, tests: &[test_desc]) -> [test_desc] {
|
|||
// Sort the tests alphabetically
|
||||
filtered =
|
||||
{
|
||||
fn lteq(t1: &test_desc, t2: &test_desc) -> bool {
|
||||
fn lteq(t1: test_desc, t2: test_desc) -> bool {
|
||||
str::lteq(t1.name, t2.name)
|
||||
}
|
||||
sort::merge_sort(lteq, filtered)
|
||||
|
|
@ -299,7 +298,7 @@ fn filter_tests(opts: &test_opts, tests: &[test_desc]) -> [test_desc] {
|
|||
|
||||
type test_future = {test: test_desc, wait: fn() -> test_result};
|
||||
|
||||
fn run_test(test: &test_desc, to_task: &test_to_task) -> test_future {
|
||||
fn run_test(test: test_desc, to_task: test_to_task) -> test_future {
|
||||
if !test.ignore {
|
||||
let test_task = to_task(test.fn);
|
||||
ret {test: test,
|
||||
|
|
@ -315,7 +314,7 @@ fn run_test(test: &test_desc, to_task: &test_to_task) -> test_future {
|
|||
|
||||
// We need to run our tests in another task in order to trap test failures.
|
||||
// This function only works with functions that don't contain closures.
|
||||
fn default_test_to_task(f: &fn()) -> joinable {
|
||||
fn default_test_to_task(f: fn()) -> joinable {
|
||||
fn run_task(f: fn()) { configure_test_task(); f(); }
|
||||
ret task::spawn_joinable(bind run_task(f));
|
||||
}
|
||||
|
|
|
|||
|
|
@ -23,7 +23,7 @@ type treemap<@K, @V> = @mutable tree_node<K, V>;
|
|||
|
||||
fn init<@K, @V>() -> treemap<K, V> { @mutable empty }
|
||||
|
||||
fn insert<@K, @V>(m: &treemap<K, V>, k: &K, v: &V) {
|
||||
fn insert<@K, @V>(m: treemap<K, V>, k: K, v: V) {
|
||||
alt m {
|
||||
@empty. { *m = node(@k, @v, @mutable empty, @mutable empty); }
|
||||
@node(@kk, _, _, _) {
|
||||
|
|
@ -37,13 +37,14 @@ fn insert<@K, @V>(m: &treemap<K, V>, k: &K, v: &V) {
|
|||
}
|
||||
}
|
||||
|
||||
fn find<@K, @V>(m: &treemap<K, V>, k: &K) -> option<V> {
|
||||
fn find<@K, @V>(m: treemap<K, V>, k: K) -> option<V> {
|
||||
alt *m {
|
||||
empty. { none }
|
||||
node(@kk, @v, _, _) {
|
||||
if k == kk {
|
||||
some(v)
|
||||
} else if k < kk {
|
||||
|
||||
// Again, ugliness to unpack left and right individually.
|
||||
alt *m { node(_, _, left, _) { find(left, k) } }
|
||||
} else { alt *m { node(_, _, _, right) { find(right, k) } } }
|
||||
|
|
@ -52,7 +53,7 @@ fn find<@K, @V>(m: &treemap<K, V>, k: &K) -> option<V> {
|
|||
}
|
||||
|
||||
// Performs an in-order traversal
|
||||
fn traverse<@K, @V>(m: &treemap<K, V>, f: fn(&K, &V)) {
|
||||
fn traverse<@K, @V>(m: treemap<K, V>, f: fn(K, V)) {
|
||||
alt *m {
|
||||
empty. { }
|
||||
node(k, v, _, _) {
|
||||
|
|
|
|||
|
|
@ -12,7 +12,7 @@ type ufind = {mutable nodes: [mutable node]};
|
|||
|
||||
fn make() -> ufind { ret {mutable nodes: [mutable]}; }
|
||||
|
||||
fn make_set(ufnd: &ufind) -> uint {
|
||||
fn make_set(ufnd: ufind) -> uint {
|
||||
let idx = vec::len(ufnd.nodes);
|
||||
ufnd.nodes += [mutable none::<uint>];
|
||||
ret idx;
|
||||
|
|
@ -21,18 +21,18 @@ fn make_set(ufnd: &ufind) -> uint {
|
|||
|
||||
/// Creates sets as necessary to ensure that least `n` sets are present in the
|
||||
/// data structure.
|
||||
fn grow(ufnd: &ufind, n: uint) {
|
||||
fn grow(ufnd: ufind, n: uint) {
|
||||
while set_count(ufnd) < n { make_set(ufnd); }
|
||||
}
|
||||
|
||||
fn find(ufnd: &ufind, n: uint) -> uint {
|
||||
fn find(ufnd: ufind, n: uint) -> uint {
|
||||
alt ufnd.nodes[n] {
|
||||
none. { ret n; }
|
||||
some(m) { let m_ = m; be find(ufnd, m_); }
|
||||
}
|
||||
}
|
||||
|
||||
fn union(ufnd: &ufind, m: uint, n: uint) {
|
||||
fn union(ufnd: ufind, m: uint, n: uint) {
|
||||
let m_root = find(ufnd, m);
|
||||
let n_root = find(ufnd, n);
|
||||
if m_root < n_root {
|
||||
|
|
@ -40,11 +40,11 @@ fn union(ufnd: &ufind, m: uint, n: uint) {
|
|||
} else if m_root > n_root { ufnd.nodes[m_root] = some::<uint>(n_root); }
|
||||
}
|
||||
|
||||
fn set_count(ufnd: &ufind) -> uint { ret vec::len::<node>(ufnd.nodes); }
|
||||
fn set_count(ufnd: ufind) -> uint { ret vec::len::<node>(ufnd.nodes); }
|
||||
|
||||
|
||||
// Removes all sets with IDs greater than or equal to the given value.
|
||||
fn prune(ufnd: &ufind, n: uint) {
|
||||
fn prune(ufnd: ufind, n: uint) {
|
||||
// TODO: Use "slice" once we get rid of "mutable?"
|
||||
|
||||
let len = vec::len::<node>(ufnd.nodes);
|
||||
|
|
|
|||
|
|
@ -39,7 +39,7 @@ fn next_power_of_two(n: uint) -> uint {
|
|||
ret tmp + 1u;
|
||||
}
|
||||
|
||||
fn parse_buf(buf: &[u8], radix: uint) -> uint {
|
||||
fn parse_buf(buf: [u8], radix: uint) -> uint {
|
||||
if vec::len::<u8>(buf) == 0u {
|
||||
log_err "parse_buf(): buf is empty";
|
||||
fail;
|
||||
|
|
@ -56,7 +56,7 @@ fn parse_buf(buf: &[u8], radix: uint) -> uint {
|
|||
fail;
|
||||
}
|
||||
|
||||
fn from_str(s: &str) -> uint { parse_buf(str::bytes(s), 10u) }
|
||||
fn from_str(s: str) -> uint { parse_buf(str::bytes(s), 10u) }
|
||||
|
||||
fn to_str(num: uint, radix: uint) -> str {
|
||||
let n = num;
|
||||
|
|
|
|||
|
|
@ -1,7 +1,7 @@
|
|||
// Unsafe operations.
|
||||
|
||||
native "rust-intrinsic" mod rusti {
|
||||
fn cast<T, U>(src: &T) -> U;
|
||||
fn cast<T, U>(src: T) -> U;
|
||||
}
|
||||
|
||||
native "rust" mod rustrt {
|
||||
|
|
@ -9,6 +9,6 @@ native "rust" mod rustrt {
|
|||
}
|
||||
|
||||
// Casts the value at `src` to U. The two types must have the same length.
|
||||
fn reinterpret_cast<T, @U>(src: &T) -> U { ret rusti::cast(src); }
|
||||
fn reinterpret_cast<T, @U>(src: T) -> U { ret rusti::cast(src); }
|
||||
|
||||
fn leak<@T>(thing: -T) { rustrt::leak(thing); }
|
||||
|
|
|
|||
|
|
@ -1,6 +1,6 @@
|
|||
|
||||
|
||||
fn id<@T>(x: &T) -> T { ret x; }
|
||||
fn id<@T>(x: T) -> T { ret x; }
|
||||
|
||||
|
||||
/* FIXME (issue #141): See test/run-pass/constrained-type.rs. Uncomment
|
||||
|
|
@ -9,13 +9,13 @@ type rational = {num: int, den: int};
|
|||
|
||||
|
||||
// : int::positive(*.den);
|
||||
fn rational_leq(x: &rational, y: &rational) -> bool {
|
||||
fn rational_leq(x: rational, y: rational) -> bool {
|
||||
// NB: Uses the fact that rationals have positive denominators WLOG:
|
||||
|
||||
ret x.num * y.den <= y.num * x.den;
|
||||
}
|
||||
|
||||
fn orb(a: &bool, b: &bool) -> bool { ret a || b; }
|
||||
fn orb(a: bool, b: bool) -> bool { ret a || b; }
|
||||
// Local Variables:
|
||||
// mode: rust;
|
||||
// fill-column: 78;
|
||||
|
|
|
|||
|
|
@ -6,7 +6,7 @@ import uint::next_power_of_two;
|
|||
import ptr::addr_of;
|
||||
|
||||
native "rust-intrinsic" mod rusti {
|
||||
fn vec_len<T>(v: &[T]) -> uint;
|
||||
fn vec_len<T>(v: [T]) -> uint;
|
||||
}
|
||||
|
||||
native "rust" mod rustrt {
|
||||
|
|
@ -19,11 +19,11 @@ fn reserve<@T>(v: &mutable [mutable? T], n: uint) {
|
|||
rustrt::vec_reserve_shared(v, n);
|
||||
}
|
||||
|
||||
fn len<T>(v: &[mutable? T]) -> uint { ret rusti::vec_len(v); }
|
||||
fn len<T>(v: [mutable? T]) -> uint { ret rusti::vec_len(v); }
|
||||
|
||||
type init_op<T> = fn(uint) -> T;
|
||||
|
||||
fn init_fn<@T>(op: &init_op<T>, n_elts: uint) -> [T] {
|
||||
fn init_fn<@T>(op: init_op<T>, n_elts: uint) -> [T] {
|
||||
let v = [];
|
||||
reserve(v, n_elts);
|
||||
let i: uint = 0u;
|
||||
|
|
@ -32,7 +32,7 @@ fn init_fn<@T>(op: &init_op<T>, n_elts: uint) -> [T] {
|
|||
}
|
||||
|
||||
// TODO: Remove me once we have slots.
|
||||
fn init_fn_mut<@T>(op: &init_op<T>, n_elts: uint) -> [mutable T] {
|
||||
fn init_fn_mut<@T>(op: init_op<T>, n_elts: uint) -> [mutable T] {
|
||||
let v = [mutable];
|
||||
reserve(v, n_elts);
|
||||
let i: uint = 0u;
|
||||
|
|
@ -40,7 +40,7 @@ fn init_fn_mut<@T>(op: &init_op<T>, n_elts: uint) -> [mutable T] {
|
|||
ret v;
|
||||
}
|
||||
|
||||
fn init_elt<@T>(t: &T, n_elts: uint) -> [T] {
|
||||
fn init_elt<@T>(t: T, n_elts: uint) -> [T] {
|
||||
let v = [];
|
||||
reserve(v, n_elts);
|
||||
let i: uint = 0u;
|
||||
|
|
@ -49,7 +49,7 @@ fn init_elt<@T>(t: &T, n_elts: uint) -> [T] {
|
|||
}
|
||||
|
||||
// TODO: Remove me once we have slots.
|
||||
fn init_elt_mut<@T>(t: &T, n_elts: uint) -> [mutable T] {
|
||||
fn init_elt_mut<@T>(t: T, n_elts: uint) -> [mutable T] {
|
||||
let v = [mutable];
|
||||
reserve(v, n_elts);
|
||||
let i: uint = 0u;
|
||||
|
|
@ -59,51 +59,51 @@ fn init_elt_mut<@T>(t: &T, n_elts: uint) -> [mutable T] {
|
|||
|
||||
// FIXME: Possible typestate postcondition:
|
||||
// len(result) == len(v) (needs issue #586)
|
||||
fn to_mut<@T>(v: &[T]) -> [mutable T] {
|
||||
fn to_mut<@T>(v: [T]) -> [mutable T] {
|
||||
let vres = [mutable];
|
||||
for t: T in v { vres += [mutable t]; }
|
||||
ret vres;
|
||||
}
|
||||
|
||||
// Same comment as from_mut
|
||||
fn from_mut<@T>(v: &[mutable T]) -> [T] {
|
||||
fn from_mut<@T>(v: [mutable T]) -> [T] {
|
||||
let vres = [];
|
||||
for t: T in v { vres += [t]; }
|
||||
ret vres;
|
||||
}
|
||||
|
||||
// Predicates
|
||||
pure fn is_empty<T>(v: &[mutable? T]) -> bool {
|
||||
pure fn is_empty<T>(v: [mutable? T]) -> bool {
|
||||
// FIXME: This would be easier if we could just call len
|
||||
for t: T in v { ret false; }
|
||||
ret true;
|
||||
}
|
||||
|
||||
pure fn is_not_empty<T>(v: &[mutable? T]) -> bool { ret !is_empty(v); }
|
||||
pure fn is_not_empty<T>(v: [mutable? T]) -> bool { ret !is_empty(v); }
|
||||
|
||||
// Accessors
|
||||
|
||||
/// Returns the first element of a vector
|
||||
fn head<@T>(v: &[mutable? T]) : is_not_empty(v) -> T { ret v[0]; }
|
||||
fn head<@T>(v: [mutable? T]) : is_not_empty(v) -> T { ret v[0]; }
|
||||
|
||||
/// Returns all but the first element of a vector
|
||||
fn tail<@T>(v: &[mutable? T]) : is_not_empty(v) -> [mutable? T] {
|
||||
fn tail<@T>(v: [mutable? T]) : is_not_empty(v) -> [mutable? T] {
|
||||
ret slice(v, 1u, len(v));
|
||||
}
|
||||
|
||||
/// Returns the last element of `v`.
|
||||
fn last<@T>(v: &[mutable? T]) -> option::t<T> {
|
||||
fn last<@T>(v: [mutable? T]) -> option::t<T> {
|
||||
if len(v) == 0u { ret none; }
|
||||
ret some(v[len(v) - 1u]);
|
||||
}
|
||||
|
||||
/// Returns the last element of a non-empty vector `v`.
|
||||
fn last_total<@T>(v: &[mutable? T]) : is_not_empty(v) -> T {
|
||||
fn last_total<@T>(v: [mutable? T]) : is_not_empty(v) -> T {
|
||||
ret v[len(v) - 1u];
|
||||
}
|
||||
|
||||
/// Returns a copy of the elements from [`start`..`end`) from `v`.
|
||||
fn slice<@T>(v: &[mutable? T], start: uint, end: uint) -> [T] {
|
||||
fn slice<@T>(v: [mutable? T], start: uint, end: uint) -> [T] {
|
||||
assert (start <= end);
|
||||
assert (end <= len(v));
|
||||
let result = [];
|
||||
|
|
@ -114,7 +114,7 @@ fn slice<@T>(v: &[mutable? T], start: uint, end: uint) -> [T] {
|
|||
}
|
||||
|
||||
// TODO: Remove me once we have slots.
|
||||
fn slice_mut<@T>(v: &[mutable? T], start: uint, end: uint) -> [mutable T] {
|
||||
fn slice_mut<@T>(v: [mutable? T], start: uint, end: uint) -> [mutable T] {
|
||||
assert (start <= end);
|
||||
assert (end <= len(v));
|
||||
let result = [mutable];
|
||||
|
|
@ -151,14 +151,14 @@ fn pop<@T>(v: &mutable [mutable? T]) -> T {
|
|||
// Appending
|
||||
|
||||
/// Expands the given vector in-place by appending `n` copies of `initval`.
|
||||
fn grow<@T>(v: &mutable [T], n: uint, initval: &T) {
|
||||
fn grow<@T>(v: &mutable [T], n: uint, initval: T) {
|
||||
reserve(v, next_power_of_two(len(v) + n));
|
||||
let i: uint = 0u;
|
||||
while i < n { v += [initval]; i += 1u; }
|
||||
}
|
||||
|
||||
// TODO: Remove me once we have slots.
|
||||
fn grow_mut<@T>(v: &mutable [mutable T], n: uint, initval: &T) {
|
||||
fn grow_mut<@T>(v: &mutable [mutable T], n: uint, initval: T) {
|
||||
reserve(v, next_power_of_two(len(v) + n));
|
||||
let i: uint = 0u;
|
||||
while i < n { v += [mutable initval]; i += 1u; }
|
||||
|
|
@ -175,7 +175,7 @@ fn grow_fn<@T>(v: &mutable [T], n: uint, init_fn: fn(uint) -> T) {
|
|||
/// Sets the element at position `index` to `val`. If `index` is past the end
|
||||
/// of the vector, expands the vector by replicating `initval` to fill the
|
||||
/// intervening space.
|
||||
fn grow_set<@T>(v: &mutable [mutable T], index: uint, initval: &T, val: &T) {
|
||||
fn grow_set<@T>(v: &mutable [mutable T], index: uint, initval: T, val: T) {
|
||||
if index >= len(v) { grow_mut(v, index - len(v) + 1u, initval); }
|
||||
v[index] = val;
|
||||
}
|
||||
|
|
@ -183,7 +183,7 @@ fn grow_set<@T>(v: &mutable [mutable T], index: uint, initval: &T, val: &T) {
|
|||
|
||||
// Functional utilities
|
||||
|
||||
fn map<@T, @U>(f: &block(&T) -> U, v: &[mutable? T]) -> [U] {
|
||||
fn map<@T, @U>(f: block(T) -> U, v: [mutable? T]) -> [U] {
|
||||
let result = [];
|
||||
reserve(result, len(v));
|
||||
for elem: T in v {
|
||||
|
|
@ -193,7 +193,7 @@ fn map<@T, @U>(f: &block(&T) -> U, v: &[mutable? T]) -> [U] {
|
|||
ret result;
|
||||
}
|
||||
|
||||
fn map2<@T, @U, @V>(f: &block(&T, &U) -> V, v0: &[T], v1: &[U]) -> [V] {
|
||||
fn map2<@T, @U, @V>(f: block(T, U) -> V, v0: [T], v1: [U]) -> [V] {
|
||||
let v0_len = len::<T>(v0);
|
||||
if v0_len != len::<U>(v1) { fail; }
|
||||
let u: [V] = [];
|
||||
|
|
@ -202,8 +202,7 @@ fn map2<@T, @U, @V>(f: &block(&T, &U) -> V, v0: &[T], v1: &[U]) -> [V] {
|
|||
ret u;
|
||||
}
|
||||
|
||||
fn filter_map<@T, @U>(f: &block(&T) -> option::t<U>, v: &[mutable? T]) ->
|
||||
[U] {
|
||||
fn filter_map<@T, @U>(f: block(T) -> option::t<U>, v: [mutable? T]) -> [U] {
|
||||
let result = [];
|
||||
for elem: T in v {
|
||||
let elem2 = elem; // satisfies alias checker
|
||||
|
|
@ -215,7 +214,7 @@ fn filter_map<@T, @U>(f: &block(&T) -> option::t<U>, v: &[mutable? T]) ->
|
|||
ret result;
|
||||
}
|
||||
|
||||
fn foldl<@T, @U>(p: &block(&U, &T) -> U, z: &U, v: &[mutable? T]) -> U {
|
||||
fn foldl<@T, @U>(p: block(U, T) -> U, z: U, v: [mutable? T]) -> U {
|
||||
let sz = len(v);
|
||||
if sz == 0u { ret z; }
|
||||
let first = v[0];
|
||||
|
|
@ -223,45 +222,45 @@ fn foldl<@T, @U>(p: &block(&U, &T) -> U, z: &U, v: &[mutable? T]) -> U {
|
|||
ret p(foldl(p, z, rest), first);
|
||||
}
|
||||
|
||||
fn any<T>(f: &block(&T) -> bool, v: &[T]) -> bool {
|
||||
fn any<T>(f: block(T) -> bool, v: [T]) -> bool {
|
||||
for elem: T in v { if f(elem) { ret true; } }
|
||||
ret false;
|
||||
}
|
||||
|
||||
fn all<T>(f: &block(&T) -> bool, v: &[T]) -> bool {
|
||||
fn all<T>(f: block(T) -> bool, v: [T]) -> bool {
|
||||
for elem: T in v { if !f(elem) { ret false; } }
|
||||
ret true;
|
||||
}
|
||||
|
||||
fn member<T>(x: &T, v: &[T]) -> bool {
|
||||
fn member<T>(x: T, v: [T]) -> bool {
|
||||
for elt: T in v { if x == elt { ret true; } }
|
||||
ret false;
|
||||
}
|
||||
|
||||
fn count<T>(x: &T, v: &[mutable? T]) -> uint {
|
||||
fn count<T>(x: T, v: [mutable? T]) -> uint {
|
||||
let cnt = 0u;
|
||||
for elt: T in v { if x == elt { cnt += 1u; } }
|
||||
ret cnt;
|
||||
}
|
||||
|
||||
fn find<@T>(f: &block(&T) -> bool, v: &[T]) -> option::t<T> {
|
||||
fn find<@T>(f: block(T) -> bool, v: [T]) -> option::t<T> {
|
||||
for elt: T in v { if f(elt) { ret some(elt); } }
|
||||
ret none;
|
||||
}
|
||||
|
||||
fn position<@T>(x: &T, v: &[T]) -> option::t<uint> {
|
||||
fn position<@T>(x: T, v: [T]) -> option::t<uint> {
|
||||
let i: uint = 0u;
|
||||
while i < len(v) { if x == v[i] { ret some::<uint>(i); } i += 1u; }
|
||||
ret none;
|
||||
}
|
||||
|
||||
fn position_pred<T>(f: fn(&T) -> bool, v: &[T]) -> option::t<uint> {
|
||||
fn position_pred<T>(f: fn(T) -> bool, v: [T]) -> option::t<uint> {
|
||||
let i: uint = 0u;
|
||||
while i < len(v) { if f(v[i]) { ret some::<uint>(i); } i += 1u; }
|
||||
ret none;
|
||||
}
|
||||
|
||||
pure fn same_length<T, U>(xs: &[T], ys: &[U]) -> bool {
|
||||
pure fn same_length<T, U>(xs: [T], ys: [U]) -> bool {
|
||||
let xlen = unchecked{ vec::len(xs) };
|
||||
let ylen = unchecked{ vec::len(ys) };
|
||||
xlen == ylen
|
||||
|
|
@ -271,13 +270,13 @@ pure fn same_length<T, U>(xs: &[T], ys: &[U]) -> bool {
|
|||
// saying the two result lists have the same length -- or, could
|
||||
// return a nominal record with a constraint saying that, instead of
|
||||
// returning a tuple (contingent on issue #869)
|
||||
fn unzip<@T, @U>(v: &[(T, U)]) -> ([T], [U]) {
|
||||
fn unzip<@T, @U>(v: [(T, U)]) -> ([T], [U]) {
|
||||
let as = [], bs = [];
|
||||
for (a, b) in v { as += [a]; bs += [b]; }
|
||||
ret (as, bs);
|
||||
}
|
||||
|
||||
fn zip<@T, @U>(v: &[T], u: &[U]) : same_length(v, u) -> [(T, U)] {
|
||||
fn zip<@T, @U>(v: [T], u: [U]) : same_length(v, u) -> [(T, U)] {
|
||||
let zipped = [];
|
||||
let sz = len(v), i = 0u;
|
||||
assert (sz == len(u));
|
||||
|
|
@ -286,14 +285,14 @@ fn zip<@T, @U>(v: &[T], u: &[U]) : same_length(v, u) -> [(T, U)] {
|
|||
}
|
||||
|
||||
// Swaps two elements in a vector
|
||||
fn swap<@T>(v: &[mutable T], a: uint, b: uint) {
|
||||
fn swap<@T>(v: [mutable T], a: uint, b: uint) {
|
||||
let t: T = v[a];
|
||||
v[a] = v[b];
|
||||
v[b] = t;
|
||||
}
|
||||
|
||||
// In place vector reversal
|
||||
fn reverse<@T>(v: &[mutable T]) {
|
||||
fn reverse<@T>(v: [mutable T]) {
|
||||
let i: uint = 0u;
|
||||
let ln = len::<T>(v);
|
||||
while i < ln / 2u { swap(v, i, ln - i - 1u); i += 1u; }
|
||||
|
|
@ -301,7 +300,7 @@ fn reverse<@T>(v: &[mutable T]) {
|
|||
|
||||
|
||||
// Functional vector reversal. Returns a reversed copy of v.
|
||||
fn reversed<@T>(v: &[T]) -> [T] {
|
||||
fn reversed<@T>(v: [T]) -> [T] {
|
||||
let rs: [T] = [];
|
||||
let i = len::<T>(v);
|
||||
if i == 0u { ret rs; } else { i -= 1u; }
|
||||
|
|
@ -326,7 +325,7 @@ fn enum_uints(start: uint, end: uint) : uint::le(start, end) -> [uint] {
|
|||
}
|
||||
|
||||
// Iterate over a list with with the indexes
|
||||
iter iter2<@T>(v: &[T]) -> (uint, T) {
|
||||
iter iter2<@T>(v: [T]) -> (uint, T) {
|
||||
let i = 0u;
|
||||
for x in v { put (i, x); i += 1u; }
|
||||
}
|
||||
|
|
@ -343,13 +342,13 @@ mod unsafe {
|
|||
(**repr).fill = new_len * sys::size_of::<T>();
|
||||
}
|
||||
|
||||
fn to_ptr<T>(v: &[T]) -> *T {
|
||||
fn to_ptr<T>(v: [T]) -> *T {
|
||||
let repr: **vec_repr = ::unsafe::reinterpret_cast(addr_of(v));
|
||||
ret ::unsafe::reinterpret_cast(addr_of((**repr).data));
|
||||
}
|
||||
}
|
||||
|
||||
fn to_ptr<T>(v: &[T]) -> *T { ret unsafe::to_ptr(v); }
|
||||
fn to_ptr<T>(v: [T]) -> *T { ret unsafe::to_ptr(v); }
|
||||
|
||||
// Local Variables:
|
||||
// mode: rust;
|
||||
|
|
|
|||
|
|
@ -1,16 +1,16 @@
|
|||
|
||||
|
||||
native "rust" mod rustrt {
|
||||
fn rust_list_files(path: &str) -> [str];
|
||||
fn rust_list_files(path: str) -> [str];
|
||||
fn rust_file_is_dir(path: str) -> int;
|
||||
}
|
||||
|
||||
fn list_dir(path: &str) -> [str] {
|
||||
fn list_dir(path: str) -> [str] {
|
||||
let path = path + "*";
|
||||
ret rustrt::rust_list_files(path);
|
||||
}
|
||||
|
||||
fn path_is_absolute(p: &str) -> bool {
|
||||
fn path_is_absolute(p: str) -> bool {
|
||||
ret str::char_at(p, 0u) == '/' ||
|
||||
str::char_at(p, 1u) == ':' && str::char_at(p, 2u) == '\\';
|
||||
}
|
||||
|
|
|
|||
|
|
@ -49,7 +49,7 @@ fn exec_suffix() -> str { ret ".exe"; }
|
|||
|
||||
fn target_os() -> str { ret "win32"; }
|
||||
|
||||
fn dylib_filename(base: &str) -> str { ret base + ".dll"; }
|
||||
fn dylib_filename(base: str) -> str { ret base + ".dll"; }
|
||||
|
||||
fn pipe() -> {in: int, out: int} {
|
||||
// Windows pipes work subtly differently than unix pipes, and their
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue