2012-08-07 12:14:35 -05:00
|
|
|
|
|
|
|
// Protocols
|
|
|
|
proto! foo {
|
|
|
|
foo:recv {
|
|
|
|
do_foo -> foo
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
proto! bar {
|
|
|
|
bar:recv {
|
|
|
|
do_bar(int) -> barbar,
|
|
|
|
do_baz(bool) -> bazbar,
|
|
|
|
}
|
|
|
|
|
|
|
|
barbar:send {
|
|
|
|
rebarbar -> bar,
|
|
|
|
}
|
|
|
|
|
|
|
|
bazbar:send {
|
|
|
|
rebazbar -> bar
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
// select!
|
|
|
|
macro_rules! select_if {
|
2012-08-13 18:03:13 -05:00
|
|
|
|
|
|
|
{
|
|
|
|
$index:expr,
|
|
|
|
$count:expr
|
|
|
|
} => {
|
|
|
|
fail
|
|
|
|
};
|
|
|
|
|
2012-08-07 12:14:35 -05:00
|
|
|
{
|
|
|
|
$index:expr,
|
|
|
|
$count:expr,
|
|
|
|
$port:path => [
|
2012-08-13 18:03:13 -05:00
|
|
|
$(type_this $message:path$(($(x $x: ident),+))dont_type_this*
|
|
|
|
-> $next:ident => { $e:expr }),+
|
|
|
|
]
|
|
|
|
$(, $ports:path => [
|
|
|
|
$(type_this $messages:path$(($(x $xs: ident),+))dont_type_this*
|
|
|
|
-> $nexts:ident => { $es:expr }),+
|
|
|
|
] )*
|
2012-08-07 12:14:35 -05:00
|
|
|
} => {
|
|
|
|
if $index == $count {
|
2012-08-13 18:03:13 -05:00
|
|
|
match move pipes::try_recv($port) {
|
2012-08-07 12:14:35 -05:00
|
|
|
$(some($message($($($x,)+)* next)) => {
|
|
|
|
// FIXME (#2329) we really want move out of enum here.
|
|
|
|
let $next = unsafe { let x <- *ptr::addr_of(next); x };
|
|
|
|
$e
|
|
|
|
})+
|
|
|
|
_ => fail
|
|
|
|
}
|
|
|
|
} else {
|
|
|
|
select_if!{
|
|
|
|
$index,
|
2012-08-13 18:03:13 -05:00
|
|
|
$count + 1
|
|
|
|
$(, $ports => [
|
|
|
|
$(type_this $messages$(($(x $xs),+))dont_type_this*
|
|
|
|
-> $nexts => { $es }),+
|
|
|
|
])*
|
2012-08-07 12:14:35 -05:00
|
|
|
}
|
|
|
|
}
|
|
|
|
};
|
|
|
|
}
|
|
|
|
|
|
|
|
macro_rules! select {
|
|
|
|
{
|
|
|
|
$( $port:path => {
|
|
|
|
$($message:path$(($($x: ident),+))dont_type_this*
|
|
|
|
-> $next:ident $e:expr),+
|
|
|
|
} )+
|
|
|
|
} => {
|
|
|
|
let index = pipes::selecti([$(($port).header()),+]/_);
|
2012-08-13 18:03:13 -05:00
|
|
|
select_if!{index, 0 $(, $port => [
|
|
|
|
$(type_this $message$(($(x $x),+))dont_type_this* -> $next => { $e }),+
|
|
|
|
])+}
|
2012-08-07 12:14:35 -05:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
// Code
|
|
|
|
fn test(+foo: foo::client::foo, +bar: bar::client::bar) {
|
2012-08-13 18:03:13 -05:00
|
|
|
import bar::do_baz;
|
|
|
|
|
2012-08-07 12:14:35 -05:00
|
|
|
select! {
|
|
|
|
foo => {
|
|
|
|
foo::do_foo -> _next {
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
bar => {
|
|
|
|
bar::do_bar(x) -> _next {
|
2012-08-13 18:03:13 -05:00
|
|
|
debug!("%?", x)
|
2012-08-07 12:14:35 -05:00
|
|
|
},
|
|
|
|
|
|
|
|
do_baz(b) -> _next {
|
2012-08-13 18:03:13 -05:00
|
|
|
if b { debug!("true") } else { debug!("false") }
|
2012-08-07 12:14:35 -05:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
fn main() {
|
|
|
|
}
|