core: Camel case some lesser-used modules
This commit is contained in:
parent
6b43c0c1ad
commit
5394e34aa4
@ -14,7 +14,7 @@ export unsafe;
|
||||
|
||||
#[abi = "cdecl"]
|
||||
extern mod rustrt {
|
||||
fn vec_reserve_shared_actual(++t: *sys::type_desc,
|
||||
fn vec_reserve_shared_actual(++t: *sys::TypeDesc,
|
||||
++v: **vec::unsafe::vec_repr,
|
||||
++n: libc::size_t);
|
||||
}
|
||||
|
@ -4,22 +4,22 @@
|
||||
|
||||
/// Interfaces used for comparison.
|
||||
|
||||
trait ord {
|
||||
trait Ord {
|
||||
pure fn lt(&&other: self) -> bool;
|
||||
}
|
||||
|
||||
trait eq {
|
||||
trait Eq {
|
||||
pure fn eq(&&other: self) -> bool;
|
||||
}
|
||||
|
||||
pure fn lt<T: ord>(v1: &T, v2: &T) -> bool {
|
||||
pure fn lt<T: Ord>(v1: &T, v2: &T) -> bool {
|
||||
v1.lt(*v2)
|
||||
}
|
||||
|
||||
pure fn le<T: ord eq>(v1: &T, v2: &T) -> bool {
|
||||
pure fn le<T: Ord Eq>(v1: &T, v2: &T) -> bool {
|
||||
v1.lt(*v2) || v1.eq(*v2)
|
||||
}
|
||||
|
||||
pure fn eq<T: eq>(v1: &T, v2: &T) -> bool {
|
||||
pure fn eq<T: Eq>(v1: &T, v2: &T) -> bool {
|
||||
v1.eq(*v2)
|
||||
}
|
||||
|
@ -159,17 +159,22 @@ mod ptr;
|
||||
mod vec;
|
||||
mod at_vec;
|
||||
mod bool;
|
||||
#[warn(non_camel_case_types)]
|
||||
mod tuple;
|
||||
|
||||
// Ubiquitous-utility-type modules
|
||||
|
||||
#[cfg(notest)]
|
||||
mod ops;
|
||||
#[warn(non_camel_case_types)]
|
||||
mod cmp;
|
||||
#[warn(non_camel_case_types)]
|
||||
mod num;
|
||||
#[warn(non_camel_case_types)]
|
||||
mod hash;
|
||||
mod either;
|
||||
mod iter;
|
||||
#[warn(non_camel_case_types)]
|
||||
mod logging;
|
||||
mod option;
|
||||
#[path="iter-trait"]
|
||||
@ -178,8 +183,11 @@ mod option_iter {
|
||||
mod inst;
|
||||
}
|
||||
mod result;
|
||||
#[warn(non_camel_case_types)]
|
||||
mod to_str;
|
||||
#[warn(non_camel_case_types)]
|
||||
mod to_bytes;
|
||||
#[warn(non_camel_case_types)]
|
||||
mod util;
|
||||
|
||||
// Data structure modules
|
||||
@ -212,7 +220,9 @@ mod os;
|
||||
mod path;
|
||||
mod rand;
|
||||
mod run;
|
||||
#[warn(non_camel_case_types)]
|
||||
mod sys;
|
||||
#[warn(non_camel_case_types)]
|
||||
mod unsafe;
|
||||
|
||||
|
||||
@ -227,9 +237,13 @@ mod rt;
|
||||
|
||||
// For internal use, not exported
|
||||
|
||||
#[warn(non_camel_case_types)]
|
||||
mod unicode;
|
||||
#[warn(non_camel_case_types)]
|
||||
mod priv;
|
||||
#[warn(non_camel_case_types)]
|
||||
mod cmath;
|
||||
#[warn(non_camel_case_types)]
|
||||
mod stackwalk;
|
||||
|
||||
// Local Variables:
|
||||
|
@ -5,27 +5,27 @@
|
||||
import option::{some, none};
|
||||
import option = option::option;
|
||||
import path = path::path;
|
||||
import tuple::{tuple_ops, extended_tuple_ops};
|
||||
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 num::num;
|
||||
import num::Num;
|
||||
import ptr::ptr;
|
||||
import to_str::to_str;
|
||||
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, timesi;
|
||||
// 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 tuple_ops, extended_tuple_ops;
|
||||
export TupleOps, ExtendedTupleOps;
|
||||
export ptr;
|
||||
export to_str;
|
||||
export ToStr;
|
||||
|
||||
// The following exports are the core operators and kinds
|
||||
// The compiler has special knowlege of these so we must not duplicate them
|
||||
|
@ -167,7 +167,7 @@ pure fn log2(n: f32) -> f32 {
|
||||
return ln(n) / consts::ln_2;
|
||||
}
|
||||
|
||||
impl f32: num::num {
|
||||
impl f32: num::Num {
|
||||
pure fn add(&&other: f32) -> f32 { return self + other; }
|
||||
pure fn sub(&&other: f32) -> f32 { return self - other; }
|
||||
pure fn mul(&&other: f32) -> f32 { return self * other; }
|
||||
|
@ -194,7 +194,7 @@ pure fn log2(n: f64) -> f64 {
|
||||
return ln(n) / consts::ln_2;
|
||||
}
|
||||
|
||||
impl f64: num::num {
|
||||
impl f64: num::Num {
|
||||
pure fn add(&&other: f64) -> f64 { return self + other; }
|
||||
pure fn sub(&&other: f64) -> f64 { return self - other; }
|
||||
pure fn mul(&&other: f64) -> f64 { return self * other; }
|
||||
|
@ -409,7 +409,7 @@ pure fn sin(x: float) -> float { f64::sin(x as f64) as float }
|
||||
pure fn cos(x: float) -> float { f64::cos(x as f64) as float }
|
||||
pure fn tan(x: float) -> float { f64::tan(x as f64) as float }
|
||||
|
||||
impl float: num::num {
|
||||
impl float: num::Num {
|
||||
pure fn add(&&other: float) -> float { return self + other; }
|
||||
pure fn sub(&&other: float) -> float { return self - other; }
|
||||
pure fn mul(&&other: float) -> float { return self * other; }
|
||||
@ -516,7 +516,7 @@ fn test_to_str_inf() {
|
||||
|
||||
#[test]
|
||||
fn test_traits() {
|
||||
fn test<U:num::num>(ten: U) {
|
||||
fn test<U:num::Num>(ten: U) {
|
||||
assert (ten.to_int() == 10);
|
||||
|
||||
let two = ten.from_int(2);
|
||||
|
@ -1,5 +1,5 @@
|
||||
import T = inst::T;
|
||||
import cmp::{eq, ord};
|
||||
import cmp::{Eq, Ord};
|
||||
|
||||
export min_value, max_value;
|
||||
export min, max;
|
||||
@ -62,20 +62,20 @@ pure fn abs(i: T) -> T {
|
||||
if is_negative(i) { -i } else { i }
|
||||
}
|
||||
|
||||
impl T: ord {
|
||||
impl T: Ord {
|
||||
pure fn lt(&&other: T) -> bool {
|
||||
return self < other;
|
||||
}
|
||||
}
|
||||
|
||||
impl T: eq {
|
||||
impl T: Eq {
|
||||
pure fn eq(&&other: T) -> bool {
|
||||
return self == other;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
impl T: num::num {
|
||||
impl T: num::Num {
|
||||
pure fn add(&&other: T) -> T { return self + other; }
|
||||
pure fn sub(&&other: T) -> T { return self - other; }
|
||||
pure fn mul(&&other: T) -> T { return self * other; }
|
||||
@ -235,7 +235,7 @@ fn test_to_str() {
|
||||
|
||||
#[test]
|
||||
fn test_interfaces() {
|
||||
fn test<U:num::num>(ten: U) {
|
||||
fn test<U:num::Num>(ten: U) {
|
||||
assert (ten.to_int() == 10);
|
||||
|
||||
let two = ten.from_int(2);
|
||||
|
@ -1,6 +1,6 @@
|
||||
/// An interface for numbers.
|
||||
|
||||
trait num {
|
||||
trait Num {
|
||||
// FIXME: Cross-crate overloading doesn't work yet. (#2615)
|
||||
// FIXME: Trait composition. (#2616)
|
||||
pure fn add(&&other: self) -> self;
|
||||
|
@ -227,7 +227,7 @@ fn test_option_dance() {
|
||||
}
|
||||
#[test] #[should_fail] #[ignore(cfg(windows))]
|
||||
fn test_option_too_much_dance() {
|
||||
let mut y = some(util::noncopyable());
|
||||
let mut y = some(util::NonCopyable());
|
||||
let _y2 = swap_unwrap(&mut y);
|
||||
let _y3 = swap_unwrap(&mut y);
|
||||
}
|
||||
|
@ -1081,7 +1081,7 @@ impl<T: send> port<T>: selectable {
|
||||
}
|
||||
|
||||
/// A channel that can be shared between many senders.
|
||||
type shared_chan<T: send> = unsafe::exclusive<chan<T>>;
|
||||
type shared_chan<T: send> = unsafe::Exclusive<chan<T>>;
|
||||
|
||||
impl<T: send> shared_chan<T>: channel<T> {
|
||||
fn send(+x: T) {
|
||||
|
@ -5,6 +5,7 @@ export chan_from_global_ptr, weaken_task;
|
||||
import compare_and_swap = rustrt::rust_compare_and_swap_ptr;
|
||||
import task::task_builder;
|
||||
|
||||
#[allow(non_camel_case_types)] // runtime type
|
||||
type rust_port_id = uint;
|
||||
|
||||
extern mod rustrt {
|
||||
@ -15,7 +16,7 @@ extern mod rustrt {
|
||||
fn rust_task_unweaken(ch: rust_port_id);
|
||||
}
|
||||
|
||||
type global_ptr = *libc::uintptr_t;
|
||||
type GlobalPtr = *libc::uintptr_t;
|
||||
|
||||
/**
|
||||
* Atomically gets a channel from a pointer to a pointer-sized memory location
|
||||
@ -23,14 +24,14 @@ type global_ptr = *libc::uintptr_t;
|
||||
* new task to receive from it.
|
||||
*/
|
||||
unsafe fn chan_from_global_ptr<T: send>(
|
||||
global: global_ptr,
|
||||
global: GlobalPtr,
|
||||
task_fn: fn() -> task::task_builder,
|
||||
+f: fn~(comm::port<T>)
|
||||
) -> comm::chan<T> {
|
||||
|
||||
enum msg {
|
||||
proceed,
|
||||
abort
|
||||
enum Msg {
|
||||
Proceed,
|
||||
Abort
|
||||
}
|
||||
|
||||
log(debug,~"ENTERING chan_from_global_ptr, before is_prob_zero check");
|
||||
@ -48,9 +49,9 @@ unsafe fn chan_from_global_ptr<T: send>(
|
||||
|
||||
// Wait to hear if we are the official instance of
|
||||
// this global task
|
||||
match comm::recv::<msg>(setup_po) {
|
||||
proceed => f(po),
|
||||
abort => ()
|
||||
match comm::recv::<Msg>(setup_po) {
|
||||
Proceed => f(po),
|
||||
Abort => ()
|
||||
}
|
||||
};
|
||||
|
||||
@ -68,11 +69,11 @@ unsafe fn chan_from_global_ptr<T: send>(
|
||||
|
||||
if swapped {
|
||||
// Success!
|
||||
comm::send(setup_ch, proceed);
|
||||
comm::send(setup_ch, Proceed);
|
||||
ch
|
||||
} else {
|
||||
// Somebody else got in before we did
|
||||
comm::send(setup_ch, abort);
|
||||
comm::send(setup_ch, Abort);
|
||||
unsafe::reinterpret_cast(*global)
|
||||
}
|
||||
} else {
|
||||
@ -186,10 +187,10 @@ unsafe fn weaken_task(f: fn(comm::port<()>)) {
|
||||
unsafe {
|
||||
rustrt::rust_task_weaken(unsafe::reinterpret_cast(ch));
|
||||
}
|
||||
let _unweaken = unweaken(ch);
|
||||
let _unweaken = Unweaken(ch);
|
||||
f(po);
|
||||
|
||||
class unweaken {
|
||||
class Unweaken {
|
||||
let ch: comm::chan<()>;
|
||||
new(ch: comm::chan<()>) { self.ch = ch; }
|
||||
drop unsafe {
|
||||
|
@ -4,32 +4,32 @@ import unsafe::reinterpret_cast;
|
||||
import ptr::offset;
|
||||
import sys::size_of;
|
||||
|
||||
type word = uint;
|
||||
type Word = uint;
|
||||
|
||||
class frame {
|
||||
let fp: *word;
|
||||
class Frame {
|
||||
let fp: *Word;
|
||||
|
||||
new(fp: *word) {
|
||||
new(fp: *Word) {
|
||||
self.fp = fp;
|
||||
}
|
||||
}
|
||||
|
||||
fn walk_stack(visit: fn(frame) -> bool) {
|
||||
fn walk_stack(visit: fn(Frame) -> bool) {
|
||||
|
||||
debug!{"beginning stack walk"};
|
||||
|
||||
do frame_address |frame_pointer| {
|
||||
let mut frame_address: *word = unsafe {
|
||||
let mut frame_address: *Word = unsafe {
|
||||
reinterpret_cast(frame_pointer)
|
||||
};
|
||||
loop {
|
||||
let fr = frame(frame_address);
|
||||
let fr = Frame(frame_address);
|
||||
|
||||
debug!{"frame: %x", unsafe { reinterpret_cast(fr.fp) }};
|
||||
visit(fr);
|
||||
|
||||
unsafe {
|
||||
let next_fp: **word = reinterpret_cast(frame_address);
|
||||
let next_fp: **Word = reinterpret_cast(frame_address);
|
||||
frame_address = *next_fp;
|
||||
if *frame_address == 0u {
|
||||
debug!{"encountered task_start_wrapper. ending walk"};
|
||||
|
@ -1,6 +1,6 @@
|
||||
//! Misc low level stuff
|
||||
|
||||
export type_desc;
|
||||
export TypeDesc;
|
||||
export get_type_desc;
|
||||
export size_of;
|
||||
export min_align_of;
|
||||
@ -9,7 +9,8 @@ export refcount;
|
||||
export log_str;
|
||||
export shape_eq, shape_lt, shape_le;
|
||||
|
||||
enum type_desc = {
|
||||
// Corresponds to runtime type_desc type
|
||||
enum TypeDesc = {
|
||||
size: uint,
|
||||
align: uint
|
||||
// Remaining fields not listed
|
||||
@ -17,7 +18,7 @@ enum type_desc = {
|
||||
|
||||
#[abi = "cdecl"]
|
||||
extern mod rustrt {
|
||||
pure fn shape_log_str(t: *sys::type_desc, data: *()) -> ~str;
|
||||
pure fn shape_log_str(t: *sys::TypeDesc, data: *()) -> ~str;
|
||||
}
|
||||
|
||||
#[abi = "rust-intrinsic"]
|
||||
@ -48,8 +49,8 @@ pure fn shape_le<T>(x1: &T, x2: &T) -> bool {
|
||||
* Useful for calling certain function in the Rust runtime or otherwise
|
||||
* performing dark magick.
|
||||
*/
|
||||
pure fn get_type_desc<T>() -> *type_desc {
|
||||
unchecked { rusti::get_tydesc::<T>() as *type_desc }
|
||||
pure fn get_type_desc<T>() -> *TypeDesc {
|
||||
unchecked { rusti::get_tydesc::<T>() as *TypeDesc }
|
||||
}
|
||||
|
||||
/// Returns the size of a type
|
||||
|
@ -188,7 +188,7 @@ type task_opts = {
|
||||
enum task_builder = {
|
||||
opts: task_opts,
|
||||
gen_body: fn@(+fn~()) -> fn~(),
|
||||
can_not_copy: option<util::noncopyable>,
|
||||
can_not_copy: option<util::NonCopyable>,
|
||||
mut consumed: bool,
|
||||
};
|
||||
|
||||
@ -725,7 +725,7 @@ type taskgroup_data = {
|
||||
// tasks in this group.
|
||||
mut descendants: taskset,
|
||||
};
|
||||
type taskgroup_arc = unsafe::exclusive<option<taskgroup_data>>;
|
||||
type taskgroup_arc = unsafe::Exclusive<option<taskgroup_data>>;
|
||||
|
||||
type taskgroup_inner = &mut option<taskgroup_data>;
|
||||
|
||||
@ -754,7 +754,7 @@ type ancestor_node = {
|
||||
// Recursive rest of the list.
|
||||
mut ancestors: ancestor_list,
|
||||
};
|
||||
enum ancestor_list = option<unsafe::exclusive<ancestor_node>>;
|
||||
enum ancestor_list = option<unsafe::Exclusive<ancestor_node>>;
|
||||
|
||||
// Accessors for taskgroup arcs and ancestor arcs that wrap the unsafety.
|
||||
#[inline(always)]
|
||||
@ -762,7 +762,7 @@ fn access_group<U>(x: taskgroup_arc, blk: fn(taskgroup_inner) -> U) -> U {
|
||||
unsafe { x.with(blk) }
|
||||
}
|
||||
#[inline(always)]
|
||||
fn access_ancestors<U>(x: unsafe::exclusive<ancestor_node>,
|
||||
fn access_ancestors<U>(x: unsafe::Exclusive<ancestor_node>,
|
||||
blk: fn(x: &mut ancestor_node) -> U) -> U {
|
||||
unsafe { x.with(blk) }
|
||||
}
|
||||
|
@ -1,19 +1,19 @@
|
||||
trait to_bytes {
|
||||
trait ToBytes {
|
||||
fn to_bytes() -> ~[u8];
|
||||
}
|
||||
|
||||
impl ~[u8]: to_bytes {
|
||||
impl ~[u8]: ToBytes {
|
||||
fn to_bytes() -> ~[u8] { copy self }
|
||||
}
|
||||
|
||||
impl @~[u8]: to_bytes {
|
||||
impl @~[u8]: ToBytes {
|
||||
fn to_bytes() -> ~[u8] { copy *self }
|
||||
}
|
||||
|
||||
impl ~str: to_bytes {
|
||||
impl ~str: ToBytes {
|
||||
fn to_bytes() -> ~[u8] { str::bytes(self) }
|
||||
}
|
||||
|
||||
impl @(~str): to_bytes {
|
||||
impl @(~str): ToBytes {
|
||||
fn to_bytes() -> ~[u8] { str::bytes(*self) }
|
||||
}
|
||||
|
@ -1,62 +1,62 @@
|
||||
trait to_str { fn to_str() -> ~str; }
|
||||
trait ToStr { fn to_str() -> ~str; }
|
||||
|
||||
impl int: to_str {
|
||||
impl int: ToStr {
|
||||
fn to_str() -> ~str { int::str(self) }
|
||||
}
|
||||
impl i8: to_str {
|
||||
impl i8: ToStr {
|
||||
fn to_str() -> ~str { i8::str(self) }
|
||||
}
|
||||
impl i16: to_str {
|
||||
impl i16: ToStr {
|
||||
fn to_str() -> ~str { i16::str(self) }
|
||||
}
|
||||
impl i32: to_str {
|
||||
impl i32: ToStr {
|
||||
fn to_str() -> ~str { i32::str(self) }
|
||||
}
|
||||
impl i64: to_str {
|
||||
impl i64: ToStr {
|
||||
fn to_str() -> ~str { i64::str(self) }
|
||||
}
|
||||
impl uint: to_str {
|
||||
impl uint: ToStr {
|
||||
fn to_str() -> ~str { uint::str(self) }
|
||||
}
|
||||
impl u8: to_str {
|
||||
impl u8: ToStr {
|
||||
fn to_str() -> ~str { u8::str(self) }
|
||||
}
|
||||
impl u16: to_str {
|
||||
impl u16: ToStr {
|
||||
fn to_str() -> ~str { u16::str(self) }
|
||||
}
|
||||
impl u32: to_str {
|
||||
impl u32: ToStr {
|
||||
fn to_str() -> ~str { u32::str(self) }
|
||||
}
|
||||
impl u64: to_str {
|
||||
impl u64: ToStr {
|
||||
fn to_str() -> ~str { u64::str(self) }
|
||||
}
|
||||
impl float: to_str {
|
||||
impl float: ToStr {
|
||||
fn to_str() -> ~str { float::to_str(self, 4u) }
|
||||
}
|
||||
impl bool: to_str {
|
||||
impl bool: ToStr {
|
||||
fn to_str() -> ~str { bool::to_str(self) }
|
||||
}
|
||||
impl (): to_str {
|
||||
impl (): ToStr {
|
||||
fn to_str() -> ~str { ~"()" }
|
||||
}
|
||||
impl ~str: to_str {
|
||||
impl ~str: ToStr {
|
||||
fn to_str() -> ~str { self }
|
||||
}
|
||||
|
||||
impl<A: to_str copy, B: to_str copy> (A, B): to_str {
|
||||
impl<A: ToStr copy, B: ToStr copy> (A, B): ToStr {
|
||||
fn to_str() -> ~str {
|
||||
let (a, b) = self;
|
||||
~"(" + a.to_str() + ~", " + b.to_str() + ~")"
|
||||
}
|
||||
}
|
||||
impl<A: to_str copy, B: to_str copy, C: to_str copy> (A, B, C): to_str {
|
||||
impl<A: ToStr copy, B: ToStr copy, C: ToStr copy> (A, B, C): ToStr {
|
||||
fn to_str() -> ~str {
|
||||
let (a, b, c) = self;
|
||||
~"(" + a.to_str() + ~", " + b.to_str() + ~", " + c.to_str() + ~")"
|
||||
}
|
||||
}
|
||||
|
||||
impl<A: to_str> ~[A]: to_str {
|
||||
impl<A: ToStr> ~[A]: ToStr {
|
||||
fn to_str() -> ~str {
|
||||
let mut acc = ~"[", first = true;
|
||||
for vec::each(self) |elt| {
|
||||
@ -69,10 +69,10 @@ impl<A: to_str> ~[A]: to_str {
|
||||
}
|
||||
}
|
||||
|
||||
impl<A: to_str> @A: to_str {
|
||||
impl<A: ToStr> @A: ToStr {
|
||||
fn to_str() -> ~str { ~"@" + (*self).to_str() }
|
||||
}
|
||||
impl<A: to_str> ~A: to_str {
|
||||
impl<A: ToStr> ~A: ToStr {
|
||||
fn to_str() -> ~str { ~"~" + (*self).to_str() }
|
||||
}
|
||||
|
||||
|
@ -1,12 +1,12 @@
|
||||
//! Operations on tuples
|
||||
|
||||
trait tuple_ops<T,U> {
|
||||
trait TupleOps<T,U> {
|
||||
pure fn first() -> T;
|
||||
pure fn second() -> U;
|
||||
pure fn swap() -> (U, T);
|
||||
}
|
||||
|
||||
impl<T: copy, U: copy> (T, U): tuple_ops<T,U> {
|
||||
impl<T: copy, U: copy> (T, U): TupleOps<T,U> {
|
||||
|
||||
/// Return the first element of self
|
||||
pure fn first() -> T {
|
||||
@ -28,12 +28,12 @@ impl<T: copy, U: copy> (T, U): tuple_ops<T,U> {
|
||||
|
||||
}
|
||||
|
||||
trait extended_tuple_ops<A,B> {
|
||||
trait ExtendedTupleOps<A,B> {
|
||||
fn zip() -> ~[(A, B)];
|
||||
fn map<C>(f: fn(A, B) -> C) -> ~[C];
|
||||
}
|
||||
|
||||
impl<A: copy, B: copy> (&[A], &[B]): extended_tuple_ops<A,B> {
|
||||
impl<A: copy, B: copy> (&[A], &[B]): ExtendedTupleOps<A,B> {
|
||||
|
||||
fn zip() -> ~[(A, B)] {
|
||||
let (a, b) = self;
|
||||
@ -46,7 +46,7 @@ impl<A: copy, B: copy> (&[A], &[B]): extended_tuple_ops<A,B> {
|
||||
}
|
||||
}
|
||||
|
||||
impl<A: copy, B: copy> (~[A], ~[B]): extended_tuple_ops<A,B> {
|
||||
impl<A: copy, B: copy> (~[A], ~[B]): ExtendedTupleOps<A,B> {
|
||||
|
||||
fn zip() -> ~[(A, B)] {
|
||||
let (a, b) = self;
|
||||
|
@ -1,5 +1,5 @@
|
||||
import T = inst::T;
|
||||
import cmp::{eq, ord};
|
||||
import cmp::{Eq, Ord};
|
||||
|
||||
export min_value, max_value;
|
||||
export min, max;
|
||||
@ -56,19 +56,19 @@ pure fn compl(i: T) -> T {
|
||||
max_value ^ i
|
||||
}
|
||||
|
||||
impl T: ord {
|
||||
impl T: Ord {
|
||||
pure fn lt(&&other: T) -> bool {
|
||||
return self < other;
|
||||
}
|
||||
}
|
||||
|
||||
impl T: eq {
|
||||
impl T: Eq {
|
||||
pure fn eq(&&other: T) -> bool {
|
||||
return self == other;
|
||||
}
|
||||
}
|
||||
|
||||
impl T: num::num {
|
||||
impl T: num::Num {
|
||||
pure fn add(&&other: T) -> T { return self + other; }
|
||||
pure fn sub(&&other: T) -> T { return self - other; }
|
||||
pure fn mul(&&other: T) -> T { return self * other; }
|
||||
|
@ -2,9 +2,9 @@
|
||||
|
||||
export reinterpret_cast, forget, bump_box_refcount, transmute;
|
||||
|
||||
export shared_mutable_state, clone_shared_mutable_state;
|
||||
export SharedMutableState, shared_mutable_state, clone_shared_mutable_state;
|
||||
export get_shared_mutable_state, get_shared_immutable_state;
|
||||
export exclusive;
|
||||
export Exclusive, exclusive;
|
||||
|
||||
import task::atomically;
|
||||
|
||||
@ -57,16 +57,16 @@ unsafe fn transmute<L, G>(-thing: L) -> G {
|
||||
* Shared state & exclusive ARC
|
||||
****************************************************************************/
|
||||
|
||||
type arc_data<T> = {
|
||||
type ArcData<T> = {
|
||||
mut count: libc::intptr_t,
|
||||
data: T
|
||||
};
|
||||
|
||||
class arc_destruct<T> {
|
||||
class ArcDestruct<T> {
|
||||
let data: *libc::c_void;
|
||||
new(data: *libc::c_void) { self.data = data; }
|
||||
drop unsafe {
|
||||
let data: ~arc_data<T> = unsafe::reinterpret_cast(self.data);
|
||||
let data: ~ArcData<T> = unsafe::reinterpret_cast(self.data);
|
||||
let new_count = rustrt::rust_atomic_decrement(&mut data.count);
|
||||
assert new_count >= 0;
|
||||
if new_count == 0 {
|
||||
@ -83,20 +83,20 @@ class arc_destruct<T> {
|
||||
* Data races between tasks can result in crashes and, with sufficient
|
||||
* cleverness, arbitrary type coercion.
|
||||
*/
|
||||
type shared_mutable_state<T: send> = arc_destruct<T>;
|
||||
type SharedMutableState<T: send> = ArcDestruct<T>;
|
||||
|
||||
unsafe fn shared_mutable_state<T: send>(+data: T) -> shared_mutable_state<T> {
|
||||
unsafe fn shared_mutable_state<T: send>(+data: T) -> SharedMutableState<T> {
|
||||
let data = ~{mut count: 1, data: data};
|
||||
unsafe {
|
||||
let ptr = unsafe::transmute(data);
|
||||
arc_destruct(ptr)
|
||||
ArcDestruct(ptr)
|
||||
}
|
||||
}
|
||||
|
||||
unsafe fn get_shared_mutable_state<T: send>(rc: &shared_mutable_state<T>)
|
||||
unsafe fn get_shared_mutable_state<T: send>(rc: &SharedMutableState<T>)
|
||||
-> &mut T {
|
||||
unsafe {
|
||||
let ptr: ~arc_data<T> = unsafe::reinterpret_cast((*rc).data);
|
||||
let ptr: ~ArcData<T> = unsafe::reinterpret_cast((*rc).data);
|
||||
assert ptr.count > 0;
|
||||
// Cast us back into the correct region
|
||||
let r = unsafe::reinterpret_cast(&ptr.data);
|
||||
@ -104,10 +104,10 @@ unsafe fn get_shared_mutable_state<T: send>(rc: &shared_mutable_state<T>)
|
||||
return r;
|
||||
}
|
||||
}
|
||||
unsafe fn get_shared_immutable_state<T: send>(rc: &shared_mutable_state<T>)
|
||||
unsafe fn get_shared_immutable_state<T: send>(rc: &SharedMutableState<T>)
|
||||
-> &T {
|
||||
unsafe {
|
||||
let ptr: ~arc_data<T> = unsafe::reinterpret_cast((*rc).data);
|
||||
let ptr: ~ArcData<T> = unsafe::reinterpret_cast((*rc).data);
|
||||
assert ptr.count > 0;
|
||||
// Cast us back into the correct region
|
||||
let r = unsafe::reinterpret_cast(&ptr.data);
|
||||
@ -116,19 +116,20 @@ unsafe fn get_shared_immutable_state<T: send>(rc: &shared_mutable_state<T>)
|
||||
}
|
||||
}
|
||||
|
||||
unsafe fn clone_shared_mutable_state<T: send>(rc: &shared_mutable_state<T>)
|
||||
-> shared_mutable_state<T> {
|
||||
unsafe fn clone_shared_mutable_state<T: send>(rc: &SharedMutableState<T>)
|
||||
-> SharedMutableState<T> {
|
||||
unsafe {
|
||||
let ptr: ~arc_data<T> = unsafe::reinterpret_cast((*rc).data);
|
||||
let ptr: ~ArcData<T> = unsafe::reinterpret_cast((*rc).data);
|
||||
let new_count = rustrt::rust_atomic_increment(&mut ptr.count);
|
||||
assert new_count >= 2;
|
||||
unsafe::forget(ptr);
|
||||
}
|
||||
arc_destruct((*rc).data)
|
||||
ArcDestruct((*rc).data)
|
||||
}
|
||||
|
||||
/****************************************************************************/
|
||||
|
||||
#[allow(non_camel_case_types)] // runtime type
|
||||
type rust_little_lock = *libc::c_void;
|
||||
|
||||
#[abi = "cdecl"]
|
||||
@ -147,7 +148,7 @@ extern mod rustrt {
|
||||
fn rust_unlock_little_lock(lock: rust_little_lock);
|
||||
}
|
||||
|
||||
class little_lock {
|
||||
class LittleLock {
|
||||
let l: rust_little_lock;
|
||||
new() {
|
||||
self.l = rustrt::rust_create_little_lock();
|
||||
@ -155,9 +156,9 @@ class little_lock {
|
||||
drop { rustrt::rust_destroy_little_lock(self.l); }
|
||||
}
|
||||
|
||||
impl little_lock {
|
||||
impl LittleLock {
|
||||
unsafe fn lock<T>(f: fn() -> T) -> T {
|
||||
class unlock {
|
||||
class Unlock {
|
||||
let l: rust_little_lock;
|
||||
new(l: rust_little_lock) { self.l = l; }
|
||||
drop { rustrt::rust_unlock_little_lock(self.l); }
|
||||
@ -165,29 +166,29 @@ impl little_lock {
|
||||
|
||||
do atomically {
|
||||
rustrt::rust_lock_little_lock(self.l);
|
||||
let _r = unlock(self.l);
|
||||
let _r = Unlock(self.l);
|
||||
f()
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
struct ex_data<T: send> { lock: little_lock; mut failed: bool; mut data: T; }
|
||||
struct ExData<T: send> { lock: LittleLock; mut failed: bool; mut data: T; }
|
||||
/**
|
||||
* An arc over mutable data that is protected by a lock. For library use only.
|
||||
*/
|
||||
struct exclusive<T: send> { x: shared_mutable_state<ex_data<T>>; }
|
||||
struct Exclusive<T: send> { x: SharedMutableState<ExData<T>>; }
|
||||
|
||||
fn exclusive<T:send >(+user_data: T) -> exclusive<T> {
|
||||
let data = ex_data {
|
||||
lock: little_lock(), mut failed: false, mut data: user_data
|
||||
fn exclusive<T:send >(+user_data: T) -> Exclusive<T> {
|
||||
let data = ExData {
|
||||
lock: LittleLock(), mut failed: false, mut data: user_data
|
||||
};
|
||||
exclusive { x: unsafe { shared_mutable_state(data) } }
|
||||
Exclusive { x: unsafe { shared_mutable_state(data) } }
|
||||
}
|
||||
|
||||
impl<T: send> exclusive<T> {
|
||||
impl<T: send> Exclusive<T> {
|
||||
// Duplicate an exclusive ARC, as std::arc::clone.
|
||||
fn clone() -> exclusive<T> {
|
||||
exclusive { x: unsafe { clone_shared_mutable_state(&self.x) } }
|
||||
fn clone() -> Exclusive<T> {
|
||||
Exclusive { x: unsafe { clone_shared_mutable_state(&self.x) } }
|
||||
}
|
||||
|
||||
// Exactly like std::arc::mutex_arc,access(), but with the little_lock
|
||||
|
@ -29,7 +29,7 @@ fn replace<T>(dest: &mut T, +src: T) -> T {
|
||||
}
|
||||
|
||||
/// A non-copyable dummy type.
|
||||
class noncopyable {
|
||||
class NonCopyable {
|
||||
i: ();
|
||||
new() { self.i = (); }
|
||||
drop { }
|
||||
@ -52,7 +52,7 @@ mod tests {
|
||||
}
|
||||
#[test]
|
||||
fn test_replace() {
|
||||
let mut x = some(noncopyable());
|
||||
let mut x = some(NonCopyable());
|
||||
let y = replace(&mut x, none);
|
||||
assert x.is_none();
|
||||
assert y.is_some();
|
||||
|
@ -95,10 +95,10 @@ export vec_concat;
|
||||
|
||||
#[abi = "cdecl"]
|
||||
extern mod rustrt {
|
||||
fn vec_reserve_shared(++t: *sys::type_desc,
|
||||
fn vec_reserve_shared(++t: *sys::TypeDesc,
|
||||
++v: **unsafe::vec_repr,
|
||||
++n: libc::size_t);
|
||||
fn vec_from_buf_shared(++t: *sys::type_desc,
|
||||
fn vec_from_buf_shared(++t: *sys::TypeDesc,
|
||||
++ptr: *(),
|
||||
++count: libc::size_t) -> *unsafe::vec_repr;
|
||||
}
|
||||
|
@ -3,7 +3,8 @@
|
||||
* between tasks.
|
||||
*/
|
||||
|
||||
import unsafe::{shared_mutable_state, clone_shared_mutable_state,
|
||||
import unsafe::{SharedMutableState,
|
||||
shared_mutable_state, clone_shared_mutable_state,
|
||||
get_shared_mutable_state, get_shared_immutable_state};
|
||||
import sync;
|
||||
import sync::{mutex, rwlock};
|
||||
@ -39,7 +40,7 @@ impl &condvar {
|
||||
****************************************************************************/
|
||||
|
||||
/// An atomically reference counted wrapper for shared immutable state.
|
||||
struct arc<T: const send> { x: shared_mutable_state<T>; }
|
||||
struct arc<T: const send> { x: SharedMutableState<T>; }
|
||||
|
||||
/// Create an atomically reference counted wrapper.
|
||||
fn arc<T: const send>(+data: T) -> arc<T> {
|
||||
@ -71,7 +72,7 @@ fn clone<T: const send>(rc: &arc<T>) -> arc<T> {
|
||||
|
||||
struct mutex_arc_inner<T: send> { lock: mutex; failed: bool; data: T; }
|
||||
/// An ARC with mutable data protected by a blocking mutex.
|
||||
struct mutex_arc<T: send> { x: shared_mutable_state<mutex_arc_inner<T>>; }
|
||||
struct mutex_arc<T: send> { x: SharedMutableState<mutex_arc_inner<T>>; }
|
||||
|
||||
/// Create a mutex-protected ARC with the supplied data.
|
||||
fn mutex_arc<T: send>(+user_data: T) -> mutex_arc<T> {
|
||||
@ -176,7 +177,7 @@ struct rw_arc_inner<T: const send> { lock: rwlock; failed: bool; data: T; }
|
||||
* Unlike mutex_arcs, rw_arcs are safe, because they cannot be nested.
|
||||
*/
|
||||
struct rw_arc<T: const send> {
|
||||
x: shared_mutable_state<rw_arc_inner<T>>;
|
||||
x: SharedMutableState<rw_arc_inner<T>>;
|
||||
mut cant_nest: ();
|
||||
}
|
||||
|
||||
|
@ -12,12 +12,12 @@ export breakpoint;
|
||||
|
||||
#[abi = "cdecl"]
|
||||
extern mod rustrt {
|
||||
fn debug_tydesc(td: *sys::type_desc);
|
||||
fn debug_opaque(td: *sys::type_desc, x: *());
|
||||
fn debug_box(td: *sys::type_desc, x: *());
|
||||
fn debug_tag(td: *sys::type_desc, x: *());
|
||||
fn debug_fn(td: *sys::type_desc, x: *());
|
||||
fn debug_ptrcast(td: *sys::type_desc, x: *()) -> *();
|
||||
fn debug_tydesc(td: *sys::TypeDesc);
|
||||
fn debug_opaque(td: *sys::TypeDesc, x: *());
|
||||
fn debug_box(td: *sys::TypeDesc, x: *());
|
||||
fn debug_tag(td: *sys::TypeDesc, x: *());
|
||||
fn debug_fn(td: *sys::TypeDesc, x: *());
|
||||
fn debug_ptrcast(td: *sys::TypeDesc, x: *()) -> *();
|
||||
fn rust_dbg_breakpoint();
|
||||
}
|
||||
|
||||
|
@ -622,11 +622,11 @@ impl <A: to_json> option<A>: to_json {
|
||||
}
|
||||
}
|
||||
|
||||
impl json: to_str::to_str {
|
||||
impl json: to_str::ToStr {
|
||||
fn to_str() -> ~str { to_str(self) }
|
||||
}
|
||||
|
||||
impl error: to_str::to_str {
|
||||
impl error: to_str::ToStr {
|
||||
fn to_str() -> ~str {
|
||||
fmt!{"%u:%u: %s", self.line, self.col, *self.msg}
|
||||
}
|
||||
|
@ -3,7 +3,7 @@
|
||||
#[warn(deprecated_mode)];
|
||||
|
||||
import io::writer_util;
|
||||
import to_str::to_str;
|
||||
import to_str::ToStr;
|
||||
export hashmap, hashfn, eqfn, set, map, chained, hashmap, str_hash;
|
||||
export box_str_hash;
|
||||
export bytes_hash, int_hash, uint_hash, set_add;
|
||||
@ -327,7 +327,7 @@ mod chained {
|
||||
}
|
||||
}
|
||||
|
||||
impl<K: copy to_str, V: to_str copy> t<K, V>: to_str {
|
||||
impl<K: copy ToStr, V: ToStr copy> t<K, V>: ToStr {
|
||||
fn to_writer(wr: io::writer) {
|
||||
if self.count == 0u {
|
||||
wr.write_str(~"{}");
|
||||
|
@ -673,7 +673,7 @@ fn to_str(url: url) -> ~str {
|
||||
fragment]);
|
||||
}
|
||||
|
||||
impl url: to_str::to_str {
|
||||
impl url: to_str::ToStr {
|
||||
fn to_str() -> ~str {
|
||||
to_str(self)
|
||||
}
|
||||
|
@ -1,6 +1,6 @@
|
||||
//! Sorting methods
|
||||
import vec::{len, push};
|
||||
import core::cmp::{eq, ord};
|
||||
import core::cmp::{Eq, Ord};
|
||||
|
||||
export le;
|
||||
export merge_sort;
|
||||
@ -153,7 +153,7 @@ fn qsort3<T: copy>(compare_func_lt: le<T>, compare_func_eq: le<T>,
|
||||
*
|
||||
* This is an unstable sort.
|
||||
*/
|
||||
fn quick_sort3<T: copy ord eq>(arr: ~[mut T]) {
|
||||
fn quick_sort3<T: copy Ord Eq>(arr: ~[mut T]) {
|
||||
if arr.len() <= 1 { return; }
|
||||
qsort3(core::cmp::lt, core::cmp::eq, arr, 0, (arr.len() - 1) as int);
|
||||
}
|
||||
|
@ -8,7 +8,7 @@
|
||||
export condvar, semaphore, mutex, rwlock;
|
||||
|
||||
// FIXME (#3119) This shouldn't be a thing exported from core.
|
||||
import unsafe::exclusive;
|
||||
import unsafe::{Exclusive, exclusive};
|
||||
|
||||
/****************************************************************************
|
||||
* Internals
|
||||
@ -55,7 +55,7 @@ struct sem_inner<Q> {
|
||||
// a condition variable attached, others should.
|
||||
blocked: Q;
|
||||
}
|
||||
enum sem<Q: send> = exclusive<sem_inner<Q>>;
|
||||
enum sem<Q: send> = Exclusive<sem_inner<Q>>;
|
||||
|
||||
fn new_sem<Q: send>(count: int, +q: Q) -> sem<Q> {
|
||||
let (wait_tail, wait_head) = pipes::stream();
|
||||
@ -293,7 +293,7 @@ struct rwlock_inner {
|
||||
struct rwlock {
|
||||
/* priv */ order_lock: semaphore;
|
||||
/* priv */ access_lock: sem<waitqueue>;
|
||||
/* priv */ state: exclusive<rwlock_inner>;
|
||||
/* priv */ state: Exclusive<rwlock_inner>;
|
||||
}
|
||||
|
||||
/// Create a new rwlock.
|
||||
|
@ -1,6 +1,6 @@
|
||||
// A protocol compiler for Rust.
|
||||
|
||||
import to_str::to_str;
|
||||
import to_str::ToStr;
|
||||
|
||||
import dvec::dvec;
|
||||
|
||||
|
@ -1,4 +1,4 @@
|
||||
import to_str::to_str;
|
||||
import to_str::ToStr;
|
||||
import dvec::dvec;
|
||||
|
||||
import ast::{ident};
|
||||
@ -9,7 +9,7 @@ enum direction {
|
||||
send, recv
|
||||
}
|
||||
|
||||
impl direction: to_str {
|
||||
impl direction: ToStr {
|
||||
fn to_str() -> ~str {
|
||||
match self {
|
||||
send => ~"send",
|
||||
|
@ -152,11 +152,11 @@ fn check_crate(tcx: ty::ctxt,
|
||||
return last_use_map;
|
||||
}
|
||||
|
||||
impl live_node: to_str::to_str {
|
||||
impl live_node: to_str::ToStr {
|
||||
fn to_str() -> ~str { fmt!{"ln(%u)", *self} }
|
||||
}
|
||||
|
||||
impl variable: to_str::to_str {
|
||||
impl variable: to_str::ToStr {
|
||||
fn to_str() -> ~str { fmt!{"v(%u)", *self} }
|
||||
}
|
||||
|
||||
|
@ -1,9 +1,9 @@
|
||||
import to_str::*;
|
||||
import to_str::to_str;
|
||||
import to_str::ToStr;
|
||||
|
||||
mod kitty {
|
||||
|
||||
class cat : to_str {
|
||||
class cat : ToStr {
|
||||
priv {
|
||||
let mut meows : uint;
|
||||
fn meow() {
|
||||
|
@ -1,10 +1,10 @@
|
||||
#[link(name = "a", vers = "0.1")];
|
||||
#[crate_type = "lib"];
|
||||
|
||||
trait to_str {
|
||||
fn to_str() -> ~str;
|
||||
trait to_strz {
|
||||
fn to_strz() -> ~str;
|
||||
}
|
||||
|
||||
impl ~str: to_str {
|
||||
fn to_str() -> ~str { self }
|
||||
impl ~str: to_strz {
|
||||
fn to_strz() -> ~str { self }
|
||||
}
|
||||
|
@ -2,8 +2,8 @@
|
||||
#[crate_type = "lib"];
|
||||
|
||||
use a;
|
||||
import a::to_str;
|
||||
import a::to_strz;
|
||||
|
||||
impl int: to_str {
|
||||
fn to_str() -> ~str { fmt!{"%?", self} }
|
||||
impl int: to_strz {
|
||||
fn to_strz() -> ~str { fmt!{"%?", self} }
|
||||
}
|
||||
|
@ -3,8 +3,8 @@
|
||||
|
||||
use a;
|
||||
|
||||
import a::to_str;
|
||||
import a::to_strz;
|
||||
|
||||
impl bool: to_str {
|
||||
fn to_str() -> ~str { fmt!{"%b", self} }
|
||||
impl bool: to_strz {
|
||||
fn to_strz() -> ~str { fmt!{"%b", self} }
|
||||
}
|
||||
|
@ -1,17 +1,17 @@
|
||||
// xfail-fast
|
||||
// aux-build:cci_class_cast.rs
|
||||
use cci_class_cast;
|
||||
import to_str::to_str;
|
||||
import to_str::ToStr;
|
||||
import cci_class_cast::kitty::*;
|
||||
|
||||
fn print_out<T: to_str>(thing: T, expected: ~str) {
|
||||
fn print_out<T: ToStr>(thing: T, expected: ~str) {
|
||||
let actual = thing.to_str();
|
||||
debug!{"%s", actual};
|
||||
assert(actual == expected);
|
||||
}
|
||||
|
||||
fn main() {
|
||||
let nyan : to_str = cat(0u, 2, ~"nyan") as to_str;
|
||||
let nyan : ToStr = cat(0u, 2, ~"nyan") as ToStr;
|
||||
print_out(nyan, ~"nyan");
|
||||
}
|
||||
|
||||
|
@ -1,6 +1,6 @@
|
||||
// xfail-fast
|
||||
import to_str::*;
|
||||
import to_str::to_str;
|
||||
import to_str::ToStr;
|
||||
|
||||
class cat {
|
||||
priv {
|
||||
@ -35,17 +35,17 @@ class cat {
|
||||
}
|
||||
}
|
||||
|
||||
impl cat: to_str {
|
||||
impl cat: ToStr {
|
||||
fn to_str() -> ~str { self.name }
|
||||
}
|
||||
|
||||
fn print_out<T: to_str>(thing: T, expected: ~str) {
|
||||
fn print_out<T: ToStr>(thing: T, expected: ~str) {
|
||||
let actual = thing.to_str();
|
||||
debug!{"%s", actual};
|
||||
assert(actual == expected);
|
||||
}
|
||||
|
||||
fn main() {
|
||||
let nyan : to_str = cat(0u, 2, ~"nyan") as to_str;
|
||||
let nyan : ToStr = cat(0u, 2, ~"nyan") as ToStr;
|
||||
print_out(nyan, ~"nyan");
|
||||
}
|
||||
|
@ -7,10 +7,10 @@ use a;
|
||||
use b;
|
||||
use c;
|
||||
|
||||
import a::to_str;
|
||||
import a::to_strz;
|
||||
|
||||
fn main() {
|
||||
io::println((~"foo").to_str());
|
||||
io::println(1.to_str());
|
||||
io::println(true.to_str());
|
||||
io::println((~"foo").to_strz());
|
||||
io::println(1.to_strz());
|
||||
io::println(true.to_strz());
|
||||
}
|
||||
|
@ -13,7 +13,7 @@ enum square {
|
||||
empty
|
||||
}
|
||||
|
||||
impl square: to_str::to_str {
|
||||
impl square: to_str::ToStr {
|
||||
fn to_str() -> ~str {
|
||||
match self {
|
||||
bot => { ~"R" }
|
||||
|
Loading…
x
Reference in New Issue
Block a user