diff options
| author | Erick Tryzelaar <erick.tryzelaar@gmail.com> | 2011-08-10 09:27:11 -0700 |
|---|---|---|
| committer | Graydon Hoare <graydon@mozilla.com> | 2011-08-16 15:05:56 -0700 |
| commit | f764f9a8cf52e686ba6e54b594e6bbbdd5bc7b32 (patch) | |
| tree | 24a39688027a41a7a3e7e4a2239cfedf12fb20e9 | |
| parent | 8043788e3a71a951892577cbcb623ac94b908677 (diff) | |
| download | rust-f764f9a8cf52e686ba6e54b594e6bbbdd5bc7b32.tar.gz rust-f764f9a8cf52e686ba6e54b594e6bbbdd5bc7b32.zip | |
Port the stdlib to the typaram foo<T> syntax.
| -rw-r--r-- | src/lib/aio.rs | 48 | ||||
| -rw-r--r-- | src/lib/comm.rs | 2 | ||||
| -rw-r--r-- | src/lib/deque.rs | 26 | ||||
| -rw-r--r-- | src/lib/ebml.rs | 2 | ||||
| -rw-r--r-- | src/lib/either.rs | 14 | ||||
| -rw-r--r-- | src/lib/extfmt.rs | 6 | ||||
| -rw-r--r-- | src/lib/generic_os.rs | 4 | ||||
| -rw-r--r-- | src/lib/getopts.rs | 6 | ||||
| -rw-r--r-- | src/lib/io.rs | 6 | ||||
| -rw-r--r-- | src/lib/list.rs | 20 | ||||
| -rw-r--r-- | src/lib/map.rs | 52 | ||||
| -rw-r--r-- | src/lib/option.rs | 14 | ||||
| -rw-r--r-- | src/lib/posix_fs.rs | 2 | ||||
| -rw-r--r-- | src/lib/sio.rs | 18 | ||||
| -rw-r--r-- | src/lib/smallintmap.rs | 26 | ||||
| -rw-r--r-- | src/lib/sort.rs | 14 | ||||
| -rw-r--r-- | src/lib/test.rs | 10 | ||||
| -rw-r--r-- | src/lib/ufind.rs | 2 | ||||
| -rw-r--r-- | src/lib/vec.rs | 16 |
19 files changed, 144 insertions, 144 deletions
diff --git a/src/lib/aio.rs b/src/lib/aio.rs index bb9caf05697..03953f40a42 100644 --- a/src/lib/aio.rs +++ b/src/lib/aio.rs @@ -15,11 +15,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; } @@ -40,36 +40,36 @@ tag socket_event { } tag server_event { - pending(_chan[_chan[socket_event]]); + pending(_chan<_chan<socket_event>>); } tag request { quit; - connect(pending_connection,_chan[socket_event]); - serve(net::ip_addr,int,_chan[server_event],_chan[server]); - write(client,[u8],_chan[bool]); - close_server(server, _chan[bool]); + connect(pending_connection,_chan<socket_event>); + serve(net::ip_addr,int,_chan<server_event>,_chan<server>); + write(client,[u8],_chan<bool>); + close_server(server, _chan<bool>); close_client(client); } -type ctx = _chan[request]; +type ctx = _chan<request>; fn ip_to_sbuf(ip: net::ip_addr) -> *u8 { vec::to_ptr(str::bytes(net::format_addr(ip))) } -fn connect_task(ip: net::ip_addr, portnum: int, evt: _chan[socket_event]) { - let connecter: _port[client] = mk_port(); +fn connect_task(ip: net::ip_addr, portnum: int, evt: _chan<socket_event>) { + let connecter: _port<client> = mk_port(); rustrt::aio_connect(ip_to_sbuf(ip), portnum, connecter.mk_chan()); let client = connecter.recv(); new_client(client, evt); } -fn new_client(client: client, evt: _chan[socket_event]) { +fn new_client(client: client, evt: _chan<socket_event>) { // Start the read before notifying about the connect. This avoids a race // condition where the receiver can close the socket before we start // reading. - let reader: _port[[u8]] = mk_port(); + let reader: _port<[u8]> = mk_port(); rustrt::aio_read(client, reader.mk_chan()); send(evt, connected(client)); @@ -92,18 +92,18 @@ fn new_client(client: client, evt: _chan[socket_event]) { log "close message sent"; } -fn accept_task(client: client, events: _chan[server_event]) { +fn accept_task(client: client, events: _chan<server_event>) { log "accept task was spawned"; - let p: _port[_chan[socket_event]] = mk_port(); + let p: _port<_chan<socket_event>> = mk_port(); send(events, pending(p.mk_chan())); let evt = p.recv(); new_client(client, evt); log "done accepting"; } -fn server_task(ip: net::ip_addr, portnum: int, events: _chan[server_event], - server: _chan[server]) { - let accepter: _port[client] = mk_port(); +fn server_task(ip: net::ip_addr, portnum: int, events: _chan<server_event>, + server: _chan<server>) { + let accepter: _port<client> = mk_port(); send(server, rustrt::aio_serve(ip_to_sbuf(ip), portnum, accepter.mk_chan())); @@ -120,9 +120,9 @@ fn server_task(ip: net::ip_addr, portnum: int, events: _chan[server_event], } } -fn request_task(c: _chan[ctx]) { +fn request_task(c: _chan<ctx>) { // Create a port to accept IO requests on - let p: _port[request] = mk_port(); + let p: _port<request> = mk_port(); // Hand of its channel to our spawner send(c, p.mk_chan()); log "uv run task spawned"; @@ -160,7 +160,7 @@ fn request_task(c: _chan[ctx]) { } } -fn iotask(c: _chan[ctx]) { +fn iotask(c: _chan<ctx>) { log "io task spawned"; // Initialize before accepting requests rustrt::aio_init(); @@ -178,7 +178,7 @@ fn iotask(c: _chan[ctx]) { } fn new() -> ctx { - let p: _port[ctx] = mk_port(); + let p: _port<ctx> = mk_port(); task::_spawn(bind iotask(p.mk_chan())); ret p.recv(); } diff --git a/src/lib/comm.rs b/src/lib/comm.rs index b359c1d8858..01da63635ea 100644 --- a/src/lib/comm.rs +++ b/src/lib/comm.rs @@ -59,7 +59,7 @@ obj _port[~T](raw_port : @port_ptr) { } } -fn mk_port[~T]() -> _port[T] { +fn mk_port[~T]() -> _port<T> { _port(@port_ptr(rustrt::new_port(sys::size_of[T]()))) } diff --git a/src/lib/deque.rs b/src/lib/deque.rs index 65cae49ab16..c3d17314a41 100644 --- a/src/lib/deque.rs +++ b/src/lib/deque.rs @@ -16,8 +16,8 @@ type t[T] = fn get(int) -> T ; }; -fn create[@T]() -> t[T] { - type cell[T] = option::t[T]; +fn create[@T]() -> t<T> { + type cell[T] = option::t<T>; let initial_capacity: uint = 32u; // 2^5 /** @@ -26,8 +26,8 @@ fn create[@T]() -> t[T] { */ - fn grow[@T](nelts: uint, lo: uint, elts: &[mutable cell[T]]) -> - [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]; @@ -42,22 +42,22 @@ 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, mutable lo: uint, mutable hi: uint, - mutable elts: [mutable cell[T]]) { + mutable elts: [mutable cell<T>]) { fn size() -> uint { ret nelts; } fn add_front(t: &T) { let oldlo: uint = lo; if lo == 0u { - lo = vec::len[cell[T]](elts) - 1u; + lo = vec::len[cell<T>](elts) - 1u; } else { lo -= 1u; } if lo == hi { elts = grow[T](nelts, oldlo, elts); - lo = vec::len[cell[T]](elts) - 1u; + lo = vec::len[cell<T>](elts) - 1u; hi = nelts; } elts.(lo) = option::some[T](t); @@ -70,7 +70,7 @@ fn create[@T]() -> t[T] { hi = nelts; } elts.(hi) = option::some[T](t); - hi = (hi + 1u) % vec::len[cell[T]](elts); + hi = (hi + 1u) % vec::len[cell<T>](elts); nelts += 1u; } @@ -81,13 +81,13 @@ fn create[@T]() -> t[T] { fn pop_front() -> T { let t: T = get[T](elts, lo); elts.(lo) = option::none[T]; - lo = (lo + 1u) % vec::len[cell[T]](elts); + lo = (lo + 1u) % vec::len[cell<T>](elts); nelts -= 1u; ret t; } fn pop_back() -> T { if hi == 0u { - hi = vec::len[cell[T]](elts) - 1u; + hi = vec::len[cell<T>](elts) - 1u; } else { hi -= 1u; } let t: T = get[T](elts, hi); elts.(hi) = option::none[T]; @@ -97,11 +97,11 @@ fn create[@T]() -> t[T] { fn peek_front() -> T { ret get[T](elts, lo); } fn peek_back() -> T { ret get[T](elts, hi - 1u); } fn get(i: int) -> T { - let idx: uint = (lo + (i as uint)) % vec::len[cell[T]](elts); + let idx: uint = (lo + (i as uint)) % vec::len[cell<T>](elts); ret get[T](elts, idx); } } - let v: [mutable cell[T]] = + let v: [mutable cell<T>] = vec::init_elt_mut(option::none, initial_capacity); ret deque[T](0u, 0u, 0u, v); } diff --git a/src/lib/ebml.rs b/src/lib/ebml.rs index b7603affb6c..cd7fbf9eb3b 100644 --- a/src/lib/ebml.rs +++ b/src/lib/ebml.rs @@ -50,7 +50,7 @@ fn doc_at(data: &@[u8], start: uint) -> doc { ret {data: data, start: elt_size.next, end: end}; } -fn maybe_get_doc(d: doc, tg: uint) -> option::t[doc] { +fn maybe_get_doc(d: doc, tg: uint) -> option::t<doc> { let pos = d.start; while pos < d.end { let elt_tag = vint_at(*d.data, pos); diff --git a/src/lib/either.rs b/src/lib/either.rs index 018eee24dc6..78496bec917 100644 --- a/src/lib/either.rs +++ b/src/lib/either.rs @@ -6,30 +6,30 @@ 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 { + 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 { + for elt: t<T, U> in eithers { alt elt { left(l) { result += ~[l] } _ {/* fallthrough */ } } } 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 { + for elt: t<T, U> in eithers { alt elt { right(r) { result += ~[r] } _ {/* fallthrough */ } } } 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 { + for elt: t<T, U> in eithers { alt elt { left(l) { lefts += ~[l] } right(r) { rights += ~[r] } } } ret {lefts: lefts, rights: rights}; diff --git a/src/lib/extfmt.rs b/src/lib/extfmt.rs index e188b74ab02..11239d7ed42 100644 --- a/src/lib/extfmt.rs +++ b/src/lib/extfmt.rs @@ -60,7 +60,7 @@ mod ct { // A formatted conversion from an expression to a string type conv = - {param: option::t[int], + {param: option::t<int>, flags: [flag], width: count, precision: count, @@ -105,7 +105,7 @@ mod ct { ret pieces; } fn peek_num(s: str, i: uint, lim: uint) -> - option::t[{num: uint, next: uint}] { + option::t<{num: uint, next: uint}> { if i >= lim { ret none; } let c = s.(i); if !('0' as u8 <= c && c <= '9' as u8) { ret option::none; } @@ -135,7 +135,7 @@ mod ct { next: ty.next}; } fn parse_parameter(s: str, i: uint, lim: uint) -> - {param: option::t[int], next: uint} { + {param: option::t<int>, next: uint} { if i >= lim { ret {param: none, next: i}; } let num = peek_num(s, i, lim); ret alt num { diff --git a/src/lib/generic_os.rs b/src/lib/generic_os.rs index bd78f020104..da660e34dc5 100644 --- a/src/lib/generic_os.rs +++ b/src/lib/generic_os.rs @@ -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 = os::libc::getenv(str::buf(n)); ret if s as int == 0 { option::none[str] @@ -19,7 +19,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 nbuf = str::buf(n); let nsize = 256u; while true { diff --git a/src/lib/getopts.rs b/src/lib/getopts.rs index f7795520ef5..eb56b44b490 100644 --- a/src/lib/getopts.rs +++ b/src/lib/getopts.rs @@ -75,7 +75,7 @@ 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; } @@ -224,7 +224,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] } }; @@ -234,7 +234,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) } } diff --git a/src/lib/io.rs b/src/lib/io.rs index 808c4e84c98..d10cb2fe33b 100644 --- a/src/lib/io.rs +++ b/src/lib/io.rs @@ -59,7 +59,7 @@ resource FILE_res(f: os::libc::FILE) { os::libc::fclose(f); } -obj FILE_buf_reader(f: os::libc::FILE, res: option::t[@FILE_res]) { +obj FILE_buf_reader(f: os::libc::FILE, res: option::t<@FILE_res>) { fn read(len: uint) -> [u8] { let buf = ~[]; vec::reserve[u8](buf, len); @@ -243,7 +243,7 @@ type buf_writer = fn tell() -> uint ; }; -obj FILE_writer(f: os::libc::FILE, res: option::t[@FILE_res]) { +obj FILE_writer(f: os::libc::FILE, res: option::t<@FILE_res>) { fn write(v: &[u8]) { let len = vec::len[u8](v); let vbuf = vec::to_ptr[u8](v); @@ -262,7 +262,7 @@ resource fd_res(fd: int) { os::libc::close(fd); } -obj fd_buf_writer(fd: int, res: option::t[@fd_res]) { +obj fd_buf_writer(fd: int, res: option::t<@fd_res>) { fn write(v: &[u8]) { let len = vec::len[u8](v); let count = 0u; diff --git a/src/lib/list.rs b/src/lib/list.rs index cd379abd750..9657a4fe451 100644 --- a/src/lib/list.rs +++ b/src/lib/list.rs @@ -1,9 +1,9 @@ import option::some; import option::none; -tag list[T] { cons(T, @list[T]); nil; } +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,8 @@ 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 +39,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,26 +50,26 @@ fn has[@T](ls_: &list[T], elt: &T) -> bool { ret false; } -fn length[@T](ls: &list[T]) -> uint { +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) { diff --git a/src/lib/map.rs b/src/lib/map.rs index 3d9c11e9061..d6135864e5b 100644 --- a/src/lib/map.rs +++ b/src/lib/map.rs @@ -11,23 +11,23 @@ type hashmap[K, 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 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, ()]; +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}; tag bucket[@K, @V] { nil; deleted; some(K, V); } - fn make_buckets[@K, @V](nbkts: uint) -> [mutable (bucket[K, V])] { - ret vec::init_elt_mut[bucket[K, V]](nil[K, V], nbkts); + fn make_buckets[@K, @V](nbkts: uint) -> [mutable (bucket<K, V>)] { + ret vec::init_elt_mut[bucket<K, V>](nil[K, V], nbkts); } // Derive two hash functions from the one given by taking the upper // half and lower half of the uint bits. Our bucket probing @@ -53,8 +53,8 @@ fn mk_hashmap[@K, @V](hasher: &hashfn[K], eqer: &eqfn[K]) -> hashmap[K, V] { * will fail. */ - fn insert_common[@K, @V](hasher: &hashfn[K], eqer: &eqfn[K], - bkts: &[mutable bucket[K, V]], nbkts: uint, + fn insert_common[@K, @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); @@ -76,9 +76,9 @@ 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) -> option::t[V] { + fn find_common[@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); while i < nbkts { @@ -97,10 +97,10 @@ 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) { - for b: bucket[K, V] in oldbkts { + fn rehash[@K, @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_) { let k = k_; @@ -111,9 +111,9 @@ fn mk_hashmap[@K, @V](hasher: &hashfn[K], eqer: &eqfn[K]) -> hashmap[K, V] { } } } - obj hashmap[@K, @V](hasher: hashfn[K], - eqer: eqfn[K], - mutable bkts: [mutable bucket[K, V]], + obj hashmap[@K, @V](hasher: hashfn<K>, + eqer: eqfn<K>, + mutable bkts: [mutable bucket<K, V>], mutable nbkts: uint, mutable nelts: uint, lf: util::rational) { @@ -146,10 +146,10 @@ fn mk_hashmap[@K, @V](hasher: &hashfn[K], eqer: &eqfn[K]) -> hashmap[K, V] { _ { 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 { @@ -177,12 +177,12 @@ fn mk_hashmap[@K, @V](hasher: &hashfn[K], eqer: &eqfn[K]) -> hashmap[K, V] { bkts = newbkts; } iter items() -> @{key: K, val: V} { - for b: bucket[K, V] in bkts { + for b: bucket<K, V> in bkts { alt b { some(k, v) { put @{key: k, val: v}; } _ { } } } } iter keys() -> K { - for b: bucket[K, V] in bkts { + for b: bucket<K, V> in bkts { alt b { some(k, _) { put k; } _ { } } } } @@ -193,17 +193,17 @@ fn mk_hashmap[@K, @V](hasher: &hashfn[K], eqer: &eqfn[K]) -> hashmap[K, V] { // Hash map constructors for basic types -fn new_str_hash[@V]() -> hashmap[str, V] { +fn new_str_hash[@V]() -> hashmap<str, V> { ret mk_hashmap(str::hash, str::eq); } -fn new_int_hash[@V]() -> hashmap[int, 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; } ret mk_hashmap(hash_int, eq_int); } -fn new_uint_hash[@V]() -> hashmap[uint, V] { +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; } ret mk_hashmap(hash_uint, eq_uint); diff --git a/src/lib/option.rs b/src/lib/option.rs index ff2dfc71efb..e803c9fc66c 100644 --- a/src/lib/option.rs +++ b/src/lib/option.rs @@ -2,33 +2,33 @@ 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); } } } diff --git a/src/lib/posix_fs.rs b/src/lib/posix_fs.rs index 1a84e0faf5a..16dacf287f6 100644 --- a/src/lib/posix_fs.rs +++ b/src/lib/posix_fs.rs @@ -17,7 +17,7 @@ fn list_dir(path: str) -> [str] { /* auto dir = os::libc::opendir(str::buf(path)); assert (dir as uint != 0u); - let vec[str] result = []; + let vec<str> result = []; while (true) { auto ent = os::libc::readdir(dir); if (ent as int == 0) { diff --git a/src/lib/sio.rs b/src/lib/sio.rs index 7f8e56516e3..bd75efa76a5 100644 --- a/src/lib/sio.rs +++ b/src/lib/sio.rs @@ -8,9 +8,9 @@ import net; type ctx = aio::ctx; type client = { ctx: ctx, client: aio::client, - evt: _port[aio::socket_event] }; + evt: _port<aio::socket_event> }; type server = { ctx: ctx, server: aio::server, - evt: _port[aio::server_event] }; + evt: _port<aio::server_event> }; fn new() -> ctx { ret aio::new(); @@ -20,7 +20,7 @@ fn destroy(ctx: ctx) { send(ctx, aio::quit); } -fn make_socket(ctx: ctx, p: _port[aio::socket_event]) -> client { +fn make_socket(ctx: ctx, p: _port<aio::socket_event>) -> client { let evt: aio::socket_event = p.recv(); alt evt { aio::connected(client) { @@ -31,7 +31,7 @@ fn make_socket(ctx: ctx, p: _port[aio::socket_event]) -> client { } fn connect_to(ctx: ctx, ip: net::ip_addr, portnum: int) -> client { - let p: _port[aio::socket_event] = mk_port(); + let p: _port<aio::socket_event> = mk_port(); send(ctx, aio::connect(aio::remote(ip, portnum), p.mk_chan())); ret make_socket(ctx, p); } @@ -48,8 +48,8 @@ fn read(c: client) -> [u8] { } fn create_server(ctx: ctx, ip: net::ip_addr, portnum: int) -> server { - let evt: _port[aio::server_event] = mk_port(); - let p: _port[aio::server] = mk_port(); + let evt: _port<aio::server_event> = mk_port(); + let p: _port<aio::server> = mk_port(); send(ctx, aio::serve(ip, portnum, evt.mk_chan(), p.mk_chan())); let srv: aio::server = p.recv(); @@ -60,7 +60,7 @@ fn accept_from(server: server) -> client { let evt: aio::server_event = server.evt.recv(); alt evt { aio::pending(callback) { - let p: _port[aio::socket_event] = mk_port(); + let p: _port<aio::socket_event> = mk_port(); send(callback, p.mk_chan()); ret make_socket(server.ctx, p); } @@ -68,14 +68,14 @@ fn accept_from(server: server) -> client { } fn write_data(c: client, data: [u8]) -> bool { - let p: _port[bool] = mk_port(); + let p: _port<bool> = mk_port(); send(c.ctx, aio::write(c.client, data, p.mk_chan())); ret p.recv(); } fn close_server(server: server) { // TODO: make this unit once we learn to send those from native code - let p: _port[bool] = mk_port(); + let p: _port<bool> = mk_port(); send(server.ctx, aio::close_server(server.server, p.mk_chan())); log "Waiting for close"; p.recv(); diff --git a/src/lib/smallintmap.rs b/src/lib/smallintmap.rs index c3da9dfa366..682cc47d647 100644 --- a/src/lib/smallintmap.rs +++ b/src/lib/smallintmap.rs @@ -7,38 +7,38 @@ import option::some; // FIXME: Should not be @; there's a bug somewhere in rustc that requires this // to be. -type smallintmap[T] = @{mutable v: [mutable option::t[T]]}; +type smallintmap[T] = @{mutable v: [mutable option::t<T>]}; -fn mk[@T]() -> smallintmap[T] { - let v: [mutable option::t[T]] = ~[mutable]; +fn mk[@T]() -> smallintmap<T> { + let v: [mutable option::t<T>] = ~[mutable]; ret @{mutable v: v}; } -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 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] { - if key < vec::len[option::t[T]](m.v) { ret m.v.(key); } +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) { - m.v = vec::slice_mut[option::t[T]](m.v, 0u, len); +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 { - ret vec::len[option::t[T]](m.v); +fn max_key[T](m: &smallintmap<T>) -> uint { + ret vec::len[option::t<T>](m.v); } diff --git a/src/lib/sort.rs b/src/lib/sort.rs index 0aa8c5b6d13..24f06f55099 100644 --- a/src/lib/sort.rs +++ b/src/lib/sort.rs @@ -8,8 +8,8 @@ export quick_sort3; 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: <eq<T>, v: &[T]) -> [T] { + fn merge[@T](le: <eq<T>, a: &[T], b: &[T]) -> [T] { let rs: [T] = ~[]; let a_len: uint = len[T](a); let a_ix: uint = 0u; @@ -39,7 +39,7 @@ fn swap[@T](arr: &[mutable T], x: uint, y: uint) { arr.(y) = a; } -fn part[@T](compare_func: <eq[T], arr: &[mutable T], left: uint, +fn part[@T](compare_func: <eq<T>, arr: &[mutable T], left: uint, right: uint, pivot: uint) -> uint { let pivot_value = arr.(pivot); swap[T](arr, pivot, right); @@ -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: <eq<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: <eq<T>, arr: &[mutable T]) { if len[T](arr) == 0u { ret; } qsort[T](compare_func, arr, 0u, len[T](arr) - 1u); } @@ -79,7 +79,7 @@ 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], +fn qsort3[@T](compare_func_lt: <eq<T>, compare_func_eq: <eq<T>, arr: &[mutable T], left: int, right: int) { if right <= left { ret; } let v: T = arr.(right); @@ -127,7 +127,7 @@ 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], +fn quick_sort3[@T](compare_func_lt: <eq<T>, compare_func_eq: <eq<T>, arr: &[mutable T]) { if len[T](arr) == 0u { ret; } qsort3[T](compare_func_lt, compare_func_eq, arr, 0, diff --git a/src/lib/test.rs b/src/lib/test.rs index 46f166995d6..9cde409df93 100644 --- a/src/lib/test.rs +++ b/src/lib/test.rs @@ -59,13 +59,13 @@ fn test_main_ivec(args: &[str], tests: &[test_desc]) { if !run_tests_console(opts, tests) { fail "Some tests failed"; } } -fn test_main(args: &vec[str], tests: &[test_desc]) { +fn test_main(args: &vec<str>, tests: &[test_desc]) { test_main_ivec(vec::from_vec(args), tests); } -type test_opts = {filter: option::t[str], run_ignored: bool}; +type test_opts = {filter: option::t<str>, run_ignored: bool}; -type opt_res = either::t[test_opts, str]; +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 { @@ -268,7 +268,7 @@ fn filter_tests(opts: &test_opts, tests: &[test_desc]) -> [test_desc] { let filter = bind fn (test: &test_desc, filter_str: str) -> - option::t[test_desc] { + option::t<test_desc> { if str::find(test.name, filter_str) >= 0 { ret option::some(test); } else { ret option::none; } @@ -284,7 +284,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, diff --git a/src/lib/ufind.rs b/src/lib/ufind.rs index ecaec535797..eb52027d4b8 100644 --- a/src/lib/ufind.rs +++ b/src/lib/ufind.rs @@ -6,7 +6,7 @@ import option::some; // A very naive implementation of union-find with unsigned integer nodes. // Maintains the invariant that the root of a node is always equal to or less // than the node itself. -type node = option::t[uint]; +type node = option::t<uint>; type ufind = {mutable nodes: [mutable node]}; diff --git a/src/lib/vec.rs b/src/lib/vec.rs index be2a1eeea6f..f82eec559ed 100644 --- a/src/lib/vec.rs +++ b/src/lib/vec.rs @@ -17,7 +17,7 @@ native "rust" mod rustrt { count: uint); } -fn from_vec[@T](v: &vec[mutable? T]) -> [T] { +fn from_vec[@T](v: &vec<mutable? T>) -> [T] { let iv = ~[]; for e in v { iv += ~[e]; @@ -38,7 +38,7 @@ fn len[T](v: &[mutable? T]) -> uint { ret rusti::ivec_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; @@ -47,7 +47,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; @@ -104,7 +104,7 @@ fn tail[@T](v: &[mutable? T]) : is_not_empty(v) -> [mutable? T] { } /// 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)); } @@ -210,7 +210,7 @@ fn map2[@T, @U, @V](f: &block(&T, &U) -> V, v0: &[T], v1: &[U]) ret u; } -fn filter_map[@T, @U](f: &block(&T) -> option::t[U], +fn filter_map[@T, @U](f: &block(&T) -> option::t<U>, v: &[mutable? T]) -> [U] { let result = ~[]; for elem: T in v { @@ -252,18 +252,18 @@ fn count[T](x: &T, v: &[mutable? T]) -> uint { 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[uint]; } -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[uint]; |
