From 9b95d511316ae7124046de61d19335fdfaa021cc Mon Sep 17 00:00:00 2001 From: Brian Anderson Date: Wed, 28 Nov 2012 15:24:39 -0800 Subject: [PATCH] core: Remove old template files --- src/libcore/core.rc | 26 +-- src/libcore/int-template/i16.rs | 6 +- src/libcore/int-template/i16b.rs | 4 - src/libcore/int-template/i32.rs | 6 +- src/libcore/int-template/i32b.rs | 4 - src/libcore/int-template/i64.rs | 6 +- src/libcore/int-template/i64b.rs | 4 - src/libcore/int-template/i8.rs | 6 +- src/libcore/int-template/i8b.rs | 4 - src/libcore/int-template/int.rs | 75 ++++---- src/libcore/int-template/intb.rs | 45 ----- src/libcore/iter-trait/dlist.rs | 64 ++++--- src/libcore/iter-trait/dlistb.rs | 38 ---- src/libcore/iter-trait/dvec.rs | 34 ++-- src/libcore/iter-trait/dvecb.rs | 22 --- src/libcore/iter-trait/option.rs | 26 +-- src/libcore/iter-trait/optionb.rs | 18 -- src/libcore/uint-template/u16.rs | 6 +- src/libcore/uint-template/u16b.rs | 4 - src/libcore/uint-template/u32.rs | 6 +- src/libcore/uint-template/u32b.rs | 4 - src/libcore/uint-template/u64.rs | 6 +- src/libcore/uint-template/u64b.rs | 4 - src/libcore/uint-template/u8.rs | 14 +- src/libcore/uint-template/u8b.rs | 11 -- src/libcore/uint-template/uint.rs | 295 +++++++++++++++-------------- src/libcore/uint-template/uintb.rs | 160 ---------------- 27 files changed, 308 insertions(+), 590 deletions(-) delete mode 100644 src/libcore/int-template/i16b.rs delete mode 100644 src/libcore/int-template/i32b.rs delete mode 100644 src/libcore/int-template/i64b.rs delete mode 100644 src/libcore/int-template/i8b.rs delete mode 100644 src/libcore/int-template/intb.rs delete mode 100644 src/libcore/iter-trait/dlistb.rs delete mode 100644 src/libcore/iter-trait/dvecb.rs delete mode 100644 src/libcore/iter-trait/optionb.rs delete mode 100644 src/libcore/uint-template/u16b.rs delete mode 100644 src/libcore/uint-template/u32b.rs delete mode 100644 src/libcore/uint-template/u64b.rs delete mode 100644 src/libcore/uint-template/u8b.rs delete mode 100644 src/libcore/uint-template/uintb.rs diff --git a/src/libcore/core.rc b/src/libcore/core.rc index 9e8dc94cd84..4c5a56cc6ff 100644 --- a/src/libcore/core.rc +++ b/src/libcore/core.rc @@ -46,52 +46,52 @@ Implicitly, all crates behave as if they included the following prologue: /// Operations and constants for `int` #[path = "int-template.rs"] -#[merge = "int-template/intb.rs"] +#[merge = "int-template/int.rs"] pub mod int; /// Operations and constants for `i8` #[path = "int-template.rs"] -#[merge = "int-template/i8b.rs"] +#[merge = "int-template/i8.rs"] pub mod i8; /// Operations and constants for `i16` #[path = "int-template.rs"] -#[merge = "int-template/i16b.rs"] +#[merge = "int-template/i16.rs"] pub mod i16; /// Operations and constants for `i32` #[path = "int-template.rs"] -#[merge = "int-template/i32b.rs"] +#[merge = "int-template/i32.rs"] pub mod i32; /// Operations and constants for `i64` #[path = "int-template.rs"] -#[merge = "int-template/i64b.rs"] +#[merge = "int-template/i64.rs"] pub mod i64; /// Operations and constants for `uint` #[path = "uint-template.rs"] -#[merge = "uint-template/uintb.rs"] +#[merge = "uint-template/uint.rs"] pub mod uint; /// Operations and constants for `u8` #[path = "uint-template.rs"] -#[merge = "uint-template/u8b.rs"] +#[merge = "uint-template/u8.rs"] pub mod u8; /// Operations and constants for `u16` #[path = "uint-template.rs"] -#[merge = "uint-template/u16b.rs"] +#[merge = "uint-template/u16.rs"] pub mod u16; /// Operations and constants for `u32` #[path = "uint-template.rs"] -#[merge = "uint-template/u32b.rs"] +#[merge = "uint-template/u32.rs"] pub mod u32; /// Operations and constants for `u64` #[path = "uint-template.rs"] -#[merge = "uint-template/u64b.rs"] +#[merge = "uint-template/u64.rs"] pub mod u64; @@ -121,7 +121,7 @@ pub mod iter; pub mod logging; pub mod option; #[path="iter-trait.rs"] -#[merge = "iter-trait/optionb.rs"] +#[merge = "iter-trait/option.rs"] pub mod option_iter; pub mod result; pub mod to_str; @@ -134,11 +134,11 @@ pub mod clone; pub mod dvec; #[path="iter-trait.rs"] -#[merge = "iter-trait/dvecb.rs"] +#[merge = "iter-trait/dvec.rs"] pub mod dvec_iter; pub mod dlist; #[path="iter-trait.rs"] -#[merge = "iter-trait/dlistb.rs"] +#[merge = "iter-trait/dlist.rs"] pub mod dlist_iter; pub mod send_map; diff --git a/src/libcore/int-template/i16.rs b/src/libcore/int-template/i16.rs index 9e7055c3e7a..b24eb86e4ae 100644 --- a/src/libcore/int-template/i16.rs +++ b/src/libcore/int-template/i16.rs @@ -1,2 +1,4 @@ -pub type T = i16; -pub const bits: uint = u16::bits; \ No newline at end of file +mod inst { + pub type T = i16; + pub const bits: uint = u16::bits; +} \ No newline at end of file diff --git a/src/libcore/int-template/i16b.rs b/src/libcore/int-template/i16b.rs deleted file mode 100644 index b24eb86e4ae..00000000000 --- a/src/libcore/int-template/i16b.rs +++ /dev/null @@ -1,4 +0,0 @@ -mod inst { - pub type T = i16; - pub const bits: uint = u16::bits; -} \ No newline at end of file diff --git a/src/libcore/int-template/i32.rs b/src/libcore/int-template/i32.rs index 6545eaffdac..5bfb8a6d01c 100644 --- a/src/libcore/int-template/i32.rs +++ b/src/libcore/int-template/i32.rs @@ -1,2 +1,4 @@ -pub type T = i32; -pub const bits: uint = u32::bits; +mod inst { + pub type T = i32; + pub const bits: uint = u32::bits; +} diff --git a/src/libcore/int-template/i32b.rs b/src/libcore/int-template/i32b.rs deleted file mode 100644 index 5bfb8a6d01c..00000000000 --- a/src/libcore/int-template/i32b.rs +++ /dev/null @@ -1,4 +0,0 @@ -mod inst { - pub type T = i32; - pub const bits: uint = u32::bits; -} diff --git a/src/libcore/int-template/i64.rs b/src/libcore/int-template/i64.rs index c6ed97e8162..86552b2cced 100644 --- a/src/libcore/int-template/i64.rs +++ b/src/libcore/int-template/i64.rs @@ -1,2 +1,4 @@ -pub type T = i64; -pub const bits: uint = u64::bits; \ No newline at end of file +mod inst { + pub type T = i64; + pub const bits: uint = u64::bits; +} \ No newline at end of file diff --git a/src/libcore/int-template/i64b.rs b/src/libcore/int-template/i64b.rs deleted file mode 100644 index 86552b2cced..00000000000 --- a/src/libcore/int-template/i64b.rs +++ /dev/null @@ -1,4 +0,0 @@ -mod inst { - pub type T = i64; - pub const bits: uint = u64::bits; -} \ No newline at end of file diff --git a/src/libcore/int-template/i8.rs b/src/libcore/int-template/i8.rs index 0a2823e63c6..2cf7ed2983f 100644 --- a/src/libcore/int-template/i8.rs +++ b/src/libcore/int-template/i8.rs @@ -1,2 +1,4 @@ -pub type T = i8; -pub const bits: uint = u8::bits; \ No newline at end of file +mod inst { + pub type T = i8; + pub const bits: uint = u8::bits; +} \ No newline at end of file diff --git a/src/libcore/int-template/i8b.rs b/src/libcore/int-template/i8b.rs deleted file mode 100644 index 2cf7ed2983f..00000000000 --- a/src/libcore/int-template/i8b.rs +++ /dev/null @@ -1,4 +0,0 @@ -mod inst { - pub type T = i8; - pub const bits: uint = u8::bits; -} \ No newline at end of file diff --git a/src/libcore/int-template/int.rs b/src/libcore/int-template/int.rs index 8b898b173ac..c1f2ca944dd 100644 --- a/src/libcore/int-template/int.rs +++ b/src/libcore/int-template/int.rs @@ -1,38 +1,45 @@ -pub type T = int; -pub const bits: uint = uint::bits; +pub use inst::pow; -/// Returns `base` raised to the power of `exponent` -pub fn pow(base: int, exponent: uint) -> int { - if exponent == 0u { return 1; } //Not mathemtically true if ~[base == 0] - if base == 0 { return 0; } - let mut my_pow = exponent; - let mut acc = 1; - let mut multiplier = base; - while(my_pow > 0u) { - if my_pow % 2u == 1u { - acc *= multiplier; - } - my_pow /= 2u; - multiplier *= multiplier; +mod inst { + pub type T = int; + pub const bits: uint = uint::bits; + + /// Returns `base` raised to the power of `exponent` + pub fn pow(base: int, exponent: uint) -> int { + if exponent == 0u { + //Not mathemtically true if ~[base == 0] + return 1; + } + if base == 0 { return 0; } + let mut my_pow = exponent; + let mut acc = 1; + let mut multiplier = base; + while(my_pow > 0u) { + if my_pow % 2u == 1u { + acc *= multiplier; + } + my_pow /= 2u; + multiplier *= multiplier; + } + return acc; } - return acc; -} -#[test] -fn test_pow() { - assert (pow(0, 0u) == 1); - assert (pow(0, 1u) == 0); - assert (pow(0, 2u) == 0); - assert (pow(-1, 0u) == 1); - assert (pow(1, 0u) == 1); - assert (pow(-3, 2u) == 9); - assert (pow(-3, 3u) == -27); - assert (pow(4, 9u) == 262144); -} + #[test] + fn test_pow() { + assert (pow(0, 0u) == 1); + assert (pow(0, 1u) == 0); + assert (pow(0, 2u) == 0); + assert (pow(-1, 0u) == 1); + assert (pow(1, 0u) == 1); + assert (pow(-3, 2u) == 9); + assert (pow(-3, 3u) == -27); + assert (pow(4, 9u) == 262144); + } -#[test] -fn test_overflows() { - assert (max_value > 0); - assert (min_value <= 0); - assert (min_value + max_value + 1 == 0); -} + #[test] + fn test_overflows() { + assert (max_value > 0); + assert (min_value <= 0); + assert (min_value + max_value + 1 == 0); + } +} \ No newline at end of file diff --git a/src/libcore/int-template/intb.rs b/src/libcore/int-template/intb.rs deleted file mode 100644 index c1f2ca944dd..00000000000 --- a/src/libcore/int-template/intb.rs +++ /dev/null @@ -1,45 +0,0 @@ -pub use inst::pow; - -mod inst { - pub type T = int; - pub const bits: uint = uint::bits; - - /// Returns `base` raised to the power of `exponent` - pub fn pow(base: int, exponent: uint) -> int { - if exponent == 0u { - //Not mathemtically true if ~[base == 0] - return 1; - } - if base == 0 { return 0; } - let mut my_pow = exponent; - let mut acc = 1; - let mut multiplier = base; - while(my_pow > 0u) { - if my_pow % 2u == 1u { - acc *= multiplier; - } - my_pow /= 2u; - multiplier *= multiplier; - } - return acc; - } - - #[test] - fn test_pow() { - assert (pow(0, 0u) == 1); - assert (pow(0, 1u) == 0); - assert (pow(0, 2u) == 0); - assert (pow(-1, 0u) == 1); - assert (pow(1, 0u) == 1); - assert (pow(-3, 2u) == 9); - assert (pow(-3, 3u) == -27); - assert (pow(4, 9u) == 262144); - } - - #[test] - fn test_overflows() { - assert (max_value > 0); - assert (min_value <= 0); - assert (min_value + max_value + 1 == 0); - } -} \ No newline at end of file diff --git a/src/libcore/iter-trait/dlist.rs b/src/libcore/iter-trait/dlist.rs index 1b5f11569c3..2d782b1262b 100644 --- a/src/libcore/iter-trait/dlist.rs +++ b/src/libcore/iter-trait/dlist.rs @@ -1,34 +1,38 @@ -#[allow(non_camel_case_types)] -pub type IMPL_T = dlist::DList; +mod inst { + #[allow(non_camel_case_types)] + pub type IMPL_T = dlist::DList; -/** - * Iterates through the current contents. - * - * Attempts to access this dlist during iteration are allowed (to allow for - * e.g. breadth-first search with in-place enqueues), but removing the current - * node is forbidden. - */ -pub pure fn EACH(self: &IMPL_T, f: fn(v: &A) -> bool) { - let mut link = self.peek_n(); - while option::is_some(&link) { - let nobe = option::get(link); - assert nobe.linked; - if !f(&nobe.data) { break; } - // Check (weakly) that the user didn't do a remove. - if self.size == 0 { - fail ~"The dlist became empty during iteration??" + /** + * Iterates through the current contents. + * + * Attempts to access this dlist during iteration are allowed (to + * allow for e.g. breadth-first search with in-place enqueues), but + * removing the current node is forbidden. + */ + pub pure fn EACH(self: &IMPL_T, f: fn(v: &A) -> bool) { + let mut link = self.peek_n(); + while option::is_some(&link) { + let nobe = option::get(link); + assert nobe.linked; + if !f(&nobe.data) { break; } + // Check (weakly) that the user didn't do a remove. + if self.size == 0 { + fail ~"The dlist became empty during iteration??" + } + if !nobe.linked || + (!((nobe.prev.is_some() + || box::ptr_eq(*self.hd.expect(~"headless dlist?"), + *nobe)) + && (nobe.next.is_some() + || box::ptr_eq(*self.tl.expect(~"tailless dlist?"), + *nobe)))) { + fail ~"Removing a dlist node during iteration is forbidden!" + } + link = nobe.next_link(); } - if !nobe.linked || - (!((nobe.prev.is_some() - || box::ptr_eq(*self.hd.expect(~"headless dlist?"), *nobe)) && - (nobe.next.is_some() - || box::ptr_eq(*self.tl.expect(~"tailless dlist?"), *nobe)))) { - fail ~"Removing a dlist node during iteration is forbidden!" - } - link = nobe.next_link(); } -} -pub pure fn SIZE_HINT(self: &IMPL_T) -> Option { - Some(self.len()) -} + pub pure fn SIZE_HINT(self: &IMPL_T) -> Option { + Some(self.len()) + } +} \ No newline at end of file diff --git a/src/libcore/iter-trait/dlistb.rs b/src/libcore/iter-trait/dlistb.rs deleted file mode 100644 index 2d782b1262b..00000000000 --- a/src/libcore/iter-trait/dlistb.rs +++ /dev/null @@ -1,38 +0,0 @@ -mod inst { - #[allow(non_camel_case_types)] - pub type IMPL_T = dlist::DList; - - /** - * Iterates through the current contents. - * - * Attempts to access this dlist during iteration are allowed (to - * allow for e.g. breadth-first search with in-place enqueues), but - * removing the current node is forbidden. - */ - pub pure fn EACH(self: &IMPL_T, f: fn(v: &A) -> bool) { - let mut link = self.peek_n(); - while option::is_some(&link) { - let nobe = option::get(link); - assert nobe.linked; - if !f(&nobe.data) { break; } - // Check (weakly) that the user didn't do a remove. - if self.size == 0 { - fail ~"The dlist became empty during iteration??" - } - if !nobe.linked || - (!((nobe.prev.is_some() - || box::ptr_eq(*self.hd.expect(~"headless dlist?"), - *nobe)) - && (nobe.next.is_some() - || box::ptr_eq(*self.tl.expect(~"tailless dlist?"), - *nobe)))) { - fail ~"Removing a dlist node during iteration is forbidden!" - } - link = nobe.next_link(); - } - } - - pub pure fn SIZE_HINT(self: &IMPL_T) -> Option { - Some(self.len()) - } -} \ No newline at end of file diff --git a/src/libcore/iter-trait/dvec.rs b/src/libcore/iter-trait/dvec.rs index f03f1a154e4..b30c1372a2e 100644 --- a/src/libcore/iter-trait/dvec.rs +++ b/src/libcore/iter-trait/dvec.rs @@ -1,20 +1,22 @@ -#[allow(non_camel_case_types)] -pub type IMPL_T = dvec::DVec; +mod inst { + #[allow(non_camel_case_types)] + pub type IMPL_T = dvec::DVec; -/** - * Iterates through the current contents. - * - * Attempts to access this dvec during iteration will fail. - */ -pub pure fn EACH(self: &IMPL_T, f: fn(v: &A) -> bool) { - unsafe { - do self.swap |v| { - v.each(f); - move v + /** + * Iterates through the current contents. + * + * Attempts to access this dvec during iteration will fail. + */ + pub pure fn EACH(self: &IMPL_T, f: fn(v: &A) -> bool) { + unsafe { + do self.swap |v| { + v.each(f); + move v + } } } -} -pub pure fn SIZE_HINT(self: &IMPL_T) -> Option { - Some(self.len()) -} + pub pure fn SIZE_HINT(self: &IMPL_T) -> Option { + Some(self.len()) + } +} \ No newline at end of file diff --git a/src/libcore/iter-trait/dvecb.rs b/src/libcore/iter-trait/dvecb.rs deleted file mode 100644 index b30c1372a2e..00000000000 --- a/src/libcore/iter-trait/dvecb.rs +++ /dev/null @@ -1,22 +0,0 @@ -mod inst { - #[allow(non_camel_case_types)] - pub type IMPL_T = dvec::DVec; - - /** - * Iterates through the current contents. - * - * Attempts to access this dvec during iteration will fail. - */ - pub pure fn EACH(self: &IMPL_T, f: fn(v: &A) -> bool) { - unsafe { - do self.swap |v| { - v.each(f); - move v - } - } - } - - pub pure fn SIZE_HINT(self: &IMPL_T) -> Option { - Some(self.len()) - } -} \ No newline at end of file diff --git a/src/libcore/iter-trait/option.rs b/src/libcore/iter-trait/option.rs index 44afe9f54f0..680893eb95b 100644 --- a/src/libcore/iter-trait/option.rs +++ b/src/libcore/iter-trait/option.rs @@ -1,16 +1,18 @@ -#[allow(non_camel_case_types)] -pub type IMPL_T = Option; +mod inst { + #[allow(non_camel_case_types)] + pub type IMPL_T = Option; -pub pure fn EACH(self: &IMPL_T, f: fn(v: &A) -> bool) { - match *self { - None => (), - Some(ref a) => { f(a); } + pub pure fn EACH(self: &IMPL_T, f: fn(v: &A) -> bool) { + match *self { + None => (), + Some(ref a) => { f(a); } + } } -} -pub pure fn SIZE_HINT(self: &IMPL_T) -> Option { - match *self { - None => Some(0), - Some(_) => Some(1) + pub pure fn SIZE_HINT(self: &IMPL_T) -> Option { + match *self { + None => Some(0), + Some(_) => Some(1) + } } -} +} \ No newline at end of file diff --git a/src/libcore/iter-trait/optionb.rs b/src/libcore/iter-trait/optionb.rs deleted file mode 100644 index 680893eb95b..00000000000 --- a/src/libcore/iter-trait/optionb.rs +++ /dev/null @@ -1,18 +0,0 @@ -mod inst { - #[allow(non_camel_case_types)] - pub type IMPL_T = Option; - - pub pure fn EACH(self: &IMPL_T, f: fn(v: &A) -> bool) { - match *self { - None => (), - Some(ref a) => { f(a); } - } - } - - pub pure fn SIZE_HINT(self: &IMPL_T) -> Option { - match *self { - None => Some(0), - Some(_) => Some(1) - } - } -} \ No newline at end of file diff --git a/src/libcore/uint-template/u16.rs b/src/libcore/uint-template/u16.rs index d8e078eb65c..aafd46f845b 100644 --- a/src/libcore/uint-template/u16.rs +++ b/src/libcore/uint-template/u16.rs @@ -1,2 +1,4 @@ -pub type T = u16; -pub const bits: uint = 16; +mod inst { + pub type T = u16; + pub const bits: uint = 16; +} diff --git a/src/libcore/uint-template/u16b.rs b/src/libcore/uint-template/u16b.rs deleted file mode 100644 index aafd46f845b..00000000000 --- a/src/libcore/uint-template/u16b.rs +++ /dev/null @@ -1,4 +0,0 @@ -mod inst { - pub type T = u16; - pub const bits: uint = 16; -} diff --git a/src/libcore/uint-template/u32.rs b/src/libcore/uint-template/u32.rs index 0e2eb2f09e1..8e784bdf225 100644 --- a/src/libcore/uint-template/u32.rs +++ b/src/libcore/uint-template/u32.rs @@ -1,2 +1,4 @@ -pub type T = u32; -pub const bits: uint = 32; \ No newline at end of file +mod inst { + pub type T = u32; + pub const bits: uint = 32; +} \ No newline at end of file diff --git a/src/libcore/uint-template/u32b.rs b/src/libcore/uint-template/u32b.rs deleted file mode 100644 index 8e784bdf225..00000000000 --- a/src/libcore/uint-template/u32b.rs +++ /dev/null @@ -1,4 +0,0 @@ -mod inst { - pub type T = u32; - pub const bits: uint = 32; -} \ No newline at end of file diff --git a/src/libcore/uint-template/u64.rs b/src/libcore/uint-template/u64.rs index 030c6379628..43a8169f08b 100644 --- a/src/libcore/uint-template/u64.rs +++ b/src/libcore/uint-template/u64.rs @@ -1,2 +1,4 @@ -pub type T = u64; -pub const bits: uint = 64; \ No newline at end of file +mod inst { + pub type T = u64; + pub const bits: uint = 64; +} \ No newline at end of file diff --git a/src/libcore/uint-template/u64b.rs b/src/libcore/uint-template/u64b.rs deleted file mode 100644 index 43a8169f08b..00000000000 --- a/src/libcore/uint-template/u64b.rs +++ /dev/null @@ -1,4 +0,0 @@ -mod inst { - pub type T = u64; - pub const bits: uint = 64; -} \ No newline at end of file diff --git a/src/libcore/uint-template/u8.rs b/src/libcore/uint-template/u8.rs index 539567a2cfd..a3e750861e5 100644 --- a/src/libcore/uint-template/u8.rs +++ b/src/libcore/uint-template/u8.rs @@ -1,7 +1,11 @@ -pub type T = u8; -pub const bits: uint = 8; +pub use inst::is_ascii; -// Type-specific functions here. These must be reexported by the -// parent module so that they appear in core::u8 and not core::u8::u8; +mod inst { + pub type T = u8; + pub const bits: uint = 8; -pub pure fn is_ascii(x: T) -> bool { return 0 as T == x & 128 as T; } + // Type-specific functions here. These must be reexported by the + // parent module so that they appear in core::u8 and not core::u8::u8; + + pub pure fn is_ascii(x: T) -> bool { return 0 as T == x & 128 as T; } +} diff --git a/src/libcore/uint-template/u8b.rs b/src/libcore/uint-template/u8b.rs deleted file mode 100644 index a3e750861e5..00000000000 --- a/src/libcore/uint-template/u8b.rs +++ /dev/null @@ -1,11 +0,0 @@ -pub use inst::is_ascii; - -mod inst { - pub type T = u8; - pub const bits: uint = 8; - - // Type-specific functions here. These must be reexported by the - // parent module so that they appear in core::u8 and not core::u8::u8; - - pub pure fn is_ascii(x: T) -> bool { return 0 as T == x & 128 as T; } -} diff --git a/src/libcore/uint-template/uint.rs b/src/libcore/uint-template/uint.rs index 24beaad4d5e..68054d47e1f 100644 --- a/src/libcore/uint-template/uint.rs +++ b/src/libcore/uint-template/uint.rs @@ -1,153 +1,160 @@ -pub type T = uint; +pub use inst::{ + div_ceil, div_round, div_floor, iterate, + next_power_of_two +}; -#[cfg(target_arch = "x86")] -#[cfg(target_arch = "arm")] -pub const bits: uint = 32; +mod inst { + pub type T = uint; -#[cfg(target_arch = "x86_64")] -pub const bits: uint = 64; + #[cfg(target_arch = "x86")] + #[cfg(target_arch = "arm")] + pub const bits: uint = 32; -/** - * Divide two numbers, return the result, rounded up. - * - * # Arguments - * - * * x - an integer - * * y - an integer distinct from 0u - * - * # Return value - * - * The smallest integer `q` such that `x/y <= q`. - */ -pub pure fn div_ceil(x: uint, y: uint) -> uint { - let div = x / y; - if x % y == 0u { div } - else { div + 1u } -} + #[cfg(target_arch = "x86_64")] + pub const bits: uint = 64; -/** - * Divide two numbers, return the result, rounded to the closest integer. - * - * # Arguments - * - * * x - an integer - * * y - an integer distinct from 0u - * - * # Return value - * - * The integer `q` closest to `x/y`. - */ -pub pure fn div_round(x: uint, y: uint) -> uint { - let div = x / y; - if x % y * 2u < y { div } - else { div + 1u } -} - -/** - * Divide two numbers, return the result, rounded down. - * - * Note: This is the same function as `div`. - * - * # Arguments - * - * * x - an integer - * * y - an integer distinct from 0u - * - * # Return value - * - * The smallest integer `q` such that `x/y <= q`. This - * is either `x/y` or `x/y + 1`. - */ -pub pure fn div_floor(x: uint, y: uint) -> uint { return x / y; } - -/** - * Iterate over the range [`lo`..`hi`), or stop when requested - * - * # Arguments - * - * * lo - The integer at which to start the loop (included) - * * hi - The integer at which to stop the loop (excluded) - * * it - A block to execute with each consecutive integer of the range. - * Return `true` to continue, `false` to stop. - * - * # Return value - * - * `true` If execution proceeded correctly, `false` if it was interrupted, - * that is if `it` returned `false` at any point. - */ -pub pure fn iterate(lo: uint, hi: uint, it: fn(uint) -> bool) -> bool { - let mut i = lo; - while i < hi { - if (!it(i)) { return false; } - i += 1u; + /** + * Divide two numbers, return the result, rounded up. + * + * # Arguments + * + * * x - an integer + * * y - an integer distinct from 0u + * + * # Return value + * + * The smallest integer `q` such that `x/y <= q`. + */ + pub pure fn div_ceil(x: uint, y: uint) -> uint { + let div = x / y; + if x % y == 0u { div } + else { div + 1u } } - return true; -} -/// Returns the smallest power of 2 greater than or equal to `n` -#[inline(always)] -pub fn next_power_of_two(n: uint) -> uint { - let halfbits: uint = sys::size_of::() * 4u; - let mut tmp: uint = n - 1u; - let mut shift: uint = 1u; - while shift <= halfbits { tmp |= tmp >> shift; shift <<= 1u; } - return tmp + 1u; -} + /** + * Divide two numbers, return the result, rounded to the closest integer. + * + * # Arguments + * + * * x - an integer + * * y - an integer distinct from 0u + * + * # Return value + * + * The integer `q` closest to `x/y`. + */ + pub pure fn div_round(x: uint, y: uint) -> uint { + let div = x / y; + if x % y * 2u < y { div } + else { div + 1u } + } -#[test] -fn test_next_power_of_two() { - assert (uint::next_power_of_two(0u) == 0u); - assert (uint::next_power_of_two(1u) == 1u); - assert (uint::next_power_of_two(2u) == 2u); - assert (uint::next_power_of_two(3u) == 4u); - assert (uint::next_power_of_two(4u) == 4u); - assert (uint::next_power_of_two(5u) == 8u); - assert (uint::next_power_of_two(6u) == 8u); - assert (uint::next_power_of_two(7u) == 8u); - assert (uint::next_power_of_two(8u) == 8u); - assert (uint::next_power_of_two(9u) == 16u); - assert (uint::next_power_of_two(10u) == 16u); - assert (uint::next_power_of_two(11u) == 16u); - assert (uint::next_power_of_two(12u) == 16u); - assert (uint::next_power_of_two(13u) == 16u); - assert (uint::next_power_of_two(14u) == 16u); - assert (uint::next_power_of_two(15u) == 16u); - assert (uint::next_power_of_two(16u) == 16u); - assert (uint::next_power_of_two(17u) == 32u); - assert (uint::next_power_of_two(18u) == 32u); - assert (uint::next_power_of_two(19u) == 32u); - assert (uint::next_power_of_two(20u) == 32u); - assert (uint::next_power_of_two(21u) == 32u); - assert (uint::next_power_of_two(22u) == 32u); - assert (uint::next_power_of_two(23u) == 32u); - assert (uint::next_power_of_two(24u) == 32u); - assert (uint::next_power_of_two(25u) == 32u); - assert (uint::next_power_of_two(26u) == 32u); - assert (uint::next_power_of_two(27u) == 32u); - assert (uint::next_power_of_two(28u) == 32u); - assert (uint::next_power_of_two(29u) == 32u); - assert (uint::next_power_of_two(30u) == 32u); - assert (uint::next_power_of_two(31u) == 32u); - assert (uint::next_power_of_two(32u) == 32u); - assert (uint::next_power_of_two(33u) == 64u); - assert (uint::next_power_of_two(34u) == 64u); - assert (uint::next_power_of_two(35u) == 64u); - assert (uint::next_power_of_two(36u) == 64u); - assert (uint::next_power_of_two(37u) == 64u); - assert (uint::next_power_of_two(38u) == 64u); - assert (uint::next_power_of_two(39u) == 64u); -} + /** + * Divide two numbers, return the result, rounded down. + * + * Note: This is the same function as `div`. + * + * # Arguments + * + * * x - an integer + * * y - an integer distinct from 0u + * + * # Return value + * + * The smallest integer `q` such that `x/y <= q`. This + * is either `x/y` or `x/y + 1`. + */ + pub pure fn div_floor(x: uint, y: uint) -> uint { return x / y; } -#[test] -fn test_overflows() { - assert (uint::max_value > 0u); - assert (uint::min_value <= 0u); - assert (uint::min_value + uint::max_value + 1u == 0u); -} + /** + * Iterate over the range [`lo`..`hi`), or stop when requested + * + * # Arguments + * + * * lo - The integer at which to start the loop (included) + * * hi - The integer at which to stop the loop (excluded) + * * it - A block to execute with each consecutive integer of the range. + * Return `true` to continue, `false` to stop. + * + * # Return value + * + * `true` If execution proceeded correctly, `false` if it was interrupted, + * that is if `it` returned `false` at any point. + */ + pub pure fn iterate(lo: uint, hi: uint, it: fn(uint) -> bool) -> bool { + let mut i = lo; + while i < hi { + if (!it(i)) { return false; } + i += 1u; + } + return true; + } -#[test] -fn test_div() { - assert(uint::div_floor(3u, 4u) == 0u); - assert(uint::div_ceil(3u, 4u) == 1u); - assert(uint::div_round(3u, 4u) == 1u); -} + /// Returns the smallest power of 2 greater than or equal to `n` + #[inline(always)] + pub fn next_power_of_two(n: uint) -> uint { + let halfbits: uint = sys::size_of::() * 4u; + let mut tmp: uint = n - 1u; + let mut shift: uint = 1u; + while shift <= halfbits { tmp |= tmp >> shift; shift <<= 1u; } + return tmp + 1u; + } + + #[test] + fn test_next_power_of_two() { + assert (uint::next_power_of_two(0u) == 0u); + assert (uint::next_power_of_two(1u) == 1u); + assert (uint::next_power_of_two(2u) == 2u); + assert (uint::next_power_of_two(3u) == 4u); + assert (uint::next_power_of_two(4u) == 4u); + assert (uint::next_power_of_two(5u) == 8u); + assert (uint::next_power_of_two(6u) == 8u); + assert (uint::next_power_of_two(7u) == 8u); + assert (uint::next_power_of_two(8u) == 8u); + assert (uint::next_power_of_two(9u) == 16u); + assert (uint::next_power_of_two(10u) == 16u); + assert (uint::next_power_of_two(11u) == 16u); + assert (uint::next_power_of_two(12u) == 16u); + assert (uint::next_power_of_two(13u) == 16u); + assert (uint::next_power_of_two(14u) == 16u); + assert (uint::next_power_of_two(15u) == 16u); + assert (uint::next_power_of_two(16u) == 16u); + assert (uint::next_power_of_two(17u) == 32u); + assert (uint::next_power_of_two(18u) == 32u); + assert (uint::next_power_of_two(19u) == 32u); + assert (uint::next_power_of_two(20u) == 32u); + assert (uint::next_power_of_two(21u) == 32u); + assert (uint::next_power_of_two(22u) == 32u); + assert (uint::next_power_of_two(23u) == 32u); + assert (uint::next_power_of_two(24u) == 32u); + assert (uint::next_power_of_two(25u) == 32u); + assert (uint::next_power_of_two(26u) == 32u); + assert (uint::next_power_of_two(27u) == 32u); + assert (uint::next_power_of_two(28u) == 32u); + assert (uint::next_power_of_two(29u) == 32u); + assert (uint::next_power_of_two(30u) == 32u); + assert (uint::next_power_of_two(31u) == 32u); + assert (uint::next_power_of_two(32u) == 32u); + assert (uint::next_power_of_two(33u) == 64u); + assert (uint::next_power_of_two(34u) == 64u); + assert (uint::next_power_of_two(35u) == 64u); + assert (uint::next_power_of_two(36u) == 64u); + assert (uint::next_power_of_two(37u) == 64u); + assert (uint::next_power_of_two(38u) == 64u); + assert (uint::next_power_of_two(39u) == 64u); + } + + #[test] + fn test_overflows() { + assert (uint::max_value > 0u); + assert (uint::min_value <= 0u); + assert (uint::min_value + uint::max_value + 1u == 0u); + } + + #[test] + fn test_div() { + assert(uint::div_floor(3u, 4u) == 0u); + assert(uint::div_ceil(3u, 4u) == 1u); + assert(uint::div_round(3u, 4u) == 1u); + } +} \ No newline at end of file diff --git a/src/libcore/uint-template/uintb.rs b/src/libcore/uint-template/uintb.rs deleted file mode 100644 index 68054d47e1f..00000000000 --- a/src/libcore/uint-template/uintb.rs +++ /dev/null @@ -1,160 +0,0 @@ -pub use inst::{ - div_ceil, div_round, div_floor, iterate, - next_power_of_two -}; - -mod inst { - pub type T = uint; - - #[cfg(target_arch = "x86")] - #[cfg(target_arch = "arm")] - pub const bits: uint = 32; - - #[cfg(target_arch = "x86_64")] - pub const bits: uint = 64; - - /** - * Divide two numbers, return the result, rounded up. - * - * # Arguments - * - * * x - an integer - * * y - an integer distinct from 0u - * - * # Return value - * - * The smallest integer `q` such that `x/y <= q`. - */ - pub pure fn div_ceil(x: uint, y: uint) -> uint { - let div = x / y; - if x % y == 0u { div } - else { div + 1u } - } - - /** - * Divide two numbers, return the result, rounded to the closest integer. - * - * # Arguments - * - * * x - an integer - * * y - an integer distinct from 0u - * - * # Return value - * - * The integer `q` closest to `x/y`. - */ - pub pure fn div_round(x: uint, y: uint) -> uint { - let div = x / y; - if x % y * 2u < y { div } - else { div + 1u } - } - - /** - * Divide two numbers, return the result, rounded down. - * - * Note: This is the same function as `div`. - * - * # Arguments - * - * * x - an integer - * * y - an integer distinct from 0u - * - * # Return value - * - * The smallest integer `q` such that `x/y <= q`. This - * is either `x/y` or `x/y + 1`. - */ - pub pure fn div_floor(x: uint, y: uint) -> uint { return x / y; } - - /** - * Iterate over the range [`lo`..`hi`), or stop when requested - * - * # Arguments - * - * * lo - The integer at which to start the loop (included) - * * hi - The integer at which to stop the loop (excluded) - * * it - A block to execute with each consecutive integer of the range. - * Return `true` to continue, `false` to stop. - * - * # Return value - * - * `true` If execution proceeded correctly, `false` if it was interrupted, - * that is if `it` returned `false` at any point. - */ - pub pure fn iterate(lo: uint, hi: uint, it: fn(uint) -> bool) -> bool { - let mut i = lo; - while i < hi { - if (!it(i)) { return false; } - i += 1u; - } - return true; - } - - /// Returns the smallest power of 2 greater than or equal to `n` - #[inline(always)] - pub fn next_power_of_two(n: uint) -> uint { - let halfbits: uint = sys::size_of::() * 4u; - let mut tmp: uint = n - 1u; - let mut shift: uint = 1u; - while shift <= halfbits { tmp |= tmp >> shift; shift <<= 1u; } - return tmp + 1u; - } - - #[test] - fn test_next_power_of_two() { - assert (uint::next_power_of_two(0u) == 0u); - assert (uint::next_power_of_two(1u) == 1u); - assert (uint::next_power_of_two(2u) == 2u); - assert (uint::next_power_of_two(3u) == 4u); - assert (uint::next_power_of_two(4u) == 4u); - assert (uint::next_power_of_two(5u) == 8u); - assert (uint::next_power_of_two(6u) == 8u); - assert (uint::next_power_of_two(7u) == 8u); - assert (uint::next_power_of_two(8u) == 8u); - assert (uint::next_power_of_two(9u) == 16u); - assert (uint::next_power_of_two(10u) == 16u); - assert (uint::next_power_of_two(11u) == 16u); - assert (uint::next_power_of_two(12u) == 16u); - assert (uint::next_power_of_two(13u) == 16u); - assert (uint::next_power_of_two(14u) == 16u); - assert (uint::next_power_of_two(15u) == 16u); - assert (uint::next_power_of_two(16u) == 16u); - assert (uint::next_power_of_two(17u) == 32u); - assert (uint::next_power_of_two(18u) == 32u); - assert (uint::next_power_of_two(19u) == 32u); - assert (uint::next_power_of_two(20u) == 32u); - assert (uint::next_power_of_two(21u) == 32u); - assert (uint::next_power_of_two(22u) == 32u); - assert (uint::next_power_of_two(23u) == 32u); - assert (uint::next_power_of_two(24u) == 32u); - assert (uint::next_power_of_two(25u) == 32u); - assert (uint::next_power_of_two(26u) == 32u); - assert (uint::next_power_of_two(27u) == 32u); - assert (uint::next_power_of_two(28u) == 32u); - assert (uint::next_power_of_two(29u) == 32u); - assert (uint::next_power_of_two(30u) == 32u); - assert (uint::next_power_of_two(31u) == 32u); - assert (uint::next_power_of_two(32u) == 32u); - assert (uint::next_power_of_two(33u) == 64u); - assert (uint::next_power_of_two(34u) == 64u); - assert (uint::next_power_of_two(35u) == 64u); - assert (uint::next_power_of_two(36u) == 64u); - assert (uint::next_power_of_two(37u) == 64u); - assert (uint::next_power_of_two(38u) == 64u); - assert (uint::next_power_of_two(39u) == 64u); - } - - #[test] - fn test_overflows() { - assert (uint::max_value > 0u); - assert (uint::min_value <= 0u); - assert (uint::min_value + uint::max_value + 1u == 0u); - } - - #[test] - fn test_div() { - assert(uint::div_floor(3u, 4u) == 0u); - assert(uint::div_ceil(3u, 4u) == 1u); - assert(uint::div_round(3u, 4u) == 1u); - } -} \ No newline at end of file