Ignore:
Timestamp:
Jul 16, 2018, 2:59:32 PM (6 years ago)
Author:
Peter A. Buhr <pabuhr@…>
Branches:
ADT, aaron-thesis, arm-eh, ast-experimental, cleanup-dtors, deferred_resn, demangler, enum, forall-pointer-decay, jacob/cs343-translation, jenkins-sandbox, master, new-ast, new-ast-unique-expr, no_list, persistent-indexer, pthread-emulation, qualifiedEnum
Children:
8a3ecb9, 95d09bdb
Parents:
0a73148
Message:

add new forall test

File:
1 edited

Legend:

Unmodified
Added
Removed
  • src/tests/forall.c

    r0a73148 r6da49249  
    1 int ?=?( int*, int );
    2 float ?=?( float*, float );
    3 int * ?=?( int **, int * );
    4 float * ?=?( float **, float * );
    5 char ?=?( char*, char );
    6 void (* ?=?( void (**)(void), void (*)(void) ))(void);
     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// forall.c --
     8//
     9// Author           : Peter A. Buhr
     10// Created On       : Wed May  9 08:48:15 2018
     11// Last Modified By : Peter A. Buhr
     12// Last Modified On : Thu Jul 12 16:19:08 2018
     13// Update Count     : 30
     14//
    715
    816void g1() {
    9         forall( otype T ) T f( T );
    10         void f( int );
    11         void h( void (*p)(void) );
     17        forall( otype T ) T f( T ) {};
     18        void f( int ) {};
     19        void h( void (*p)(void) ) {};
    1220
    1321        int x;
     
    2432
    2533void g2() {
    26         forall( otype T ) void f( T, T );
    27         forall( otype T, otype U ) void f( T, U );
     34        forall( otype T ) void f( T, T ) {}
     35        forall( otype T, otype U ) void f( T, U ) {}
    2836
    2937        int x;
     
    3745}
    3846
    39 typedef forall ( otype T ) int (*f)( int );
     47typedef forall ( otype T ) int (* f)( int );
    4048
    4149forall( otype T )
     
    4654}
    4755
     56void ?{}( int & c, zero_t ) { c = 0; }                                  // not in prelude
     57
    4858trait sumable( otype T ) {
    49         const T 0;
    50         T ?+?(T, T);
    51         T ?++(T);
    52         [T] ?+=?(T,T);
    53 };
    54 
    55 otype T1 | { const T1 0; T1 ?+?(T1, T1); T1 ?++(T1); [T1] ?+=?(T1,T1); },
    56         T2(otype P1, otype P2 ),
    57         T3 | sumable(T3);
    58 
    59 otype T2(otype P1, otype P2) | sumable(T2(P1,P2)) = struct { P1 i; P2 j; };
    60 
    61 T2(int, int) w1;
    62 typedef T2(int, int) w2;
    63 w2 g2;
    64 otype w3 = T2(int, int);
    65 w3 g3;
    66 
    67 forall( otype T | sumable( T ) )
    68 T sum( int n, T a[] ) {
    69         T total = 0;
    70         int i;
    71         for ( i = 0; i < n; i += 1 )
    72                 total = total + a[i];
     59        void ?{}( T &, zero_t );                                                        // 0 literal constructor
     60        T ?+?( T, T );                                                                          // assortment of additions
     61        T ?+=?( T &, T );
     62        T ++?( T & );
     63        T ?++( T & );
     64}; // sumable
     65
     66forall( otype T | sumable( T ) )                                                // use trait
     67T sum( size_t size, T a[] ) {
     68        T total = 0;                                                                            // initialize by 0 constructor
     69        for ( size_t i = 0; i < size; i += 1 )
     70                total = total + a[i];                                                   // select appropriate +
    7371        return total;
    74 }
    75 
    76 forall( otype T | { const T 0; T ?+?(T, T); T ?++(T); [T] ?+=?(T,T); } )
     72} // sum
     73
     74forall( otype T | { T ?+?( T, T ); T ?++( T & ); [T] ?+=?( T &,T ); } )
    7775T twice( T t ) {
    7876        return t + t;
    7977}
    8078
    81 forall( otype T | { const T 0; int ?!=?(T, T); int ?<?(T, T); } )
     79forall( otype T | { int ?<?(T, T); } )
    8280T min( T t1, T t2 ) {
    8381        return t1 < t2 ? t1 : t2;
    8482}
    8583
    86 int main() {
     84int fred() {
    8785        int x = 1, y = 2, a[10];
    8886        float f;
     
    9492}
    9593
     94// Multiple forall
     95forall( otype T ) forall( otype S ) struct { int i; };
     96forall( otype T ) struct { int i; } forall( otype S );
     97struct { int i; } forall( otype T ) forall( otype S );
     98forall( otype W ) struct { int i; } forall( otype T ) forall( otype S );
     99
     100// Distribution
     101struct P { int i; };
     102forall( otype T ) struct Q { T i; };
     103forall( otype T ) struct { int i; };
     104struct KK { int i; };
     105inline static {
     106        void RT1() {}
     107}
     108forall( otype T ) {
     109        T RT2( T ) {
     110                typedef int TD1;
     111                struct S1 { T t; };
     112        }
     113        forall( otype X ) {
     114                typedef int TD2;
     115                struct S2 {};
     116                X RT2( T, X ) {
     117                        int TD2;
     118                }
     119        }
     120        extern "C" {
     121                forall( otype W ) {
     122                        W RT3( W ) {}
     123                        struct S3 {};
     124                }
     125        }
     126        void RT4() {
     127                forall( otype W ) struct S4 {};
     128                typedef int TD3;
     129        }
     130        static {
     131                struct S5 {};
     132                void RT5( T ) {
     133                        struct S6 {};
     134                        int TD2;
     135                }
     136        }
     137        struct S7 {};
     138        typedef int TD4;
     139}
     140TD2 t2;
     141TD4 t4;
     142struct Q( int ) t;
     143struct S2( int, int ) t;
     144struct S5( int ) t;
     145struct S7( int ) t;
     146
     147int i = RT2( 3 );
     148double j = RT2( 3, 4.5 );
     149
     150static inline {
     151        forall( otype T ) {
     152                int RT6( T p );
     153        }
     154        forall( otype T, otype U ) {
     155                int RT7( T, U );
     156        }
     157}
     158static forall( otype T ) {
     159        int RT8( T );
     160}
     161forall( otype T ) inline static {
     162        int RT9( T ) { T t; }
     163}
     164
     165forall( otype T | { T ?+?( T, T ); } ) {
     166        forall( otype S | { T ?+?( T, S ); } ) {
     167                forall( otype W ) T bar( T t, S s ) { return t + s; }
     168                forall( otype W | { W ?+?( T, W ); } ) W baz( T t, S s, W w ) { return t + s + w; }
     169                struct W { T t; } (int,int) ww;
     170                struct P pp;
     171        }
     172}
     173
     174forall( otype T | { T ?+?( T, T ); } ) forall( otype S | { T ?+?( T, S ); } )
     175struct XW { T t; };
     176XW(int,int) xww;
     177
     178forall( otype T ) struct S { T t; } (int) x, y, z;
     179forall( otype T ) struct { T t; } (int) a, b, c;
     180
     181forall( otype T ) static forall( otype S ) {
     182    forall( otype X ) struct U {
     183                T x;
     184    };
     185}
     186
     187forall( otype T ) {
     188        extern "C" {
     189                struct SS { T t; };
     190                T foo( T ) {}
     191        }
     192}
     193
     194SS(int) s;
     195W(int,int) w;
     196
     197int jane() {
     198//      int j = bar( 3, 4 );
     199        int k = baz( 3, 4, 5 );
     200        int i = foo( 3 );
     201}
     202
     203//otype T1 | { void xxx( T1 ); };
     204
     205// otype T1 | { void ?{}( T1 &, zero_t ); T1 ?+?(T1, T1); T1 ?++(T1); [T1] ?+=?(T1,T1); },
     206//      T2(otype P1, otype P2 ),
     207//      T3 | sumable(T3);
     208
     209//otype T2(otype P1, otype P2) | sumable( T2( P1,P2 ) ) = struct { P1 i; P2 j; };
     210
     211// T2(int, int) w1;
     212// typedef T2(int, int) w2;
     213// w2 g2;
     214// otype w3 = T2(int, int);
     215// w3 g3;
     216
     217int main( void ) {}
     218
    96219// Local Variables: //
    97220// tab-width: 4 //
     221// compile-command: "cfa forall.c" //
    98222// End: //
Note: See TracChangeset for help on using the changeset viewer.