[b6ad601] | 1 | // |
---|
| 2 | // Cforall Version 1.0.0 Copyright (C) 2015 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 | // |
---|
[dc8511c] | 7 | // loopctrl.cfa -- |
---|
[b6ad601] | 8 | // |
---|
| 9 | // Author : Peter A. Buhr |
---|
| 10 | // Created On : Wed Aug 8 18:32:59 2018 |
---|
| 11 | // Last Modified By : Peter A. Buhr |
---|
[9853d9b0] | 12 | // Last Modified On : Thu Dec 12 17:55:26 2019 |
---|
| 13 | // Update Count : 108 |
---|
[b6ad601] | 14 | // |
---|
| 15 | |
---|
| 16 | #include <fstream.hfa> |
---|
| 17 | |
---|
| 18 | struct S { int i, j; }; |
---|
| 19 | void ?{}( S & s ) { s.[i, j] = 0; } |
---|
| 20 | void ?{}( S & s, int i ) { s.[i, j] = [i, 0]; } |
---|
| 21 | void ?{}( S & s, int i, int j ) { s.[i, j] = [i, j]; } |
---|
| 22 | void ?{}( S & s, zero_t ) { s.[i, j] = 0; } |
---|
| 23 | void ?{}( S & s, one_t ) { s.[i, j] = 1; } |
---|
| 24 | int ?<?( S t1, S t2 ) { return t1.i < t2.i && t1.j < t2.j; } |
---|
| 25 | int ?<=?( S t1, S t2 ) { return t1.i <= t2.i && t1.j <= t2.j; } |
---|
| 26 | int ?>?( S t1, S t2 ) { return t1.i > t2.i && t1.j > t2.j; } |
---|
| 27 | int ?>=?( S t1, S t2 ) { return t1.i >= t2.i && t1.j >= t2.j; } |
---|
| 28 | S ?=?( S & t1, S t2 ) { t1.i = t2.i; t1.j = t2.j; return t1; } |
---|
| 29 | S ?+=?( S & t1, S t2 ) { t1.i += t2.i; t1.j += t2.j; return t1; } |
---|
| 30 | S ?+=?( S & t, one_t ) { t.i += 1; t.j += 1; return t; } |
---|
| 31 | S ?-=?( S & t1, S t2 ) { t1.i -= t2.i; t1.j -= t2.j; return t1; } |
---|
| 32 | S ?-=?( S & t, one_t ) { t.i -= 1; t.j -= 1; return t; } |
---|
| 33 | ofstream & ?|?( ofstream & os, S v ) { return os | '(' | v.i | v.j | ')'; } |
---|
[65240bb] | 34 | void & ?|?( ofstream & os, S v ) { (ofstream &)(os | v); ends( os ); } |
---|
[b6ad601] | 35 | |
---|
| 36 | int main() { |
---|
[200fcb3] | 37 | sout | nlOff; // turn off auto newline |
---|
| 38 | while () { sout | "empty"; break; } sout | nl; |
---|
| 39 | do { sout | "empty"; break; } while (); sout | nl; |
---|
[5ea5b28] | 40 | for () { sout | "empty"; break; } sout | nl | nl; |
---|
[b6ad601] | 41 | |
---|
[200fcb3] | 42 | for ( 0 ) { sout | "A"; } sout | "zero" | nl; |
---|
| 43 | for ( 1 ) { sout | "A"; } sout | nl; |
---|
| 44 | for ( 10 ) { sout | "A"; } sout | nl; |
---|
[9853d9b0] | 45 | for ( = 10 ) { sout | "A"; } sout | nl; |
---|
[200fcb3] | 46 | for ( 1 ~= 10 ~ 2 ) { sout | "B"; } sout | nl; |
---|
| 47 | for ( 10 -~= 1 ~ 2 ) { sout | "C"; } sout | nl; |
---|
| 48 | for ( 0.5 ~ 5.5 ) { sout | "D"; } sout | nl; |
---|
| 49 | for ( 5.5 -~ 0.5 ) { sout | "E"; } sout | nl | nl; |
---|
[b6ad601] | 50 | |
---|
[200fcb3] | 51 | for ( i; 10 ) { sout | i; } sout | nl; |
---|
[9853d9b0] | 52 | for ( i; = 10 ) { sout | i; } sout | nl; |
---|
[200fcb3] | 53 | for ( i; 1 ~= 10 ~ 2 ) { sout | i; } sout | nl; |
---|
| 54 | for ( i; 10 -~= 1 ~ 2 ) { sout | i; } sout | nl; |
---|
| 55 | for ( i; 0.5 ~ 5.5 ) { sout | i; } sout | nl; |
---|
| 56 | for ( i; 5.5 -~ 0.5 ) { sout | i; } sout | nl; |
---|
| 57 | for ( ui; 2u ~= 10u ~ 2u ) { sout | ui; } sout | nl; |
---|
[1b54b54] | 58 | for ( ui; 10u -~= 2u ~ 2u ) { sout | ui; } sout | nl | nl; |
---|
[b6ad601] | 59 | |
---|
[67d4e37] | 60 | // @ means do nothing |
---|
| 61 | for ( i; 1 ~ @ ) { |
---|
| 62 | if ( i > 10 ) break; |
---|
| 63 | sout | i; |
---|
| 64 | } sout | nl; |
---|
| 65 | for ( i; 10 -~ @ ) { |
---|
| 66 | if ( i < 0 ) break; |
---|
| 67 | sout | i; |
---|
| 68 | } sout | nl; |
---|
[1b54b54] | 69 | for ( i; 2 ~ @ ~ 2 ) { |
---|
| 70 | if ( i > 10 ) break; |
---|
| 71 | sout | i; |
---|
| 72 | } sout | nl; |
---|
| 73 | for ( i; 2.1 ~ @ ~ @ ) { |
---|
| 74 | if ( i > 10.5 ) break; |
---|
| 75 | sout | i; |
---|
| 76 | i += 1.7; |
---|
| 77 | } sout | nl; |
---|
| 78 | for ( i; 10 -~ @ ~ 2 ) { |
---|
| 79 | if ( i < 0 ) break; |
---|
| 80 | sout | i; |
---|
| 81 | } sout | nl; |
---|
| 82 | for ( i; 12.1 ~ @ ~ @ ) { |
---|
| 83 | if ( i < 2.5 ) break; |
---|
| 84 | sout | i; |
---|
| 85 | i -= 1.7; |
---|
| 86 | } sout | nl | nl; |
---|
| 87 | |
---|
[61dafb8] | 88 | enum { N = 10 }; |
---|
[200fcb3] | 89 | for ( N ) { sout | "N"; } sout | nl; |
---|
| 90 | for ( i; N ) { sout | i; } sout | nl; |
---|
[9853d9b0] | 91 | for ( i; = N ) { sout | i; } sout | nl; |
---|
[1b54b54] | 92 | for ( i; N -~ 0 ) { sout | i; } sout | nl | nl; |
---|
[61dafb8] | 93 | |
---|
[dc8511c] | 94 | const int start = 3, comp = 10, inc = 2; |
---|
[200fcb3] | 95 | for ( i; start ~ comp ~ inc + 1 ) { sout | i; } sout | nl | nl; |
---|
[b6ad601] | 96 | |
---|
[200fcb3] | 97 | for ( S s = (S){0}; s < (S){10,10}; s += (S){1} ) { sout | s; } sout | nl; |
---|
| 98 | for ( s; (S){10,10} ) { sout | s; } sout | nl; |
---|
| 99 | sout | nl; |
---|
| 100 | for ( s; (S){0} ~ (S){10,10} ) { sout | s; } sout | nl; |
---|
| 101 | for ( s; (S){0} ~ (S){10,10} ~ (S){1} ) { sout | s; } sout | nl; |
---|
| 102 | for ( s; (S){0} ~= (S){10,10} ) { sout | s; } sout | nl; |
---|
| 103 | for ( s; (S){0} ~= (S){10,10} ~ (S){1} ) { sout | s; } sout | nl; |
---|
| 104 | sout | nl; |
---|
| 105 | for ( s; (S){10,10} -~ (S){0} ) { sout | s; } sout | nl; |
---|
| 106 | for ( s; (S){10,10} -~ (S){0} ~ (S){1} ) { sout | s; } sout | nl; |
---|
| 107 | for ( s; (S){10,10} -~= (S){0} ) { sout | s; } sout | nl; |
---|
[67d4e37] | 108 | for ( s; (S){10,10} -~= (S){0} ~ (S){1} ) { sout | s; } sout | nl | nl; |
---|
| 109 | |
---|
| 110 | for ( i; 10 : j; -5 ~ @ ) { sout | i | j; } sout | nl; |
---|
| 111 | for ( i; 10 : j; -5 -~ @ ) { sout | i | j; } sout | nl; |
---|
| 112 | for ( i; 10 : j; -5 ~ @ ~ 2 ) { sout | i | j; } sout | nl; |
---|
| 113 | for ( i; 10 : j; -5 -~ @ ~ 2 ) { sout | i | j; } sout | nl | nl; |
---|
| 114 | |
---|
| 115 | for ( j; -5 ~ @ : i; 10 ) { sout | i | j; } sout | nl; |
---|
| 116 | for ( j; -5 -~ @ : i; 10 ) { sout | i | j; } sout | nl; |
---|
| 117 | for ( j; -5 ~ @ ~ 2 : i; 10 ) { sout | i | j; } sout | nl; |
---|
| 118 | for ( j; -5 -~ @ ~ 2 : i; 10 ) { sout | i | j; } sout | nl | nl; |
---|
| 119 | |
---|
| 120 | for ( j; -5 -~ @ ~ 2 : i; 10 : k; 1.5 ~ @ ) { sout | i | j | k; } sout | nl; |
---|
| 121 | for ( j; -5 -~ @ ~ 2 : k; 1.5 ~ @ : i; 10 ) { sout | i | j | k; } sout | nl; |
---|
| 122 | for ( k; 1.5 ~ @ : j; -5 -~ @ ~ 2 : i; 10 ) { sout | i | j | k; } sout | nl; |
---|
[b6ad601] | 123 | } |
---|
| 124 | |
---|
| 125 | // Local Variables: // |
---|
| 126 | // tab-width: 4 // |
---|
[dc8511c] | 127 | // compile-command: "cfa loopctrl.cfa" // |
---|
[b6ad601] | 128 | // End: // |
---|