Permalink
Browse files

Updating tests to use pipes.

  • Loading branch information...
1 parent fa41346 commit 7b03832c958826b27ea77df91f2d2ac276bb7411 @eholk eholk committed Jul 6, 2012
View
@@ -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) }
@@ -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;
}
@@ -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();
+ });
}
}
@@ -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
@@ -13,41 +13,16 @@ 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 }]
];
@@ -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));
@@ -1,110 +0,0 @@
-/*
-
-The first test case using pipes. The idea is to break this into
-several stages for prototyping. Here's the plan:
-
-1. Write an already-compiled protocol using existing ports and chans.
-
-2. Take the already-compiled version and add the low-level
-synchronization code instead.
-
-3. Write a syntax extension to compile the protocols.
-
-At some point, we'll need to add support for select.
-
-*/
-
-mod pingpong {
- import newcomm::*;
-
- type pingpong = ~mut option<(chan<()>, port<()>)>;
-
- fn init() -> (client::ping, server::ping) {
- let cp = port();
- let sp = port();
- let cc = chan(sp);
- let sc = chan(cp);
-
- let client = client::ping(~mut some((cc, cp)));
- let server = server::ping(~mut some((sc, sp)));
-
- (client, server)
- }
-
- mod client {
- enum ping = pingpong;
- enum pong = pingpong;
-
- fn do_ping(-c: ping) -> pong {
- let mut op = none;
- op <-> **c;
- let (c, s) <- option::unwrap(op);
- c.send(());
- let p <- (c, s);
- pong(~mut some(p))
- }
-
- fn do_pong(-c: pong) -> (ping, ()) {
- let mut op = none;
- op <-> **c;
- let (c, s) <- option::unwrap(op);
- let d = s.recv();
- let p <- (c, s);
- (ping(~mut some(p)), d)
- }
- }
-
- mod server {
- enum ping = pingpong;
- enum pong = pingpong;
-
- fn do_ping(-c: ping) -> (pong, ()) {
- let mut op = none;
- op <-> **c;
- let (c, s) <- option::unwrap(op);
- let d = s.recv();
- let p <- (c, s);
- (pong(~mut some(p)), d)
- }
-
- fn do_pong(-c: pong) -> ping {
- let mut op = none;
- op <-> **c;
- let (c, s) <- option::unwrap(op);
- c.send(());
- let p <- (c, s);
- ping(~mut some(p))
- }
- }
-}
-
-fn client(-chan: pingpong::client::ping) {
- let chan = pingpong::client::do_ping(chan);
- log(error, "Sent ping");
- let (_chan, _data) = pingpong::client::do_pong(chan);
- log(error, "Received pong");
-}
-
-fn server(-chan: pingpong::server::ping) {
- let (chan, _data) = pingpong::server::do_ping(chan);
- log(error, "Received ping");
- let _chan = pingpong::server::do_pong(chan);
- log(error, "Sent pong");
-}
-
-fn main() {
- let (client_, server_) = pingpong::init();
- let client_ = ~mut some(client_);
- let server_ = ~mut some(server_);
-
- do task::spawn |move client_| {
- let mut client__ = none;
- *client_ <-> client__;
- client(option::unwrap(client__));
- };
- do task::spawn |move server_| {
- let mut server_ˊ = none;
- *server_ <-> server_ˊ;
- server(option::unwrap(server_ˊ));
- };
-}
@@ -1,93 +0,0 @@
-/*
-The first test case using pipes. The idea is to break this into
-several stages for prototyping. Here's the plan:
-
-1. Write an already-compiled protocol using existing ports and chans.
-
-2. Take the already-compiled version and add the low-level
-synchronization code instead. (That's what this file attempts to do)
-
-3. Write a syntax extension to compile the protocols.
-
-At some point, we'll need to add support for select.
-
-*/
-
-mod pingpong {
- enum ping = *pipes::packet<pong>;
- enum pong = *pipes::packet<ping>;
-
- fn init() -> (client::ping, server::ping) {
- pipes::entangle()
- }
-
- mod client {
- type ping = pipes::send_packet<pingpong::ping>;
- type pong = pipes::recv_packet<pingpong::pong>;
-
- fn do_ping(-c: ping) -> pong {
- let p = pipes::packet();
-
- pipes::send(c, pingpong::ping(p));
- pipes::recv_packet(p)
- }
-
- fn do_pong(-c: pong) -> (ping, ()) {
- let packet = pipes::recv(c);
- if packet == none {
- fail "sender closed the connection"
- }
- (pipes::send_packet(*option::unwrap(packet)), ())
- }
- }
-
- mod server {
- type ping = pipes::recv_packet<pingpong::ping>;
- type pong = pipes::send_packet<pingpong::pong>;
-
- fn do_ping(-c: ping) -> (pong, ()) {
- let packet = pipes::recv(c);
- if packet == none {
- fail "sender closed the connection"
- }
- (pipes::send_packet(*option::unwrap(packet)), ())
- }
-
- fn do_pong(-c: pong) -> ping {
- let p = pipes::packet();
- pipes::send(c, pingpong::pong(p));
- pipes::recv_packet(p)
- }
- }
-}
-
-fn client(-chan: pingpong::client::ping) {
- let chan = pingpong::client::do_ping(chan);
- log(error, "Sent ping");
- let (chan, _data) = pingpong::client::do_pong(chan);
- log(error, "Received pong");
-}
-
-fn server(-chan: pingpong::server::ping) {
- let (chan, _data) = pingpong::server::do_ping(chan);
- log(error, "Received ping");
- let chan = pingpong::server::do_pong(chan);
- log(error, "Sent pong");
-}
-
-fn main() {
- let (client_, server_) = pingpong::init();
- let client_ = ~mut some(client_);
- let server_ = ~mut some(server_);
-
- do task::spawn |move client_| {
- let mut client__ = none;
- *client_ <-> client__;
- client(option::unwrap(client__));
- };
- do task::spawn |move server_| {
- let mut server_ˊ = none;
- *server_ <-> server_ˊ;
- server(option::unwrap(server_ˊ));
- };
-}
Oops, something went wrong.

0 comments on commit 7b03832

Please sign in to comment.