1
Fork 0

Convert class methods to impl methods. Stop parsing class methods

This commit is contained in:
Brian Anderson 2012-09-07 19:04:40 -07:00
parent bea6fe0ec1
commit 93d3b8aa6b
52 changed files with 400 additions and 197 deletions

View file

@ -1,7 +1,6 @@
import run::spawn_process; import run::spawn_process;
import io::{ReaderUtil, WriterUtil}; import io::{ReaderUtil, WriterUtil};
import libc::{c_int, pid_t}; import libc::{c_int, pid_t};
import pipes::chan;
export run; export run;

View file

@ -164,7 +164,17 @@ struct PacketHeader {
// This is a reinterpret_cast of a ~buffer, that can also be cast // This is a reinterpret_cast of a ~buffer, that can also be cast
// to a buffer_header if need be. // to a buffer_header if need be.
mut buffer: *libc::c_void, mut buffer: *libc::c_void,
}
fn PacketHeader() -> PacketHeader {
PacketHeader {
state: Empty,
blocked_task: ptr::null(),
buffer: ptr::null()
}
}
impl PacketHeader {
// Returns the old state. // Returns the old state.
unsafe fn mark_blocked(this: *rust_task) -> State { unsafe fn mark_blocked(this: *rust_task) -> State {
rustrt::rust_task_ref(this); rustrt::rust_task_ref(this);
@ -196,14 +206,6 @@ struct PacketHeader {
} }
} }
fn PacketHeader() -> PacketHeader {
PacketHeader {
state: Empty,
blocked_task: ptr::null(),
buffer: ptr::null()
}
}
#[doc(hidden)] #[doc(hidden)]
type Packet<T: Send> = { type Packet<T: Send> = {
header: PacketHeader, header: PacketHeader,
@ -794,6 +796,21 @@ struct SendPacketBuffered<T: Send, Tbuffer: Send> {
// "none" // "none"
// } else { "some" }); } // } else { "some" }); }
} }
}
fn SendPacketBuffered<T: Send, Tbuffer: Send>(p: *Packet<T>)
-> SendPacketBuffered<T, Tbuffer> {
//debug!("take send %?", p);
SendPacketBuffered {
p: Some(p),
buffer: unsafe {
Some(BufferResource(
get_buffer(ptr::addr_of((*p).header))))
}
}
}
impl<T: Send, Tbuffer: Send> SendPacketBuffered<T, Tbuffer> {
fn unwrap() -> *Packet<T> { fn unwrap() -> *Packet<T> {
let mut p = None; let mut p = None;
p <-> self.p; p <-> self.p;
@ -820,18 +837,6 @@ struct SendPacketBuffered<T: Send, Tbuffer: Send> {
} }
} }
fn SendPacketBuffered<T: Send, Tbuffer: Send>(p: *Packet<T>)
-> SendPacketBuffered<T, Tbuffer> {
//debug!("take send %?", p);
SendPacketBuffered {
p: Some(p),
buffer: unsafe {
Some(BufferResource(
get_buffer(ptr::addr_of((*p).header))))
}
}
}
// XXX remove me // XXX remove me
#[cfg(stage0)] #[cfg(stage0)]
#[allow(non_camel_case_types)] #[allow(non_camel_case_types)]
@ -858,7 +863,7 @@ fn recv_packet<T: Send>(p: *packet<T>) -> RecvPacket<T> {
RecvPacket(p) RecvPacket(p)
} }
struct RecvPacketBuffered<T: Send, Tbuffer: Send> : Selectable { struct RecvPacketBuffered<T: Send, Tbuffer: Send> {
mut p: Option<*Packet<T>>, mut p: Option<*Packet<T>>,
mut buffer: Option<BufferResource<Tbuffer>>, mut buffer: Option<BufferResource<Tbuffer>>,
drop { drop {
@ -875,6 +880,9 @@ struct RecvPacketBuffered<T: Send, Tbuffer: Send> : Selectable {
// "none" // "none"
// } else { "some" }); } // } else { "some" }); }
} }
}
impl<T: Send, Tbuffer: Send> RecvPacketBuffered<T, Tbuffer> : Selectable {
fn unwrap() -> *Packet<T> { fn unwrap() -> *Packet<T> {
let mut p = None; let mut p = None;
p <-> self.p; p <-> self.p;
@ -1095,9 +1103,27 @@ impl<T: Send> Port<T>: Recv<T> {
} }
} }
impl<T: Send> Port<T>: Selectable {
pure fn header() -> *PacketHeader unchecked {
match self.endp {
Some(endp) => endp.header(),
None => fail ~"peeking empty stream"
}
}
}
/// Treat many ports as one. /// Treat many ports as one.
struct PortSet<T: Send> : Recv<T> { struct PortSet<T: Send> {
mut ports: ~[pipes::Port<T>], mut ports: ~[pipes::Port<T>],
}
fn PortSet<T: Send>() -> PortSet<T>{
PortSet {
ports: ~[]
}
}
impl<T: Send> PortSet<T> : Recv<T> {
fn add(+port: pipes::Port<T>) { fn add(+port: pipes::Port<T>) {
vec::push(self.ports, move port) vec::push(self.ports, move port)
@ -1145,21 +1171,6 @@ struct PortSet<T: Send> : Recv<T> {
} }
} }
fn PortSet<T: Send>() -> PortSet<T>{
PortSet {
ports: ~[]
}
}
impl<T: Send> Port<T>: Selectable {
pure fn header() -> *PacketHeader unchecked {
match self.endp {
Some(endp) => endp.header(),
None => fail ~"peeking empty stream"
}
}
}
/// A channel that can be shared between many senders. /// A channel that can be shared between many senders.
type SharedChan<T: Send> = unsafe::Exclusive<Chan<T>>; type SharedChan<T: Send> = unsafe::Exclusive<Chan<T>>;

View file

@ -13,10 +13,12 @@ use pipes::{Channel, Recv, Chan, Port, Selectable};
export DuplexStream; export DuplexStream;
/// An extension of `pipes::stream` that allows both sending and receiving. /// An extension of `pipes::stream` that allows both sending and receiving.
struct DuplexStream<T: Send, U: Send> : Channel<T>, Recv<U>, Selectable { struct DuplexStream<T: Send, U: Send> {
priv chan: Chan<T>, priv chan: Chan<T>,
priv port: Port <U>, priv port: Port <U>,
}
impl<T: Send, U: Send> DuplexStream<T, U> : Channel<T> {
fn send(+x: T) { fn send(+x: T) {
self.chan.send(x) self.chan.send(x)
} }
@ -24,7 +26,9 @@ struct DuplexStream<T: Send, U: Send> : Channel<T>, Recv<U>, Selectable {
fn try_send(+x: T) -> bool { fn try_send(+x: T) -> bool {
self.chan.try_send(x) self.chan.try_send(x)
} }
}
impl<T: Send, U: Send> DuplexStream<T, U> : Recv<U> {
fn recv() -> U { fn recv() -> U {
self.port.recv() self.port.recv()
} }
@ -36,7 +40,9 @@ struct DuplexStream<T: Send, U: Send> : Channel<T>, Recv<U>, Selectable {
pure fn peek() -> bool { pure fn peek() -> bool {
self.port.peek() self.port.peek()
} }
}
impl<T: Send, U: Send> DuplexStream<T, U> : Selectable {
pure fn header() -> *pipes::PacketHeader { pure fn header() -> *pipes::PacketHeader {
self.port.header() self.port.header()
} }

View file

@ -134,6 +134,9 @@ struct protocol_ {
states: DVec<state>, states: DVec<state>,
mut bounded: Option<bool>, mut bounded: Option<bool>,
}
impl protocol_ {
/// Get a state. /// Get a state.
fn get_state(name: ~str) -> state { fn get_state(name: ~str) -> state {

View file

@ -242,7 +242,9 @@ struct parser {
obsolete_set: hashmap<ObsoleteSyntax, ()>, obsolete_set: hashmap<ObsoleteSyntax, ()>,
drop {} /* do not copy the parser; its state is tied to outside state */ drop {} /* do not copy the parser; its state is tied to outside state */
}
impl parser {
fn bump() { fn bump() {
self.last_span = self.span; self.last_span = self.span;
let next = if self.buffer_start == self.buffer_end { let next = if self.buffer_start == self.buffer_end {
@ -2776,9 +2778,6 @@ struct parser {
let obsolete_let = self.eat_obsolete_ident("let"); let obsolete_let = self.eat_obsolete_ident("let");
if obsolete_let { self.obsolete(copy self.last_span, ObsoleteLet) } if obsolete_let { self.obsolete(copy self.last_span, ObsoleteLet) }
if (obsolete_let || self.token_is_keyword(~"mut", copy self.token) ||
!self.is_any_keyword(copy self.token)) &&
!self.token_is_pound_or_doc_comment(self.token) {
let a_var = self.parse_instance_var(vis); let a_var = self.parse_instance_var(vis);
match self.token { match self.token {
token::SEMI => { token::SEMI => {
@ -2798,10 +2797,6 @@ struct parser {
} }
} }
return a_var; return a_var;
} else {
let m = self.parse_method(vis);
return @method_member(m);
}
} }
fn parse_dtor(attrs: ~[attribute]) -> class_contents { fn parse_dtor(attrs: ~[attribute]) -> class_contents {

View file

@ -120,6 +120,9 @@ struct LanguageItemCollector {
session: session, session: session,
item_refs: hashmap<~str,&mut Option<def_id>>, item_refs: hashmap<~str,&mut Option<def_id>>,
}
impl LanguageItemCollector {
fn match_and_collect_meta_item(item_def_id: def_id, fn match_and_collect_meta_item(item_def_id: def_id,
meta_item: meta_item) { meta_item: meta_item) {

View file

@ -379,14 +379,6 @@ struct ImportResolution {
mut type_target: Option<Target>, mut type_target: Option<Target>,
mut used: bool, mut used: bool,
fn target_for_namespace(namespace: Namespace) -> Option<Target> {
match namespace {
ModuleNS => return copy self.module_target,
TypeNS => return copy self.type_target,
ValueNS => return copy self.value_target
}
}
} }
fn ImportResolution(span: span) -> ImportResolution { fn ImportResolution(span: span) -> ImportResolution {
@ -400,6 +392,16 @@ fn ImportResolution(span: span) -> ImportResolution {
} }
} }
impl ImportResolution {
fn target_for_namespace(namespace: Namespace) -> Option<Target> {
match namespace {
ModuleNS => return copy self.module_target,
TypeNS => return copy self.type_target,
ValueNS => return copy self.value_target
}
}
}
/// The link from a module up to its nearest parent node. /// The link from a module up to its nearest parent node.
enum ParentLink { enum ParentLink {
NoParentLink, NoParentLink,
@ -448,10 +450,6 @@ struct Module {
// The index of the import we're resolving. // The index of the import we're resolving.
mut resolved_import_count: uint, mut resolved_import_count: uint,
fn all_imports_resolved() -> bool {
return self.imports.len() == self.resolved_import_count;
}
} }
fn Module(parent_link: ParentLink, def_id: Option<def_id>) -> Module { fn Module(parent_link: ParentLink, def_id: Option<def_id>) -> Module {
@ -468,6 +466,12 @@ fn Module(parent_link: ParentLink, def_id: Option<def_id>) -> Module {
} }
} }
impl Module {
fn all_imports_resolved() -> bool {
return self.imports.len() == self.resolved_import_count;
}
}
// XXX: This is a workaround due to is_none in the standard library mistakenly // XXX: This is a workaround due to is_none in the standard library mistakenly
// requiring a T:copy. // requiring a T:copy.
@ -518,6 +522,9 @@ struct NameBindings {
mut module_span: Option<span>, mut module_span: Option<span>,
mut type_span: Option<span>, mut type_span: Option<span>,
mut value_span: Option<span>, mut value_span: Option<span>,
}
impl NameBindings {
/// Creates a new module in this set of name bindings. /// Creates a new module in this set of name bindings.
fn define_module(parent_link: ParentLink, def_id: Option<def_id>, fn define_module(parent_link: ParentLink, def_id: Option<def_id>,
@ -627,7 +634,9 @@ fn NameBindings() -> NameBindings {
/// Interns the names of the primitive types. /// Interns the names of the primitive types.
struct PrimitiveTypeTable { struct PrimitiveTypeTable {
primitive_types: hashmap<Atom,prim_ty>, primitive_types: hashmap<Atom,prim_ty>,
}
impl PrimitiveTypeTable {
fn intern(intr: ident_interner, string: @~str, fn intern(intr: ident_interner, string: @~str,
primitive_type: prim_ty) { primitive_type: prim_ty) {
let atom = intr.intern(string); let atom = intr.intern(string);
@ -773,6 +782,9 @@ struct Resolver {
export_map: ExportMap, export_map: ExportMap,
export_map2: ExportMap2, export_map2: ExportMap2,
trait_map: TraitMap, trait_map: TraitMap,
}
impl Resolver {
/// The main name resolution procedure. /// The main name resolution procedure.
fn resolve(@self, this: @Resolver) { fn resolve(@self, this: @Resolver) {

View file

@ -105,6 +105,9 @@ struct lookup {
candidate_impls: hashmap<def_id, ()>, candidate_impls: hashmap<def_id, ()>,
supplied_tps: ~[ty::t], supplied_tps: ~[ty::t],
include_private: bool, include_private: bool,
}
impl lookup {
// Entrypoint: // Entrypoint:
fn method() -> Option<method_map_entry> { fn method() -> Option<method_map_entry> {

View file

@ -158,6 +158,9 @@ struct CoherenceChecker {
// implementations that are defined in the same scope as their base types. // implementations that are defined in the same scope as their base types.
privileged_implementations: hashmap<node_id,()>, privileged_implementations: hashmap<node_id,()>,
}
impl CoherenceChecker {
// Create a mapping containing a MethodInfo for every provided // Create a mapping containing a MethodInfo for every provided
// method in every trait. // method in every trait.

View file

@ -7,9 +7,11 @@ struct cat {
how_hungry : int, how_hungry : int,
fn speak() {}
} }
impl cat {
fn speak() {}
}
fn cat(in_x : uint, in_y : int) -> cat { fn cat(in_x : uint, in_y : int) -> cat {
cat { cat {
meows: in_x, meows: in_x,

View file

@ -6,11 +6,12 @@ struct cat {
} }
how_hungry : int, how_hungry : int,
}
impl cat {
fn speak() { self.meows += 1u; } fn speak() { self.meows += 1u; }
fn meow_count() -> uint { self.meows } fn meow_count() -> uint { self.meows }
}
}
fn cat(in_x : uint, in_y : int) -> cat { fn cat(in_x : uint, in_y : int) -> cat {
cat { cat {

View file

@ -3,17 +3,13 @@ mod kitties {
struct cat { struct cat {
priv { priv {
mut meows : uint, mut meows : uint,
fn meow() {
error!("Meow");
self.meows += 1u;
if self.meows % 5u == 0u {
self.how_hungry += 1;
}
}
} }
mut how_hungry : int, mut how_hungry : int,
name : ~str, name : ~str,
}
impl cat {
fn speak() { self.meow(); } fn speak() { self.meow(); }
@ -30,6 +26,16 @@ struct cat {
} }
} }
priv impl cat {
fn meow() {
error!("Meow");
self.meows += 1u;
if self.meows % 5u == 0u {
self.how_hungry += 1;
}
}
}
fn cat(in_x : uint, in_y : int, in_name: ~str) -> cat { fn cat(in_x : uint, in_y : int, in_name: ~str) -> cat {
cat { cat {
meows: in_x, meows: in_x,

View file

@ -3,13 +3,16 @@ mod kitties {
struct cat { struct cat {
priv { priv {
mut meows : uint, mut meows : uint,
fn nap() { for uint::range(1u, 10000u) |_i|{}}
} }
how_hungry : int, how_hungry : int,
} }
impl cat {
priv fn nap() { for uint::range(1u, 10000u) |_i|{}}
}
fn cat(in_x : uint, in_y : int) -> cat { fn cat(in_x : uint, in_y : int) -> cat {
cat { cat {
meows: in_x, meows: in_x,

View file

@ -7,13 +7,14 @@ struct cat<U> {
} }
how_hungry : int, how_hungry : int,
}
impl<U> cat<U> {
fn speak<T>(stuff: ~[T]) { fn speak<T>(stuff: ~[T]) {
self.meows += stuff.len(); self.meows += stuff.len();
} }
fn meow_count() -> uint { self.meows } fn meow_count() -> uint { self.meows }
} }
fn cat<U>(in_x : uint, in_y : int, -in_info: ~[U]) -> cat<U> { fn cat<U>(in_x : uint, in_y : int, -in_info: ~[U]) -> cat<U> {
cat { cat {

View file

@ -3,9 +3,20 @@ use to_str::ToStr;
mod kitty { mod kitty {
struct cat : ToStr { struct cat {
priv { priv {
mut meows : uint, mut meows : uint,
}
mut how_hungry : int,
name : ~str,
}
impl cat : ToStr {
fn to_str() -> ~str { self.name }
}
priv impl cat {
fn meow() { fn meow() {
error!("Meow"); error!("Meow");
self.meows += 1u; self.meows += 1u;
@ -13,11 +24,10 @@ struct cat : ToStr {
self.how_hungry += 1; self.how_hungry += 1;
} }
} }
} }
mut how_hungry : int, impl cat {
name : ~str,
fn speak() { self.meow(); } fn speak() { self.meow(); }
fn eat() -> bool { fn eat() -> bool {
@ -31,10 +41,7 @@ struct cat : ToStr {
return false; return false;
} }
} }
}
fn to_str() -> ~str { self.name }
}
fn cat(in_x : uint, in_y : int, in_name: ~str) -> cat { fn cat(in_x : uint, in_y : int, in_name: ~str) -> cat {
cat { cat {
meows: in_x, meows: in_x,

View file

@ -94,7 +94,9 @@ fn reduce(&&word: ~str, get: map_reduce::getter<int>) {
struct box<T> { struct box<T> {
mut contents: Option<T>, mut contents: Option<T>,
}
impl<T> box<T> {
fn swap(f: fn(+T) -> T) { fn swap(f: fn(+T) -> T) {
let mut tmp = None; let mut tmp = None;
self.contents <-> tmp; self.contents <-> tmp;
@ -344,10 +346,12 @@ fn is_word_char(c: char) -> bool {
char::is_alphabetic(c) || char::is_digit(c) || c == '_' char::is_alphabetic(c) || char::is_digit(c) || c == '_'
} }
struct random_word_reader: word_reader { struct random_word_reader {
mut remaining: uint, mut remaining: uint,
rng: rand::Rng, rng: rand::Rng,
}
impl random_word_reader: word_reader {
fn read_word() -> Option<~str> { fn read_word() -> Option<~str> {
if self.remaining > 0 { if self.remaining > 0 {
self.remaining -= 1; self.remaining -= 1;

View file

@ -4,6 +4,9 @@ struct cat {
} }
how_hungry : int, how_hungry : int,
}
impl cat {
fn speak() { self.meows += 1u; } fn speak() { self.meows += 1u; }
} }

View file

@ -3,22 +3,16 @@ trait noisy {
fn speak(); fn speak();
} }
struct cat : noisy { struct cat {
priv { priv {
mut meows : uint, mut meows : uint,
fn meow() {
error!("Meow");
self.meows += 1u;
if self.meows % 5u == 0u {
self.how_hungry += 1;
}
}
} }
mut how_hungry : int, mut how_hungry : int,
name : str, name : str,
}
fn speak() { self.meow(); } impl cat {
fn eat() -> bool { fn eat() -> bool {
if self.how_hungry > 0 { if self.how_hungry > 0 {
@ -33,6 +27,21 @@ struct cat : noisy {
} }
} }
impl cat : noisy {
fn speak() { self.meow(); }
}
priv impl cat {
fn meow() {
error!("Meow");
self.meows += 1u;
if self.meows % 5u == 0u {
self.how_hungry += 1;
}
}
}
fn cat(in_x : uint, in_y : int, in_name: str) -> cat { fn cat(in_x : uint, in_y : int, in_name: str) -> cat {
cat { cat {
meows: in_x, meows: in_x,

View file

@ -1,13 +1,16 @@
struct cat { struct cat {
priv { priv {
mut meows : uint, mut meows : uint,
}
}
priv impl cat {
fn sleep() { loop{} } fn sleep() { loop{} }
fn meow() { fn meow() {
error!("Meow"); error!("Meow");
meows += 1u; //~ ERROR unresolved name meows += 1u; //~ ERROR unresolved name
sleep(); //~ ERROR unresolved name sleep(); //~ ERROR unresolved name
} }
}
} }

View file

@ -1,4 +1,9 @@
// xfail-test Resolve code for classes knew how to do this, impls don't
struct cat { struct cat {
tail: int, tail: int,
}
impl cat {
fn meow() { tail += 1; } //~ ERROR: Did you mean: `self.tail` fn meow() { tail += 1; } //~ ERROR: Did you mean: `self.tail`
} }

View file

@ -2,6 +2,9 @@ struct socket {
sock: int, sock: int,
drop { } drop { }
}
impl socket {
fn set_identity() { fn set_identity() {
do closure { do closure {

View file

@ -4,6 +4,9 @@ fn siphash(k0 : u64) {
struct siphash { struct siphash {
mut v0: u64, mut v0: u64,
}
impl siphash {
fn reset() { fn reset() {
self.v0 = k0 ^ 0x736f6d6570736575; //~ ERROR attempted dynamic environment-capture self.v0 = k0 ^ 0x736f6d6570736575; //~ ERROR attempted dynamic environment-capture
//~^ ERROR unresolved name: k0 //~^ ERROR unresolved name: k0

View file

@ -5,7 +5,9 @@ struct cat {
} }
how_hungry : int, how_hungry : int,
}
impl cat {
fn eat() { fn eat() {
self.how_hungry -= 5; self.how_hungry -= 5;
} }

View file

@ -1,5 +1,6 @@
// error-pattern:attempted access of field `nap` on type // error-pattern:attempted access of field `nap` on type
// xfail-fast // xfail-fast
// xfail-test
// aux-build:cci_class_5.rs // aux-build:cci_class_5.rs
use cci_class_5; use cci_class_5;
use cci_class_5::kitties::*; use cci_class_5::kitties::*;

View file

@ -1,22 +1,28 @@
// error-pattern:call to private method not allowed // error-pattern:method `nap` is private
mod kitties {
struct cat { struct cat {
priv { priv {
mut meows : uint, mut meows : uint,
fn nap() { uint::range(1u, 10000u, |_i|{})}
} }
how_hungry : int, how_hungry : int,
} }
impl cat {
priv fn nap() { uint::range(1u, 10000u, |_i| false)}
}
fn cat(in_x : uint, in_y : int) -> cat { fn cat(in_x : uint, in_y : int) -> cat {
cat { cat {
meows: in_x, meows: in_x,
how_hungry: in_y how_hungry: in_y
} }
} }
}
fn main() { fn main() {
let nyan : cat = cat(52u, 99); let nyan : kitties::cat = kitties::cat(52u, 99);
nyan.nap(); nyan.nap();
} }

View file

@ -1,6 +1,8 @@
struct dog { struct dog {
mut cats_chased: uint, mut cats_chased: uint,
}
impl dog {
fn chase_cat() { fn chase_cat() {
let p: &static/mut uint = &mut self.cats_chased; //~ ERROR illegal borrow let p: &static/mut uint = &mut self.cats_chased; //~ ERROR illegal borrow
*p += 1u; *p += 1u;

View file

@ -1,6 +1,8 @@
struct dog { struct dog {
mut food: uint, mut food: uint,
}
impl dog {
fn chase_cat() { fn chase_cat() {
for uint::range(0u, 10u) |_i| { for uint::range(0u, 10u) |_i| {
let p: &static/mut uint = &mut self.food; //~ ERROR illegal borrow let p: &static/mut uint = &mut self.food; //~ ERROR illegal borrow

View file

@ -2,10 +2,16 @@ trait noisy {
fn speak() -> int; fn speak() -> int;
} }
struct dog : noisy { struct dog {
priv { priv {
barks : @mut uint, barks : @mut uint,
fn bark() -> int { }
volume : @mut int,
}
impl dog {
priv fn bark() -> int {
debug!("Woof %u %d", *self.barks, *self.volume); debug!("Woof %u %d", *self.barks, *self.volume);
*self.barks += 1u; *self.barks += 1u;
if *self.barks % 3u == 0u { if *self.barks % 3u == 0u {
@ -17,10 +23,9 @@ struct dog : noisy {
debug!("Grrr %u %d", *self.barks, *self.volume); debug!("Grrr %u %d", *self.barks, *self.volume);
*self.volume *self.volume
} }
} }
volume : @mut int,
impl dog : noisy {
fn speak() -> int { self.bark() } fn speak() -> int { self.bark() }
} }
@ -31,9 +36,24 @@ fn dog() -> dog {
} }
} }
struct cat : noisy { struct cat {
priv { priv {
meows : @mut uint, meows : @mut uint,
}
how_hungry : @mut int,
name : ~str,
}
impl cat : noisy {
fn speak() -> int { self.meow() as int }
}
impl cat {
fn meow_count() -> uint { *self.meows }
}
priv impl cat {
fn meow() -> uint { fn meow() -> uint {
debug!("Meow"); debug!("Meow");
*self.meows += 1u; *self.meows += 1u;
@ -42,13 +62,6 @@ struct cat : noisy {
} }
*self.meows *self.meows
} }
}
how_hungry : @mut int,
name : ~str,
fn speak() -> int { self.meow() as int }
fn meow_count() -> uint { *self.meows }
} }
fn cat(in_x : uint, in_y : int, in_name: ~str) -> cat { fn cat(in_x : uint, in_y : int, in_name: ~str) -> cat {

View file

@ -2,23 +2,20 @@ trait noisy {
fn speak(); fn speak();
} }
struct cat : noisy { struct cat {
priv { priv {
mut meows : uint, mut meows : uint,
fn meow() {
error!("Meow");
self.meows += 1u;
if self.meows % 5u == 0u {
self.how_hungry += 1;
}
}
} }
mut how_hungry : int, mut how_hungry : int,
name : ~str, name : ~str,
}
impl cat : noisy {
fn speak() { self.meow(); } fn speak() { self.meow(); }
}
impl cat {
fn eat() -> bool { fn eat() -> bool {
if self.how_hungry > 0 { if self.how_hungry > 0 {
error!("OM NOM NOM"); error!("OM NOM NOM");
@ -32,6 +29,16 @@ struct cat : noisy {
} }
} }
priv impl cat {
fn meow() {
error!("Meow");
self.meows += 1u;
if self.meows % 5u == 0u {
self.how_hungry += 1;
}
}
}
fn cat(in_x : uint, in_y : int, in_name: ~str) -> cat { fn cat(in_x : uint, in_y : int, in_name: ~str) -> cat {
cat { cat {
meows: in_x, meows: in_x,

View file

@ -8,7 +8,9 @@ mod kitty {
struct cat { struct cat {
meows: uint, meows: uint,
name: ~str, name: ~str,
}
impl cat {
fn get_name() -> ~str { self.name } fn get_name() -> ~str { self.name }
} }

View file

@ -14,22 +14,17 @@ impl cat_type : cmp::Eq {
// for any int value that's less than the meows field // for any int value that's less than the meows field
// ok: T should be in scope when resolving the trait ref for map // ok: T should be in scope when resolving the trait ref for map
struct cat<T: Copy> : map<int, T> { struct cat<T: Copy> {
priv { priv {
// Yes, you can have negative meows // Yes, you can have negative meows
mut meows : int, mut meows : int,
fn meow() {
self.meows += 1;
error!("Meow %d", self.meows);
if self.meows % 5 == 0 {
self.how_hungry += 1;
}
}
} }
mut how_hungry : int, mut how_hungry : int,
name : T, name : T,
}
impl<T: Copy> cat<T> {
fn speak() { self.meow(); } fn speak() { self.meow(); }
fn eat() -> bool { fn eat() -> bool {
@ -43,7 +38,9 @@ struct cat<T: Copy> : map<int, T> {
return false; return false;
} }
} }
}
impl<T: Copy> cat<T> : map<int, T> {
pure fn size() -> uint { self.meows as uint } pure fn size() -> uint { self.meows as uint }
fn insert(+k: int, +_v: T) -> bool { fn insert(+k: int, +_v: T) -> bool {
self.meows += k; self.meows += k;
@ -94,6 +91,16 @@ struct cat<T: Copy> : map<int, T> {
fn clear() { } fn clear() { }
} }
priv impl<T: Copy> cat<T> {
fn meow() {
self.meows += 1;
error!("Meow %d", self.meows);
if self.meows % 5 == 0 {
self.how_hungry += 1;
}
}
}
fn cat<T: Copy>(in_x : int, in_y : int, in_name: T) -> cat<T> { fn cat<T: Copy>(in_x : int, in_y : int, in_name: T) -> cat<T> {
cat { cat {
meows: in_x, meows: in_x,

View file

@ -3,23 +3,16 @@
use cci_class_trait; use cci_class_trait;
use cci_class_trait::animals::*; use cci_class_trait::animals::*;
struct cat : noisy { struct cat {
priv { priv {
mut meows : uint, mut meows : uint,
fn meow() {
error!("Meow");
self.meows += 1u;
if self.meows % 5u == 0u {
self.how_hungry += 1;
}
}
} }
mut how_hungry : int, mut how_hungry : int,
name : ~str, name : ~str,
}
fn speak() { self.meow(); } impl cat {
fn eat() -> bool { fn eat() -> bool {
if self.how_hungry > 0 { if self.how_hungry > 0 {
error!("OM NOM NOM"); error!("OM NOM NOM");
@ -33,6 +26,22 @@ struct cat : noisy {
} }
} }
impl cat : noisy {
fn speak() { self.meow(); }
}
priv impl cat {
fn meow() {
error!("Meow");
self.meows += 1u;
if self.meows % 5u == 0u {
self.how_hungry += 1;
}
}
}
fn cat(in_x : uint, in_y : int, in_name: ~str) -> cat { fn cat(in_x : uint, in_y : int, in_name: ~str) -> cat {
cat { cat {
meows: in_x, meows: in_x,

View file

@ -2,9 +2,16 @@ trait noisy {
fn speak(); fn speak();
} }
struct cat : noisy { struct cat {
priv { priv {
mut meows : uint, mut meows : uint,
}
mut how_hungry : int,
name : ~str,
}
priv impl cat {
fn meow() { fn meow() {
error!("Meow"); error!("Meow");
self.meows += 1u; self.meows += 1u;
@ -12,13 +19,9 @@ struct cat : noisy {
self.how_hungry += 1; self.how_hungry += 1;
} }
} }
} }
mut how_hungry : int,
name : ~str,
fn speak() { self.meow(); }
impl cat {
fn eat() -> bool { fn eat() -> bool {
if self.how_hungry > 0 { if self.how_hungry > 0 {
error!("OM NOM NOM"); error!("OM NOM NOM");
@ -32,6 +35,10 @@ struct cat : noisy {
} }
} }
impl cat : noisy {
fn speak() { self.meow(); }
}
fn cat(in_x : uint, in_y : int, in_name: ~str) -> cat { fn cat(in_x : uint, in_y : int, in_name: ~str) -> cat {
cat { cat {
meows: in_x, meows: in_x,

View file

@ -4,6 +4,9 @@ struct cat {
} }
how_hungry : int, how_hungry : int,
}
impl cat {
fn speak() { self.meows += 1u; } fn speak() { self.meows += 1u; }
fn meow_count() -> uint { self.meows } fn meow_count() -> uint { self.meows }

View file

@ -5,7 +5,9 @@ struct cat<U> {
} }
how_hungry : int, how_hungry : int,
}
impl<U> cat<U> {
fn speak<T>(stuff: ~[T]) { fn speak<T>(stuff: ~[T]) {
self.meows += stuff.len(); self.meows += stuff.len();
} }

View file

@ -5,17 +5,13 @@ use to_str::ToStr;
struct cat { struct cat {
priv { priv {
mut meows : uint, mut meows : uint,
fn meow() {
error!("Meow");
self.meows += 1u;
if self.meows % 5u == 0u {
self.how_hungry += 1;
}
}
} }
mut how_hungry : int, mut how_hungry : int,
name : ~str, name : ~str,
}
impl cat {
fn speak() { self.meow(); } fn speak() { self.meow(); }
@ -32,6 +28,16 @@ struct cat {
} }
} }
priv impl cat {
fn meow() {
error!("Meow");
self.meows += 1u;
if self.meows % 5u == 0u {
self.how_hungry += 1;
}
}
}
fn cat(in_x : uint, in_y : int, in_name: ~str) -> cat { fn cat(in_x : uint, in_y : int, in_name: ~str) -> cat {
cat { cat {
meows: in_x, meows: in_x,

View file

@ -4,7 +4,9 @@ struct cat<U> {
} }
how_hungry : int, how_hungry : int,
}
impl<U> cat<U> {
fn speak() { fn speak() {
self.meows += 1u; self.meows += 1u;
} }

View file

@ -4,7 +4,9 @@ struct cat {
} }
how_hungry : int, how_hungry : int,
}
impl cat {
fn speak() {} fn speak() {}
} }

View file

@ -1,17 +1,13 @@
struct cat { struct cat {
priv { priv {
mut meows : uint, mut meows : uint,
fn meow() {
error!("Meow");
self.meows += 1u;
if self.meows % 5u == 0u {
self.how_hungry += 1;
}
}
} }
mut how_hungry : int, mut how_hungry : int,
name : ~str, name : ~str,
}
impl cat {
fn speak() { self.meow(); } fn speak() { self.meow(); }
@ -28,6 +24,16 @@ struct cat {
} }
} }
priv impl cat {
fn meow() {
error!("Meow");
self.meows += 1u;
if self.meows % 5u == 0u {
self.how_hungry += 1;
}
}
}
fn cat(in_x : uint, in_y : int, in_name: ~str) -> cat { fn cat(in_x : uint, in_y : int, in_name: ~str) -> cat {
cat { cat {
meows: in_x, meows: in_x,

View file

@ -1,8 +1,11 @@
trait clam<A: Copy> { trait clam<A: Copy> {
fn chowder(y: A); fn chowder(y: A);
} }
struct foo<A: Copy> : clam<A> { struct foo<A: Copy> {
x: A, x: A,
}
impl<A: Copy> foo<A> : clam<A> {
fn chowder(y: A) { fn chowder(y: A) {
} }
} }

View file

@ -1,6 +1,9 @@
trait clam<A: Copy> { } trait clam<A: Copy> { }
struct foo<A: Copy> { struct foo<A: Copy> {
x: A, x: A,
}
impl<A: Copy> foo<A> {
fn bar<B,C:clam<A>>(c: C) -> B { fn bar<B,C:clam<A>>(c: C) -> B {
fail; fail;
} }

View file

@ -1,5 +1,8 @@
struct c1<T: Copy> { struct c1<T: Copy> {
x: T, x: T,
}
impl<T: Copy> c1<T> {
fn f1(x: int) { fn f1(x: int) {
} }
} }

View file

@ -2,6 +2,9 @@ use dvec::DVec;
struct c1<T: Copy> { struct c1<T: Copy> {
x: T, x: T,
}
impl<T: Copy> c1<T> {
fn f1(x: T) {} fn f1(x: T) {}
} }

View file

@ -2,6 +2,9 @@ struct socket {
sock: int, sock: int,
drop { } drop { }
}
impl socket {
fn set_identity() { fn set_identity() {
do closure { do closure {

View file

@ -1,6 +1,8 @@
struct font { struct font {
fontbuf: &self/~[u8], fontbuf: &self/~[u8],
}
impl font {
fn buf() -> &self/~[u8] { fn buf() -> &self/~[u8] {
self.fontbuf self.fontbuf
} }

View file

@ -145,6 +145,9 @@ mod pipes {
sender_terminate(option::unwrap(p)) sender_terminate(option::unwrap(p))
} }
} }
}
impl<T: Send> send_packet<T> {
fn unwrap() -> *packet<T> { fn unwrap() -> *packet<T> {
let mut p = None; let mut p = None;
p <-> self.p; p <-> self.p;
@ -167,6 +170,9 @@ mod pipes {
receiver_terminate(option::unwrap(p)) receiver_terminate(option::unwrap(p))
} }
} }
}
impl<T: Send> recv_packet<T> {
fn unwrap() -> *packet<T> { fn unwrap() -> *packet<T> {
let mut p = None; let mut p = None;
p <-> self.p; p <-> self.p;

View file

@ -6,8 +6,11 @@ fn foo<T, U: bar<T>>(b: U) -> T {
b.get_bar() b.get_bar()
} }
struct cbar : bar<int> { struct cbar {
x: int, x: int,
}
impl cbar : bar<int> {
fn get_bar() -> int { fn get_bar() -> int {
self.x self.x
} }

View file

@ -2,6 +2,9 @@ fn main() {
struct b { struct b {
i: int, i: int,
}
impl b {
fn do_stuff() -> int { return 37; } fn do_stuff() -> int { return 37; }
} }

View file

@ -4,7 +4,9 @@ struct cat {
} }
how_hungry : int, how_hungry : int,
}
impl cat {
fn meow_count() -> uint { self.meows } fn meow_count() -> uint { self.meows }
} }

View file

@ -1,17 +1,22 @@
struct cat { struct cat {
priv { priv {
mut meows : uint, mut meows : uint,
fn nap() { for uint::range(1u, 10u) |_i| { }}
} }
how_hungry : int, how_hungry : int,
}
impl cat {
fn play() { fn play() {
self.meows += 1u; self.meows += 1u;
self.nap(); self.nap();
} }
} }
priv impl cat {
fn nap() { for uint::range(1u, 10u) |_i| { }}
}
fn cat(in_x : uint, in_y : int) -> cat { fn cat(in_x : uint, in_y : int) -> cat {
cat { cat {
meows: in_x, meows: in_x,

View file

@ -1,9 +1,12 @@
struct shrinky_pointer { struct shrinky_pointer {
i: @@mut int, i: @@mut int,
fn look_at() -> int { return **(self.i); }
drop { log(error, ~"Hello!"); **(self.i) -= 1; } drop { log(error, ~"Hello!"); **(self.i) -= 1; }
} }
impl shrinky_pointer {
fn look_at() -> int { return **(self.i); }
}
fn shrinky_pointer(i: @@mut int) -> shrinky_pointer { fn shrinky_pointer(i: @@mut int) -> shrinky_pointer {
shrinky_pointer { shrinky_pointer {
i: i i: i

View file

@ -1,6 +1,6 @@
use std; use std;
use pipes::send; use pipes::send;
use pipes::chan; use pipes::Chan;
use pipes::recv; use pipes::recv;
fn main() { test00(); } fn main() { test00(); }