diff options
| author | Brian Anderson <banderson@mozilla.com> | 2012-11-18 17:56:50 -0800 |
|---|---|---|
| committer | Brian Anderson <banderson@mozilla.com> | 2012-11-26 18:13:54 -0800 |
| commit | be6613e048c889a0aeaff056131c2406259f1fb4 (patch) | |
| tree | 1067f383db3a97a6b85e11637ef23b0a0a6a3549 /src/libcore | |
| parent | 81a79603c0c9c2425d0a8475d29b4ef77fae8607 (diff) | |
| download | rust-be6613e048c889a0aeaff056131c2406259f1fb4.tar.gz rust-be6613e048c889a0aeaff056131c2406259f1fb4.zip | |
Remove the crate language
Diffstat (limited to 'src/libcore')
| -rw-r--r-- | src/libcore/alternate_crate.rc | 273 | ||||
| -rw-r--r-- | src/libcore/core.rc | 2 | ||||
| -rw-r--r-- | src/libcore/int-template/i16b.rs | 4 | ||||
| -rw-r--r-- | src/libcore/int-template/i32b.rs | 4 | ||||
| -rw-r--r-- | src/libcore/int-template/i64b.rs | 4 | ||||
| -rw-r--r-- | src/libcore/int-template/i8b.rs | 4 | ||||
| -rw-r--r-- | src/libcore/int-template/intb.rs | 45 | ||||
| -rw-r--r-- | src/libcore/iter-trait/dlistb.rs | 38 | ||||
| -rw-r--r-- | src/libcore/iter-trait/dvecb.rs | 22 | ||||
| -rw-r--r-- | src/libcore/iter-trait/optionb.rs | 18 | ||||
| -rw-r--r-- | src/libcore/task/mod.rs | 8 | ||||
| -rw-r--r-- | src/libcore/uint-template/u16b.rs | 4 | ||||
| -rw-r--r-- | src/libcore/uint-template/u32b.rs | 4 | ||||
| -rw-r--r-- | src/libcore/uint-template/u64b.rs | 4 | ||||
| -rw-r--r-- | src/libcore/uint-template/u8b.rs | 11 | ||||
| -rw-r--r-- | src/libcore/uint-template/uintb.rs | 160 |
16 files changed, 605 insertions, 0 deletions
diff --git a/src/libcore/alternate_crate.rc b/src/libcore/alternate_crate.rc new file mode 100644 index 00000000000..74f8d6b5cec --- /dev/null +++ b/src/libcore/alternate_crate.rc @@ -0,0 +1,273 @@ +/*! + +The Rust core library. + +The Rust core library provides runtime features required by the language, +including the task scheduler and memory allocators, as well as library +support for Rust built-in types, platform abstractions, and other commonly +used features. + +`core` includes modules corresponding to each of the integer types, each of +the floating point types, the `bool` type, tuples, characters, strings, +vectors (`vec`), shared boxes (`box`), and unsafe and borrowed pointers +(`ptr`). Additionally, `core` provides task management and creation (`task`), +communication primitives (`comm` and `pipes`), an efficient vector builder +(`dvec`), platform abstractions (`os` and `path`), basic I/O abstractions +(`io`), common traits (`cmp`, `num`, `to_str`), and complete bindings +to the C standard library (`libc`). + +`core` is linked to all crates by default and its contents imported. +Implicitly, all crates behave as if they included the following prologue: + + extern mod core; + use core::*; + +*/ + +#[link(name = "core", + vers = "0.5", + uuid = "c70c24a7-5551-4f73-8e37-380b11d80be8", + url = "https://github.com/mozilla/rust/tree/master/src/libcore")]; + +#[comment = "The Rust core library"]; +#[license = "MIT"]; +#[crate_type = "lib"]; + +// Don't link to core. We are core. +#[no_core]; + +#[warn(deprecated_mode)]; +#[warn(deprecated_pattern)]; + +#[warn(vecs_implicitly_copyable)]; +#[deny(non_camel_case_types)]; + +// Built-in-type support modules + +/// Operations and constants for `int` +#[path = "int-template.rs"] +#[merge = "int-template/intb.rs"] +pub mod int; + +/// Operations and constants for `i8` +#[path = "int-template.rs"] +#[merge = "int-template/i8b.rs"] +pub mod i8; + +/// Operations and constants for `i16` +#[path = "int-template.rs"] +#[merge = "int-template/i16b.rs"] +pub mod i16; + +/// Operations and constants for `i32` +#[path = "int-template.rs"] +#[merge = "int-template/i32b.rs"] +pub mod i32; + +/// Operations and constants for `i64` +#[path = "int-template.rs"] +#[merge = "int-template/i64b.rs"] +pub mod i64; + +/// Operations and constants for `uint` +#[path = "uint-template.rs"] +#[merge = "uint-template/uintb.rs"] +pub mod uint; + +/// Operations and constants for `u8` +#[path = "uint-template.rs"] +#[merge = "uint-template/u8b.rs"] +pub mod u8; + +/// Operations and constants for `u16` +#[path = "uint-template.rs"] +#[merge = "uint-template/u16b.rs"] +pub mod u16; + +/// Operations and constants for `u32` +#[path = "uint-template.rs"] +#[merge = "uint-template/u32b.rs"] +pub mod u32; + +/// Operations and constants for `u64` +#[path = "uint-template.rs"] +#[merge = "uint-template/u64b.rs"] +pub mod u64; + + +pub mod box; +pub mod char; +pub mod float; +pub mod f32; +pub mod f64; +pub mod str; +pub mod ptr; +pub mod vec; +pub mod at_vec; +pub mod bool; +pub mod tuple; +pub mod unit; +pub mod owned; + +// Ubiquitous-utility-type modules + +#[cfg(notest)] +pub mod ops; +pub mod cmp; +pub mod num; +pub mod hash; +pub mod either; +pub mod iter; +pub mod logging; +pub mod option; +#[path="iter-trait.rs"] +#[merge = "iter-trait/optionb.rs"] +pub mod option_iter; +pub mod result; +pub mod to_str; +pub mod to_bytes; +pub mod from_str; +pub mod util; + +// Data structure modules + +pub mod dvec; +#[path="iter-trait.rs"] +#[merge = "iter-trait/dvecb.rs"] +pub mod dvec_iter; +pub mod dlist; +#[path="iter-trait.rs"] +#[merge = "iter-trait/dlistb.rs"] +pub mod dlist_iter; +pub mod send_map; + +// Concurrency +pub mod comm; +#[merge = "task/mod.rs"] +pub mod task; +pub mod pipes; + +// Runtime and language-primitive support + +pub mod gc; +pub mod io; +pub mod libc; +pub mod os; +pub mod path; +pub mod rand; +pub mod run; +pub mod sys; +pub mod cast; +pub mod mutable; +pub mod flate; +pub mod repr; +pub mod cleanup; +pub mod reflect; +pub mod condition; + +// Modules supporting compiler-generated code +// Exported but not part of the public interface + +pub mod extfmt; +// The test harness links against core, so don't include runtime in tests. +#[cfg(notest)] +#[legacy_exports] +pub mod rt; + +// Ideally not exported, but currently is. +pub mod private; + +// For internal use, not exported. +mod unicode; +mod cmath; +mod stackwalk; + +// Top-level, visible-everywhere definitions. + +// Export various ubiquitous types, constructors, methods. + +pub use option::{Some, None}; +pub use Option = option::Option; +pub use result::{Result, Ok, Err}; + +pub use Path = path::Path; +pub use GenericPath = path::GenericPath; +pub use WindowsPath = path::WindowsPath; +pub use PosixPath = path::PosixPath; + +pub use tuple::{CopyableTuple, ImmutableTuple, ExtendedTupleOps}; +pub use str::{StrSlice, Trimmable}; +pub use vec::{ConstVector, CopyableVector, ImmutableVector}; +pub use vec::{ImmutableEqVector, ImmutableCopyableVector}; +pub use vec::{MutableVector, MutableCopyableVector}; +pub use iter::{BaseIter, ExtendedIter, EqIter, CopyableIter}; +pub use iter::{CopyableOrderedIter, CopyableNonstrictIter, Times}; +pub use num::Num; +pub use ptr::Ptr; +pub use to_str::ToStr; + +// The following exports are the core operators and kinds +// The compiler has special knowlege of these so we must not duplicate them +// when compiling for testing +#[cfg(notest)] +pub use ops::{Const, Copy, Send, Owned}; +#[cfg(notest)] +pub use ops::{Drop}; +#[cfg(notest)] +pub use ops::{Add, Sub, Mul, Div, Modulo, Neg, BitAnd, BitOr, BitXor}; +#[cfg(notest)] +pub use ops::{Shl, Shr, Index}; + +#[cfg(test)] +extern mod coreops(name = "core", vers = "0.5"); + +#[cfg(test)] +pub use coreops::ops::{Const, Copy, Send, Owned}; +#[cfg(test)] +pub use coreops::ops::{Drop}; +#[cfg(test)] +pub use coreops::ops::{Add, Sub, Mul, Div, Modulo, Neg, BitAnd, BitOr}; +#[cfg(test)] +pub use coreops::ops::{BitXor}; +#[cfg(test)] +pub use coreops::ops::{Shl, Shr, Index}; + + +// Export the log levels as global constants. Higher levels mean +// more-verbosity. Error is the bottom level, default logging level is +// warn-and-below. + +/// The error log level +pub const error : u32 = 1_u32; +/// The warning log level +pub const warn : u32 = 2_u32; +/// The info log level +pub const info : u32 = 3_u32; +/// The debug log level +pub const debug : u32 = 4_u32; + +// A curious inner-module that's not exported that contains the binding +// 'core' so that macro-expanded references to core::error and such +// can be resolved within libcore. +#[doc(hidden)] // FIXME #3538 +mod core { + pub const error : u32 = 1_u32; + pub const warn : u32 = 2_u32; + pub const info : u32 = 3_u32; + pub const debug : u32 = 4_u32; +} + +// Similar to above. Some magic to make core testable. +#[cfg(test)] +mod std { + extern mod std(vers = "0.5"); + pub use std::test; +} + +// Local Variables: +// mode: rust; +// fill-column: 78; +// indent-tabs-mode: nil +// c-basic-offset: 4 +// buffer-file-coding-system: utf-8-unix +// End: diff --git a/src/libcore/core.rc b/src/libcore/core.rc index 707d6125046..86417c93616 100644 --- a/src/libcore/core.rc +++ b/src/libcore/core.rc @@ -1,3 +1,5 @@ +// DIVERT + /*! The Rust core library. diff --git a/src/libcore/int-template/i16b.rs b/src/libcore/int-template/i16b.rs new file mode 100644 index 00000000000..b24eb86e4ae --- /dev/null +++ b/src/libcore/int-template/i16b.rs @@ -0,0 +1,4 @@ +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/i32b.rs b/src/libcore/int-template/i32b.rs new file mode 100644 index 00000000000..5bfb8a6d01c --- /dev/null +++ b/src/libcore/int-template/i32b.rs @@ -0,0 +1,4 @@ +mod inst { + pub type T = i32; + pub const bits: uint = u32::bits; +} diff --git a/src/libcore/int-template/i64b.rs b/src/libcore/int-template/i64b.rs new file mode 100644 index 00000000000..86552b2cced --- /dev/null +++ b/src/libcore/int-template/i64b.rs @@ -0,0 +1,4 @@ +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/i8b.rs b/src/libcore/int-template/i8b.rs new file mode 100644 index 00000000000..2cf7ed2983f --- /dev/null +++ b/src/libcore/int-template/i8b.rs @@ -0,0 +1,4 @@ +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/intb.rs b/src/libcore/int-template/intb.rs new file mode 100644 index 00000000000..c1f2ca944dd --- /dev/null +++ b/src/libcore/int-template/intb.rs @@ -0,0 +1,45 @@ +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/dlistb.rs b/src/libcore/iter-trait/dlistb.rs new file mode 100644 index 00000000000..2d782b1262b --- /dev/null +++ b/src/libcore/iter-trait/dlistb.rs @@ -0,0 +1,38 @@ +mod inst { + #[allow(non_camel_case_types)] + pub type IMPL_T<A> = dlist::DList<A>; + + /** + * 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<A>(self: &IMPL_T<A>, 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<A>(self: &IMPL_T<A>) -> Option<uint> { + 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 new file mode 100644 index 00000000000..b30c1372a2e --- /dev/null +++ b/src/libcore/iter-trait/dvecb.rs @@ -0,0 +1,22 @@ +mod inst { + #[allow(non_camel_case_types)] + pub type IMPL_T<A> = dvec::DVec<A>; + + /** + * Iterates through the current contents. + * + * Attempts to access this dvec during iteration will fail. + */ + pub pure fn EACH<A>(self: &IMPL_T<A>, f: fn(v: &A) -> bool) { + unsafe { + do self.swap |v| { + v.each(f); + move v + } + } + } + + pub pure fn SIZE_HINT<A>(self: &IMPL_T<A>) -> Option<uint> { + Some(self.len()) + } +} \ No newline at end of file diff --git a/src/libcore/iter-trait/optionb.rs b/src/libcore/iter-trait/optionb.rs new file mode 100644 index 00000000000..680893eb95b --- /dev/null +++ b/src/libcore/iter-trait/optionb.rs @@ -0,0 +1,18 @@ +mod inst { + #[allow(non_camel_case_types)] + pub type IMPL_T<A> = Option<A>; + + pub pure fn EACH<A>(self: &IMPL_T<A>, f: fn(v: &A) -> bool) { + match *self { + None => (), + Some(ref a) => { f(a); } + } + } + + pub pure fn SIZE_HINT<A>(self: &IMPL_T<A>) -> Option<uint> { + match *self { + None => Some(0), + Some(_) => Some(1) + } + } +} \ No newline at end of file diff --git a/src/libcore/task/mod.rs b/src/libcore/task/mod.rs new file mode 100644 index 00000000000..887983e8b6c --- /dev/null +++ b/src/libcore/task/mod.rs @@ -0,0 +1,8 @@ + +mod local_data_priv; + +pub mod local_data; + +pub mod rt; + +pub mod spawn; diff --git a/src/libcore/uint-template/u16b.rs b/src/libcore/uint-template/u16b.rs new file mode 100644 index 00000000000..aafd46f845b --- /dev/null +++ b/src/libcore/uint-template/u16b.rs @@ -0,0 +1,4 @@ +mod inst { + pub type T = u16; + pub const bits: uint = 16; +} diff --git a/src/libcore/uint-template/u32b.rs b/src/libcore/uint-template/u32b.rs new file mode 100644 index 00000000000..8e784bdf225 --- /dev/null +++ b/src/libcore/uint-template/u32b.rs @@ -0,0 +1,4 @@ +mod inst { + pub type T = u32; + pub const bits: uint = 32; +} \ No newline at end of file diff --git a/src/libcore/uint-template/u64b.rs b/src/libcore/uint-template/u64b.rs new file mode 100644 index 00000000000..43a8169f08b --- /dev/null +++ b/src/libcore/uint-template/u64b.rs @@ -0,0 +1,4 @@ +mod inst { + pub type T = u64; + pub const bits: uint = 64; +} \ No newline at end of file diff --git a/src/libcore/uint-template/u8b.rs b/src/libcore/uint-template/u8b.rs new file mode 100644 index 00000000000..a3e750861e5 --- /dev/null +++ b/src/libcore/uint-template/u8b.rs @@ -0,0 +1,11 @@ +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/uintb.rs b/src/libcore/uint-template/uintb.rs new file mode 100644 index 00000000000..68054d47e1f --- /dev/null +++ b/src/libcore/uint-template/uintb.rs @@ -0,0 +1,160 @@ +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::<uint>() * 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 |
