source: tests/coroutine/suspend_then.cfa @ 427854b

ADTarm-ehast-experimentalenumforall-pointer-decayjacob/cs343-translationjenkins-sandboxnew-astnew-ast-unique-exprpthread-emulationqualifiedEnum
Last change on this file since 427854b was 427854b, checked in by Thierry Delisle <tdelisle@…>, 4 years ago

First draft implementation of generators, still missing error checking, testing and clean-up

  • Property mode set to 100644
File size: 1.3 KB
Line 
1//
2// Cforall Version 1.0.0 Copyright (C) 2019 University of Waterloo
3//
4// The contents of this file are covered under the licence agreement in the
5// file "LICENCE" distributed with Cforall.
6//
7// suspend_then.cfa --
8//
9// Author           : Peter A. Buhr
10// Created On       : Mon Apr 29 12:01:35 2019
11// Last Modified By :
12// Last Modified On :
13// Update Count     :
14//
15
16#include <fstream.hfa>
17#include <coroutine.hfa>
18
19void then() {
20
21}
22
23coroutine Fibonacci { int fn; };                                                // used for communication
24
25void main( Fibonacci & fib ) with( fib ) {                              // called on first resume
26        int fn1, fn2;                                                           // retained between resumes
27        fn = 0;  fn1 = fn;                                                      // 1st case
28        suspend { sout | "Then!"; }                                             // restart last resume
29        fn = 1;  fn2 = fn1;  fn1 = fn;                                  // 2nd case
30        suspend { sout | "Then!"; }                                             // restart last resume
31        for () {
32                fn = fn1 + fn2;  fn2 = fn1;  fn1 = fn;                  // general case
33                suspend { sout | "Then!"; }                                     // restart last resume
34        } // for
35}
36
37int next( Fibonacci & fib ) with( fib ) {
38        resume( fib );                                                          // restart last suspend
39        return fn;
40}
41
42int main() {
43        Fibonacci f1, f2;
44        for ( 10 ) {                                                            // print N Fibonacci values
45                sout | next( f1 ) | next( f2 );
46        } // for
47}
48
49// Local Variables: //
50// tab-width: 4 //
51// compile-command: "cfa runningTotal.cfa" //
52// End: //
Note: See TracBrowser for help on using the repository browser.