Skip to content

Commit

Permalink
Convert more core types to camel case
Browse files Browse the repository at this point in the history
  • Loading branch information
brson committed Aug 16, 2012
1 parent af43613 commit 9c6890f
Show file tree
Hide file tree
Showing 57 changed files with 415 additions and 390 deletions.
12 changes: 6 additions & 6 deletions doc/tutorial.md
Expand Up @@ -2975,9 +2975,9 @@ the string in response. The child terminates when `0` is received.
Here is the function that implements the child task:

~~~~
# import comm::{port, chan};
fn stringifier(from_parent: port<uint>,
to_parent: chan<~str>) {
# import comm::{Port, port, Chan, chan};
fn stringifier(from_parent: Port<uint>,
to_parent: Chan<~str>) {
let mut value: uint;
loop {
value = from_parent.recv();
Expand All @@ -2999,9 +2999,9 @@ Here is the code for the parent task:

~~~~
# import task::{spawn_conversation};
# import comm::{chan, port};
# fn stringifier(from_parent: comm::port<uint>,
# to_parent: comm::chan<~str>) {
# import comm::{Chan, chan, Port, port};
# fn stringifier(from_parent: comm::Port<uint>,
# to_parent: comm::Chan<~str>) {
# comm::send(to_parent, ~"22");
# comm::send(to_parent, ~"23");
# comm::send(to_parent, ~"0");
Expand Down
4 changes: 2 additions & 2 deletions src/compiletest/procsrv.rs
Expand Up @@ -62,12 +62,12 @@ fn run(lib_path: ~str,
writeclose(pipe_in.out, input);
let p = pipes::port_set();
let ch = p.chan();
do task::spawn_sched(task::single_threaded) {
do task::spawn_sched(task::SingleThreaded) {
let errput = readclose(pipe_err.in);
ch.send((2, errput));
}
let ch = p.chan();
do task::spawn_sched(task::single_threaded) {
do task::spawn_sched(task::SingleThreaded) {
let output = readclose(pipe_out.in);
ch.send((1, output));
}
Expand Down
57 changes: 29 additions & 28 deletions src/libcore/comm.rs
Expand Up @@ -30,8 +30,8 @@
import either::Either;
import libc::size_t;

export port;
export chan;
export Port, port;
export Chan, chan;
export send;
export recv;
export peek;
Expand All @@ -48,8 +48,8 @@ export listen;
* transmitted. If a port value is copied, both copies refer to the same
* port. Ports may be associated with multiple `chan`s.
*/
enum port<T: send> {
port_t(@port_ptr<T>)
enum Port<T: send> {
Port_(@PortPtr<T>)
}

// It's critical that this only have one variant, so it has a record
Expand All @@ -64,40 +64,40 @@ enum port<T: send> {
* data will be silently dropped. Channels may be duplicated and
* themselves transmitted over other channels.
*/
enum chan<T: send> {
chan_t(port_id)
enum Chan<T: send> {
Chan_(port_id)
}

/// Constructs a port
fn port<T: send>() -> port<T> {
port_t(@port_ptr(rustrt::new_port(sys::size_of::<T>() as size_t)))
fn port<T: send>() -> Port<T> {
Port_(@PortPtr(rustrt::new_port(sys::size_of::<T>() as size_t)))
}

impl<T: send> port<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) }

}

impl<T: send> chan<T> {
impl<T: send> Chan<T> {

fn chan() -> chan<T> { self }
fn chan() -> Chan<T> { self }
fn send(+v: T) { send(self, v) }
fn recv() -> T { recv_chan(self) }
fn peek() -> bool { peek_chan(self) }

}

/// Open a new receiving channel for the duration of a function
fn listen<T: send, U>(f: fn(chan<T>) -> U) -> U {
fn listen<T: send, U>(f: fn(Chan<T>) -> U) -> U {
let po = port();
f(po.chan())
}

class port_ptr<T:send> {
class PortPtr<T:send> {
let po: *rust_port;
new(po: *rust_port) { self.po = po; }
drop unsafe {
Expand Down Expand Up @@ -130,9 +130,9 @@ class port_ptr<T:send> {
* Fails if the port is detached or dead. Fails if the port
* is owned by a different task.
*/
fn as_raw_port<T: send, U>(ch: comm::chan<T>, f: fn(*rust_port) -> U) -> U {
fn as_raw_port<T: send, U>(ch: comm::Chan<T>, f: fn(*rust_port) -> U) -> U {

class portref {
class PortRef {
let p: *rust_port;
new(p: *rust_port) { self.p = p; }
drop {
Expand All @@ -142,7 +142,7 @@ fn as_raw_port<T: send, U>(ch: comm::chan<T>, f: fn(*rust_port) -> U) -> U {
}
}

let p = portref(rustrt::rust_port_take(*ch));
let p = PortRef(rustrt::rust_port_take(*ch));

if ptr::is_null(p.p) {
fail ~"unable to locate port for channel"
Expand All @@ -157,16 +157,16 @@ 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> {
chan_t(rustrt::get_port_id((**p).po))
fn chan<T: send>(p: Port<T>) -> Chan<T> {
Chan_(rustrt::get_port_id((**p).po))
}

/**
* Sends data over a channel. The sent data is moved into the channel,
* whereupon the caller loses access to it.
*/
fn send<T: send>(ch: chan<T>, +data: T) {
let chan_t(p) = ch;
fn send<T: send>(ch: Chan<T>, +data: T) {
let Chan_(p) = ch;
let data_ptr = ptr::addr_of(data) as *();
let res = rustrt::rust_port_id_send(p, data_ptr);
if res != 0u unsafe {
Expand All @@ -180,17 +180,17 @@ fn send<T: send>(ch: chan<T>, +data: T) {
* Receive from a port. If no data is available on the port then the
* task will block until data becomes available.
*/
fn recv<T: send>(p: port<T>) -> T { recv_((**p).po) }
fn recv<T: send>(p: Port<T>) -> T { recv_((**p).po) }

/// Returns true if there are messages available
fn peek<T: send>(p: port<T>) -> bool { peek_((**p).po) }
fn peek<T: send>(p: Port<T>) -> bool { peek_((**p).po) }

#[doc(hidden)]
fn recv_chan<T: send>(ch: comm::chan<T>) -> T {
fn recv_chan<T: send>(ch: comm::Chan<T>) -> T {
as_raw_port(ch, |x|recv_(x))
}

fn peek_chan<T: send>(ch: comm::chan<T>) -> bool {
fn peek_chan<T: send>(ch: comm::Chan<T>) -> bool {
as_raw_port(ch, |x|peek_(x))
}

Expand Down Expand Up @@ -221,7 +221,7 @@ fn peek_(p: *rust_port) -> bool {
}

/// Receive on one of two ports
fn select2<A: send, B: send>(p_a: port<A>, p_b: port<B>)
fn select2<A: send, B: send>(p_a: Port<A>, p_b: Port<B>)
-> Either<A, B> {
let ports = ~[(**p_a).po, (**p_b).po];
let yield = 0u, yieldp = ptr::addr_of(yield);
Expand Down Expand Up @@ -257,9 +257,10 @@ fn select2<A: send, B: send>(p_a: port<A>, p_b: port<B>)

/* Implementation details */


#[allow(non_camel_case_types)] // runtime type
enum rust_port {}

#[allow(non_camel_case_types)] // runtime type
type port_id = int;

#[abi = "cdecl"]
Expand Down Expand Up @@ -329,7 +330,7 @@ fn chan_chan_infer() {

#[test]
fn chan_chan() {
let p = port::<chan<int>>(), p2 = port::<int>();
let p = port::<Chan<int>>(), p2 = port::<int>();
let c = chan(p);
send(c, chan(p2));
recv(p);
Expand Down
3 changes: 3 additions & 0 deletions src/libcore/core.rc
Expand Up @@ -235,8 +235,11 @@ mod dlist_iter {
mod send_map;

// Concurrency
#[warn(non_camel_case_types)]
mod comm;
#[warn(non_camel_case_types)]
mod task;
//#[warn(non_camel_ase_types)] pipec code continues to trip this warning
mod future;
mod pipes;

Expand Down
22 changes: 11 additions & 11 deletions src/libcore/future.rs
Expand Up @@ -18,7 +18,7 @@
import either::Either;
import pipes::recv;

export future;
export Future;
export extensions;
export from_value;
export from_port;
Expand All @@ -31,12 +31,12 @@ export spawn;
export future_pipe;

#[doc = "The future type"]
enum future<A> = {
enum Future<A> = {
mut v: Either<@A, fn@() -> A>
};

/// Methods on the `future` type
impl<A:copy send> future<A> {
impl<A:copy send> Future<A> {

fn get() -> A {
//! Get the value of the future
Expand All @@ -51,15 +51,15 @@ impl<A:copy send> future<A> {
}
}

fn from_value<A>(+val: A) -> future<A> {
fn from_value<A>(+val: A) -> Future<A> {
/*!
* Create a future from a value
*
* The value is immediately available and calling `get` later will
* not block.
*/

future({
Future({
mut v: either::Left(@val)
})
}
Expand All @@ -68,7 +68,7 @@ macro_rules! move_it {
{$x:expr} => { unsafe { let y <- *ptr::addr_of($x); y } }
}

fn from_port<A:send>(+port: future_pipe::client::waiting<A>) -> future<A> {
fn from_port<A:send>(+port: future_pipe::client::waiting<A>) -> Future<A> {
#[doc = "
Create a future from a port
Expand All @@ -87,7 +87,7 @@ fn from_port<A:send>(+port: future_pipe::client::waiting<A>) -> future<A> {
}
}

fn from_fn<A>(f: fn@() -> A) -> future<A> {
fn from_fn<A>(f: fn@() -> A) -> Future<A> {
/*!
* Create a future from a function.
*
Expand All @@ -96,12 +96,12 @@ fn from_fn<A>(f: fn@() -> A) -> future<A> {
* function. It is not spawned into another task.
*/

future({
Future({
mut v: either::Right(f)
})
}

fn spawn<A:send>(+blk: fn~() -> A) -> future<A> {
fn spawn<A:send>(+blk: fn~() -> A) -> Future<A> {
/*!
* Create a future from a unique closure.
*
Expand All @@ -114,13 +114,13 @@ fn spawn<A:send>(+blk: fn~() -> A) -> future<A> {
}))
}

fn get<A:copy>(future: &future<A>) -> A {
fn get<A:copy>(future: &Future<A>) -> A {
//! Get the value of the future

do with(future) |v| { *v }
}

fn with<A,B>(future: &future<A>, blk: fn((&A)) -> B) -> B {
fn with<A,B>(future: &Future<A>, blk: fn((&A)) -> B) -> B {
//! Work with the value without copying it

let v = match copy future.v {
Expand Down
14 changes: 7 additions & 7 deletions src/libcore/os.rs
Expand Up @@ -24,7 +24,7 @@ import option::{some, none};

import getcwd = rustrt::rust_getcwd;
import consts::*;
import task::task_builder;
import task::TaskBuilder;

export close, fclose, fsync_fd, waitpid;
export env, getenv, setenv, fdopen, pipe;
Expand Down Expand Up @@ -135,9 +135,9 @@ mod global_env {
}

enum Msg {
MsgGetEnv(~str, comm::chan<option<~str>>),
MsgSetEnv(~str, ~str, comm::chan<()>),
MsgEnv(comm::chan<~[(~str,~str)]>)
MsgGetEnv(~str, comm::Chan<option<~str>>),
MsgSetEnv(~str, ~str, comm::Chan<()>),
MsgEnv(comm::Chan<~[(~str,~str)]>)
}

fn getenv(n: ~str) -> option<~str> {
Expand All @@ -161,18 +161,18 @@ mod global_env {
comm::recv(po)
}

fn get_global_env_chan() -> comm::chan<Msg> {
fn get_global_env_chan() -> comm::Chan<Msg> {
let global_ptr = rustrt::rust_global_env_chan_ptr();
unsafe {
priv::chan_from_global_ptr(global_ptr, || {
// FIXME (#2621): This would be a good place to use a very
// small foreign stack
task::task().sched_mode(task::single_threaded).unlinked()
task::task().sched_mode(task::SingleThreaded).unlinked()
}, global_env_task)
}
}

fn global_env_task(msg_po: comm::port<Msg>) {
fn global_env_task(msg_po: comm::Port<Msg>) {
unsafe {
do priv::weaken_task |weak_po| {
loop {
Expand Down
14 changes: 7 additions & 7 deletions src/libcore/priv.rs
Expand Up @@ -7,7 +7,7 @@
export chan_from_global_ptr, weaken_task;

import compare_and_swap = rustrt::rust_compare_and_swap_ptr;
import task::task_builder;
import task::TaskBuilder;

#[allow(non_camel_case_types)] // runtime type
type rust_port_id = uint;
Expand All @@ -29,9 +29,9 @@ type GlobalPtr = *libc::uintptr_t;
*/
unsafe fn chan_from_global_ptr<T: send>(
global: GlobalPtr,
task_fn: fn() -> task::task_builder,
+f: fn~(comm::port<T>)
) -> comm::chan<T> {
task_fn: fn() -> task::TaskBuilder,
+f: fn~(comm::Port<T>)
) -> comm::Chan<T> {

enum Msg {
Proceed,
Expand Down Expand Up @@ -185,7 +185,7 @@ fn test_from_global_chan2() {
* * Weak tasks must not be supervised. A supervised task keeps
* a reference to its parent, so the parent will not die.
*/
unsafe fn weaken_task(f: fn(comm::port<()>)) {
unsafe fn weaken_task(f: fn(comm::Port<()>)) {
let po = comm::port();
let ch = comm::chan(po);
unsafe {
Expand All @@ -195,8 +195,8 @@ unsafe fn weaken_task(f: fn(comm::port<()>)) {
f(po);

class Unweaken {
let ch: comm::chan<()>;
new(ch: comm::chan<()>) { self.ch = ch; }
let ch: comm::Chan<()>;
new(ch: comm::Chan<()>) { self.ch = ch; }
drop unsafe {
rustrt::rust_task_unweaken(unsafe::reinterpret_cast(self.ch));
}
Expand Down

0 comments on commit 9c6890f

Please sign in to comment.