Changeset 1d71208


Ignore:
Timestamp:
Jun 23, 2021, 4:59:37 PM (7 months ago)
Author:
Michael Brooks <mlbrooks@…>
Branches:
jacob/cs343-translation, master, new-ast-unique-expr
Children:
27434e9
Parents:
6448f7d
Message:

Implementing new-array subscripting syntax, in which a[x,y,z] now means the same as ax,y,z?.

This behaviour immediately replaces a syntax error that prohibits the -[-,-,-] syntax. The prior state showed that the C programs we compile don't use the C-compatible meaning of commas in subscripts.

This behaviour ultimately replaces the C-compatible interpretation in which a[x,y,z] means a[(x,y,z)] or, roughly, ({ x; y; a[z]; }).

Files:
3 edited

Legend:

Unmodified
Added
Removed
  • src/Parser/parser.yy

    r6448f7d r1d71208  
    635635postfix_expression:
    636636        primary_expression
    637         | postfix_expression '[' assignment_expression ',' comma_expression ']'
    638                 // { $$ = new ExpressionNode( build_binary_val( OperKinds::Index, $1, new ExpressionNode( build_binary_val( OperKinds::Index, $3, $5 ) ) ) ); }
    639                 { SemanticError( yylloc, "New array subscript is currently unimplemented." ); $$ = nullptr; }
     637        | postfix_expression '[' assignment_expression ',' tuple_expression_list ']'
     638                        // Historic, transitional: Disallow commas in subscripts.
     639                        // Switching to this behaviour may help check if a C compatibilty case uses comma-exprs in subscripts.
     640                // { SemanticError( yylloc, "New array subscript is currently unimplemented." ); $$ = nullptr; }
     641                        // Current: Commas in subscripts make tuples.
     642                { $$ = new ExpressionNode( build_binary_val( OperKinds::Index, $1, new ExpressionNode( build_tuple( (ExpressionNode *)($3->set_last( $5 ) ) )) ) ); }
    640643        | postfix_expression '[' assignment_expression ']'
    641644                // CFA, comma_expression disallowed in this context because it results in a common user error: subscripting a
  • tests/array-container/array-basic.cfa

    r6448f7d r1d71208  
    105105    printf("result Ws [][][][] lo = %f\n", result);
    106106
    107     result = total1d_low( wxyz[[all, slice_ix, slice_ix, slice_ix]] );
     107    result = total1d_low( wxyz[all, slice_ix, slice_ix, slice_ix] );
    108108    printf("result Ws [,,,]    lo = %f\n", result);
    109109
     
    111111    printf("result Ws [][][][] hi = %f\n", result);
    112112
    113     result = total1d_hi( wxyz[[all, slice_ix, slice_ix, slice_ix]] );
     113    result = total1d_hi( wxyz[all, slice_ix, slice_ix, slice_ix] );
    114114    printf("result Ws [,,,]    hi = %f\n", result);
    115115
     
    124124    printf("result Xs [][][][] lo = %f\n", result);
    125125
    126     result = total1d_low( wxyz[[slice_ix, all, slice_ix, slice_ix]] );
     126    result = total1d_low( wxyz[slice_ix, all, slice_ix, slice_ix] );
    127127    printf("result Xs [,,,]    lo = %f\n", result);
    128128
     
    130130    printf("result Xs [][][][] hi = %f\n", result);
    131131
    132     result = total1d_hi( wxyz[[slice_ix, all, slice_ix, slice_ix]] );
     132    result = total1d_hi( wxyz[slice_ix, all, slice_ix, slice_ix] );
    133133    printf("result Xs [,,,]    hi = %f\n", result);
    134134
  • tests/array-container/array-md-sbscr-cases.cfa

    r6448f7d r1d71208  
    5353    // order wxyz, natural split (4-0 or 0-4, no intermediate to declare)
    5454
    55     assert(( wxyz[[iw, ix, iy, iz]] == valExpected ));
     55    assert(( wxyz[iw, ix, iy, iz] == valExpected ));
    5656
    5757    // order wxyz, unnatural split 1-3  (three ways declared)
    5858
    5959    typeof( wxyz[iw] ) xyz1 = wxyz[iw];
    60     assert(( xyz1[[ix, iy, iz]]  == valExpected ));
     60    assert(( xyz1[ix, iy, iz]  == valExpected ));
    6161
    6262    typeof( wxyz[iw] ) xyz2;
    6363    &xyz2 = &wxyz[iw];
    64     assert(( xyz2[[ix, iy, iz]] == valExpected ));
    65 
    66     assert(( wxyz[iw][[ix, iy, iz]] == valExpected ));
     64    assert(( xyz2[ix, iy, iz] == valExpected ));
     65
     66    assert(( wxyz[iw][ix, iy, iz] == valExpected ));
    6767
    6868    // order wxyz, unnatural split 2-2  (three ways declared)
    6969
    70     typeof( wxyz[[iw, ix]] ) yz1 = wxyz[[iw,ix]];
    71     assert(( yz1[[iy, iz]]  == valExpected ));
    72 
    73     typeof( wxyz[[iw, ix]] ) yz2;
    74     &yz2 = &wxyz[[iw, ix]];
    75     assert(( yz2[[iy, iz]]  == valExpected ));
    76 
    77     assert(( wxyz[[iw, ix]][[iy, iz]] == valExpected ));
     70    typeof( wxyz[iw, ix] ) yz1 = wxyz[iw,ix];
     71    assert(( yz1[iy, iz]  == valExpected ));
     72
     73    typeof( wxyz[iw, ix] ) yz2;
     74    &yz2 = &wxyz[iw, ix];
     75    assert(( yz2[iy, iz]  == valExpected ));
     76
     77    assert(( wxyz[iw, ix][iy, iz] == valExpected ));
    7878
    7979    // order wxyz, unnatural split 3-1  (three ways declared)
    8080
    81     typeof( wxyz[[iw, ix, iy]] ) z1 = wxyz[[iw, ix, iy]];
     81    typeof( wxyz[iw, ix, iy] ) z1 = wxyz[iw, ix, iy];
    8282    assert(( z1[iz]  == valExpected ));
    8383
    84     typeof( wxyz[[iw, ix, iy]] ) z2;
    85     &z2 = &wxyz[[iw, ix, iy]];
     84    typeof( wxyz[iw, ix, iy] ) z2;
     85    &z2 = &wxyz[iw, ix, iy];
    8686    assert(( z2[iz] == valExpected ));
    8787
    88     assert(( wxyz[[iw, ix, iy]][iz] == valExpected ));
     88    assert(( wxyz[iw, ix, iy][iz] == valExpected ));
    8989}
    9090
     
    104104    // order wxyz (no intermediates to declare)
    105105
    106     assert(( wxyz[[iw  , ix  , iy  , iz  ]]       == valExpected ));
    107     assert(( wxyz[[iw-1, ix  , iy  , iz  ]]       != valExpected ));
     106    assert(( wxyz[iw  , ix  , iy  , iz  ]       == valExpected ));
     107    assert(( wxyz[iw-1, ix  , iy  , iz  ]       != valExpected ));
    108108
    109109    // order xyzw: *xyz, w
    110110
    111     assert(( wxyz[[all , ix  , iy  , iz  ]][iw  ] == valExpected ));
    112     assert(( wxyz[[all , ix-1, iy  , iz  ]][iw  ] != valExpected ));
    113     assert(( wxyz[[all , ix  , iy  , iz  ]][iw-1] != valExpected ));
     111    assert(( wxyz[all , ix  , iy  , iz  ][iw  ] == valExpected ));
     112    assert(( wxyz[all , ix-1, iy  , iz  ][iw  ] != valExpected ));
     113    assert(( wxyz[all , ix  , iy  , iz  ][iw-1] != valExpected ));
    114114
    115115    // order wyzx: w*yz, x
    116116
    117     assert(( wxyz[[iw  , all , iy  , iz  ]][ix  ] == valExpected ));
    118     assert(( wxyz[[iw  , all , iy-1, iz  ]][ix  ] != valExpected ));
    119     assert(( wxyz[[iw  , all , iy  , iz  ]][ix-1] != valExpected ));
     117    assert(( wxyz[iw  , all , iy  , iz  ][ix  ] == valExpected ));
     118    assert(( wxyz[iw  , all , iy-1, iz  ][ix  ] != valExpected ));
     119    assert(( wxyz[iw  , all , iy  , iz  ][ix-1] != valExpected ));
    120120
    121121    // order wxzy: wx*z, y
    122122  #if 0
    123123    // not working on 32-bit
    124     assert(( wxyz[[iw  , ix  , all , iz  ]][iy  ] == valExpected ));
    125     assert(( wxyz[[iw  , ix  , all , iz-1]][iy  ] != valExpected ));
    126     assert(( wxyz[[iw  , ix  , all , iz  ]][iy-1] != valExpected ));
     124    assert(( wxyz[iw  , ix  , all , iz  ][iy  ] == valExpected ));
     125    assert(( wxyz[iw  , ix  , all , iz-1][iy  ] != valExpected ));
     126    assert(( wxyz[iw  , ix  , all , iz  ][iy-1] != valExpected ));
    127127  #endif
    128128}
     
    131131// The comments specify a covering set of orders, each in its most natural split.
    132132// Covering means that each edge on the lattice of dimesnions-provided is used.
    133 // Natural split means the arity of every -[[-,...]] tuple equals the dimensionality of its "this" operand, then that the fewest "all" subscripts are given.
     133// Natural split means the arity of every -[-,...] tuple equals the dimensionality of its "this" operand, then that the fewest "all" subscripts are given.
    134134// The commented-out test code shows cases that don't work.  We wish all the comment-coverd cases worked.
    135135forall( [Nw], [Nx], [Ny], [Nz] )
     
    147147    // order wxyz (no intermediates to declare)
    148148
    149     assert(( wxyz[[iw, ix, iy, iz]] == valExpected ));
     149    assert(( wxyz[iw, ix, iy, iz] == valExpected ));
    150150
    151151    {
     
    153153        assert( wxyz[iw][all][iy][all] [ix][iz] == valExpected );
    154154
    155         typeof( wxyz[[iw, all, iy, all]] ) xz1 = wxyz[[iw, all, iy, all]];
    156         assert(( xz1[[ix, iz]]  == valExpected ));
    157 
    158         typeof( wxyz[[iw, all, iy, all]] ) xz2;
    159         &xz2 = &wxyz[[iw, all, iy, all]];
    160         assert(( xz2[[ix, iz]]  == valExpected ));
    161 
    162         assert(( wxyz[[iw  , all, iy  , all]][[ix  , iz  ]] == valExpected ));
    163         assert(( wxyz[[iw-1, all, iy  , all]][[ix  , iz  ]] != valExpected ));
    164         assert(( wxyz[[iw  , all, iy-1, all]][[ix  , iz  ]] != valExpected ));
    165         assert(( wxyz[[iw  , all, iy  , all]][[ix-1, iz  ]] != valExpected ));
    166         assert(( wxyz[[iw  , all, iy  , all]][[ix  , iz-1]] != valExpected ));
     155        typeof( wxyz[iw, all, iy, all] ) xz1 = wxyz[iw, all, iy, all];
     156        assert(( xz1[ix, iz]  == valExpected ));
     157
     158        typeof( wxyz[iw, all, iy, all] ) xz2;
     159        &xz2 = &wxyz[iw, all, iy, all];
     160        assert(( xz2[ix, iz]  == valExpected ));
     161
     162        assert(( wxyz[iw  , all, iy  , all][ix  , iz  ] == valExpected ));
     163        assert(( wxyz[iw-1, all, iy  , all][ix  , iz  ] != valExpected ));
     164        assert(( wxyz[iw  , all, iy-1, all][ix  , iz  ] != valExpected ));
     165        assert(( wxyz[iw  , all, iy  , all][ix-1, iz  ] != valExpected ));
     166        assert(( wxyz[iw  , all, iy  , all][ix  , iz-1] != valExpected ));
    167167    }
    168168    {
     
    170170        assert( wxyz[iw][all][all][iz] [ix][iy] == valExpected );
    171171
    172         // typeof( wxyz[[iw, all, all, iz]] ) xy1 = wxyz[[iw, all, all, iz]];
    173         // assert(( xy1[[ix, iy]]  == valExpected ));
    174 
    175         // typeof(  wxyz[[iw, all, all, iz]] ) xy2;
    176         // &xy2 = &wxyz[[iw, all, all, iz]];
    177         // assert(( xy2[[ix, iy]]  == valExpected ));
    178 
    179         // assert(( wxyz[[iw  , all, all, iz  ]][[ix  , iy  ]] == valExpected ));
    180         // assert(( wxyz[[iw-1, all, all, iz  ]][[ix  , iy  ]] != valExpected ));
    181         // assert(( wxyz[[iw  , all, all, iz-1]][[ix  , iy  ]] != valExpected ));
    182         // assert(( wxyz[[iw  , all, all, iz  ]][[ix-1, iy  ]] != valExpected ));
    183         // assert(( wxyz[[iw  , all, all, iz  ]][[ix  , iy-1]] != valExpected ));
     172        // typeof( wxyz[iw, all, all, iz] ) xy1 = wxyz[iw, all, all, iz];
     173        // assert(( xy1[ix, iy]  == valExpected ));
     174
     175        // typeof(  wxyz[iw, all, all, iz] ) xy2;
     176        // &xy2 = &wxyz[iw, all, all, iz];
     177        // assert(( xy2[ix, iy]  == valExpected ));
     178
     179        // assert(( wxyz[iw  , all, all, iz  ][ix  , iy  ] == valExpected ));
     180        // assert(( wxyz[iw-1, all, all, iz  ][ix  , iy  ] != valExpected ));
     181        // assert(( wxyz[iw  , all, all, iz-1][ix  , iy  ] != valExpected ));
     182        // assert(( wxyz[iw  , all, all, iz  ][ix-1, iy  ] != valExpected ));
     183        // assert(( wxyz[iw  , all, all, iz  ][ix  , iy-1] != valExpected ));
    184184    }
    185185    {
     
    187187        assert( wxyz[all][ix][iy][all] [iw][iz] == valExpected );
    188188
    189         typeof( wxyz[[all, ix, iy, all]] ) wz1 = wxyz[[all, ix, iy, all]];
    190         assert(( wz1[[iw, iz]]  == valExpected ));
    191 
    192         assert(( wxyz[[all  , ix, iy  , all]][[iw  , iz  ]] == valExpected ));
     189        typeof( wxyz[all, ix, iy, all] ) wz1 = wxyz[all, ix, iy, all];
     190        assert(( wz1[iw, iz]  == valExpected ));
     191
     192        assert(( wxyz[all  , ix, iy  , all][iw  , iz  ] == valExpected ));
    193193    }
    194194    {
     
    196196        assert( wxyz[all][ix][all][iz] [iw][iy] == valExpected );
    197197
    198         // assert(( wxyz[[all , ix  , all , iz  ]][[iw  , iy  ]] == valExpected ));
     198        // assert(( wxyz[all , ix  , all , iz  ][iw  , iy  ] == valExpected ));
    199199    }
    200200    {
     
    202202        assert( wxyz[all][all][iy][iz] [iw][ix] == valExpected );
    203203
    204         // assert(( wxyz[[all , all , iy  , iz  ]][[iw  , ix  ]] == valExpected ));
     204        // assert(( wxyz[all , all , iy  , iz  ][iw  , ix  ] == valExpected ));
    205205    }
    206206    {
     
    208208        assert( wxyz[all][ix][all][all] [iw][all][iz] [iy] == valExpected );
    209209
    210         typeof( wxyz[all][ix][all][all] ) wyz_workaround = wxyz[[all , ix , all  , all  ]];
    211         typeof( wyz_workaround[iw][all][iz] ) y_workaround = wyz_workaround[[iw , all , iz  ]];
     210        typeof( wxyz[all][ix][all][all] ) wyz_workaround = wxyz[all , ix , all  , all  ];
     211        typeof( wyz_workaround[iw][all][iz] ) y_workaround = wyz_workaround[iw , all , iz  ];
    212212        assert( y_workaround[iy] == valExpected );
    213213
    214         // assert(( wxyz[[all , ix , all  , all  ]][[iw  , all , iz  ]][iy  ] == valExpected ));
     214        // assert(( wxyz[all , ix , all  , all  ][iw  , all , iz  ][iy  ] == valExpected ));
    215215    }
    216216    {
     
    239239    valExpected = getMagicNumber(2, 3, 4, 5);
    240240    assert(( wxyz [2] [3] [4] [5]  == valExpected ));
    241     assert(( wxyz[[2,  3]][4] [5]  == valExpected ));
    242     assert(( wxyz [2][[3,  4]][5]  == valExpected ));
    243     assert(( wxyz [2] [3][[4,  5]] == valExpected ));
    244     assert(( wxyz[[2,  3,  4]][5]  == valExpected ));
    245     assert(( wxyz [2][[3,  4,  5]] == valExpected ));
    246     assert(( wxyz[[2,  3,  4,  5]] == valExpected ));
     241    assert(( wxyz[2,  3][4] [5]  == valExpected ));
     242    assert(( wxyz [2][3,  4][5]  == valExpected ));
     243    assert(( wxyz [2] [3][4,  5] == valExpected ));
     244    assert(( wxyz[2,  3,  4][5]  == valExpected ));
     245    assert(( wxyz [2][3,  4,  5] == valExpected ));
     246    assert(( wxyz[2,  3,  4,  5] == valExpected ));
    247247
    248248    for ( i; Nw ) {
    249         assert(( wxyz[[ i, 3, 4, 5 ]] == getMagicNumber(i, 3, 4, 5) ));
     249        assert(( wxyz[ i, 3, 4, 5 ] == getMagicNumber(i, 3, 4, 5) ));
    250250    }
    251251
    252252    for ( i; Nx ) {
    253         assert(( wxyz[[ 2, i, 4, 5 ]] == getMagicNumber(2, i, 4, 5) ));
     253        assert(( wxyz[ 2, i, 4, 5 ] == getMagicNumber(2, i, 4, 5) ));
    254254    }
    255255
    256256    for ( i; Ny ) {
    257         assert(( wxyz[[ 2, 3, i, 5 ]] == getMagicNumber(2, 3, i, 5) ));
     257        assert(( wxyz[ 2, 3, i, 5 ] == getMagicNumber(2, 3, i, 5) ));
    258258    }
    259259
    260260    for ( i; Nz ) {
    261         assert(( wxyz[[ 2, 3, 4, i ]] == getMagicNumber(2, 3, 4, i) ));
     261        assert(( wxyz[ 2, 3, 4, i ] == getMagicNumber(2, 3, 4, i) ));
    262262    }
    263263
    264264    for ( i; Nw ) {
    265         assert(( wxyz[[ i, all, 4, 5 ]][3] == getMagicNumber(i, 3, 4, 5) ));
     265        assert(( wxyz[ i, all, 4, 5 ][3] == getMagicNumber(i, 3, 4, 5) ));
    266266    }
    267267
    268268    for ( i; Nw ) {
    269         assert(( wxyz[[ all, 3, 4, 5 ]][i] == getMagicNumber(i, 3, 4, 5) ));
     269        assert(( wxyz[ all, 3, 4, 5 ][i] == getMagicNumber(i, 3, 4, 5) ));
    270270    }
    271271}
Note: See TracChangeset for help on using the changeset viewer.