Skip to content

De-implicit-self libcore #5233

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
Mar 5, 2013
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 4 additions & 4 deletions src/libcore/cell.rs
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@ pub pure fn empty_cell<T>() -> Cell<T> {

pub impl<T> Cell<T> {
/// Yields the value, failing if the cell is empty.
fn take() -> T {
fn take(&self) -> T {
if self.is_empty() {
fail!(~"attempt to take an empty cell");
}
Expand All @@ -41,20 +41,20 @@ pub impl<T> Cell<T> {
}

/// Returns the value, failing if the cell is full.
fn put_back(value: T) {
fn put_back(&self, value: T) {
if !self.is_empty() {
fail!(~"attempt to put a value back into a full cell");
}
self.value = Some(value);
}

/// Returns true if the cell is empty and false if the cell is full.
pure fn is_empty() -> bool {
pure fn is_empty(&self) -> bool {
self.value.is_none()
}

// Calls a closure with a reference to the value.
fn with_ref<R>(op: fn(v: &T) -> R) -> R {
fn with_ref<R>(&self, op: fn(v: &T) -> R) -> R {
let v = self.take();
let r = op(&v);
self.put_back(v);
Expand Down
48 changes: 24 additions & 24 deletions src/libcore/comm.rs
Original file line number Diff line number Diff line change
Expand Up @@ -24,31 +24,31 @@ pub use pipes::Selectable;
/// A trait for things that can send multiple messages.
pub trait GenericChan<T> {
/// Sends a message.
fn send(x: T);
fn send(&self, x: T);
}

/// Things that can send multiple messages and can detect when the receiver
/// is closed
pub trait GenericSmartChan<T> {
/// Sends a message, or report if the receiver has closed the connection.
fn try_send(x: T) -> bool;
fn try_send(&self, x: T) -> bool;
}

/// A trait for things that can receive multiple messages.
pub trait GenericPort<T> {
/// Receives a message, or fails if the connection closes.
fn recv() -> T;
fn recv(&self) -> T;

/** Receives a message, or returns `none` if
the connection is closed or closes.
*/
fn try_recv() -> Option<T>;
fn try_recv(&self) -> Option<T>;
}

/// Ports that can `peek`
pub trait Peekable<T> {
/// Returns true if a message is available
pure fn peek() -> bool;
pure fn peek(&self) -> bool;
}

/// Returns the index of an endpoint that is ready to receive.
Expand Down Expand Up @@ -105,7 +105,7 @@ pub fn stream<T:Owned>() -> (Port<T>, Chan<T>) {
}

impl<T: Owned> GenericChan<T> for Chan<T> {
fn send(x: T) {
fn send(&self, x: T) {
let mut endp = None;
endp <-> self.endp;
self.endp = Some(
Expand All @@ -115,7 +115,7 @@ impl<T: Owned> GenericChan<T> for Chan<T> {

impl<T: Owned> GenericSmartChan<T> for Chan<T> {

fn try_send(x: T) -> bool {
fn try_send(&self, x: T) -> bool {
let mut endp = None;
endp <-> self.endp;
match streamp::client::try_data(unwrap(endp), x) {
Expand All @@ -129,15 +129,15 @@ impl<T: Owned> GenericSmartChan<T> for Chan<T> {
}

impl<T: Owned> GenericPort<T> for Port<T> {
fn recv() -> T {
fn recv(&self) -> T {
let mut endp = None;
endp <-> self.endp;
let streamp::data(x, endp) = recv(unwrap(endp));
self.endp = Some(endp);
x
}

fn try_recv() -> Option<T> {
fn try_recv(&self) -> Option<T> {
let mut endp = None;
endp <-> self.endp;
match try_recv(unwrap(endp)) {
Expand All @@ -151,7 +151,7 @@ impl<T: Owned> GenericPort<T> for Port<T> {
}

impl<T: Owned> Peekable<T> for Port<T> {
pure fn peek() -> bool {
pure fn peek(&self) -> bool {
unsafe {
let mut endp = None;
endp <-> self.endp;
Expand All @@ -166,7 +166,7 @@ impl<T: Owned> Peekable<T> for Port<T> {
}

impl<T: Owned> Selectable for Port<T> {
pure fn header() -> *PacketHeader {
pure fn header(&self) -> *PacketHeader {
unsafe {
match self.endp {
Some(ref endp) => endp.header(),
Expand All @@ -189,11 +189,11 @@ pub fn PortSet<T: Owned>() -> PortSet<T>{

pub impl<T: Owned> PortSet<T> {

fn add(port: Port<T>) {
fn add(&self, port: Port<T>) {
self.ports.push(port)
}

fn chan() -> Chan<T> {
fn chan(&self) -> Chan<T> {
let (po, ch) = stream();
self.add(po);
ch
Expand All @@ -202,7 +202,7 @@ pub impl<T: Owned> PortSet<T> {

impl<T: Owned> GenericPort<T> for PortSet<T> {

fn try_recv() -> Option<T> {
fn try_recv(&self) -> Option<T> {
let mut result = None;
// we have to swap the ports array so we aren't borrowing
// aliasable mutable memory.
Expand All @@ -224,14 +224,14 @@ impl<T: Owned> GenericPort<T> for PortSet<T> {
result
}

fn recv() -> T {
fn recv(&self) -> T {
self.try_recv().expect("port_set: endpoints closed")
}

}

impl<T: Owned> Peekable<T> for PortSet<T> {
pure fn peek() -> bool {
pure fn peek(&self) -> bool {
// It'd be nice to use self.port.each, but that version isn't
// pure.
for vec::each(self.ports) |p| {
Expand All @@ -245,7 +245,7 @@ impl<T: Owned> Peekable<T> for PortSet<T> {
pub type SharedChan<T> = unstable::Exclusive<Chan<T>>;

impl<T: Owned> GenericChan<T> for SharedChan<T> {
fn send(x: T) {
fn send(&self, x: T) {
let mut xx = Some(x);
do self.with_imm |chan| {
let mut x = None;
Expand All @@ -256,7 +256,7 @@ impl<T: Owned> GenericChan<T> for SharedChan<T> {
}

impl<T: Owned> GenericSmartChan<T> for SharedChan<T> {
fn try_send(x: T) -> bool {
fn try_send(&self, x: T) -> bool {
let mut xx = Some(x);
do self.with_imm |chan| {
let mut x = None;
Expand All @@ -274,27 +274,27 @@ pub fn SharedChan<T:Owned>(c: Chan<T>) -> SharedChan<T> {
/// Receive a message from one of two endpoints.
pub trait Select2<T: Owned, U: Owned> {
/// Receive a message or return `None` if a connection closes.
fn try_select() -> Either<Option<T>, Option<U>>;
fn try_select(&self) -> Either<Option<T>, Option<U>>;
/// Receive a message or fail if a connection closes.
fn select() -> Either<T, U>;
fn select(&self) -> Either<T, U>;
}

impl<T: Owned, U: Owned,
Left: Selectable + GenericPort<T>,
Right: Selectable + GenericPort<U>>
Select2<T, U> for (Left, Right) {

fn select() -> Either<T, U> {
match self {
fn select(&self) -> Either<T, U> {
match *self {
(ref lp, ref rp) => match select2i(lp, rp) {
Left(()) => Left (lp.recv()),
Right(()) => Right(rp.recv())
}
}
}

fn try_select() -> Either<Option<T>, Option<U>> {
match self {
fn try_select(&self) -> Either<Option<T>, Option<U>> {
match *self {
(ref lp, ref rp) => match select2i(lp, rp) {
Left(()) => Left (lp.try_recv()),
Right(()) => Right(rp.try_recv())
Expand Down
4 changes: 2 additions & 2 deletions src/libcore/condition.rs
Original file line number Diff line number Diff line change
Expand Up @@ -35,12 +35,12 @@ pub impl<T, U> Condition<T, U> {
}
}

fn raise(t: T) -> U {
fn raise(&self, t: T) -> U {
let msg = fmt!("Unhandled condition: %s: %?", self.name, t);
self.raise_default(t, || fail!(copy msg))
}

fn raise_default(t: T, default: &fn() -> U) -> U {
fn raise_default(&self, t: T, default: &fn() -> U) -> U {
unsafe {
match local_data_pop(self.key) {
None => {
Expand Down
2 changes: 1 addition & 1 deletion src/libcore/dlist.rs
Original file line number Diff line number Diff line change
Expand Up @@ -148,7 +148,7 @@ priv impl<T> DList<T> {
fail!(~"That node isn't on this dlist.")
}
}
fn make_mine(nobe: @mut DListNode<T>) {
fn make_mine(&self, nobe: @mut DListNode<T>) {
if nobe.prev.is_some() || nobe.next.is_some() || nobe.linked {
fail!(~"Cannot insert node that's already on a dlist!")
}
Expand Down
Loading