Skip to content

Commit

Permalink
Updating tests to use pipes.
Browse files Browse the repository at this point in the history
  • Loading branch information
eholk committed Jul 6, 2012
1 parent fa41346 commit 7b03832
Show file tree
Hide file tree
Showing 8 changed files with 71 additions and 487 deletions.
9 changes: 9 additions & 0 deletions src/libcore/future.rs
Original file line number Diff line number Diff line change
Expand Up @@ -138,6 +138,15 @@ fn with<A,B>(future: future<A>, blk: fn(A) -> B) -> B {
}

// The pipe protocol, generated by pipec
/*
proto! future_pipe {
waiting:recv<T:send> {
completed(T) -> terminated
}
terminated { }
}
*/
mod future_pipe {
fn init<T: send>() -> (client::waiting<T>, server::waiting<T>) {
{ let (s, c) = pipes::entangle(); (c, s) }
Expand Down
58 changes: 36 additions & 22 deletions src/libsyntax/ext/pipes/parse_proto.rs
Original file line number Diff line number Diff line change
Expand Up @@ -10,11 +10,10 @@ impl proto_parser for parser {
fn parse_proto(id: ident) -> protocol {
let proto = protocol(id);

self.expect(token::LBRACE);

while self.token != token::RBRACE {
self.parse_state(proto);
}
self.parse_unspanned_seq(token::LBRACE,
token::RBRACE,
{sep: none, trailing_sep_allowed: false},
|self| self.parse_state(proto));

ret proto;
}
Expand All @@ -35,29 +34,44 @@ impl proto_parser for parser {
_ { fail }
};

let state = proto.add_state(id, dir);
// TODO: add typarams too.
let typarms = if self.token == token::LT {
self.parse_ty_params()
}
else { ~[] };

let state = proto.add_state_poly(id, dir, typarms);

self.expect(token::LBRACE);
// parse the messages
self.parse_unspanned_seq(
token::LBRACE, token::RBRACE,
{sep: some(token::COMMA), trailing_sep_allowed: true},
|self| {
let mname = self.parse_ident();

while self.token != token::RBRACE {
let mname = self.parse_ident();
let args = if self.token == token::LPAREN {
self.parse_unspanned_seq(token::LPAREN,
token::RPAREN,
{sep: some(token::COMMA),
trailing_sep_allowed: true},
|p| p.parse_ty(false))
}
else { ~[] };

// TODO: parse data
self.expect(token::RARROW);

self.expect(token::RARROW);
let next = self.parse_ident();

let next = self.parse_ident();
// TODO: parse next types
let ntys = if self.token == token::LT {
self.parse_unspanned_seq(token::LT,
token::GT,
{sep: some(token::COMMA),
trailing_sep_allowed: true},
|p| p.parse_ty(false))
}
else { ~[] };

state.add_message(mname, ~[], next, ~[]);
state.add_message(mname, args, next, ntys);

alt copy self.token {
token::COMMA { self.bump() }
token::RBRACE { }
_ { fail }
}
}
self.bump();
});
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
// that things will look really good once we get that lock out of the
// message path.

// This version uses semi-automatically compiled channel contracts.
// This version uses automatically compiled channel contracts.

// xfail-pretty

Expand All @@ -13,40 +13,15 @@ import future::future;
use std;
import std::time;

import ring::server::recv;

// This module was generated by the pipe compiler.
mod ring {
fn init() -> (client::num, server::num) { pipes::entangle() }
enum num { num(uint, server::num), }
mod client {
fn num(-pipe: num, x_0: uint) -> num {
let (c, s) = pipes::entangle();
let message = ring::num(x_0, s);
pipes::send(pipe, message);
c
}
type num = pipes::send_packet<ring::num>;
}
mod server {
impl recv for num {
fn recv() -> extern fn(-num) -> ring::num {
fn recv(-pipe: num) -> ring::num {
option::unwrap(pipes::recv(pipe))
}
recv
}
}
type num = pipes::recv_packet<ring::num>;
import pipes::recv;

proto! ring {
num:send {
num(uint) -> num
}
}

fn macros() {
#macro[
[#recv[chan],
chan.recv()(chan)]
];

#macro[
[#move[x],
unsafe { let y <- *ptr::addr_of(x); y }]
Expand All @@ -68,7 +43,7 @@ fn thread_ring(i: uint,
num_port2 <-> num_port;
num_chan = some(ring::client::num(option::unwrap(num_chan2), i * j));
let port = option::unwrap(num_port2);
alt (#recv(port)) {
alt (option::unwrap(recv(port))) {
ring::num(_n, p) {
//log(error, _n);
num_port = some(#move(p));
Expand Down
110 changes: 0 additions & 110 deletions src/test/run-pass/pipe-manual-1.rs

This file was deleted.

93 changes: 0 additions & 93 deletions src/test/run-pass/pipe-manual-2.rs

This file was deleted.

Loading

0 comments on commit 7b03832

Please sign in to comment.