diff options
Diffstat (limited to 'src/libcore')
| -rw-r--r-- | src/libcore/at_vec.rs | 20 | ||||
| -rw-r--r-- | src/libcore/comm.rs | 20 | ||||
| -rw-r--r-- | src/libcore/core.rc | 27 | ||||
| -rw-r--r-- | src/libcore/core.rs | 22 | ||||
| -rw-r--r-- | src/libcore/dlist.rs | 104 | ||||
| -rw-r--r-- | src/libcore/dvec.rs | 31 | ||||
| -rw-r--r-- | src/libcore/either.rs | 70 | ||||
| -rw-r--r-- | src/libcore/future.rs | 14 | ||||
| -rw-r--r-- | src/libcore/int-template.rs | 8 | ||||
| -rw-r--r-- | src/libcore/io.rs | 4 | ||||
| -rw-r--r-- | src/libcore/iter-trait.rs | 6 | ||||
| -rw-r--r-- | src/libcore/iter-trait/dlist.rs | 3 | ||||
| -rw-r--r-- | src/libcore/iter-trait/dvec.rs | 3 | ||||
| -rw-r--r-- | src/libcore/iter.rs | 36 | ||||
| -rw-r--r-- | src/libcore/os.rs | 8 | ||||
| -rw-r--r-- | src/libcore/pipes.rs | 32 | ||||
| -rw-r--r-- | src/libcore/ptr.rs | 6 | ||||
| -rw-r--r-- | src/libcore/result.rs | 8 | ||||
| -rw-r--r-- | src/libcore/send_map.rs | 84 | ||||
| -rw-r--r-- | src/libcore/str.rs | 14 | ||||
| -rw-r--r-- | src/libcore/task.rs | 4 | ||||
| -rw-r--r-- | src/libcore/uint-template.rs | 6 | ||||
| -rw-r--r-- | src/libcore/vec.rs | 62 |
23 files changed, 311 insertions, 281 deletions
diff --git a/src/libcore/at_vec.rs b/src/libcore/at_vec.rs index 060015c26cf..59ed352e1ee 100644 --- a/src/libcore/at_vec.rs +++ b/src/libcore/at_vec.rs @@ -15,7 +15,7 @@ export unsafe; #[abi = "cdecl"] extern mod rustrt { fn vec_reserve_shared_actual(++t: *sys::TypeDesc, - ++v: **vec::unsafe::vec_repr, + ++v: **vec::unsafe::VecRepr, ++n: libc::size_t); } @@ -25,13 +25,13 @@ extern mod rusti { } /// A function used to initialize the elements of a vector -type init_op<T> = fn(uint) -> T; +type InitOp<T> = fn(uint) -> T; /// Returns the number of elements the vector can hold without reallocating #[inline(always)] pure fn capacity<T>(&&v: @[const T]) -> uint { unsafe { - let repr: **unsafe::vec_repr = + let repr: **unsafe::VecRepr = ::unsafe::reinterpret_cast(addr_of(v)); (**repr).alloc / sys::size_of::<T>() } @@ -103,7 +103,7 @@ pure fn map<T, U>(v: &[T], f: fn(T) -> U) -> @[U] { * Creates an immutable vector of size `n_elts` and initializes the elements * to the value returned by the function `op`. */ -pure fn from_fn<T>(n_elts: uint, op: init_op<T>) -> @[T] { +pure fn from_fn<T>(n_elts: uint, op: InitOp<T>) -> @[T] { do build_sized(n_elts) |push| { let mut i: uint = 0u; while i < n_elts { push(op(i)); i += 1u; } @@ -133,8 +133,8 @@ impl<T: copy> @[T]: add<&[const T],@[T]> { mod unsafe { - type vec_repr = vec::unsafe::vec_repr; - type slice_repr = vec::unsafe::slice_repr; + type VecRepr = vec::unsafe::VecRepr; + type SliceRepr = vec::unsafe::SliceRepr; /** * Sets the length of a vector @@ -145,13 +145,13 @@ mod unsafe { */ #[inline(always)] unsafe fn set_len<T>(&&v: @[const T], new_len: uint) { - let repr: **vec_repr = ::unsafe::reinterpret_cast(addr_of(v)); + let repr: **VecRepr = ::unsafe::reinterpret_cast(addr_of(v)); (**repr).fill = new_len * sys::size_of::<T>(); } #[inline(always)] unsafe fn push<T>(&v: @[const T], +initval: T) { - let repr: **vec_repr = ::unsafe::reinterpret_cast(addr_of(v)); + let repr: **VecRepr = ::unsafe::reinterpret_cast(addr_of(v)); let fill = (**repr).fill; if (**repr).alloc > fill { push_fast(v, initval); @@ -163,7 +163,7 @@ mod unsafe { // This doesn't bother to make sure we have space. #[inline(always)] // really pretty please unsafe fn push_fast<T>(&v: @[const T], +initval: T) { - let repr: **vec_repr = ::unsafe::reinterpret_cast(addr_of(v)); + let repr: **VecRepr = ::unsafe::reinterpret_cast(addr_of(v)); let fill = (**repr).fill; (**repr).fill += sys::size_of::<T>(); let p = ptr::addr_of((**repr).data); @@ -190,7 +190,7 @@ mod unsafe { unsafe fn reserve<T>(&v: @[const T], n: uint) { // Only make the (slow) call into the runtime if we have to if capacity(v) < n { - let ptr = addr_of(v) as **vec_repr; + let ptr = addr_of(v) as **VecRepr; rustrt::vec_reserve_shared_actual(sys::get_type_desc::<T>(), ptr, n as libc::size_t); } diff --git a/src/libcore/comm.rs b/src/libcore/comm.rs index b4cf0ef1002..eb19a12c254 100644 --- a/src/libcore/comm.rs +++ b/src/libcore/comm.rs @@ -27,7 +27,7 @@ * ~~~ */ -import either::either; +import either::Either; import libc::size_t; export port; @@ -222,7 +222,7 @@ fn peek_(p: *rust_port) -> bool { /// Receive on one of two ports fn select2<A: send, B: send>(p_a: port<A>, p_b: port<B>) - -> either<A, B> { + -> Either<A, B> { let ports = ~[(**p_a).po, (**p_b).po]; let yield = 0u, yieldp = ptr::addr_of(yield); @@ -246,9 +246,9 @@ fn select2<A: send, B: send>(p_a: port<A>, p_b: port<B>) assert resport != ptr::null(); if resport == (**p_a).po { - either::left(recv(p_a)) + either::Left(recv(p_a)) } else if resport == (**p_b).po { - either::right(recv(p_b)) + either::Right(recv(p_b)) } else { fail ~"unexpected result from rust_port_select"; } @@ -355,11 +355,11 @@ fn test_select2_available() { send(ch_a, ~"a"); - assert select2(po_a, po_b) == either::left(~"a"); + assert select2(po_a, po_b) == either::Left(~"a"); send(ch_b, ~"b"); - assert select2(po_a, po_b) == either::right(~"b"); + assert select2(po_a, po_b) == either::Right(~"b"); } #[test] @@ -375,14 +375,14 @@ fn test_select2_rendezvous() { send(ch_a, ~"a"); }; - assert select2(po_a, po_b) == either::left(~"a"); + assert select2(po_a, po_b) == either::Left(~"a"); do task::spawn { for iter::repeat(10u) { task::yield() } send(ch_b, ~"b"); }; - assert select2(po_a, po_b) == either::right(~"b"); + assert select2(po_a, po_b) == either::Right(~"b"); } } @@ -413,8 +413,8 @@ fn test_select2_stress() { let mut bs = 0; for iter::repeat(msgs * times * 2u) { match select2(po_a, po_b) { - either::left(~"a") => as += 1, - either::right(~"b") => bs += 1, + either::Left(~"a") => as += 1, + either::Right(~"b") => bs += 1, _ => fail ~"test_select_2_stress failed" } } diff --git a/src/libcore/core.rc b/src/libcore/core.rc index f5c9039ad25..3c54e077cc3 100644 --- a/src/libcore/core.rc +++ b/src/libcore/core.rc @@ -68,6 +68,7 @@ export priv; // Built-in-type support modules /// Operations and constants for `int` +#[warn(non_camel_case_types)] #[path = "int-template"] mod int { import inst::{ hash, pow }; @@ -77,6 +78,7 @@ mod int { } /// Operations and constants for `i8` +#[warn(non_camel_case_types)] #[path = "int-template"] mod i8 { #[path = "i8.rs"] @@ -84,6 +86,7 @@ mod i8 { } /// Operations and constants for `i16` +#[warn(non_camel_case_types)] #[path = "int-template"] mod i16 { #[path = "i16.rs"] @@ -91,6 +94,7 @@ mod i16 { } /// Operations and constants for `i32` +#[warn(non_camel_case_types)] #[path = "int-template"] mod i32 { #[path = "i32.rs"] @@ -98,6 +102,7 @@ mod i32 { } /// Operations and constants for `i64` +#[warn(non_camel_case_types)] #[path = "int-template"] mod i64 { #[path = "i64.rs"] @@ -105,6 +110,7 @@ mod i64 { } /// Operations and constants for `uint` +#[warn(non_camel_case_types)] #[path = "uint-template"] mod uint { import inst::{ @@ -119,6 +125,7 @@ mod uint { } /// Operations and constants for `u8` +#[warn(non_camel_case_types)] #[path = "uint-template"] mod u8 { import inst::is_ascii; @@ -129,6 +136,7 @@ mod u8 { } /// Operations and constants for `u16` +#[warn(non_camel_case_types)] #[path = "uint-template"] mod u16 { #[path = "u16.rs"] @@ -136,6 +144,7 @@ mod u16 { } /// Operations and constants for `u32` +#[warn(non_camel_case_types)] #[path = "uint-template"] mod u32 { #[path = "u32.rs"] @@ -143,6 +152,7 @@ mod u32 { } /// Operations and constants for `u64` +#[warn(non_camel_case_types)] #[path = "uint-template"] mod u64 { #[path = "u64.rs"] @@ -150,15 +160,25 @@ mod u64 { } +#[warn(non_camel_case_types)] mod box; +#[warn(non_camel_case_types)] mod char; +#[warn(non_camel_case_types)] mod float; +#[warn(non_camel_case_types)] mod f32; +#[warn(non_camel_case_types)] mod f64; +#[warn(non_camel_case_types)] mod str; +#[warn(non_camel_case_types)] mod ptr; +#[warn(non_camel_case_types)] mod vec; +#[warn(non_camel_case_types)] mod at_vec; +#[warn(non_camel_case_types)] mod bool; #[warn(non_camel_case_types)] mod tuple; @@ -173,7 +193,9 @@ mod cmp; mod num; #[warn(non_camel_case_types)] mod hash; +#[warn(non_camel_case_types)] mod either; +#[warn(non_camel_case_types)] mod iter; #[warn(non_camel_case_types)] mod logging; @@ -193,18 +215,23 @@ mod util; // Data structure modules +#[warn(non_camel_case_types)] mod dvec; #[path="iter-trait"] +#[warn(non_camel_case_types)] mod dvec_iter { #[path = "dvec.rs"] mod inst; } +#[warn(non_camel_case_types)] mod dlist; #[path="iter-trait"] +#[warn(non_camel_case_types)] mod dlist_iter { #[path ="dlist.rs"] mod inst; } +#[warn(non_camel_case_types)] mod send_map; // Concurrency diff --git a/src/libcore/core.rs b/src/libcore/core.rs index f6a721d102a..1fb831b46fa 100644 --- a/src/libcore/core.rs +++ b/src/libcore/core.rs @@ -6,25 +6,25 @@ import option::{some, none}; import option = option::option; import Path = path::Path; import tuple::{TupleOps, ExtendedTupleOps}; -import str::{str_slice, unique_str}; -import vec::{const_vector, copyable_vector, immutable_vector}; -import vec::{immutable_copyable_vector, iter_trait_extensions}; -import iter::{base_iter, extended_iter, copyable_iter, times, timesi}; +import str::{StrSlice, UniqueStr}; +import vec::{ConstVector, CopyableVector, ImmutableVector}; +import vec::{ImmutableCopyableVector, IterTraitExtensions}; +import iter::{BaseIter, ExtendedIter, CopyableIter, Times, TimesIx}; import num::Num; -import ptr::ptr; +import ptr::Ptr; import to_str::ToStr; export Path, option, some, none, unreachable; export extensions; // The following exports are the extension impls for numeric types -export Num, times, timesi; +export Num, Times, TimesIx; // The following exports are the common traits -export str_slice, unique_str; -export const_vector, copyable_vector, immutable_vector; -export immutable_copyable_vector, iter_trait_extensions; -export base_iter, copyable_iter, extended_iter; +export StrSlice, UniqueStr; +export ConstVector, CopyableVector, ImmutableVector; +export ImmutableCopyableVector, IterTraitExtensions; +export BaseIter, CopyableIter, ExtendedIter; export TupleOps, ExtendedTupleOps; -export ptr; +export Ptr; export ToStr; // The following exports are the core operators and kinds diff --git a/src/libcore/dlist.rs b/src/libcore/dlist.rs index b3f56109ee4..f835344f2d1 100644 --- a/src/libcore/dlist.rs +++ b/src/libcore/dlist.rs @@ -8,25 +8,25 @@ * Do not use ==, !=, <, etc on doubly-linked lists -- it may not terminate. */ -export dlist, dlist_node; +export DList, dlist, dlist_node; export new_dlist, from_elem, from_vec, extensions; -type dlist_link<T> = option<dlist_node<T>>; +type DListLink<T> = option<DListNode<T>>; -enum dlist_node<T> = @{ +enum DListNode<T> = @{ data: T, mut linked: bool, // for assertions - mut prev: dlist_link<T>, - mut next: dlist_link<T> + mut prev: DListLink<T>, + mut next: DListLink<T> }; -enum dlist<T> = @{ +enum DList<T> = @{ mut size: uint, - mut hd: dlist_link<T>, - mut tl: dlist_link<T>, + mut hd: DListLink<T>, + mut tl: DListLink<T>, }; -priv impl<T> dlist_node<T> { +priv impl<T> DListNode<T> { pure fn assert_links() { match self.next { some(neighbour) => match neighbour.prev { @@ -49,26 +49,26 @@ priv impl<T> dlist_node<T> { } } -impl<T> dlist_node<T> { +impl<T> DListNode<T> { /// Get the next node in the list, if there is one. - pure fn next_link() -> option<dlist_node<T>> { + pure fn next_link() -> option<DListNode<T>> { self.assert_links(); self.next } /// Get the next node in the list, failing if there isn't one. - pure fn next_node() -> dlist_node<T> { + pure fn next_node() -> DListNode<T> { match self.next_link() { some(nobe) => nobe, none => fail ~"This dlist node has no next neighbour." } } /// Get the previous node in the list, if there is one. - pure fn prev_link() -> option<dlist_node<T>> { + pure fn prev_link() -> option<DListNode<T>> { self.assert_links(); self.prev } /// Get the previous node in the list, failing if there isn't one. - pure fn prev_node() -> dlist_node<T> { + pure fn prev_node() -> DListNode<T> { match self.prev_link() { some(nobe) => nobe, none => fail ~"This dlist node has no previous neighbour." @@ -77,24 +77,24 @@ impl<T> dlist_node<T> { } /// Creates a new dlist node with the given data. -pure fn new_dlist_node<T>(+data: T) -> dlist_node<T> { - dlist_node(@{data: data, mut linked: false, +pure fn new_dlist_node<T>(+data: T) -> DListNode<T> { + DListNode(@{data: data, mut linked: false, mut prev: none, mut next: none}) } /// Creates a new, empty dlist. -pure fn new_dlist<T>() -> dlist<T> { - dlist(@{mut size: 0, mut hd: none, mut tl: none}) +pure fn new_dlist<T>() -> DList<T> { + DList(@{mut size: 0, mut hd: none, mut tl: none}) } /// Creates a new dlist with a single element -pure fn from_elem<T>(+data: T) -> dlist<T> { +pure fn from_elem<T>(+data: T) -> DList<T> { let list = new_dlist(); unchecked { list.push(data); } list } -fn from_vec<T: copy>(+vec: &[T]) -> dlist<T> { +fn from_vec<T: copy>(+vec: &[T]) -> DList<T> { do vec::foldl(new_dlist(), vec) |list,data| { list.push(data); // Iterating left-to-right -- add newly to the tail. list @@ -103,7 +103,7 @@ fn from_vec<T: copy>(+vec: &[T]) -> dlist<T> { /// Produce a list from a list of lists, leaving no elements behind in the /// input. O(number of sub-lists). -fn concat<T>(lists: dlist<dlist<T>>) -> dlist<T> { +fn concat<T>(lists: DList<DList<T>>) -> DList<T> { let result = new_dlist(); while !lists.is_empty() { result.append(lists.pop().get()); @@ -111,12 +111,12 @@ fn concat<T>(lists: dlist<dlist<T>>) -> dlist<T> { result } -priv impl<T> dlist<T> { - pure fn new_link(-data: T) -> dlist_link<T> { - some(dlist_node(@{data: data, mut linked: true, +priv impl<T> DList<T> { + pure fn new_link(-data: T) -> DListLink<T> { + some(DListNode(@{data: data, mut linked: true, mut prev: none, mut next: none})) } - pure fn assert_mine(nobe: dlist_node<T>) { + pure fn assert_mine(nobe: DListNode<T>) { // These asserts could be stronger if we had node-root back-pointers, // but those wouldn't allow for O(1) append. if self.size == 0 { @@ -130,7 +130,7 @@ priv impl<T> dlist<T> { fail ~"That node isn't on this dlist." } } - fn make_mine(nobe: dlist_node<T>) { + fn make_mine(nobe: DListNode<T>) { if nobe.prev.is_some() || nobe.next.is_some() || nobe.linked { fail ~"Cannot insert node that's already on a dlist!" } @@ -139,7 +139,7 @@ priv impl<T> dlist<T> { // Link two nodes together. If either of them are 'none', also sets // the head and/or tail pointers appropriately. #[inline(always)] - fn link(+before: dlist_link<T>, +after: dlist_link<T>) { + fn link(+before: DListLink<T>, +after: DListLink<T>) { match before { some(neighbour) => neighbour.next = after, none => self.hd = after @@ -150,7 +150,7 @@ priv impl<T> dlist<T> { } } // Remove a node from the list. - fn unlink(nobe: dlist_node<T>) { + fn unlink(nobe: DListNode<T>) { self.assert_mine(nobe); assert self.size > 0; self.link(nobe.prev, nobe.next); @@ -160,24 +160,24 @@ priv impl<T> dlist<T> { self.size -= 1; } - fn add_head(+nobe: dlist_link<T>) { + fn add_head(+nobe: DListLink<T>) { self.link(nobe, self.hd); // Might set tail too. self.hd = nobe; self.size += 1; } - fn add_tail(+nobe: dlist_link<T>) { + fn add_tail(+nobe: DListLink<T>) { self.link(self.tl, nobe); // Might set head too. self.tl = nobe; self.size += 1; } - fn insert_left(nobe: dlist_link<T>, neighbour: dlist_node<T>) { + fn insert_left(nobe: DListLink<T>, neighbour: DListNode<T>) { self.assert_mine(neighbour); assert self.size > 0; self.link(neighbour.prev, nobe); self.link(nobe, some(neighbour)); self.size += 1; } - fn insert_right(neighbour: dlist_node<T>, nobe: dlist_link<T>) { + fn insert_right(neighbour: DListNode<T>, nobe: DListLink<T>) { self.assert_mine(neighbour); assert self.size > 0; self.link(nobe, neighbour.next); @@ -186,7 +186,7 @@ priv impl<T> dlist<T> { } } -impl<T> dlist<T> { +impl<T> DList<T> { /// Get the size of the list. O(1). pure fn len() -> uint { self.size } /// Returns true if the list is empty. O(1). @@ -202,7 +202,7 @@ impl<T> dlist<T> { * Add data to the head of the list, and get the new containing * node. O(1). */ - fn push_head_n(+data: T) -> dlist_node<T> { + fn push_head_n(+data: T) -> DListNode<T> { let mut nobe = self.new_link(data); self.add_head(nobe); option::get(nobe) @@ -215,7 +215,7 @@ impl<T> dlist<T> { * Add data to the tail of the list, and get the new containing * node. O(1). */ - fn push_n(+data: T) -> dlist_node<T> { + fn push_n(+data: T) -> DListNode<T> { let mut nobe = self.new_link(data); self.add_tail(nobe); option::get(nobe) @@ -224,14 +224,14 @@ impl<T> dlist<T> { * Insert data into the middle of the list, left of the given node. * O(1). */ - fn insert_before(+data: T, neighbour: dlist_node<T>) { + fn insert_before(+data: T, neighbour: DListNode<T>) { self.insert_left(self.new_link(data), neighbour); } /** * Insert an existing node in the middle of the list, left of the * given node. O(1). */ - fn insert_n_before(nobe: dlist_node<T>, neighbour: dlist_node<T>) { + fn insert_n_before(nobe: DListNode<T>, neighbour: DListNode<T>) { self.make_mine(nobe); self.insert_left(some(nobe), neighbour); } @@ -239,7 +239,7 @@ impl<T> dlist<T> { * Insert data in the middle of the list, left of the given node, * and get its containing node. O(1). */ - fn insert_before_n(+data: T, neighbour: dlist_node<T>) -> dlist_node<T> { + fn insert_before_n(+data: T, neighbour: DListNode<T>) -> DListNode<T> { let mut nobe = self.new_link(data); self.insert_left(nobe, neighbour); option::get(nobe) @@ -248,14 +248,14 @@ impl<T> dlist<T> { * Insert data into the middle of the list, right of the given node. * O(1). */ - fn insert_after(+data: T, neighbour: dlist_node<T>) { + fn insert_after(+data: T, neighbour: DListNode<T>) { self.insert_right(neighbour, self.new_link(data)); } /** * Insert an existing node in the middle of the list, right of the * given node. O(1). */ - fn insert_n_after(nobe: dlist_node<T>, neighbour: dlist_node<T>) { + fn insert_n_after(nobe: DListNode<T>, neighbour: DListNode<T>) { self.make_mine(nobe); self.insert_right(neighbour, some(nobe)); } @@ -263,38 +263,38 @@ impl<T> dlist<T> { * Insert data in the middle of the list, right of the given node, * and get its containing node. O(1). */ - fn insert_after_n(+data: T, neighbour: dlist_node<T>) -> dlist_node<T> { + fn insert_after_n(+data: T, neighbour: DListNode<T>) -> DListNode<T> { let mut nobe = self.new_link(data); self.insert_right(neighbour, nobe); option::get(nobe) } /// Remove a node from the head of the list. O(1). - fn pop_n() -> option<dlist_node<T>> { + fn pop_n() -> option<DListNode<T>> { let hd = self.peek_n(); hd.map(|nobe| self.unlink(nobe)); hd } /// Remove a node from the tail of the list. O(1). - fn pop_tail_n() -> option<dlist_node<T>> { + fn pop_tail_n() -> option<DListNode<T>> { let tl = self.peek_tail_n(); tl.map(|nobe| self.unlink(nobe)); tl } /// Get the node at the list's head. O(1). - pure fn peek_n() -> option<dlist_node<T>> { self.hd } + pure fn peek_n() -> option<DListNode<T>> { self.hd } /// Get the node at the list's tail. O(1). - pure fn peek_tail_n() -> option<dlist_node<T>> { self.tl } + pure fn peek_tail_n() -> option<DListNode<T>> { self.tl } /// Get the node at the list's head, failing if empty. O(1). - pure fn head_n() -> dlist_node<T> { + pure fn head_n() -> DListNode<T> { match self.hd { some(nobe) => nobe, none => fail ~"Attempted to get the head of an empty dlist." } } /// Get the node at the list's tail, failing if empty. O(1). - pure fn tail_n() -> dlist_node<T> { + pure fn tail_n() -> DListNode<T> { match self.tl { some(nobe) => nobe, none => fail ~"Attempted to get the tail of an empty dlist." @@ -302,13 +302,13 @@ impl<T> dlist<T> { } /// Remove a node from anywhere in the list. O(1). - fn remove(nobe: dlist_node<T>) { self.unlink(nobe); } + fn remove(nobe: DListNode<T>) { self.unlink(nobe); } /** * Empty another list onto the end of this list, joining this list's tail * to the other list's head. O(1). */ - fn append(them: dlist<T>) { + fn append(them: DList<T>) { if box::ptr_eq(*self, *them) { fail ~"Cannot append a dlist to itself!" } @@ -325,7 +325,7 @@ impl<T> dlist<T> { * Empty another list onto the start of this list, joining the other * list's tail to this list's head. O(1). */ - fn prepend(them: dlist<T>) { + fn prepend(them: DList<T>) { if box::ptr_eq(*self, *them) { fail ~"Cannot prepend a dlist to itself!" } @@ -363,7 +363,7 @@ impl<T> dlist<T> { } /// Iterate over nodes. - pure fn each_node(f: fn(dlist_node<T>) -> bool) { + pure fn each_node(f: fn(DListNode<T>) -> bool) { let mut link = self.peek_n(); while link.is_some() { let nobe = link.get(); @@ -415,7 +415,7 @@ impl<T> dlist<T> { } } -impl<T: copy> dlist<T> { +impl<T: copy> DList<T> { /// Remove data from the head of the list. O(1). fn pop() -> option<T> { self.pop_n().map (|nobe| nobe.data) } /// Remove data from the tail of the list. O(1). diff --git a/src/libcore/dvec.rs b/src/libcore/dvec.rs index 1f349b67002..ecbff6f12df 100644 --- a/src/libcore/dvec.rs +++ b/src/libcore/dvec.rs @@ -12,6 +12,7 @@ import unsafe::reinterpret_cast; import ptr::null; +export DVec; export dvec; export from_elem; export from_vec; @@ -49,36 +50,36 @@ export unwrap; * pointers achieved about 103 million pushes/second. Using an option * type could only produce 47 million pushes/second. */ -type dvec_<A> = { +type DVec_<A> = { mut data: ~[mut A] }; -enum dvec<A> { - dvec_(dvec_<A>) +enum DVec<A> { + DVec_(DVec_<A>) } /// Creates a new, empty dvec -fn dvec<A>() -> dvec<A> { - dvec_({mut data: ~[mut]}) +fn dvec<A>() -> DVec<A> { + DVec_({mut data: ~[mut]}) } /// Creates a new dvec with a single element -fn from_elem<A>(+e: A) -> dvec<A> { - dvec_({mut data: ~[mut e]}) +fn from_elem<A>(+e: A) -> DVec<A> { + DVec_({mut data: ~[mut e]}) } /// Creates a new dvec with the contents of a vector -fn from_vec<A>(+v: ~[mut A]) -> dvec<A> { - dvec_({mut data: v}) +fn from_vec<A>(+v: ~[mut A]) -> DVec<A> { + DVec_({mut data: v}) } /// Consumes the vector and returns its contents -fn unwrap<A>(+d: dvec<A>) -> ~[mut A] { - let dvec_({data: v}) <- d; +fn unwrap<A>(+d: DVec<A>) -> ~[mut A] { + let DVec_({data: v}) <- d; return v; } -priv impl<A> dvec<A> { +priv impl<A> DVec<A> { pure fn check_not_borrowed() { unsafe { let data: *() = unsafe::reinterpret_cast(self.data); @@ -110,7 +111,7 @@ priv impl<A> dvec<A> { // In theory, most everything should work with any A, but in practice // almost nothing works without the copy bound due to limitations // around closures. -impl<A> dvec<A> { +impl<A> DVec<A> { /// Reserves space for N elements fn reserve(count: uint) { vec::reserve(self.data, count) @@ -191,7 +192,7 @@ impl<A> dvec<A> { } } -impl<A: copy> dvec<A> { +impl<A: copy> DVec<A> { /** * Append all elements of a vector to the end of the list * @@ -308,7 +309,7 @@ impl<A: copy> dvec<A> { } } -impl<A:copy> dvec<A>: index<uint,A> { +impl<A:copy> DVec<A>: index<uint,A> { pure fn index(&&idx: uint) -> A { self.get_elt(idx) } diff --git a/src/libcore/either.rs b/src/libcore/either.rs index 6b9c1846c37..6e2698ce8ab 100644 --- a/src/libcore/either.rs +++ b/src/libcore/either.rs @@ -7,13 +7,13 @@ import result::result; /// The either type -enum either<T, U> { - left(T), - right(U) +enum Either<T, U> { + Left(T), + Right(U) } fn either<T, U, V>(f_left: fn((&T)) -> V, - f_right: fn((&U)) -> V, value: &either<T, U>) -> V { + f_right: fn((&U)) -> V, value: &Either<T, U>) -> V { /*! * Applies a function based on the given either value * @@ -23,38 +23,38 @@ fn either<T, U, V>(f_left: fn((&T)) -> V, */ match *value { - left(ref l) => f_left(l), - right(ref r) => f_right(r) + Left(ref l) => f_left(l), + Right(ref r) => f_right(r) } } -fn lefts<T: copy, U>(eithers: &[either<T, U>]) -> ~[T] { +fn lefts<T: copy, U>(eithers: &[Either<T, U>]) -> ~[T] { //! Extracts from a vector of either all the left values let mut result: ~[T] = ~[]; for vec::each(eithers) |elt| { match elt { - left(l) => vec::push(result, l), + Left(l) => vec::push(result, l), _ => { /* fallthrough */ } } } return result; } -fn rights<T, U: copy>(eithers: &[either<T, U>]) -> ~[U] { +fn rights<T, U: copy>(eithers: &[Either<T, U>]) -> ~[U] { //! Extracts from a vector of either all the right values let mut result: ~[U] = ~[]; for vec::each(eithers) |elt| { match elt { - right(r) => vec::push(result, r), + Right(r) => vec::push(result, r), _ => { /* fallthrough */ } } } return result; } -fn partition<T: copy, U: copy>(eithers: &[either<T, U>]) +fn partition<T: copy, U: copy>(eithers: &[Either<T, U>]) -> {lefts: ~[T], rights: ~[U]} { /*! * Extracts from a vector of either all the left values and right values @@ -67,23 +67,23 @@ fn partition<T: copy, U: copy>(eithers: &[either<T, U>]) let mut rights: ~[U] = ~[]; for vec::each(eithers) |elt| { match elt { - left(l) => vec::push(lefts, l), - right(r) => vec::push(rights, r) + Left(l) => vec::push(lefts, l), + Right(r) => vec::push(rights, r) } } return {lefts: lefts, rights: rights}; } -pure fn flip<T: copy, U: copy>(eith: &either<T, U>) -> either<U, T> { +pure fn flip<T: copy, U: copy>(eith: &Either<T, U>) -> Either<U, T> { //! Flips between left and right of a given either match *eith { - right(r) => left(r), - left(l) => right(l) + Right(r) => Left(r), + Left(l) => Right(l) } } -pure fn to_result<T: copy, U: copy>(eith: &either<T, U>) -> result<U, T> { +pure fn to_result<T: copy, U: copy>(eith: &Either<T, U>) -> result<U, T> { /*! * Converts either::t to a result::t * @@ -92,26 +92,26 @@ pure fn to_result<T: copy, U: copy>(eith: &either<T, U>) -> result<U, T> { */ match *eith { - right(r) => result::ok(r), - left(l) => result::err(l) + Right(r) => result::ok(r), + Left(l) => result::err(l) } } -pure fn is_left<T, U>(eith: &either<T, U>) -> bool { +pure fn is_left<T, U>(eith: &Either<T, U>) -> bool { //! Checks whether the given value is a left - match *eith { left(_) => true, _ => false } + match *eith { Left(_) => true, _ => false } } -pure fn is_right<T, U>(eith: &either<T, U>) -> bool { +pure fn is_right<T, U>(eith: &Either<T, U>) -> bool { //! Checks whether the given value is a right - match *eith { right(_) => true, _ => false } + match *eith { Right(_) => true, _ => false } } #[test] fn test_either_left() { - let val = left(10); + let val = Left(10); fn f_left(x: &int) -> bool { *x == 10 } fn f_right(_x: &uint) -> bool { false } assert (either(f_left, f_right, &val)); @@ -119,7 +119,7 @@ fn test_either_left() { #[test] fn test_either_right() { - let val = right(10u); + let val = Right(10u); fn f_left(_x: &int) -> bool { false } fn f_right(x: &uint) -> bool { *x == 10u } assert (either(f_left, f_right, &val)); @@ -127,49 +127,49 @@ fn test_either_right() { #[test] fn test_lefts() { - let input = ~[left(10), right(11), left(12), right(13), left(14)]; + let input = ~[Left(10), Right(11), Left(12), Right(13), Left(14)]; let result = lefts(input); assert (result == ~[10, 12, 14]); } #[test] fn test_lefts_none() { - let input: ~[either<int, int>] = ~[right(10), right(10)]; + let input: ~[Either<int, int>] = ~[Right(10), Right(10)]; let result = lefts(input); assert (vec::len(result) == 0u); } #[test] fn test_lefts_empty() { - let input: ~[either<int, int>] = ~[]; + let input: ~[Either<int, int>] = ~[]; let result = lefts(input); assert (vec::len(result) == 0u); } #[test] fn test_rights() { - let input = ~[left(10), right(11), left(12), right(13), left(14)]; + let input = ~[Left(10), Right(11), Left(12), Right(13), Left(14)]; let result = rights(input); assert (result == ~[11, 13]); } #[test] fn test_rights_none() { - let input: ~[either<int, int>] = ~[left(10), left(10)]; + let input: ~[Either<int, int>] = ~[Left(10), Left(10)]; let result = rights(input); assert (vec::len(result) == 0u); } #[test] fn test_rights_empty() { - let input: ~[either<int, int>] = ~[]; + let input: ~[Either<int, int>] = ~[]; let result = rights(input); assert (vec::len(result) == 0u); } #[test] fn test_partition() { - let input = ~[left(10), right(11), left(12), right(13), left(14)]; + let input = ~[Left(10), Right(11), Left(12), Right(13), Left(14)]; let result = partition(input); assert (result.lefts[0] == 10); assert (result.lefts[1] == 12); @@ -180,7 +180,7 @@ fn test_partition() { #[test] fn test_partition_no_lefts() { - let input: ~[either<int, int>] = ~[right(10), right(11)]; + let input: ~[Either<int, int>] = ~[Right(10), Right(11)]; let result = partition(input); assert (vec::len(result.lefts) == 0u); assert (vec::len(result.rights) == 2u); @@ -188,7 +188,7 @@ fn test_partition_no_lefts() { #[test] fn test_partition_no_rights() { - let input: ~[either<int, int>] = ~[left(10), left(11)]; + let input: ~[Either<int, int>] = ~[Left(10), Left(11)]; let result = partition(input); assert (vec::len(result.lefts) == 2u); assert (vec::len(result.rights) == 0u); @@ -196,7 +196,7 @@ fn test_partition_no_rights() { #[test] fn test_partition_empty() { - let input: ~[either<int, int>] = ~[]; + let input: ~[Either<int, int>] = ~[]; let result = partition(input); assert (vec::len(result.lefts) == 0u); assert (vec::len(result.rights) == 0u); diff --git a/src/libcore/future.rs b/src/libcore/future.rs index 79259c785fe..a935a50ddb6 100644 --- a/src/libcore/future.rs +++ b/src/libcore/future.rs @@ -15,7 +15,7 @@ * ~~~ */ -import either::either; +import either::Either; import pipes::recv; export future; @@ -32,7 +32,7 @@ export future_pipe; #[doc = "The future type"] enum future<A> = { - mut v: either<@A, fn@() -> A> + mut v: Either<@A, fn@() -> A> }; /// Methods on the `future` type @@ -60,7 +60,7 @@ fn from_value<A>(+val: A) -> future<A> { */ future({ - mut v: either::left(@val) + mut v: either::Left(@val) }) } @@ -97,7 +97,7 @@ fn from_fn<A>(f: fn@() -> A) -> future<A> { */ future({ - mut v: either::right(f) + mut v: either::Right(f) }) } @@ -124,10 +124,10 @@ fn with<A,B>(future: &future<A>, blk: fn((&A)) -> B) -> B { //! Work with the value without copying it let v = match copy future.v { - either::left(v) => v, - either::right(f) => { + either::Left(v) => v, + either::Right(f) => { let v = @f(); - future.v = either::left(v); + future.v = either::Left(v); v } }; diff --git a/src/libcore/int-template.rs b/src/libcore/int-template.rs index 0819d702456..9ebfec47c7c 100644 --- a/src/libcore/int-template.rs +++ b/src/libcore/int-template.rs @@ -88,7 +88,7 @@ impl T: num::Num { static pure fn from_int(n: int) -> T { return n as T; } } -impl T: iter::times { +impl T: iter::Times { #[inline(always)] #[doc = "A convenience form for basic iteration. Given a variable `x` \ of any numeric type, the expression `for x.times { /* anything */ }` \ @@ -108,7 +108,7 @@ impl T: iter::times { } } -impl T: iter::timesi { +impl T: iter::TimesIx { #[inline(always)] /// Like `times`, but provides an index fn timesi(it: fn(uint) -> bool) { @@ -255,7 +255,7 @@ fn test_interfaces() { #[test] fn test_times() { - import iter::times; + import iter::Times; let ten = 10 as T; let mut accum = 0; for ten.times { accum += 1; } @@ -266,6 +266,6 @@ fn test_times() { #[should_fail] #[ignore(cfg(windows))] fn test_times_negative() { - import iter::times; + import iter::Times; for (-10).times { log(error, ~"nope!"); } } diff --git a/src/libcore/io.rs b/src/libcore/io.rs index c01672b5c73..d85ffb4981d 100644 --- a/src/libcore/io.rs +++ b/src/libcore/io.rs @@ -6,7 +6,7 @@ Basic input/output import result::result; -import dvec::dvec; +import dvec::{DVec, dvec}; import libc::{c_int, c_long, c_uint, c_void, size_t, ssize_t}; import libc::consts::os::posix88::*; import libc::consts::os::extra::*; @@ -657,7 +657,7 @@ fn stderr() -> Writer { fd_writer(libc::STDERR_FILENO as c_int, false) } fn print(s: &str) { stdout().write_str(s); } fn println(s: &str) { stdout().write_line(s); } -type MemBuffer = @{buf: dvec<u8>, mut pos: uint}; +type MemBuffer = @{buf: DVec<u8>, mut pos: uint}; impl MemBuffer: Writer { fn write(v: &[const u8]) { diff --git a/src/libcore/iter-trait.rs b/src/libcore/iter-trait.rs index d448292b1aa..5aeb958f5b2 100644 --- a/src/libcore/iter-trait.rs +++ b/src/libcore/iter-trait.rs @@ -5,12 +5,12 @@ import inst::{IMPL_T, EACH, SIZE_HINT}; export extensions; -impl<A> IMPL_T<A>: iter::base_iter<A> { +impl<A> IMPL_T<A>: iter::BaseIter<A> { fn each(blk: fn(A) -> bool) { EACH(self, blk) } fn size_hint() -> option<uint> { SIZE_HINT(self) } } -impl<A> IMPL_T<A>: iter::extended_iter<A> { +impl<A> IMPL_T<A>: iter::ExtendedIter<A> { fn eachi(blk: fn(uint, A) -> bool) { iter::eachi(self, blk) } fn all(blk: fn(A) -> bool) -> bool { iter::all(self, blk) } fn any(blk: fn(A) -> bool) -> bool { iter::any(self, blk) } @@ -24,7 +24,7 @@ impl<A> IMPL_T<A>: iter::extended_iter<A> { } } -impl<A: copy> IMPL_T<A>: iter::copyable_iter<A> { +impl<A: copy> IMPL_T<A>: iter::CopyableIter<A> { fn filter_to_vec(pred: fn(A) -> bool) -> ~[A] { iter::filter_to_vec(self, pred) } diff --git a/src/libcore/iter-trait/dlist.rs b/src/libcore/iter-trait/dlist.rs index 9d8d147ffd7..91d6ffa765a 100644 --- a/src/libcore/iter-trait/dlist.rs +++ b/src/libcore/iter-trait/dlist.rs @@ -1,4 +1,5 @@ -type IMPL_T<A> = dlist::dlist<A>; +#[allow(non_camel_case_types)] +type IMPL_T<A> = dlist::DList<A>; /** * Iterates through the current contents. diff --git a/src/libcore/iter-trait/dvec.rs b/src/libcore/iter-trait/dvec.rs index d40eead14ff..5c02f8b5dea 100644 --- a/src/libcore/iter-trait/dvec.rs +++ b/src/libcore/iter-trait/dvec.rs @@ -1,4 +1,5 @@ -type IMPL_T<A> = dvec::dvec<A>; +#[allow(non_camel_case_types)] +type IMPL_T<A> = dvec::DVec<A>; /** * Iterates through the current contents. diff --git a/src/libcore/iter.rs b/src/libcore/iter.rs index 2cb3369dbc7..06a1c6c9fba 100644 --- a/src/libcore/iter.rs +++ b/src/libcore/iter.rs @@ -1,9 +1,9 @@ -trait base_iter<A> { +trait BaseIter<A> { fn each(blk: fn(A) -> bool); fn size_hint() -> option<uint>; } -trait extended_iter<A> { +trait ExtendedIter<A> { fn eachi(blk: fn(uint, A) -> bool); fn all(blk: fn(A) -> bool) -> bool; fn any(blk: fn(A) -> bool) -> bool; @@ -13,14 +13,14 @@ trait extended_iter<A> { fn position(f: fn(A) -> bool) -> option<uint>; } -trait times { +trait Times { fn times(it: fn() -> bool); } -trait timesi{ +trait TimesIx{ fn timesi(it: fn(uint) -> bool); } -trait copyable_iter<A:copy> { +trait CopyableIter<A:copy> { fn filter_to_vec(pred: fn(A) -> bool) -> ~[A]; fn map_to_vec<B>(op: fn(A) -> B) -> ~[B]; fn to_vec() -> ~[A]; @@ -29,7 +29,7 @@ trait copyable_iter<A:copy> { fn find(p: fn(A) -> bool) -> option<A>; } -fn eachi<A,IA:base_iter<A>>(self: IA, blk: fn(uint, A) -> bool) { +fn eachi<A,IA:BaseIter<A>>(self: IA, blk: fn(uint, A) -> bool) { let mut i = 0u; for self.each |a| { if !blk(i, a) { break; } @@ -37,21 +37,21 @@ fn eachi<A,IA:base_iter<A>>(self: IA, blk: fn(uint, A) -> bool) { } } -fn all<A,IA:base_iter<A>>(self: IA, blk: fn(A) -> bool) -> bool { +fn all<A,IA:BaseIter<A>>(self: IA, blk: fn(A) -> bool) -> bool { for self.each |a| { if !blk(a) { return false; } } return true; } -fn any<A,IA:base_iter<A>>(self: IA, blk: fn(A) -> bool) -> bool { +fn any<A,IA:BaseIter<A>>(self: IA, blk: fn(A) -> bool) -> bool { for self.each |a| { if blk(a) { return true; } } return false; } -fn filter_to_vec<A:copy,IA:base_iter<A>>(self: IA, +fn filter_to_vec<A:copy,IA:BaseIter<A>>(self: IA, prd: fn(A) -> bool) -> ~[A] { let mut result = ~[]; self.size_hint().iter(|hint| vec::reserve(result, hint)); @@ -61,7 +61,7 @@ fn filter_to_vec<A:copy,IA:base_iter<A>>(self: IA, return result; } -fn map_to_vec<A:copy,B,IA:base_iter<A>>(self: IA, op: fn(A) -> B) -> ~[B] { +fn map_to_vec<A:copy,B,IA:BaseIter<A>>(self: IA, op: fn(A) -> B) -> ~[B] { let mut result = ~[]; self.size_hint().iter(|hint| vec::reserve(result, hint)); for self.each |a| { @@ -70,7 +70,7 @@ fn map_to_vec<A:copy,B,IA:base_iter<A>>(self: IA, op: fn(A) -> B) -> ~[B] { return result; } -fn flat_map_to_vec<A:copy,B:copy,IA:base_iter<A>,IB:base_iter<B>>( +fn flat_map_to_vec<A:copy,B:copy,IA:BaseIter<A>,IB:BaseIter<B>>( self: IA, op: fn(A) -> IB) -> ~[B] { let mut result = ~[]; @@ -82,7 +82,7 @@ fn flat_map_to_vec<A:copy,B:copy,IA:base_iter<A>,IB:base_iter<B>>( return result; } -fn foldl<A,B,IA:base_iter<A>>(self: IA, +b0: B, blk: fn(B, A) -> B) -> B { +fn foldl<A,B,IA:BaseIter<A>>(self: IA, +b0: B, blk: fn(B, A) -> B) -> B { let mut b <- b0; for self.each |a| { b = blk(b, a); @@ -90,18 +90,18 @@ fn foldl<A,B,IA:base_iter<A>>(self: IA, +b0: B, blk: fn(B, A) -> B) -> B { return b; } -fn to_vec<A:copy,IA:base_iter<A>>(self: IA) -> ~[A] { +fn to_vec<A:copy,IA:BaseIter<A>>(self: IA) -> ~[A] { foldl::<A,~[A],IA>(self, ~[], |r, a| vec::append(r, ~[a])) } -fn contains<A,IA:base_iter<A>>(self: IA, x: A) -> bool { +fn contains<A,IA:BaseIter<A>>(self: IA, x: A) -> bool { for self.each |a| { if a == x { return true; } } return false; } -fn count<A,IA:base_iter<A>>(self: IA, x: A) -> uint { +fn count<A,IA:BaseIter<A>>(self: IA, x: A) -> uint { do foldl(self, 0u) |count, value| { if value == x { count + 1u @@ -111,7 +111,7 @@ fn count<A,IA:base_iter<A>>(self: IA, x: A) -> uint { } } -fn position<A,IA:base_iter<A>>(self: IA, f: fn(A) -> bool) +fn position<A,IA:BaseIter<A>>(self: IA, f: fn(A) -> bool) -> option<uint> { let mut i = 0; for self.each |a| { @@ -133,7 +133,7 @@ fn repeat(times: uint, blk: fn() -> bool) { } } -fn min<A:copy,IA:base_iter<A>>(self: IA) -> A { +fn min<A:copy,IA:BaseIter<A>>(self: IA) -> A { match do foldl::<A,option<A>,IA>(self, none) |a, b| { match a { some(a_) if a_ < b => { @@ -149,7 +149,7 @@ fn min<A:copy,IA:base_iter<A>>(self: IA) -> A { } } -fn max<A:copy,IA:base_iter<A>>(self: IA) -> A { +fn max<A:copy,IA:BaseIter<A>>(self: IA) -> A { match do foldl::<A,option<A>,IA>(self, none) |a, b| { match a { some(a_) if a_ > b => { diff --git a/src/libcore/os.rs b/src/libcore/os.rs index ec4485bb123..7d5e98c08bd 100644 --- a/src/libcore/os.rs +++ b/src/libcore/os.rs @@ -177,16 +177,16 @@ mod global_env { do priv::weaken_task |weak_po| { loop { match comm::select2(msg_po, weak_po) { - either::left(MsgGetEnv(n, resp_ch)) => { + either::Left(MsgGetEnv(n, resp_ch)) => { comm::send(resp_ch, impl::getenv(n)) } - either::left(MsgSetEnv(n, v, resp_ch)) => { + either::Left(MsgSetEnv(n, v, resp_ch)) => { comm::send(resp_ch, impl::setenv(n, v)) } - either::left(MsgEnv(resp_ch)) => { + either::Left(MsgEnv(resp_ch)) => { comm::send(resp_ch, impl::env()) } - either::right(_) => break + either::Right(_) => break } } } diff --git a/src/libcore/pipes.rs b/src/libcore/pipes.rs index ba8ac5cae87..6de2059d2de 100644 --- a/src/libcore/pipes.rs +++ b/src/libcore/pipes.rs @@ -77,7 +77,7 @@ bounded and unbounded protocols allows for less code duplication. #[forbid(deprecated_pattern)]; import unsafe::{forget, reinterpret_cast, transmute}; -import either::{either, left, right}; +import either::{Either, Left, Right}; import option::unwrap; // Things used by code generated by the pipe compiler. @@ -658,15 +658,15 @@ this case, `select2` may return either `left` or `right`. fn select2<A: send, Ab: send, B: send, Bb: send>( +a: recv_packet_buffered<A, Ab>, +b: recv_packet_buffered<B, Bb>) - -> either<(option<A>, recv_packet_buffered<B, Bb>), + -> Either<(option<A>, recv_packet_buffered<B, Bb>), (recv_packet_buffered<A, Ab>, option<B>)> { let i = wait_many([a.header(), b.header()]/_); unsafe { match i { - 0 => left((try_recv(a), b)), - 1 => right((a, try_recv(b))), + 0 => Left((try_recv(a), b)), + 1 => Right((a, try_recv(b))), _ => fail ~"select2 return an invalid packet" } } @@ -687,10 +687,10 @@ fn selecti<T: selectable>(endpoints: &[T]) -> uint { } /// Returns 0 or 1 depending on which endpoint is ready to receive -fn select2i<A: selectable, B: selectable>(a: &A, b: &B) -> either<(), ()> { +fn select2i<A: selectable, B: selectable>(a: &A, b: &B) -> Either<(), ()> { match wait_many([a.header(), b.header()]/_) { - 0 => left(()), - 1 => right(()), + 0 => Left(()), + 1 => Right(()), _ => fail ~"wait returned unexpected index" } } @@ -1117,28 +1117,28 @@ fn shared_chan<T:send>(+c: chan<T>) -> shared_chan<T> { /// Receive a message from one of two endpoints. trait select2<T: send, U: send> { /// Receive a message or return `none` if a connection closes. - fn try_select() -> either<option<T>, option<U>>; + fn try_select() -> Either<option<T>, option<U>>; /// Receive a message or fail if a connection closes. - fn select() -> either<T, U>; + fn select() -> Either<T, U>; } impl<T: send, U: send, Left: selectable recv<T>, Right: selectable recv<U>> (Left, Right): select2<T, U> { - fn select() -> either<T, U> { + fn select() -> Either<T, U> { match self { (lp, rp) => match select2i(&lp, &rp) { - left(()) => left (lp.recv()), - right(()) => right(rp.recv()) + Left(()) => Left (lp.recv()), + Right(()) => Right(rp.recv()) } } } - fn try_select() -> either<option<T>, option<U>> { + fn try_select() -> Either<option<T>, option<U>> { match self { (lp, rp) => match select2i(&lp, &rp) { - left(()) => left (lp.try_recv()), - right(()) => right(rp.try_recv()) + Left(()) => Left (lp.try_recv()), + Right(()) => Right(rp.try_recv()) } } } @@ -1204,7 +1204,7 @@ mod test { c1.send(~"abc"); match (p1, p2).select() { - right(_) => fail, + Right(_) => fail, _ => () } diff --git a/src/libcore/ptr.rs b/src/libcore/ptr.rs index b7b63af0afb..2c3ff0121ba 100644 --- a/src/libcore/ptr.rs +++ b/src/libcore/ptr.rs @@ -16,7 +16,7 @@ export to_uint; export ref_eq; export buf_len; export position; -export ptr; +export Ptr; import libc::{c_void, size_t}; @@ -156,13 +156,13 @@ fn ref_eq<T>(thing: &a/T, other: &b/T) -> bool { to_uint(thing) == to_uint(other) } -trait ptr { +trait Ptr { pure fn is_null() -> bool; pure fn is_not_null() -> bool; } /// Extension methods for pointers -impl<T> *T: ptr { +impl<T> *T: Ptr { /// Returns true if the pointer is equal to the null pointer. pure fn is_null() -> bool { is_null(self) } diff --git a/src/libcore/result.rs b/src/libcore/result.rs index 762191842b8..341d28e67e8 100644 --- a/src/libcore/result.rs +++ b/src/libcore/result.rs @@ -1,6 +1,6 @@ //! A type representing either success or failure -import either::either; +import either::Either; /// The result type enum result<T, U> { @@ -59,10 +59,10 @@ pure fn is_err<T, U>(res: result<T, U>) -> bool { * `ok` result variants are converted to `either::right` variants, `err` * result variants are converted to `either::left`. */ -pure fn to_either<T: copy, U: copy>(res: result<U, T>) -> either<T, U> { +pure fn to_either<T: copy, U: copy>(res: result<U, T>) -> Either<T, U> { match res { - ok(res) => either::right(res), - err(fail_) => either::left(fail_) + ok(res) => either::Right(res), + err(fail_) => either::Left(fail_) } } diff --git a/src/libcore/send_map.rs b/src/libcore/send_map.rs index 1a130e0e273..cb8d596cf88 100644 --- a/src/libcore/send_map.rs +++ b/src/libcore/send_map.rs @@ -10,28 +10,28 @@ Sendable hash maps. Very much a work in progress. * * The hash should concentrate entropy in the lower bits. */ -type hashfn<K> = pure fn~(K) -> uint; -type eqfn<K> = pure fn~(K, K) -> bool; +type HashFn<K> = pure fn~(K) -> uint; +type EqFn<K> = pure fn~(K, K) -> bool; /// Open addressing with linear probing. mod linear { - export linear_map, linear_map_with_capacity, public_methods; + export LinearMap, linear_map, linear_map_with_capacity, public_methods; const initial_capacity: uint = 32u; // 2^5 - type bucket<K,V> = {hash: uint, key: K, value: V}; - enum linear_map<K,V> { - linear_map_({ + type Bucket<K,V> = {hash: uint, key: K, value: V}; + enum LinearMap<K,V> { + LinearMap_({ hashfn: pure fn~(x: &K) -> uint, eqfn: pure fn~(x: &K, y: &K) -> bool, resize_at: uint, size: uint, - buckets: ~[option<bucket<K,V>>]}) + buckets: ~[option<Bucket<K,V>>]}) } // FIXME(#2979) -- with #2979 we could rewrite found_entry // to have type option<&bucket<K,V>> which would be nifty - enum search_result { - found_entry(uint), found_hole(uint), table_full + enum SearchResult { + FoundEntry(uint), FoundHole(uint), TableFull } fn resize_at(capacity: uint) -> uint { @@ -40,7 +40,7 @@ mod linear { fn linear_map<K,V>( +hashfn: pure fn~(x: &K) -> uint, - +eqfn: pure fn~(x: &K, y: &K) -> bool) -> linear_map<K,V> { + +eqfn: pure fn~(x: &K, y: &K) -> bool) -> LinearMap<K,V> { linear_map_with_capacity(hashfn, eqfn, 32) } @@ -48,9 +48,9 @@ mod linear { fn linear_map_with_capacity<K,V>( +hashfn: pure fn~(x: &K) -> uint, +eqfn: pure fn~(x: &K, y: &K) -> bool, - initial_capacity: uint) -> linear_map<K,V> { + initial_capacity: uint) -> LinearMap<K,V> { - linear_map_({ + LinearMap_({ hashfn: hashfn, eqfn: eqfn, resize_at: resize_at(initial_capacity), @@ -64,7 +64,7 @@ mod linear { unsafe::reinterpret_cast(p) } - priv impl<K, V> &const linear_map<K,V> { + priv impl<K, V> &const LinearMap<K,V> { #[inline(always)] pure fn to_bucket(h: uint) -> uint { // FIXME(#3041) borrow a more sophisticated technique here from @@ -101,8 +101,8 @@ mod linear { #[inline(always)] pure fn bucket_for_key( - buckets: &[option<bucket<K,V>>], - k: &K) -> search_result { + buckets: &[option<Bucket<K,V>>], + k: &K) -> SearchResult { let hash = self.hashfn(k); self.bucket_for_key_with_hash(buckets, hash, k) @@ -110,23 +110,23 @@ mod linear { #[inline(always)] pure fn bucket_for_key_with_hash( - buckets: &[option<bucket<K,V>>], + buckets: &[option<Bucket<K,V>>], hash: uint, - k: &K) -> search_result { + k: &K) -> SearchResult { let _ = for self.bucket_sequence(hash) |i| { match buckets[i] { some(bkt) => if bkt.hash == hash && self.eqfn(k, &bkt.key) { - return found_entry(i); + return FoundEntry(i); }, - none => return found_hole(i) + none => return FoundHole(i) } }; - return table_full; + return TableFull; } } - priv impl<K,V> &mut linear_map<K,V> { + priv impl<K,V> &mut LinearMap<K,V> { /// Expands the capacity of the array and re-inserts each /// of the existing buckets. fn expand() { @@ -146,7 +146,7 @@ mod linear { } } - fn insert_bucket(+bucket: option<bucket<K,V>>) { + fn insert_bucket(+bucket: option<Bucket<K,V>>) { let {hash, key, value} <- option::unwrap(bucket); let _ = self.insert_internal(hash, key, value); } @@ -157,15 +157,15 @@ mod linear { fn insert_internal(hash: uint, +k: K, +v: V) -> bool { match self.bucket_for_key_with_hash(self.buckets, hash, unsafe{borrow(k)}) { - table_full => {fail ~"Internal logic error";} - found_hole(idx) => { + TableFull => {fail ~"Internal logic error";} + FoundHole(idx) => { debug!{"insert fresh (%?->%?) at idx %?, hash %?", k, v, idx, hash}; self.buckets[idx] = some({hash: hash, key: k, value: v}); self.size += 1; return true; } - found_entry(idx) => { + FoundEntry(idx) => { debug!{"insert overwrite (%?->%?) at idx %?, hash %?", k, v, idx, hash}; self.buckets[idx] = some({hash: hash, key: k, value: v}); @@ -175,7 +175,7 @@ mod linear { } } - impl<K,V> &mut linear_map<K,V> { + impl<K,V> &mut LinearMap<K,V> { fn insert(+k: K, +v: V) -> bool { if self.size >= self.resize_at { // n.b.: We could also do this after searching, so @@ -208,10 +208,10 @@ mod linear { // http://www.maths.lse.ac.uk/Courses/MA407/del-hash.pdf let mut idx = match self.bucket_for_key(self.buckets, k) { - table_full | found_hole(_) => { + TableFull | FoundHole(_) => { return false; } - found_entry(idx) => { + FoundEntry(idx) => { idx } }; @@ -230,13 +230,13 @@ mod linear { } } - priv impl<K,V> &linear_map<K,V> { - fn search(hash: uint, op: fn(x: &option<bucket<K,V>>) -> bool) { + priv impl<K,V> &LinearMap<K,V> { + fn search(hash: uint, op: fn(x: &option<Bucket<K,V>>) -> bool) { let _ = self.bucket_sequence(hash, |i| op(&self.buckets[i])); } } - impl<K,V> &const linear_map<K,V> { + impl<K,V> &const LinearMap<K,V> { pure fn len() -> uint { self.size } @@ -247,21 +247,21 @@ mod linear { fn contains_key(k: &K) -> bool { match self.bucket_for_key(self.buckets, k) { - found_entry(_) => {true} - table_full | found_hole(_) => {false} + FoundEntry(_) => {true} + TableFull | FoundHole(_) => {false} } } } - impl<K,V: copy> &const linear_map<K,V> { + impl<K,V: copy> &const LinearMap<K,V> { fn find(k: &K) -> option<V> { match self.bucket_for_key(self.buckets, k) { - found_entry(idx) => { + FoundEntry(idx) => { match check self.buckets[idx] { some(bkt) => {some(copy bkt.value)} } } - table_full | found_hole(_) => { + TableFull | FoundHole(_) => { none } } @@ -277,7 +277,7 @@ mod linear { } - impl<K,V> &linear_map<K,V> { + impl<K,V> &LinearMap<K,V> { /* FIXME --- #2979 must be fixed to typecheck this fn find_ptr(k: K) -> option<&V> { @@ -306,17 +306,17 @@ mod linear { } } - impl<K: copy, V: copy> &linear_map<K,V> { + impl<K: copy, V: copy> &LinearMap<K,V> { fn each(blk: fn(+K,+V) -> bool) { self.each_ref(|k,v| blk(copy *k, copy *v)); } } - impl<K: copy, V> &linear_map<K,V> { + impl<K: copy, V> &LinearMap<K,V> { fn each_key(blk: fn(+K) -> bool) { self.each_key_ref(|k| blk(copy *k)); } } - impl<K, V: copy> &linear_map<K,V> { + impl<K, V: copy> &LinearMap<K,V> { fn each_value(blk: fn(+V) -> bool) { self.each_value_ref(|v| blk(copy *v)); } @@ -326,12 +326,12 @@ mod linear { #[test] mod test { - import linear::linear_map; + import linear::{LinearMap, linear_map}; pure fn uint_hash(x: &uint) -> uint { *x } pure fn uint_eq(x: &uint, y: &uint) -> bool { *x == *y } - fn int_linear_map<V>() -> linear_map<uint,V> { + fn int_linear_map<V>() -> LinearMap<uint,V> { return linear_map(uint_hash, uint_eq); } diff --git a/src/libcore/str.rs b/src/libcore/str.rs index 9a1e32a6711..d73c71c510a 100644 --- a/src/libcore/str.rs +++ b/src/libcore/str.rs @@ -108,8 +108,8 @@ export unsafe, extensions, - str_slice, - unique_str; + StrSlice, + UniqueStr; #[abi = "cdecl"] extern mod rustrt { @@ -1877,7 +1877,7 @@ mod unsafe { /// Sets the length of the string and adds the null terminator unsafe fn set_len(&v: ~str, new_len: uint) { - let repr: *vec::unsafe::vec_repr = ::unsafe::reinterpret_cast(v); + let repr: *vec::unsafe::VecRepr = ::unsafe::reinterpret_cast(v); (*repr).fill = new_len + 1u; let null = ptr::mut_offset(ptr::mut_addr_of((*repr).data), new_len); *null = 0u8; @@ -1895,14 +1895,14 @@ mod unsafe { } -trait unique_str { +trait UniqueStr { fn trim() -> self; fn trim_left() -> self; fn trim_right() -> self; } /// Extension methods for strings -impl ~str: unique_str { +impl ~str: UniqueStr { /// Returns a string with leading and trailing whitespace removed #[inline] fn trim() -> ~str { trim(self) } @@ -1922,7 +1922,7 @@ impl ~str: add<&str,~str> { } } -trait str_slice { +trait StrSlice { fn all(it: fn(char) -> bool) -> bool; fn any(it: fn(char) -> bool) -> bool; fn contains(needle: &a/str) -> bool; @@ -1951,7 +1951,7 @@ trait str_slice { } /// Extension methods for strings -impl &str: str_slice { +impl &str: StrSlice { /** * Return true if a predicate matches all characters or if the string * contains no characters diff --git a/src/libcore/task.rs b/src/libcore/task.rs index 2748b53fb54..678cda32404 100644 --- a/src/libcore/task.rs +++ b/src/libcore/task.rs @@ -693,7 +693,7 @@ type task_id = int; type rust_task = libc::c_void; type rust_closure = libc::c_void; -type taskset = send_map::linear::linear_map<*rust_task,()>; +type taskset = send_map::linear::LinearMap<*rust_task,()>; fn new_taskset() -> taskset { pure fn task_hash(t: &*rust_task) -> uint { @@ -1271,7 +1271,7 @@ impl<T: owned> @T: local_data { } // heavily in future, this could be made more efficient with a proper map. type task_local_element = (*libc::c_void, *libc::c_void, local_data); // Has to be a pointer at outermost layer; the foreign call returns void *. -type task_local_map = @dvec::dvec<option<task_local_element>>; +type task_local_map = @dvec::DVec<option<task_local_element>>; extern fn cleanup_task_local_map(map_ptr: *libc::c_void) unsafe { assert !map_ptr.is_null(); diff --git a/src/libcore/uint-template.rs b/src/libcore/uint-template.rs index 0fc35156f3a..4f27e8cea8f 100644 --- a/src/libcore/uint-template.rs +++ b/src/libcore/uint-template.rs @@ -80,7 +80,7 @@ impl T: num::Num { static pure fn from_int(n: int) -> T { return n as T; } } -impl T: iter::times { +impl T: iter::Times { #[inline(always)] #[doc = "A convenience form for basic iteration. Given a variable `x` \ of any numeric type, the expression `for x.times { /* anything */ }` \ @@ -96,7 +96,7 @@ impl T: iter::times { } } -impl T: iter::timesi { +impl T: iter::TimesIx { #[inline(always)] /// Like `times`, but with an index, `eachi`-style. fn timesi(it: fn(uint) -> bool) { @@ -295,7 +295,7 @@ fn to_str_radix17() { #[test] fn test_times() { - import iter::times; + import iter::Times; let ten = 10 as T; let mut accum = 0; for ten.times { accum += 1; } diff --git a/src/libcore/vec.rs b/src/libcore/vec.rs index 6bd0e8c8cd2..e53cd1ddccf 100644 --- a/src/libcore/vec.rs +++ b/src/libcore/vec.rs @@ -86,21 +86,21 @@ export as_const_buf; export unsafe; export u8; export extensions; -export const_vector; -export copyable_vector; -export immutable_vector; -export immutable_copyable_vector; -export iter_trait_extensions; +export ConstVector; +export CopyableVector; +export ImmutableVector; +export ImmutableCopyableVector; +export IterTraitExtensions; export vec_concat; #[abi = "cdecl"] extern mod rustrt { fn vec_reserve_shared(++t: *sys::TypeDesc, - ++v: **unsafe::vec_repr, + ++v: **unsafe::VecRepr, ++n: libc::size_t); fn vec_from_buf_shared(++t: *sys::TypeDesc, ++ptr: *(), - ++count: libc::size_t) -> *unsafe::vec_repr; + ++count: libc::size_t) -> *unsafe::VecRepr; } #[abi = "rust-intrinsic"] @@ -109,7 +109,7 @@ extern mod rusti { } /// A function used to initialize the elements of a vector -type init_op/&<T> = fn(uint) -> T; +type InitOp/&<T> = fn(uint) -> T; /// Returns true if a vector contains no elements pure fn is_empty<T>(v: &[const T]) -> bool { @@ -140,7 +140,7 @@ pure fn same_length<T, U>(xs: &[const T], ys: &[const U]) -> bool { fn reserve<T>(&v: ~[const T], n: uint) { // Only make the (slow) call into the runtime if we have to if capacity(v) < n { - let ptr = ptr::addr_of(v) as **unsafe::vec_repr; + let ptr = ptr::addr_of(v) as **unsafe::VecRepr; rustrt::vec_reserve_shared(sys::get_type_desc::<T>(), ptr, n as size_t); } @@ -169,7 +169,7 @@ fn reserve_at_least<T>(&v: ~[const T], n: uint) { #[inline(always)] pure fn capacity<T>(&&v: ~[const T]) -> uint { unsafe { - let repr: **unsafe::vec_repr = ::unsafe::reinterpret_cast(addr_of(v)); + let repr: **unsafe::VecRepr = ::unsafe::reinterpret_cast(addr_of(v)); (**repr).alloc / sys::size_of::<T>() } } @@ -186,7 +186,7 @@ pure fn len<T>(&&v: &[const T]) -> uint { * Creates an immutable vector of size `n_elts` and initializes the elements * to the value returned by the function `op`. */ -pure fn from_fn<T>(n_elts: uint, op: init_op<T>) -> ~[T] { +pure fn from_fn<T>(n_elts: uint, op: InitOp<T>) -> ~[T] { let mut v = ~[]; unchecked{reserve(v, n_elts);} let mut i: uint = 0u; @@ -523,7 +523,7 @@ fn pop<T>(&v: ~[const T]) -> T { #[inline(always)] fn push<T>(&v: ~[const T], +initval: T) { unsafe { - let repr: **unsafe::vec_repr = ::unsafe::reinterpret_cast(addr_of(v)); + let repr: **unsafe::VecRepr = ::unsafe::reinterpret_cast(addr_of(v)); let fill = (**repr).fill; if (**repr).alloc > fill { push_fast(v, initval); @@ -537,7 +537,7 @@ fn push<T>(&v: ~[const T], +initval: T) { // This doesn't bother to make sure we have space. #[inline(always)] // really pretty please unsafe fn push_fast<T>(&v: ~[const T], +initval: T) { - let repr: **unsafe::vec_repr = ::unsafe::reinterpret_cast(addr_of(v)); + let repr: **unsafe::VecRepr = ::unsafe::reinterpret_cast(addr_of(v)); let fill = (**repr).fill; (**repr).fill += sys::size_of::<T>(); let p = ptr::addr_of((**repr).data); @@ -640,7 +640,7 @@ fn grow<T: copy>(&v: ~[const T], n: uint, initval: T) { * * init_op - A function to call to retreive each appended element's * value */ -fn grow_fn<T>(&v: ~[const T], n: uint, op: init_op<T>) { +fn grow_fn<T>(&v: ~[const T], n: uint, op: InitOp<T>) { reserve_at_least(v, len(v) + n); let mut i: uint = 0u; while i < n { push(v, op(i)); i += 1u; } @@ -1304,14 +1304,14 @@ impl<T: copy> ~[mut T]: add<&[const T],~[mut T]> { } } -trait const_vector { +trait ConstVector { pure fn is_empty() -> bool; pure fn is_not_empty() -> bool; pure fn len() -> uint; } /// Extension methods for vectors -impl<T> &[const T]: const_vector { +impl<T> &[const T]: ConstVector { /// Returns true if a vector contains no elements #[inline] pure fn is_empty() -> bool { is_empty(self) } @@ -1323,7 +1323,7 @@ impl<T> &[const T]: const_vector { pure fn len() -> uint { len(self) } } -trait copyable_vector<T> { +trait CopyableVector<T> { pure fn head() -> T; pure fn init() -> ~[T]; pure fn last() -> T; @@ -1332,7 +1332,7 @@ trait copyable_vector<T> { } /// Extension methods for vectors -impl<T: copy> &[const T]: copyable_vector<T> { +impl<T: copy> &[const T]: CopyableVector<T> { /// Returns the first element of a vector #[inline] pure fn head() -> T { head(self) } @@ -1350,7 +1350,7 @@ impl<T: copy> &[const T]: copyable_vector<T> { pure fn tail() -> ~[T] { tail(self) } } -trait immutable_vector<T> { +trait ImmutableVector<T> { pure fn foldr<U: copy>(z: U, p: fn(T, U) -> U) -> U; pure fn iter(f: fn(T)); pure fn iteri(f: fn(uint, T)); @@ -1369,7 +1369,7 @@ trait immutable_vector<T> { } /// Extension methods for vectors -impl<T> &[T]: immutable_vector<T> { +impl<T> &[T]: ImmutableVector<T> { /// Reduce a vector from right to left #[inline] pure fn foldr<U: copy>(z: U, p: fn(T, U) -> U) -> U { foldr(self, z, p) } @@ -1477,14 +1477,14 @@ impl<T> &[T]: immutable_vector<T> { } } -trait immutable_copyable_vector<T> { +trait ImmutableCopyableVector<T> { pure fn filter(f: fn(T) -> bool) -> ~[T]; pure fn find(f: fn(T) -> bool) -> option<T>; pure fn rfind(f: fn(T) -> bool) -> option<T>; } /// Extension methods for vectors -impl<T: copy> &[T]: immutable_copyable_vector<T> { +impl<T: copy> &[T]: ImmutableCopyableVector<T> { /** * Construct a new vector from the elements of a vector for which some * predicate holds. @@ -1518,14 +1518,14 @@ impl<T: copy> &[T]: immutable_copyable_vector<T> { mod unsafe { // FIXME: This should have crate visibility (#1893 blocks that) /// The internal representation of a vector - type vec_repr = { + type VecRepr = { box_header: (uint, uint, uint, uint), mut fill: uint, mut alloc: uint, data: u8 }; - type slice_repr = { + type SliceRepr = { mut data: *u8, mut len: uint }; @@ -1555,7 +1555,7 @@ mod unsafe { */ #[inline(always)] unsafe fn set_len<T>(&&v: ~[const T], new_len: uint) { - let repr: **vec_repr = ::unsafe::reinterpret_cast(addr_of(v)); + let repr: **VecRepr = ::unsafe::reinterpret_cast(addr_of(v)); (**repr).fill = new_len * sys::size_of::<T>(); } @@ -1570,14 +1570,14 @@ mod unsafe { */ #[inline(always)] unsafe fn to_ptr<T>(v: ~[const T]) -> *T { - let repr: **vec_repr = ::unsafe::reinterpret_cast(addr_of(v)); + let repr: **VecRepr = ::unsafe::reinterpret_cast(addr_of(v)); return ::unsafe::reinterpret_cast(addr_of((**repr).data)); } #[inline(always)] unsafe fn to_ptr_slice<T>(v: &[const T]) -> *T { - let repr: **slice_repr = ::unsafe::reinterpret_cast(addr_of(v)); + let repr: **SliceRepr = ::unsafe::reinterpret_cast(addr_of(v)); return ::unsafe::reinterpret_cast(addr_of((**repr).data)); } @@ -1729,12 +1729,12 @@ mod u8 { // This cannot be used with iter-trait.rs because of the region pointer // required in the slice. -impl<A> &[A]: iter::base_iter<A> { +impl<A> &[A]: iter::BaseIter<A> { fn each(blk: fn(A) -> bool) { each(self, blk) } fn size_hint() -> option<uint> { some(len(self)) } } -impl<A> &[A]: iter::extended_iter<A> { +impl<A> &[A]: iter::ExtendedIter<A> { fn eachi(blk: fn(uint, A) -> bool) { iter::eachi(self, blk) } fn all(blk: fn(A) -> bool) -> bool { iter::all(self, blk) } fn any(blk: fn(A) -> bool) -> bool { iter::any(self, blk) } @@ -1746,7 +1746,7 @@ impl<A> &[A]: iter::extended_iter<A> { fn position(f: fn(A) -> bool) -> option<uint> { iter::position(self, f) } } -trait iter_trait_extensions<A> { +trait IterTraitExtensions<A> { fn filter_to_vec(pred: fn(A) -> bool) -> ~[A]; fn map_to_vec<B>(op: fn(A) -> B) -> ~[B]; fn to_vec() -> ~[A]; @@ -1754,7 +1754,7 @@ trait iter_trait_extensions<A> { fn max() -> A; } -impl<A: copy> &[A]: iter_trait_extensions<A> { +impl<A: copy> &[A]: IterTraitExtensions<A> { fn filter_to_vec(pred: fn(A) -> bool) -> ~[A] { iter::filter_to_vec(self, pred) } |
