Changeset 262a864


Ignore:
Timestamp:
Dec 16, 2024, 9:37:09 PM (9 months ago)
Author:
Peter A. Buhr <pabuhr@…>
Branches:
master
Children:
2980ccb8, 9b55aa3
Parents:
9a01745 (diff), 80018f5 (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

Files:
5 edited

Legend:

Unmodified
Added
Removed
  • doc/proposals/enums.md

    r9a01745 r262a864  
    88--------------
    99Because Cforall enumerations are encoded using their position, it can be
    10 difficult to give them a stable encoding. The
     10difficult to give them a stable encoding, this is important in seperate
     11compilation.
    1112
    1213The example (provided by Gregor Richards), is a system header that defines
     
    4243(instead of a subset of int) is used in the index operation.
    4344
     45```cfa
     46enum() Colour {
     47  Red,
     48  Violet,
     49  Blue,
     50  Green
     51  Yellow,
     52  Orange,
     53};
     54
     55// Declare an array with an index of an enumeration:
     56int jarsOfPaint[Colour] = {0};
     57
     58// Index the array:
     59printf("I have %d jars of blue paint.\n", jarsOfPaint[Blue]);
     60jarsOfPaint[Green] = 3;
     61jarsOfPaint[Red] += 1;
     62
     63// Use the function for higher order programming:
     64int (*lookup)(int collection[Colour], Colour key) = ?[?];
     65
     66// ERROR! Use the enumeration index for safety:
     67jarsOfPaint[0] = 0;
     68```
     69
    4470Although described differently, this is actually a generalization of typed
    4571enumerations, as it can be used to safely represent a constant of any type
     
    80106Or one of the new safer Cforall arrays, as the features could be combined.
    81107
    82 (Previously, a compined declaration to declare both an enumeration and
     108(Previously, a combined declaration to declare both an enumeration and
    83109an enumerated array was proposed. That only covers the simple case that
    84110typed enumerations already cover.)
     
    90116generalized to work with the other features of ranges, such as going over
    91117just part of the enumeration (see Ranges in doc/proposals/iterators.md).
     118
     119This will work best with some alias labels that mark out the beginning of
     120ranges. That is the ranges within the enum will often have to be an
     121intended part of the interface.
     122
     123```cfa
     124for ( kind : DataKind.BeginIntegers +~ DataKind.EndIntegers ) { ... }
     125```
     126
     127Writing the declaration is a bit tricker, because of the lack of aliasing,
     128but this should echo a common C pattern.
    92129
    93130Flag Set Enumerations
     
    111148```
    112149
     150Some example usages:
     151```cfa
     152// If it is exactly Up/Upwards, then set exactly Down
     153if ( Upwards == dirs ) {
     154  dirs = Down
     155// Otherwise, if a vertical is set, unset them:
     156} else if ( Vertical & dirs ) {
     157  dirs = dirs & ~Vertical;
     158// Otherwise, if any direction is set then also set Up:
     159} else if ( dirs ) {
     160  dirs |= Up;
     161}
     162```
     163
    113164Uses the existing enumeration syntax, except that all initializers must be
    114165bitwise expressions, using only the operators |, & and ~ and, as leaf values,
     
    132183
    133184Note: Scoping rules are also waiting on the namespacing and module system.
     185
     186Feature (and Storage) Control
     187-----------------------------
     188Right now features are very coursely grouped. You have exactly three options
     189for your enumeration. However since there are more than two features this
     190means there are some combinations you cannot have.
     191
     192For instance, labels (which are mostly useful for generating debug output)
     193are not available for C style enum, but for both of the new Cforall enums,
     194opaque and typed. However, there is no innate connection between the
     195additional type safety of the opaque enum or the associated values/payloads
     196of the typed enums.
     197
     198Enumerations do interact with on feature that shows this orthagonality,
     199and that is the scoping "no export" marker, that can be applied to any
     200enumeration to change the visibility rules of the enumeration and does not
     201change anything else.
     202
     203This is not urgent, just not using the features you don't want is almost as
     204clear and the compile-time, binary-size and runtime costs are all good enough
     205for now (and some day all of those may have to be improved even when the
     206feature is being used). Isolating independent features is just good design.
  • src/CodeGen/OperatorTable.cpp

    r9a01745 r262a864  
    7676        }
    7777
    78         if ( inputName.find_first_of( "?^*+-!", 0, 1 ) == std::string::npos ) return nullptr; // prefilter
    79         const OperatorInfo * ret = inputTable.find( inputName )->second;
     78        // Filter out non-operator names:
     79        if ( inputName.find_first_of( "?^*+-!", 0, 1 ) == std::string::npos ) return nullptr;
     80        auto entry = inputTable.find( inputName );
    8081        // This can only happen if an invalid identifier name has been used.
     82        assertf( entry != inputTable.end(), "Not a real operator: %s\n", inputName.c_str() );
     83        const OperatorInfo * ret = entry->second;
    8184        assert( ret );
    8285        return ret;
  • src/Validate/ReplaceTypedef.cpp

    r9a01745 r262a864  
    1010// Created On       : Tue Jun 29 14:59:00 2022
    1111// Last Modified By : Peter A. Buhr
    12 // Last Modified On : Thu Dec 14 16:11:51 2023
    13 // Update Count     : 4
     12// Last Modified On : Mon Dec 16 20:50:42 2024
     13// Update Count     : 5
    1414//
    1515
     
    135135};
    136136static bool dimensionPresenceMismatched( const ast::Type * t0, const ast::Type * t1) {
    137         std::vector<const ast::ArrayType *> at0s = std::move(
    138                 ast::Pass<ArrayTypeExtractor>::read( t0 ) );
    139         std::vector<const ast::ArrayType *> at1s = std::move(
    140                 ast::Pass<ArrayTypeExtractor>::read( t1 ) );
     137        std::vector<const ast::ArrayType *> at0s = ast::Pass<ArrayTypeExtractor>::read( t0 );
     138        std::vector<const ast::ArrayType *> at1s = ast::Pass<ArrayTypeExtractor>::read( t1 );
    141139        assert( at0s.size() == at1s.size() );
    142140        for (size_t i = 0; i < at0s.size(); i++) {
  • tests/.expect/attributes.arm64.txt

    r9a01745 r262a864  
    13371337    return _X4_retS3Vad_1;
    13381338}
     1339__attribute__ (( noreturn )) void _X4fredFv___1(void){
     1340    __attribute__ ((unused)) signed int _X1ii_2;
     1341    switch ( 3 ) {
     1342        case 2:
     1343            {
     1344                {
     1345                    ((void)4);
     1346                }
     1347
     1348            }
     1349        case 1:
     1350            {
     1351                {
     1352                    ((void)3);
     1353                }
     1354
     1355            }
     1356    }
     1357
     1358}
     1359__attribute__ ((noreturn)) void _X4maryFv___1(void){
     1360    struct __attribute__ ((aligned(64))) S {
     1361        signed int _X1ii_2;
     1362    };
     1363    inline void _X12_constructorFv_S1S_autogen___2(__attribute__ ((unused)) struct S *_X4_dstS1S_2){
     1364        {
     1365            ((void)((*_X4_dstS1S_2)._X1ii_2) /* ?{} */);
     1366        }
     1367
     1368    }
     1369    inline void _X12_constructorFv_S1SS1S_autogen___2(__attribute__ ((unused)) struct S *_X4_dstS1S_2, __attribute__ ((unused)) struct S _X4_srcS1S_2){
     1370        {
     1371            ((void)((*_X4_dstS1S_2)._X1ii_2=_X4_srcS1S_2._X1ii_2) /* ?{} */);
     1372        }
     1373
     1374    }
     1375    inline void _X11_destructorFv_S1S_autogen___2(__attribute__ ((unused)) struct S *_X4_dstS1S_2){
     1376        {
     1377            ((void)((*_X4_dstS1S_2)._X1ii_2) /* ^?{} */);
     1378        }
     1379
     1380    }
     1381    inline struct S _X16_operator_assignFS1S_S1SS1S_autogen___2(__attribute__ ((unused)) struct S *_X4_dstS1S_2, __attribute__ ((unused)) struct S _X4_srcS1S_2){
     1382        __attribute__ ((unused)) struct S _X4_retS1S_2;
     1383        {
     1384            ((void)((*_X4_dstS1S_2)._X1ii_2=_X4_srcS1S_2._X1ii_2));
     1385        }
     1386
     1387        {
     1388            ((void)_X12_constructorFv_S1SS1S_autogen___2((&_X4_retS1S_2), (*_X4_dstS1S_2)));
     1389        }
     1390
     1391        return _X4_retS1S_2;
     1392    }
     1393    inline void _X12_constructorFv_S1Si_autogen___2(__attribute__ ((unused)) struct S *_X4_dstS1S_2, signed int _X1ii_2){
     1394        {
     1395            ((void)((*_X4_dstS1S_2)._X1ii_2=_X1ii_2) /* ?{} */);
     1396        }
     1397
     1398    }
     1399    __attribute__ ((unused)) signed int _X1ii_2;
     1400    switch ( 3 ) {
     1401        case 2:
     1402            {
     1403                {
     1404                    ((void)4);
     1405                }
     1406
     1407            }
     1408        case 1:
     1409            {
     1410                {
     1411                    ((void)3);
     1412                }
     1413
     1414            }
     1415    }
     1416
     1417}
  • tests/.expect/attributes.x86.txt

    r9a01745 r262a864  
    13371337    return _X4_retS3Vad_1;
    13381338}
     1339__attribute__ (( noreturn )) void _X4fredFv___1(void){
     1340    __attribute__ ((unused)) signed int _X1ii_2;
     1341    switch ( 3 ) {
     1342        case 2:
     1343            {
     1344                {
     1345                    ((void)4);
     1346                }
     1347
     1348            }
     1349        case 1:
     1350            {
     1351                {
     1352                    ((void)3);
     1353                }
     1354
     1355            }
     1356    }
     1357
     1358}
     1359__attribute__ ((noreturn)) void _X4maryFv___1(void){
     1360    struct __attribute__ ((aligned(64))) S {
     1361        signed int _X1ii_2;
     1362    };
     1363    inline void _X12_constructorFv_S1S_autogen___2(__attribute__ ((unused)) struct S *_X4_dstS1S_2){
     1364        {
     1365            ((void)((*_X4_dstS1S_2)._X1ii_2) /* ?{} */);
     1366        }
     1367
     1368    }
     1369    inline void _X12_constructorFv_S1SS1S_autogen___2(__attribute__ ((unused)) struct S *_X4_dstS1S_2, __attribute__ ((unused)) struct S _X4_srcS1S_2){
     1370        {
     1371            ((void)((*_X4_dstS1S_2)._X1ii_2=_X4_srcS1S_2._X1ii_2) /* ?{} */);
     1372        }
     1373
     1374    }
     1375    inline void _X11_destructorFv_S1S_autogen___2(__attribute__ ((unused)) struct S *_X4_dstS1S_2){
     1376        {
     1377            ((void)((*_X4_dstS1S_2)._X1ii_2) /* ^?{} */);
     1378        }
     1379
     1380    }
     1381    inline struct S _X16_operator_assignFS1S_S1SS1S_autogen___2(__attribute__ ((unused)) struct S *_X4_dstS1S_2, __attribute__ ((unused)) struct S _X4_srcS1S_2){
     1382        __attribute__ ((unused)) struct S _X4_retS1S_2;
     1383        {
     1384            ((void)((*_X4_dstS1S_2)._X1ii_2=_X4_srcS1S_2._X1ii_2));
     1385        }
     1386
     1387        {
     1388            ((void)_X12_constructorFv_S1SS1S_autogen___2((&_X4_retS1S_2), (*_X4_dstS1S_2)));
     1389        }
     1390
     1391        return _X4_retS1S_2;
     1392    }
     1393    inline void _X12_constructorFv_S1Si_autogen___2(__attribute__ ((unused)) struct S *_X4_dstS1S_2, signed int _X1ii_2){
     1394        {
     1395            ((void)((*_X4_dstS1S_2)._X1ii_2=_X1ii_2) /* ?{} */);
     1396        }
     1397
     1398    }
     1399    __attribute__ ((unused)) signed int _X1ii_2;
     1400    switch ( 3 ) {
     1401        case 2:
     1402            {
     1403                {
     1404                    ((void)4);
     1405                }
     1406
     1407            }
     1408        case 1:
     1409            {
     1410                {
     1411                    ((void)3);
     1412                }
     1413
     1414            }
     1415    }
     1416
     1417}
Note: See TracChangeset for help on using the changeset viewer.