Skip to content

Commit 0777cef

Browse files
committed
---
yaml --- r: 22736 b: refs/heads/master c: f65d602 h: refs/heads/master v: v3
1 parent 58274f6 commit 0777cef

File tree

2 files changed

+73
-7
lines changed

2 files changed

+73
-7
lines changed

[refs]

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
---
2-
refs/heads/master: 6535da84176bb1a72871a89740b0def9221cc351
2+
refs/heads/master: f65d6026ef84d16e5b27ab4c852df46044091e2d
33
refs/heads/snap-stage1: e33de59e47c5076a89eadeb38f4934f58a3618a6
44
refs/heads/snap-stage3: cd6f24f9d14ac90d167386a56e7a6ac1f0318195
55
refs/heads/try: ffbe0e0e00374358b789b0037bcb3a577cd218be

trunk/src/test/run-pass/pipe-bank-proto.rs

Lines changed: 72 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -32,20 +32,86 @@ proto! bank {
3232
}
3333
}
3434

35-
fn macros() {
36-
#macro[
37-
[#move[x],
38-
unsafe { let y <- *ptr::addr_of(x); y }]
39-
];
35+
macro_rules! move {
36+
{ $x:expr } => { unsafe { let y <- *ptr::addr_of($x); y } }
4037
}
4138

39+
fn switch<T: send, U>(+endp: pipes::recv_packet<T>,
40+
f: fn(+option<T>) -> U) -> U {
41+
f(pipes::try_recv(endp))
42+
}
43+
44+
fn move<T>(-x: T) -> T { x }
45+
46+
macro_rules! follow {
47+
{
48+
$($message:path($($x: ident),+) => $next:ident $e:expr)+
49+
} => (
50+
|m| alt move(m) {
51+
$(some($message($($x,)* next)) {
52+
let $next = move!{next};
53+
$e })+
54+
_ { fail }
55+
}
56+
);
57+
58+
{
59+
$($message:path => $next:ident $e:expr)+
60+
} => (
61+
|m| alt move(m) {
62+
$(some($message(next)) {
63+
let $next = move!{next};
64+
$e })+
65+
_ { fail }
66+
}
67+
)
68+
}
69+
70+
/*
71+
fn client_follow(+bank: bank::client::login) {
72+
import bank::*;
73+
74+
let bank = client::login(bank, ~"theincredibleholk", ~"1234");
75+
let bank = switch(bank, follow! {
76+
ok => connected { connected }
77+
invalid => _next { fail ~"bank closed the connected" }
78+
});
79+
80+
/* // potential alternate syntax
81+
let bank = recv_alt! {
82+
bank => {
83+
| ok -> connected { connected }
84+
| invalid -> _next { fail }
85+
}
86+
bank2 => {
87+
| foo -> _n { fail }
88+
}
89+
}
90+
*/
91+
92+
let bank = client::deposit(bank, 100.00);
93+
let bank = client::withdrawal(bank, 50.00);
94+
alt try_recv(bank) {
95+
some(money(m, _)) {
96+
io::println(~"Yay! I got money!");
97+
}
98+
some(insufficient_funds(_)) {
99+
fail ~"someone stole my money"
100+
}
101+
none {
102+
fail ~"bank closed the connection"
103+
}
104+
}
105+
}
106+
*/
107+
42108
fn bank_client(+bank: bank::client::login) {
43109
import bank::*;
44110

45111
let bank = client::login(bank, ~"theincredibleholk", ~"1234");
46112
let bank = alt try_recv(bank) {
47113
some(ok(connected)) {
48-
#move(connected)
114+
move!{connected}
49115
}
50116
some(invalid(_)) { fail ~"login unsuccessful" }
51117
none { fail ~"bank closed the connection" }

0 commit comments

Comments
 (0)