- Timestamp:
- Jul 10, 2023, 3:45:12 PM (19 months ago)
- Branches:
- master
- Children:
- 04c31f4
- Parents:
- 555c599 (diff), 713905fd (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:
- tests/exceptions
- Files:
-
- 2 edited
- 2 moved
Legend:
- Unmodified
- Added
- Removed
-
tests/exceptions/.expect/fibonacci_nonlocal.txt
r555c599 rc3f7dd9 1 0 2 1 3 1 4 0 5 2 6 4 7 20 1 0 0 2 1 1 3 1 1 4 2 2 5 3 3 6 5 5 7 8 8 8 13 13 -
tests/exceptions/fibonacci_nonlocal.cfa
r555c599 rc3f7dd9 9 9 // Author : Colby Parsons 10 10 // Created On : Thu July 6 07:29:37 2023 11 // Last Modified By : Colby Parsons12 // Last Modified On : Thu Jul y 6 07:29:37202313 // Update Count : 011 // Last Modified By : Peter A. Buhr 12 // Last Modified On : Thu Jul 6 21:49:04 2023 13 // Update Count : 18 14 14 // 15 15 … … 18 18 #include <stdlib.hfa> 19 19 20 exception fib_num { 21 int num; 22 }; 20 exception fib_num {}; 23 21 vtable(fib_num) fib_num_vt; 24 25 exception fib_2_num { 26 int num1, num2; 27 }; 28 vtable(fib_2_num) fib_2_num_vt; 22 fib_num except{ &fib_num_vt }; 29 23 30 24 coroutine Fibonacci { int fn; }; // used for communication 31 25 32 26 void main( Fibonacci & fib ) with( fib ) { // called on first resume 33 int fn1, fn2; // retained between resumes 34 try{ 35 fn = 0; fn1 = fn; // 1st case 36 poll( fib ); 37 suspend; // restart last resume 38 fn = 1; fn2 = fn1; fn1 = fn; // 2nd case 39 poll( fib ); 40 suspend; // restart last resume 41 for () { 42 fn = fn1 + fn2; fn2 = fn1; fn1 = fn; // general case 43 poll( fib ); 44 suspend; // restart last resume 45 } // for 46 } catchResume ( fib_num * e ) { 47 fn1 = e->num; 48 fn2 = e->num; 49 fn = fn1 + fn2; 50 } catchResume ( fib_2_num * e ) { 51 fn1 = e->num1; 52 fn2 = e->num1; 53 fn = fn1 + fn2; 54 } 27 int fn1, fn2; // retained between resumes 28 try { 29 poll( fib ); 30 suspend; // restart last resume 31 } catchResume ( fib_num * e ) { 32 fn = 0; fn1 = fn; // 1st case 33 } 34 try { 35 poll( fib ); 36 suspend; // restart last resume 37 } catchResume ( fib_num * e ) { 38 fn = 1; fn2 = fn1; fn1 = fn; // 2nd case 39 } 40 try { 41 for () { 42 poll( fib ); 43 suspend; // restart last resume 44 } // for 45 } catchResume ( fib_num * e ) { 46 fn = fn1 + fn2; fn2 = fn1; fn1 = fn; // general case 47 } 55 48 } 56 49 57 50 int main() { 58 51 Fibonacci f1, f2; 59 for ( 3 ) { // print N Fibonacci values 60 sout | resume( f1 ).fn; 61 } // for 62 for ( i; 3 ) { 63 fib_num except{ &fib_num_vt, i }; 64 resumeAt( f1, except ); 65 sout | resume( f1 ).fn; 66 } 67 { 68 fib_2_num except{ &fib_2_num_vt, 10, 12 }; 69 resumeAt( f1, except ); 70 } 71 sout | resume( f1 ).fn; 52 for ( i; 8 ) { 53 resumeAt( f1, except ); resumeAt( f2, except ); 54 sout | wd( 5, resume( f1 ).fn ) | wd( 5, resume( f2 ).fn ); 55 } 72 56 } 73 57 74 58 // Local Variables: // 75 // tab-width: 4 // 76 // compile-command: "cfa fibonacci.cfa" // 59 // compile-command: "cfa fibonacci_nonlocal.cfa" // 77 60 // End: //
Note: See TracChangeset
for help on using the changeset viewer.