Changeset b9dae14c


Ignore:
Timestamp:
Apr 30, 2021, 9:23:12 AM (3 years ago)
Author:
Michael Brooks <mlbrooks@…>
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
Message:

Activated syntax, forall( [N] ).

This implementation desugars in the parser, as forall( ztype(N) ) did in
the preprocessor. Semantic analysis is still required to lock down treating N as a
a traditional type (forbid: N x = 17; vector(N) v;). Deferring that work until
the N--value adapters ( Z(17), z(N) ) are settled.

Files:
4 edited

Legend:

Unmodified
Added
Removed
  • libcfa/src/containers/array.hfa

    r63a4b92 rb9dae14c  
    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     Timmed & ?[?]( arpk(Zn, S, Timmed, Tbase) & a, int i ) {
     27    Timmed & ?[?]( arpk(N, S, Timmed, Tbase) & a, int i ) {
    3128        return (Timmed &) a.strides[i];
    3229    }
    3330
    34     Timmed & ?[?]( arpk(Zn, S, Timmed, Tbase) & a, size_t i ) {
     31    Timmed & ?[?]( arpk(N, S, Timmed, Tbase) & a, size_t i ) {
    3532        return (Timmed &) a.strides[i];
    3633    }
    3734
    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);
    4037    }
    4138
    4239    // 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)] ) {}
    4542        ?{}(this.strides);
    4643    }
    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)] ) {}
    4946        ^?{}(this.strides);
    5047    }
     
    5855Te mkar_( tag(Te) ) {}
    5956
    60 forall( ztype(Zn), ZTags ... , Trslt &, Tatom & | { Trslt mkar_( tag(Tatom), ZTags ); } )
    61 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 ) {}
    6259
    6360// based on https://stackoverflow.com/questions/1872220/is-it-possible-to-iterate-over-arguments-in-variadic-macros
     
    123120
    124121// Base
    125 forall( ztype(Zq), ztype(Sq), Tbase & )
    126 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) ) {}
    127124
    128125// 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)) ) {}
     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)) ) {}
    131128
    132129// Wrapper
    133130struct 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 ) {
     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 ) {
    136133    return (result&) this;
    137134}
  • src/Parser/DeclarationNode.cc

    r63a4b92 rb9dae14c  
    10761076        if ( variable.tyClass != TypeDecl::NUMBER_OF_KINDS ) {
    10771077                // otype is internally converted to dtype + otype parameters
    1078                 static const TypeDecl::Kind kindMap[] = { TypeDecl::Dtype, TypeDecl::DStype, TypeDecl::Dtype, TypeDecl::Ftype, TypeDecl::Ttype, TypeDecl::ALtype };
     1078                static const TypeDecl::Kind kindMap[] = { TypeDecl::Dtype, TypeDecl::DStype, TypeDecl::Dtype, TypeDecl::Ftype, TypeDecl::Ttype, TypeDecl::Dtype };
    10791079                static_assert( sizeof(kindMap) / sizeof(kindMap[0]) == TypeDecl::NUMBER_OF_KINDS, "DeclarationNode::build: kindMap is out of sync." );
    10801080                assertf( variable.tyClass < sizeof(kindMap)/sizeof(kindMap[0]), "Variable's tyClass is out of bounds." );
    1081                 TypeDecl * ret = new TypeDecl( *name, Type::StorageClasses(), nullptr, kindMap[ variable.tyClass ], variable.tyClass == TypeDecl::Otype, variable.initializer ? variable.initializer->buildType() : nullptr );
     1081                TypeDecl * ret = new TypeDecl( *name, Type::StorageClasses(), nullptr, kindMap[ variable.tyClass ], variable.tyClass == TypeDecl::Otype || variable.tyClass == TypeDecl::ALtype, variable.initializer ? variable.initializer->buildType() : nullptr );
    10821082                buildList( variable.assertions, ret->get_assertions() );
    10831083                return ret;
  • tests/array-container/array-basic.cfa

    r63a4b92 rb9dae14c  
    55//
    66
    7 forall( ztype(Nx), ztype(Ny), ztype(Nz) )
     7forall( [Nx], [Ny], [Nz] )
    88void typesTest( tag(Nx), tag(Ny), tag(Nz) ) {
    99
     
    5959}
    6060
    61 forall( ztype(Nw), ztype(Nx), ztype(Ny), ztype(Nz) )
     61forall( [Nw], [Nx], [Ny], [Nz] )
    6262void fillHelloData( array( float, Nw, Nx, Ny, Nz ) & wxyz ) {
    6363    for (w; z(Nw))
     
    6868}
    6969
    70 forall( ztype(Zn)
     70forall( [Zn]
    7171      , S & | sized(S)
    7272      )
     
    8686}
    8787
    88 forall( ztype(Nw), ztype(Nx), ztype(Ny), ztype(Nz) )
     88forall( [Nw], [Nx], [Ny], [Nz] )
    8989void runtimeTest( tag(Nw), tag(Nx), tag(Ny), tag(Nz) ) {
    9090
  • tests/array-container/array-md-sbscr-cases.cfa

    r63a4b92 rb9dae14c  
    1818}
    1919
    20 forall( ztype(Nw), ztype(Nx), ztype(Ny), ztype(Nz) )
     20forall( [Nw], [Nx], [Ny], [Nz] )
    2121void fillHelloData( array( float, Nw, Nx, Ny, Nz ) & wxyz ) {
    2222    for (w; z(Nw))
     
    2727}
    2828
    29 forall( ztype(Zn)
    30       , S & | sized(S)
    31       )
    32 float total1d_low( arpk(Zn, S, float, float ) & a ) {
    33     float total = 0.0f;
    34     for (i; z(Zn))
    35         total += a[i];
    36     return total;
    37 }
    38 
    39 forall( A & | ar(A, float) )
    40 float total1d_hi( A & a ) {
    41     float total = 0.0f;
    42     for (i; a`len)
    43         total += a[i];
    44     return total;
    45 }
    46 
    4729// Tests all the ways to split dimensions into CFA-supported chunks, by the only order that C supports: coarsest to finest stride.
    48 forall( ztype(Nw), ztype(Nx), ztype(Ny), ztype(Nz) )
     30forall( [Nw], [Nx], [Ny], [Nz] )
    4931void test_inOrderSplits( tag(Nw), tag(Nx), tag(Ny), tag(Nz) ) {
    5032
     
    9678
    9779// All orders that skip a single dimension, each in its most natural split.
    98 forall( ztype(Nw), ztype(Nx), ztype(Ny), ztype(Nz) )
     80forall( [Nw], [Nx], [Ny], [Nz] )
    9981void test_skipSingle( tag(Nw), tag(Nx), tag(Ny), tag(Nz) ) {
    10082
     
    137119// Natural split means the arity of every -[[-,...]] tuple equals the dimensionality of its "this" operand, then that the fewest "all" subscripts are given.
    138120// The commented-out test code shows cases that don't work.  We wish all the comment-coverd cases worked.
    139 forall( ztype(Nw), ztype(Nx), ztype(Ny), ztype(Nz) )
     121forall( [Nw], [Nx], [Ny], [Nz] )
    140122void test_latticeCoverage( tag(Nw), tag(Nx), tag(Ny), tag(Nz) ) {
    141123
     
    235217}
    236218
    237 forall( ztype(Nw), ztype(Nx), ztype(Ny), ztype(Nz) )
     219forall( [Nw], [Nx], [Ny], [Nz] )
    238220void test_numSubscrTypeCompatibility( tag(Nw), tag(Nx), tag(Ny), tag(Nz) ) {
    239221
     
    282264    test_skipSingle     ( ztag(KW), ztag(KX), ztag(KY), ztag(KZ) );
    283265    test_latticeCoverage( ztag(KW), ztag(KX), ztag(KY), ztag(KZ) );
     266    test_numSubscrTypeCompatibility( ztag(KW), ztag(KX), ztag(KY), ztag(KZ) );
    284267    printf("done\n");
    285268}
Note: See TracChangeset for help on using the changeset viewer.