Camel case various core constructors
This commit is contained in:
@@ -30,8 +30,8 @@
|
||||
import either::Either;
|
||||
import libc::size_t;
|
||||
|
||||
export Port, port;
|
||||
export Chan, chan;
|
||||
export Port;
|
||||
export Chan;
|
||||
export send;
|
||||
export recv;
|
||||
export peek;
|
||||
@@ -69,13 +69,13 @@ enum Chan<T: send> {
|
||||
}
|
||||
|
||||
/// Constructs a port
|
||||
fn port<T: send>() -> Port<T> {
|
||||
fn Port<T: send>() -> Port<T> {
|
||||
Port_(@PortPtr(rustrt::new_port(sys::size_of::<T>() as size_t)))
|
||||
}
|
||||
|
||||
impl<T: send> Port<T> {
|
||||
|
||||
fn chan() -> Chan<T> { chan(self) }
|
||||
fn chan() -> Chan<T> { Chan(self) }
|
||||
fn send(+v: T) { self.chan().send(v) }
|
||||
fn recv() -> T { recv(self) }
|
||||
fn peek() -> bool { peek(self) }
|
||||
@@ -93,7 +93,7 @@ impl<T: send> Chan<T> {
|
||||
|
||||
/// Open a new receiving channel for the duration of a function
|
||||
fn listen<T: send, U>(f: fn(Chan<T>) -> U) -> U {
|
||||
let po = port();
|
||||
let po = Port();
|
||||
f(po.chan())
|
||||
}
|
||||
|
||||
@@ -157,7 +157,7 @@ fn as_raw_port<T: send, U>(ch: comm::Chan<T>, f: fn(*rust_port) -> U) -> U {
|
||||
* Constructs a channel. The channel is bound to the port used to
|
||||
* construct it.
|
||||
*/
|
||||
fn chan<T: send>(p: Port<T>) -> Chan<T> {
|
||||
fn Chan<T: send>(p: Port<T>) -> Chan<T> {
|
||||
Chan_(rustrt::get_port_id((**p).po))
|
||||
}
|
||||
|
||||
@@ -295,51 +295,51 @@ extern mod rusti {
|
||||
|
||||
|
||||
#[test]
|
||||
fn create_port_and_chan() { let p = port::<int>(); chan(p); }
|
||||
fn create_port_and_chan() { let p = Port::<int>(); Chan(p); }
|
||||
|
||||
#[test]
|
||||
fn send_int() {
|
||||
let p = port::<int>();
|
||||
let c = chan(p);
|
||||
let p = Port::<int>();
|
||||
let c = Chan(p);
|
||||
send(c, 22);
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn send_recv_fn() {
|
||||
let p = port::<int>();
|
||||
let c = chan::<int>(p);
|
||||
let p = Port::<int>();
|
||||
let c = Chan::<int>(p);
|
||||
send(c, 42);
|
||||
assert (recv(p) == 42);
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn send_recv_fn_infer() {
|
||||
let p = port();
|
||||
let c = chan(p);
|
||||
let p = Port();
|
||||
let c = Chan(p);
|
||||
send(c, 42);
|
||||
assert (recv(p) == 42);
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn chan_chan_infer() {
|
||||
let p = port(), p2 = port::<int>();
|
||||
let c = chan(p);
|
||||
send(c, chan(p2));
|
||||
let p = Port(), p2 = Port::<int>();
|
||||
let c = Chan(p);
|
||||
send(c, Chan(p2));
|
||||
recv(p);
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn chan_chan() {
|
||||
let p = port::<Chan<int>>(), p2 = port::<int>();
|
||||
let c = chan(p);
|
||||
send(c, chan(p2));
|
||||
let p = Port::<Chan<int>>(), p2 = Port::<int>();
|
||||
let c = Chan(p);
|
||||
send(c, Chan(p2));
|
||||
recv(p);
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn test_peek() {
|
||||
let po = port();
|
||||
let ch = chan(po);
|
||||
let po = Port();
|
||||
let ch = Chan(po);
|
||||
assert !peek(po);
|
||||
send(ch, ());
|
||||
assert peek(po);
|
||||
@@ -349,10 +349,10 @@ fn test_peek() {
|
||||
|
||||
#[test]
|
||||
fn test_select2_available() {
|
||||
let po_a = port();
|
||||
let po_b = port();
|
||||
let ch_a = chan(po_a);
|
||||
let ch_b = chan(po_b);
|
||||
let po_a = Port();
|
||||
let po_b = Port();
|
||||
let ch_a = Chan(po_a);
|
||||
let ch_b = Chan(po_b);
|
||||
|
||||
send(ch_a, ~"a");
|
||||
|
||||
@@ -365,10 +365,10 @@ fn test_select2_available() {
|
||||
|
||||
#[test]
|
||||
fn test_select2_rendezvous() {
|
||||
let po_a = port();
|
||||
let po_b = port();
|
||||
let ch_a = chan(po_a);
|
||||
let ch_b = chan(po_b);
|
||||
let po_a = Port();
|
||||
let po_b = Port();
|
||||
let ch_a = Chan(po_a);
|
||||
let ch_b = Chan(po_b);
|
||||
|
||||
for iter::repeat(10u) {
|
||||
do task::spawn {
|
||||
@@ -389,10 +389,10 @@ fn test_select2_rendezvous() {
|
||||
|
||||
#[test]
|
||||
fn test_select2_stress() {
|
||||
let po_a = port();
|
||||
let po_b = port();
|
||||
let ch_a = chan(po_a);
|
||||
let ch_b = chan(po_b);
|
||||
let po_a = Port();
|
||||
let po_b = Port();
|
||||
let ch_a = Chan(po_a);
|
||||
let ch_b = Chan(po_b);
|
||||
|
||||
let msgs = 100u;
|
||||
let times = 4u;
|
||||
@@ -426,8 +426,8 @@ fn test_select2_stress() {
|
||||
|
||||
#[test]
|
||||
fn test_recv_chan() {
|
||||
let po = port();
|
||||
let ch = chan(po);
|
||||
let po = Port();
|
||||
let ch = Chan(po);
|
||||
send(ch, ~"flower");
|
||||
assert recv_chan(ch) == ~"flower";
|
||||
}
|
||||
@@ -436,7 +436,7 @@ fn test_recv_chan() {
|
||||
#[should_fail]
|
||||
#[ignore(cfg(windows))]
|
||||
fn test_recv_chan_dead() {
|
||||
let ch = chan(port());
|
||||
let ch = Chan(Port());
|
||||
send(ch, ~"flower");
|
||||
recv_chan(ch);
|
||||
}
|
||||
@@ -444,8 +444,8 @@ fn test_recv_chan_dead() {
|
||||
#[test]
|
||||
#[ignore(cfg(windows))]
|
||||
fn test_recv_chan_wrong_task() {
|
||||
let po = port();
|
||||
let ch = chan(po);
|
||||
let po = Port();
|
||||
let ch = Chan(po);
|
||||
send(ch, ~"flower");
|
||||
assert result::is_err(task::try(||
|
||||
recv_chan(ch)
|
||||
@@ -454,14 +454,14 @@ fn test_recv_chan_wrong_task() {
|
||||
|
||||
#[test]
|
||||
fn test_port_send() {
|
||||
let po = port();
|
||||
let po = Port();
|
||||
po.send(());
|
||||
po.recv();
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn test_chan_peek() {
|
||||
let po = port();
|
||||
let po = Port();
|
||||
let ch = po.chan();
|
||||
ch.send(());
|
||||
assert ch.peek();
|
||||
@@ -482,7 +482,7 @@ fn test_listen() {
|
||||
fn test_port_detach_fail() {
|
||||
for iter::repeat(100u) {
|
||||
do task::spawn_unlinked {
|
||||
let po = port();
|
||||
let po = Port();
|
||||
let ch = po.chan();
|
||||
|
||||
do task::spawn {
|
||||
|
||||
@@ -8,7 +8,7 @@
|
||||
* Do not use ==, !=, <, etc on doubly-linked lists -- it may not terminate.
|
||||
*/
|
||||
|
||||
export DList, dlist, dlist_node;
|
||||
export DList;
|
||||
export new_dlist, from_elem, from_vec, extensions;
|
||||
|
||||
type DListLink<T> = Option<DListNode<T>>;
|
||||
@@ -20,11 +20,13 @@ enum DListNode<T> = @{
|
||||
mut next: DListLink<T>
|
||||
};
|
||||
|
||||
enum DList<T> = @{
|
||||
mut size: uint,
|
||||
mut hd: DListLink<T>,
|
||||
mut tl: DListLink<T>,
|
||||
};
|
||||
enum DList<T> {
|
||||
DList_(@{
|
||||
mut size: uint,
|
||||
mut hd: DListLink<T>,
|
||||
mut tl: DListLink<T>
|
||||
})
|
||||
}
|
||||
|
||||
priv impl<T> DListNode<T> {
|
||||
pure fn assert_links() {
|
||||
@@ -83,19 +85,19 @@ pure fn new_dlist_node<T>(+data: T) -> DListNode<T> {
|
||||
}
|
||||
|
||||
/// Creates a new, empty dlist.
|
||||
pure fn new_dlist<T>() -> DList<T> {
|
||||
DList(@{mut size: 0, mut hd: None, mut tl: None})
|
||||
pure fn DList<T>() -> DList<T> {
|
||||
DList_(@{mut size: 0, mut hd: None, mut tl: None})
|
||||
}
|
||||
|
||||
/// Creates a new dlist with a single element
|
||||
pure fn from_elem<T>(+data: T) -> DList<T> {
|
||||
let list = new_dlist();
|
||||
let list = DList();
|
||||
unchecked { list.push(data); }
|
||||
list
|
||||
}
|
||||
|
||||
fn from_vec<T: copy>(+vec: &[T]) -> DList<T> {
|
||||
do vec::foldl(new_dlist(), vec) |list,data| {
|
||||
do vec::foldl(DList(), vec) |list,data| {
|
||||
list.push(data); // Iterating left-to-right -- add newly to the tail.
|
||||
list
|
||||
}
|
||||
@@ -104,7 +106,7 @@ fn from_vec<T: copy>(+vec: &[T]) -> DList<T> {
|
||||
/// Produce a list from a list of lists, leaving no elements behind in the
|
||||
/// input. O(number of sub-lists).
|
||||
fn concat<T>(lists: DList<DList<T>>) -> DList<T> {
|
||||
let result = new_dlist();
|
||||
let result = DList();
|
||||
while !lists.is_empty() {
|
||||
result.append(lists.pop().get());
|
||||
}
|
||||
@@ -485,7 +487,7 @@ mod tests {
|
||||
#[test]
|
||||
fn test_dlist_append_empty() {
|
||||
let a = from_vec(~[1,2,3]);
|
||||
let b = new_dlist::<int>();
|
||||
let b = DList::<int>();
|
||||
a.append(b);
|
||||
assert a.len() == 3;
|
||||
assert b.len() == 0;
|
||||
@@ -497,7 +499,7 @@ mod tests {
|
||||
}
|
||||
#[test]
|
||||
fn test_dlist_append_to_empty() {
|
||||
let a = new_dlist::<int>();
|
||||
let a = DList::<int>();
|
||||
let b = from_vec(~[4,5,6]);
|
||||
a.append(b);
|
||||
assert a.len() == 3;
|
||||
@@ -510,8 +512,8 @@ mod tests {
|
||||
}
|
||||
#[test]
|
||||
fn test_dlist_append_two_empty() {
|
||||
let a = new_dlist::<int>();
|
||||
let b = new_dlist::<int>();
|
||||
let a = DList::<int>();
|
||||
let b = DList::<int>();
|
||||
a.append(b);
|
||||
assert a.len() == 0;
|
||||
assert b.len() == 0;
|
||||
@@ -522,14 +524,14 @@ mod tests {
|
||||
#[ignore(cfg(windows))]
|
||||
#[should_fail]
|
||||
fn test_dlist_append_self() {
|
||||
let a = new_dlist::<int>();
|
||||
let a = DList::<int>();
|
||||
a.append(a);
|
||||
}
|
||||
#[test]
|
||||
#[ignore(cfg(windows))]
|
||||
#[should_fail]
|
||||
fn test_dlist_prepend_self() {
|
||||
let a = new_dlist::<int>();
|
||||
let a = DList::<int>();
|
||||
a.prepend(a);
|
||||
}
|
||||
#[test]
|
||||
@@ -562,7 +564,7 @@ mod tests {
|
||||
}
|
||||
#[test]
|
||||
fn test_dlist_reverse_empty() {
|
||||
let a = new_dlist::<int>();
|
||||
let a = DList::<int>();
|
||||
a.reverse();
|
||||
assert a.len() == 0;
|
||||
a.assert_consistent();
|
||||
@@ -593,7 +595,7 @@ mod tests {
|
||||
}
|
||||
#[test]
|
||||
fn test_dlist_is_empty() {
|
||||
let empty = new_dlist::<int>();
|
||||
let empty = DList::<int>();
|
||||
let full1 = from_vec(~[1,2,3]);
|
||||
assert empty.is_empty();
|
||||
assert !full1.is_empty();
|
||||
@@ -635,7 +637,7 @@ mod tests {
|
||||
}
|
||||
#[test]
|
||||
fn test_dlist_push() {
|
||||
let l = new_dlist::<int>();
|
||||
let l = DList::<int>();
|
||||
l.push(1);
|
||||
assert l.head() == 1;
|
||||
assert l.tail() == 1;
|
||||
@@ -649,7 +651,7 @@ mod tests {
|
||||
}
|
||||
#[test]
|
||||
fn test_dlist_push_head() {
|
||||
let l = new_dlist::<int>();
|
||||
let l = DList::<int>();
|
||||
l.push_head(3);
|
||||
assert l.head() == 3;
|
||||
assert l.tail() == 3;
|
||||
@@ -678,7 +680,7 @@ mod tests {
|
||||
}
|
||||
#[test]
|
||||
fn test_dlist_remove_head() {
|
||||
let l = new_dlist::<int>();
|
||||
let l = DList::<int>();
|
||||
l.assert_consistent(); let one = l.push_n(1);
|
||||
l.assert_consistent(); let _two = l.push_n(2);
|
||||
l.assert_consistent(); let _three = l.push_n(3);
|
||||
@@ -693,7 +695,7 @@ mod tests {
|
||||
}
|
||||
#[test]
|
||||
fn test_dlist_remove_mid() {
|
||||
let l = new_dlist::<int>();
|
||||
let l = DList::<int>();
|
||||
l.assert_consistent(); let _one = l.push_n(1);
|
||||
l.assert_consistent(); let two = l.push_n(2);
|
||||
l.assert_consistent(); let _three = l.push_n(3);
|
||||
@@ -708,7 +710,7 @@ mod tests {
|
||||
}
|
||||
#[test]
|
||||
fn test_dlist_remove_tail() {
|
||||
let l = new_dlist::<int>();
|
||||
let l = DList::<int>();
|
||||
l.assert_consistent(); let _one = l.push_n(1);
|
||||
l.assert_consistent(); let _two = l.push_n(2);
|
||||
l.assert_consistent(); let three = l.push_n(3);
|
||||
@@ -723,7 +725,7 @@ mod tests {
|
||||
}
|
||||
#[test]
|
||||
fn test_dlist_remove_one_two() {
|
||||
let l = new_dlist::<int>();
|
||||
let l = DList::<int>();
|
||||
l.assert_consistent(); let one = l.push_n(1);
|
||||
l.assert_consistent(); let two = l.push_n(2);
|
||||
l.assert_consistent(); let _three = l.push_n(3);
|
||||
@@ -739,7 +741,7 @@ mod tests {
|
||||
}
|
||||
#[test]
|
||||
fn test_dlist_remove_one_three() {
|
||||
let l = new_dlist::<int>();
|
||||
let l = DList::<int>();
|
||||
l.assert_consistent(); let one = l.push_n(1);
|
||||
l.assert_consistent(); let _two = l.push_n(2);
|
||||
l.assert_consistent(); let three = l.push_n(3);
|
||||
@@ -754,7 +756,7 @@ mod tests {
|
||||
}
|
||||
#[test]
|
||||
fn test_dlist_remove_two_three() {
|
||||
let l = new_dlist::<int>();
|
||||
let l = DList::<int>();
|
||||
l.assert_consistent(); let _one = l.push_n(1);
|
||||
l.assert_consistent(); let two = l.push_n(2);
|
||||
l.assert_consistent(); let three = l.push_n(3);
|
||||
@@ -769,7 +771,7 @@ mod tests {
|
||||
}
|
||||
#[test]
|
||||
fn test_dlist_remove_all() {
|
||||
let l = new_dlist::<int>();
|
||||
let l = DList::<int>();
|
||||
l.assert_consistent(); let one = l.push_n(1);
|
||||
l.assert_consistent(); let two = l.push_n(2);
|
||||
l.assert_consistent(); let three = l.push_n(3);
|
||||
@@ -782,7 +784,7 @@ mod tests {
|
||||
}
|
||||
#[test]
|
||||
fn test_dlist_insert_n_before() {
|
||||
let l = new_dlist::<int>();
|
||||
let l = DList::<int>();
|
||||
l.assert_consistent(); let _one = l.push_n(1);
|
||||
l.assert_consistent(); let two = l.push_n(2);
|
||||
l.assert_consistent(); let three = new_dlist_node(3);
|
||||
@@ -798,7 +800,7 @@ mod tests {
|
||||
}
|
||||
#[test]
|
||||
fn test_dlist_insert_n_after() {
|
||||
let l = new_dlist::<int>();
|
||||
let l = DList::<int>();
|
||||
l.assert_consistent(); let one = l.push_n(1);
|
||||
l.assert_consistent(); let _two = l.push_n(2);
|
||||
l.assert_consistent(); let three = new_dlist_node(3);
|
||||
@@ -814,7 +816,7 @@ mod tests {
|
||||
}
|
||||
#[test]
|
||||
fn test_dlist_insert_before_head() {
|
||||
let l = new_dlist::<int>();
|
||||
let l = DList::<int>();
|
||||
l.assert_consistent(); let one = l.push_n(1);
|
||||
l.assert_consistent(); let _two = l.push_n(2);
|
||||
l.assert_consistent(); assert l.len() == 2;
|
||||
@@ -829,7 +831,7 @@ mod tests {
|
||||
}
|
||||
#[test]
|
||||
fn test_dlist_insert_after_tail() {
|
||||
let l = new_dlist::<int>();
|
||||
let l = DList::<int>();
|
||||
l.assert_consistent(); let _one = l.push_n(1);
|
||||
l.assert_consistent(); let two = l.push_n(2);
|
||||
l.assert_consistent(); assert l.len() == 2;
|
||||
@@ -844,7 +846,7 @@ mod tests {
|
||||
}
|
||||
#[test] #[should_fail] #[ignore(cfg(windows))]
|
||||
fn test_dlist_asymmetric_link() {
|
||||
let l = new_dlist::<int>();
|
||||
let l = DList::<int>();
|
||||
let _one = l.push_n(1);
|
||||
let two = l.push_n(2);
|
||||
two.prev = None;
|
||||
@@ -852,7 +854,7 @@ mod tests {
|
||||
}
|
||||
#[test] #[should_fail] #[ignore(cfg(windows))]
|
||||
fn test_dlist_cyclic_list() {
|
||||
let l = new_dlist::<int>();
|
||||
let l = DList::<int>();
|
||||
let one = l.push_n(1);
|
||||
let _two = l.push_n(2);
|
||||
let three = l.push_n(3);
|
||||
@@ -862,32 +864,32 @@ mod tests {
|
||||
}
|
||||
#[test] #[should_fail] #[ignore(cfg(windows))]
|
||||
fn test_dlist_headless() {
|
||||
new_dlist::<int>().head();
|
||||
DList::<int>().head();
|
||||
}
|
||||
#[test] #[should_fail] #[ignore(cfg(windows))]
|
||||
fn test_dlist_insert_already_present_before() {
|
||||
let l = new_dlist::<int>();
|
||||
let l = DList::<int>();
|
||||
let one = l.push_n(1);
|
||||
let two = l.push_n(2);
|
||||
l.insert_n_before(two, one);
|
||||
}
|
||||
#[test] #[should_fail] #[ignore(cfg(windows))]
|
||||
fn test_dlist_insert_already_present_after() {
|
||||
let l = new_dlist::<int>();
|
||||
let l = DList::<int>();
|
||||
let one = l.push_n(1);
|
||||
let two = l.push_n(2);
|
||||
l.insert_n_after(one, two);
|
||||
}
|
||||
#[test] #[should_fail] #[ignore(cfg(windows))]
|
||||
fn test_dlist_insert_before_orphan() {
|
||||
let l = new_dlist::<int>();
|
||||
let l = DList::<int>();
|
||||
let one = new_dlist_node(1);
|
||||
let two = new_dlist_node(2);
|
||||
l.insert_n_before(one, two);
|
||||
}
|
||||
#[test] #[should_fail] #[ignore(cfg(windows))]
|
||||
fn test_dlist_insert_after_orphan() {
|
||||
let l = new_dlist::<int>();
|
||||
let l = DList::<int>();
|
||||
let one = new_dlist_node(1);
|
||||
let two = new_dlist_node(2);
|
||||
l.insert_n_after(two, one);
|
||||
|
||||
@@ -13,7 +13,6 @@ import unsafe::reinterpret_cast;
|
||||
import ptr::null;
|
||||
|
||||
export DVec;
|
||||
export dvec;
|
||||
export from_elem;
|
||||
export from_vec;
|
||||
export extensions;
|
||||
@@ -59,7 +58,7 @@ enum DVec<A> {
|
||||
}
|
||||
|
||||
/// Creates a new, empty dvec
|
||||
fn dvec<A>() -> DVec<A> {
|
||||
fn DVec<A>() -> DVec<A> {
|
||||
DVec_({mut data: ~[mut]})
|
||||
}
|
||||
|
||||
|
||||
@@ -6,7 +6,7 @@ Basic input/output
|
||||
|
||||
import result::Result;
|
||||
|
||||
import dvec::{DVec, dvec};
|
||||
import dvec::DVec;
|
||||
import libc::{c_int, c_long, c_uint, c_void, size_t, ssize_t};
|
||||
import libc::consts::os::posix88::*;
|
||||
import libc::consts::os::extra::*;
|
||||
@@ -683,7 +683,7 @@ impl MemBuffer: Writer {
|
||||
}
|
||||
|
||||
fn mem_buffer() -> MemBuffer {
|
||||
@{buf: dvec(), mut pos: 0u}
|
||||
@{buf: DVec(), mut pos: 0u}
|
||||
}
|
||||
fn mem_buffer_writer(b: MemBuffer) -> Writer { b as Writer }
|
||||
fn mem_buffer_buf(b: MemBuffer) -> ~[u8] { b.buf.get() }
|
||||
|
||||
@@ -149,25 +149,25 @@ mod global_env {
|
||||
|
||||
fn getenv(n: &str) -> Option<~str> {
|
||||
let env_ch = get_global_env_chan();
|
||||
let po = comm::port();
|
||||
let po = comm::Port();
|
||||
comm::send(env_ch, MsgGetEnv(str::from_slice(n),
|
||||
comm::chan(po)));
|
||||
comm::Chan(po)));
|
||||
comm::recv(po)
|
||||
}
|
||||
|
||||
fn setenv(n: &str, v: &str) {
|
||||
let env_ch = get_global_env_chan();
|
||||
let po = comm::port();
|
||||
let po = comm::Port();
|
||||
comm::send(env_ch, MsgSetEnv(str::from_slice(n),
|
||||
str::from_slice(v),
|
||||
comm::chan(po)));
|
||||
comm::Chan(po)));
|
||||
comm::recv(po)
|
||||
}
|
||||
|
||||
fn env() -> ~[(~str,~str)] {
|
||||
let env_ch = get_global_env_chan();
|
||||
let po = comm::port();
|
||||
comm::send(env_ch, MsgEnv(comm::chan(po)));
|
||||
let po = comm::Port();
|
||||
comm::send(env_ch, MsgEnv(comm::Chan(po)));
|
||||
comm::recv(po)
|
||||
}
|
||||
|
||||
@@ -833,7 +833,7 @@ mod tests {
|
||||
|
||||
fn make_rand_name() -> ~str {
|
||||
import rand;
|
||||
let rng: rand::Rng = rand::rng();
|
||||
let rng: rand::Rng = rand::Rng();
|
||||
let n = ~"TEST" + rng.gen_str(10u);
|
||||
assert option::is_none(getenv(n));
|
||||
n
|
||||
|
||||
@@ -47,8 +47,8 @@ unsafe fn chan_from_global_ptr<T: send>(
|
||||
|
||||
let (setup_po, setup_ch) = do task_fn().spawn_conversation
|
||||
|setup_po, setup_ch| {
|
||||
let po = comm::port::<T>();
|
||||
let ch = comm::chan(po);
|
||||
let po = comm::Port::<T>();
|
||||
let ch = comm::Chan(po);
|
||||
comm::send(setup_ch, ch);
|
||||
|
||||
// Wait to hear if we are the official instance of
|
||||
@@ -105,8 +105,8 @@ fn test_from_global_chan1() {
|
||||
}
|
||||
};
|
||||
// Talk to it
|
||||
let po = comm::port();
|
||||
comm::send(ch, comm::chan(po));
|
||||
let po = comm::Port();
|
||||
comm::send(ch, comm::Chan(po));
|
||||
assert comm::recv(po) == true;
|
||||
|
||||
// This one just reuses the previous channel
|
||||
@@ -118,8 +118,8 @@ fn test_from_global_chan1() {
|
||||
};
|
||||
|
||||
// Talk to the original global task
|
||||
let po = comm::port();
|
||||
comm::send(ch, comm::chan(po));
|
||||
let po = comm::Port();
|
||||
comm::send(ch, comm::Chan(po));
|
||||
assert comm::recv(po) == true;
|
||||
}
|
||||
|
||||
@@ -131,8 +131,8 @@ fn test_from_global_chan2() {
|
||||
let globchan = 0u;
|
||||
let globchanp = ptr::addr_of(globchan);
|
||||
|
||||
let resultpo = comm::port();
|
||||
let resultch = comm::chan(resultpo);
|
||||
let resultpo = comm::Port();
|
||||
let resultch = comm::Chan(resultpo);
|
||||
|
||||
// Spawn a bunch of tasks that all want to compete to
|
||||
// create the global channel
|
||||
@@ -148,9 +148,9 @@ fn test_from_global_chan2() {
|
||||
}
|
||||
}
|
||||
};
|
||||
let po = comm::port();
|
||||
comm::send(ch, comm::chan(po));
|
||||
// We are the winner if our version of the
|
||||
let po = comm::Port();
|
||||
comm::send(ch, comm::Chan(po));
|
||||
// We are The winner if our version of the
|
||||
// task was installed
|
||||
let winner = comm::recv(po);
|
||||
comm::send(resultch, winner == i);
|
||||
@@ -186,8 +186,8 @@ fn test_from_global_chan2() {
|
||||
* a reference to its parent, so the parent will not die.
|
||||
*/
|
||||
unsafe fn weaken_task(f: fn(comm::Port<()>)) {
|
||||
let po = comm::port();
|
||||
let ch = comm::chan(po);
|
||||
let po = comm::Port();
|
||||
let ch = comm::Chan(po);
|
||||
unsafe {
|
||||
rustrt::rust_task_weaken(unsafe::reinterpret_cast(ch));
|
||||
}
|
||||
|
||||
@@ -1,6 +1,6 @@
|
||||
//! Random number generation
|
||||
|
||||
export Rng, rng, seed, seeded_rng, Weighted, extensions;
|
||||
export Rng, seed, seeded_rng, Weighted, extensions;
|
||||
export xorshift, seeded_xorshift;
|
||||
|
||||
#[allow(non_camel_case_types)] // runtime type
|
||||
@@ -259,7 +259,7 @@ fn seed() -> ~[u8] {
|
||||
}
|
||||
|
||||
/// Create a random number generator with a system specified seed
|
||||
fn rng() -> Rng {
|
||||
fn Rng() -> Rng {
|
||||
@RandRes(rustrt::rand_new()) as Rng
|
||||
}
|
||||
|
||||
@@ -335,7 +335,7 @@ mod tests {
|
||||
|
||||
#[test]
|
||||
fn gen_int_range() {
|
||||
let r = rand::rng();
|
||||
let r = rand::Rng();
|
||||
let a = r.gen_int_range(-3, 42);
|
||||
assert a >= -3 && a < 42;
|
||||
assert r.gen_int_range(0, 1) == 0;
|
||||
@@ -346,12 +346,12 @@ mod tests {
|
||||
#[should_fail]
|
||||
#[ignore(cfg(windows))]
|
||||
fn gen_int_from_fail() {
|
||||
rand::rng().gen_int_range(5, -2);
|
||||
rand::Rng().gen_int_range(5, -2);
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn gen_uint_range() {
|
||||
let r = rand::rng();
|
||||
let r = rand::Rng();
|
||||
let a = r.gen_uint_range(3u, 42u);
|
||||
assert a >= 3u && a < 42u;
|
||||
assert r.gen_uint_range(0u, 1u) == 0u;
|
||||
@@ -362,12 +362,12 @@ mod tests {
|
||||
#[should_fail]
|
||||
#[ignore(cfg(windows))]
|
||||
fn gen_uint_range_fail() {
|
||||
rand::rng().gen_uint_range(5u, 2u);
|
||||
rand::Rng().gen_uint_range(5u, 2u);
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn gen_float() {
|
||||
let r = rand::rng();
|
||||
let r = rand::Rng();
|
||||
let a = r.gen_float();
|
||||
let b = r.gen_float();
|
||||
log(debug, (a, b));
|
||||
@@ -375,14 +375,14 @@ mod tests {
|
||||
|
||||
#[test]
|
||||
fn gen_weighted_bool() {
|
||||
let r = rand::rng();
|
||||
let r = rand::Rng();
|
||||
assert r.gen_weighted_bool(0u) == true;
|
||||
assert r.gen_weighted_bool(1u) == true;
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn gen_str() {
|
||||
let r = rand::rng();
|
||||
let r = rand::Rng();
|
||||
log(debug, r.gen_str(10u));
|
||||
log(debug, r.gen_str(10u));
|
||||
log(debug, r.gen_str(10u));
|
||||
@@ -393,7 +393,7 @@ mod tests {
|
||||
|
||||
#[test]
|
||||
fn gen_bytes() {
|
||||
let r = rand::rng();
|
||||
let r = rand::Rng();
|
||||
assert r.gen_bytes(0u).len() == 0u;
|
||||
assert r.gen_bytes(10u).len() == 10u;
|
||||
assert r.gen_bytes(16u).len() == 16u;
|
||||
@@ -401,20 +401,20 @@ mod tests {
|
||||
|
||||
#[test]
|
||||
fn choose() {
|
||||
let r = rand::rng();
|
||||
let r = rand::Rng();
|
||||
assert r.choose(~[1, 1, 1]) == 1;
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn choose_option() {
|
||||
let r = rand::rng();
|
||||
let r = rand::Rng();
|
||||
assert r.choose_option(~[]) == None::<int>;
|
||||
assert r.choose_option(~[1, 1, 1]) == Some(1);
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn choose_weighted() {
|
||||
let r = rand::rng();
|
||||
let r = rand::Rng();
|
||||
assert r.choose_weighted(~[{weight: 1u, item: 42}]) == 42;
|
||||
assert r.choose_weighted(~[
|
||||
{weight: 0u, item: 42},
|
||||
@@ -424,7 +424,7 @@ mod tests {
|
||||
|
||||
#[test]
|
||||
fn choose_weighted_option() {
|
||||
let r = rand::rng();
|
||||
let r = rand::Rng();
|
||||
assert r.choose_weighted_option(~[{weight: 1u, item: 42}]) ==
|
||||
Some(42);
|
||||
assert r.choose_weighted_option(~[
|
||||
@@ -436,7 +436,7 @@ mod tests {
|
||||
|
||||
#[test]
|
||||
fn weighted_vec() {
|
||||
let r = rand::rng();
|
||||
let r = rand::Rng();
|
||||
let empty: ~[int] = ~[];
|
||||
assert r.weighted_vec(~[]) == empty;
|
||||
assert r.weighted_vec(~[
|
||||
@@ -448,7 +448,7 @@ mod tests {
|
||||
|
||||
#[test]
|
||||
fn shuffle() {
|
||||
let r = rand::rng();
|
||||
let r = rand::Rng();
|
||||
let empty: ~[int] = ~[];
|
||||
assert r.shuffle(~[]) == empty;
|
||||
assert r.shuffle(~[1, 1, 1]) == ~[1, 1, 1];
|
||||
|
||||
@@ -297,8 +297,8 @@ fn program_output(prog: &str, args: &[~str]) ->
|
||||
// in parallel so we don't deadlock while blocking on one
|
||||
// or the other. FIXME (#2625): Surely there's a much more
|
||||
// clever way to do this.
|
||||
let p = comm::port();
|
||||
let ch = comm::chan(p);
|
||||
let p = comm::Port();
|
||||
let ch = comm::Chan(p);
|
||||
do task::spawn_sched(task::SingleThreaded) {
|
||||
let errput = readclose(pipe_err.in);
|
||||
comm::send(ch, (2, errput));
|
||||
|
||||
@@ -39,7 +39,7 @@ mod linear {
|
||||
((capacity as float) * 3. / 4.) as uint
|
||||
}
|
||||
|
||||
fn linear_map<K,V>(
|
||||
fn LinearMap<K,V>(
|
||||
+hashfn: pure fn~(x: &K) -> uint,
|
||||
+eqfn: pure fn~(x: &K, y: &K) -> bool) -> LinearMap<K,V> {
|
||||
|
||||
@@ -338,13 +338,13 @@ mod linear {
|
||||
#[test]
|
||||
mod test {
|
||||
|
||||
import linear::{LinearMap, linear_map};
|
||||
import linear::LinearMap;
|
||||
|
||||
pure fn uint_hash(x: &uint) -> uint { *x }
|
||||
pure fn uint_eq(x: &uint, y: &uint) -> bool { *x == *y }
|
||||
|
||||
fn int_linear_map<V>() -> LinearMap<uint,V> {
|
||||
return linear_map(uint_hash, uint_eq);
|
||||
return LinearMap(uint_hash, uint_eq);
|
||||
}
|
||||
|
||||
#[test]
|
||||
|
||||
@@ -285,8 +285,8 @@ impl TaskBuilder {
|
||||
}
|
||||
|
||||
// Construct the future and give it to the caller.
|
||||
let po = comm::port::<Notification>();
|
||||
let ch = comm::chan(po);
|
||||
let po = comm::Port::<Notification>();
|
||||
let ch = comm::Chan(po);
|
||||
|
||||
blk(do future::from_fn {
|
||||
match comm::recv(po) {
|
||||
@@ -368,11 +368,11 @@ impl TaskBuilder {
|
||||
* to the child.
|
||||
*/
|
||||
fn spawn_listener<A: send>(+f: fn~(comm::Port<A>)) -> comm::Chan<A> {
|
||||
let setup_po = comm::port();
|
||||
let setup_ch = comm::chan(setup_po);
|
||||
let setup_po = comm::Port();
|
||||
let setup_ch = comm::Chan(setup_po);
|
||||
do self.spawn {
|
||||
let po = comm::port();
|
||||
let ch = comm::chan(po);
|
||||
let po = comm::Port();
|
||||
let ch = comm::Chan(po);
|
||||
comm::send(setup_ch, ch);
|
||||
f(po);
|
||||
}
|
||||
@@ -385,8 +385,8 @@ impl TaskBuilder {
|
||||
fn spawn_conversation<A: send, B: send>
|
||||
(+f: fn~(comm::Port<A>, comm::Chan<B>))
|
||||
-> (comm::Port<B>, comm::Chan<A>) {
|
||||
let from_child = comm::port();
|
||||
let to_parent = comm::chan(from_child);
|
||||
let from_child = comm::Port();
|
||||
let to_parent = comm::Chan(from_child);
|
||||
let to_child = do self.spawn_listener |from_parent| {
|
||||
f(from_parent, to_parent)
|
||||
};
|
||||
@@ -407,8 +407,8 @@ impl TaskBuilder {
|
||||
* Fails if a future_result was already set for this task.
|
||||
*/
|
||||
fn try<T: send>(+f: fn~() -> T) -> Result<T,()> {
|
||||
let po = comm::port();
|
||||
let ch = comm::chan(po);
|
||||
let po = comm::Port();
|
||||
let ch = comm::Chan(po);
|
||||
let mut result = None;
|
||||
|
||||
do self.future_result(|+r| { result = Some(r); }).spawn {
|
||||
@@ -711,7 +711,7 @@ fn new_taskset() -> TaskSet {
|
||||
task1 == task2
|
||||
}
|
||||
|
||||
send_map::linear::linear_map(task_hash, task_eq)
|
||||
send_map::linear::LinearMap(task_hash, task_eq)
|
||||
}
|
||||
fn taskset_insert(tasks: &mut TaskSet, task: *rust_task) {
|
||||
let didnt_overwrite = tasks.insert(task, ());
|
||||
@@ -1295,7 +1295,7 @@ unsafe fn get_task_local_map(task: *rust_task) -> TaskLocalMap {
|
||||
// drop when they finish. No "re-storing after modifying" is needed.
|
||||
let map_ptr = rustrt::rust_get_task_local_data(task);
|
||||
if map_ptr.is_null() {
|
||||
let map: TaskLocalMap = @dvec::dvec();
|
||||
let map: TaskLocalMap = @dvec::DVec();
|
||||
// Use reinterpret_cast -- transmute would take map away from us also.
|
||||
rustrt::rust_set_task_local_data(task, unsafe::reinterpret_cast(map));
|
||||
rustrt::rust_task_local_data_atexit(task, cleanup_task_local_map);
|
||||
@@ -1494,8 +1494,8 @@ extern mod rustrt {
|
||||
|
||||
#[test]
|
||||
fn test_spawn_raw_simple() {
|
||||
let po = comm::port();
|
||||
let ch = comm::chan(po);
|
||||
let po = comm::Port();
|
||||
let ch = comm::Chan(po);
|
||||
do spawn_raw(default_task_opts()) {
|
||||
comm::send(ch, ());
|
||||
}
|
||||
@@ -1532,8 +1532,8 @@ fn test_cant_dup_task_builder() {
|
||||
|
||||
#[test] #[ignore(cfg(windows))]
|
||||
fn test_spawn_unlinked_unsup_no_fail_down() { // grandchild sends on a port
|
||||
let po = comm::port();
|
||||
let ch = comm::chan(po);
|
||||
let po = comm::Port();
|
||||
let ch = comm::Chan(po);
|
||||
do spawn_unlinked {
|
||||
do spawn_unlinked {
|
||||
// Give middle task a chance to fail-but-not-kill-us.
|
||||
@@ -1562,8 +1562,8 @@ fn test_spawn_unlinked_sup_fail_down() {
|
||||
|
||||
#[test] #[should_fail] #[ignore(cfg(windows))]
|
||||
fn test_spawn_linked_sup_fail_up() { // child fails; parent fails
|
||||
let po = comm::port::<()>();
|
||||
let _ch = comm::chan(po);
|
||||
let po = comm::Port::<()>();
|
||||
let _ch = comm::Chan(po);
|
||||
// Unidirectional "parenting" shouldn't override bidirectional linked.
|
||||
// We have to cheat with opts - the interface doesn't support them because
|
||||
// they don't make sense (redundant with task().supervised()).
|
||||
@@ -1591,8 +1591,8 @@ fn test_spawn_linked_sup_fail_down() { // parent fails; child fails
|
||||
}
|
||||
#[test] #[should_fail] #[ignore(cfg(windows))]
|
||||
fn test_spawn_linked_unsup_fail_up() { // child fails; parent fails
|
||||
let po = comm::port::<()>();
|
||||
let _ch = comm::chan(po);
|
||||
let po = comm::Port::<()>();
|
||||
let _ch = comm::Chan(po);
|
||||
// Default options are to spawn linked & unsupervised.
|
||||
do spawn { fail; }
|
||||
comm::recv(po); // We should get punted awake
|
||||
@@ -1664,10 +1664,10 @@ fn test_spawn_linked_sup_propagate_sibling() {
|
||||
#[test]
|
||||
#[ignore(cfg(windows))]
|
||||
fn test_spawn_raw_notify() {
|
||||
let task_po = comm::port();
|
||||
let task_ch = comm::chan(task_po);
|
||||
let notify_po = comm::port();
|
||||
let notify_ch = comm::chan(notify_po);
|
||||
let task_po = comm::Port();
|
||||
let task_ch = comm::Chan(task_po);
|
||||
let notify_po = comm::Port();
|
||||
let notify_ch = comm::Chan(notify_po);
|
||||
|
||||
let opts = {
|
||||
notify_chan: Some(notify_ch)
|
||||
@@ -1694,8 +1694,8 @@ fn test_spawn_raw_notify() {
|
||||
|
||||
#[test]
|
||||
fn test_run_basic() {
|
||||
let po = comm::port();
|
||||
let ch = comm::chan(po);
|
||||
let po = comm::Port();
|
||||
let ch = comm::Chan(po);
|
||||
do task().spawn {
|
||||
comm::send(ch, ());
|
||||
}
|
||||
@@ -1704,8 +1704,8 @@ fn test_run_basic() {
|
||||
|
||||
#[test]
|
||||
fn test_add_wrapper() {
|
||||
let po = comm::port();
|
||||
let ch = comm::chan(po);
|
||||
let po = comm::Port();
|
||||
let ch = comm::Chan(po);
|
||||
let b0 = task();
|
||||
let b1 = do b0.add_wrapper |body| {
|
||||
fn~() {
|
||||
@@ -1738,8 +1738,8 @@ fn test_back_to_the_future_result() {
|
||||
|
||||
#[test]
|
||||
fn test_spawn_listiner_bidi() {
|
||||
let po = comm::port();
|
||||
let ch = comm::chan(po);
|
||||
let po = comm::Port();
|
||||
let ch = comm::Chan(po);
|
||||
let ch = do spawn_listener |po| {
|
||||
// Now the child has a port called 'po' to read from and
|
||||
// an environment-captured channel called 'ch'.
|
||||
@@ -1794,8 +1794,8 @@ fn test_spawn_sched_no_threads() {
|
||||
|
||||
#[test]
|
||||
fn test_spawn_sched() {
|
||||
let po = comm::port();
|
||||
let ch = comm::chan(po);
|
||||
let po = comm::Port();
|
||||
let ch = comm::Chan(po);
|
||||
|
||||
fn f(i: int, ch: comm::Chan<()>) {
|
||||
let parent_sched_id = rustrt::rust_get_sched_id();
|
||||
@@ -1818,8 +1818,8 @@ fn test_spawn_sched() {
|
||||
|
||||
#[test]
|
||||
fn test_spawn_sched_childs_on_same_sched() {
|
||||
let po = comm::port();
|
||||
let ch = comm::chan(po);
|
||||
let po = comm::Port();
|
||||
let ch = comm::Chan(po);
|
||||
|
||||
do spawn_sched(SingleThreaded) {
|
||||
let parent_sched_id = rustrt::rust_get_sched_id();
|
||||
@@ -1852,10 +1852,10 @@ fn test_spawn_sched_blocking() {
|
||||
// without affecting other schedulers
|
||||
for iter::repeat(20u) {
|
||||
|
||||
let start_po = comm::port();
|
||||
let start_ch = comm::chan(start_po);
|
||||
let fin_po = comm::port();
|
||||
let fin_ch = comm::chan(fin_po);
|
||||
let start_po = comm::Port();
|
||||
let start_ch = comm::Chan(start_po);
|
||||
let fin_po = comm::Port();
|
||||
let fin_ch = comm::Chan(fin_po);
|
||||
|
||||
let lock = testrt::rust_dbg_lock_create();
|
||||
|
||||
@@ -1882,13 +1882,13 @@ fn test_spawn_sched_blocking() {
|
||||
}
|
||||
}
|
||||
|
||||
let setup_po = comm::port();
|
||||
let setup_ch = comm::chan(setup_po);
|
||||
let parent_po = comm::port();
|
||||
let parent_ch = comm::chan(parent_po);
|
||||
let setup_po = comm::Port();
|
||||
let setup_ch = comm::Chan(setup_po);
|
||||
let parent_po = comm::Port();
|
||||
let parent_ch = comm::Chan(parent_po);
|
||||
do spawn {
|
||||
let child_po = comm::port();
|
||||
comm::send(setup_ch, comm::chan(child_po));
|
||||
let child_po = comm::Port();
|
||||
comm::send(setup_ch, comm::Chan(child_po));
|
||||
pingpong(child_po, parent_ch);
|
||||
};
|
||||
|
||||
@@ -1905,8 +1905,8 @@ fn test_spawn_sched_blocking() {
|
||||
|
||||
#[cfg(test)]
|
||||
fn avoid_copying_the_body(spawnfn: fn(+fn~())) {
|
||||
let p = comm::port::<uint>();
|
||||
let ch = comm::chan(p);
|
||||
let p = comm::Port::<uint>();
|
||||
let ch = comm::Chan(p);
|
||||
|
||||
let x = ~1;
|
||||
let x_in_parent = ptr::addr_of(*x) as uint;
|
||||
@@ -1972,8 +1972,8 @@ fn test_avoid_copying_the_body_unlinked() {
|
||||
|
||||
#[test]
|
||||
fn test_platform_thread() {
|
||||
let po = comm::port();
|
||||
let ch = comm::chan(po);
|
||||
let po = comm::Port();
|
||||
let ch = comm::Chan(po);
|
||||
do task().sched_mode(PlatformThread).spawn {
|
||||
comm::send(ch, ());
|
||||
}
|
||||
@@ -1984,7 +1984,7 @@ fn test_platform_thread() {
|
||||
#[ignore(cfg(windows))]
|
||||
#[should_fail]
|
||||
fn test_unkillable() {
|
||||
let po = comm::port();
|
||||
let po = comm::Port();
|
||||
let ch = po.chan();
|
||||
|
||||
// We want to do this after failing
|
||||
@@ -2020,7 +2020,7 @@ fn test_unkillable() {
|
||||
#[ignore(cfg(windows))]
|
||||
#[should_fail]
|
||||
fn test_unkillable_nested() {
|
||||
let po = comm::port();
|
||||
let po = comm::Port();
|
||||
let ch = po.chan();
|
||||
|
||||
// We want to do this after failing
|
||||
|
||||
Reference in New Issue
Block a user