]> git.proxmox.com Git - rustc.git/blob - src/test/run-pass/select-macro.rs
Imported Upstream version 0.7
[rustc.git] / src / test / run-pass / select-macro.rs
1 // Copyright 2012 The Rust Project Developers. See the COPYRIGHT
2 // file at the top-level directory of this distribution and at
3 // http://rust-lang.org/COPYRIGHT.
4 //
5 // Licensed under the Apache License, Version 2.0 <LICENSE-APACHE or
6 // http://www.apache.org/licenses/LICENSE-2.0> or the MIT license
7 // <LICENSE-MIT or http://opensource.org/licenses/MIT>, at your
8 // option. This file may not be copied, modified, or distributed
9 // except according to those terms.
10
11 // xfail-test - this isn't really a test.
12
13 {
14
15 // select!
16 macro_rules! select_if (
17
18 {
19 $index:expr,
20 $count:expr
21 } => {
22 fail!()
23 };
24
25 {
26 $index:expr,
27 $count:expr,
28 $port:path => [
29 $(type_this $message:path$(($(x $x: ident),+))dont_type_this*
30 -> $next:ident => { $e:expr }),+
31 ]
32 $(, $ports:path => [
33 $(type_this $messages:path$(($(x $xs: ident),+))dont_type_this*
34 -> $nexts:ident => { $es:expr }),+
35 ] )*
36 } => {
37 if $index == $count {
38 match pipes::try_recv($port) {
39 $(Some($message($($($x,)+)* next)) => {
40 let $next = next;
41 $e
42 })+
43 _ => fail!()
44 }
45 } else {
46 select_if!(
47 $index,
48 $count + 1
49 $(, $ports => [
50 $(type_this $messages$(($(x $xs),+))dont_type_this*
51 -> $nexts => { $es }),+
52 ])*
53 )
54 }
55 };
56 )
57
58 macro_rules! select (
59 {
60 $( $port:path => {
61 $($message:path$(($($x: ident),+))dont_type_this*
62 -> $next:ident $e:expr),+
63 } )+
64 } => {
65 let index = pipes::selecti([$(($port).header()),+]);
66 select_if!(index, 0 $(, $port => [
67 $(type_this $message$(($(x $x),+))dont_type_this* -> $next => { $e }),+
68 ])+)
69 }
70 )
71
72 }