ADTaaron-thesisarm-ehast-experimentalcleanup-dtorsdeferred_resndemanglerenumforall-pointer-decayjacob/cs343-translationjenkins-sandboxnew-astnew-ast-unique-exprnew-envno_listpersistent-indexerpthread-emulationqualifiedEnumresolv-newwith_gc
Last change
on this file since c15b805 was
c15b805,
checked in by Thierry Delisle <tdelisle@…>, 8 years ago
|
added skeleton for coroutines to cfa
|
-
Property mode set to
100644
|
File size:
935 bytes
|
Line | |
---|
1 | #include <fstream> |
---|
2 | #include "../libcfa/kernel/kernel.h" |
---|
3 | |
---|
4 | struct Fibonacci { |
---|
5 | coroutine c; |
---|
6 | int fn; // used for communication |
---|
7 | }; |
---|
8 | |
---|
9 | void ?{}(Fibonacci* this) { |
---|
10 | this->fn = 0; |
---|
11 | } |
---|
12 | |
---|
13 | coroutine* this_coroutine(Fibonacci* this) { |
---|
14 | |
---|
15 | } |
---|
16 | |
---|
17 | void co_main(Fibonacci* this) { |
---|
18 | int fn1, fn2; // retained between resumes |
---|
19 | this->fn = 0; |
---|
20 | fn1 = this->fn; |
---|
21 | suspend(this); // return to last resume |
---|
22 | |
---|
23 | this->fn = 1; |
---|
24 | fn2 = fn1; |
---|
25 | fn1 = this->fn; |
---|
26 | suspend(this); // return to last resume |
---|
27 | |
---|
28 | for ( ;; ) { |
---|
29 | this->fn = fn1 + fn2; |
---|
30 | fn2 = fn1; |
---|
31 | fn1 = this->fn; |
---|
32 | suspend(this); // return to last resume |
---|
33 | } |
---|
34 | } |
---|
35 | |
---|
36 | int next(Fibonacci* this) { |
---|
37 | resume(this); // transfer to last suspend |
---|
38 | return this->fn; |
---|
39 | } |
---|
40 | |
---|
41 | void main() { |
---|
42 | Fibonacci f1, f2; |
---|
43 | for ( int i = 1; i <= 10; i += 1 ) { |
---|
44 | sout | next(&f1) | ' ' | next(&f2) | endl; |
---|
45 | } |
---|
46 | } |
---|
Note: See
TracBrowser
for help on using the repository browser.