|
| 1 | +// xfail-test |
| 2 | + |
| 3 | +// Protocols |
| 4 | +proto! foo { |
| 5 | + foo:recv { |
| 6 | + do_foo -> foo |
| 7 | + } |
| 8 | +} |
| 9 | + |
| 10 | +proto! bar { |
| 11 | + bar:recv { |
| 12 | + do_bar(int) -> barbar, |
| 13 | + do_baz(bool) -> bazbar, |
| 14 | + } |
| 15 | + |
| 16 | + barbar:send { |
| 17 | + rebarbar -> bar, |
| 18 | + } |
| 19 | + |
| 20 | + bazbar:send { |
| 21 | + rebazbar -> bar |
| 22 | + } |
| 23 | +} |
| 24 | + |
| 25 | + |
| 26 | +// select! |
| 27 | +macro_rules! select_if { |
| 28 | + { |
| 29 | + $index:expr, |
| 30 | + $count:expr, |
| 31 | + $port:path => [ |
| 32 | + $($message:path$(($($x: ident),+))dont_type_this* |
| 33 | + -> $next:ident $e:expr),+ |
| 34 | + ], |
| 35 | + $( $ports:path => [ |
| 36 | + $($messages:path$(($($xs: ident),+))dont_type_this* |
| 37 | + -> $nexts:ident $es:expr),+ |
| 38 | + ], )* |
| 39 | + } => { |
| 40 | + log_syntax!{select_if1}; |
| 41 | + if $index == $count { |
| 42 | + alt move pipes::try_recv($port) { |
| 43 | + $(some($message($($($x,)+)* next)) => { |
| 44 | + // FIXME (#2329) we really want move out of enum here. |
| 45 | + let $next = unsafe { let x <- *ptr::addr_of(next); x }; |
| 46 | + $e |
| 47 | + })+ |
| 48 | + _ => fail |
| 49 | + } |
| 50 | + } else { |
| 51 | + select_if!{ |
| 52 | + $index, |
| 53 | + $count + 1, |
| 54 | + $( $ports => [ |
| 55 | + $($messages$(($($xs),+))dont_type_this* |
| 56 | + -> $nexts $es),+ |
| 57 | + ], )* |
| 58 | + } |
| 59 | + } |
| 60 | + }; |
| 61 | + |
| 62 | + { |
| 63 | + $index:expr, |
| 64 | + $count:expr, |
| 65 | + } => { |
| 66 | + log_syntax!{select_if2}; |
| 67 | + fail |
| 68 | + } |
| 69 | +} |
| 70 | + |
| 71 | +macro_rules! select { |
| 72 | + { |
| 73 | + $( $port:path => { |
| 74 | + $($message:path$(($($x: ident),+))dont_type_this* |
| 75 | + -> $next:ident $e:expr),+ |
| 76 | + } )+ |
| 77 | + } => { |
| 78 | + let index = pipes::selecti([$(($port).header()),+]/_); |
| 79 | + log_syntax!{select}; |
| 80 | + log_syntax!{ |
| 81 | + select_if!{index, 0, $( $port => [ |
| 82 | + $($message$(($($x),+))dont_type_this* -> $next $e),+ |
| 83 | + ], )+} |
| 84 | + }; |
| 85 | + select_if!{index, 0, $( $port => [ |
| 86 | + $($message$(($($x),+))dont_type_this* -> $next $e),+ |
| 87 | + ], )+} |
| 88 | + } |
| 89 | +} |
| 90 | + |
| 91 | +// Code |
| 92 | +fn test(+foo: foo::client::foo, +bar: bar::client::bar) { |
| 93 | + select! { |
| 94 | + foo => { |
| 95 | + foo::do_foo -> _next { |
| 96 | + } |
| 97 | + } |
| 98 | + |
| 99 | + bar => { |
| 100 | + bar::do_bar(x) -> _next { |
| 101 | + //debug!("%?", x) |
| 102 | + }, |
| 103 | + |
| 104 | + do_baz(b) -> _next { |
| 105 | + //if b { debug!("true") } else { debug!("false") } |
| 106 | + } |
| 107 | + } |
| 108 | + } |
| 109 | +} |
| 110 | + |
| 111 | +fn main() { |
| 112 | +} |
0 commit comments