source: tests/generator/suspend_then.cfa @ e84ab3d

ADTast-experimentalenumforall-pointer-decayjacob/cs343-translationnew-ast-unique-exprpthread-emulationqualifiedEnum
Last change on this file since e84ab3d was 3720c9aa, checked in by Peter A. Buhr <pabuhr@…>, 3 years ago

formatting and indicate compiler bug

  • 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 : Peter A. Buhr
12// Last Modified On : Thu Jun 10 21:55:51 2021
13// Update Count     : 1
14//
15
16#include <fstream.hfa>
17
18generator Fibonacci {
19        int fn1, fn2;                                                           // retained between resumes
20        int fn;                                                                 // used for communication
21};
22
23void main( Fibonacci & fib ) with( fib ) {                              // called on first resume
24        fn = 0;  fn1 = fn;                                                      // 1st case
25        suspend { sout | "Then!"; }                                             // restart last resume
26        fn = 1;  fn2 = fn1;  fn1 = fn;                                  // 2nd case
27        suspend { sout | "Then!"; }                                             // restart last resume
28        for () {
29                fn = fn1 + fn2;  fn2 = fn1;  fn1 = fn;                  // general case
30                suspend { sout | "Then!"; }                                     // restart last resume
31        } // for
32}
33
34int next( Fibonacci & fib ) with( fib ) {
35        resume( fib );                                                          // restart last suspend
36        return fn;
37}
38
39int main() {
40        Fibonacci f1, f2;
41        for ( 10 ) {                                                            // print N Fibonacci values
42                int v1 = next( f1 );
43                int v2 = next( f2 );
44                sout | v1 | v2;
45        } // for
46}
47
48// Local Variables: //
49// tab-width: 4 //
50// compile-command: "cfa runningTotal.cfa" //
51// End: //
Note: See TracBrowser for help on using the repository browser.