1
Fork 0

core: Camel case some lesser-used modules

This commit is contained in:
Brian Anderson 2012-08-13 16:20:27 -07:00
parent 6b43c0c1ad
commit 5394e34aa4
40 changed files with 187 additions and 169 deletions

View file

@ -14,7 +14,7 @@ export unsafe;
#[abi = "cdecl"] #[abi = "cdecl"]
extern mod rustrt { 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, ++v: **vec::unsafe::vec_repr,
++n: libc::size_t); ++n: libc::size_t);
} }

View file

@ -4,22 +4,22 @@
/// Interfaces used for comparison. /// Interfaces used for comparison.
trait ord { trait Ord {
pure fn lt(&&other: self) -> bool; pure fn lt(&&other: self) -> bool;
} }
trait eq { trait Eq {
pure fn eq(&&other: self) -> bool; 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) 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) 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) v1.eq(*v2)
} }

View file

@ -159,17 +159,22 @@ mod ptr;
mod vec; mod vec;
mod at_vec; mod at_vec;
mod bool; mod bool;
#[warn(non_camel_case_types)]
mod tuple; mod tuple;
// Ubiquitous-utility-type modules // Ubiquitous-utility-type modules
#[cfg(notest)] #[cfg(notest)]
mod ops; mod ops;
#[warn(non_camel_case_types)]
mod cmp; mod cmp;
#[warn(non_camel_case_types)]
mod num; mod num;
#[warn(non_camel_case_types)]
mod hash; mod hash;
mod either; mod either;
mod iter; mod iter;
#[warn(non_camel_case_types)]
mod logging; mod logging;
mod option; mod option;
#[path="iter-trait"] #[path="iter-trait"]
@ -178,8 +183,11 @@ mod option_iter {
mod inst; mod inst;
} }
mod result; mod result;
#[warn(non_camel_case_types)]
mod to_str; mod to_str;
#[warn(non_camel_case_types)]
mod to_bytes; mod to_bytes;
#[warn(non_camel_case_types)]
mod util; mod util;
// Data structure modules // Data structure modules
@ -212,7 +220,9 @@ mod os;
mod path; mod path;
mod rand; mod rand;
mod run; mod run;
#[warn(non_camel_case_types)]
mod sys; mod sys;
#[warn(non_camel_case_types)]
mod unsafe; mod unsafe;
@ -227,9 +237,13 @@ mod rt;
// For internal use, not exported // For internal use, not exported
#[warn(non_camel_case_types)]
mod unicode; mod unicode;
#[warn(non_camel_case_types)]
mod priv; mod priv;
#[warn(non_camel_case_types)]
mod cmath; mod cmath;
#[warn(non_camel_case_types)]
mod stackwalk; mod stackwalk;
// Local Variables: // Local Variables:

View file

@ -5,27 +5,27 @@
import option::{some, none}; import option::{some, none};
import option = option::option; import option = option::option;
import path = path::path; import path = path::path;
import tuple::{tuple_ops, extended_tuple_ops}; import tuple::{TupleOps, ExtendedTupleOps};
import str::{str_slice, unique_str}; import str::{str_slice, unique_str};
import vec::{const_vector, copyable_vector, immutable_vector}; import vec::{const_vector, copyable_vector, immutable_vector};
import vec::{immutable_copyable_vector, iter_trait_extensions}; import vec::{immutable_copyable_vector, iter_trait_extensions};
import iter::{base_iter, extended_iter, copyable_iter, times, timesi}; import iter::{base_iter, extended_iter, copyable_iter, times, timesi};
import num::num; import num::Num;
import ptr::ptr; import ptr::ptr;
import to_str::to_str; import to_str::ToStr;
export path, option, some, none, unreachable; export path, option, some, none, unreachable;
export extensions; export extensions;
// The following exports are the extension impls for numeric types // 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 // The following exports are the common traits
export str_slice, unique_str; export str_slice, unique_str;
export const_vector, copyable_vector, immutable_vector; export const_vector, copyable_vector, immutable_vector;
export immutable_copyable_vector, iter_trait_extensions; export immutable_copyable_vector, iter_trait_extensions;
export base_iter, copyable_iter, extended_iter; export base_iter, copyable_iter, extended_iter;
export tuple_ops, extended_tuple_ops; export TupleOps, ExtendedTupleOps;
export ptr; export ptr;
export to_str; export ToStr;
// The following exports are the core operators and kinds // The following exports are the core operators and kinds
// The compiler has special knowlege of these so we must not duplicate them // The compiler has special knowlege of these so we must not duplicate them

View file

@ -167,7 +167,7 @@ pure fn log2(n: f32) -> f32 {
return ln(n) / consts::ln_2; 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 add(&&other: f32) -> f32 { return self + other; }
pure fn sub(&&other: f32) -> f32 { return self - other; } pure fn sub(&&other: f32) -> f32 { return self - other; }
pure fn mul(&&other: f32) -> f32 { return self * other; } pure fn mul(&&other: f32) -> f32 { return self * other; }

View file

@ -194,7 +194,7 @@ pure fn log2(n: f64) -> f64 {
return ln(n) / consts::ln_2; 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 add(&&other: f64) -> f64 { return self + other; }
pure fn sub(&&other: f64) -> f64 { return self - other; } pure fn sub(&&other: f64) -> f64 { return self - other; }
pure fn mul(&&other: f64) -> f64 { return self * other; } pure fn mul(&&other: f64) -> f64 { return self * other; }

View file

@ -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 cos(x: float) -> float { f64::cos(x as f64) as float }
pure fn tan(x: float) -> float { f64::tan(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 add(&&other: float) -> float { return self + other; }
pure fn sub(&&other: float) -> float { return self - other; } pure fn sub(&&other: float) -> float { return self - other; }
pure fn mul(&&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] #[test]
fn test_traits() { fn test_traits() {
fn test<U:num::num>(ten: U) { fn test<U:num::Num>(ten: U) {
assert (ten.to_int() == 10); assert (ten.to_int() == 10);
let two = ten.from_int(2); let two = ten.from_int(2);

View file

@ -1,5 +1,5 @@
import T = inst::T; import T = inst::T;
import cmp::{eq, ord}; import cmp::{Eq, Ord};
export min_value, max_value; export min_value, max_value;
export min, max; export min, max;
@ -62,20 +62,20 @@ pure fn abs(i: T) -> T {
if is_negative(i) { -i } else { i } if is_negative(i) { -i } else { i }
} }
impl T: ord { impl T: Ord {
pure fn lt(&&other: T) -> bool { pure fn lt(&&other: T) -> bool {
return self < other; return self < other;
} }
} }
impl T: eq { impl T: Eq {
pure fn eq(&&other: T) -> bool { pure fn eq(&&other: T) -> bool {
return self == other; return self == other;
} }
} }
impl T: num::num { impl T: num::Num {
pure fn add(&&other: T) -> T { return self + other; } pure fn add(&&other: T) -> T { return self + other; }
pure fn sub(&&other: T) -> T { return self - other; } pure fn sub(&&other: T) -> T { return self - other; }
pure fn mul(&&other: T) -> T { return self * other; } pure fn mul(&&other: T) -> T { return self * other; }
@ -235,7 +235,7 @@ fn test_to_str() {
#[test] #[test]
fn test_interfaces() { fn test_interfaces() {
fn test<U:num::num>(ten: U) { fn test<U:num::Num>(ten: U) {
assert (ten.to_int() == 10); assert (ten.to_int() == 10);
let two = ten.from_int(2); let two = ten.from_int(2);

View file

@ -1,6 +1,6 @@
/// An interface for numbers. /// An interface for numbers.
trait num { trait Num {
// FIXME: Cross-crate overloading doesn't work yet. (#2615) // FIXME: Cross-crate overloading doesn't work yet. (#2615)
// FIXME: Trait composition. (#2616) // FIXME: Trait composition. (#2616)
pure fn add(&&other: self) -> self; pure fn add(&&other: self) -> self;

View file

@ -227,7 +227,7 @@ fn test_option_dance() {
} }
#[test] #[should_fail] #[ignore(cfg(windows))] #[test] #[should_fail] #[ignore(cfg(windows))]
fn test_option_too_much_dance() { 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 _y2 = swap_unwrap(&mut y);
let _y3 = swap_unwrap(&mut y); let _y3 = swap_unwrap(&mut y);
} }

View file

@ -1081,7 +1081,7 @@ impl<T: send> port<T>: selectable {
} }
/// A channel that can be shared between many senders. /// 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> { impl<T: send> shared_chan<T>: channel<T> {
fn send(+x: T) { fn send(+x: T) {

View file

@ -5,6 +5,7 @@ export chan_from_global_ptr, weaken_task;
import compare_and_swap = rustrt::rust_compare_and_swap_ptr; import compare_and_swap = rustrt::rust_compare_and_swap_ptr;
import task::task_builder; import task::task_builder;
#[allow(non_camel_case_types)] // runtime type
type rust_port_id = uint; type rust_port_id = uint;
extern mod rustrt { extern mod rustrt {
@ -15,7 +16,7 @@ extern mod rustrt {
fn rust_task_unweaken(ch: rust_port_id); 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 * 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. * new task to receive from it.
*/ */
unsafe fn chan_from_global_ptr<T: send>( unsafe fn chan_from_global_ptr<T: send>(
global: global_ptr, global: GlobalPtr,
task_fn: fn() -> task::task_builder, task_fn: fn() -> task::task_builder,
+f: fn~(comm::port<T>) +f: fn~(comm::port<T>)
) -> comm::chan<T> { ) -> comm::chan<T> {
enum msg { enum Msg {
proceed, Proceed,
abort Abort
} }
log(debug,~"ENTERING chan_from_global_ptr, before is_prob_zero check"); 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 // Wait to hear if we are the official instance of
// this global task // this global task
match comm::recv::<msg>(setup_po) { match comm::recv::<Msg>(setup_po) {
proceed => f(po), Proceed => f(po),
abort => () Abort => ()
} }
}; };
@ -68,11 +69,11 @@ unsafe fn chan_from_global_ptr<T: send>(
if swapped { if swapped {
// Success! // Success!
comm::send(setup_ch, proceed); comm::send(setup_ch, Proceed);
ch ch
} else { } else {
// Somebody else got in before we did // Somebody else got in before we did
comm::send(setup_ch, abort); comm::send(setup_ch, Abort);
unsafe::reinterpret_cast(*global) unsafe::reinterpret_cast(*global)
} }
} else { } else {
@ -186,10 +187,10 @@ unsafe fn weaken_task(f: fn(comm::port<()>)) {
unsafe { unsafe {
rustrt::rust_task_weaken(unsafe::reinterpret_cast(ch)); rustrt::rust_task_weaken(unsafe::reinterpret_cast(ch));
} }
let _unweaken = unweaken(ch); let _unweaken = Unweaken(ch);
f(po); f(po);
class unweaken { class Unweaken {
let ch: comm::chan<()>; let ch: comm::chan<()>;
new(ch: comm::chan<()>) { self.ch = ch; } new(ch: comm::chan<()>) { self.ch = ch; }
drop unsafe { drop unsafe {

View file

@ -4,32 +4,32 @@ import unsafe::reinterpret_cast;
import ptr::offset; import ptr::offset;
import sys::size_of; import sys::size_of;
type word = uint; type Word = uint;
class frame { class Frame {
let fp: *word; let fp: *Word;
new(fp: *word) { new(fp: *Word) {
self.fp = fp; self.fp = fp;
} }
} }
fn walk_stack(visit: fn(frame) -> bool) { fn walk_stack(visit: fn(Frame) -> bool) {
debug!{"beginning stack walk"}; debug!{"beginning stack walk"};
do frame_address |frame_pointer| { do frame_address |frame_pointer| {
let mut frame_address: *word = unsafe { let mut frame_address: *Word = unsafe {
reinterpret_cast(frame_pointer) reinterpret_cast(frame_pointer)
}; };
loop { loop {
let fr = frame(frame_address); let fr = Frame(frame_address);
debug!{"frame: %x", unsafe { reinterpret_cast(fr.fp) }}; debug!{"frame: %x", unsafe { reinterpret_cast(fr.fp) }};
visit(fr); visit(fr);
unsafe { unsafe {
let next_fp: **word = reinterpret_cast(frame_address); let next_fp: **Word = reinterpret_cast(frame_address);
frame_address = *next_fp; frame_address = *next_fp;
if *frame_address == 0u { if *frame_address == 0u {
debug!{"encountered task_start_wrapper. ending walk"}; debug!{"encountered task_start_wrapper. ending walk"};

View file

@ -1,6 +1,6 @@
//! Misc low level stuff //! Misc low level stuff
export type_desc; export TypeDesc;
export get_type_desc; export get_type_desc;
export size_of; export size_of;
export min_align_of; export min_align_of;
@ -9,7 +9,8 @@ export refcount;
export log_str; export log_str;
export shape_eq, shape_lt, shape_le; export shape_eq, shape_lt, shape_le;
enum type_desc = { // Corresponds to runtime type_desc type
enum TypeDesc = {
size: uint, size: uint,
align: uint align: uint
// Remaining fields not listed // Remaining fields not listed
@ -17,7 +18,7 @@ enum type_desc = {
#[abi = "cdecl"] #[abi = "cdecl"]
extern mod rustrt { 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"] #[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 * Useful for calling certain function in the Rust runtime or otherwise
* performing dark magick. * performing dark magick.
*/ */
pure fn get_type_desc<T>() -> *type_desc { pure fn get_type_desc<T>() -> *TypeDesc {
unchecked { rusti::get_tydesc::<T>() as *type_desc } unchecked { rusti::get_tydesc::<T>() as *TypeDesc }
} }
/// Returns the size of a type /// Returns the size of a type

View file

@ -188,7 +188,7 @@ type task_opts = {
enum task_builder = { enum task_builder = {
opts: task_opts, opts: task_opts,
gen_body: fn@(+fn~()) -> fn~(), gen_body: fn@(+fn~()) -> fn~(),
can_not_copy: option<util::noncopyable>, can_not_copy: option<util::NonCopyable>,
mut consumed: bool, mut consumed: bool,
}; };
@ -725,7 +725,7 @@ type taskgroup_data = {
// tasks in this group. // tasks in this group.
mut descendants: taskset, 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>; type taskgroup_inner = &mut option<taskgroup_data>;
@ -754,7 +754,7 @@ type ancestor_node = {
// Recursive rest of the list. // Recursive rest of the list.
mut ancestors: ancestor_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. // Accessors for taskgroup arcs and ancestor arcs that wrap the unsafety.
#[inline(always)] #[inline(always)]
@ -762,7 +762,7 @@ fn access_group<U>(x: taskgroup_arc, blk: fn(taskgroup_inner) -> U) -> U {
unsafe { x.with(blk) } unsafe { x.with(blk) }
} }
#[inline(always)] #[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 { blk: fn(x: &mut ancestor_node) -> U) -> U {
unsafe { x.with(blk) } unsafe { x.with(blk) }
} }

View file

@ -1,19 +1,19 @@
trait to_bytes { trait ToBytes {
fn to_bytes() -> ~[u8]; fn to_bytes() -> ~[u8];
} }
impl ~[u8]: to_bytes { impl ~[u8]: ToBytes {
fn to_bytes() -> ~[u8] { copy self } fn to_bytes() -> ~[u8] { copy self }
} }
impl @~[u8]: to_bytes { impl @~[u8]: ToBytes {
fn to_bytes() -> ~[u8] { copy *self } fn to_bytes() -> ~[u8] { copy *self }
} }
impl ~str: to_bytes { impl ~str: ToBytes {
fn to_bytes() -> ~[u8] { str::bytes(self) } fn to_bytes() -> ~[u8] { str::bytes(self) }
} }
impl @(~str): to_bytes { impl @(~str): ToBytes {
fn to_bytes() -> ~[u8] { str::bytes(*self) } fn to_bytes() -> ~[u8] { str::bytes(*self) }
} }

View file

@ -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) } fn to_str() -> ~str { int::str(self) }
} }
impl i8: to_str { impl i8: ToStr {
fn to_str() -> ~str { i8::str(self) } fn to_str() -> ~str { i8::str(self) }
} }
impl i16: to_str { impl i16: ToStr {
fn to_str() -> ~str { i16::str(self) } fn to_str() -> ~str { i16::str(self) }
} }
impl i32: to_str { impl i32: ToStr {
fn to_str() -> ~str { i32::str(self) } fn to_str() -> ~str { i32::str(self) }
} }
impl i64: to_str { impl i64: ToStr {
fn to_str() -> ~str { i64::str(self) } fn to_str() -> ~str { i64::str(self) }
} }
impl uint: to_str { impl uint: ToStr {
fn to_str() -> ~str { uint::str(self) } fn to_str() -> ~str { uint::str(self) }
} }
impl u8: to_str { impl u8: ToStr {
fn to_str() -> ~str { u8::str(self) } fn to_str() -> ~str { u8::str(self) }
} }
impl u16: to_str { impl u16: ToStr {
fn to_str() -> ~str { u16::str(self) } fn to_str() -> ~str { u16::str(self) }
} }
impl u32: to_str { impl u32: ToStr {
fn to_str() -> ~str { u32::str(self) } fn to_str() -> ~str { u32::str(self) }
} }
impl u64: to_str { impl u64: ToStr {
fn to_str() -> ~str { u64::str(self) } fn to_str() -> ~str { u64::str(self) }
} }
impl float: to_str { impl float: ToStr {
fn to_str() -> ~str { float::to_str(self, 4u) } fn to_str() -> ~str { float::to_str(self, 4u) }
} }
impl bool: to_str { impl bool: ToStr {
fn to_str() -> ~str { bool::to_str(self) } fn to_str() -> ~str { bool::to_str(self) }
} }
impl (): to_str { impl (): ToStr {
fn to_str() -> ~str { ~"()" } fn to_str() -> ~str { ~"()" }
} }
impl ~str: to_str { impl ~str: ToStr {
fn to_str() -> ~str { self } 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 { fn to_str() -> ~str {
let (a, b) = self; let (a, b) = self;
~"(" + a.to_str() + ~", " + b.to_str() + ~")" ~"(" + 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 { fn to_str() -> ~str {
let (a, b, c) = self; let (a, b, c) = self;
~"(" + a.to_str() + ~", " + b.to_str() + ~", " + c.to_str() + ~")" ~"(" + 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 { fn to_str() -> ~str {
let mut acc = ~"[", first = true; let mut acc = ~"[", first = true;
for vec::each(self) |elt| { 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() } 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() } fn to_str() -> ~str { ~"~" + (*self).to_str() }
} }

View file

@ -1,12 +1,12 @@
//! Operations on tuples //! Operations on tuples
trait tuple_ops<T,U> { trait TupleOps<T,U> {
pure fn first() -> T; pure fn first() -> T;
pure fn second() -> U; pure fn second() -> U;
pure fn swap() -> (U, T); 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 /// Return the first element of self
pure fn first() -> T { 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 zip() -> ~[(A, B)];
fn map<C>(f: fn(A, B) -> C) -> ~[C]; 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)] { fn zip() -> ~[(A, B)] {
let (a, b) = self; 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)] { fn zip() -> ~[(A, B)] {
let (a, b) = self; let (a, b) = self;

View file

@ -1,5 +1,5 @@
import T = inst::T; import T = inst::T;
import cmp::{eq, ord}; import cmp::{Eq, Ord};
export min_value, max_value; export min_value, max_value;
export min, max; export min, max;
@ -56,19 +56,19 @@ pure fn compl(i: T) -> T {
max_value ^ i max_value ^ i
} }
impl T: ord { impl T: Ord {
pure fn lt(&&other: T) -> bool { pure fn lt(&&other: T) -> bool {
return self < other; return self < other;
} }
} }
impl T: eq { impl T: Eq {
pure fn eq(&&other: T) -> bool { pure fn eq(&&other: T) -> bool {
return self == other; return self == other;
} }
} }
impl T: num::num { impl T: num::Num {
pure fn add(&&other: T) -> T { return self + other; } pure fn add(&&other: T) -> T { return self + other; }
pure fn sub(&&other: T) -> T { return self - other; } pure fn sub(&&other: T) -> T { return self - other; }
pure fn mul(&&other: T) -> T { return self * other; } pure fn mul(&&other: T) -> T { return self * other; }

View file

@ -2,9 +2,9 @@
export reinterpret_cast, forget, bump_box_refcount, transmute; 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 get_shared_mutable_state, get_shared_immutable_state;
export exclusive; export Exclusive, exclusive;
import task::atomically; import task::atomically;
@ -57,16 +57,16 @@ unsafe fn transmute<L, G>(-thing: L) -> G {
* Shared state & exclusive ARC * Shared state & exclusive ARC
****************************************************************************/ ****************************************************************************/
type arc_data<T> = { type ArcData<T> = {
mut count: libc::intptr_t, mut count: libc::intptr_t,
data: T data: T
}; };
class arc_destruct<T> { class ArcDestruct<T> {
let data: *libc::c_void; let data: *libc::c_void;
new(data: *libc::c_void) { self.data = data; } new(data: *libc::c_void) { self.data = data; }
drop unsafe { 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); let new_count = rustrt::rust_atomic_decrement(&mut data.count);
assert new_count >= 0; assert new_count >= 0;
if 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 * Data races between tasks can result in crashes and, with sufficient
* cleverness, arbitrary type coercion. * 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}; let data = ~{mut count: 1, data: data};
unsafe { unsafe {
let ptr = unsafe::transmute(data); 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 { -> &mut T {
unsafe { unsafe {
let ptr: ~arc_data<T> = unsafe::reinterpret_cast((*rc).data); let ptr: ~ArcData<T> = unsafe::reinterpret_cast((*rc).data);
assert ptr.count > 0; assert ptr.count > 0;
// Cast us back into the correct region // Cast us back into the correct region
let r = unsafe::reinterpret_cast(&ptr.data); 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; 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 { -> &T {
unsafe { unsafe {
let ptr: ~arc_data<T> = unsafe::reinterpret_cast((*rc).data); let ptr: ~ArcData<T> = unsafe::reinterpret_cast((*rc).data);
assert ptr.count > 0; assert ptr.count > 0;
// Cast us back into the correct region // Cast us back into the correct region
let r = unsafe::reinterpret_cast(&ptr.data); 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>) unsafe fn clone_shared_mutable_state<T: send>(rc: &SharedMutableState<T>)
-> shared_mutable_state<T> { -> SharedMutableState<T> {
unsafe { 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); let new_count = rustrt::rust_atomic_increment(&mut ptr.count);
assert new_count >= 2; assert new_count >= 2;
unsafe::forget(ptr); unsafe::forget(ptr);
} }
arc_destruct((*rc).data) ArcDestruct((*rc).data)
} }
/****************************************************************************/ /****************************************************************************/
#[allow(non_camel_case_types)] // runtime type
type rust_little_lock = *libc::c_void; type rust_little_lock = *libc::c_void;
#[abi = "cdecl"] #[abi = "cdecl"]
@ -147,7 +148,7 @@ extern mod rustrt {
fn rust_unlock_little_lock(lock: rust_little_lock); fn rust_unlock_little_lock(lock: rust_little_lock);
} }
class little_lock { class LittleLock {
let l: rust_little_lock; let l: rust_little_lock;
new() { new() {
self.l = rustrt::rust_create_little_lock(); self.l = rustrt::rust_create_little_lock();
@ -155,9 +156,9 @@ class little_lock {
drop { rustrt::rust_destroy_little_lock(self.l); } drop { rustrt::rust_destroy_little_lock(self.l); }
} }
impl little_lock { impl LittleLock {
unsafe fn lock<T>(f: fn() -> T) -> T { unsafe fn lock<T>(f: fn() -> T) -> T {
class unlock { class Unlock {
let l: rust_little_lock; let l: rust_little_lock;
new(l: rust_little_lock) { self.l = l; } new(l: rust_little_lock) { self.l = l; }
drop { rustrt::rust_unlock_little_lock(self.l); } drop { rustrt::rust_unlock_little_lock(self.l); }
@ -165,29 +166,29 @@ impl little_lock {
do atomically { do atomically {
rustrt::rust_lock_little_lock(self.l); rustrt::rust_lock_little_lock(self.l);
let _r = unlock(self.l); let _r = Unlock(self.l);
f() 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. * 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> { fn exclusive<T:send >(+user_data: T) -> Exclusive<T> {
let data = ex_data { let data = ExData {
lock: little_lock(), mut failed: false, mut data: user_data 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. // Duplicate an exclusive ARC, as std::arc::clone.
fn clone() -> exclusive<T> { fn clone() -> Exclusive<T> {
exclusive { x: unsafe { clone_shared_mutable_state(&self.x) } } Exclusive { x: unsafe { clone_shared_mutable_state(&self.x) } }
} }
// Exactly like std::arc::mutex_arc,access(), but with the little_lock // Exactly like std::arc::mutex_arc,access(), but with the little_lock

View file

@ -29,7 +29,7 @@ fn replace<T>(dest: &mut T, +src: T) -> T {
} }
/// A non-copyable dummy type. /// A non-copyable dummy type.
class noncopyable { class NonCopyable {
i: (); i: ();
new() { self.i = (); } new() { self.i = (); }
drop { } drop { }
@ -52,7 +52,7 @@ mod tests {
} }
#[test] #[test]
fn test_replace() { fn test_replace() {
let mut x = some(noncopyable()); let mut x = some(NonCopyable());
let y = replace(&mut x, none); let y = replace(&mut x, none);
assert x.is_none(); assert x.is_none();
assert y.is_some(); assert y.is_some();

View file

@ -95,10 +95,10 @@ export vec_concat;
#[abi = "cdecl"] #[abi = "cdecl"]
extern mod rustrt { extern mod rustrt {
fn vec_reserve_shared(++t: *sys::type_desc, fn vec_reserve_shared(++t: *sys::TypeDesc,
++v: **unsafe::vec_repr, ++v: **unsafe::vec_repr,
++n: libc::size_t); ++n: libc::size_t);
fn vec_from_buf_shared(++t: *sys::type_desc, fn vec_from_buf_shared(++t: *sys::TypeDesc,
++ptr: *(), ++ptr: *(),
++count: libc::size_t) -> *unsafe::vec_repr; ++count: libc::size_t) -> *unsafe::vec_repr;
} }

View file

@ -3,7 +3,8 @@
* between tasks. * 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}; get_shared_mutable_state, get_shared_immutable_state};
import sync; import sync;
import sync::{mutex, rwlock}; import sync::{mutex, rwlock};
@ -39,7 +40,7 @@ impl &condvar {
****************************************************************************/ ****************************************************************************/
/// An atomically reference counted wrapper for shared immutable state. /// 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. /// Create an atomically reference counted wrapper.
fn arc<T: const send>(+data: T) -> arc<T> { 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; } struct mutex_arc_inner<T: send> { lock: mutex; failed: bool; data: T; }
/// An ARC with mutable data protected by a blocking mutex. /// 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. /// Create a mutex-protected ARC with the supplied data.
fn mutex_arc<T: send>(+user_data: T) -> mutex_arc<T> { 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. * Unlike mutex_arcs, rw_arcs are safe, because they cannot be nested.
*/ */
struct rw_arc<T: const send> { struct rw_arc<T: const send> {
x: shared_mutable_state<rw_arc_inner<T>>; x: SharedMutableState<rw_arc_inner<T>>;
mut cant_nest: (); mut cant_nest: ();
} }

View file

@ -12,12 +12,12 @@ export breakpoint;
#[abi = "cdecl"] #[abi = "cdecl"]
extern mod rustrt { extern mod rustrt {
fn debug_tydesc(td: *sys::type_desc); fn debug_tydesc(td: *sys::TypeDesc);
fn debug_opaque(td: *sys::type_desc, x: *()); fn debug_opaque(td: *sys::TypeDesc, x: *());
fn debug_box(td: *sys::type_desc, x: *()); fn debug_box(td: *sys::TypeDesc, x: *());
fn debug_tag(td: *sys::type_desc, x: *()); fn debug_tag(td: *sys::TypeDesc, x: *());
fn debug_fn(td: *sys::type_desc, x: *()); fn debug_fn(td: *sys::TypeDesc, x: *());
fn debug_ptrcast(td: *sys::type_desc, x: *()) -> *(); fn debug_ptrcast(td: *sys::TypeDesc, x: *()) -> *();
fn rust_dbg_breakpoint(); fn rust_dbg_breakpoint();
} }

View file

@ -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) } fn to_str() -> ~str { to_str(self) }
} }
impl error: to_str::to_str { impl error: to_str::ToStr {
fn to_str() -> ~str { fn to_str() -> ~str {
fmt!{"%u:%u: %s", self.line, self.col, *self.msg} fmt!{"%u:%u: %s", self.line, self.col, *self.msg}
} }

View file

@ -3,7 +3,7 @@
#[warn(deprecated_mode)]; #[warn(deprecated_mode)];
import io::writer_util; import io::writer_util;
import to_str::to_str; import to_str::ToStr;
export hashmap, hashfn, eqfn, set, map, chained, hashmap, str_hash; export hashmap, hashfn, eqfn, set, map, chained, hashmap, str_hash;
export box_str_hash; export box_str_hash;
export bytes_hash, int_hash, uint_hash, set_add; 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) { fn to_writer(wr: io::writer) {
if self.count == 0u { if self.count == 0u {
wr.write_str(~"{}"); wr.write_str(~"{}");

View file

@ -673,7 +673,7 @@ fn to_str(url: url) -> ~str {
fragment]); fragment]);
} }
impl url: to_str::to_str { impl url: to_str::ToStr {
fn to_str() -> ~str { fn to_str() -> ~str {
to_str(self) to_str(self)
} }

View file

@ -1,6 +1,6 @@
//! Sorting methods //! Sorting methods
import vec::{len, push}; import vec::{len, push};
import core::cmp::{eq, ord}; import core::cmp::{Eq, Ord};
export le; export le;
export merge_sort; 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. * 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; } if arr.len() <= 1 { return; }
qsort3(core::cmp::lt, core::cmp::eq, arr, 0, (arr.len() - 1) as int); qsort3(core::cmp::lt, core::cmp::eq, arr, 0, (arr.len() - 1) as int);
} }

View file

@ -8,7 +8,7 @@
export condvar, semaphore, mutex, rwlock; export condvar, semaphore, mutex, rwlock;
// FIXME (#3119) This shouldn't be a thing exported from core. // FIXME (#3119) This shouldn't be a thing exported from core.
import unsafe::exclusive; import unsafe::{Exclusive, exclusive};
/**************************************************************************** /****************************************************************************
* Internals * Internals
@ -55,7 +55,7 @@ struct sem_inner<Q> {
// a condition variable attached, others should. // a condition variable attached, others should.
blocked: Q; 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> { fn new_sem<Q: send>(count: int, +q: Q) -> sem<Q> {
let (wait_tail, wait_head) = pipes::stream(); let (wait_tail, wait_head) = pipes::stream();
@ -293,7 +293,7 @@ struct rwlock_inner {
struct rwlock { struct rwlock {
/* priv */ order_lock: semaphore; /* priv */ order_lock: semaphore;
/* priv */ access_lock: sem<waitqueue>; /* priv */ access_lock: sem<waitqueue>;
/* priv */ state: exclusive<rwlock_inner>; /* priv */ state: Exclusive<rwlock_inner>;
} }
/// Create a new rwlock. /// Create a new rwlock.

View file

@ -1,6 +1,6 @@
// A protocol compiler for Rust. // A protocol compiler for Rust.
import to_str::to_str; import to_str::ToStr;
import dvec::dvec; import dvec::dvec;

View file

@ -1,4 +1,4 @@
import to_str::to_str; import to_str::ToStr;
import dvec::dvec; import dvec::dvec;
import ast::{ident}; import ast::{ident};
@ -9,7 +9,7 @@ enum direction {
send, recv send, recv
} }
impl direction: to_str { impl direction: ToStr {
fn to_str() -> ~str { fn to_str() -> ~str {
match self { match self {
send => ~"send", send => ~"send",

View file

@ -152,11 +152,11 @@ fn check_crate(tcx: ty::ctxt,
return last_use_map; 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} } 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} } fn to_str() -> ~str { fmt!{"v(%u)", *self} }
} }

View file

@ -1,9 +1,9 @@
import to_str::*; import to_str::*;
import to_str::to_str; import to_str::ToStr;
mod kitty { mod kitty {
class cat : to_str { class cat : ToStr {
priv { priv {
let mut meows : uint; let mut meows : uint;
fn meow() { fn meow() {

View file

@ -1,10 +1,10 @@
#[link(name = "a", vers = "0.1")]; #[link(name = "a", vers = "0.1")];
#[crate_type = "lib"]; #[crate_type = "lib"];
trait to_str { trait to_strz {
fn to_str() -> ~str; fn to_strz() -> ~str;
} }
impl ~str: to_str { impl ~str: to_strz {
fn to_str() -> ~str { self } fn to_strz() -> ~str { self }
} }

View file

@ -2,8 +2,8 @@
#[crate_type = "lib"]; #[crate_type = "lib"];
use a; use a;
import a::to_str; import a::to_strz;
impl int: to_str { impl int: to_strz {
fn to_str() -> ~str { fmt!{"%?", self} } fn to_strz() -> ~str { fmt!{"%?", self} }
} }

View file

@ -3,8 +3,8 @@
use a; use a;
import a::to_str; import a::to_strz;
impl bool: to_str { impl bool: to_strz {
fn to_str() -> ~str { fmt!{"%b", self} } fn to_strz() -> ~str { fmt!{"%b", self} }
} }

View file

@ -1,17 +1,17 @@
// xfail-fast // xfail-fast
// aux-build:cci_class_cast.rs // aux-build:cci_class_cast.rs
use cci_class_cast; use cci_class_cast;
import to_str::to_str; import to_str::ToStr;
import cci_class_cast::kitty::*; 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(); let actual = thing.to_str();
debug!{"%s", actual}; debug!{"%s", actual};
assert(actual == expected); assert(actual == expected);
} }
fn main() { 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"); print_out(nyan, ~"nyan");
} }

View file

@ -1,6 +1,6 @@
// xfail-fast // xfail-fast
import to_str::*; import to_str::*;
import to_str::to_str; import to_str::ToStr;
class cat { class cat {
priv { priv {
@ -35,17 +35,17 @@ class cat {
} }
} }
impl cat: to_str { impl cat: ToStr {
fn to_str() -> ~str { self.name } 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(); let actual = thing.to_str();
debug!{"%s", actual}; debug!{"%s", actual};
assert(actual == expected); assert(actual == expected);
} }
fn main() { 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"); print_out(nyan, ~"nyan");
} }

View file

@ -7,10 +7,10 @@ use a;
use b; use b;
use c; use c;
import a::to_str; import a::to_strz;
fn main() { fn main() {
io::println((~"foo").to_str()); io::println((~"foo").to_strz());
io::println(1.to_str()); io::println(1.to_strz());
io::println(true.to_str()); io::println(true.to_strz());
} }

View file

@ -13,7 +13,7 @@ enum square {
empty empty
} }
impl square: to_str::to_str { impl square: to_str::ToStr {
fn to_str() -> ~str { fn to_str() -> ~str {
match self { match self {
bot => { ~"R" } bot => { ~"R" }