source: tests/loopctrl.cfa @ 0c81320

ADTarm-ehast-experimentalcleanup-dtorsenumforall-pointer-decayjacob/cs343-translationjenkins-sandboxnew-astnew-ast-unique-exprpthread-emulationqualifiedEnum
Last change on this file since 0c81320 was 1b54b54, checked in by Peter A. Buhr <pabuhr@…>, 5 years ago

add decrement to new for control, add tests for it

  • Property mode set to 100644
File size: 3.7 KB
Line 
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//
7// loopctrl.cfa --
8//
9// Author           : Peter A. Buhr
10// Created On       : Wed Aug  8 18:32:59 2018
11// Last Modified By : Peter A. Buhr
12// Last Modified On : Thu Feb 21 08:54:47 2019
13// Update Count     : 86
14//
15
16#include <fstream.hfa>
17
18struct S { int i, j; };
19void ?{}( S & s ) { s.[i, j] = 0; }
20void ?{}( S & s, int i ) { s.[i, j] = [i, 0]; }
21void ?{}( S & s, int i, int j ) { s.[i, j] = [i, j]; }
22void ?{}( S & s, zero_t ) { s.[i, j] = 0; }
23void ?{}( S & s, one_t ) { s.[i, j] = 1; }
24int ?<?( S t1, S t2 ) { return t1.i < t2.i && t1.j < t2.j; }
25int ?<=?( S t1, S t2 ) { return t1.i <= t2.i && t1.j <= t2.j; }
26int ?>?( S t1, S t2 ) { return t1.i > t2.i && t1.j > t2.j; }
27int ?>=?( S t1, S t2 ) { return t1.i >= t2.i && t1.j >= t2.j; }
28S ?=?( S & t1, S t2 ) { t1.i = t2.i; t1.j = t2.j; return t1; }
29S ?+=?( S & t1, S t2 ) { t1.i += t2.i; t1.j += t2.j; return t1; }
30S ?+=?( S & t, one_t ) { t.i += 1; t.j += 1; return t; }
31S ?-=?( S & t1, S t2 ) { t1.i -= t2.i; t1.j -= t2.j; return t1; }
32S ?-=?( S & t, one_t ) { t.i -= 1; t.j -= 1; return t; }
33ofstream & ?|?( ofstream & os, S v ) { return os | '(' | v.i | v.j | ')'; }
34void & ?|?( ofstream & os, S v ) { (ofstream &)(os | v); nl( os ); }
35
36int main() {
37        sout | nlOff;                                                                           // turn off auto newline
38        while () { sout | "empty"; break; }                                     sout | nl;
39        do { sout | "empty"; break; } while ();                         sout | nl;
40        for () { sout | "empty"; break; }                                       sout | nl | nl;
41
42        for ( 0 ) { sout | "A"; }                                                       sout | "zero" | nl;
43        for ( 1 ) { sout | "A"; }                                                       sout | nl;
44        for ( 10 ) { sout | "A"; }                                                      sout | nl;
45        for ( 1 ~= 10 ~ 2 ) { sout | "B"; }                                     sout | nl;
46        for ( 10 -~= 1 ~ 2 ) { sout | "C"; }                            sout | nl;
47        for ( 0.5 ~ 5.5 ) { sout | "D"; }                                       sout | nl;
48        for ( 5.5 -~ 0.5 ) { sout | "E"; }                                      sout | nl | nl;
49
50        for ( i; 10 ) { sout | i; }                                                     sout | nl;
51        for ( i; 1 ~= 10 ~ 2 ) { sout | i; }                            sout | nl;
52        for ( i; 10 -~= 1 ~ 2 ) { sout | i; }                           sout | nl;
53        for ( i; 0.5 ~ 5.5 ) { sout | i; }                                      sout | nl;
54        for ( i; 5.5 -~ 0.5 ) { sout | i; }                                     sout | nl;
55        for ( ui; 2u ~= 10u ~ 2u ) { sout | ui; }                       sout | nl;
56        for ( ui; 10u -~= 2u ~ 2u ) { sout | ui; }                      sout | nl | nl;
57
58        for ( i; 2 ~ @ ~ 2 ) {
59          if ( i > 10 ) break;
60                sout | i;
61        }                                                                                                       sout | nl;
62        for ( i; 2.1 ~ @ ~ @ ) {
63          if ( i > 10.5 ) break;
64                sout | i;
65                i += 1.7;
66        }                                                                                                       sout | nl;
67        for ( i; 10 -~ @ ~ 2 ) {
68          if ( i < 0 ) break;
69                sout | i;
70        }                                                                                                       sout | nl;
71        for ( i; 12.1 ~ @ ~ @ ) {
72          if ( i < 2.5 ) break;
73                sout | i;
74                i -= 1.7;
75        }                                                                                                       sout | nl | nl;
76       
77        enum { N = 10 };
78        for ( N ) { sout | "N"; }                                                       sout | nl;
79        for ( i; N ) { sout | i; }                                                      sout | nl;
80        for ( i; N -~ 0 ) { sout | i; }                                         sout | nl | nl;
81
82        const int start = 3, comp = 10, inc = 2;
83        for ( i; start ~ comp ~ inc + 1 ) { sout | i; }         sout | nl | nl;
84
85        for ( S s = (S){0}; s < (S){10,10}; s += (S){1} ) { sout | s; } sout | nl;
86        for ( s; (S){10,10} ) { sout | s; } sout | nl;
87        sout | nl;
88        for ( s; (S){0} ~ (S){10,10} ) { sout | s; }             sout | nl;
89        for ( s; (S){0} ~ (S){10,10} ~ (S){1} ) { sout | s; } sout | nl;
90        for ( s; (S){0} ~= (S){10,10} ) { sout | s; }            sout | nl;
91        for ( s; (S){0} ~= (S){10,10} ~ (S){1} ) { sout | s; } sout | nl;
92        sout | nl;
93        for ( s; (S){10,10} -~ (S){0} ) { sout | s; }            sout | nl;
94        for ( s; (S){10,10} -~ (S){0} ~ (S){1} ) { sout | s; } sout | nl;
95        for ( s; (S){10,10} -~= (S){0} ) { sout | s; }           sout | nl;
96        for ( s; (S){10,10} -~= (S){0} ~ (S){1} ) { sout | s; } sout | nl;
97}
98
99// Local Variables: //
100// tab-width: 4 //
101// compile-command: "cfa loopctrl.cfa" //
102// End: //
Note: See TracBrowser for help on using the repository browser.