Changeset 3253c32 for tests/sum.cfa


Ignore:
Timestamp:
Jun 24, 2019, 1:26:04 PM (5 years ago)
Author:
Peter A. Buhr <pabuhr@…>
Branches:
ADT, arm-eh, ast-experimental, enum, forall-pointer-decay, jacob/cs343-translation, jenkins-sandbox, master, new-ast, new-ast-unique-expr, pthread-emulation, qualifiedEnum
Children:
fb2bde4
Parents:
397edf7 (diff), b58affe7 (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.
Message:

Merge branch 'master' of plg.uwaterloo.ca:software/cfa/cfa-cc

File:
1 edited

Legend:

Unmodified
Added
Removed
  • tests/sum.cfa

    r397edf7 r3253c32  
    3535
    3636int main( void ) {
     37#if 0
    3738        const int low = 5, High = 15, size = High - low;
    3839
     
    121122                 | sum( size, gs.x ) | ", check" | (int)s;              // add field array in generic type
    122123        delete( gs.x );
     124#else
     125        const int low = 5, High = 15, size = High - low;
     126
     127        signed char s = 0, a[size], v = (char)low;
     128        for ( int i = 0; i < size; i += 1, v += 1hh ) {
     129                s += v;
     130                a[i] = v;
     131        } // for
     132        printf( "sum from %d to %d is %hhd, check %hhd\n", low, High,
     133                 sum( size, (signed char *)a ), (signed char)s );
     134
     135        unsigned char s = 0, a[size], v = low;
     136        for ( int i = 0; i < size; i += 1, v += 1hhu ) {
     137                s += (unsigned char)v;
     138                a[i] = (unsigned char)v;
     139        } // for
     140        printf( "sum from %d to %d is %hhu, check %hhu\n", low, High,
     141                 sum( size, (unsigned char *)a ), (unsigned char)s );
     142
     143        short int s = 0, a[size], v = low;
     144        for ( int i = 0; i < size; i += 1, v += 1h ) {
     145                s += (short int)v;
     146                a[i] = (short int)v;
     147        } // for
     148        printf( "sum from %d to %d is %hd, check %hd\n", low, High,
     149                 sum( size, (short int *)a ), (short int)s );
     150
     151        int s = 0, a[size], v = low;
     152        for ( int i = 0; i < size; i += 1, v += 1 ) {
     153                s += (int)v;
     154                a[i] = (int)v;
     155        } // for
     156        printf( "sum from %d to %d is %d, check %d\n", low, High,
     157                 sum( size, (int *)a ), (int)s );
     158
     159        float s = 0.0f, a[size], v = low / 10.0f;
     160        for ( int i = 0; i < size; i += 1, v += 0.1f ) {
     161                s += (float)v;
     162                a[i] = (float)v;
     163        } // for
     164        printf( "sum from %g to %g is %g, check %g\n", low / 10.0f, High / 10.0f,
     165                 sum( size, (float *)a ), (float)s );
     166
     167        double s = 0.0, a[size], v = low / 10.0;
     168        for ( int i = 0; i < size; i += 1, v += 0.1 ) {
     169                s += (double)v;
     170                a[i] = (double)v;
     171        } // for
     172        printf( "sum from %g to %g is %g, check %g\n", low / 10.0f, High / 10.0f,
     173                 sum( size, (double *)a ), (double)s );
     174
     175        struct S { int i, j; };
     176        void ?{}( S & s ) { s.[i, j] = 0; }
     177        void ?{}( S & s, int i ) { s.[i, j] = [i, 0]; }
     178        void ?{}( S & s, int i, int j ) { s.[i, j] = [i, j]; }
     179        void ?{}( S & s, zero_t ) { s.[i, j] = 0; }
     180        void ?{}( S & s, one_t ) { s.[i, j] = 1; }
     181        S ?+?( S t1, S t2 ) { return (S){ t1.i + t2.i, t1.j + t2.j }; }
     182        S ?+=?( S & t1, S t2 ) { t1 = t1 + t2; return t1; }
     183        S ++?( S & t ) { t += (S){1}; return t; }
     184        S ?++( S & t ) { S temp = t; t += (S){1}; return temp; }
     185        ofstream & ?|?( ofstream & os, S v ) { return os | v.i | v.j; }
     186        void ?|?( ofstream & os, S v ) { (ofstream &)(os | v); nl( os ); }
     187
     188        S s = (S){0}, a[size], v = { low, low };
     189        for ( int i = 0; i < size; i += 1, v += (S){1} ) {
     190                s += (S)v;
     191                a[i] = (S)v;
     192        } // for
     193        printf( "sum from %d to %d is %d %d, check %d %d\n", low, High,
     194                 sum( size, (S *)a ).[i, j], s.[i, j] );
     195
     196        forall( otype Impl | sumable( Impl ) )
     197        struct GS {
     198                Impl * x, * y;
     199        };
     200        GS(int) gs;
     201        // FIX ME, resolution problem with anew not picking up the LH type
     202        gs.x = (typeof(gs.x))anew( size );                                      // create array storage for field
     203        s = 0; v = low;
     204        for ( int i = 0; i < size; i += 1, v += 1 ) {
     205                s += (int)v;
     206                gs.x[i] = (int)v;                                                               // set field array in generic type
     207        } // for
     208        printf( "sum from %d to %d is %d, check %d\n", low, High,
     209                 sum( size, gs.x ), (int)s );           // add field array in generic type
     210        delete( gs.x );
     211#endif
    123212} // main
    124213
Note: See TracChangeset for help on using the changeset viewer.