Changeset ad89296 for libcfa


Ignore:
Timestamp:
Apr 30, 2021, 1:09:38 PM (3 years ago)
Author:
Thierry Delisle <tdelisle@…>
Branches:
ADT, arm-eh, ast-experimental, enum, forall-pointer-decay, jacob/cs343-translation, master, new-ast-unique-expr, pthread-emulation, qualifiedEnum
Children:
bac0ba8
Parents:
34b2796 (diff), b9dae14c (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
  • libcfa/src/containers/array.hfa

    r34b2796 rad89296  
    55
    66// the inverse of Z(-)
    7 #define z(Zn) sizeof(Zn)
    8 
    9 // if you're expecting a Z(n), say so, by asking for a ztype, instead of dtype or otype
    10 #define ztype(Zn) Zn & | sized(Zn)
     7#define z(N) sizeof(N)
    118
    129forall( T & ) struct tag {};
     
    1916//
    2017
    21 forall( ztype(Zn), ztype(S), Timmed &, Tbase & ) {
     18forall( [N], [S], Timmed &, Tbase & ) {
    2219    struct arpk {
    23         S strides[z(Zn)];
     20        S strides[z(N)];
    2421    };
    2522
    26     Timmed & ?[?]( arpk(Zn, S, Timmed, Tbase) & a, ptrdiff_t i ) {
     23    Timmed & ?[?]( arpk(N, S, Timmed, Tbase) & a, ptrdiff_t i ) {
    2724        return (Timmed &) a.strides[i];
    2825    }
    2926
    30     size_t ?`len( arpk(Zn, S, Timmed, Tbase) & a ) {
    31         return z(Zn);
     27    Timmed & ?[?]( arpk(N, S, Timmed, Tbase) & a, int i ) {
     28        return (Timmed &) a.strides[i];
     29    }
     30
     31    Timmed & ?[?]( arpk(N, S, Timmed, Tbase) & a, size_t i ) {
     32        return (Timmed &) a.strides[i];
     33    }
     34
     35    size_t ?`len( arpk(N, S, Timmed, Tbase) & a ) {
     36        return z(N);
    3237    }
    3338
    3439    // workaround #226 (and array relevance thereof demonstrated in mike102/otype-slow-ndims.cfa)
    35     void ?{}( arpk(Zn, S, Timmed, Tbase) & this ) {
    36         void ?{}( S (&inner)[z(Zn)] ) {}
     40    void ?{}( arpk(N, S, Timmed, Tbase) & this ) {
     41        void ?{}( S (&inner)[z(N)] ) {}
    3742        ?{}(this.strides);
    3843    }
    39     void ^?{}( arpk(Zn, S, Timmed, Tbase) & this ) {
    40         void ^?{}( S (&inner)[z(Zn)] ) {}
     44    void ^?{}( arpk(N, S, Timmed, Tbase) & this ) {
     45        void ^?{}( S (&inner)[z(N)] ) {}
    4146        ^?{}(this.strides);
    4247    }
     
    5055Te mkar_( tag(Te) ) {}
    5156
    52 forall( ztype(Zn), ZTags ... , Trslt &, Tatom & | { Trslt mkar_( tag(Tatom), ZTags ); } )
    53 arpk(Zn, Trslt, Trslt, Tatom) mkar_( tag(Tatom), tag(Zn), ZTags ) {}
     57forall( [N], ZTags ... , Trslt &, Tatom & | { Trslt mkar_( tag(Tatom), ZTags ); } )
     58arpk(N, Trslt, Trslt, Tatom) mkar_( tag(Tatom), tag(N), ZTags ) {}
    5459
    5560// based on https://stackoverflow.com/questions/1872220/is-it-possible-to-iterate-over-arguments-in-variadic-macros
     
    8085// Core -[[-,-,-]] operator
    8186
     87#ifdef TRY_BROKEN_DESIRED_MD_SUBSCRIPT
     88
    8289// Desired form.  One definition with recursion on IxBC (worked until Jan 2021, see trac #__TODO__)
    83 // forall( TA &, TB &, TC &, IxAB, IxBC ... | { TB & ?[?]( TA &, IxAB ); TC & ?[?]( TB &, IxBC ); } )
    84 // TC & ?[?]( TA & this, IxAB ab, IxBC bc ) {
    85 //     return this[ab][bc];
    86 // }
    8790
    88 // Workaround form.  Listing all possibilities up to 4 dims.
    89 forall( TA &, TB &, IxAB | { TB & ?[?]( TA &, IxAB ); }
    90             , TC &, IxBC | { TC & ?[?]( TB &, IxBC ); } )
     91forall( TA &, TB &, TC &, IxAB, IxBC ... | { TB & ?[?]( TA &, IxAB ); TC & ?[?]( TB &, IxBC ); } )
    9192TC & ?[?]( TA & this, IxAB ab, IxBC bc ) {
    9293    return this[ab][bc];
    9394}
    94 forall( TA &, TB &, IxAB | { TB & ?[?]( TA &, IxAB ); }
    95             , TC &, IxBC | { TC & ?[?]( TB &, IxBC ); }
    96             , TD &, IxCD | { TD & ?[?]( TC &, IxCD ); } )
    97 TD & ?[?]( TA & this, IxAB ab, IxBC bc, IxCD cd ) {
    98     return this[ab][bc][cd];
    99 }
    100 forall( TA &, TB &, IxAB | { TB & ?[?]( TA &, IxAB ); }
    101             , TC &, IxBC | { TC & ?[?]( TB &, IxBC ); }
    102             , TD &, IxCD | { TD & ?[?]( TC &, IxCD ); }
    103             , TE &, IxDE | { TE & ?[?]( TD &, IxDE ); } )
    104 TE & ?[?]( TA & this, IxAB ab, IxBC bc, IxCD cd, IxDE de ) {
    105     return this[ab][bc][cd][de];
     95
     96#else
     97
     98// Workaround form.  Listing all possibilities up to 4 dims.
     99
     100forall( TA &, TB &, TC &, IxAB_0, IxBC | { TB & ?[?]( TA &, IxAB_0 ); TC & ?[?]( TB &, IxBC ); } )
     101TC & ?[?]( TA & this, IxAB_0 ab, IxBC bc ) {
     102    return this[ab][bc];
    106103}
    107104
    108 // Adapters for "indexed by ptrdiff_t" implies "indexed by [this other integral type]"
    109 // Work around restriction that assertions underlying -[[-,-,-]] must match excatly
    110 forall( C &, E & | { E & ?[?]( C &, ptrdiff_t ); } ) {
     105forall( TA &, TB &, TC &, IxAB_0, IxAB_1, IxBC | { TB & ?[?]( TA &, IxAB_0, IxAB_1 ); TC & ?[?]( TB &, IxBC ); } )
     106TC & ?[?]( TA & this, IxAB_0 ab0, IxAB_1 ab1, IxBC bc ) {
     107    return this[[ab0,ab1]][bc];
     108}
    111109
    112     // Targeted to support:  for( i; z(N) ) ... a[[ ..., i, ... ]]
    113     E & ?[?]( C & this, size_t i ) {
    114         return this[ (ptrdiff_t) i ];
    115     }
     110forall( TA &, TB &, TC &, IxAB_0, IxAB_1, IxAB_2, IxBC | { TB & ?[?]( TA &, IxAB_0, IxAB_1, IxAB_2 ); TC & ?[?]( TB &, IxBC ); } )
     111TC & ?[?]( TA & this, IxAB_0 ab0, IxAB_1 ab1, IxAB_2 ab2, IxBC bc ) {
     112    return this[[ab0,ab1,ab2]][bc];
     113}
    116114
    117     // Targeted to support:  for( i; 5 ) ... a[[ ..., i, ... ]]
    118     E & ?[?]( C & this, int i ) {
    119         return this[ (ptrdiff_t) i ];
    120     }
    121 }
     115#endif
    122116
    123117//
     
    126120
    127121// Base
    128 forall( ztype(Zq), ztype(Sq), Tbase & )
    129 tag(arpk(Zq, Sq, Tbase, Tbase)) enq_( tag(Tbase), tag(Zq), tag(Sq), tag(Tbase) ) {}
     122forall( [Nq], [Sq], Tbase & )
     123tag(arpk(Nq, Sq, Tbase, Tbase)) enq_( tag(Tbase), tag(Nq), tag(Sq), tag(Tbase) ) {}
    130124
    131125// Rec
    132 forall( ztype(Zq), ztype(Sq), ztype(Z), ztype(S), recq &, recr &, Tbase & | { tag(recr) enq_( tag(Tbase), tag(Zq), tag(Sq), tag(recq) ); } )
    133 tag(arpk(Z, S, recr, Tbase)) enq_( tag(Tbase), tag(Zq), tag(Sq), tag(arpk(Z, S, recq, Tbase)) ) {}
     126forall( [Nq], [Sq], [N], [S], recq &, recr &, Tbase & | { tag(recr) enq_( tag(Tbase), tag(Nq), tag(Sq), tag(recq) ); } )
     127tag(arpk(N, S, recr, Tbase)) enq_( tag(Tbase), tag(Nq), tag(Sq), tag(arpk(N, S, recq, Tbase)) ) {}
    134128
    135129// Wrapper
    136130struct all_t {} all;
    137 forall( ztype(Z), ztype(S), Te &, result &, Tbase & | { tag(result) enq_( tag(Tbase), tag(Z), tag(S), tag(Te) ); } )
    138 result & ?[?]( arpk(Z, S, Te, Tbase) & this, all_t ) {
     131forall( [N], [S], Te &, result &, Tbase & | { tag(result) enq_( tag(Tbase), tag(N), tag(S), tag(Te) ); } )
     132result & ?[?]( arpk(N, S, Te, Tbase) & this, all_t ) {
    139133    return (result&) this;
    140134}
Note: See TracChangeset for help on using the changeset viewer.