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 io::{ReaderUtil, WriterUtil};
import libc::{c_int, pid_t};
import pipes::chan;
export run;

View File

@ -164,7 +164,17 @@ struct PacketHeader {
// This is a reinterpret_cast of a ~buffer, that can also be cast
// to a buffer_header if need be.
mut buffer: *libc::c_void,
}
fn PacketHeader() -> PacketHeader {
PacketHeader {
state: Empty,
blocked_task: ptr::null(),
buffer: ptr::null()
}
}
impl PacketHeader {
// Returns the old state.
unsafe fn mark_blocked(this: *rust_task) -> State {
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)]
type Packet<T: Send> = {
header: PacketHeader,
@ -794,6 +796,21 @@ struct SendPacketBuffered<T: Send, Tbuffer: Send> {
// "none"
// } 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> {
let mut p = None;
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
#[cfg(stage0)]
#[allow(non_camel_case_types)]
@ -858,7 +863,7 @@ fn recv_packet<T: Send>(p: *packet<T>) -> RecvPacket<T> {
RecvPacket(p)
}
struct RecvPacketBuffered<T: Send, Tbuffer: Send> : Selectable {
struct RecvPacketBuffered<T: Send, Tbuffer: Send> {
mut p: Option<*Packet<T>>,
mut buffer: Option<BufferResource<Tbuffer>>,
drop {
@ -875,6 +880,9 @@ struct RecvPacketBuffered<T: Send, Tbuffer: Send> : Selectable {
// "none"
// } else { "some" }); }
}
}
impl<T: Send, Tbuffer: Send> RecvPacketBuffered<T, Tbuffer> : Selectable {
fn unwrap() -> *Packet<T> {
let mut p = None;
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.
struct PortSet<T: Send> : Recv<T> {
struct PortSet<T: Send> {
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>) {
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.
type SharedChan<T: Send> = unsafe::Exclusive<Chan<T>>;

View File

@ -13,10 +13,12 @@ use pipes::{Channel, Recv, Chan, Port, Selectable};
export DuplexStream;
/// 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 port: Port <U>,
}
impl<T: Send, U: Send> DuplexStream<T, U> : Channel<T> {
fn send(+x: T) {
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 {
self.chan.try_send(x)
}
}
impl<T: Send, U: Send> DuplexStream<T, U> : Recv<U> {
fn recv() -> U {
self.port.recv()
}
@ -36,7 +40,9 @@ struct DuplexStream<T: Send, U: Send> : Channel<T>, Recv<U>, Selectable {
pure fn peek() -> bool {
self.port.peek()
}
}
impl<T: Send, U: Send> DuplexStream<T, U> : Selectable {
pure fn header() -> *pipes::PacketHeader {
self.port.header()
}

View File

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

View File

@ -242,7 +242,9 @@ struct parser {
obsolete_set: hashmap<ObsoleteSyntax, ()>,
drop {} /* do not copy the parser; its state is tied to outside state */
}
impl parser {
fn bump() {
self.last_span = self.span;
let next = if self.buffer_start == self.buffer_end {
@ -2776,32 +2778,25 @@ struct parser {
let obsolete_let = self.eat_obsolete_ident("let");
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);
match self.token {
token::SEMI => {
self.obsolete(copy self.span, ObsoleteFieldTerminator);
self.bump();
}
token::COMMA => {
self.bump();
}
token::RBRACE => {}
_ => {
self.span_fatal(copy self.span,
fmt!("expected `;`, `,`, or '}' but \
found `%s`",
token_to_str(self.reader,
self.token)));
}
}
return a_var;
} else {
let m = self.parse_method(vis);
return @method_member(m);
let a_var = self.parse_instance_var(vis);
match self.token {
token::SEMI => {
self.obsolete(copy self.span, ObsoleteFieldTerminator);
self.bump();
}
token::COMMA => {
self.bump();
}
token::RBRACE => {}
_ => {
self.span_fatal(copy self.span,
fmt!("expected `;`, `,`, or '}' but \
found `%s`",
token_to_str(self.reader,
self.token)));
}
}
return a_var;
}
fn parse_dtor(attrs: ~[attribute]) -> class_contents {

View File

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

View File

@ -379,14 +379,6 @@ struct ImportResolution {
mut type_target: Option<Target>,
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 {
@ -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.
enum ParentLink {
NoParentLink,
@ -448,10 +450,6 @@ struct Module {
// The index of the import we're resolving.
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 {
@ -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
// requiring a T:copy.
@ -518,6 +522,9 @@ struct NameBindings {
mut module_span: Option<span>,
mut type_span: Option<span>,
mut value_span: Option<span>,
}
impl NameBindings {
/// Creates a new module in this set of name bindings.
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.
struct PrimitiveTypeTable {
primitive_types: hashmap<Atom,prim_ty>,
}
impl PrimitiveTypeTable {
fn intern(intr: ident_interner, string: @~str,
primitive_type: prim_ty) {
let atom = intr.intern(string);
@ -773,6 +782,9 @@ struct Resolver {
export_map: ExportMap,
export_map2: ExportMap2,
trait_map: TraitMap,
}
impl Resolver {
/// The main name resolution procedure.
fn resolve(@self, this: @Resolver) {

View File

@ -105,6 +105,9 @@ struct lookup {
candidate_impls: hashmap<def_id, ()>,
supplied_tps: ~[ty::t],
include_private: bool,
}
impl lookup {
// Entrypoint:
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.
privileged_implementations: hashmap<node_id,()>,
}
impl CoherenceChecker {
// Create a mapping containing a MethodInfo for every provided
// method in every trait.

View File

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

View File

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

View File

@ -3,17 +3,13 @@ mod kitties {
struct cat {
priv {
mut meows : uint,
fn meow() {
error!("Meow");
self.meows += 1u;
if self.meows % 5u == 0u {
self.how_hungry += 1;
}
}
}
mut how_hungry : int,
name : ~str,
}
impl cat {
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 {
cat {
meows: in_x,

View File

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

View File

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

View File

@ -3,38 +3,45 @@ use to_str::ToStr;
mod kitty {
struct cat : ToStr {
struct cat {
priv {
mut meows : uint,
fn meow() {
error!("Meow");
self.meows += 1u;
if self.meows % 5u == 0u {
self.how_hungry += 1;
}
}
}
mut how_hungry : int,
name : ~str,
fn speak() { self.meow(); }
fn eat() -> bool {
if self.how_hungry > 0 {
error!("OM NOM NOM");
self.how_hungry -= 2;
return true;
}
else {
error!("Not hungry!");
return false;
}
}
fn to_str() -> ~str { self.name }
}
impl cat : ToStr {
fn to_str() -> ~str { self.name }
}
priv impl cat {
fn meow() {
error!("Meow");
self.meows += 1u;
if self.meows % 5u == 0u {
self.how_hungry += 1;
}
}
}
impl cat {
fn speak() { self.meow(); }
fn eat() -> bool {
if self.how_hungry > 0 {
error!("OM NOM NOM");
self.how_hungry -= 2;
return true;
}
else {
error!("Not hungry!");
return false;
}
}
}
fn cat(in_x : uint, in_y : int, in_name: ~str) -> cat {
cat {
meows: in_x,

View File

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

View File

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

View File

@ -3,22 +3,16 @@ trait noisy {
fn speak();
}
struct cat : noisy {
struct cat {
priv {
mut meows : uint,
fn meow() {
error!("Meow");
self.meows += 1u;
if self.meows % 5u == 0u {
self.how_hungry += 1;
}
}
}
mut how_hungry : int,
name : str,
}
fn speak() { self.meow(); }
impl cat {
fn eat() -> bool {
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 {
cat {
meows: in_x,

View File

@ -1,13 +1,16 @@
struct cat {
priv {
mut meows : uint,
}
}
priv impl cat {
fn sleep() { loop{} }
fn meow() {
error!("Meow");
meows += 1u; //~ 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 {
tail: int,
}
impl cat {
fn meow() { tail += 1; } //~ ERROR: Did you mean: `self.tail`
}

View File

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

View File

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

View File

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

View File

@ -1,5 +1,6 @@
// error-pattern:attempted access of field `nap` on type
// xfail-fast
// xfail-test
// aux-build:cci_class_5.rs
use cci_class_5;
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 {
priv {
mut meows : uint,
fn nap() { uint::range(1u, 10000u, |_i|{})}
}
how_hungry : int,
}
impl cat {
priv fn nap() { uint::range(1u, 10000u, |_i| false)}
}
fn cat(in_x : uint, in_y : int) -> cat {
cat {
meows: in_x,
how_hungry: in_y
}
}
}
fn main() {
let nyan : cat = cat(52u, 99);
let nyan : kitties::cat = kitties::cat(52u, 99);
nyan.nap();
}

View File

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

View File

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

View File

@ -2,10 +2,16 @@ trait noisy {
fn speak() -> int;
}
struct dog : noisy {
struct dog {
priv {
barks : @mut uint,
fn bark() -> int {
}
volume : @mut int,
}
impl dog {
priv fn bark() -> int {
debug!("Woof %u %d", *self.barks, *self.volume);
*self.barks += 1u;
if *self.barks % 3u == 0u {
@ -17,10 +23,9 @@ struct dog : noisy {
debug!("Grrr %u %d", *self.barks, *self.volume);
*self.volume
}
}
volume : @mut int,
}
impl dog : noisy {
fn speak() -> int { self.bark() }
}
@ -31,9 +36,24 @@ fn dog() -> dog {
}
}
struct cat : noisy {
struct cat {
priv {
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 {
debug!("Meow");
*self.meows += 1u;
@ -42,13 +62,6 @@ struct cat : noisy {
}
*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 {

View File

@ -2,23 +2,20 @@ trait noisy {
fn speak();
}
struct cat : noisy {
struct cat {
priv {
mut meows : uint,
fn meow() {
error!("Meow");
self.meows += 1u;
if self.meows % 5u == 0u {
self.how_hungry += 1;
}
}
}
mut how_hungry : int,
name : ~str,
}
impl cat : noisy {
fn speak() { self.meow(); }
}
impl cat {
fn eat() -> bool {
if self.how_hungry > 0 {
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 {
cat {
meows: in_x,

View File

@ -8,7 +8,9 @@ mod kitty {
struct cat {
meows: uint,
name: ~str,
}
impl cat {
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
// 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 {
// Yes, you can have negative meows
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,
name : T,
}
impl<T: Copy> cat<T> {
fn speak() { self.meow(); }
fn eat() -> bool {
@ -43,7 +38,9 @@ struct cat<T: Copy> : map<int, T> {
return false;
}
}
}
impl<T: Copy> cat<T> : map<int, T> {
pure fn size() -> uint { self.meows as uint }
fn insert(+k: int, +_v: T) -> bool {
self.meows += k;
@ -94,6 +91,16 @@ struct cat<T: Copy> : map<int, T> {
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> {
cat {
meows: in_x,

View File

@ -3,23 +3,16 @@
use cci_class_trait;
use cci_class_trait::animals::*;
struct cat : noisy {
struct cat {
priv {
mut meows : uint,
fn meow() {
error!("Meow");
self.meows += 1u;
if self.meows % 5u == 0u {
self.how_hungry += 1;
}
}
}
mut how_hungry : int,
name : ~str,
}
fn speak() { self.meow(); }
impl cat {
fn eat() -> bool {
if self.how_hungry > 0 {
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 {
cat {
meows: in_x,

View File

@ -2,9 +2,16 @@ trait noisy {
fn speak();
}
struct cat : noisy {
struct cat {
priv {
mut meows : uint,
}
mut how_hungry : int,
name : ~str,
}
priv impl cat {
fn meow() {
error!("Meow");
self.meows += 1u;
@ -12,13 +19,9 @@ struct cat : noisy {
self.how_hungry += 1;
}
}
}
mut how_hungry : int,
name : ~str,
fn speak() { self.meow(); }
}
impl cat {
fn eat() -> bool {
if self.how_hungry > 0 {
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 {
cat {
meows: in_x,

View File

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

View File

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

View File

@ -5,17 +5,13 @@ use to_str::ToStr;
struct cat {
priv {
mut meows : uint,
fn meow() {
error!("Meow");
self.meows += 1u;
if self.meows % 5u == 0u {
self.how_hungry += 1;
}
}
}
mut how_hungry : int,
name : ~str,
}
impl cat {
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 {
cat {
meows: in_x,

View File

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

View File

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

View File

@ -1,17 +1,13 @@
struct cat {
priv {
mut meows : uint,
fn meow() {
error!("Meow");
self.meows += 1u;
if self.meows % 5u == 0u {
self.how_hungry += 1;
}
}
}
mut how_hungry : int,
name : ~str,
}
impl cat {
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 {
cat {
meows: in_x,

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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

View File

@ -1,9 +1,12 @@
struct shrinky_pointer {
i: @@mut int,
fn look_at() -> int { return **(self.i); }
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 {
shrinky_pointer {
i: i

View File

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