Skip to content

Commit

Permalink
Camel case various core constructors
Browse files Browse the repository at this point in the history
  • Loading branch information
brson committed Aug 28, 2012
1 parent 4ba9fdd commit 161a82e
Show file tree
Hide file tree
Showing 113 changed files with 530 additions and 545 deletions.
14 changes: 7 additions & 7 deletions doc/rust.md
Expand Up @@ -3030,8 +3030,8 @@ The result of a `spawn` call is a `core::task::task` value.
An example of a `spawn` call:

~~~~
let po = comm::port();
let ch = comm::chan(po);
let po = comm::Port();
let ch = comm::Chan(po);
do task::spawn {
// let task run, do other things
Expand All @@ -3052,24 +3052,24 @@ channel's outgoing buffer.
An example of a send:

~~~~
let po = comm::port();
let ch = comm::chan(po);
let po = comm::Port();
let ch = comm::Chan(po);
comm::send(ch, ~"hello, world");
~~~~


### Receiving values from ports

Receiving a value is done by a call to the `recv` method on a value of type
`core::comm::port`. This call causes the receiving task to enter the *blocked
`core::comm::Port`. This call causes the receiving task to enter the *blocked
reading* state until a value arrives in the port's receive queue, at which
time the port deques a value to return, and un-blocks the receiving task.

An example of a *receive*:

~~~~~~~~
# let po = comm::port();
# let ch = comm::chan(po);
# let po = comm::Port();
# let ch = comm::Chan(po);
# comm::send(ch, ~"");
let s = comm::recv(po);
~~~~~~~~
Expand Down
4 changes: 2 additions & 2 deletions doc/tutorial.md
Expand Up @@ -2996,9 +2996,9 @@ message to the port. The next statement actually spawns the child:

~~~~
# import task::{spawn};
# import comm::{port, chan};
# import comm::{Port, Chan};
# fn some_expensive_computation() -> int { 42 }
# let port = port();
# let port = Port();
# let chan = port.chan();
do spawn {
let result = some_expensive_computation();
Expand Down
82 changes: 41 additions & 41 deletions src/libcore/comm.rs
Expand Up @@ -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;
Expand Down Expand Up @@ -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) }
Expand All @@ -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())
}

Expand Down Expand Up @@ -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))
}

Expand Down Expand Up @@ -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);
Expand All @@ -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");

Expand All @@ -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 {
Expand All @@ -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;
Expand Down Expand Up @@ -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";
}
Expand All @@ -436,16 +436,16 @@ 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);
}

#[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)
Expand All @@ -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();
Expand All @@ -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 {
Expand Down

0 comments on commit 161a82e

Please sign in to comment.