ADT
arm-eh
ast-experimental
cleanup-dtors
enum
forall-pointer-decay
jacob/cs343-translation
jenkins-sandbox
new-ast
new-ast-unique-expr
pthread-emulation
qualifiedEnum
Last change
on this file since d3c1c6a was 17c6c1c3, checked in by Peter A. Buhr <pabuhr@…>, 7 years ago |
add more paper examples
|
-
Property mode
set to
100644
|
File size:
955 bytes
|
Rev | Line | |
---|
[17c6c1c3] | 1 | #include <coroutine.hfa>
|
---|
| 2 | #include <fstream.hfa>
|
---|
| 3 |
|
---|
| 4 | coroutine PingPong {
|
---|
| 5 | const char * name;
|
---|
| 6 | /* const */ unsigned int N;
|
---|
| 7 | PingPong * part;
|
---|
| 8 | };
|
---|
| 9 |
|
---|
| 10 | void ?{}( PingPong & this, const char * name, unsigned int N, PingPong & part ) {
|
---|
| 11 | (this.__cor){name};
|
---|
| 12 | this.name = name;
|
---|
| 13 | this.N = N;
|
---|
| 14 | this.part = ∂
|
---|
| 15 | }
|
---|
| 16 | void ?{}( PingPong & this, const char * name, unsigned int N ) {
|
---|
| 17 | this{ name, N, *(PingPong *)0 };
|
---|
| 18 | }
|
---|
| 19 | void cycle( PingPong & pingpong ) {
|
---|
| 20 | resume( pingpong );
|
---|
| 21 | }
|
---|
| 22 | void partner( PingPong & this, PingPong & part ) {
|
---|
| 23 | this.part = ∂
|
---|
| 24 | resume( this );
|
---|
| 25 | }
|
---|
| 26 | void main( PingPong & pingpong ) { // ping's starter ::main, pong's starter ping
|
---|
| 27 | for ( pingpong.N ) { // N ping-pongs
|
---|
| 28 | sout | pingpong.name;
|
---|
| 29 | cycle( *pingpong.part );
|
---|
| 30 | } // for
|
---|
| 31 | }
|
---|
| 32 | int main() {
|
---|
| 33 | enum { N = 20 };
|
---|
| 34 | PingPong ping = { "ping", N }, pong = { "pong", N, ping };
|
---|
| 35 | partner( ping, pong );
|
---|
| 36 | }
|
---|
| 37 |
|
---|
| 38 | // Local Variables: //
|
---|
| 39 | // tab-width: 4 //
|
---|
| 40 | // compile-command: "cfa pingpong.cfa" //
|
---|
| 41 | // End: //
|
---|
Note:
See
TracBrowser
for help on using the repository browser.