test: Fix a bunch of run-pass tests. rs=bustage
This commit is contained in:
parent
4e07a6385d
commit
f67c37263e
22 changed files with 135 additions and 160 deletions
|
@ -8,13 +8,9 @@
|
||||||
// option. This file may not be copied, modified, or distributed
|
// option. This file may not be copied, modified, or distributed
|
||||||
// except according to those terms.
|
// except according to those terms.
|
||||||
|
|
||||||
#[legacy_exports];
|
|
||||||
|
|
||||||
export foo;
|
|
||||||
|
|
||||||
use core::oldcomm::*;
|
use core::oldcomm::*;
|
||||||
|
|
||||||
fn foo<T: Owned Copy>(x: T) -> Port<T> {
|
pub fn foo<T: Owned Copy>(x: T) -> Port<T> {
|
||||||
let p = Port();
|
let p = Port();
|
||||||
let c = Chan(&p);
|
let c = Chan(&p);
|
||||||
do task::spawn() |copy c, copy x| {
|
do task::spawn() |copy c, copy x| {
|
||||||
|
|
|
@ -14,15 +14,13 @@ use to_str::*;
|
||||||
use to_str::ToStr;
|
use to_str::ToStr;
|
||||||
|
|
||||||
mod kitty {
|
mod kitty {
|
||||||
#[legacy_exports];
|
pub struct cat {
|
||||||
|
priv mut meows : uint,
|
||||||
|
mut how_hungry : int,
|
||||||
|
name : ~str,
|
||||||
|
}
|
||||||
|
|
||||||
struct cat {
|
pub impl cat : ToStr {
|
||||||
priv mut meows : uint,
|
|
||||||
mut how_hungry : int,
|
|
||||||
name : ~str,
|
|
||||||
}
|
|
||||||
|
|
||||||
impl cat : ToStr {
|
|
||||||
pure fn to_str() -> ~str { copy self.name }
|
pure fn to_str() -> ~str { copy self.name }
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -37,7 +35,7 @@ struct cat {
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
impl cat {
|
pub impl cat {
|
||||||
fn speak() { self.meow(); }
|
fn speak() { self.meow(); }
|
||||||
|
|
||||||
fn eat() -> bool {
|
fn eat() -> bool {
|
||||||
|
@ -52,14 +50,14 @@ struct cat {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
fn cat(in_x : uint, in_y : int, in_name: ~str) -> cat {
|
|
||||||
cat {
|
pub fn cat(in_x : uint, in_y : int, in_name: ~str) -> cat {
|
||||||
meows: in_x,
|
cat {
|
||||||
how_hungry: in_y,
|
meows: in_x,
|
||||||
name: in_name
|
how_hungry: in_y,
|
||||||
|
name: in_name
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
|
|
|
@ -10,17 +10,15 @@
|
||||||
|
|
||||||
#[link(name = "req")];
|
#[link(name = "req")];
|
||||||
#[crate_type = "lib"];
|
#[crate_type = "lib"];
|
||||||
#[legacy_exports];
|
|
||||||
|
|
||||||
extern mod std;
|
extern mod std;
|
||||||
|
|
||||||
use dvec::*;
|
use core::dvec::*;
|
||||||
use dvec::DVec;
|
|
||||||
use std::map::HashMap;
|
use std::map::HashMap;
|
||||||
|
|
||||||
type header_map = HashMap<~str, @DVec<@~str>>;
|
pub type header_map = HashMap<~str, @DVec<@~str>>;
|
||||||
|
|
||||||
// the unused ty param is necessary so this gets monomorphized
|
// the unused ty param is necessary so this gets monomorphized
|
||||||
fn request<T: Copy>(req: header_map) {
|
pub fn request<T: Copy>(req: header_map) {
|
||||||
let _x = copy *(copy *req.get(~"METHOD"))[0u];
|
let _x = copy *(copy *req.get(~"METHOD"))[0u];
|
||||||
}
|
}
|
||||||
|
|
|
@ -12,10 +12,8 @@
|
||||||
vers = "0.1")];
|
vers = "0.1")];
|
||||||
|
|
||||||
#[crate_type = "lib"];
|
#[crate_type = "lib"];
|
||||||
#[legacy_exports];
|
|
||||||
export read, readMaybe;
|
|
||||||
|
|
||||||
trait read {
|
pub trait read {
|
||||||
static fn readMaybe(s: ~str) -> Option<self>;
|
static fn readMaybe(s: ~str) -> Option<self>;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -35,7 +33,7 @@ impl bool: read {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
fn read<T: read Copy>(s: ~str) -> T {
|
pub fn read<T: read Copy>(s: ~str) -> T {
|
||||||
match read::readMaybe(s) {
|
match read::readMaybe(s) {
|
||||||
Some(x) => x,
|
Some(x) => x,
|
||||||
_ => fail ~"read failed!"
|
_ => fail ~"read failed!"
|
||||||
|
|
|
@ -16,7 +16,7 @@ pub mod num {
|
||||||
}
|
}
|
||||||
|
|
||||||
pub mod float {
|
pub mod float {
|
||||||
impl float: num::Num2 {
|
impl float: ::num::Num2 {
|
||||||
#[inline]
|
#[inline]
|
||||||
static pure fn from_int2(n: int) -> float { return n as float; }
|
static pure fn from_int2(n: int) -> float { return n as float; }
|
||||||
}
|
}
|
||||||
|
|
|
@ -5,7 +5,7 @@ pub mod num {
|
||||||
}
|
}
|
||||||
|
|
||||||
pub mod float {
|
pub mod float {
|
||||||
impl float: num::Num2 {
|
impl float: ::num::Num2 {
|
||||||
static pure fn from_int2(n: int) -> float { return n as float; }
|
static pure fn from_int2(n: int) -> float { return n as float; }
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -13,12 +13,8 @@
|
||||||
|
|
||||||
Could probably be more minimal.
|
Could probably be more minimal.
|
||||||
*/
|
*/
|
||||||
#[legacy_exports];
|
|
||||||
|
|
||||||
use libc::size_t;
|
use core::libc::size_t;
|
||||||
|
|
||||||
export port;
|
|
||||||
export recv;
|
|
||||||
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
@ -28,12 +24,12 @@ export recv;
|
||||||
* transmitted. If a port value is copied, both copies refer to the same
|
* transmitted. If a port value is copied, both copies refer to the same
|
||||||
* port. Ports may be associated with multiple `chan`s.
|
* port. Ports may be associated with multiple `chan`s.
|
||||||
*/
|
*/
|
||||||
enum port<T: Owned> {
|
pub enum port<T: Owned> {
|
||||||
port_t(@port_ptr<T>)
|
port_t(@port_ptr<T>)
|
||||||
}
|
}
|
||||||
|
|
||||||
/// Constructs a port
|
/// Constructs a port
|
||||||
fn port<T: Owned>() -> port<T> {
|
pub fn port<T: Owned>() -> port<T> {
|
||||||
port_t(@port_ptr(rustrt::new_port(sys::size_of::<T>() as size_t)))
|
port_t(@port_ptr(rustrt::new_port(sys::size_of::<T>() as size_t)))
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -74,11 +70,11 @@ fn port_ptr<T: Owned>(po: *rust_port) -> port_ptr<T> {
|
||||||
* Receive from a port. If no data is available on the port then the
|
* Receive from a port. If no data is available on the port then the
|
||||||
* task will block until data becomes available.
|
* task will block until data becomes available.
|
||||||
*/
|
*/
|
||||||
fn recv<T: Owned>(p: port<T>) -> T { recv_((**p).po) }
|
pub fn recv<T: Owned>(p: port<T>) -> T { recv_((**p).po) }
|
||||||
|
|
||||||
|
|
||||||
/// Receive on a raw port pointer
|
/// Receive on a raw port pointer
|
||||||
fn recv_<T: Owned>(p: *rust_port) -> T {
|
pub fn recv_<T: Owned>(p: *rust_port) -> T {
|
||||||
let yield = 0;
|
let yield = 0;
|
||||||
let yieldp = ptr::addr_of(&yield);
|
let yieldp = ptr::addr_of(&yield);
|
||||||
let mut res;
|
let mut res;
|
||||||
|
|
|
@ -26,12 +26,12 @@ use std::serialize::{Encodable, Decodable};
|
||||||
use std::prettyprint;
|
use std::prettyprint;
|
||||||
use std::time;
|
use std::time;
|
||||||
|
|
||||||
fn test_prettyprint<A: Encodable<prettyprint::Encoder>>(
|
fn test_prettyprint<A: Encodable<prettyprint::Serializer>>(
|
||||||
a: &A,
|
a: &A,
|
||||||
expected: &~str
|
expected: &~str
|
||||||
) {
|
) {
|
||||||
let s = do io::with_str_writer |w| {
|
let s = do io::with_str_writer |w| {
|
||||||
a.encode(&prettyprint::Encoder(w))
|
a.encode(&prettyprint::Serializer(w))
|
||||||
};
|
};
|
||||||
debug!("s == %?", s);
|
debug!("s == %?", s);
|
||||||
assert s == *expected;
|
assert s == *expected;
|
||||||
|
|
|
@ -18,7 +18,7 @@
|
||||||
|
|
||||||
extern mod cci_capture_clause;
|
extern mod cci_capture_clause;
|
||||||
|
|
||||||
use oldcomm::recv;
|
use core::oldcomm::recv;
|
||||||
|
|
||||||
fn main() {
|
fn main() {
|
||||||
cci_capture_clause::foo(()).recv()
|
cci_capture_clause::foo(()).recv()
|
||||||
|
|
|
@ -9,8 +9,7 @@
|
||||||
// except according to those terms.
|
// except according to those terms.
|
||||||
|
|
||||||
// xfail-fast
|
// xfail-fast
|
||||||
use to_str::*;
|
use core::to_str::*;
|
||||||
use to_str::ToStr;
|
|
||||||
|
|
||||||
struct cat {
|
struct cat {
|
||||||
priv mut meows : uint,
|
priv mut meows : uint,
|
||||||
|
|
|
@ -9,17 +9,11 @@
|
||||||
// except according to those terms.
|
// except according to those terms.
|
||||||
|
|
||||||
mod foo {
|
mod foo {
|
||||||
#[legacy_exports];
|
pub fn x() { bar::x(); }
|
||||||
export x;
|
|
||||||
|
|
||||||
fn x() { bar::x(); }
|
|
||||||
}
|
}
|
||||||
|
|
||||||
mod bar {
|
mod bar {
|
||||||
#[legacy_exports];
|
pub fn x() { debug!("x"); }
|
||||||
export x;
|
|
||||||
|
|
||||||
fn x() { debug!("x"); }
|
|
||||||
}
|
}
|
||||||
|
|
||||||
fn main() { foo::x(); }
|
fn main() { foo::x(); }
|
||||||
|
|
|
@ -28,14 +28,12 @@ use oldcomm::recv;
|
||||||
fn map(filename: ~str, emit: map_reduce::putter) { emit(filename, ~"1"); }
|
fn map(filename: ~str, emit: map_reduce::putter) { emit(filename, ~"1"); }
|
||||||
|
|
||||||
mod map_reduce {
|
mod map_reduce {
|
||||||
#[legacy_exports];
|
use std::map;
|
||||||
export putter;
|
use std::map::HashMap;
|
||||||
export mapper;
|
|
||||||
export map_reduce;
|
|
||||||
|
|
||||||
type putter = fn@(~str, ~str);
|
pub type putter = fn@(~str, ~str);
|
||||||
|
|
||||||
type mapper = extern fn(~str, putter);
|
pub type mapper = extern fn(~str, putter);
|
||||||
|
|
||||||
enum ctrl_proto { find_reducer(~[u8], Chan<int>), mapper_done, }
|
enum ctrl_proto { find_reducer(~[u8], Chan<int>), mapper_done, }
|
||||||
|
|
||||||
|
@ -70,7 +68,7 @@ mod map_reduce {
|
||||||
send(ctrl, mapper_done);
|
send(ctrl, mapper_done);
|
||||||
}
|
}
|
||||||
|
|
||||||
fn map_reduce(inputs: ~[~str]) {
|
pub fn map_reduce(inputs: ~[~str]) {
|
||||||
let ctrl = Port();
|
let ctrl = Port();
|
||||||
|
|
||||||
// This task becomes the master control task. It spawns others
|
// This task becomes the master control task. It spawns others
|
||||||
|
|
|
@ -12,7 +12,7 @@
|
||||||
|
|
||||||
|
|
||||||
extern mod std;
|
extern mod std;
|
||||||
use vec::*;
|
use core::vec::*;
|
||||||
|
|
||||||
fn main() {
|
fn main() {
|
||||||
let mut v = from_elem(0u, 0);
|
let mut v = from_elem(0u, 0);
|
||||||
|
|
|
@ -21,26 +21,24 @@ extern mod rusti {
|
||||||
#[cfg(target_os = "macos")]
|
#[cfg(target_os = "macos")]
|
||||||
#[cfg(target_os = "freebsd")]
|
#[cfg(target_os = "freebsd")]
|
||||||
mod m {
|
mod m {
|
||||||
#[legacy_exports];
|
|
||||||
#[cfg(target_arch = "x86")]
|
#[cfg(target_arch = "x86")]
|
||||||
fn main() {
|
pub fn main() {
|
||||||
assert rusti::pref_align_of::<u64>() == 8u;
|
assert ::rusti::pref_align_of::<u64>() == 8u;
|
||||||
assert rusti::min_align_of::<u64>() == 4u;
|
assert ::rusti::min_align_of::<u64>() == 4u;
|
||||||
}
|
}
|
||||||
|
|
||||||
#[cfg(target_arch = "x86_64")]
|
#[cfg(target_arch = "x86_64")]
|
||||||
fn main() {
|
pub fn main() {
|
||||||
assert rusti::pref_align_of::<u64>() == 8u;
|
assert ::rusti::pref_align_of::<u64>() == 8u;
|
||||||
assert rusti::min_align_of::<u64>() == 8u;
|
assert ::rusti::min_align_of::<u64>() == 8u;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
#[cfg(target_os = "win32")]
|
#[cfg(target_os = "win32")]
|
||||||
mod m {
|
mod m {
|
||||||
#[legacy_exports];
|
|
||||||
#[cfg(target_arch = "x86")]
|
#[cfg(target_arch = "x86")]
|
||||||
fn main() {
|
pub fn main() {
|
||||||
assert rusti::pref_align_of::<u64>() == 8u;
|
assert ::rusti::pref_align_of::<u64>() == 8u;
|
||||||
assert rusti::min_align_of::<u64>() == 8u;
|
assert ::rusti::min_align_of::<u64>() == 8u;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -10,8 +10,9 @@
|
||||||
// option. This file may not be copied, modified, or distributed
|
// option. This file may not be copied, modified, or distributed
|
||||||
// except according to those terms.
|
// except according to those terms.
|
||||||
|
|
||||||
use libc::{c_double, c_int};
|
use core::cast;
|
||||||
use f64::*;
|
use core::libc::{c_double, c_int};
|
||||||
|
use core::f64::*;
|
||||||
|
|
||||||
fn to_c_int(v: &mut int) -> &mut c_int unsafe {
|
fn to_c_int(v: &mut int) -> &mut c_int unsafe {
|
||||||
cast::reinterpret_cast(&v)
|
cast::reinterpret_cast(&v)
|
||||||
|
@ -24,13 +25,12 @@ fn lgamma(n: c_double, value: &mut int) -> c_double {
|
||||||
#[link_name = "m"]
|
#[link_name = "m"]
|
||||||
#[abi = "cdecl"]
|
#[abi = "cdecl"]
|
||||||
extern mod m {
|
extern mod m {
|
||||||
#[legacy_exports];
|
|
||||||
#[cfg(unix)]
|
#[cfg(unix)]
|
||||||
#[link_name="lgamma_r"] fn lgamma(n: c_double, sign: &mut c_int)
|
#[link_name="lgamma_r"] pub fn lgamma(n: c_double, sign: &mut c_int)
|
||||||
-> c_double;
|
-> c_double;
|
||||||
#[cfg(windows)]
|
#[cfg(windows)]
|
||||||
#[link_name="__lgamma_r"] fn lgamma(n: c_double,
|
#[link_name="__lgamma_r"] pub fn lgamma(n: c_double,
|
||||||
sign: &mut c_int) -> c_double;
|
sign: &mut c_int) -> c_double;
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -11,31 +11,30 @@
|
||||||
// except according to those terms.
|
// except according to those terms.
|
||||||
|
|
||||||
// tjc: I don't know why
|
// tjc: I don't know why
|
||||||
mod pipes {
|
pub mod pipes {
|
||||||
#[legacy_exports];
|
use core::cast::{forget, transmute};
|
||||||
use cast::{forget, transmute};
|
|
||||||
|
|
||||||
enum state {
|
pub enum state {
|
||||||
empty,
|
empty,
|
||||||
full,
|
full,
|
||||||
blocked,
|
blocked,
|
||||||
terminated
|
terminated
|
||||||
}
|
}
|
||||||
|
|
||||||
impl state : cmp::Eq {
|
pub impl state : cmp::Eq {
|
||||||
pure fn eq(&self, other: &state) -> bool {
|
pure fn eq(&self, other: &state) -> bool {
|
||||||
((*self) as uint) == ((*other) as uint)
|
((*self) as uint) == ((*other) as uint)
|
||||||
}
|
}
|
||||||
pure fn ne(&self, other: &state) -> bool { !(*self).eq(other) }
|
pure fn ne(&self, other: &state) -> bool { !(*self).eq(other) }
|
||||||
}
|
}
|
||||||
|
|
||||||
type packet<T: Owned> = {
|
pub type packet<T: Owned> = {
|
||||||
mut state: state,
|
mut state: state,
|
||||||
mut blocked_task: Option<task::Task>,
|
mut blocked_task: Option<task::Task>,
|
||||||
mut payload: Option<T>
|
mut payload: Option<T>
|
||||||
};
|
};
|
||||||
|
|
||||||
fn packet<T: Owned>() -> *packet<T> unsafe {
|
pub fn packet<T: Owned>() -> *packet<T> unsafe {
|
||||||
let p: *packet<T> = cast::transmute(~{
|
let p: *packet<T> = cast::transmute(~{
|
||||||
mut state: empty,
|
mut state: empty,
|
||||||
mut blocked_task: None::<task::Task>,
|
mut blocked_task: None::<task::Task>,
|
||||||
|
@ -46,31 +45,30 @@ mod pipes {
|
||||||
|
|
||||||
#[abi = "rust-intrinsic"]
|
#[abi = "rust-intrinsic"]
|
||||||
mod rusti {
|
mod rusti {
|
||||||
#[legacy_exports];
|
pub fn atomic_xchg(_dst: &mut int, _src: int) -> int { fail; }
|
||||||
fn atomic_xchg(_dst: &mut int, _src: int) -> int { fail; }
|
pub fn atomic_xchg_acq(_dst: &mut int, _src: int) -> int { fail; }
|
||||||
fn atomic_xchg_acq(_dst: &mut int, _src: int) -> int { fail; }
|
pub fn atomic_xchg_rel(_dst: &mut int, _src: int) -> int { fail; }
|
||||||
fn atomic_xchg_rel(_dst: &mut int, _src: int) -> int { fail; }
|
|
||||||
}
|
}
|
||||||
|
|
||||||
// We should consider moving this to core::unsafe, although I
|
// We should consider moving this to core::unsafe, although I
|
||||||
// suspect graydon would want us to use void pointers instead.
|
// suspect graydon would want us to use void pointers instead.
|
||||||
unsafe fn uniquify<T>(+x: *T) -> ~T {
|
pub unsafe fn uniquify<T>(+x: *T) -> ~T {
|
||||||
unsafe { cast::transmute(move x) }
|
unsafe { cast::transmute(move x) }
|
||||||
}
|
}
|
||||||
|
|
||||||
fn swap_state_acq(+dst: &mut state, src: state) -> state {
|
pub fn swap_state_acq(+dst: &mut state, src: state) -> state {
|
||||||
unsafe {
|
unsafe {
|
||||||
transmute(rusti::atomic_xchg_acq(transmute(move dst), src as int))
|
transmute(rusti::atomic_xchg_acq(transmute(move dst), src as int))
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
fn swap_state_rel(+dst: &mut state, src: state) -> state {
|
pub fn swap_state_rel(+dst: &mut state, src: state) -> state {
|
||||||
unsafe {
|
unsafe {
|
||||||
transmute(rusti::atomic_xchg_rel(transmute(move dst), src as int))
|
transmute(rusti::atomic_xchg_rel(transmute(move dst), src as int))
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
fn send<T: Owned>(-p: send_packet<T>, -payload: T) {
|
pub fn send<T: Owned>(-p: send_packet<T>, -payload: T) {
|
||||||
let p = p.unwrap();
|
let p = p.unwrap();
|
||||||
let p = unsafe { uniquify(p) };
|
let p = unsafe { uniquify(p) };
|
||||||
assert (*p).payload.is_none();
|
assert (*p).payload.is_none();
|
||||||
|
@ -96,7 +94,7 @@ mod pipes {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
fn recv<T: Owned>(-p: recv_packet<T>) -> Option<T> {
|
pub fn recv<T: Owned>(-p: recv_packet<T>) -> Option<T> {
|
||||||
let p = p.unwrap();
|
let p = p.unwrap();
|
||||||
let p = unsafe { uniquify(p) };
|
let p = unsafe { uniquify(p) };
|
||||||
loop {
|
loop {
|
||||||
|
@ -117,7 +115,7 @@ mod pipes {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
fn sender_terminate<T: Owned>(p: *packet<T>) {
|
pub fn sender_terminate<T: Owned>(p: *packet<T>) {
|
||||||
let p = unsafe { uniquify(p) };
|
let p = unsafe { uniquify(p) };
|
||||||
match swap_state_rel(&mut (*p).state, terminated) {
|
match swap_state_rel(&mut (*p).state, terminated) {
|
||||||
empty | blocked => {
|
empty | blocked => {
|
||||||
|
@ -134,7 +132,7 @@ mod pipes {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
fn receiver_terminate<T: Owned>(p: *packet<T>) {
|
pub fn receiver_terminate<T: Owned>(p: *packet<T>) {
|
||||||
let p = unsafe { uniquify(p) };
|
let p = unsafe { uniquify(p) };
|
||||||
match swap_state_rel(&mut (*p).state, terminated) {
|
match swap_state_rel(&mut (*p).state, terminated) {
|
||||||
empty => {
|
empty => {
|
||||||
|
@ -151,11 +149,11 @@ mod pipes {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
struct send_packet<T: Owned> {
|
pub struct send_packet<T: Owned> {
|
||||||
mut p: Option<*packet<T>>,
|
mut p: Option<*packet<T>>,
|
||||||
}
|
}
|
||||||
|
|
||||||
impl<T: Owned> send_packet<T> : Drop {
|
pub impl<T: Owned> send_packet<T> : Drop {
|
||||||
fn finalize(&self) {
|
fn finalize(&self) {
|
||||||
if self.p != None {
|
if self.p != None {
|
||||||
let mut p = None;
|
let mut p = None;
|
||||||
|
@ -165,7 +163,7 @@ mod pipes {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
impl<T: Owned> send_packet<T> {
|
pub impl<T: Owned> 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;
|
||||||
|
@ -173,17 +171,17 @@ mod pipes {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
fn send_packet<T: Owned>(p: *packet<T>) -> send_packet<T> {
|
pub fn send_packet<T: Owned>(p: *packet<T>) -> send_packet<T> {
|
||||||
send_packet {
|
send_packet {
|
||||||
p: Some(p)
|
p: Some(p)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
struct recv_packet<T: Owned> {
|
pub struct recv_packet<T: Owned> {
|
||||||
mut p: Option<*packet<T>>,
|
mut p: Option<*packet<T>>,
|
||||||
}
|
}
|
||||||
|
|
||||||
impl<T: Owned> recv_packet<T> : Drop {
|
pub impl<T: Owned> recv_packet<T> : Drop {
|
||||||
fn finalize(&self) {
|
fn finalize(&self) {
|
||||||
if self.p != None {
|
if self.p != None {
|
||||||
let mut p = None;
|
let mut p = None;
|
||||||
|
@ -193,7 +191,7 @@ mod pipes {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
impl<T: Owned> recv_packet<T> {
|
pub impl<T: Owned> 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;
|
||||||
|
@ -201,25 +199,27 @@ mod pipes {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
fn recv_packet<T: Owned>(p: *packet<T>) -> recv_packet<T> {
|
pub fn recv_packet<T: Owned>(p: *packet<T>) -> recv_packet<T> {
|
||||||
recv_packet {
|
recv_packet {
|
||||||
p: Some(p)
|
p: Some(p)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
fn entangle<T: Owned>() -> (send_packet<T>, recv_packet<T>) {
|
pub fn entangle<T: Owned>() -> (send_packet<T>, recv_packet<T>) {
|
||||||
let p = packet();
|
let p = packet();
|
||||||
(send_packet(p), recv_packet(p))
|
(send_packet(p), recv_packet(p))
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
mod pingpong {
|
pub mod pingpong {
|
||||||
#[legacy_exports];
|
use core::cast;
|
||||||
enum ping = pipes::send_packet<pong>;
|
use core::ptr;
|
||||||
enum pong = pipes::send_packet<ping>;
|
|
||||||
|
|
||||||
fn liberate_ping(-p: ping) -> pipes::send_packet<pong> unsafe {
|
pub enum ping = ::pipes::send_packet<pong>;
|
||||||
let addr : *pipes::send_packet<pong> = match &p {
|
pub enum pong = ::pipes::send_packet<ping>;
|
||||||
|
|
||||||
|
pub fn liberate_ping(-p: ping) -> ::pipes::send_packet<pong> unsafe {
|
||||||
|
let addr : *::pipes::send_packet<pong> = match &p {
|
||||||
&ping(ref x) => { cast::transmute(ptr::addr_of(x)) }
|
&ping(ref x) => { cast::transmute(ptr::addr_of(x)) }
|
||||||
};
|
};
|
||||||
let liberated_value = move *addr;
|
let liberated_value = move *addr;
|
||||||
|
@ -227,8 +227,8 @@ mod pingpong {
|
||||||
move liberated_value
|
move liberated_value
|
||||||
}
|
}
|
||||||
|
|
||||||
fn liberate_pong(-p: pong) -> pipes::send_packet<ping> unsafe {
|
pub fn liberate_pong(-p: pong) -> ::pipes::send_packet<ping> unsafe {
|
||||||
let addr : *pipes::send_packet<ping> = match &p {
|
let addr : *::pipes::send_packet<ping> = match &p {
|
||||||
&pong(ref x) => { cast::transmute(ptr::addr_of(x)) }
|
&pong(ref x) => { cast::transmute(ptr::addr_of(x)) }
|
||||||
};
|
};
|
||||||
let liberated_value = move *addr;
|
let liberated_value = move *addr;
|
||||||
|
@ -236,24 +236,26 @@ mod pingpong {
|
||||||
move liberated_value
|
move liberated_value
|
||||||
}
|
}
|
||||||
|
|
||||||
fn init() -> (client::ping, server::ping) {
|
pub fn init() -> (client::ping, server::ping) {
|
||||||
pipes::entangle()
|
::pipes::entangle()
|
||||||
}
|
}
|
||||||
|
|
||||||
mod client {
|
pub mod client {
|
||||||
#[legacy_exports];
|
use core::option;
|
||||||
type ping = pipes::send_packet<pingpong::ping>;
|
use pingpong;
|
||||||
type pong = pipes::recv_packet<pingpong::pong>;
|
|
||||||
|
|
||||||
fn do_ping(-c: ping) -> pong {
|
pub type ping = ::pipes::send_packet<pingpong::ping>;
|
||||||
let (sp, rp) = pipes::entangle();
|
pub type pong = ::pipes::recv_packet<pingpong::pong>;
|
||||||
|
|
||||||
pipes::send(move c, ping(move sp));
|
pub fn do_ping(-c: ping) -> pong {
|
||||||
|
let (sp, rp) = ::pipes::entangle();
|
||||||
|
|
||||||
|
::pipes::send(move c, ping(move sp));
|
||||||
move rp
|
move rp
|
||||||
}
|
}
|
||||||
|
|
||||||
fn do_pong(-c: pong) -> (ping, ()) {
|
pub fn do_pong(-c: pong) -> (ping, ()) {
|
||||||
let packet = pipes::recv(move c);
|
let packet = ::pipes::recv(move c);
|
||||||
if packet.is_none() {
|
if packet.is_none() {
|
||||||
fail ~"sender closed the connection"
|
fail ~"sender closed the connection"
|
||||||
}
|
}
|
||||||
|
@ -261,22 +263,23 @@ mod pingpong {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
mod server {
|
pub mod server {
|
||||||
#[legacy_exports];
|
use pingpong;
|
||||||
type ping = pipes::recv_packet<pingpong::ping>;
|
|
||||||
type pong = pipes::send_packet<pingpong::pong>;
|
|
||||||
|
|
||||||
fn do_ping(-c: ping) -> (pong, ()) {
|
pub type ping = ::pipes::recv_packet<pingpong::ping>;
|
||||||
let packet = pipes::recv(move c);
|
pub type pong = ::pipes::send_packet<pingpong::pong>;
|
||||||
|
|
||||||
|
pub fn do_ping(-c: ping) -> (pong, ()) {
|
||||||
|
let packet = ::pipes::recv(move c);
|
||||||
if packet.is_none() {
|
if packet.is_none() {
|
||||||
fail ~"sender closed the connection"
|
fail ~"sender closed the connection"
|
||||||
}
|
}
|
||||||
(liberate_ping(option::unwrap(move packet)), ())
|
(liberate_ping(option::unwrap(move packet)), ())
|
||||||
}
|
}
|
||||||
|
|
||||||
fn do_pong(-c: pong) -> ping {
|
pub fn do_pong(-c: pong) -> ping {
|
||||||
let (sp, rp) = pipes::entangle();
|
let (sp, rp) = ::pipes::entangle();
|
||||||
pipes::send(move c, pong(move sp));
|
::pipes::send(move c, pong(move sp));
|
||||||
move rp
|
move rp
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
Binary file not shown.
|
@ -12,7 +12,8 @@
|
||||||
|
|
||||||
// rustc --test map_to_str.rs && ./map_to_str
|
// rustc --test map_to_str.rs && ./map_to_str
|
||||||
extern mod std;
|
extern mod std;
|
||||||
use io::{WriterUtil};
|
|
||||||
|
use core::io::{WriterUtil};
|
||||||
use std::map::*;
|
use std::map::*;
|
||||||
|
|
||||||
#[cfg(test)]
|
#[cfg(test)]
|
||||||
|
|
|
@ -13,7 +13,7 @@
|
||||||
// Incorrect struct size computation in the FFI, because of not taking
|
// Incorrect struct size computation in the FFI, because of not taking
|
||||||
// the alignment of elements into account.
|
// the alignment of elements into account.
|
||||||
|
|
||||||
use libc::*;
|
use core::libc::*;
|
||||||
|
|
||||||
struct KEYGEN {
|
struct KEYGEN {
|
||||||
hash_algorithm: [c_uint * 2],
|
hash_algorithm: [c_uint * 2],
|
||||||
|
|
|
@ -18,8 +18,7 @@
|
||||||
// This was generated initially by the pipe compiler, but it's been
|
// This was generated initially by the pipe compiler, but it's been
|
||||||
// modified in hopefully straightforward ways.
|
// modified in hopefully straightforward ways.
|
||||||
mod pingpong {
|
mod pingpong {
|
||||||
#[legacy_exports];
|
use core::pipes::*;
|
||||||
use pipes::*;
|
|
||||||
|
|
||||||
type packets = {
|
type packets = {
|
||||||
// This is probably a resolve bug, I forgot to export packet,
|
// This is probably a resolve bug, I forgot to export packet,
|
||||||
|
@ -42,11 +41,10 @@ mod pingpong {
|
||||||
ptr::addr_of(&(data.ping))
|
ptr::addr_of(&(data.ping))
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
enum ping = server::pong;
|
pub enum ping = server::pong;
|
||||||
enum pong = client::ping;
|
pub enum pong = client::ping;
|
||||||
mod client {
|
pub mod client {
|
||||||
#[legacy_exports];
|
pub fn ping(+pipe: ping) -> pong {
|
||||||
fn ping(+pipe: ping) -> pong {
|
|
||||||
{
|
{
|
||||||
let b = pipe.reuse_buffer();
|
let b = pipe.reuse_buffer();
|
||||||
let s = SendPacketBuffered(ptr::addr_of(&(b.buffer.data.pong)));
|
let s = SendPacketBuffered(ptr::addr_of(&(b.buffer.data.pong)));
|
||||||
|
@ -56,16 +54,15 @@ mod pingpong {
|
||||||
move c
|
move c
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
type ping = pipes::SendPacketBuffered<pingpong::ping,
|
pub type ping = pipes::SendPacketBuffered<pingpong::ping,
|
||||||
pingpong::packets>;
|
pingpong::packets>;
|
||||||
type pong = pipes::RecvPacketBuffered<pingpong::pong,
|
pub type pong = pipes::RecvPacketBuffered<pingpong::pong,
|
||||||
pingpong::packets>;
|
pingpong::packets>;
|
||||||
}
|
}
|
||||||
mod server {
|
pub mod server {
|
||||||
#[legacy_exports];
|
pub type ping = pipes::RecvPacketBuffered<pingpong::ping,
|
||||||
type ping = pipes::RecvPacketBuffered<pingpong::ping,
|
|
||||||
pingpong::packets>;
|
pingpong::packets>;
|
||||||
fn pong(+pipe: pong) -> ping {
|
pub fn pong(+pipe: pong) -> ping {
|
||||||
{
|
{
|
||||||
let b = pipe.reuse_buffer();
|
let b = pipe.reuse_buffer();
|
||||||
let s = SendPacketBuffered(ptr::addr_of(&(b.buffer.data.ping)));
|
let s = SendPacketBuffered(ptr::addr_of(&(b.buffer.data.ping)));
|
||||||
|
@ -75,17 +72,16 @@ mod pingpong {
|
||||||
move c
|
move c
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
type pong = pipes::SendPacketBuffered<pingpong::pong,
|
pub type pong = pipes::SendPacketBuffered<pingpong::pong,
|
||||||
pingpong::packets>;
|
pingpong::packets>;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
mod test {
|
mod test {
|
||||||
#[legacy_exports];
|
|
||||||
use pipes::recv;
|
use pipes::recv;
|
||||||
use pingpong::{ping, pong};
|
use pingpong::{ping, pong};
|
||||||
|
|
||||||
fn client(-chan: pingpong::client::ping) {
|
pub fn client(-chan: pingpong::client::ping) {
|
||||||
use pingpong::client;
|
use pingpong::client;
|
||||||
|
|
||||||
let chan = client::ping(move chan); return;
|
let chan = client::ping(move chan); return;
|
||||||
|
@ -94,7 +90,7 @@ mod test {
|
||||||
log(error, "Received pong");
|
log(error, "Received pong");
|
||||||
}
|
}
|
||||||
|
|
||||||
fn server(-chan: pingpong::server::ping) {
|
pub fn server(-chan: pingpong::server::ping) {
|
||||||
use pingpong::server;
|
use pingpong::server;
|
||||||
|
|
||||||
let ping(chan) = recv(move chan); return;
|
let ping(chan) = recv(move chan); return;
|
||||||
|
|
|
@ -12,6 +12,7 @@
|
||||||
|
|
||||||
// An example to make sure the protocol parsing syntax extension works.
|
// An example to make sure the protocol parsing syntax extension works.
|
||||||
|
|
||||||
|
use core::option;
|
||||||
|
|
||||||
proto! pingpong (
|
proto! pingpong (
|
||||||
ping:send {
|
ping:send {
|
||||||
|
@ -24,11 +25,10 @@ proto! pingpong (
|
||||||
)
|
)
|
||||||
|
|
||||||
mod test {
|
mod test {
|
||||||
#[legacy_exports];
|
use core::pipes::recv;
|
||||||
use pipes::recv;
|
|
||||||
use pingpong::{ping, pong};
|
use pingpong::{ping, pong};
|
||||||
|
|
||||||
fn client(-chan: pingpong::client::ping) {
|
pub fn client(-chan: pingpong::client::ping) {
|
||||||
use pingpong::client;
|
use pingpong::client;
|
||||||
|
|
||||||
let chan = client::ping(move chan);
|
let chan = client::ping(move chan);
|
||||||
|
@ -37,7 +37,7 @@ mod test {
|
||||||
log(error, ~"Received pong");
|
log(error, ~"Received pong");
|
||||||
}
|
}
|
||||||
|
|
||||||
fn server(-chan: pingpong::server::ping) {
|
pub fn server(-chan: pingpong::server::ping) {
|
||||||
use pingpong::server;
|
use pingpong::server;
|
||||||
|
|
||||||
let ping(chan) = recv(move chan);
|
let ping(chan) = recv(move chan);
|
||||||
|
|
|
@ -17,7 +17,7 @@ mod base {
|
||||||
dummy: (),
|
dummy: (),
|
||||||
}
|
}
|
||||||
|
|
||||||
pub impl Foo : base::HasNew<Foo> {
|
pub impl Foo : ::base::HasNew<Foo> {
|
||||||
static pure fn new() -> Foo {
|
static pure fn new() -> Foo {
|
||||||
unsafe { io::println("Foo"); }
|
unsafe { io::println("Foo"); }
|
||||||
Foo { dummy: () }
|
Foo { dummy: () }
|
||||||
|
@ -28,7 +28,7 @@ mod base {
|
||||||
dummy: (),
|
dummy: (),
|
||||||
}
|
}
|
||||||
|
|
||||||
pub impl Bar : base::HasNew<Bar> {
|
pub impl Bar : ::base::HasNew<Bar> {
|
||||||
static pure fn new() -> Bar {
|
static pure fn new() -> Bar {
|
||||||
unsafe { io::println("Bar"); }
|
unsafe { io::println("Bar"); }
|
||||||
Bar { dummy: () }
|
Bar { dummy: () }
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue