Changeset b9dae14c for libcfa/src/containers
- Timestamp:
- Apr 30, 2021, 9:23:12 AM (3 years ago)
- Branches:
- ADT, arm-eh, ast-experimental, enum, forall-pointer-decay, jacob/cs343-translation, master, new-ast-unique-expr, pthread-emulation, qualifiedEnum
- Children:
- a049412, ad89296, ec1c674
- Parents:
- 63a4b92
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
libcfa/src/containers/array.hfa
r63a4b92 rb9dae14c 5 5 6 6 // 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) 11 8 12 9 forall( T & ) struct tag {}; … … 19 16 // 20 17 21 forall( ztype(Zn), ztype(S), Timmed &, Tbase & ) {18 forall( [N], [S], Timmed &, Tbase & ) { 22 19 struct arpk { 23 S strides[z( Zn)];20 S strides[z(N)]; 24 21 }; 25 22 26 Timmed & ?[?]( arpk( Zn, S, Timmed, Tbase) & a, ptrdiff_t i ) {23 Timmed & ?[?]( arpk(N, S, Timmed, Tbase) & a, ptrdiff_t i ) { 27 24 return (Timmed &) a.strides[i]; 28 25 } 29 26 30 Timmed & ?[?]( arpk( Zn, S, Timmed, Tbase) & a, int i ) {27 Timmed & ?[?]( arpk(N, S, Timmed, Tbase) & a, int i ) { 31 28 return (Timmed &) a.strides[i]; 32 29 } 33 30 34 Timmed & ?[?]( arpk( Zn, S, Timmed, Tbase) & a, size_t i ) {31 Timmed & ?[?]( arpk(N, S, Timmed, Tbase) & a, size_t i ) { 35 32 return (Timmed &) a.strides[i]; 36 33 } 37 34 38 size_t ?`len( arpk( Zn, S, Timmed, Tbase) & a ) {39 return z( Zn);35 size_t ?`len( arpk(N, S, Timmed, Tbase) & a ) { 36 return z(N); 40 37 } 41 38 42 39 // workaround #226 (and array relevance thereof demonstrated in mike102/otype-slow-ndims.cfa) 43 void ?{}( arpk( Zn, S, Timmed, Tbase) & this ) {44 void ?{}( S (&inner)[z( Zn)] ) {}40 void ?{}( arpk(N, S, Timmed, Tbase) & this ) { 41 void ?{}( S (&inner)[z(N)] ) {} 45 42 ?{}(this.strides); 46 43 } 47 void ^?{}( arpk( Zn, S, Timmed, Tbase) & this ) {48 void ^?{}( S (&inner)[z( Zn)] ) {}44 void ^?{}( arpk(N, S, Timmed, Tbase) & this ) { 45 void ^?{}( S (&inner)[z(N)] ) {} 49 46 ^?{}(this.strides); 50 47 } … … 58 55 Te mkar_( tag(Te) ) {} 59 56 60 forall( ztype(Zn), ZTags ... , Trslt &, Tatom & | { Trslt mkar_( tag(Tatom), ZTags ); } )61 arpk( Zn, Trslt, Trslt, Tatom) mkar_( tag(Tatom), tag(Zn), ZTags ) {}57 forall( [N], ZTags ... , Trslt &, Tatom & | { Trslt mkar_( tag(Tatom), ZTags ); } ) 58 arpk(N, Trslt, Trslt, Tatom) mkar_( tag(Tatom), tag(N), ZTags ) {} 62 59 63 60 // based on https://stackoverflow.com/questions/1872220/is-it-possible-to-iterate-over-arguments-in-variadic-macros … … 123 120 124 121 // Base 125 forall( ztype(Zq), ztype(Sq), Tbase & )126 tag(arpk( Zq, Sq, Tbase, Tbase)) enq_( tag(Tbase), tag(Zq), tag(Sq), tag(Tbase) ) {}122 forall( [Nq], [Sq], Tbase & ) 123 tag(arpk(Nq, Sq, Tbase, Tbase)) enq_( tag(Tbase), tag(Nq), tag(Sq), tag(Tbase) ) {} 127 124 128 125 // Rec 129 forall( ztype(Zq), ztype(Sq), ztype(Z), ztype(S), recq &, recr &, Tbase & | { tag(recr) enq_( tag(Tbase), tag(Zq), tag(Sq), tag(recq) ); } )130 tag(arpk( Z, S, recr, Tbase)) enq_( tag(Tbase), tag(Zq), tag(Sq), tag(arpk(Z, S, recq, Tbase)) ) {}126 forall( [Nq], [Sq], [N], [S], recq &, recr &, Tbase & | { tag(recr) enq_( tag(Tbase), tag(Nq), tag(Sq), tag(recq) ); } ) 127 tag(arpk(N, S, recr, Tbase)) enq_( tag(Tbase), tag(Nq), tag(Sq), tag(arpk(N, S, recq, Tbase)) ) {} 131 128 132 129 // Wrapper 133 130 struct all_t {} all; 134 forall( ztype(Z), ztype(S), Te &, result &, Tbase & | { tag(result) enq_( tag(Tbase), tag(Z), tag(S), tag(Te) ); } )135 result & ?[?]( arpk( Z, S, Te, Tbase) & this, all_t ) {131 forall( [N], [S], Te &, result &, Tbase & | { tag(result) enq_( tag(Tbase), tag(N), tag(S), tag(Te) ); } ) 132 result & ?[?]( arpk(N, S, Te, Tbase) & this, all_t ) { 136 133 return (result&) this; 137 134 }
Note: See TracChangeset
for help on using the changeset viewer.