Changeset ff29f08 for src/tests/coroutine
- Timestamp:
- May 18, 2018, 2:09:21 PM (8 years ago)
- Branches:
- new-env, with_gc
- Children:
- 2472a19
- Parents:
- f6f0cca3 (diff), c7d8100c (diff)
Note: this is a merge changeset, the changes displayed below correspond to the merge itself.
Use the(diff)links above to see all the changes relative to each parent. - Location:
- src/tests/coroutine
- Files:
-
- 2 edited
-
fibonacci.c (modified) (3 diffs)
-
fmtLines.c (modified) (3 diffs)
Legend:
- Unmodified
- Added
- Removed
-
src/tests/coroutine/fibonacci.c
rf6f0cca3 rff29f08 5 5 // file "LICENCE" distributed with Cforall. 6 6 // 7 // fibonacci.c -- 7 // fibonacci.c -- 3-state finite-state machine 8 8 9 // 9 10 // Author : Thierry Delisle 10 11 // Created On : Thu Jun 8 07:29:37 2017 11 12 // Last Modified By : Peter A. Buhr 12 // Last Modified On : Thu Mar 22 22:45:44201813 // Update Count : 1 513 // Last Modified On : Fri Apr 27 08:55:31 2018 14 // Update Count : 19 14 15 // 15 16 … … 19 20 coroutine Fibonacci { int fn; }; // used for communication 20 21 21 void ?{}( Fibonacci & fib ) with( fib ) { fn = 0; } 22 23 // main automatically called on first resume 24 void main( Fibonacci & fib ) with( fib ) { 22 void main( Fibonacci & fib ) with( fib ) { // called on first resume 25 23 int fn1, fn2; // retained between resumes 26 24 fn = 0; fn1 = fn; // 1st case … … 29 27 suspend(); // restart last resume 30 28 for ( ;; ) { 31 fn = fn1 + fn2; fn2 = fn1; fn1 = fn; // general case29 fn = fn1 + fn2; fn2 = fn1; fn1 = fn; // general case 32 30 suspend(); // restart last resume 33 31 } // for -
src/tests/coroutine/fmtLines.c
rf6f0cca3 rff29f08 5 5 // file "LICENCE" distributed with Cforall. 6 6 // 7 // fmtLines.cc -- 7 // fmtLines.cc -- format characters into blocks of 4 and groups of 5 blocks per line 8 8 // 9 9 // Author : Peter A. Buhr 10 10 // Created On : Sun Sep 17 21:56:15 2017 11 11 // Last Modified By : Peter A. Buhr 12 // Last Modified On : Tue Dec 5 21:56:35 201713 // Update Count : 3812 // Last Modified On : Tue May 15 12:25:33 2018 13 // Update Count : 42 14 14 // 15 15 … … 21 21 int g, b; // global because used in destructor 22 22 }; 23 24 void ?{}( Format & fmt ) {25 resume( fmt ); // prime (start) coroutine26 }27 28 void ^?{}( Format & fmt ) with( fmt ) {29 if ( g != 0 || b != 0 ) sout | endl;30 }31 23 32 24 void main( Format & fmt ) with( fmt ) { … … 46 38 } // main 47 39 48 void prt( Format & fmt, char ch ) { 49 fmt.ch = ch; 40 void ?{}( Format & fmt ) { 41 resume( fmt ); // prime (start) coroutine 42 } 43 44 void ^?{}( Format & fmt ) with( fmt ) { 45 if ( g != 0 || b != 0 ) sout | endl; 46 } 47 48 void format( Format & fmt ) { 50 49 resume( fmt ); 51 50 } // prt 52 51 53 52 int main() { 54 Format fmt; // format characters into blocks of 4 and groups of 5 blocks per line 55 char ch; 53 Format fmt; 56 54 57 Eof: for ( ;; ) { // read until end of file58 sin | ch;// read one character59 if ( eof( sin ) ) break Eof; // eof ?60 prt( fmt, ch); // push character for formatting55 eof: for ( ;; ) { // read until end of file 56 sin | fmt.ch; // read one character 57 if ( eof( sin ) ) break eof; // eof ? 58 format( fmt ); // push character for formatting 61 59 } // for 62 60 } // main
Note:
See TracChangeset
for help on using the changeset viewer.