Changes in / [c08c3cf:467c8b7]


Ignore:
Files:
146 edited

Legend:

Unmodified
Added
Removed
  • libcfa/prelude/builtins.c

    rc08c3cf r467c8b7  
    1818// type that wraps a pointer and a destructor-like function - used in generating implicit destructor calls for struct members in user-defined functions
    1919// Note: needs to occur early, because it is used to generate destructor calls during code generation
    20 forall(T &)
     20forall(dtype T)
    2121struct __Destructor {
    2222        T * object;
     
    2525
    2626// defined destructor in the case that non-generated code wants to use __Destructor
    27 forall(T &)
     27forall(dtype T)
    2828static inline void ^?{}(__Destructor(T) & x) {
    2929        if (x.object && x.dtor) {
     
    3434// easy interface into __Destructor's destructor for easy codegen purposes
    3535extern "C" {
    36         forall(T &)
     36        forall(dtype T)
    3737        static inline void __destroy_Destructor(__Destructor(T) * dtor) {
    3838                ^(*dtor){};
     
    5151void abort( const char fmt[], ... ) __attribute__ (( format(printf, 1, 2), __nothrow__, __leaf__, __noreturn__ ));
    5252
    53 forall(T &)
     53forall(dtype T)
    5454static inline T & identity(T & i) {
    5555        return i;
     
    6464static inline void ^?{}($generator &) {}
    6565
    66 trait is_generator(T &) {
     66trait is_generator(dtype T) {
    6767      void main(T & this);
    6868      $generator * get_generator(T & this);
    6969};
    7070
    71 forall(T & | is_generator(T))
     71forall(dtype T | is_generator(T))
    7272static inline T & resume(T & gen) {
    7373        main(gen);
     
    7878
    7979static inline {
    80         forall( DT & | { DT & ?+=?( DT &, one_t ); } )
     80        forall( dtype DT | { DT & ?+=?( DT &, one_t ); } )
    8181        DT & ++?( DT & x ) { return x += 1; }
    8282
    83         forall( DT & | sized(DT) | { void ?{}( DT &, DT ); void ^?{}( DT & ); DT & ?+=?( DT &, one_t ); } )
     83        forall( dtype DT | sized(DT) | { void ?{}( DT &, DT ); void ^?{}( DT & ); DT & ?+=?( DT &, one_t ); } )
    8484        DT & ?++( DT & x ) { DT tmp = x; x += 1; return tmp; }
    8585
    86         forall( DT & | { DT & ?-=?( DT &, one_t ); } )
     86        forall( dtype DT | { DT & ?-=?( DT &, one_t ); } )
    8787        DT & --?( DT & x ) { return x -= 1; }
    8888
    89         forall( DT & | sized(DT) | { void ?{}( DT &, DT ); void ^?{}( DT & ); DT & ?-=?( DT &, one_t ); } )
     89        forall( dtype DT | sized(DT) | { void ?{}( DT &, DT ); void ^?{}( DT & ); DT & ?-=?( DT &, one_t ); } )
    9090        DT & ?--( DT & x ) { DT tmp = x; x -= 1; return tmp; }
    9191
    92         forall( DT & | { int ?!=?( const DT &, zero_t ); } )
     92        forall( dtype DT | { int ?!=?( const DT &, zero_t ); } )
    9393        int !?( const DT & x ) { return !( x != 0 ); }
    9494} // distribution
    9595
    9696// universal typed pointer constant
    97 static inline forall( DT & ) DT * intptr( uintptr_t addr ) { return (DT *)addr; }
     97static inline forall( dtype DT ) DT * intptr( uintptr_t addr ) { return (DT *)addr; }
    9898static inline forall( ftype FT ) FT * intptr( uintptr_t addr ) { return (FT *)addr; }
    9999
     
    156156#define __CFA_EXP_OVERFLOW__()
    157157
    158 static inline forall( OT | { void ?{}( OT & this, one_t ); OT ?*?( OT, OT ); } ) {
     158static inline forall( otype OT | { void ?{}( OT & this, one_t ); OT ?*?( OT, OT ); } ) {
    159159        OT ?\?( OT ep, unsigned int y ) { __CFA_EXP__(); }
    160160        OT ?\?( OT ep, unsigned long int y ) { __CFA_EXP__(); }
  • libcfa/prelude/prelude-gen.cc

    rc08c3cf r467c8b7  
    159159int main() {
    160160        cout << "# 2 \"prelude.cfa\"  // needed for error messages from this file" << endl;
    161         cout << "trait sized(T &) {};" << endl;
     161        cout << "trait sized(dtype T) {};" << endl;
    162162
    163163        cout << "//////////////////////////" << endl;
     
    264264                for (auto cvq : qualifiersPair) {
    265265                        for (auto is_vol : { "        ", "volatile" }) {
    266                                 cout << "forall(DT &) void  ?{}(" << cvq.first << type << " * " << is_vol << " &, " << cvq.second << "DT *);" << endl;
     266                                cout << "forall(dtype DT) void  ?{}(" << cvq.first << type << " * " << is_vol << " &, " << cvq.second << "DT *);" << endl;
    267267                        }
    268268                }
     
    279279        for (auto cvq : qualifiersSingle) {
    280280                for (auto is_vol : { "        ", "volatile" }) {
    281                         cout << "forall(DT &) void  ?{}(" << cvq << "  DT" << " * " << is_vol << " &);" << endl;
     281                        cout << "forall(dtype DT) void  ?{}(" << cvq << "  DT" << " * " << is_vol << " &);" << endl;
    282282                }
    283283                for (auto is_vol : { "        ", "volatile" }) {
    284                         cout << "forall(DT &) void ^?{}(" << cvq << "  DT" << " * " << is_vol << " &);" << endl;
     284                        cout << "forall(dtype DT) void ^?{}(" << cvq << "  DT" << " * " << is_vol << " &);" << endl;
    285285                }
    286286        }
     
    290290                for (auto is_vol : { "        ", "volatile" }) {
    291291                        for (auto cvq : qualifiersSingle) {
    292                                 cout << "forall(DT &) void ?{}( " << cvq << type << " * " << is_vol << " &, zero_t);" << endl;
     292                                cout << "forall(dtype DT) void ?{}( " << cvq << type << " * " << is_vol << " &, zero_t);" << endl;
    293293                        }
    294294                }
     
    317317        for (auto op : pointerOperators) {
    318318                auto forall = [&op]() {
    319                         cout << "forall(DT &" << op.sized << ") ";
     319                        cout << "forall(dtype DT" << op.sized << ") ";
    320320                };
    321321                for (auto type : { "DT"/*, "void"*/ } ) {
     
    408408        for (auto is_vol : { "        ", "volatile" }) {
    409409                for (auto cvq : qualifiersPair) {
    410                                 cout << "forall(DT &) " << cvq.first << "void * ?=?( " << cvq.first << "void * " << is_vol << " &, " << cvq.second << "DT *);" << endl;
     410                                cout << "forall(dtype DT) " << cvq.first << "void * ?=?( " << cvq.first << "void * " << is_vol << " &, " << cvq.second << "DT *);" << endl;
    411411                }
    412412                for (auto cvq : qualifiersSingle) {
    413                         cout << "forall(DT &) " << cvq <<   "  DT * ?=?( " << cvq << "  DT * " << is_vol << " &, zero_t);" << endl;
     413                        cout << "forall(dtype DT) " << cvq <<   "  DT * ?=?( " << cvq << "  DT * " << is_vol << " &, zero_t);" << endl;
    414414                }
    415415        }
  • libcfa/prelude/prelude.old.cf

    rc08c3cf r467c8b7  
    2323// ------------------------------------------------------------
    2424
    25 trait sized(T &) {};
     25trait sized(dtype T) {};
    2626
    2727// ------------------------------------------------------------
     
    6868long double _Complex    ?--( long double _Complex & ),          ?--( volatile long double _Complex & );
    6969
    70 forall( T & | sized(T) ) T *                     ?++(                T *& );
    71 forall( T & | sized(T) ) const T *               ?++( const          T *& );
    72 forall( T & | sized(T) ) volatile T *            ?++(       volatile T *& );
    73 forall( T & | sized(T) ) const volatile T *      ?++( const volatile T *& );
    74 forall( T & | sized(T) ) T *                     ?--(                T *& );
    75 forall( T & | sized(T) ) const T *               ?--( const          T *& );
    76 forall( T & | sized(T) ) volatile T *            ?--(       volatile T *& );
    77 forall( T & | sized(T) ) const volatile T *      ?--( const volatile T *& );
    78 
    79 forall( T & | sized(T) ) T &             ?[?](                T *,          ptrdiff_t );
    80 forall( T & | sized(T) ) const T &       ?[?]( const          T *,          ptrdiff_t );
    81 forall( T & | sized(T) ) volatile T &    ?[?](       volatile T *,          ptrdiff_t );
    82 forall( T & | sized(T) ) const volatile T & ?[?]( const volatile T *,       ptrdiff_t );
    83 forall( T & | sized(T) ) T &             ?[?](          ptrdiff_t,                T * );
    84 forall( T & | sized(T) ) const T &       ?[?](          ptrdiff_t, const          T * );
    85 forall( T & | sized(T) ) volatile T &    ?[?](          ptrdiff_t,       volatile T * );
    86 forall( T & | sized(T) ) const volatile T & ?[?](               ptrdiff_t, const volatile T * );
     70forall( dtype T | sized(T) ) T *                         ?++(                T *& );
     71forall( dtype T | sized(T) ) const T *           ?++( const          T *& );
     72forall( dtype T | sized(T) ) volatile T *                ?++(       volatile T *& );
     73forall( dtype T | sized(T) ) const volatile T *  ?++( const volatile T *& );
     74forall( dtype T | sized(T) ) T *                         ?--(                T *& );
     75forall( dtype T | sized(T) ) const T *           ?--( const          T *& );
     76forall( dtype T | sized(T) ) volatile T *                ?--(       volatile T *& );
     77forall( dtype T | sized(T) ) const volatile T *  ?--( const volatile T *& );
     78
     79forall( dtype T | sized(T) ) T &                 ?[?](                T *,          ptrdiff_t );
     80forall( dtype T | sized(T) ) const T &   ?[?]( const          T *,          ptrdiff_t );
     81forall( dtype T | sized(T) ) volatile T &        ?[?](       volatile T *,          ptrdiff_t );
     82forall( dtype T | sized(T) ) const volatile T & ?[?]( const volatile T *,           ptrdiff_t );
     83forall( dtype T | sized(T) ) T &                 ?[?](          ptrdiff_t,                T * );
     84forall( dtype T | sized(T) ) const T &   ?[?](          ptrdiff_t, const          T * );
     85forall( dtype T | sized(T) ) volatile T &        ?[?](          ptrdiff_t,       volatile T * );
     86forall( dtype T | sized(T) ) const volatile T & ?[?](           ptrdiff_t, const volatile T * );
    8787
    8888// ------------------------------------------------------------
     
    107107long double _Complex    ++?( long double _Complex & ),          --?( long double _Complex & );
    108108
    109 forall( T & | sized(T) ) T *                     ++?(                T *& );
    110 forall( T & | sized(T) ) const T *               ++?( const          T *& );
    111 forall( T & | sized(T) ) volatile T *            ++?(       volatile T *& );
    112 forall( T & | sized(T) ) const volatile T *      ++?( const volatile T *& );
    113 forall( T & | sized(T) ) T *                     --?(                T *& );
    114 forall( T & | sized(T) ) const T *               --?( const          T *& );
    115 forall( T & | sized(T) ) volatile T *            --?(       volatile T *& );
    116 forall( T & | sized(T) ) const volatile T *      --?( const volatile T *& );
    117 
    118 forall( T & | sized(T) ) T &             *?(                 T * );
    119 forall( T & | sized(T) ) const T &               *?( const           T * );
    120 forall( T & | sized(T) ) volatile T &    *?(       volatile  T * );
    121 forall( T & | sized(T) ) const volatile T & *?( const volatile  T * );
     109forall( dtype T | sized(T) ) T *                         ++?(                T *& );
     110forall( dtype T | sized(T) ) const T *           ++?( const          T *& );
     111forall( dtype T | sized(T) ) volatile T *                ++?(       volatile T *& );
     112forall( dtype T | sized(T) ) const volatile T *  ++?( const volatile T *& );
     113forall( dtype T | sized(T) ) T *                         --?(                T *& );
     114forall( dtype T | sized(T) ) const T *           --?( const          T *& );
     115forall( dtype T | sized(T) ) volatile T *                --?(       volatile T *& );
     116forall( dtype T | sized(T) ) const volatile T *  --?( const volatile T *& );
     117
     118forall( dtype T | sized(T) ) T &                 *?(                 T * );
     119forall( dtype T | sized(T) ) const T &           *?( const           T * );
     120forall( dtype T | sized(T) ) volatile T &        *?(       volatile  T * );
     121forall( dtype T | sized(T) ) const volatile T & *?( const volatile  T * );
    122122forall( ftype FT ) FT &          *?( FT * );
    123123
     
    142142                !?( float _Complex ),           !?( double _Complex ),          !?( long double _Complex );
    143143
    144 forall( DT & ) int !?(                DT * );
    145 forall( DT & ) int !?( const          DT * );
    146 forall( DT & ) int !?(       volatile DT * );
    147 forall( DT & ) int !?( const volatile DT * );
     144forall( dtype DT ) int !?(                DT * );
     145forall( dtype DT ) int !?( const          DT * );
     146forall( dtype DT ) int !?(       volatile DT * );
     147forall( dtype DT ) int !?( const volatile DT * );
    148148forall( ftype FT ) int !?( FT * );
    149149
     
    191191long double _Complex    ?+?( long double _Complex, long double _Complex ),      ?-?( long double _Complex, long double _Complex );
    192192
    193 forall( T & | sized(T) ) T *            ?+?(                T *,          ptrdiff_t );
    194 forall( T & | sized(T) ) T *            ?+?(          ptrdiff_t,                T * );
    195 forall( T & | sized(T) ) const T *              ?+?( const          T *,          ptrdiff_t );
    196 forall( T & | sized(T) ) const T *              ?+?(          ptrdiff_t, const          T * );
    197 forall( T & | sized(T) ) volatile T *   ?+?(       volatile T *,          ptrdiff_t );
    198 forall( T & | sized(T) ) volatile T *   ?+?(          ptrdiff_t,       volatile T * );
    199 forall( T & | sized(T) ) const volatile T *     ?+?( const volatile T *,          ptrdiff_t );
    200 forall( T & | sized(T) ) const volatile T *     ?+?(          ptrdiff_t, const volatile T * );
    201 forall( T & | sized(T) ) T *            ?-?(                T *,          ptrdiff_t );
    202 forall( T & | sized(T) ) const T *              ?-?( const          T *,          ptrdiff_t );
    203 forall( T & | sized(T) ) volatile T *   ?-?(       volatile T *,          ptrdiff_t );
    204 forall( T & | sized(T) ) const volatile T *     ?-?( const volatile T *,          ptrdiff_t );
    205 forall( T & | sized(T) ) ptrdiff_t              ?-?( const volatile T *, const volatile T * );
     193forall( dtype T | sized(T) ) T *                ?+?(                T *,          ptrdiff_t );
     194forall( dtype T | sized(T) ) T *                ?+?(          ptrdiff_t,                T * );
     195forall( dtype T | sized(T) ) const T *          ?+?( const          T *,          ptrdiff_t );
     196forall( dtype T | sized(T) ) const T *          ?+?(          ptrdiff_t, const          T * );
     197forall( dtype T | sized(T) ) volatile T *       ?+?(       volatile T *,          ptrdiff_t );
     198forall( dtype T | sized(T) ) volatile T *       ?+?(          ptrdiff_t,       volatile T * );
     199forall( dtype T | sized(T) ) const volatile T * ?+?( const volatile T *,          ptrdiff_t );
     200forall( dtype T | sized(T) ) const volatile T * ?+?(          ptrdiff_t, const volatile T * );
     201forall( dtype T | sized(T) ) T *                ?-?(                T *,          ptrdiff_t );
     202forall( dtype T | sized(T) ) const T *          ?-?( const          T *,          ptrdiff_t );
     203forall( dtype T | sized(T) ) volatile T *       ?-?(       volatile T *,          ptrdiff_t );
     204forall( dtype T | sized(T) ) const volatile T * ?-?( const volatile T *,          ptrdiff_t );
     205forall( dtype T | sized(T) ) ptrdiff_t          ?-?( const volatile T *, const volatile T * );
    206206
    207207// ------------------------------------------------------------
     
    255255           ?>?( long double, long double ),                             ?>=?( long double, long double );
    256256
    257 forall( DT & ) signed int ?<?(                 DT *,                DT * );
    258 forall( DT & ) signed int ?<?(  const          DT *, const          DT * );
    259 forall( DT & ) signed int ?<?(        volatile DT *,       volatile DT * );
    260 forall( DT & ) signed int ?<?(  const volatile DT *, const volatile DT * );
    261 
    262 forall( DT & ) signed int ?>?(                 DT *,                DT * );
    263 forall( DT & ) signed int ?>?(  const          DT *, const          DT * );
    264 forall( DT & ) signed int ?>?(        volatile DT *,       volatile DT * );
    265 forall( DT & ) signed int ?>?(  const volatile DT *, const volatile DT * );
    266 
    267 forall( DT & ) signed int ?<=?(                 DT *,                DT * );
    268 forall( DT & ) signed int ?<=?(  const          DT *, const          DT * );
    269 forall( DT & ) signed int ?<=?(        volatile DT *,       volatile DT * );
    270 forall( DT & ) signed int ?<=?( const volatile DT *, const volatile DT * );
    271 
    272 forall( DT & ) signed int ?>=?(                 DT *,                DT * );
    273 forall( DT & ) signed int ?>=?(  const          DT *, const          DT * );
    274 forall( DT & ) signed int ?>=?(        volatile DT *,       volatile DT * );
    275 forall( DT & ) signed int ?>=?( const volatile DT *, const volatile DT * );
     257forall( dtype DT ) signed int ?<?(                 DT *,                DT * );
     258forall( dtype DT ) signed int ?<?(  const          DT *, const          DT * );
     259forall( dtype DT ) signed int ?<?(        volatile DT *,       volatile DT * );
     260forall( dtype DT ) signed int ?<?(  const volatile DT *, const volatile DT * );
     261
     262forall( dtype DT ) signed int ?>?(                 DT *,                DT * );
     263forall( dtype DT ) signed int ?>?(  const          DT *, const          DT * );
     264forall( dtype DT ) signed int ?>?(        volatile DT *,       volatile DT * );
     265forall( dtype DT ) signed int ?>?(  const volatile DT *, const volatile DT * );
     266
     267forall( dtype DT ) signed int ?<=?(                 DT *,                DT * );
     268forall( dtype DT ) signed int ?<=?(  const          DT *, const          DT * );
     269forall( dtype DT ) signed int ?<=?(        volatile DT *,       volatile DT * );
     270forall( dtype DT ) signed int ?<=?( const volatile DT *, const volatile DT * );
     271
     272forall( dtype DT ) signed int ?>=?(                 DT *,                DT * );
     273forall( dtype DT ) signed int ?>=?(  const          DT *, const          DT * );
     274forall( dtype DT ) signed int ?>=?(        volatile DT *,       volatile DT * );
     275forall( dtype DT ) signed int ?>=?( const volatile DT *, const volatile DT * );
    276276
    277277// ------------------------------------------------------------
     
    302302signed int ?==?( one_t, one_t ),                                                        ?!=?( one_t, one_t );
    303303
    304 forall( DT & ) signed int ?==?(            DT *,                DT * );
    305 forall( DT & ) signed int ?==?( const      DT *, const          DT * );
    306 forall( DT & ) signed int ?==?(       volatile DT *,       volatile DT * );
    307 forall( DT & ) signed int ?==?( const volatile DT *, const volatile DT * );
     304forall( dtype DT ) signed int ?==?(                DT *,                DT * );
     305forall( dtype DT ) signed int ?==?( const          DT *, const          DT * );
     306forall( dtype DT ) signed int ?==?(       volatile DT *,       volatile DT * );
     307forall( dtype DT ) signed int ?==?( const volatile DT *, const volatile DT * );
    308308forall( ftype FT ) signed int ?==?( FT *, FT * );
    309 forall( DT & ) signed int ?!=?(            DT *,                DT * );
    310 forall( DT & ) signed int ?!=?( const      DT *, const          DT * );
    311 forall( DT & ) signed int ?!=?(       volatile DT *,       volatile DT * );
    312 forall( DT & ) signed int ?!=?( const volatile DT *, const volatile DT * );
     309forall( dtype DT ) signed int ?!=?(                DT *,                DT * );
     310forall( dtype DT ) signed int ?!=?( const          DT *, const          DT * );
     311forall( dtype DT ) signed int ?!=?(       volatile DT *,       volatile DT * );
     312forall( dtype DT ) signed int ?!=?( const volatile DT *, const volatile DT * );
    313313forall( ftype FT ) signed int ?!=?( FT *, FT * );
    314314
     
    376376
    377377forall( ftype FT ) FT *                 ?=?( FT *&, FT * );
    378 forall( ftyep FT ) FT *                 ?=?( FT * volatile &, FT * );
    379 
    380 forall( DT & ) DT *                     ?=?(                 DT *          &,                   DT * );
    381 forall( DT & ) DT *                     ?=?(                 DT * volatile &,                   DT * );
    382 forall( DT & ) const DT *               ?=?( const           DT *          &,                   DT * );
    383 forall( DT & ) const DT *               ?=?( const           DT * volatile &,                   DT * );
    384 forall( DT & ) const DT *               ?=?( const           DT *          &, const             DT * );
    385 forall( DT & ) const DT *               ?=?( const           DT * volatile &, const             DT * );
    386 forall( DT & ) volatile DT *    ?=?(       volatile  DT *          &,                   DT * );
    387 forall( DT & ) volatile DT *    ?=?(       volatile  DT * volatile &,                   DT * );
    388 forall( DT & ) volatile DT *    ?=?(       volatile  DT *          &,       volatile    DT * );
    389 forall( DT & ) volatile DT *    ?=?(       volatile  DT * volatile &,       volatile    DT * );
    390 
    391 forall( DT & ) const volatile DT *      ?=?( const volatile  DT *          &,                   DT * );
    392 forall( DT & ) const volatile DT *  ?=?( const volatile  DT * volatile &,                       DT * );
    393 forall( DT & ) const volatile DT *  ?=?( const volatile  DT *      &, const             DT * );
    394 forall( DT & ) const volatile DT *  ?=?( const volatile  DT * volatile &, const         DT * );
    395 forall( DT & ) const volatile DT *  ?=?( const volatile  DT *      &,       volatile    DT * );
    396 forall( DT & ) const volatile DT *  ?=?( const volatile  DT * volatile &,           volatile    DT * );
    397 forall( DT & ) const volatile DT *  ?=?( const volatile  DT *      &, const volatile    DT * );
    398 forall( DT & ) const volatile DT *  ?=?( const volatile  DT * volatile &, const volatile        DT * );
    399 
    400 forall( DT & ) void *            ?=?(                void *          &,                 DT * );
    401 forall( DT & ) void *            ?=?(                void * volatile &,                 DT * );
    402 forall( DT & ) const void *              ?=?( const          void *          &,                 DT * );
    403 forall( DT & ) const void *              ?=?( const          void * volatile &,                 DT * );
    404 forall( DT & ) const void *              ?=?( const          void *          &, const           DT * );
    405 forall( DT & ) const void *              ?=?( const          void * volatile &, const           DT * );
    406 forall( DT & ) volatile void *   ?=?(       volatile void *          &,                 DT * );
    407 forall( DT & ) volatile void *   ?=?(       volatile void * volatile &,                 DT * );
    408 forall( DT & ) volatile void *   ?=?(       volatile void *          &,       volatile  DT * );
    409 forall( DT & ) volatile void *   ?=?(       volatile void * volatile &,       volatile  DT * );
    410 forall( DT & ) const volatile void * ?=?( const volatile void *      &,                 DT * );
    411 forall( DT & ) const volatile void * ?=?( const volatile void * volatile &,                     DT * );
    412 forall( DT & ) const volatile void * ?=?( const volatile void *      &, const           DT * );
    413 forall( DT & ) const volatile void * ?=?( const volatile void * volatile &, const               DT * );
    414 forall( DT & ) const volatile void * ?=?( const volatile void *      &,       volatile  DT * );
    415 forall( DT & ) const volatile void * ?=?( const volatile void * volatile &,           volatile  DT * );
    416 forall( DT & ) const volatile void * ?=?( const volatile void *      &, const volatile  DT * );
    417 forall( DT & ) const volatile void * ?=?( const volatile void * volatile &, const volatile      DT * );
     378forall( ftype FT ) FT *                 ?=?( FT * volatile &, FT * );
     379
     380forall( dtype DT ) DT *                 ?=?(                 DT *          &,                   DT * );
     381forall( dtype DT ) DT *                 ?=?(                 DT * volatile &,                   DT * );
     382forall( dtype DT ) const DT *           ?=?( const           DT *          &,                   DT * );
     383forall( dtype DT ) const DT *           ?=?( const           DT * volatile &,                   DT * );
     384forall( dtype DT ) const DT *           ?=?( const           DT *          &, const             DT * );
     385forall( dtype DT ) const DT *           ?=?( const           DT * volatile &, const             DT * );
     386forall( dtype DT ) volatile DT *        ?=?(       volatile  DT *          &,                   DT * );
     387forall( dtype DT ) volatile DT *        ?=?(       volatile  DT * volatile &,                   DT * );
     388forall( dtype DT ) volatile DT *        ?=?(       volatile  DT *          &,       volatile    DT * );
     389forall( dtype DT ) volatile DT *        ?=?(       volatile  DT * volatile &,       volatile    DT * );
     390
     391forall( dtype DT ) const volatile DT *  ?=?( const volatile  DT *          &,                   DT * );
     392forall( dtype DT ) const volatile DT *  ?=?( const volatile  DT * volatile &,                   DT * );
     393forall( dtype DT ) const volatile DT *  ?=?( const volatile  DT *          &, const             DT * );
     394forall( dtype DT ) const volatile DT *  ?=?( const volatile  DT * volatile &, const             DT * );
     395forall( dtype DT ) const volatile DT *  ?=?( const volatile  DT *          &,       volatile    DT * );
     396forall( dtype DT ) const volatile DT *  ?=?( const volatile  DT * volatile &,       volatile    DT * );
     397forall( dtype DT ) const volatile DT *  ?=?( const volatile  DT *          &, const volatile    DT * );
     398forall( dtype DT ) const volatile DT *  ?=?( const volatile  DT * volatile &, const volatile    DT * );
     399
     400forall( dtype DT ) void *                ?=?(                void *          &,                 DT * );
     401forall( dtype DT ) void *                ?=?(                void * volatile &,                 DT * );
     402forall( dtype DT ) const void *          ?=?( const          void *          &,                 DT * );
     403forall( dtype DT ) const void *          ?=?( const          void * volatile &,                 DT * );
     404forall( dtype DT ) const void *          ?=?( const          void *          &, const           DT * );
     405forall( dtype DT ) const void *          ?=?( const          void * volatile &, const           DT * );
     406forall( dtype DT ) volatile void *       ?=?(       volatile void *          &,                 DT * );
     407forall( dtype DT ) volatile void *       ?=?(       volatile void * volatile &,                 DT * );
     408forall( dtype DT ) volatile void *       ?=?(       volatile void *          &,       volatile  DT * );
     409forall( dtype DT ) volatile void *       ?=?(       volatile void * volatile &,       volatile  DT * );
     410forall( dtype DT ) const volatile void * ?=?( const volatile void *          &,                 DT * );
     411forall( dtype DT ) const volatile void * ?=?( const volatile void * volatile &,                 DT * );
     412forall( dtype DT ) const volatile void * ?=?( const volatile void *          &, const           DT * );
     413forall( dtype DT ) const volatile void * ?=?( const volatile void * volatile &, const           DT * );
     414forall( dtype DT ) const volatile void * ?=?( const volatile void *          &,       volatile  DT * );
     415forall( dtype DT ) const volatile void * ?=?( const volatile void * volatile &,       volatile  DT * );
     416forall( dtype DT ) const volatile void * ?=?( const volatile void *          &, const volatile  DT * );
     417forall( dtype DT ) const volatile void * ?=?( const volatile void * volatile &, const volatile  DT * );
    418418
    419419//forall( dtype DT ) DT *                       ?=?(                DT *          &, zero_t );
    420420//forall( dtype DT ) DT *                       ?=?(                DT * volatile &, zero_t );
    421 forall( DT & ) const DT *               ?=?( const          DT *          &, zero_t );
    422 forall( DT & ) const DT *               ?=?( const          DT * volatile &, zero_t );
     421forall( dtype DT ) const DT *           ?=?( const          DT *          &, zero_t );
     422forall( dtype DT ) const DT *           ?=?( const          DT * volatile &, zero_t );
    423423//forall( dtype DT ) volatile DT *      ?=?( volatile       DT *          &, zero_t );
    424424//forall( dtype DT ) volatile DT *      ?=?( volatile       DT * volatile &, zero_t );
    425 forall( DT & ) const volatile DT *      ?=?( const volatile DT *          &, zero_t );
    426 forall( DT & ) const volatile DT *      ?=?( const volatile DT * volatile &, zero_t );
     425forall( dtype DT ) const volatile DT *  ?=?( const volatile DT *          &, zero_t );
     426forall( dtype DT ) const volatile DT *  ?=?( const volatile DT * volatile &, zero_t );
    427427
    428428forall( ftype FT ) FT *                 ?=?( FT *          &, zero_t );
    429429forall( ftype FT ) FT *                 ?=?( FT * volatile &, zero_t );
    430430
    431 forall( T & | sized(T) ) T *            ?+=?(                T *          &, ptrdiff_t );
    432 forall( T & | sized(T) ) T *            ?+=?(                T * volatile &, ptrdiff_t );
    433 forall( T & | sized(T) ) const T *              ?+=?( const          T *          &, ptrdiff_t );
    434 forall( T & | sized(T) ) const T *              ?+=?( const          T * volatile &, ptrdiff_t );
    435 forall( T & | sized(T) ) volatile T *   ?+=?(       volatile T *          &, ptrdiff_t );
    436 forall( T & | sized(T) ) volatile T *   ?+=?(       volatile T * volatile &, ptrdiff_t );
    437 forall( T & | sized(T) ) const volatile T *     ?+=?( const volatile T *          &, ptrdiff_t );
    438 forall( T & | sized(T) ) const volatile T *     ?+=?( const volatile T * volatile &, ptrdiff_t );
    439 forall( T & | sized(T) ) T *            ?-=?(                T *          &, ptrdiff_t );
    440 forall( T & | sized(T) ) T *            ?-=?(                T * volatile &, ptrdiff_t );
    441 forall( T & | sized(T) ) const T *              ?-=?( const          T *          &, ptrdiff_t );
    442 forall( T & | sized(T) ) const T *              ?-=?( const          T * volatile &, ptrdiff_t );
    443 forall( T & | sized(T) ) volatile T *   ?-=?(       volatile T *          &, ptrdiff_t );
    444 forall( T & | sized(T) ) volatile T *   ?-=?(       volatile T * volatile &, ptrdiff_t );
    445 forall( T & | sized(T) ) const volatile T *     ?-=?( const volatile T *          &, ptrdiff_t );
    446 forall( T & | sized(T) ) const volatile T *     ?-=?( const volatile T * volatile &, ptrdiff_t );
     431forall( dtype T | sized(T) ) T *                ?+=?(                T *          &, ptrdiff_t );
     432forall( dtype T | sized(T) ) T *                ?+=?(                T * volatile &, ptrdiff_t );
     433forall( dtype T | sized(T) ) const T *          ?+=?( const          T *          &, ptrdiff_t );
     434forall( dtype T | sized(T) ) const T *          ?+=?( const          T * volatile &, ptrdiff_t );
     435forall( dtype T | sized(T) ) volatile T *       ?+=?(       volatile T *          &, ptrdiff_t );
     436forall( dtype T | sized(T) ) volatile T *       ?+=?(       volatile T * volatile &, ptrdiff_t );
     437forall( dtype T | sized(T) ) const volatile T * ?+=?( const volatile T *          &, ptrdiff_t );
     438forall( dtype T | sized(T) ) const volatile T * ?+=?( const volatile T * volatile &, ptrdiff_t );
     439forall( dtype T | sized(T) ) T *                ?-=?(                T *          &, ptrdiff_t );
     440forall( dtype T | sized(T) ) T *                ?-=?(                T * volatile &, ptrdiff_t );
     441forall( dtype T | sized(T) ) const T *          ?-=?( const          T *          &, ptrdiff_t );
     442forall( dtype T | sized(T) ) const T *          ?-=?( const          T * volatile &, ptrdiff_t );
     443forall( dtype T | sized(T) ) volatile T *       ?-=?(       volatile T *          &, ptrdiff_t );
     444forall( dtype T | sized(T) ) volatile T *       ?-=?(       volatile T * volatile &, ptrdiff_t );
     445forall( dtype T | sized(T) ) const volatile T * ?-=?( const volatile T *          &, ptrdiff_t );
     446forall( dtype T | sized(T) ) const volatile T * ?-=?( const volatile T * volatile &, ptrdiff_t );
    447447
    448448_Bool                   ?=?( _Bool &, _Bool ),                                  ?=?( volatile _Bool &, _Bool );
     
    723723forall( ftype FT ) void ?{}( FT * volatile &, FT * );
    724724
    725 forall( DT & ) void ?{}(                     DT *          &,                   DT * );
    726 forall( DT & ) void ?{}( const       DT *          &,                   DT * );
    727 forall( DT & ) void ?{}( const       DT *          &, const             DT * );
    728 forall( DT & ) void ?{}(           volatile  DT *          &,                   DT * );
    729 forall( DT & ) void ?{}(           volatile  DT *          &,       volatile    DT * );
    730 forall( DT & ) void ?{}( const volatile  DT *      &,                   DT * );
    731 forall( DT & ) void ?{}( const volatile  DT *      &, const             DT * );
    732 forall( DT & ) void ?{}( const volatile  DT *      &,       volatile    DT * );
    733 forall( DT & ) void ?{}( const volatile  DT *      &, const volatile    DT * );
    734 
    735 forall( DT & ) void ?{}(                     void *          &,                 DT * );
    736 forall( DT & ) void ?{}( const       void *          &,                 DT * );
    737 forall( DT & ) void ?{}( const       void *          &, const           DT * );
    738 forall( DT & ) void ?{}(            volatile void *          &,                 DT * );
    739 forall( DT & ) void ?{}(            volatile void *          &,       volatile  DT * );
    740 forall( DT & ) void ?{}( const volatile void *       &,                 DT * );
    741 forall( DT & ) void ?{}( const volatile void *       &, const           DT * );
    742 forall( DT & ) void ?{}( const volatile void *       &,       volatile  DT * );
    743 forall( DT & ) void ?{}( const volatile void *       &, const volatile  DT * );
     725forall( dtype DT ) void ?{}(                 DT *          &,                   DT * );
     726forall( dtype DT ) void ?{}( const           DT *          &,                   DT * );
     727forall( dtype DT ) void ?{}( const           DT *          &, const             DT * );
     728forall( dtype DT ) void ?{}(       volatile  DT *          &,                   DT * );
     729forall( dtype DT ) void ?{}(       volatile  DT *          &,       volatile    DT * );
     730forall( dtype DT ) void ?{}( const volatile  DT *          &,                   DT * );
     731forall( dtype DT ) void ?{}( const volatile  DT *          &, const             DT * );
     732forall( dtype DT ) void ?{}( const volatile  DT *          &,       volatile    DT * );
     733forall( dtype DT ) void ?{}( const volatile  DT *          &, const volatile    DT * );
     734
     735forall( dtype DT ) void ?{}(                 void *          &,                 DT * );
     736forall( dtype DT ) void ?{}( const           void *          &,                 DT * );
     737forall( dtype DT ) void ?{}( const           void *          &, const           DT * );
     738forall( dtype DT ) void ?{}(        volatile void *          &,                 DT * );
     739forall( dtype DT ) void ?{}(        volatile void *          &,       volatile  DT * );
     740forall( dtype DT ) void ?{}( const volatile void *           &,                 DT * );
     741forall( dtype DT ) void ?{}( const volatile void *           &, const           DT * );
     742forall( dtype DT ) void ?{}( const volatile void *           &,       volatile  DT * );
     743forall( dtype DT ) void ?{}( const volatile void *           &, const volatile  DT * );
    744744
    745745//forall( dtype DT ) void ?{}(              DT *          &, zero_t );
    746746//forall( dtype DT ) void ?{}(              DT * volatile &, zero_t );
    747 forall( DT & ) void ?{}( const      DT *          &, zero_t );
     747forall( dtype DT ) void ?{}( const          DT *          &, zero_t );
    748748//forall( dtype DT ) void ?{}( volatile     DT *          &, zero_t );
    749749//forall( dtype DT ) void ?{}( volatile     DT * volatile &, zero_t );
    750 forall( DT & ) void ?{}( const volatile DT *      &, zero_t );
     750forall( dtype DT ) void ?{}( const volatile DT *          &, zero_t );
    751751
    752752forall( ftype FT ) void ?{}( FT *          &, zero_t );
     
    755755forall( ftype FT ) void ?{}( FT *          & );
    756756
    757 forall( DT & ) void     ?{}(                 DT *          &);
    758 forall( DT & ) void     ?{}( const           DT *          &);
    759 forall( DT & ) void     ?{}(       volatile  DT *          &);
    760 forall( DT & ) void ?{}( const volatile  DT *      &);
     757forall( dtype DT ) void ?{}(                 DT *          &);
     758forall( dtype DT ) void ?{}( const           DT *          &);
     759forall( dtype DT ) void ?{}(       volatile  DT *          &);
     760forall( dtype DT ) void ?{}( const volatile  DT *          &);
    761761
    762762void    ?{}(                void *          &);
     
    768768forall( ftype FT ) void ^?{}( FT *         & );
    769769
    770 forall( DT & ) void     ^?{}(                DT *          &);
    771 forall( DT & ) void     ^?{}( const          DT *          &);
    772 forall( DT & ) void     ^?{}(      volatile  DT *          &);
    773 forall( DT & ) void ^?{}( const volatile  DT *     &);
     770forall( dtype DT ) void ^?{}(                DT *          &);
     771forall( dtype DT ) void ^?{}( const          DT *          &);
     772forall( dtype DT ) void ^?{}(      volatile  DT *          &);
     773forall( dtype DT ) void ^?{}( const volatile  DT *         &);
    774774
    775775void ^?{}(                  void *          &);
  • libcfa/prelude/sync-builtins.cf

    rc08c3cf r467c8b7  
    206206_Bool __sync_bool_compare_and_swap(volatile unsigned __int128 *, unsigned __int128, unsigned __int128,...);
    207207#endif
    208 forall(T &) _Bool __sync_bool_compare_and_swap(T * volatile *, T *, T*, ...);
     208forall(dtype T) _Bool __sync_bool_compare_and_swap(T * volatile *, T *, T*, ...);
    209209
    210210char __sync_val_compare_and_swap(volatile char *, char, char,...);
     
    223223unsigned __int128 __sync_val_compare_and_swap(volatile unsigned __int128 *, unsigned __int128, unsigned __int128,...);
    224224#endif
    225 forall(T &) T * __sync_val_compare_and_swap(T * volatile *, T *, T*,...);
     225forall(dtype T) T * __sync_val_compare_and_swap(T * volatile *, T *, T*,...);
    226226
    227227char __sync_lock_test_and_set(volatile char *, char,...);
     
    326326void __atomic_exchange(volatile unsigned __int128 *, volatile unsigned __int128 *, volatile unsigned __int128 *, int);
    327327#endif
    328 forall(T &) T * __atomic_exchange_n(T * volatile *, T *, int);
    329 forall(T &) void __atomic_exchange(T * volatile *, T * volatile *, T * volatile *, int);
     328forall(dtype T) T * __atomic_exchange_n(T * volatile *, T *, int);
     329forall(dtype T) void __atomic_exchange(T * volatile *, T * volatile *, T * volatile *, int);
    330330
    331331_Bool __atomic_load_n(const volatile _Bool *, int);
     
    359359void __atomic_load(const volatile unsigned __int128 *, volatile unsigned __int128 *, int);
    360360#endif
    361 forall(T &) T * __atomic_load_n(T * const volatile *, int);
    362 forall(T &) void __atomic_load(T * const volatile *, T **, int);
     361forall(dtype T) T * __atomic_load_n(T * const volatile *, int);
     362forall(dtype T) void __atomic_load(T * const volatile *, T **, int);
    363363
    364364_Bool __atomic_compare_exchange_n(volatile char *, char *, char, _Bool, int, int);
     
    390390_Bool __atomic_compare_exchange   (volatile unsigned __int128 *, unsigned __int128 *, unsigned __int128 *, _Bool, int, int);
    391391#endif
    392 forall(T &) _Bool __atomic_compare_exchange_n (T * volatile *, T **, T*, _Bool, int, int);
    393 forall(T &) _Bool __atomic_compare_exchange   (T * volatile *, T **, T**, _Bool, int, int);
     392forall(dtype T) _Bool __atomic_compare_exchange_n (T * volatile *, T **, T*, _Bool, int, int);
     393forall(dtype T) _Bool __atomic_compare_exchange   (T * volatile *, T **, T**, _Bool, int, int);
    394394
    395395void __atomic_store_n(volatile _Bool *, _Bool, int);
     
    423423void __atomic_store(volatile unsigned __int128 *, unsigned __int128 *, int);
    424424#endif
    425 forall(T &) void __atomic_store_n(T * volatile *, T *, int);
    426 forall(T &) void __atomic_store(T * volatile *, T **, int);
     425forall(dtype T) void __atomic_store_n(T * volatile *, T *, int);
     426forall(dtype T) void __atomic_store(T * volatile *, T **, int);
    427427
    428428char __atomic_add_fetch  (volatile char *, char, int);
  • libcfa/src/bitmanip.hfa

    rc08c3cf r467c8b7  
    100100        unsigned long long int floor2( unsigned long long int n, unsigned long long int align ) { verify( is_pow2( align ) ); return n & -align; }
    101101
    102         // forall( T | { T ?&?( T, T ); T -?( T ); } )
     102        // forall( otype T | { T ?&?( T, T ); T -?( T ); } )
    103103        // T floor2( T n, T align ) { verify( is_pow2( align ) ); return n & -align; }
    104104
     
    115115        unsigned long long int ceiling2( unsigned long long int n, unsigned long long int align ) { verify( is_pow2( align ) ); return -floor2( -n, align ); }
    116116
    117         // forall( T | { T floor2( T, T ); T -?( T ); } )
     117        // forall( otype T | { T floor2( T, T ); T -?( T ); } )
    118118        // T ceiling2( T n, T align ) { verify( is_pow2( align ) ); return -floor2( -n, align ); }
    119119} // distribution
  • libcfa/src/bits/algorithm.hfa

    rc08c3cf r467c8b7  
    1717
    1818#ifdef SAFE_SORT
    19 forall( T | {  int ?<?( T, T ); int ?>?( T, T ); } ) static inline void __libcfa_small_sort2( T * arr );
    20 forall( T | {  int ?<?( T, T ); int ?>?( T, T ); } ) static inline void __libcfa_small_sort3( T * arr );
    21 forall( T | {  int ?<?( T, T ); int ?>?( T, T ); } ) static inline void __libcfa_small_sort4( T * arr );
    22 forall( T | {  int ?<?( T, T ); int ?>?( T, T ); } ) static inline void __libcfa_small_sort5( T * arr );
    23 forall( T | {  int ?<?( T, T ); int ?>?( T, T ); } ) static inline void __libcfa_small_sort6( T * arr );
    24 forall( T | {  int ?<?( T, T ); int ?>?( T, T ); } ) static inline void __libcfa_small_sortN( T * arr, size_t dim );
     19forall( otype T | {  int ?<?( T, T ); int ?>?( T, T ); } ) static inline void __libcfa_small_sort2( T * arr );
     20forall( otype T | {  int ?<?( T, T ); int ?>?( T, T ); } ) static inline void __libcfa_small_sort3( T * arr );
     21forall( otype T | {  int ?<?( T, T ); int ?>?( T, T ); } ) static inline void __libcfa_small_sort4( T * arr );
     22forall( otype T | {  int ?<?( T, T ); int ?>?( T, T ); } ) static inline void __libcfa_small_sort5( T * arr );
     23forall( otype T | {  int ?<?( T, T ); int ?>?( T, T ); } ) static inline void __libcfa_small_sort6( T * arr );
     24forall( otype T | {  int ?<?( T, T ); int ?>?( T, T ); } ) static inline void __libcfa_small_sortN( T * arr, size_t dim );
    2525
    26 forall( T | {  int ?<?( T, T ); int ?>?( T, T ); } )
     26forall( otype T | {  int ?<?( T, T ); int ?>?( T, T ); } )
    2727static inline void __libcfa_small_sort( T * arr, size_t dim ) {
    2828        switch( dim ) {
     
    4141#define SWAP(x,y) { T a = min(arr[x], arr[y]); T b = max(arr[x], arr[y]); arr[x] = a; arr[y] = b;}
    4242
    43 forall( T | {  int ?<?( T, T ); int ?>?( T, T ); } )
     43forall( otype T | {  int ?<?( T, T ); int ?>?( T, T ); } )
    4444static inline void __libcfa_small_sort2( T * arr ) {
    4545        SWAP(0, 1);
    4646}
    4747
    48 forall( T | {  int ?<?( T, T ); int ?>?( T, T ); } )
     48forall( otype T | {  int ?<?( T, T ); int ?>?( T, T ); } )
    4949static inline void __libcfa_small_sort3( T * arr ) {
    5050        SWAP(1, 2);
     
    5353}
    5454
    55 forall( T | {  int ?<?( T, T ); int ?>?( T, T ); } )
     55forall( otype T | {  int ?<?( T, T ); int ?>?( T, T ); } )
    5656static inline void __libcfa_small_sort4( T * arr ) {
    5757        SWAP(0, 1);
     
    6262}
    6363
    64 forall( T | {  int ?<?( T, T ); int ?>?( T, T ); } )
     64forall( otype T | {  int ?<?( T, T ); int ?>?( T, T ); } )
    6565static inline void __libcfa_small_sort5( T * arr ) {
    6666        SWAP(0, 1);
     
    7575}
    7676
    77 forall( T | {  int ?<?( T, T ); int ?>?( T, T ); } )
     77forall( otype T | {  int ?<?( T, T ); int ?>?( T, T ); } )
    7878static inline void __libcfa_small_sort6( T * arr ) {
    7979        SWAP(1, 2);
     
    9191}
    9292
    93 forall( T | {  int ?<?( T, T ); int ?>?( T, T ); } )
     93forall( otype T | {  int ?<?( T, T ); int ?>?( T, T ); } )
    9494static inline void __libcfa_small_sortN( T * arr, size_t dim ) {
    9595        int i, j;
     
    112112static inline void __libcfa_small_sortN( void* * arr, size_t dim );
    113113
    114 forall( T & )
     114forall( dtype T )
    115115static inline void __libcfa_small_sort( T* * arr, size_t dim ) {
    116116        switch( dim ) {
  • libcfa/src/bits/collection.hfa

    rc08c3cf r467c8b7  
    3131
    3232        // // wrappers to make Collection have T
    33         // forall( T & ) {
     33        // forall( dtype T ) {
    3434        //      T *& Next( T * n ) {
    3535        //              return (T *)Next( (Colable *)n );
     
    7676        } // post: elts = null
    7777
    78         forall( T & ) {
     78        forall( dtype T ) {
    7979                T * Curr( ColIter & ci ) with( ci ) {
    8080                        return (T *)curr;
  • libcfa/src/bits/containers.hfa

    rc08c3cf r467c8b7  
    2323
    2424#ifdef __cforall
    25         forall(T &)
     25        forall(dtype T)
    2626#else
    2727        #define T void
     
    4040
    4141#ifdef __cforall
    42         // forall(T | sized(T))
     42        // forall(otype T | sized(T))
    4343        // static inline void ?{}(__small_array(T) & this) {}
    4444
    45         forall(T & | sized(T))
     45        forall(dtype T | sized(T))
    4646        static inline T & ?[?]( __small_array(T) & this, __lock_size_t idx ) {
    4747                return ((typeof(this.data))this.data)[idx];
    4848        }
    4949
    50         forall(T & | sized(T))
     50        forall(dtype T | sized(T))
    5151        static inline T & ?[?]( const __small_array(T) & this, __lock_size_t idx ) {
    5252                return ((typeof(this.data))this.data)[idx];
    5353        }
    5454
    55         forall(T &)
     55        forall(dtype T)
    5656        static inline T * begin( const __small_array(T) & this ) {
    5757                return ((typeof(this.data))this.data);
    5858        }
    5959
    60         forall(T & | sized(T))
     60        forall(dtype T | sized(T))
    6161        static inline T * end( const __small_array(T) & this ) {
    6262                return ((typeof(this.data))this.data) + this.size;
     
    6969
    7070#ifdef __cforall
    71         trait is_node(T &) {
     71        trait is_node(dtype T) {
    7272                T *& get_next( T & );
    7373        };
     
    7878//-----------------------------------------------------------------------------
    7979#ifdef __cforall
    80         forall(TYPE &)
     80        forall(dtype TYPE)
    8181        #define T TYPE
    8282#else
     
    9595
    9696#ifdef __cforall
    97         forall(T &)
     97        forall(dtype T)
    9898        static inline void ?{}( __stack(T) & this ) {
    9999                (this.top){ 0p };
    100100        }
    101101
    102         static inline forall( T & | is_node(T) ) {
     102        static inline forall( dtype T | is_node(T) ) {
    103103                void push( __stack(T) & this, T * val ) {
    104104                        verify( !get_next( *val ) );
     
    126126//-----------------------------------------------------------------------------
    127127#ifdef __cforall
    128         forall(TYPE &)
     128        forall(dtype TYPE)
    129129        #define T TYPE
    130130#else
     
    144144
    145145#ifdef __cforall
    146         static inline forall( T & | is_node(T) ) {
     146        static inline forall( dtype T | is_node(T) ) {
    147147                void ?{}( __queue(T) & this ) with( this ) {
    148148                        (this.head){ 1p };
     
    215215//-----------------------------------------------------------------------------
    216216#ifdef __cforall
    217         forall(TYPE &)
     217        forall(dtype TYPE)
    218218        #define T TYPE
    219219        #define __getter_t * [T * & next, T * & prev] ( T & )
     
    237237
    238238#ifdef __cforall
    239         forall(T & )
     239        forall(dtype T )
    240240        static inline [void] ?{}( __dllist(T) & this, * [T * & next, T * & prev] ( T & ) __get ) {
    241241                (this.head){ 0p };
     
    245245        #define next 0
    246246        #define prev 1
    247         static inline forall(T &) {
     247        static inline forall(dtype T) {
    248248                void push_front( __dllist(T) & this, T & node ) with( this ) {
    249249                        verify(__get);
  • libcfa/src/bits/defs.hfa

    rc08c3cf r467c8b7  
    55// file "LICENCE" distributed with Cforall.
    66//
    7 // defs.hfa -- Commen macros, functions and typedefs
    8 // Most files depend on them and they are always useful to have.
    9 //
    10 //  *** Must not contain code specific to libcfathread ***
     7// defs.hfa --
    118//
    129// Author           : Thierry Delisle
     
    6562        #endif
    6663}
    67 
    68 // pause to prevent excess processor bus usage
    69 #if defined( __i386 ) || defined( __x86_64 )
    70         #define Pause() __asm__ __volatile__ ( "pause" : : : )
    71 #elif defined( __ARM_ARCH )
    72         #define Pause() __asm__ __volatile__ ( "YIELD" : : : )
    73 #else
    74         #error unsupported architecture
    75 #endif
  • libcfa/src/bits/locks.hfa

    rc08c3cf r467c8b7  
    55// file "LICENCE" distributed with Cforall.
    66//
    7 // bits/locks.hfa -- Basic spinlocks that are reused in the system.
    8 // Used for locks that aren't specific to cforall threads and can be used anywhere
    9 //
    10 //  *** Must not contain code specific to libcfathread ***
     7// bits/locks.hfa -- Fast internal locks.
    118//
    129// Author           : Thierry Delisle
     
    2219#include "bits/defs.hfa"
    2320#include <assert.h>
     21
     22#ifdef __cforall
     23        extern "C" {
     24                #include <pthread.h>
     25        }
     26#endif
     27
     28// pause to prevent excess processor bus usage
     29#if defined( __i386 ) || defined( __x86_64 )
     30        #define Pause() __asm__ __volatile__ ( "pause" : : : )
     31#elif defined( __ARM_ARCH )
     32        #define Pause() __asm__ __volatile__ ( "YIELD" : : : )
     33#else
     34        #error unsupported architecture
     35#endif
    2436
    2537struct __spinlock_t {
     
    92104                enable_interrupts_noPoll();
    93105        }
     106
     107
     108        #ifdef __CFA_WITH_VERIFY__
     109                extern bool __cfaabi_dbg_in_kernel();
     110        #endif
     111
     112        extern "C" {
     113                char * strerror(int);
     114        }
     115        #define CHECKED(x) { int err = x; if( err != 0 ) abort("KERNEL ERROR: Operation \"" #x "\" return error %d - %s\n", err, strerror(err)); }
     116
     117        struct __bin_sem_t {
     118                pthread_mutex_t         lock;
     119                pthread_cond_t          cond;
     120                int                     val;
     121        };
     122
     123        static inline void ?{}(__bin_sem_t & this) with( this ) {
     124                // Create the mutex with error checking
     125                pthread_mutexattr_t mattr;
     126                pthread_mutexattr_init( &mattr );
     127                pthread_mutexattr_settype( &mattr, PTHREAD_MUTEX_ERRORCHECK_NP);
     128                pthread_mutex_init(&lock, &mattr);
     129
     130                pthread_cond_init (&cond, (const pthread_condattr_t *)0p);  // workaround trac#208: cast should not be required
     131                val = 0;
     132        }
     133
     134        static inline void ^?{}(__bin_sem_t & this) with( this ) {
     135                CHECKED( pthread_mutex_destroy(&lock) );
     136                CHECKED( pthread_cond_destroy (&cond) );
     137        }
     138
     139        static inline void wait(__bin_sem_t & this) with( this ) {
     140                verify(__cfaabi_dbg_in_kernel());
     141                CHECKED( pthread_mutex_lock(&lock) );
     142                        while(val < 1) {
     143                                pthread_cond_wait(&cond, &lock);
     144                        }
     145                        val -= 1;
     146                CHECKED( pthread_mutex_unlock(&lock) );
     147        }
     148
     149        static inline bool post(__bin_sem_t & this) with( this ) {
     150                bool needs_signal = false;
     151
     152                CHECKED( pthread_mutex_lock(&lock) );
     153                        if(val < 1) {
     154                                val += 1;
     155                                pthread_cond_signal(&cond);
     156                                needs_signal = true;
     157                        }
     158                CHECKED( pthread_mutex_unlock(&lock) );
     159
     160                return needs_signal;
     161        }
     162
     163        #undef CHECKED
     164
     165        struct $thread;
     166        extern void park( void );
     167        extern void unpark( struct $thread * this );
     168        static inline struct $thread * active_thread ();
     169
     170        // Semaphore which only supports a single thread
     171        struct single_sem {
     172                struct $thread * volatile ptr;
     173        };
     174
     175        static inline {
     176                void  ?{}(single_sem & this) {
     177                        this.ptr = 0p;
     178                }
     179
     180                void ^?{}(single_sem &) {}
     181
     182                bool wait(single_sem & this) {
     183                        for() {
     184                                struct $thread * expected = this.ptr;
     185                                if(expected == 1p) {
     186                                        if(__atomic_compare_exchange_n(&this.ptr, &expected, 0p, false, __ATOMIC_SEQ_CST, __ATOMIC_SEQ_CST)) {
     187                                                return false;
     188                                        }
     189                                }
     190                                else {
     191                                        /* paranoid */ verify( expected == 0p );
     192                                        if(__atomic_compare_exchange_n(&this.ptr, &expected, active_thread(), false, __ATOMIC_SEQ_CST, __ATOMIC_SEQ_CST)) {
     193                                                park();
     194                                                return true;
     195                                        }
     196                                }
     197
     198                        }
     199                }
     200
     201                bool post(single_sem & this) {
     202                        for() {
     203                                struct $thread * expected = this.ptr;
     204                                if(expected == 1p) return false;
     205                                if(expected == 0p) {
     206                                        if(__atomic_compare_exchange_n(&this.ptr, &expected, 1p, false, __ATOMIC_SEQ_CST, __ATOMIC_SEQ_CST)) {
     207                                                return false;
     208                                        }
     209                                }
     210                                else {
     211                                        if(__atomic_compare_exchange_n(&this.ptr, &expected, 0p, false, __ATOMIC_SEQ_CST, __ATOMIC_SEQ_CST)) {
     212                                                unpark( expected );
     213                                                return true;
     214                                        }
     215                                }
     216                        }
     217                }
     218        }
     219
     220        // Synchronozation primitive which only supports a single thread and one post
     221        // Similar to a binary semaphore with a 'one shot' semantic
     222        // is expected to be discarded after each party call their side
     223        struct oneshot {
     224                // Internal state :
     225                //     0p     : is initial state (wait will block)
     226                //     1p     : fulfilled (wait won't block)
     227                // any thread : a thread is currently waiting
     228                struct $thread * volatile ptr;
     229        };
     230
     231        static inline {
     232                void  ?{}(oneshot & this) {
     233                        this.ptr = 0p;
     234                }
     235
     236                void ^?{}(oneshot &) {}
     237
     238                // Wait for the post, return immidiately if it already happened.
     239                // return true if the thread was parked
     240                bool wait(oneshot & this) {
     241                        for() {
     242                                struct $thread * expected = this.ptr;
     243                                if(expected == 1p) return false;
     244                                /* paranoid */ verify( expected == 0p );
     245                                if(__atomic_compare_exchange_n(&this.ptr, &expected, active_thread(), false, __ATOMIC_SEQ_CST, __ATOMIC_SEQ_CST)) {
     246                                        park();
     247                                        /* paranoid */ verify( this.ptr == 1p );
     248                                        return true;
     249                                }
     250                        }
     251                }
     252
     253                // Mark as fulfilled, wake thread if needed
     254                // return true if a thread was unparked
     255                bool post(oneshot & this) {
     256                        struct $thread * got = __atomic_exchange_n( &this.ptr, 1p, __ATOMIC_SEQ_CST);
     257                        if( got == 0p ) return false;
     258                        unpark( got );
     259                        return true;
     260                }
     261        }
     262
     263        // base types for future to build upon
     264        // It is based on the 'oneshot' type to allow multiple futures
     265        // to block on the same instance, permitting users to block a single
     266        // thread on "any of" [a given set of] futures.
     267        // does not support multiple threads waiting on the same future
     268        struct future_t {
     269                // Internal state :
     270                //     0p      : is initial state (wait will block)
     271                //     1p      : fulfilled (wait won't block)
     272                //     2p      : in progress ()
     273                //     3p      : abandoned, server should delete
     274                // any oneshot : a context has been setup to wait, a thread could wait on it
     275                struct oneshot * volatile ptr;
     276        };
     277
     278        static inline {
     279                void  ?{}(future_t & this) {
     280                        this.ptr = 0p;
     281                }
     282
     283                void ^?{}(future_t &) {}
     284
     285                void reset(future_t & this) {
     286                        // needs to be in 0p or 1p
     287                        __atomic_exchange_n( &this.ptr, 0p, __ATOMIC_SEQ_CST);
     288                }
     289
     290                // check if the future is available
     291                bool available( future_t & this ) {
     292                        return this.ptr == 1p;
     293                }
     294
     295                // Prepare the future to be waited on
     296                // intented to be use by wait, wait_any, waitfor, etc. rather than used directly
     297                bool setup( future_t & this, oneshot & wait_ctx ) {
     298                        /* paranoid */ verify( wait_ctx.ptr == 0p );
     299                        // The future needs to set the wait context
     300                        for() {
     301                                struct oneshot * expected = this.ptr;
     302                                // Is the future already fulfilled?
     303                                if(expected == 1p) return false; // Yes, just return false (didn't block)
     304
     305                                // The future is not fulfilled, try to setup the wait context
     306                                /* paranoid */ verify( expected == 0p );
     307                                if(__atomic_compare_exchange_n(&this.ptr, &expected, &wait_ctx, false, __ATOMIC_SEQ_CST, __ATOMIC_SEQ_CST)) {
     308                                        return true;
     309                                }
     310                        }
     311                }
     312
     313                // Stop waiting on a future
     314                // When multiple futures are waited for together in "any of" pattern
     315                // futures that weren't fulfilled before the thread woke up
     316                // should retract the wait ctx
     317                // intented to be use by wait, wait_any, waitfor, etc. rather than used directly
     318                void retract( future_t & this, oneshot & wait_ctx ) {
     319                        // Remove the wait context
     320                        struct oneshot * got = __atomic_exchange_n( &this.ptr, 0p, __ATOMIC_SEQ_CST);
     321
     322                        // got == 0p: future was never actually setup, just return
     323                        if( got == 0p ) return;
     324
     325                        // got == wait_ctx: since fulfil does an atomic_swap,
     326                        // if we got back the original then no one else saw context
     327                        // It is safe to delete (which could happen after the return)
     328                        if( got == &wait_ctx ) return;
     329
     330                        // got == 1p: the future is ready and the context was fully consumed
     331                        // the server won't use the pointer again
     332                        // It is safe to delete (which could happen after the return)
     333                        if( got == 1p ) return;
     334
     335                        // got == 2p: the future is ready but the context hasn't fully been consumed
     336                        // spin until it is safe to move on
     337                        if( got == 2p ) {
     338                                while( this.ptr != 1p ) Pause();
     339                                return;
     340                        }
     341
     342                        // got == any thing else, something wen't wrong here, abort
     343                        abort("Future in unexpected state");
     344                }
     345
     346                // Mark the future as abandoned, meaning it will be deleted by the server
     347                bool abandon( future_t & this ) {
     348                        /* paranoid */ verify( this.ptr != 3p );
     349
     350                        // Mark the future as abandonned
     351                        struct oneshot * got = __atomic_exchange_n( &this.ptr, 3p, __ATOMIC_SEQ_CST);
     352
     353                        // If the future isn't already fulfilled, let the server delete it
     354                        if( got == 0p ) return false;
     355
     356                        // got == 2p: the future is ready but the context hasn't fully been consumed
     357                        // spin until it is safe to move on
     358                        if( got == 2p ) {
     359                                while( this.ptr != 1p ) Pause();
     360                                got = 1p;
     361                        }
     362
     363                        // The future is completed delete it now
     364                        /* paranoid */ verify( this.ptr != 1p );
     365                        free( &this );
     366                        return true;
     367                }
     368
     369                // from the server side, mark the future as fulfilled
     370                // delete it if needed
     371                bool fulfil( future_t & this ) {
     372                        for() {
     373                                struct oneshot * expected = this.ptr;
     374                                // was this abandoned?
     375                                #if defined(__GNUC__) && __GNUC__ >= 7
     376                                        #pragma GCC diagnostic push
     377                                        #pragma GCC diagnostic ignored "-Wfree-nonheap-object"
     378                                #endif
     379                                        if( expected == 3p ) { free( &this ); return false; }
     380                                #if defined(__GNUC__) && __GNUC__ >= 7
     381                                        #pragma GCC diagnostic pop
     382                                #endif
     383
     384                                /* paranoid */ verify( expected != 1p ); // Future is already fulfilled, should not happen
     385                                /* paranoid */ verify( expected != 2p ); // Future is bein fulfilled by someone else, this is even less supported then the previous case.
     386
     387                                // If there is a wait context, we need to consume it and mark it as consumed after
     388                                // If there is no context then we can skip the in progress phase
     389                                struct oneshot * want = expected == 0p ? 1p : 2p;
     390                                if(__atomic_compare_exchange_n(&this.ptr, &expected, want, false, __ATOMIC_SEQ_CST, __ATOMIC_SEQ_CST)) {
     391                                        if( expected == 0p ) { /* paranoid */ verify( this.ptr == 1p); return false; }
     392                                        bool ret = post( *expected );
     393                                        __atomic_store_n( &this.ptr, 1p, __ATOMIC_SEQ_CST);
     394                                        return ret;
     395                                }
     396                        }
     397
     398                }
     399
     400                // Wait for the future to be fulfilled
     401                bool wait( future_t & this ) {
     402                        oneshot temp;
     403                        if( !setup(this, temp) ) return false;
     404
     405                        // Wait context is setup, just wait on it
     406                        bool ret = wait( temp );
     407
     408                        // Wait for the future to tru
     409                        while( this.ptr == 2p ) Pause();
     410                        // Make sure the state makes sense
     411                        // Should be fulfilled, could be in progress but it's out of date if so
     412                        // since if that is the case, the oneshot was fulfilled (unparking this thread)
     413                        // and the oneshot should not be needed any more
     414                        __attribute__((unused)) struct oneshot * was = this.ptr;
     415                        /* paranoid */ verifyf( was == 1p, "Expected this.ptr to be 1p, was %p\n", was );
     416
     417                        // Mark the future as fulfilled, to be consistent
     418                        // with potential calls to avail
     419                        // this.ptr = 1p;
     420                        return ret;
     421                }
     422        }
    94423#endif
  • libcfa/src/bits/queue.hfa

    rc08c3cf r467c8b7  
    99// instead of being null.
    1010
    11 forall( T & | { T *& Next ( T * ); } ) {
     11forall( dtype T | { T *& Next ( T * ); } ) {
    1212        struct Queue {
    1313                inline Collection;                                                              // Plan 9 inheritance
     
    151151} // distribution
    152152
    153 forall( T & | { T *& Next ( T * ); } ) {
     153forall( dtype T | { T *& Next ( T * ); } ) {
    154154        struct QueueIter {
    155155                inline ColIter;                                                                 // Plan 9 inheritance
  • libcfa/src/bits/sequence.hfa

    rc08c3cf r467c8b7  
    2929
    3030        // // wrappers to make Collection have T
    31         // forall( T & ) {
     31        // forall( dtype T ) {
    3232        //      T *& Back( T * n ) {
    3333        //              return (T *)Back( (Seqable *)n );
     
    4343// and the back field of the last node points at the first node (circular).
    4444
    45 forall( T & | { T *& Back ( T * ); T *& Next ( T * ); } ) {
     45forall( dtype T | { T *& Back ( T * ); T *& Next ( T * ); } ) {
    4646        struct Sequence {
    4747                inline Collection;                                                              // Plan 9 inheritance
     
    231231} // distribution
    232232
    233 forall( T & | { T *& Back ( T * ); T *& Next ( T * ); } ) {
     233forall( dtype T | { T *& Back ( T * ); T *& Next ( T * ); } ) {
    234234        // SeqIter(T) is used to iterate over a Sequence(T) in head-to-tail order.
    235235        struct SeqIter {
  • libcfa/src/bits/stack.hfa

    rc08c3cf r467c8b7  
    99// instead of being null.
    1010
    11 forall( T & | { T *& Next ( T * ); } ) {
     11forall( dtype T | { T *& Next ( T * ); } ) {
    1212        struct Stack {
    1313                inline Collection;                                                              // Plan 9 inheritance
     
    6767// order returned by drop().
    6868
    69 forall( T & | { T *& Next ( T * ); } ) {
     69forall( dtype T | { T *& Next ( T * ); } ) {
    7070        struct StackIter {
    7171                inline ColIter;                                                                 // Plan 9 inheritance
  • libcfa/src/common.cfa

    rc08c3cf r467c8b7  
    2323[ long int, long int ] div( long int num, long int denom ) { ldiv_t qr = ldiv( num, denom ); return [ qr.quot, qr.rem ]; }
    2424[ long long int, long long int ] div( long long int num, long long int denom ) { lldiv_t qr = lldiv( num, denom ); return [ qr.quot, qr.rem ]; }
    25 forall( T | { T ?/?( T, T ); T ?%?( T, T ); } )
     25forall( otype T | { T ?/?( T, T ); T ?%?( T, T ); } )
    2626[ T, T ] div( T num, T denom ) { return [ num / denom, num % denom ]; }
    2727
  • libcfa/src/common.hfa

    rc08c3cf r467c8b7  
    2121[ long int, long int ] div( long int num, long int denom );
    2222[ long long int, long long int ] div( long long int num, long long int denom );
    23 forall( T | { T ?/?( T, T ); T ?%?( T, T ); } )
     23forall( otype T | { T ?/?( T, T ); T ?%?( T, T ); } )
    2424[ T, T ] div( T num, T demon );
    2525
     
    6161} // distribution
    6262
    63 forall( T | { void ?{}( T &, zero_t ); int ?<?( T, T ); T -?( T ); } )
     63forall( otype T | { void ?{}( T &, zero_t ); int ?<?( T, T ); T -?( T ); } )
    6464T abs( T );
    6565
     
    7070        intptr_t min( intptr_t t1, intptr_t t2 ) { return t1 < t2 ? t1 : t2; } // optimization
    7171        uintptr_t min( uintptr_t t1, uintptr_t t2 ) { return t1 < t2 ? t1 : t2; } // optimization
    72         forall( T | { int ?<?( T, T ); } )
     72        forall( otype T | { int ?<?( T, T ); } )
    7373        T min( T t1, T t2 ) { return t1 < t2 ? t1 : t2; }
    7474
     
    7676        intptr_t max( intptr_t t1, intptr_t t2 ) { return t1 > t2 ? t1 : t2; } // optimization
    7777        uintptr_t max( uintptr_t t1, uintptr_t t2 ) { return t1 > t2 ? t1 : t2; } // optimization
    78         forall( T | { int ?>?( T, T ); } )
     78        forall( otype T | { int ?>?( T, T ); } )
    7979        T max( T t1, T t2 ) { return t1 > t2 ? t1 : t2; }
    8080
    81         forall( T | { T min( T, T ); T max( T, T ); } )
     81        forall( otype T | { T min( T, T ); T max( T, T ); } )
    8282        T clamp( T value, T min_val, T max_val ) { return max( min_val, min( value, max_val ) ); }
    8383
    84         forall( T )
     84        forall( otype T )
    8585        void swap( T & v1, T & v2 ) { T temp = v1; v1 = v2; v2 = temp; }
    8686} // distribution
  • libcfa/src/concurrency/coroutine.cfa

    rc08c3cf r467c8b7  
    4646
    4747//-----------------------------------------------------------------------------
    48 FORALL_DATA_INSTANCE(CoroutineCancelled, (coroutine_t &), (coroutine_t))
    49 
    50 forall(T &)
     48FORALL_DATA_INSTANCE(CoroutineCancelled, (dtype coroutine_t), (coroutine_t))
     49
     50forall(dtype T)
    5151void mark_exception(CoroutineCancelled(T) *) {}
    5252
    53 forall(T &)
     53forall(dtype T)
    5454void copy(CoroutineCancelled(T) * dst, CoroutineCancelled(T) * src) {
    5555        dst->virtual_table = src->virtual_table;
     
    5858}
    5959
    60 forall(T &)
     60forall(dtype T)
    6161const char * msg(CoroutineCancelled(T) *) {
    6262        return "CoroutineCancelled(...)";
     
    6464
    6565// This code should not be inlined. It is the error path on resume.
    66 forall(T & | is_coroutine(T))
     66forall(dtype T | is_coroutine(T))
    6767void __cfaehm_cancelled_coroutine( T & cor, $coroutine * desc ) {
    6868        verify( desc->cancellation );
     
    148148// Part of the Public API
    149149// Not inline since only ever called once per coroutine
    150 forall(T & | is_coroutine(T))
     150forall(dtype T | is_coroutine(T))
    151151void prime(T& cor) {
    152152        $coroutine* this = get_coroutine(cor);
  • libcfa/src/concurrency/coroutine.hfa

    rc08c3cf r467c8b7  
    2222//-----------------------------------------------------------------------------
    2323// Exception thrown from resume when a coroutine stack is cancelled.
    24 FORALL_DATA_EXCEPTION(CoroutineCancelled, (coroutine_t &), (coroutine_t)) (
     24FORALL_DATA_EXCEPTION(CoroutineCancelled, (dtype coroutine_t), (coroutine_t)) (
    2525        coroutine_t * the_coroutine;
    2626        exception_t * the_exception;
    2727);
    2828
    29 forall(T &)
     29forall(dtype T)
    3030void copy(CoroutineCancelled(T) * dst, CoroutineCancelled(T) * src);
    3131
    32 forall(T &)
     32forall(dtype T)
    3333const char * msg(CoroutineCancelled(T) *);
    3434
     
    3737// Anything that implements this trait can be resumed.
    3838// Anything that is resumed is a coroutine.
    39 trait is_coroutine(T & | IS_RESUMPTION_EXCEPTION(CoroutineCancelled, (T))) {
     39trait is_coroutine(dtype T | IS_RESUMPTION_EXCEPTION(CoroutineCancelled, (T))) {
    4040        void main(T & this);
    4141        $coroutine * get_coroutine(T & this);
     
    6060//-----------------------------------------------------------------------------
    6161// Public coroutine API
    62 forall(T & | is_coroutine(T))
     62forall(dtype T | is_coroutine(T))
    6363void prime(T & cor);
    6464
     
    7272        void __cfactx_invoke_coroutine(void (*main)(void *), void * this);
    7373
    74         forall(T &)
     74        forall(dtype T)
    7575        void __cfactx_start(void (*main)(T &), struct $coroutine * cor, T & this, void (*invoke)(void (*main)(void *), void *));
    7676
     
    129129}
    130130
    131 forall(T & | is_coroutine(T))
     131forall(dtype T | is_coroutine(T))
    132132void __cfaehm_cancelled_coroutine( T & cor, $coroutine * desc );
    133133
    134134// Resume implementation inlined for performance
    135 forall(T & | is_coroutine(T))
     135forall(dtype T | is_coroutine(T))
    136136static inline T & resume(T & cor) {
    137137        // optimization : read TLS once and reuse it
  • libcfa/src/concurrency/future.hfa

    rc08c3cf r467c8b7  
    1919#include "monitor.hfa"
    2020
    21 forall( T ) {
     21forall( otype T ) {
    2222        struct future {
    2323                inline future_t;
     
    5858}
    5959
    60 forall( T ) {
     60forall( otype T ) {
    6161        monitor multi_future {
    6262                inline future_t;
  • libcfa/src/concurrency/io/types.hfa

    rc08c3cf r467c8b7  
    55// file "LICENCE" distributed with Cforall.
    66//
    7 // io/types.hfa -- PRIVATE
    8 // Types used by the I/O subsystem
     7// io/types.hfa --
    98//
    109// Author           : Thierry Delisle
     
    2221
    2322#include "bits/locks.hfa"
    24 #include "kernel/fwd.hfa"
    2523
    2624#if defined(CFA_HAVE_LINUX_IO_URING_H)
  • libcfa/src/concurrency/kernel.cfa

    rc08c3cf r467c8b7  
    224224        }
    225225
    226         post( this->terminated );
     226        V( this->terminated );
    227227
    228228        if(this == mainProcessor) {
     
    624624// Unexpected Terminating logic
    625625//=============================================================================================
    626 void __kernel_abort_msg( char * abort_text, int abort_text_size ) {
    627         $thread * thrd = __cfaabi_tls.this_thread;
     626
     627extern "C" {
     628        extern void __cfaabi_real_abort(void);
     629}
     630static volatile bool kernel_abort_called = false;
     631
     632void * kernel_abort(void) __attribute__ ((__nothrow__)) {
     633        // abort cannot be recursively entered by the same or different processors because all signal handlers return when
     634        // the globalAbort flag is true.
     635        bool first = !__atomic_test_and_set( &kernel_abort_called, __ATOMIC_SEQ_CST);
     636
     637        // first task to abort ?
     638        if ( !first ) {
     639                // We aren't the first to abort.
     640                // I give up, just let C handle it
     641                __cfaabi_real_abort();
     642        }
     643
     644        // disable interrupts, it no longer makes sense to try to interrupt this processor
     645        disable_interrupts();
     646
     647        return __cfaabi_tls.this_thread;
     648}
     649
     650void kernel_abort_msg( void * kernel_data, char * abort_text, int abort_text_size ) {
     651        $thread * thrd = ( $thread * ) kernel_data;
    628652
    629653        if(thrd) {
     
    645669}
    646670
    647 int __kernel_abort_lastframe( void ) __attribute__ ((__nothrow__)) {
    648         return get_coroutine(__cfaabi_tls.this_thread) == get_coroutine(mainThread) ? 4 : 2;
     671int kernel_abort_lastframe( void ) __attribute__ ((__nothrow__)) {
     672        return get_coroutine(kernelTLS().this_thread) == get_coroutine(mainThread) ? 4 : 2;
    649673}
    650674
     
    664688// Kernel Utilities
    665689//=============================================================================================
     690//-----------------------------------------------------------------------------
     691// Locks
     692void  ?{}( semaphore & this, int count = 1 ) {
     693        (this.lock){};
     694        this.count = count;
     695        (this.waiting){};
     696}
     697void ^?{}(semaphore & this) {}
     698
     699bool P(semaphore & this) with( this ){
     700        lock( lock __cfaabi_dbg_ctx2 );
     701        count -= 1;
     702        if ( count < 0 ) {
     703                // queue current task
     704                append( waiting, active_thread() );
     705
     706                // atomically release spin lock and block
     707                unlock( lock );
     708                park();
     709                return true;
     710        }
     711        else {
     712            unlock( lock );
     713            return false;
     714        }
     715}
     716
     717bool V(semaphore & this) with( this ) {
     718        $thread * thrd = 0p;
     719        lock( lock __cfaabi_dbg_ctx2 );
     720        count += 1;
     721        if ( count <= 0 ) {
     722                // remove task at head of waiting list
     723                thrd = pop_head( waiting );
     724        }
     725
     726        unlock( lock );
     727
     728        // make new owner
     729        unpark( thrd );
     730
     731        return thrd != 0p;
     732}
     733
     734bool V(semaphore & this, unsigned diff) with( this ) {
     735        $thread * thrd = 0p;
     736        lock( lock __cfaabi_dbg_ctx2 );
     737        int release = max(-count, (int)diff);
     738        count += diff;
     739        for(release) {
     740                unpark( pop_head( waiting ) );
     741        }
     742
     743        unlock( lock );
     744
     745        return thrd != 0p;
     746}
     747
    666748//-----------------------------------------------------------------------------
    667749// Debug
  • libcfa/src/concurrency/kernel.hfa

    rc08c3cf r467c8b7  
    55// file "LICENCE" distributed with Cforall.
    66//
    7 // kernel -- Header containing the core of the kernel API
     7// kernel --
    88//
    99// Author           : Thierry Delisle
     
    2424extern "C" {
    2525        #include <bits/pthreadtypes.h>
    26         #include <pthread.h>
    2726        #include <linux/types.h>
    2827}
    2928
    3029//-----------------------------------------------------------------------------
    31 // Underlying Locks
    32 #ifdef __CFA_WITH_VERIFY__
    33         extern bool __cfaabi_dbg_in_kernel();
    34 #endif
    35 
    36 extern "C" {
    37         char * strerror(int);
    38 }
    39 #define CHECKED(x) { int err = x; if( err != 0 ) abort("KERNEL ERROR: Operation \"" #x "\" return error %d - %s\n", err, strerror(err)); }
    40 
    41 struct __bin_sem_t {
    42         pthread_mutex_t         lock;
    43         pthread_cond_t          cond;
    44         int                     val;
    45 };
    46 
    47 static inline void ?{}(__bin_sem_t & this) with( this ) {
    48         // Create the mutex with error checking
    49         pthread_mutexattr_t mattr;
    50         pthread_mutexattr_init( &mattr );
    51         pthread_mutexattr_settype( &mattr, PTHREAD_MUTEX_ERRORCHECK_NP);
    52         pthread_mutex_init(&lock, &mattr);
    53 
    54         pthread_cond_init (&cond, (const pthread_condattr_t *)0p);  // workaround trac#208: cast should not be required
    55         val = 0;
    56 }
    57 
    58 static inline void ^?{}(__bin_sem_t & this) with( this ) {
    59         CHECKED( pthread_mutex_destroy(&lock) );
    60         CHECKED( pthread_cond_destroy (&cond) );
    61 }
    62 
    63 static inline void wait(__bin_sem_t & this) with( this ) {
    64         verify(__cfaabi_dbg_in_kernel());
    65         CHECKED( pthread_mutex_lock(&lock) );
    66                 while(val < 1) {
    67                         pthread_cond_wait(&cond, &lock);
    68                 }
    69                 val -= 1;
    70         CHECKED( pthread_mutex_unlock(&lock) );
    71 }
    72 
    73 static inline bool post(__bin_sem_t & this) with( this ) {
    74         bool needs_signal = false;
    75 
    76         CHECKED( pthread_mutex_lock(&lock) );
    77                 if(val < 1) {
    78                         val += 1;
    79                         pthread_cond_signal(&cond);
    80                         needs_signal = true;
    81                 }
    82         CHECKED( pthread_mutex_unlock(&lock) );
    83 
    84         return needs_signal;
    85 }
    86 
    87 #undef CHECKED
     30// Locks
     31struct semaphore {
     32        __spinlock_t lock;
     33        int count;
     34        __queue_t($thread) waiting;
     35};
     36
     37void  ?{}(semaphore & this, int count = 1);
     38void ^?{}(semaphore & this);
     39bool   P (semaphore & this);
     40bool   V (semaphore & this);
     41bool   V (semaphore & this, unsigned count);
    8842
    8943
     
    13791
    13892        // Termination synchronisation (user semaphore)
    139         oneshot terminated;
     93        semaphore terminated;
    14094
    14195        // pthread Stack
  • libcfa/src/concurrency/kernel/fwd.hfa

    rc08c3cf r467c8b7  
    55// file "LICENCE" distributed with Cforall.
    66//
    7 // kernel/fwd.hfa -- PUBLIC
    8 // Fundamental code needed to implement threading M.E.S. algorithms.
     7// kernel/fwd.hfa --
    98//
    109// Author           : Thierry Delisle
     
    135134                extern uint64_t thread_rand();
    136135
    137                 // Semaphore which only supports a single thread
    138                 struct single_sem {
    139                         struct $thread * volatile ptr;
    140                 };
    141 
    142                 static inline {
    143                         void  ?{}(single_sem & this) {
    144                                 this.ptr = 0p;
    145                         }
    146 
    147                         void ^?{}(single_sem &) {}
    148 
    149                         bool wait(single_sem & this) {
    150                                 for() {
    151                                         struct $thread * expected = this.ptr;
    152                                         if(expected == 1p) {
    153                                                 if(__atomic_compare_exchange_n(&this.ptr, &expected, 0p, false, __ATOMIC_SEQ_CST, __ATOMIC_SEQ_CST)) {
    154                                                         return false;
    155                                                 }
    156                                         }
    157                                         else {
    158                                                 /* paranoid */ verify( expected == 0p );
    159                                                 if(__atomic_compare_exchange_n(&this.ptr, &expected, active_thread(), false, __ATOMIC_SEQ_CST, __ATOMIC_SEQ_CST)) {
    160                                                         park();
    161                                                         return true;
    162                                                 }
    163                                         }
    164 
    165                                 }
    166                         }
    167 
    168                         bool post(single_sem & this) {
    169                                 for() {
    170                                         struct $thread * expected = this.ptr;
    171                                         if(expected == 1p) return false;
    172                                         if(expected == 0p) {
    173                                                 if(__atomic_compare_exchange_n(&this.ptr, &expected, 1p, false, __ATOMIC_SEQ_CST, __ATOMIC_SEQ_CST)) {
    174                                                         return false;
    175                                                 }
    176                                         }
    177                                         else {
    178                                                 if(__atomic_compare_exchange_n(&this.ptr, &expected, 0p, false, __ATOMIC_SEQ_CST, __ATOMIC_SEQ_CST)) {
    179                                                         unpark( expected );
    180                                                         return true;
    181                                                 }
    182                                         }
    183                                 }
    184                         }
    185                 }
    186 
    187                 // Synchronozation primitive which only supports a single thread and one post
    188                 // Similar to a binary semaphore with a 'one shot' semantic
    189                 // is expected to be discarded after each party call their side
    190                 struct oneshot {
    191                         // Internal state :
    192                         //     0p     : is initial state (wait will block)
    193                         //     1p     : fulfilled (wait won't block)
    194                         // any thread : a thread is currently waiting
    195                         struct $thread * volatile ptr;
    196                 };
    197 
    198                 static inline {
    199                         void  ?{}(oneshot & this) {
    200                                 this.ptr = 0p;
    201                         }
    202 
    203                         void ^?{}(oneshot &) {}
    204 
    205                         // Wait for the post, return immidiately if it already happened.
    206                         // return true if the thread was parked
    207                         bool wait(oneshot & this) {
    208                                 for() {
    209                                         struct $thread * expected = this.ptr;
    210                                         if(expected == 1p) return false;
    211                                         /* paranoid */ verify( expected == 0p );
    212                                         if(__atomic_compare_exchange_n(&this.ptr, &expected, active_thread(), false, __ATOMIC_SEQ_CST, __ATOMIC_SEQ_CST)) {
    213                                                 park();
    214                                                 /* paranoid */ verify( this.ptr == 1p );
    215                                                 return true;
    216                                         }
    217                                 }
    218                         }
    219 
    220                         // Mark as fulfilled, wake thread if needed
    221                         // return true if a thread was unparked
    222                         bool post(oneshot & this) {
    223                                 struct $thread * got = __atomic_exchange_n( &this.ptr, 1p, __ATOMIC_SEQ_CST);
    224                                 if( got == 0p ) return false;
    225                                 unpark( got );
    226                                 return true;
    227                         }
    228                 }
    229 
    230                 // base types for future to build upon
    231                 // It is based on the 'oneshot' type to allow multiple futures
    232                 // to block on the same instance, permitting users to block a single
    233                 // thread on "any of" [a given set of] futures.
    234                 // does not support multiple threads waiting on the same future
    235                 struct future_t {
    236                         // Internal state :
    237                         //     0p      : is initial state (wait will block)
    238                         //     1p      : fulfilled (wait won't block)
    239                         //     2p      : in progress ()
    240                         //     3p      : abandoned, server should delete
    241                         // any oneshot : a context has been setup to wait, a thread could wait on it
    242                         struct oneshot * volatile ptr;
    243                 };
    244 
    245                 static inline {
    246                         void  ?{}(future_t & this) {
    247                                 this.ptr = 0p;
    248                         }
    249 
    250                         void ^?{}(future_t &) {}
    251 
    252                         void reset(future_t & this) {
    253                                 // needs to be in 0p or 1p
    254                                 __atomic_exchange_n( &this.ptr, 0p, __ATOMIC_SEQ_CST);
    255                         }
    256 
    257                         // check if the future is available
    258                         bool available( future_t & this ) {
    259                                 return this.ptr == 1p;
    260                         }
    261 
    262                         // Prepare the future to be waited on
    263                         // intented to be use by wait, wait_any, waitfor, etc. rather than used directly
    264                         bool setup( future_t & this, oneshot & wait_ctx ) {
    265                                 /* paranoid */ verify( wait_ctx.ptr == 0p );
    266                                 // The future needs to set the wait context
    267                                 for() {
    268                                         struct oneshot * expected = this.ptr;
    269                                         // Is the future already fulfilled?
    270                                         if(expected == 1p) return false; // Yes, just return false (didn't block)
    271 
    272                                         // The future is not fulfilled, try to setup the wait context
    273                                         /* paranoid */ verify( expected == 0p );
    274                                         if(__atomic_compare_exchange_n(&this.ptr, &expected, &wait_ctx, false, __ATOMIC_SEQ_CST, __ATOMIC_SEQ_CST)) {
    275                                                 return true;
    276                                         }
    277                                 }
    278                         }
    279 
    280                         // Stop waiting on a future
    281                         // When multiple futures are waited for together in "any of" pattern
    282                         // futures that weren't fulfilled before the thread woke up
    283                         // should retract the wait ctx
    284                         // intented to be use by wait, wait_any, waitfor, etc. rather than used directly
    285                         void retract( future_t & this, oneshot & wait_ctx ) {
    286                                 // Remove the wait context
    287                                 struct oneshot * got = __atomic_exchange_n( &this.ptr, 0p, __ATOMIC_SEQ_CST);
    288 
    289                                 // got == 0p: future was never actually setup, just return
    290                                 if( got == 0p ) return;
    291 
    292                                 // got == wait_ctx: since fulfil does an atomic_swap,
    293                                 // if we got back the original then no one else saw context
    294                                 // It is safe to delete (which could happen after the return)
    295                                 if( got == &wait_ctx ) return;
    296 
    297                                 // got == 1p: the future is ready and the context was fully consumed
    298                                 // the server won't use the pointer again
    299                                 // It is safe to delete (which could happen after the return)
    300                                 if( got == 1p ) return;
    301 
    302                                 // got == 2p: the future is ready but the context hasn't fully been consumed
    303                                 // spin until it is safe to move on
    304                                 if( got == 2p ) {
    305                                         while( this.ptr != 1p ) Pause();
    306                                         return;
    307                                 }
    308 
    309                                 // got == any thing else, something wen't wrong here, abort
    310                                 abort("Future in unexpected state");
    311                         }
    312 
    313                         // Mark the future as abandoned, meaning it will be deleted by the server
    314                         bool abandon( future_t & this ) {
    315                                 /* paranoid */ verify( this.ptr != 3p );
    316 
    317                                 // Mark the future as abandonned
    318                                 struct oneshot * got = __atomic_exchange_n( &this.ptr, 3p, __ATOMIC_SEQ_CST);
    319 
    320                                 // If the future isn't already fulfilled, let the server delete it
    321                                 if( got == 0p ) return false;
    322 
    323                                 // got == 2p: the future is ready but the context hasn't fully been consumed
    324                                 // spin until it is safe to move on
    325                                 if( got == 2p ) {
    326                                         while( this.ptr != 1p ) Pause();
    327                                         got = 1p;
    328                                 }
    329 
    330                                 // The future is completed delete it now
    331                                 /* paranoid */ verify( this.ptr != 1p );
    332                                 free( &this );
    333                                 return true;
    334                         }
    335 
    336                         // from the server side, mark the future as fulfilled
    337                         // delete it if needed
    338                         bool fulfil( future_t & this ) {
    339                                 for() {
    340                                         struct oneshot * expected = this.ptr;
    341                                         // was this abandoned?
    342                                         #if defined(__GNUC__) && __GNUC__ >= 7
    343                                                 #pragma GCC diagnostic push
    344                                                 #pragma GCC diagnostic ignored "-Wfree-nonheap-object"
    345                                         #endif
    346                                                 if( expected == 3p ) { free( &this ); return false; }
    347                                         #if defined(__GNUC__) && __GNUC__ >= 7
    348                                                 #pragma GCC diagnostic pop
    349                                         #endif
    350 
    351                                         /* paranoid */ verify( expected != 1p ); // Future is already fulfilled, should not happen
    352                                         /* paranoid */ verify( expected != 2p ); // Future is bein fulfilled by someone else, this is even less supported then the previous case.
    353 
    354                                         // If there is a wait context, we need to consume it and mark it as consumed after
    355                                         // If there is no context then we can skip the in progress phase
    356                                         struct oneshot * want = expected == 0p ? 1p : 2p;
    357                                         if(__atomic_compare_exchange_n(&this.ptr, &expected, want, false, __ATOMIC_SEQ_CST, __ATOMIC_SEQ_CST)) {
    358                                                 if( expected == 0p ) { /* paranoid */ verify( this.ptr == 1p); return false; }
    359                                                 bool ret = post( *expected );
    360                                                 __atomic_store_n( &this.ptr, 1p, __ATOMIC_SEQ_CST);
    361                                                 return ret;
    362                                         }
    363                                 }
    364 
    365                         }
    366 
    367                         // Wait for the future to be fulfilled
    368                         bool wait( future_t & this ) {
    369                                 oneshot temp;
    370                                 if( !setup(this, temp) ) return false;
    371 
    372                                 // Wait context is setup, just wait on it
    373                                 bool ret = wait( temp );
    374 
    375                                 // Wait for the future to tru
    376                                 while( this.ptr == 2p ) Pause();
    377                                 // Make sure the state makes sense
    378                                 // Should be fulfilled, could be in progress but it's out of date if so
    379                                 // since if that is the case, the oneshot was fulfilled (unparking this thread)
    380                                 // and the oneshot should not be needed any more
    381                                 __attribute__((unused)) struct oneshot * was = this.ptr;
    382                                 /* paranoid */ verifyf( was == 1p, "Expected this.ptr to be 1p, was %p\n", was );
    383 
    384                                 // Mark the future as fulfilled, to be consistent
    385                                 // with potential calls to avail
    386                                 // this.ptr = 1p;
    387                                 return ret;
    388                         }
    389                 }
    390 
    391136                //-----------------------------------------------------------------------
    392137                // Statics call at the end of each thread to register statistics
  • libcfa/src/concurrency/kernel/startup.cfa

    rc08c3cf r467c8b7  
    199199        void ?{}(processor & this) with( this ) {
    200200                ( this.idle ){};
    201                 ( this.terminated ){};
     201                ( this.terminated ){ 0 };
    202202                ( this.runner ){};
    203203                init( this, "Main Processor", *mainCluster );
     
    528528void ?{}(processor & this, const char name[], cluster & _cltr) {
    529529        ( this.idle ){};
    530         ( this.terminated ){};
     530        ( this.terminated ){ 0 };
    531531        ( this.runner ){};
    532532
     
    549549                __wake_proc( &this );
    550550
    551                 wait( terminated );
     551                P( terminated );
    552552                /* paranoid */ verify( active_processor() != &this);
    553553        }
  • libcfa/src/concurrency/locks.cfa

    rc08c3cf r467c8b7  
    77//-----------------------------------------------------------------------------
    88// info_thread
    9 forall(L & | is_blocking_lock(L)) {
     9forall(dtype L | is_blocking_lock(L)) {
    1010        struct info_thread {
    1111                // used to put info_thread on a dl queue (aka sequence)
     
    195195//-----------------------------------------------------------------------------
    196196// alarm node wrapper
    197 forall(L & | is_blocking_lock(L)) {
     197forall(dtype L | is_blocking_lock(L)) {
    198198        struct alarm_node_wrap {
    199199                alarm_node_t alarm_node;
     
    239239//-----------------------------------------------------------------------------
    240240// condition variable
    241 forall(L & | is_blocking_lock(L)) {
     241forall(dtype L | is_blocking_lock(L)) {
    242242
    243243        void ?{}( condition_variable(L) & this ){
     
    356356        bool wait( condition_variable(L) & this, L & l, uintptr_t info, Time time         ) with(this) { WAIT_TIME( info, &l , time ) }
    357357}
    358 
    359 //-----------------------------------------------------------------------------
    360 // Semaphore
    361 void  ?{}( semaphore & this, int count = 1 ) {
    362         (this.lock){};
    363         this.count = count;
    364         (this.waiting){};
    365 }
    366 void ^?{}(semaphore & this) {}
    367 
    368 bool P(semaphore & this) with( this ){
    369         lock( lock __cfaabi_dbg_ctx2 );
    370         count -= 1;
    371         if ( count < 0 ) {
    372                 // queue current task
    373                 append( waiting, active_thread() );
    374 
    375                 // atomically release spin lock and block
    376                 unlock( lock );
    377                 park();
    378                 return true;
    379         }
    380         else {
    381             unlock( lock );
    382             return false;
    383         }
    384 }
    385 
    386 bool V(semaphore & this) with( this ) {
    387         $thread * thrd = 0p;
    388         lock( lock __cfaabi_dbg_ctx2 );
    389         count += 1;
    390         if ( count <= 0 ) {
    391                 // remove task at head of waiting list
    392                 thrd = pop_head( waiting );
    393         }
    394 
    395         unlock( lock );
    396 
    397         // make new owner
    398         unpark( thrd );
    399 
    400         return thrd != 0p;
    401 }
    402 
    403 bool V(semaphore & this, unsigned diff) with( this ) {
    404         $thread * thrd = 0p;
    405         lock( lock __cfaabi_dbg_ctx2 );
    406         int release = max(-count, (int)diff);
    407         count += diff;
    408         for(release) {
    409                 unpark( pop_head( waiting ) );
    410         }
    411 
    412         unlock( lock );
    413 
    414         return thrd != 0p;
    415 }
  • libcfa/src/concurrency/locks.hfa

    rc08c3cf r467c8b7  
    1313//-----------------------------------------------------------------------------
    1414// is_blocking_lock
    15 trait is_blocking_lock(L & | sized(L)) {
     15trait is_blocking_lock(dtype L | sized(L)) {
    1616        // For synchronization locks to use when acquiring
    1717        void on_notify( L &, struct $thread * );
     
    3131// the info thread is a wrapper around a thread used
    3232// to store extra data for use in the condition variable
    33 forall(L & | is_blocking_lock(L)) {
     33forall(dtype L | is_blocking_lock(L)) {
    3434        struct info_thread;
    3535
     
    120120//-----------------------------------------------------------------------------
    121121// Synchronization Locks
    122 forall(L & | is_blocking_lock(L)) {
     122forall(dtype L | is_blocking_lock(L)) {
    123123        struct condition_variable {
    124124                // Spin lock used for mutual exclusion
     
    157157        bool wait( condition_variable(L) & this, L & l, uintptr_t info, Time time );
    158158}
    159 
    160 //-----------------------------------------------------------------------------
    161 // Semaphore
    162 struct semaphore {
    163         __spinlock_t lock;
    164         int count;
    165         __queue_t($thread) waiting;
    166 };
    167 
    168 void  ?{}(semaphore & this, int count = 1);
    169 void ^?{}(semaphore & this);
    170 bool   P (semaphore & this);
    171 bool   V (semaphore & this);
    172 bool   V (semaphore & this, unsigned count);
  • libcfa/src/concurrency/monitor.cfa

    rc08c3cf r467c8b7  
    5050static inline [$thread *, int] search_entry_queue( const __waitfor_mask_t &, $monitor * monitors [], __lock_size_t count );
    5151
    52 forall(T & | sized( T ))
     52forall(dtype T | sized( T ))
    5353static inline __lock_size_t insert_unique( T * array [], __lock_size_t & size, T * val );
    5454static inline __lock_size_t count_max    ( const __waitfor_mask_t & mask );
     
    949949}
    950950
    951 forall(T & | sized( T ))
     951forall(dtype T | sized( T ))
    952952static inline __lock_size_t insert_unique( T * array [], __lock_size_t & size, T * val ) {
    953953        if( !val ) return size;
  • libcfa/src/concurrency/monitor.hfa

    rc08c3cf r467c8b7  
    2222#include "stdlib.hfa"
    2323
    24 trait is_monitor(T &) {
     24trait is_monitor(dtype T) {
    2525        $monitor * get_monitor( T & );
    2626        void ^?{}( T & mutex );
     
    5959void ^?{}( monitor_dtor_guard_t & this );
    6060
    61 static inline forall( T & | sized(T) | { void ^?{}( T & mutex ); } )
     61static inline forall( dtype T | sized(T) | { void ^?{}( T & mutex ); } )
    6262void delete( T * th ) {
    6363        ^(*th){};
  • libcfa/src/concurrency/mutex.cfa

    rc08c3cf r467c8b7  
    164164}
    165165
    166 forall(L & | is_lock(L))
     166forall(dtype L | is_lock(L))
    167167void wait(condition_variable & this, L & l) {
    168168        lock( this.lock __cfaabi_dbg_ctx2 );
     
    176176//-----------------------------------------------------------------------------
    177177// Scopes
    178 forall(L & | is_lock(L))
     178forall(dtype L | is_lock(L))
    179179void lock_all  ( L * locks[], size_t count) {
    180180        // Sort locks based on addresses
     
    188188}
    189189
    190 forall(L & | is_lock(L))
     190forall(dtype L | is_lock(L))
    191191void unlock_all( L * locks[], size_t count) {
    192192        // Lock all
  • libcfa/src/concurrency/mutex.hfa

    rc08c3cf r467c8b7  
    7070void unlock(recursive_mutex_lock & this) __attribute__((deprecated("use concurrency/locks.hfa instead")));
    7171
    72 trait is_lock(L & | sized(L)) {
     72trait is_lock(dtype L | sized(L)) {
    7373        void lock  (L &);
    7474        void unlock(L &);
     
    9494void wait(condition_variable & this) __attribute__((deprecated("use concurrency/locks.hfa instead")));
    9595
    96 forall(L & | is_lock(L))
     96forall(dtype L | is_lock(L))
    9797void wait(condition_variable & this, L & l) __attribute__((deprecated("use concurrency/locks.hfa instead")));
    9898
    9999//-----------------------------------------------------------------------------
    100100// Scopes
    101 forall(L & | is_lock(L)) {
     101forall(dtype L | is_lock(L)) {
    102102        #if !defined( __TUPLE_ARRAYS_EXIST__ )
    103103        void lock  ( L * locks [], size_t count);
  • libcfa/src/concurrency/preemption.cfa

    rc08c3cf r467c8b7  
    616616}
    617617
    618 // Prevent preemption since we are about to start terminating things
    619 void __kernel_abort_lock(void) {
    620         signal_block( SIGUSR1 );
    621 }
    622 
    623618// Raii ctor/dtor for the preemption_scope
    624619// Used by thread to control when they want to receive preemption signals
  • libcfa/src/concurrency/thread.cfa

    rc08c3cf r467c8b7  
    6262}
    6363
    64 FORALL_DATA_INSTANCE(ThreadCancelled, (thread_t &), (thread_t))
     64FORALL_DATA_INSTANCE(ThreadCancelled, (dtype thread_t), (thread_t))
    6565
    66 forall(T &)
     66forall(dtype T)
    6767void copy(ThreadCancelled(T) * dst, ThreadCancelled(T) * src) {
    6868        dst->virtual_table = src->virtual_table;
     
    7171}
    7272
    73 forall(T &)
     73forall(dtype T)
    7474const char * msg(ThreadCancelled(T) *) {
    7575        return "ThreadCancelled";
    7676}
    7777
    78 forall(T &)
     78forall(dtype T)
    7979static void default_thread_cancel_handler(ThreadCancelled(T) & ) {
    8080        abort( "Unhandled thread cancellation.\n" );
    8181}
    8282
    83 forall(T & | is_thread(T) | IS_EXCEPTION(ThreadCancelled, (T)))
     83forall(dtype T | is_thread(T) | IS_EXCEPTION(ThreadCancelled, (T)))
    8484void ?{}( thread_dtor_guard_t & this,
    8585                T & thrd, void(*cancelHandler)(ThreadCancelled(T) &)) {
     
    124124//-----------------------------------------------------------------------------
    125125// Starting and stopping threads
    126 forall( T & | is_thread(T) )
     126forall( dtype T | is_thread(T) )
    127127void __thrd_start( T & this, void (*main_p)(T &) ) {
    128128        $thread * this_thrd = get_thread(this);
     
    140140//-----------------------------------------------------------------------------
    141141// Support for threads that don't ues the thread keyword
    142 forall( T & | sized(T) | is_thread(T) | { void ?{}(T&); } )
     142forall( dtype T | sized(T) | is_thread(T) | { void ?{}(T&); } )
    143143void ?{}( scoped(T)& this ) with( this ) {
    144144        handle{};
     
    146146}
    147147
    148 forall( T &, P... | sized(T) | is_thread(T) | { void ?{}(T&, P); } )
     148forall( dtype T, ttype P | sized(T) | is_thread(T) | { void ?{}(T&, P); } )
    149149void ?{}( scoped(T)& this, P params ) with( this ) {
    150150        handle{ params };
     
    152152}
    153153
    154 forall( T & | sized(T) | is_thread(T) )
     154forall( dtype T | sized(T) | is_thread(T) )
    155155void ^?{}( scoped(T)& this ) with( this ) {
    156156        ^handle{};
     
    158158
    159159//-----------------------------------------------------------------------------
    160 forall(T & | is_thread(T) | IS_RESUMPTION_EXCEPTION(ThreadCancelled, (T)))
     160forall(dtype T | is_thread(T) | IS_RESUMPTION_EXCEPTION(ThreadCancelled, (T)))
    161161T & join( T & this ) {
    162162        thread_dtor_guard_t guard = { this, defaultResumptionHandler };
  • libcfa/src/concurrency/thread.hfa

    rc08c3cf r467c8b7  
    2626//-----------------------------------------------------------------------------
    2727// thread trait
    28 trait is_thread(T &) {
     28trait is_thread(dtype T) {
    2929        void ^?{}(T& mutex this);
    3030        void main(T& this);
     
    3232};
    3333
    34 FORALL_DATA_EXCEPTION(ThreadCancelled, (thread_t &), (thread_t)) (
     34FORALL_DATA_EXCEPTION(ThreadCancelled, (dtype thread_t), (thread_t)) (
    3535        thread_t * the_thread;
    3636        exception_t * the_exception;
    3737);
    3838
    39 forall(T &)
     39forall(dtype T)
    4040void copy(ThreadCancelled(T) * dst, ThreadCancelled(T) * src);
    4141
    42 forall(T &)
     42forall(dtype T)
    4343const char * msg(ThreadCancelled(T) *);
    4444
     
    4747
    4848// Inline getters for threads/coroutines/monitors
    49 forall( T & | is_thread(T) )
     49forall( dtype T | is_thread(T) )
    5050static inline $coroutine* get_coroutine(T & this) __attribute__((const)) { return &get_thread(this)->self_cor; }
    5151
    52 forall( T & | is_thread(T) )
     52forall( dtype T | is_thread(T) )
    5353static inline $monitor  * get_monitor  (T & this) __attribute__((const)) { return &get_thread(this)->self_mon; }
    5454
     
    6060extern struct cluster * mainCluster;
    6161
    62 forall( T & | is_thread(T) )
     62forall( dtype T | is_thread(T) )
    6363void __thrd_start( T & this, void (*)(T &) );
    6464
     
    8282};
    8383
    84 forall( T & | is_thread(T) | IS_EXCEPTION(ThreadCancelled, (T)) )
     84forall( dtype T | is_thread(T) | IS_EXCEPTION(ThreadCancelled, (T)) )
    8585void ?{}( thread_dtor_guard_t & this, T & thrd, void(*)(ThreadCancelled(T) &) );
    8686void ^?{}( thread_dtor_guard_t & this );
     
    8989// thread runner
    9090// Structure that actually start and stop threads
    91 forall( T & | sized(T) | is_thread(T) )
     91forall( dtype T | sized(T) | is_thread(T) )
    9292struct scoped {
    9393        T handle;
    9494};
    9595
    96 forall( T & | sized(T) | is_thread(T) | { void ?{}(T&); } )
     96forall( dtype T | sized(T) | is_thread(T) | { void ?{}(T&); } )
    9797void ?{}( scoped(T)& this );
    9898
    99 forall( T &, P... | sized(T) | is_thread(T) | { void ?{}(T&, P); } )
     99forall( dtype T, ttype P | sized(T) | is_thread(T) | { void ?{}(T&, P); } )
    100100void ?{}( scoped(T)& this, P params );
    101101
    102 forall( T & | sized(T) | is_thread(T) )
     102forall( dtype T | sized(T) | is_thread(T) )
    103103void ^?{}( scoped(T)& this );
    104104
     
    115115void unpark( $thread * this );
    116116
    117 forall( T & | is_thread(T) )
     117forall( dtype T | is_thread(T) )
    118118static inline void unpark( T & this ) { if(!&this) return; unpark( get_thread( this ) );}
    119119
     
    128128//----------
    129129// join
    130 forall( T & | is_thread(T) | IS_RESUMPTION_EXCEPTION(ThreadCancelled, (T)) )
     130forall( dtype T | is_thread(T) | IS_RESUMPTION_EXCEPTION(ThreadCancelled, (T)) )
    131131T & join( T & this );
    132132
  • libcfa/src/containers/list.hfa

    rc08c3cf r467c8b7  
    6666#define __DLISTED_MGD_JUSTIMPL(STRUCT)
    6767
    68 forall( tE & ) {
     68forall( dtype tE ) {
    6969        struct $mgd_link {
    7070                tE *elem;
     
    8383                (this.is_terminator){ 1 };
    8484        }
    85         forall ( tInit | { void ?{}( $mgd_link(tE) &, tInit); } )
     85        forall ( otype tInit | { void ?{}( $mgd_link(tE) &, tInit); } )
    8686        static inline void ?=?( $mgd_link(tE) &this, tInit i ) {
    8787                ^?{}( this );
     
    115115  __DLISTED_MGD_COMMON(STRUCT, STRUCT, $links)
    116116
    117 trait $dlistable(Tnode &, Telem &) {
     117trait $dlistable(dtype Tnode, dtype Telem) {
    118118        $mgd_link(Telem) & $prev_link(Tnode &);
    119119        $mgd_link(Telem) & $next_link(Tnode &);
     
    125125};
    126126
    127 forall (Tnode &, Telem & | $dlistable(Tnode, Telem)) {
     127forall (dtype Tnode, dtype Telem | $dlistable(Tnode, Telem)) {
    128128
    129129        // implemented as a sentinel item in an underlying cicrular list
  • libcfa/src/containers/maybe.cfa

    rc08c3cf r467c8b7  
    1818
    1919
    20 forall(T)
     20forall(otype T)
    2121void ?{}(maybe(T) & this) {
    2222        this.has_value = false;
    2323}
    2424
    25 forall(T)
     25forall(otype T)
    2626void ?{}(maybe(T) & this, T value) {
    2727        this.has_value = true;
     
    2929}
    3030
    31 forall(T)
     31forall(otype T)
    3232void ?{}(maybe(T) & this, maybe(T) other) {
    3333        this.has_value = other.has_value;
     
    3737}
    3838
    39 forall(T)
     39forall(otype T)
    4040maybe(T) ?=?(maybe(T) & this, maybe(T) that) {
    4141        if (this.has_value && that.has_value) {
     
    5151}
    5252
    53 forall(T)
     53forall(otype T)
    5454void ^?{}(maybe(T) & this) {
    5555        if (this.has_value) {
     
    5858}
    5959
    60 forall(T)
     60forall(otype T)
    6161bool ?!=?(maybe(T) this, zero_t) {
    6262        return this.has_value;
    6363}
    6464
    65 forall(T)
     65forall(otype T)
    6666maybe(T) maybe_value(T value) {
    6767        return (maybe(T)){value};
    6868}
    6969
    70 forall(T)
     70forall(otype T)
    7171maybe(T) maybe_none() {
    7272        return (maybe(T)){};
    7373}
    7474
    75 forall(T)
     75forall(otype T)
    7676bool has_value(maybe(T) * this) {
    7777        return this->has_value;
    7878}
    7979
    80 forall(T)
     80forall(otype T)
    8181T get(maybe(T) * this) {
    8282        assertf(this->has_value, "attempt to get from maybe without value");
     
    8484}
    8585
    86 forall(T)
     86forall(otype T)
    8787void set(maybe(T) * this, T value) {
    8888        if (this->has_value) {
     
    9494}
    9595
    96 forall(T)
     96forall(otype T)
    9797void set_none(maybe(T) * this) {
    9898        if (this->has_value) {
  • libcfa/src/containers/maybe.hfa

    rc08c3cf r467c8b7  
    1919
    2020// DO NOT USE DIRECTLY!
    21 forall(T)
     21forall(otype T)
    2222struct maybe {
    2323    bool has_value;
     
    2626
    2727
    28 forall(T)
     28forall(otype T)
    2929void ?{}(maybe(T) & this);
    3030
    31 forall(T)
     31forall(otype T)
    3232void ?{}(maybe(T) & this, T value);
    3333
    34 forall(T)
     34forall(otype T)
    3535void ?{}(maybe(T) & this, maybe(T) other);
    3636
    37 forall(T)
     37forall(otype T)
    3838void ^?{}(maybe(T) & this);
    3939
    40 forall(T)
     40forall(otype T)
    4141maybe(T) ?=?(maybe(T) & this, maybe(T) other);
    4242
    43 forall(T)
     43forall(otype T)
    4444bool ?!=?(maybe(T) this, zero_t);
    4545
    4646/* Waiting for bug#11 to be fixed.
    47 forall(T)
     47forall(otype T)
    4848maybe(T) maybe_value(T value);
    4949
    50 forall(T)
     50forall(otype T)
    5151maybe(T) maybe_none();
    5252*/
    5353
    54 forall(T)
     54forall(otype T)
    5555bool has_value(maybe(T) * this);
    5656
    57 forall(T)
     57forall(otype T)
    5858T get(maybe(T) * this);
    5959
    60 forall(T)
     60forall(otype T)
    6161void set(maybe(T) * this, T value);
    6262
    63 forall(T)
     63forall(otype T)
    6464void set_none(maybe(T) * this);
    6565
  • libcfa/src/containers/pair.cfa

    rc08c3cf r467c8b7  
    1313#include <containers/pair.hfa>
    1414
    15 forall(R, S
     15forall(otype R, otype S
    1616        | { int ?==?(R, R); int ?<?(R, R); int ?<?(S, S); })
    1717int ?<?(pair(R, S) p, pair(R, S) q) {
     
    1919}
    2020
    21 forall(R, S
     21forall(otype R, otype S
    2222        | { int ?==?(R, R); int ?<?(R, R); int ?<=?(S, S); })
    2323int ?<=?(pair(R, S) p, pair(R, S) q) {
     
    2525}
    2626
    27 forall(R, S | { int ?==?(R, R); int ?==?(S, S); })
     27forall(otype R, otype S | { int ?==?(R, R); int ?==?(S, S); })
    2828int ?==?(pair(R, S) p, pair(R, S) q) {
    2929        return p.first == q.first && p.second == q.second;
    3030}
    3131
    32 forall(R, S | { int ?!=?(R, R); int ?!=?(S, S); })
     32forall(otype R, otype S | { int ?!=?(R, R); int ?!=?(S, S); })
    3333int ?!=?(pair(R, S) p, pair(R, S) q) {
    3434        return p.first != q.first || p.second != q.second;
    3535}
    3636
    37 forall(R, S
     37forall(otype R, otype S
    3838        | { int ?==?(R, R); int ?>?(R, R); int ?>?(S, S); })
    3939int ?>?(pair(R, S) p, pair(R, S) q) {
     
    4141}
    4242
    43 forall(R, S
     43forall(otype R, otype S
    4444        | { int ?==?(R, R); int ?>?(R, R); int ?>=?(S, S); })
    4545int ?>=?(pair(R, S) p, pair(R, S) q) {
  • libcfa/src/containers/pair.hfa

    rc08c3cf r467c8b7  
    1616#pragma once
    1717
    18 forall(R, S) struct pair {
     18forall(otype R, otype S) struct pair {
    1919        R first;
    2020        S second;
    2121};
    2222
    23 forall(R, S
     23forall(otype R, otype S
    2424        | { int ?==?(R, R); int ?<?(R, R); int ?<?(S, S); })
    2525int ?<?(pair(R, S) p, pair(R, S) q);
    2626
    27 forall(R, S
     27forall(otype R, otype S
    2828        | { int ?==?(R, R); int ?<?(R, R); int ?<=?(S, S); })
    2929int ?<=?(pair(R, S) p, pair(R, S) q);
    3030
    31 forall(R, S | { int ?==?(R, R); int ?==?(S, S); })
     31forall(otype R, otype S | { int ?==?(R, R); int ?==?(S, S); })
    3232int ?==?(pair(R, S) p, pair(R, S) q);
    3333
    34 forall(R, S | { int ?!=?(R, R); int ?!=?(S, S); })
     34forall(otype R, otype S | { int ?!=?(R, R); int ?!=?(S, S); })
    3535int ?!=?(pair(R, S) p, pair(R, S) q);
    3636
    37 forall(R, S
     37forall(otype R, otype S
    3838        | { int ?==?(R, R); int ?>?(R, R); int ?>?(S, S); })
    3939int ?>?(pair(R, S) p, pair(R, S) q);
    4040
    41 forall(R, S
     41forall(otype R, otype S
    4242        | { int ?==?(R, R); int ?>?(R, R); int ?>=?(S, S); })
    4343int ?>=?(pair(R, S) p, pair(R, S) q);
  • libcfa/src/containers/result.cfa

    rc08c3cf r467c8b7  
    1818
    1919
    20 forall(T, E)
     20forall(otype T, otype E)
    2121void ?{}(result(T, E) & this) {
    2222        this.has_value = false;
     
    2424}
    2525
    26 forall(T, E)
     26forall(otype T, otype E)
    2727void ?{}(result(T, E) & this, one_t, T value) {
    2828        this.has_value = true;
     
    3030}
    3131
    32 forall(T, E)
     32forall(otype T, otype E)
    3333void ?{}(result(T, E) & this, zero_t, E error) {
    3434        this.has_value = false;
     
    3636}
    3737
    38 forall(T, E)
     38forall(otype T, otype E)
    3939void ?{}(result(T, E) & this, result(T, E) other) {
    4040        this.has_value = other.has_value;
     
    4646}
    4747
    48 forall(T, E)
     48forall(otype T, otype E)
    4949result(T, E) ?=?(result(T, E) & this, result(T, E) that) {
    5050        if (this.has_value && that.has_value) {
     
    6363}
    6464
    65 forall(T, E)
     65forall(otype T, otype E)
    6666void ^?{}(result(T, E) & this) {
    6767        if (this.has_value) {
     
    7272}
    7373
    74 forall(T, E)
     74forall(otype T, otype E)
    7575bool ?!=?(result(T, E) this, zero_t) {
    7676        return this.has_value;
    7777}
    7878
    79 forall(T, E)
     79forall(otype T, otype E)
    8080result(T, E) result_value(T value) {
    8181        return (result(T, E)){1, value};
    8282}
    8383
    84 forall(T, E)
     84forall(otype T, otype E)
    8585result(T, E) result_error(E error) {
    8686        return (result(T, E)){0, error};
    8787}
    8888
    89 forall(T, E)
     89forall(otype T, otype E)
    9090bool has_value(result(T, E) * this) {
    9191        return this->has_value;
    9292}
    9393
    94 forall(T, E)
     94forall(otype T, otype E)
    9595T get(result(T, E) * this) {
    9696        assertf(this->has_value, "attempt to get from result without value");
     
    9898}
    9999
    100 forall(T, E)
     100forall(otype T, otype E)
    101101E get_error(result(T, E) * this) {
    102102        assertf(!this->has_value, "attempt to get from result without error");
     
    104104}
    105105
    106 forall(T, E)
     106forall(otype T, otype E)
    107107void set(result(T, E) * this, T value) {
    108108        if (this->has_value) {
     
    115115}
    116116
    117 forall(T, E)
     117forall(otype T, otype E)
    118118void set_error(result(T, E) * this, E error) {
    119119        if (this->has_value) {
  • libcfa/src/containers/result.hfa

    rc08c3cf r467c8b7  
    1919
    2020// DO NOT USE DIRECTLY!
    21 forall(T, E)
     21forall(otype T, otype E)
    2222union inner_result{
    2323        T value;
     
    2525};
    2626
    27 forall(T, E)
     27forall(otype T, otype E)
    2828struct result {
    2929        bool has_value;
     
    3232
    3333
    34 forall(T, E)
     34forall(otype T, otype E)
    3535void ?{}(result(T, E) & this);
    3636
    37 forall(T, E)
     37forall(otype T, otype E)
    3838void ?{}(result(T, E) & this, one_t, T value);
    3939
    40 forall(T, E)
     40forall(otype T, otype E)
    4141void ?{}(result(T, E) & this, zero_t, E error);
    4242
    43 forall(T, E)
     43forall(otype T, otype E)
    4444void ?{}(result(T, E) & this, result(T, E) other);
    4545
    46 forall(T, E)
     46forall(otype T, otype E)
    4747void ^?{}(result(T, E) & this);
    4848
    49 forall(T, E)
     49forall(otype T, otype E)
    5050result(T, E) ?=?(result(T, E) & this, result(T, E) other);
    5151
    52 forall(T, E)
     52forall(otype T, otype E)
    5353bool ?!=?(result(T, E) this, zero_t);
    5454
    5555/* Wating for bug#11 to be fixed.
    56 forall(T, E)
     56forall(otype T, otype E)
    5757result(T, E) result_value(T value);
    5858
    59 forall(T, E)
     59forall(otype T, otype E)
    6060result(T, E) result_error(E error);
    6161*/
    6262
    63 forall(T, E)
     63forall(otype T, otype E)
    6464bool has_value(result(T, E) * this);
    6565
    66 forall(T, E)
     66forall(otype T, otype E)
    6767T get(result(T, E) * this);
    6868
    69 forall(T, E)
     69forall(otype T, otype E)
    7070E get_error(result(T, E) * this);
    7171
    72 forall(T, E)
     72forall(otype T, otype E)
    7373void set(result(T, E) * this, T value);
    7474
    75 forall(T, E)
     75forall(otype T, otype E)
    7676void set_error(result(T, E) * this, E error);
    7777
  • libcfa/src/containers/stackLockFree.hfa

    rc08c3cf r467c8b7  
    1717#include <stdint.h>
    1818
    19 forall( T & )
     19forall( dtype T )
    2020union Link {
    2121        struct {                                                                                        // 32/64-bit x 2
     
    3131}; // Link
    3232
    33 forall( T | sized(T) | { Link(T) * ?`next( T * ); } ) {
     33forall( otype T | sized(T) | { Link(T) * ?`next( T * ); } ) {
    3434        struct StackLF {
    3535                Link(T) stack;
  • libcfa/src/containers/vector.cfa

    rc08c3cf r467c8b7  
    1818#include <stdlib.hfa>
    1919
    20 forall(T, allocator_t | allocator_c(T, allocator_t))
     20forall(otype T, otype allocator_t | allocator_c(T, allocator_t))
    2121void copy_internal(vector(T, allocator_t)* this, vector(T, allocator_t)* other);
    2222
    2323//------------------------------------------------------------------------------
    2424//Initialization
    25 forall(T, allocator_t | allocator_c(T, allocator_t))
     25forall(otype T, otype allocator_t | allocator_c(T, allocator_t))
    2626void ?{}(vector(T, allocator_t)& this)
    2727{
     
    3030}
    3131
    32 forall(T, allocator_t | allocator_c(T, allocator_t))
     32forall(otype T, otype allocator_t | allocator_c(T, allocator_t))
    3333void ?{}(vector(T, allocator_t)& this, vector(T, allocator_t) rhs)
    3434{
     
    3737}
    3838
    39 // forall(T, allocator_t | allocator_c(T, allocator_t))
     39// forall(otype T, otype allocator_t | allocator_c(T, allocator_t))
    4040// vector(T, allocator_t) ?=?(vector(T, allocator_t)* this, vector(T, allocator_t) rhs)
    4141// {
     
    4545// }
    4646
    47 forall(T, allocator_t | allocator_c(T, allocator_t))
     47forall(otype T, otype allocator_t | allocator_c(T, allocator_t))
    4848void ^?{}(vector(T, allocator_t)& this)
    4949{
     
    5454//------------------------------------------------------------------------------
    5555//Modifiers
    56 forall(T, allocator_t | allocator_c(T, allocator_t))
     56forall(otype T, otype allocator_t | allocator_c(T, allocator_t))
    5757void push_back(vector(T, allocator_t)* this, T value)
    5858{
     
    6262}
    6363
    64 forall(T, allocator_t | allocator_c(T, allocator_t))
     64forall(otype T, otype allocator_t | allocator_c(T, allocator_t))
    6565void pop_back(vector(T, allocator_t)* this)
    6666{
     
    6969}
    7070
    71 forall(T, allocator_t | allocator_c(T, allocator_t))
     71forall(otype T, otype allocator_t | allocator_c(T, allocator_t))
    7272void clear(vector(T, allocator_t)* this)
    7373{
     
    8282//Internal Helpers
    8383
    84 forall(T, allocator_t | allocator_c(T, allocator_t))
     84forall(otype T, otype allocator_t | allocator_c(T, allocator_t))
    8585void copy_internal(vector(T, allocator_t)* this, vector(T, allocator_t)* other)
    8686{
     
    9393//------------------------------------------------------------------------------
    9494//Allocator
    95 forall(T)
     95forall(otype T)
    9696void ?{}(heap_allocator(T)& this)
    9797{
     
    100100}
    101101
    102 forall(T)
     102forall(otype T)
    103103void ?{}(heap_allocator(T)& this, heap_allocator(T) rhs)
    104104{
     
    107107}
    108108
    109 forall(T)
     109forall(otype T)
    110110heap_allocator(T) ?=?(heap_allocator(T)& this, heap_allocator(T) rhs)
    111111{
     
    115115}
    116116
    117 forall(T)
     117forall(otype T)
    118118void ^?{}(heap_allocator(T)& this)
    119119{
     
    121121}
    122122
    123 forall(T)
     123forall(otype T)
    124124inline void realloc_storage(heap_allocator(T)* this, size_t size)
    125125{
  • libcfa/src/containers/vector.hfa

    rc08c3cf r467c8b7  
    2020//------------------------------------------------------------------------------
    2121//Allocator
    22 forall(T)
     22forall(otype T)
    2323struct heap_allocator
    2424{
     
    2727};
    2828
    29 forall(T)
     29forall(otype T)
    3030void ?{}(heap_allocator(T)& this);
    3131
    32 forall(T)
     32forall(otype T)
    3333void ?{}(heap_allocator(T)& this, heap_allocator(T) rhs);
    3434
    35 forall(T)
     35forall(otype T)
    3636heap_allocator(T) ?=?(heap_allocator(T)& this, heap_allocator(T) rhs);
    3737
    38 forall(T)
     38forall(otype T)
    3939void ^?{}(heap_allocator(T)& this);
    4040
    41 forall(T)
     41forall(otype T)
    4242void realloc_storage(heap_allocator(T)* this, size_t size);
    4343
    44 forall(T)
     44forall(otype T)
    4545static inline T* data(heap_allocator(T)* this)
    4646{
     
    5050//------------------------------------------------------------------------------
    5151//Declaration
    52 trait allocator_c(T, allocator_t)
     52trait allocator_c(otype T, otype allocator_t)
    5353{
    5454        void realloc_storage(allocator_t*, size_t);
     
    5656};
    5757
    58 forall(T, allocator_t = heap_allocator(T) | allocator_c(T, allocator_t))
     58forall(otype T, otype allocator_t = heap_allocator(T) | allocator_c(T, allocator_t))
    5959struct vector;
    6060
    6161//------------------------------------------------------------------------------
    6262//Initialization
    63 forall(T, allocator_t | allocator_c(T, allocator_t))
     63forall(otype T, otype allocator_t | allocator_c(T, allocator_t))
    6464void ?{}(vector(T, allocator_t)& this);
    6565
    66 forall(T, allocator_t | allocator_c(T, allocator_t))
     66forall(otype T, otype allocator_t | allocator_c(T, allocator_t))
    6767void ?{}(vector(T, allocator_t)& this, vector(T, allocator_t) rhs);
    6868
    69 forall(T, allocator_t | allocator_c(T, allocator_t))
     69forall(otype T, otype allocator_t | allocator_c(T, allocator_t))
    7070vector(T, allocator_t) ?=?(vector(T, allocator_t)& this, vector(T, allocator_t) rhs);
    7171
    72 forall(T, allocator_t | allocator_c(T, allocator_t))
     72forall(otype T, otype allocator_t | allocator_c(T, allocator_t))
    7373void ^?{}(vector(T, allocator_t)& this);
    7474
    75 forall(T, allocator_t = heap_allocator(T) | allocator_c(T, allocator_t))
     75forall(otype T, otype allocator_t = heap_allocator(T) | allocator_c(T, allocator_t))
    7676struct vector
    7777{
     
    8282//------------------------------------------------------------------------------
    8383//Capacity
    84 forall(T, allocator_t | allocator_c(T, allocator_t))
     84forall(otype T, otype allocator_t | allocator_c(T, allocator_t))
    8585static inline bool empty(vector(T, allocator_t)* this)
    8686{
     
    8888}
    8989
    90 forall(T, allocator_t | allocator_c(T, allocator_t))
     90forall(otype T, otype allocator_t | allocator_c(T, allocator_t))
    9191static inline size_t size(vector(T, allocator_t)* this)
    9292{
     
    9494}
    9595
    96 forall(T, allocator_t | allocator_c(T, allocator_t))
     96forall(otype T, otype allocator_t | allocator_c(T, allocator_t))
    9797static inline void reserve(vector(T, allocator_t)* this, size_t size)
    9898{
     
    102102//------------------------------------------------------------------------------
    103103//Element access
    104 forall(T, allocator_t | allocator_c(T, allocator_t))
     104forall(otype T, otype allocator_t | allocator_c(T, allocator_t))
    105105static inline T at(vector(T, allocator_t)* this, size_t index)
    106106{
     
    108108}
    109109
    110 forall(T, allocator_t | allocator_c(T, allocator_t))
     110forall(otype T, otype allocator_t | allocator_c(T, allocator_t))
    111111static inline T ?[?](vector(T, allocator_t)* this, size_t index)
    112112{
     
    114114}
    115115
    116 forall(T, allocator_t | allocator_c(T, allocator_t))
     116forall(otype T, otype allocator_t | allocator_c(T, allocator_t))
    117117static inline T front(vector(T, allocator_t)* this)
    118118{
     
    120120}
    121121
    122 forall(T, allocator_t | allocator_c(T, allocator_t))
     122forall(otype T, otype allocator_t | allocator_c(T, allocator_t))
    123123static inline T back(vector(T, allocator_t)* this)
    124124{
     
    128128//------------------------------------------------------------------------------
    129129//Modifiers
    130 forall(T, allocator_t | allocator_c(T, allocator_t))
     130forall(otype T, otype allocator_t | allocator_c(T, allocator_t))
    131131void push_back(vector(T, allocator_t)* this, T value);
    132132
    133 forall(T, allocator_t | allocator_c(T, allocator_t))
     133forall(otype T, otype allocator_t | allocator_c(T, allocator_t))
    134134void pop_back(vector(T, allocator_t)* this);
    135135
    136 forall(T, allocator_t | allocator_c(T, allocator_t))
     136forall(otype T, otype allocator_t | allocator_c(T, allocator_t))
    137137void clear(vector(T, allocator_t)* this);
    138138
    139139//------------------------------------------------------------------------------
    140140//Iterators
    141 forall(T, allocator_t | allocator_c(T, allocator_t))
     141forall(otype T, otype allocator_t | allocator_c(T, allocator_t))
    142142static inline T* begin(vector(T, allocator_t)* this)
    143143{
     
    145145}
    146146
    147 // forall(T, allocator_t | allocator_c(T, allocator_t))
     147// forall(otype T, otype allocator_t | allocator_c(T, allocator_t))
    148148// static inline const T* cbegin(const vector(T, allocator_t)* this)
    149149// {
     
    151151// }
    152152
    153 forall(T, allocator_t | allocator_c(T, allocator_t))
     153forall(otype T, otype allocator_t | allocator_c(T, allocator_t))
    154154static inline T* end(vector(T, allocator_t)* this)
    155155{
     
    157157}
    158158
    159 // forall(T, allocator_t | allocator_c(T, allocator_t))
     159// forall(otype T, otype allocator_t | allocator_c(T, allocator_t))
    160160// static inline const T* cend(const vector(T, allocator_t)* this)
    161161// {
  • libcfa/src/exception.h

    rc08c3cf r467c8b7  
    101101// implemented in the .c file either so they all have to be inline.
    102102
    103 trait is_exception(exceptT &, virtualT &) {
     103trait is_exception(dtype exceptT, dtype virtualT) {
    104104        /* The first field must be a pointer to a virtual table.
    105105         * That virtual table must be a decendent of the base exception virtual table.
     
    109109};
    110110
    111 trait is_termination_exception(exceptT &, virtualT & | is_exception(exceptT, virtualT)) {
     111trait is_termination_exception(dtype exceptT, dtype virtualT | is_exception(exceptT, virtualT)) {
    112112        void defaultTerminationHandler(exceptT &);
    113113};
    114114
    115 trait is_resumption_exception(exceptT &, virtualT & | is_exception(exceptT, virtualT)) {
     115trait is_resumption_exception(dtype exceptT, dtype virtualT | is_exception(exceptT, virtualT)) {
    116116        void defaultResumptionHandler(exceptT &);
    117117};
    118118
    119 forall(exceptT &, virtualT & | is_termination_exception(exceptT, virtualT))
     119forall(dtype exceptT, dtype virtualT | is_termination_exception(exceptT, virtualT))
    120120static inline void $throw(exceptT & except) {
    121121        __cfaehm_throw_terminate(
     
    125125}
    126126
    127 forall(exceptT &, virtualT & | is_resumption_exception(exceptT, virtualT))
     127forall(dtype exceptT, dtype virtualT | is_resumption_exception(exceptT, virtualT))
    128128static inline void $throwResume(exceptT & except) {
    129129        __cfaehm_throw_resume(
     
    133133}
    134134
    135 forall(exceptT &, virtualT & | is_exception(exceptT, virtualT))
     135forall(dtype exceptT, dtype virtualT | is_exception(exceptT, virtualT))
    136136static inline void cancel_stack(exceptT & except) __attribute__((noreturn)) {
    137137        __cfaehm_cancel_stack( (exception_t *)&except );
    138138}
    139139
    140 forall(exceptT &, virtualT & | is_exception(exceptT, virtualT))
     140forall(dtype exceptT, dtype virtualT | is_exception(exceptT, virtualT))
    141141static inline void defaultTerminationHandler(exceptT & except) {
    142142        return cancel_stack( except );
    143143}
    144144
    145 forall(exceptT &, virtualT & | is_exception(exceptT, virtualT))
     145forall(dtype exceptT, dtype virtualT | is_exception(exceptT, virtualT))
    146146static inline void defaultResumptionHandler(exceptT & except) {
    147147        throw except;
  • libcfa/src/executor.cfa

    rc08c3cf r467c8b7  
    77#include <containers/list.hfa>
    88
    9 forall( T & | $dlistable(T, T) ) {
     9forall( dtype T | $dlistable(T, T) ) {
    1010        monitor Buffer {                                                                        // unbounded buffer
    1111                dlist( T, T ) queue;                                                    // unbounded list of work requests
  • libcfa/src/gmp.hfa

    rc08c3cf r467c8b7  
    255255
    256256        // I/O
    257         forall( istype & | istream( istype ) )
     257        forall( dtype istype | istream( istype ) )
    258258                istype & ?|?( istype & is, Int & mp ) {
    259259                gmp_scanf( "%Zd", &mp );
     
    261261        } // ?|?
    262262
    263         forall( ostype & | ostream( ostype ) ) {
     263        forall( dtype ostype | ostream( ostype ) ) {
    264264                ostype & ?|?( ostype & os, Int mp ) {
    265265                        if ( $sepPrt( os ) ) fmt( os, "%s", $sepGetCur( os ) );
  • libcfa/src/interpose.cfa

    rc08c3cf r467c8b7  
    125125
    126126                // Failure handler
    127                  // internal errors
    128                 __cfaabi_sigaction( SIGSEGV, sigHandler_segv, SA_SIGINFO | SA_ONSTACK ); // Invalid memory reference (default: Core)
    129                 __cfaabi_sigaction( SIGBUS , sigHandler_segv, SA_SIGINFO | SA_ONSTACK ); // Bus error, bad memory access (default: Core)
    130                 __cfaabi_sigaction( SIGILL , sigHandler_ill , SA_SIGINFO | SA_ONSTACK ); // Illegal Instruction (default: Core)
    131                 __cfaabi_sigaction( SIGFPE , sigHandler_fpe , SA_SIGINFO | SA_ONSTACK ); // Floating-point exception (default: Core)
    132 
    133                 // handlers to outside errors
    134                 // reset in-case they insist and send it over and over
    135                 __cfaabi_sigaction( SIGTERM, sigHandler_term, SA_SIGINFO | SA_ONSTACK | SA_RESETHAND ); // Termination signal (default: Term)
    136                 __cfaabi_sigaction( SIGINT , sigHandler_term, SA_SIGINFO | SA_ONSTACK | SA_RESETHAND ); // Interrupt from keyboard (default: Term)
    137                 __cfaabi_sigaction( SIGHUP , sigHandler_term, SA_SIGINFO | SA_ONSTACK | SA_RESETHAND ); // Hangup detected on controlling terminal or death of controlling process (default: Term)
    138                 __cfaabi_sigaction( SIGQUIT, sigHandler_term, SA_SIGINFO | SA_ONSTACK | SA_RESETHAND ); // Quit from keyboard (default: Core)
    139                 __cfaabi_sigaction( SIGABRT, sigHandler_term, SA_SIGINFO | SA_ONSTACK | SA_RESETHAND ); // Abort signal from abort(3) (default: Core)
     127                __cfaabi_sigaction( SIGSEGV, sigHandler_segv, SA_SIGINFO | SA_ONSTACK );
     128                __cfaabi_sigaction( SIGBUS , sigHandler_segv, SA_SIGINFO | SA_ONSTACK );
     129                __cfaabi_sigaction( SIGILL , sigHandler_ill , SA_SIGINFO | SA_ONSTACK );
     130                __cfaabi_sigaction( SIGFPE , sigHandler_fpe , SA_SIGINFO | SA_ONSTACK );
     131                __cfaabi_sigaction( SIGTERM, sigHandler_term, SA_SIGINFO | SA_ONSTACK | SA_RESETHAND ); // one shot handler, return to default
     132                __cfaabi_sigaction( SIGINT , sigHandler_term, SA_SIGINFO | SA_ONSTACK | SA_RESETHAND );
     133                __cfaabi_sigaction( SIGABRT, sigHandler_term, SA_SIGINFO | SA_ONSTACK | SA_RESETHAND );
     134                __cfaabi_sigaction( SIGHUP , sigHandler_term, SA_SIGINFO | SA_ONSTACK | SA_RESETHAND ); // terminal hangup
    140135        }
    141136}
     
    168163}
    169164
    170 // See concurrency/kernel.cfa and concurrency/preemption.cfa for strong definition used in multi-processor mode.
    171 void __kernel_abort_lock( void ) __attribute__(( __nothrow__, __leaf__, __weak__ )) {}
    172 void __kernel_abort_msg( char buffer[], int size ) __attribute__(( __nothrow__, __leaf__, __weak__ )) {}
    173 int __kernel_abort_lastframe( void ) __attribute__(( __nothrow__, __leaf__, __weak__ )) { return 4; }
     165void * kernel_abort( void ) __attribute__(( __nothrow__, __leaf__, __weak__ )) { return 0p; }
     166void kernel_abort_msg( void * data, char buffer[], int size ) __attribute__(( __nothrow__, __leaf__, __weak__ )) {}
     167// See concurrency/kernel.cfa for strong definition used in multi-processor mode.
     168int kernel_abort_lastframe( void ) __attribute__(( __nothrow__, __leaf__, __weak__ )) { return 4; }
    174169
    175170enum { abort_text_size = 1024 };
     
    178173static void __cfaabi_backtrace( int start ) {
    179174        enum { Frames = 50, };                                                          // maximum number of stack frames
    180         int last = __kernel_abort_lastframe();                          // skip last N stack frames
     175        int last = kernel_abort_lastframe();                            // skip last N stack frames
    181176
    182177        void * array[Frames];
     
    225220}
    226221
    227 static volatile bool __abort_first = 0;
     222static volatile int __abort_stage = 0;
    228223
    229224// Cannot forward va_list.
    230225void __abort( bool signalAbort, const char fmt[], va_list args ) {
    231         // Multiple threads can come here from multiple paths
    232         // To make sure this is safe any concurrent/subsequent call to abort is redirected to libc-abort
    233         bool first = ! __atomic_test_and_set( &__abort_first, __ATOMIC_SEQ_CST);
    234 
    235         // Prevent preemption from kicking-in and messing with the abort
    236         __kernel_abort_lock();
    237 
    238         // first to abort ?
    239         if ( !first ) {
    240                 // We aren't the first to abort just let C handle it
    241                 signal( SIGABRT, SIG_DFL );     // restore default in case we came here through the function.
     226        int stage = __atomic_add_fetch( &__abort_stage, 1, __ATOMIC_SEQ_CST );
     227
     228        // First stage: stop the cforall kernel and print
     229        if(stage == 1) {
     230                // increment stage
     231                stage = __atomic_add_fetch( &__abort_stage, 1, __ATOMIC_SEQ_CST );
     232
     233                // must be done here to lock down kernel
     234                void * kernel_data = kernel_abort();
     235                int len;
     236
     237                signal( SIGABRT, SIG_DFL );                                                     // prevent final "real" abort from recursing to handler
     238
     239                len = snprintf( abort_text, abort_text_size, "Cforall Runtime error (UNIX pid:%ld) ", (long int)getpid() ); // use UNIX pid (versus getPid)
     240                __cfaabi_bits_write( STDERR_FILENO, abort_text, len );
     241
     242                assert( fmt );
     243                len = vsnprintf( abort_text, abort_text_size, fmt, args );
     244                __cfaabi_bits_write( STDERR_FILENO, abort_text, len );
     245
     246                // add optional newline if missing at the end of the format text
     247                if ( fmt[strlen( fmt ) - 1] != '\n' ) {
     248                        __cfaabi_bits_write( STDERR_FILENO, "\n", 1 );
     249                } // if
     250                kernel_abort_msg( kernel_data, abort_text, abort_text_size );
     251        }
     252
     253        // Second stage: print the backtrace
     254        if(stage == 2) {
     255                // increment stage
     256                stage = __atomic_add_fetch( &__abort_stage, 1, __ATOMIC_SEQ_CST );
     257
     258                // print stack trace in handler
     259                __cfaabi_backtrace( signalAbort ? 4 : 2 );
     260        }
     261
     262        do {
     263                // Finally call abort
    242264                __cabi_libc.abort();
    243         }
    244 
    245         int len = snprintf( abort_text, abort_text_size, "Cforall Runtime error (UNIX pid:%ld) ", (long int)getpid() ); // use UNIX pid (versus getPid)
    246         __cfaabi_bits_write( STDERR_FILENO, abort_text, len );
    247 
    248         // print the cause of the error
    249         assert( fmt );
    250         len = vsnprintf( abort_text, abort_text_size, fmt, args );
    251         __cfaabi_bits_write( STDERR_FILENO, abort_text, len );
    252 
    253         // add optional newline if missing at the end of the format text
    254         if ( fmt[strlen( fmt ) - 1] != '\n' ) {
    255                 __cfaabi_bits_write( STDERR_FILENO, "\n", 1 );
    256         } // if
    257 
    258         // Give the kernel the chance to add some data in here
    259         __kernel_abort_msg( abort_text, abort_text_size );
    260 
    261         // print stack trace in handler
    262         __cfaabi_backtrace( signalAbort ? 4 : 2 );
    263 
    264         // Finally call abort
    265         __cabi_libc.abort();
    266 
     265
     266                // Loop so that we never return
     267        } while(true);
    267268}
    268269
     
    281282    // CONTROL NEVER REACHES HERE!
    282283    va_end( args );
     284}
     285
     286extern "C" {
     287        void __cfaabi_real_abort(void) {
     288                __cabi_libc.abort();
     289        }
    283290}
    284291
  • libcfa/src/iostream.cfa

    rc08c3cf r467c8b7  
    3636
    3737
    38 forall( ostype & | ostream( ostype ) ) {
     38forall( dtype ostype | ostream( ostype ) ) {
    3939        ostype & ?|?( ostype & os, bool b ) {
    4040                if ( $sepPrt( os ) ) fmt( os, "%s", $sepGetCur( os ) );
     
    407407
    408408// tuples
    409 forall( ostype &, T, Params... | writeable( T, ostype ) | { ostype & ?|?( ostype &, Params ); } ) {
     409forall( dtype ostype, otype T, ttype Params | writeable( T, ostype ) | { ostype & ?|?( ostype &, Params ); } ) {
    410410        ostype & ?|?( ostype & os, T arg, Params rest ) {
    411411                (ostype &)(os | arg);                                                   // print first argument
     
    426426
    427427// writes the range [begin, end) to the given stream
    428 forall( ostype &, elt_type | writeable( elt_type, ostype ), iterator_type | iterator( iterator_type, elt_type ) ) {
     428forall( dtype ostype, otype elt_type | writeable( elt_type, ostype ), otype iterator_type | iterator( iterator_type, elt_type ) ) {
    429429        void write( iterator_type begin, iterator_type end, ostype & os ) {
    430430                void print( elt_type i ) { os | i; }
     
    447447// Default prefix for non-decimal prints is 0b, 0, 0x.
    448448#define IntegralFMTImpl( T, IFMTNP, IFMTP ) \
    449 forall( ostype & | ostream( ostype ) ) { \
     449forall( dtype ostype | ostream( ostype ) ) { \
    450450        ostype & ?|?( ostype & os, _Ostream_Manip(T) f ) { \
    451451                if ( $sepPrt( os ) ) fmt( os, "%s", $sepGetCur( os ) ); \
     
    540540// Default prefix for non-decimal prints is 0b, 0, 0x.
    541541#define IntegralFMTImpl128( T, SIGNED, CODE, IFMTNP, IFMTP ) \
    542 forall( ostype & | ostream( ostype ) ) \
     542forall( dtype ostype | ostream( ostype ) ) \
    543543static void base10_128( ostype & os, _Ostream_Manip(T) f ) { \
    544544        if ( f.val > UINT64_MAX ) { \
     
    557557        } /* if */ \
    558558} /* base10_128 */ \
    559 forall( ostype & | ostream( ostype ) ) { \
     559forall( dtype ostype | ostream( ostype ) ) { \
    560560        ostype & ?|?( ostype & os, _Ostream_Manip(T) f ) { \
    561561                if ( $sepPrt( os ) ) fmt( os, "%s", $sepGetCur( os ) ); \
     
    659659#if defined( __SIZEOF_INT128__ )
    660660// Default prefix for non-decimal prints is 0b, 0, 0x.
    661 forall( ostype & | ostream( ostype ) )
     661forall( dtype ostype | ostream( ostype ) )
    662662static inline void base_128( ostype & os, unsigned int128 val, unsigned int128 power, _Ostream_Manip(uint64_t) & f, unsigned int maxdig, unsigned int bits, unsigned int cnt = 0 ) {
    663663        int wd = 1;                                                                                     // f.wd is never 0 because 0 implies left-pad
     
    724724
    725725#define IntegralFMTImpl128( T ) \
    726 forall( ostype & | ostream( ostype ) ) { \
     726forall( dtype ostype | ostream( ostype ) ) { \
    727727        ostype & ?|?( ostype & os, _Ostream_Manip(T) f ) { \
    728728                _Ostream_Manip(uint64_t) fmt; \
     
    772772
    773773#define FloatingPointFMTImpl( T, DFMTNP, DFMTP ) \
    774 forall( ostype & | ostream( ostype ) ) { \
     774forall( dtype ostype | ostream( ostype ) ) { \
    775775        ostype & ?|?( ostype & os, _Ostream_Manip(T) f ) { \
    776776                if ( $sepPrt( os ) ) fmt( os, "%s", $sepGetCur( os ) ); \
     
    806806// *********************************** character ***********************************
    807807
    808 forall( ostype & | ostream( ostype ) ) {
     808forall( dtype ostype | ostream( ostype ) ) {
    809809        ostype & ?|?( ostype & os, _Ostream_Manip(char) f ) {
    810810                if ( f.base != 'c' ) {                                                  // bespoke binary/octal/hex format
     
    839839// *********************************** C string ***********************************
    840840
    841 forall( ostype & | ostream( ostype ) ) {
     841forall( dtype ostype | ostream( ostype ) ) {
    842842        ostype & ?|?( ostype & os, _Ostream_Manip(const char *) f ) {
    843843                if ( ! f.val ) return os;                                               // null pointer ?
     
    887887
    888888
    889 forall( istype & | istream( istype ) ) {
     889forall( dtype istype | istream( istype ) ) {
    890890        istype & ?|?( istype & is, bool & b ) {
    891891                char val[6];
     
    10531053// *********************************** manipulators ***********************************
    10541054
    1055 forall( istype & | istream( istype ) )
     1055forall( dtype istype | istream( istype ) )
    10561056istype & ?|?( istype & is, _Istream_Cstr f ) {
    10571057        // skip xxx
     
    10881088} // ?|?
    10891089
    1090 forall( istype & | istream( istype ) )
     1090forall( dtype istype | istream( istype ) )
    10911091istype & ?|?( istype & is, _Istream_Char f ) {
    10921092        fmt( is, "%*c" );                                                                       // argument variable unused
     
    10951095
    10961096#define InputFMTImpl( T, CODE ) \
    1097 forall( istype & | istream( istype ) ) \
     1097forall( dtype istype | istream( istype ) ) \
    10981098istype & ?|?( istype & is, _Istream_Manip(T) f ) { \
    10991099        enum { size = 16 }; \
     
    11241124InputFMTImpl( long double, "Lf" )
    11251125
    1126 forall( istype & | istream( istype ) )
     1126forall( dtype istype | istream( istype ) )
    11271127istype & ?|?( istype & is, _Istream_Manip(float _Complex) fc ) {
    11281128        float re, im;
     
    11351135} // ?|?
    11361136
    1137 forall( istype & | istream( istype ) )
     1137forall( dtype istype | istream( istype ) )
    11381138istype & ?|?( istype & is, _Istream_Manip(double _Complex) dc ) {
    11391139        double re, im;
     
    11461146} // ?|?
    11471147
    1148 forall( istype & | istream( istype ) )
     1148forall( dtype istype | istream( istype ) )
    11491149istype & ?|?( istype & is, _Istream_Manip(long double _Complex) ldc ) {
    11501150        long double re, im;
  • libcfa/src/iostream.hfa

    rc08c3cf r467c8b7  
    2222
    2323
    24 trait ostream( ostype & ) {
     24trait ostream( dtype ostype ) {
    2525        // private
    2626        bool $sepPrt( ostype & );                                                       // get separator state (on/off)
     
    5757}; // ostream
    5858
    59 // trait writeable( T ) {
    60 //      forall( ostype & | ostream( ostype ) ) ostype & ?|?( ostype &, T );
     59// trait writeable( otype T ) {
     60//      forall( dtype ostype | ostream( ostype ) ) ostype & ?|?( ostype &, T );
    6161// }; // writeable
    6262
    63 trait writeable( T, ostype & | ostream( ostype ) ) {
     63trait writeable( otype T, dtype ostype | ostream( ostype ) ) {
    6464        ostype & ?|?( ostype &, T );
    6565}; // writeable
     
    6767// implement writable for intrinsic types
    6868
    69 forall( ostype & | ostream( ostype ) ) {
     69forall( dtype ostype | ostream( ostype ) ) {
    7070        ostype & ?|?( ostype &, bool );
    7171        void ?|?( ostype &, bool );
     
    142142
    143143// tuples
    144 forall( ostype &, T, Params... | writeable( T, ostype ) | { ostype & ?|?( ostype &, Params ); } ) {
     144forall( dtype ostype, otype T, ttype Params | writeable( T, ostype ) | { ostype & ?|?( ostype &, Params ); } ) {
    145145        ostype & ?|?( ostype & os, T arg, Params rest );
    146146        void ?|?( ostype & os, T arg, Params rest );
     
    148148
    149149// writes the range [begin, end) to the given stream
    150 forall( ostype &, elt_type | writeable( elt_type, ostype ), iterator_type | iterator( iterator_type, elt_type ) ) {
     150forall( dtype ostype, otype elt_type | writeable( elt_type, ostype ), otype iterator_type | iterator( iterator_type, elt_type ) ) {
    151151        void write( iterator_type begin, iterator_type end, ostype & os );
    152152        void write_reverse( iterator_type begin, iterator_type end, ostype & os );
     
    155155// *********************************** manipulators ***********************************
    156156
    157 forall( T )
     157forall( otype T )
    158158struct _Ostream_Manip {
    159159        T val;                                                                                          // polymorphic base-type
     
    195195        _Ostream_Manip(T) & sign( _Ostream_Manip(T) & fmt ) { fmt.flags.sign = true; return fmt; } \
    196196} /* distribution */ \
    197 forall( ostype & | ostream( ostype ) ) { \
     197forall( dtype ostype | ostream( ostype ) ) { \
    198198        ostype & ?|?( ostype & os, _Ostream_Manip(T) f ); \
    199199        void ?|?( ostype & os, _Ostream_Manip(T) f ); \
     
    236236        _Ostream_Manip(T) & nodp( _Ostream_Manip(T) & fmt ) { fmt.flags.nobsdp = true; return fmt; } \
    237237} /* distribution */ \
    238 forall( ostype & | ostream( ostype ) ) { \
     238forall( dtype ostype | ostream( ostype ) ) { \
    239239        ostype & ?|?( ostype & os, _Ostream_Manip(T) f ); \
    240240        void ?|?( ostype & os, _Ostream_Manip(T) f ); \
     
    256256        _Ostream_Manip(char) & nobase( _Ostream_Manip(char) & fmt ) { fmt.flags.nobsdp = true; return fmt; }
    257257} // distribution
    258 forall( ostype & | ostream( ostype ) ) {
     258forall( dtype ostype | ostream( ostype ) ) {
    259259        ostype & ?|?( ostype & os, _Ostream_Manip(char) f );
    260260        void ?|?( ostype & os, _Ostream_Manip(char) f );
     
    274274        _Ostream_Manip(const char *) & nobase( _Ostream_Manip(const char *) & fmt ) { fmt.flags.nobsdp = true; return fmt; }
    275275} // distribution
    276 forall( ostype & | ostream( ostype ) ) {
     276forall( dtype ostype | ostream( ostype ) ) {
    277277        ostype & ?|?( ostype & os, _Ostream_Manip(const char *) f );
    278278        void ?|?( ostype & os, _Ostream_Manip(const char *) f );
     
    283283
    284284
    285 trait istream( istype & ) {
     285trait istream( dtype istype ) {
    286286        void nlOn( istype & );                                                          // read newline
    287287        void nlOff( istype & );                                                         // scan newline
     
    296296}; // istream
    297297
    298 trait readable( T ) {
    299         forall( istype & | istream( istype ) ) istype & ?|?( istype &, T );
     298trait readable( otype T ) {
     299        forall( dtype istype | istream( istype ) ) istype & ?|?( istype &, T );
    300300}; // readable
    301301
    302 forall( istype & | istream( istype ) ) {
     302forall( dtype istype | istream( istype ) ) {
    303303        istype & ?|?( istype &, bool & );
    304304
     
    365365        _Istream_Cstr & wdi( unsigned int w, _Istream_Cstr & fmt ) { fmt.wd = w; return fmt; }
    366366} // distribution
    367 forall( istype & | istream( istype ) ) istype & ?|?( istype & is, _Istream_Cstr f );
     367forall( dtype istype | istream( istype ) ) istype & ?|?( istype & is, _Istream_Cstr f );
    368368
    369369struct _Istream_Char {
     
    375375        _Istream_Char & ignore( _Istream_Char & fmt ) { fmt.ignore = true; return fmt; }
    376376} // distribution
    377 forall( istype & | istream( istype ) ) istype & ?|?( istype & is, _Istream_Char f );
    378 
    379 forall( T & | sized( T ) )
     377forall( dtype istype | istream( istype ) ) istype & ?|?( istype & is, _Istream_Char f );
     378
     379forall( dtype T | sized( T ) )
    380380struct _Istream_Manip {
    381381        T & val;                                                                                        // polymorphic base-type
     
    391391        _Istream_Manip(T) & wdi( unsigned int w, _Istream_Manip(T) & fmt ) { fmt.wd = w; return fmt; } \
    392392} /* distribution */ \
    393 forall( istype & | istream( istype ) ) { \
     393forall( dtype istype | istream( istype ) ) { \
    394394        istype & ?|?( istype & is, _Istream_Manip(T) f ); \
    395395} // ?|?
     
    420420#include <time_t.hfa>                                                                   // Duration (constructors) / Time (constructors)
    421421
    422 forall( ostype & | ostream( ostype ) ) {
     422forall( dtype ostype | ostream( ostype ) ) {
    423423        ostype & ?|?( ostype & os, Duration dur );
    424424        void ?|?( ostype & os, Duration dur );
  • libcfa/src/iterator.cfa

    rc08c3cf r467c8b7  
    1616#include "iterator.hfa"
    1717
    18 forall( iterator_type, elt_type | iterator( iterator_type, elt_type ) )
     18forall( otype iterator_type, otype elt_type | iterator( iterator_type, elt_type ) )
    1919void for_each( iterator_type begin, iterator_type end, void (* func)( elt_type ) ) {
    2020        for ( iterator_type i = begin; i != end; ++i ) {
     
    2323} // for_each
    2424
    25 forall( iterator_type, elt_type | iterator( iterator_type, elt_type ) )
     25forall( otype iterator_type, otype elt_type | iterator( iterator_type, elt_type ) )
    2626void for_each_reverse( iterator_type begin, iterator_type end, void (* func)( elt_type ) ) {
    2727        for ( iterator_type i = end; i != begin; ) {
  • libcfa/src/iterator.hfa

    rc08c3cf r467c8b7  
    1717
    1818// An iterator can be used to traverse a data structure.
    19 trait iterator( iterator_type, elt_type ) {
     19trait iterator( otype iterator_type, otype elt_type ) {
    2020        // point to the next element
    2121//      iterator_type ?++( iterator_type & );
     
    3131};
    3232
    33 trait iterator_for( iterator_type, collection_type, elt_type | iterator( iterator_type, elt_type ) ) {
     33trait iterator_for( otype iterator_type, otype collection_type, otype elt_type | iterator( iterator_type, elt_type ) ) {
    3434//      [ iterator_type begin, iterator_type end ] get_iterators( collection_type );
    3535        iterator_type begin( collection_type );
     
    3737};
    3838
    39 forall( iterator_type, elt_type | iterator( iterator_type, elt_type ) )
     39forall( otype iterator_type, otype elt_type | iterator( iterator_type, elt_type ) )
    4040void for_each( iterator_type begin, iterator_type end, void (* func)( elt_type ) );
    4141
    42 forall( iterator_type, elt_type | iterator( iterator_type, elt_type ) )
     42forall( otype iterator_type, otype elt_type | iterator( iterator_type, elt_type ) )
    4343void for_each_reverse( iterator_type begin, iterator_type end, void (* func)( elt_type ) );
    4444
  • libcfa/src/math.hfa

    rc08c3cf r467c8b7  
    286286        unsigned long long int floor( unsigned long long int n, unsigned long long int align ) { return n / align * align; }
    287287
    288         // forall( T | { T ?/?( T, T ); T ?*?( T, T ); } )
     288        // forall( otype T | { T ?/?( T, T ); T ?*?( T, T ); } )
    289289        // T floor( T n, T align ) { return n / align * align; }
    290290
     
    300300        unsigned long long int ceiling_div( unsigned long long int n, unsigned long long int align ) { return (n + (align - 1)) / align; }
    301301
    302         // forall( T | { T ?+?( T, T ); T ?-?( T, T ); T ?%?( T, T ); } )
     302        // forall( otype T | { T ?+?( T, T ); T ?-?( T, T ); T ?%?( T, T ); } )
    303303        // T ceiling_div( T n, T align ) { verify( is_pow2( align ) );return (n + (align - 1)) / align; }
    304304       
     
    315315        unsigned long long int ceiling( unsigned long long int n, unsigned long long int align ) { return floor( n + (n % align != 0 ? align - 1 : 0), align ); }
    316316
    317         // forall( T | { void ?{}( T &, one_t ); T ?+?( T, T ); T ?-?( T, T ); T ?/?( T, T ); } )
     317        // forall( otype T | { void ?{}( T &, one_t ); T ?+?( T, T ); T ?-?( T, T ); T ?/?( T, T ); } )
    318318        // T ceiling( T n, T align ) { return return floor( n + (n % align != 0 ? align - 1 : 0), align ); *}
    319319
     
    414414
    415415static inline {
    416         forall( T | { void ?{}( T &, one_t ); T ?+?( T, T ); T ?-?( T, T );T ?*?( T, T ); } )
     416        forall( otype T | { void ?{}( T &, one_t ); T ?+?( T, T ); T ?-?( T, T );T ?*?( T, T ); } )
    417417        T lerp( T x, T y, T a ) { return x * ((T){1} - a) + y * a; }
    418418
    419         forall( T | { void ?{}( T &, zero_t ); void ?{}( T &, one_t ); int ?<?( T, T ); } )
     419        forall( otype T | { void ?{}( T &, zero_t ); void ?{}( T &, one_t ); int ?<?( T, T ); } )
    420420        T step( T edge, T x ) { return x < edge ? (T){0} : (T){1}; }
    421421
    422         forall( T | { void ?{}( T &, int ); T clamp( T, T, T ); T ?-?( T, T ); T ?*?( T, T ); T ?/?( T, T ); } )
     422        forall( otype T | { void ?{}( T &, int ); T clamp( T, T, T ); T ?-?( T, T ); T ?*?( T, T ); T ?/?( T, T ); } )
    423423        T smoothstep( T edge0, T edge1, T x ) { T t = clamp( (x - edge0) / (edge1 - edge0), (T){0}, (T){1} ); return t * t * ((T){3} - (T){2} * t); }
    424424} // distribution
  • libcfa/src/memory.cfa

    rc08c3cf r467c8b7  
    1818
    1919// Internal data object.
    20 forall(T & | sized(T), Args... | { void ?{}(T &, Args); })
     20forall(dtype T | sized(T), ttype Args | { void ?{}(T &, Args); })
    2121void ?{}(counter_data(T) & this, Args args) {
    2222        (this.counter){1};
     
    2424}
    2525
    26 forall(T & | sized(T) | { void ^?{}(T &); })
     26forall(dtype T | sized(T) | { void ^?{}(T &); })
    2727void ^?{}(counter_data(T) & this) {
    2828        assert(0 == this.counter);
     
    3131
    3232// This is one of many pointers keeping this alive.
    33 forall(T & | sized(T))
     33forall(dtype T | sized(T))
    3434void ?{}(counter_ptr(T) & this) {
    3535        this.data = 0p;
    3636}
    3737
    38 forall(T & | sized(T))
     38forall(dtype T | sized(T))
    3939void ?{}(counter_ptr(T) & this, zero_t) {
    4040        this.data = 0p;
    4141}
    4242
    43 forall(T & | sized(T) | { void ^?{}(T &); })
     43forall(dtype T | sized(T) | { void ^?{}(T &); })
    4444static void internal_decrement(counter_ptr(T) & this) {
    4545        if (this.data && 0 == --this.data->counter) {
     
    4848}
    4949
    50 forall(T & | sized(T))
     50forall(dtype T | sized(T))
    5151static void internal_copy(counter_ptr(T) & this, counter_ptr(T) & that) {
    5252        this.data = that.data;
     
    5656}
    5757
    58 forall(T & | sized(T) | { void ^?{}(T &); })
     58forall(dtype T | sized(T) | { void ^?{}(T &); })
    5959void ?{}(counter_ptr(T) & this, counter_ptr(T) that) {
    6060        // `that` is a copy but it should have neither a constructor
     
    6464}
    6565
    66 forall(T & | sized(T), Args... | { void ?{}(T&, Args); })
     66forall(dtype T | sized(T), ttype Args | { void ?{}(T&, Args); })
    6767void ?{}(counter_ptr(T) & this, Args args) {
    6868        this.data = (counter_data(T)*)new(args);
    6969}
    7070
    71 forall(T & | sized(T) | { void ^?{}(T &); })
     71forall(dtype T | sized(T) | { void ^?{}(T &); })
    7272void ^?{}(counter_ptr(T) & this) {
    7373        internal_decrement(this);
    7474}
    7575
    76 forall(T & | sized(T))
     76forall(dtype T | sized(T))
    7777T & *?(counter_ptr(T) & this) {
    7878        return *((this.data) ? &this.data->object : 0p);
    7979}
    8080
    81 forall(T & | sized(T) | { void ^?{}(T &); })
     81forall(dtype T | sized(T) | { void ^?{}(T &); })
    8282void ?=?(counter_ptr(T) & this, counter_ptr(T) that) {
    8383        if (this.data != that.data) {
     
    8787}
    8888
    89 forall(T & | sized(T) | { void ^?{}(T &); })
     89forall(dtype T | sized(T) | { void ^?{}(T &); })
    9090void ?=?(counter_ptr(T) & this, zero_t) {
    9191        internal_decrement(this);
     
    9393}
    9494
    95 forall(T & | sized(T))
     95forall(dtype T | sized(T))
    9696int ?==?(counter_ptr(T) const & this, counter_ptr(T) const & that) {
    9797        return this.data == that.data;
    9898}
    9999
    100 forall(T & | sized(T))
     100forall(dtype T | sized(T))
    101101int ?!=?(counter_ptr(T) const & this, counter_ptr(T) const & that) {
    102102        return !?==?(this, that);
    103103}
    104104
    105 forall(T & | sized(T))
     105forall(dtype T | sized(T))
    106106int ?==?(counter_ptr(T) const & this, zero_t) {
    107107        return this.data == 0;
    108108}
    109109
    110 forall(T & | sized(T))
     110forall(dtype T | sized(T))
    111111int ?!=?(counter_ptr(T) const & this, zero_t) {
    112112        return !?==?(this, (zero_t)0);
     
    114114
    115115// This is the only pointer that keeps this alive.
    116 forall(T &)
     116forall(dtype T)
    117117void ?{}(unique_ptr(T) & this) {
    118118        this.data = 0p;
    119119}
    120120
    121 forall(T &)
     121forall(dtype T)
    122122void ?{}(unique_ptr(T) & this, zero_t) {
    123123        this.data = 0p;
    124124}
    125125
    126 forall(T & | sized(T), Args... | { void ?{}(T &, Args); })
     126forall(dtype T | sized(T), ttype Args | { void ?{}(T &, Args); })
    127127void ?{}(unique_ptr(T) & this, Args args) {
    128128        this.data = (T *)new(args);
    129129}
    130130
    131 forall(T & | { void ^?{}(T &); })
     131forall(dtype T | { void ^?{}(T &); })
    132132void ^?{}(unique_ptr(T) & this) {
    133133        delete(this.data);
    134134}
    135135
    136 forall(T &)
     136forall(dtype T)
    137137T & *?(unique_ptr(T) & this) {
    138138        return *this.data;
    139139}
    140140
    141 forall(T & | { void ^?{}(T &); })
     141forall(dtype T | { void ^?{}(T &); })
    142142void ?=?(unique_ptr(T) & this, zero_t) {
    143143        delete(this.data);
     
    145145}
    146146
    147 forall(T & | { void ^?{}(T &); })
     147forall(dtype T | { void ^?{}(T &); })
    148148void move(unique_ptr(T) & this, unique_ptr(T) & that) {
    149149        delete(this.data);
     
    152152}
    153153
    154 forall(T &)
     154forall(dtype T)
    155155int ?==?(unique_ptr(T) const & this, unique_ptr(T) const & that) {
    156156        return this.data == that.data;
    157157}
    158158
    159 forall(T &)
     159forall(dtype T)
    160160int ?!=?(unique_ptr(T) const & this, unique_ptr(T) const & that) {
    161161        return !?==?(this, that);
    162162}
    163163
    164 forall(T &)
     164forall(dtype T)
    165165int ?==?(unique_ptr(T) const & this, zero_t) {
    166166        return this.data == 0;
    167167}
    168168
    169 forall(T &)
     169forall(dtype T)
    170170int ?!=?(unique_ptr(T) const & this, zero_t) {
    171171        return !?==?(this, (zero_t)0);
  • libcfa/src/memory.hfa

    rc08c3cf r467c8b7  
    1717
    1818// Internal data object.
    19 forall(T & | sized(T)) {
     19forall(dtype T | sized(T)) {
    2020        struct counter_data {
    2121                unsigned int counter;
     
    2323        };
    2424
    25         forall(Args... | { void ?{}(T &, Args); })
     25        forall(ttype Args | { void ?{}(T &, Args); })
    2626        void ?{}(counter_data(T) & this, Args args);
    2727
     
    3131
    3232// This is one of many pointers keeping this alive.
    33 forall(T & | sized(T)) {
     33forall(dtype T | sized(T)) {
    3434        struct counter_ptr {
    3535                counter_data(T) * data;
     
    4040        forall( | { void ^?{}(T &); })
    4141        void ?{}(counter_ptr(T) & this, counter_ptr(T) that);
    42         forall(Args... | { void ?{}(T&, Args); })
     42        forall(ttype Args | { void ?{}(T&, Args); })
    4343        void ?{}(counter_ptr(T) & this, Args args);
    4444
     
    6060
    6161// This is the only pointer that keeps this alive.
    62 forall(T &) {
     62forall(dtype T) {
    6363        struct unique_ptr {
    6464                T * data;
     
    6868        void ?{}(unique_ptr(T) & this, zero_t);
    6969        void ?{}(unique_ptr(T) & this, unique_ptr(T) that) = void;
    70         forall( | sized(T), Args... | { void ?{}(T &, Args); })
     70        forall( | sized(T), ttype Args | { void ?{}(T &, Args); })
    7171        void ?{}(unique_ptr(T) & this, Args args);
    7272
  • libcfa/src/parseargs.hfa

    rc08c3cf r467c8b7  
    1414static inline void ?{}( cfa_option & this ) {}
    1515
    16 forall(T & | { bool parse(const char *, T & ); })
     16forall(dtype T | { bool parse(const char *, T & ); })
    1717static inline void ?{}( cfa_option & this, char short_name, const char * long_name, const char * help, T & variable ) {
    1818      this.val        = 0;
     
    2424}
    2525
    26 forall(T &)
     26forall(dtype T)
    2727static inline void ?{}( cfa_option & this, char short_name, const char * long_name, const char * help, T & variable, bool (*parse)(const char *, T & )) {
    2828      this.val        = 0;
  • libcfa/src/rational.cfa

    rc08c3cf r467c8b7  
    1818#include "stdlib.hfa"
    1919
    20 forall( RationalImpl | arithmetic( RationalImpl ) ) {
     20forall( otype RationalImpl | arithmetic( RationalImpl ) ) {
    2121        // helper routines
    2222
     
    159159        // I/O
    160160
    161         forall( istype & | istream( istype ) | { istype & ?|?( istype &, RationalImpl & ); } )
     161        forall( dtype istype | istream( istype ) | { istype & ?|?( istype &, RationalImpl & ); } )
    162162        istype & ?|?( istype & is, Rational(RationalImpl) & r ) {
    163163                is | r.numerator | r.denominator;
     
    168168        } // ?|?
    169169
    170         forall( ostype & | ostream( ostype ) | { ostype & ?|?( ostype &, RationalImpl ); } ) {
     170        forall( dtype ostype | ostream( ostype ) | { ostype & ?|?( ostype &, RationalImpl ); } ) {
    171171                ostype & ?|?( ostype & os, Rational(RationalImpl) r ) {
    172172                        return os | r.numerator | '/' | r.denominator;
     
    179179} // distribution
    180180
    181 forall( RationalImpl | arithmetic( RationalImpl ) | { RationalImpl ?\?( RationalImpl, unsigned long ); } )
     181forall( otype RationalImpl | arithmetic( RationalImpl ) | { RationalImpl ?\?( RationalImpl, unsigned long ); } )
    182182Rational(RationalImpl) ?\?( Rational(RationalImpl) x, long int y ) {
    183183        if ( y < 0 ) {
     
    190190// conversion
    191191
    192 forall( RationalImpl | arithmetic( RationalImpl ) | { double convert( RationalImpl ); } )
     192forall( otype RationalImpl | arithmetic( RationalImpl ) | { double convert( RationalImpl ); } )
    193193double widen( Rational(RationalImpl) r ) {
    194194        return convert( r.numerator ) / convert( r.denominator );
    195195} // widen
    196196
    197 forall( RationalImpl | arithmetic( RationalImpl ) | { double convert( RationalImpl ); RationalImpl convert( double ); } )
     197forall( otype RationalImpl | arithmetic( RationalImpl ) | { double convert( RationalImpl ); RationalImpl convert( double ); } )
    198198Rational(RationalImpl) narrow( double f, RationalImpl md ) {
    199199        // http://www.ics.uci.edu/~eppstein/numth/frap.c
  • libcfa/src/rational.hfa

    rc08c3cf r467c8b7  
    2020#include "iostream.hfa"
    2121
    22 trait scalar( T ) {
     22trait scalar( otype T ) {
    2323};
    2424
    25 trait arithmetic( T | scalar( T ) ) {
     25trait arithmetic( otype T | scalar( T ) ) {
    2626        int !?( T );
    2727        int ?==?( T, T );
     
    4646// implementation
    4747
    48 forall( RationalImpl | arithmetic( RationalImpl ) ) {
     48forall( otype RationalImpl | arithmetic( RationalImpl ) ) {
    4949        struct Rational {
    5050                RationalImpl numerator, denominator;                    // invariant: denominator > 0
     
    8989
    9090        // I/O
    91         forall( istype & | istream( istype ) | { istype & ?|?( istype &, RationalImpl & ); } )
     91        forall( dtype istype | istream( istype ) | { istype & ?|?( istype &, RationalImpl & ); } )
    9292        istype & ?|?( istype &, Rational(RationalImpl) & );
    9393
    94         forall( ostype & | ostream( ostype ) | { ostype & ?|?( ostype &, RationalImpl ); } ) {
     94        forall( dtype ostype | ostream( ostype ) | { ostype & ?|?( ostype &, RationalImpl ); } ) {
    9595                ostype & ?|?( ostype &, Rational(RationalImpl) );
    9696                void ?|?( ostype &, Rational(RationalImpl) );
     
    9898} // distribution
    9999
    100 forall( RationalImpl | arithmetic( RationalImpl ) |{RationalImpl ?\?( RationalImpl, unsigned long );} )
     100forall( otype RationalImpl | arithmetic( RationalImpl ) |{RationalImpl ?\?( RationalImpl, unsigned long );} )
    101101Rational(RationalImpl) ?\?( Rational(RationalImpl) x, long int y );
    102102
    103103// conversion
    104 forall( RationalImpl | arithmetic( RationalImpl ) | { double convert( RationalImpl ); } )
     104forall( otype RationalImpl | arithmetic( RationalImpl ) | { double convert( RationalImpl ); } )
    105105double widen( Rational(RationalImpl) r );
    106 forall( RationalImpl | arithmetic( RationalImpl ) | { double convert( RationalImpl );  RationalImpl convert( double );} )
     106forall( otype RationalImpl | arithmetic( RationalImpl ) | { double convert( RationalImpl );  RationalImpl convert( double );} )
    107107Rational(RationalImpl) narrow( double f, RationalImpl md );
    108108
  • libcfa/src/stdlib.cfa

    rc08c3cf r467c8b7  
    2828// Cforall allocation/deallocation and constructor/destructor, array types
    2929
    30 forall( T & | sized(T), TT... | { void ?{}( T &, TT ); } )
     30forall( dtype T | sized(T), ttype TT | { void ?{}( T &, TT ); } )
    3131T * anew( size_t dim, TT p ) {
    3232        T * arr = alloc( dim );
     
    3737} // anew
    3838
    39 forall( T & | sized(T) | { void ^?{}( T & ); } )
     39forall( dtype T | sized(T) | { void ^?{}( T & ); } )
    4040void adelete( T arr[] ) {
    4141        if ( arr ) {                                                                            // ignore null
     
    4848} // adelete
    4949
    50 forall( T & | sized(T) | { void ^?{}( T & ); }, TT... | { void adelete( TT ); } )
     50forall( dtype T | sized(T) | { void ^?{}( T & ); }, ttype TT | { void adelete( TT ); } )
    5151void adelete( T arr[], TT rest ) {
    5252        if ( arr ) {                                                                            // ignore null
     
    9797//---------------------------------------
    9898
    99 forall( E | { int ?<?( E, E ); } ) {
     99forall( otype E | { int ?<?( E, E ); } ) {
    100100        E * bsearch( E key, const E * vals, size_t dim ) {
    101101                int cmp( const void * t1, const void * t2 ) {
     
    156156
    157157
    158 forall( K, E | { int ?<?( K, K ); K getKey( const E & ); } ) {
     158forall( otype K, otype E | { int ?<?( K, K ); K getKey( const E & ); } ) {
    159159        E * bsearch( K key, const E * vals, size_t dim ) {
    160160                int cmp( const void * t1, const void * t2 ) {
  • libcfa/src/stdlib.hfa

    rc08c3cf r467c8b7  
    4848        else return (T *)alignment( _Alignof(T), dim, sizeof(T) )
    4949
    50 static inline forall( T & | sized(T) ) {
     50static inline forall( dtype T | sized(T) ) {
    5151        // CFA safe equivalents, i.e., implicit size specification
    5252
     
    108108
    109109        1. Replace the current forall-block that contains defintions of S_fill and S_realloc with following:
    110                 forall( T & | sized(T) ) {
     110                forall( dtype T | sized(T) ) {
    111111                        union  U_fill           { char c; T * a; T t; };
    112112                        struct S_fill           { char tag; U_fill(T) fill; };
     
    151151typedef struct S_resize                 { inline void *;  }     T_resize;
    152152
    153 forall( T & ) {
     153forall( dtype T ) {
    154154        struct S_fill           { char tag; char c; size_t size; T * at; char t[50]; };
    155155        struct S_realloc        { inline T *; };
     
    159159static inline T_resize  ?`resize  ( void * a )  { return (T_resize){a}; }
    160160
    161 static inline forall( T & | sized(T) ) {
     161static inline forall( dtype T | sized(T) ) {
    162162        S_fill(T) ?`fill ( T t ) {
    163163                S_fill(T) ret = { 't' };
     
    207207        } // $alloc_internal
    208208
    209         forall( TT... | { T * $alloc_internal( void *, T *, size_t, size_t, S_fill(T), TT ); } ) {
     209        forall( ttype TT | { T * $alloc_internal( void *, T *, size_t, size_t, S_fill(T), TT ); } ) {
    210210
    211211                T * $alloc_internal( void *       , T * Realloc, size_t Align, size_t Dim, S_fill(T) Fill, T_resize Resize, TT rest) {
     
    236236} // distribution T
    237237
    238 static inline forall( T & | sized(T) ) {
     238static inline forall( dtype T | sized(T) ) {
    239239        // CFA safe initialization/copy, i.e., implicit size specification, non-array types
    240240        T * memset( T * dest, char fill ) {
     
    257257
    258258// CFA deallocation for multiple objects
    259 static inline forall( T & )                                                     // FIX ME, problems with 0p in list
     259static inline forall( dtype T )                                                 // FIX ME, problems with 0p in list
    260260void free( T * ptr ) {
    261261        free( (void *)ptr );                                                            // C free
    262262} // free
    263 static inline forall( T &, TT... | { void free( TT ); } )
     263static inline forall( dtype T, ttype TT | { void free( TT ); } )
    264264void free( T * ptr, TT rest ) {
    265265        free( ptr );
     
    268268
    269269// CFA allocation/deallocation and constructor/destructor, non-array types
    270 static inline forall( T & | sized(T), TT... | { void ?{}( T &, TT ); } )
     270static inline forall( dtype T | sized(T), ttype TT | { void ?{}( T &, TT ); } )
    271271T * new( TT p ) {
    272272        return &(*(T *)malloc()){ p };                                          // run constructor
    273273} // new
    274274
    275 static inline forall( T & | { void ^?{}( T & ); } )
     275static inline forall( dtype T | { void ^?{}( T & ); } )
    276276void delete( T * ptr ) {
    277277        // special case for 0-sized object => always call destructor
     
    281281        free( ptr );                                                                            // always call free
    282282} // delete
    283 static inline forall( T &, TT... | { void ^?{}( T & ); void delete( TT ); } )
     283static inline forall( dtype T, ttype TT | { void ^?{}( T & ); void delete( TT ); } )
    284284void delete( T * ptr, TT rest ) {
    285285        delete( ptr );
     
    288288
    289289// CFA allocation/deallocation and constructor/destructor, array types
    290 forall( T & | sized(T), TT... | { void ?{}( T &, TT ); } ) T * anew( size_t dim, TT p );
    291 forall( T & | sized(T) | { void ^?{}( T & ); } ) void adelete( T arr[] );
    292 forall( T & | sized(T) | { void ^?{}( T & ); }, TT... | { void adelete( TT ); } ) void adelete( T arr[], TT rest );
     290forall( dtype T | sized(T), ttype TT | { void ?{}( T &, TT ); } ) T * anew( size_t dim, TT p );
     291forall( dtype T | sized(T) | { void ^?{}( T & ); } ) void adelete( T arr[] );
     292forall( dtype T | sized(T) | { void ^?{}( T & ); }, ttype TT | { void adelete( TT ); } ) void adelete( T arr[], TT rest );
    293293
    294294//---------------------------------------
     
    330330//---------------------------------------
    331331
    332 forall( E | { int ?<?( E, E ); } ) {
     332forall( otype E | { int ?<?( E, E ); } ) {
    333333        E * bsearch( E key, const E * vals, size_t dim );
    334334        size_t bsearch( E key, const E * vals, size_t dim );
     
    339339} // distribution
    340340
    341 forall( K, E | { int ?<?( K, K ); K getKey( const E & ); } ) {
     341forall( otype K, otype E | { int ?<?( K, K ); K getKey( const E & ); } ) {
    342342        E * bsearch( K key, const E * vals, size_t dim );
    343343        size_t bsearch( K key, const E * vals, size_t dim );
     
    348348} // distribution
    349349
    350 forall( E | { int ?<?( E, E ); } ) {
     350forall( otype E | { int ?<?( E, E ); } ) {
    351351        void qsort( E * vals, size_t dim );
    352352} // distribution
  • libcfa/src/time.cfa

    rc08c3cf r467c8b7  
    3131
    3232
    33 forall( ostype & | ostream( ostype ) ) {
     33forall( dtype ostype | ostream( ostype ) ) {
    3434        ostype & ?|?( ostype & os, Duration dur ) with( dur ) {
    3535                (ostype &)(os | tn / TIMEGRAN);                                 // print seconds
     
    136136} // strftime
    137137
    138 forall( ostype & | ostream( ostype ) ) {
     138forall( dtype ostype | ostream( ostype ) ) {
    139139        ostype & ?|?( ostype & os, Time time ) with( time ) {
    140140                char buf[32];                                                                   // at least 26
  • libcfa/src/vec/vec.hfa

    rc08c3cf r467c8b7  
    1818#include <math.hfa>
    1919
    20 trait fromint(T) {
     20trait fromint(otype T) {
    2121    void ?{}(T&, int);
    2222};
    23 trait zeroinit(T) {
     23trait zeroinit(otype T) {
    2424    void ?{}(T&, zero_t);
    2525};
    26 trait zero_assign(T) {
     26trait zero_assign(otype T) {
    2727    T ?=?(T&, zero_t);
    2828};
    29 trait subtract(T) {
     29trait subtract(otype T) {
    3030    T ?-?(T, T);
    3131};
    32 trait negate(T) {
     32trait negate(otype T) {
    3333    T -?(T);
    3434};
    35 trait add(T) {
     35trait add(otype T) {
    3636    T ?+?(T, T);
    3737};
    38 trait multiply(T) {
     38trait multiply(otype T) {
    3939    T ?*?(T, T);
    4040};
    41 trait divide(T) {
     41trait divide(otype T) {
    4242    T ?/?(T, T);
    4343};
    44 trait lessthan(T) {
     44trait lessthan(otype T) {
    4545    int ?<?(T, T);
    4646};
    47 trait equality(T) {
     47trait equality(otype T) {
    4848    int ?==?(T, T);
    4949};
    50 trait sqrt(T) {
     50trait sqrt(otype T) {
    5151    T sqrt(T);
    5252};
     
    6868}
    6969
    70 trait dottable(V, T) {
     70trait dottable(otype V, otype T) {
    7171    T dot(V, V);
    7272};
     
    7474static inline {
    7575
    76 forall(T | sqrt(T), V | dottable(V, T))
     76forall(otype T | sqrt(T), otype V | dottable(V, T))
    7777T length(V v) {
    7878   return sqrt(dot(v, v));
    7979}
    8080
    81 forall(T, V | dottable(V, T))
     81forall(otype T, otype V | dottable(V, T))
    8282T length_squared(V v) {
    8383   return dot(v, v);
    8484}
    8585
    86 forall(T, V | { T length(V); } | subtract(V))
     86forall(otype T, otype V | { T length(V); } | subtract(V))
    8787T distance(V v1, V v2) {
    8888    return length(v1 - v2);
    8989}
    9090
    91 forall(T, V | { T length(V); V ?/?(V, T); })
     91forall(otype T, otype V | { T length(V); V ?/?(V, T); })
    9292V normalize(V v) {
    9393    return v / length(v);
     
    9595
    9696// Project vector u onto vector v
    97 forall(T, V | dottable(V, T) | { V normalize(V); V ?*?(V, T); })
     97forall(otype T, otype V | dottable(V, T) | { V normalize(V); V ?*?(V, T); })
    9898V project(V u, V v) {
    9999    V v_norm = normalize(v);
     
    102102
    103103// Reflect incident vector v with respect to surface with normal n
    104 forall(T | fromint(T), V | { V project(V, V); V ?*?(T, V); V ?-?(V,V); })
     104forall(otype T | fromint(T), otype V | { V project(V, V); V ?*?(T, V); V ?-?(V,V); })
    105105V reflect(V v, V n) {
    106106    return v - (T){2} * project(v, n);
     
    111111// entering material (i.e., from air to water, eta = 1/1.33)
    112112// v and n must already be normalized
    113 forall(T | fromint(T) | subtract(T) | multiply(T) | add(T) | lessthan(T) | sqrt(T),
    114        V | dottable(V, T) | { V ?*?(T, V); V ?-?(V,V); void ?{}(V&, zero_t); })
     113forall(otype T | fromint(T) | subtract(T) | multiply(T) | add(T) | lessthan(T) | sqrt(T),
     114       otype V | dottable(V, T) | { V ?*?(T, V); V ?-?(V,V); void ?{}(V&, zero_t); })
    115115V refract(V v, V n, T eta) {
    116116    T dotValue = dot(n, v);
     
    128128// i is the incident vector
    129129// ng is the geometric normal of the surface
    130 forall(T | lessthan(T) | zeroinit(T), V | dottable(V, T) | negate(V))
     130forall(otype T | lessthan(T) | zeroinit(T), otype V | dottable(V, T) | negate(V))
    131131V faceforward(V n, V i, V ng) {
    132132    return dot(ng, i) < (T){0} ? n : -n;
  • libcfa/src/vec/vec2.hfa

    rc08c3cf r467c8b7  
    1919#include "vec.hfa"
    2020
    21 forall (T) {
     21forall (otype T) {
    2222    struct vec2 {
    2323        T x, y;
     
    2525}
    2626
    27 forall (T) {
     27forall (otype T) {
    2828    static inline {
    2929
     
    279279}
    280280
    281 forall(ostype &, T | writeable(T, ostype)) {
     281forall(dtype ostype, otype T | writeable(T, ostype)) {
    282282    ostype & ?|?(ostype & os, vec2(T) v) with (v) {
    283283        return os | '<' | x | ',' | y | '>';
  • libcfa/src/vec/vec3.hfa

    rc08c3cf r467c8b7  
    1919#include "vec.hfa"
    2020
    21 forall (T) {
     21forall (otype T) {
    2222    struct vec3 {
    2323        T x, y, z;
     
    2525}
    2626
    27 forall (T) {
     27forall (otype T) {
    2828    static inline {
    2929
     
    288288}
    289289
    290 forall(ostype &, T | writeable(T, ostype)) {
     290forall(dtype ostype, otype T | writeable(T, ostype)) {
    291291    ostype & ?|?(ostype & os, vec3(T) v) with (v) {
    292292        return os | '<' | x | ',' | y | ',' | z | '>';
  • libcfa/src/vec/vec4.hfa

    rc08c3cf r467c8b7  
    1919#include "vec.hfa"
    2020
    21 forall (T) {
     21forall (otype T) {
    2222    struct vec4 {
    2323        T x, y, z, w;
     
    2525}
    2626
    27 forall (T) {
     27forall (otype T) {
    2828    static inline {
    2929
     
    283283}
    284284
    285 forall(ostype &, T | writeable(T, ostype)) {
     285forall(dtype ostype, otype T | writeable(T, ostype)) {
    286286    ostype & ?|?(ostype & os, vec4(T) v) with (v) {
    287287        return os | '<' | x | ',' | y | ',' | z | ',' | w | '>';
  • src/Parser/parser.yy

    rc08c3cf r467c8b7  
    24412441type_parameter:                                                                                 // CFA
    24422442        type_class identifier_or_type_name
    2443                 {   typedefTable.addToScope( *$2, TYPEDEFname, "9" );
    2444                         if ( $1 == TypeDecl::Otype ) { SemanticError( yylloc, "otype keyword is deprecated" ); }
    2445                         if ( $1 == TypeDecl::Dtype ) { SemanticError( yylloc, "dtype keyword is deprecated" ); }
    2446                         if ( $1 == TypeDecl::Ttype ) { SemanticError( yylloc, "ttype keyword is deprecated" ); }
    2447                 }
     2443                { typedefTable.addToScope( *$2, TYPEDEFname, "9" ); }
    24482444          type_initializer_opt assertion_list_opt
    24492445                { $$ = DeclarationNode::newTypeParam( $1, $2 )->addTypeInitializer( $4 )->addAssertions( $5 ); }
  • tests/avltree/avl-private.cfa

    rc08c3cf r467c8b7  
    1111// an AVL tree's height is easy to compute
    1212// just follow path with the larger balance
    13 forall(K | Comparable(K), V)
     13forall(otype K | Comparable(K), otype V)
    1414int height(tree(K, V) * t){
    1515  int helper(tree(K, V) * t, int ht){
     
    2727}
    2828
    29 forall(K | Comparable(K), V)
     29forall(otype K | Comparable(K), otype V)
    3030int calcBalance(tree(K, V) * t){
    3131  int l = height(t->left);
     
    3636
    3737// re-establish the link between parent and child
    38 forall(K | Comparable(K), V)
     38forall(otype K | Comparable(K), otype V)
    3939void relinkToParent(tree(K, V) * t){
    4040  tree(K, V) * parent = t->parent; // FIX ME!!
     
    4949
    5050// rotate left from t
    51 forall(K | Comparable(K), V)
     51forall(otype K | Comparable(K), otype V)
    5252tree(K, V) * rotateLeft(tree(K, V) * t){
    5353  tree(K, V) * newRoot = t->right;
     
    6868
    6969// rotate right from t
    70 forall(K | Comparable(K), V)
     70forall(otype K | Comparable(K), otype V)
    7171tree(K, V) * rotateRight(tree(K, V) * t){
    7272  tree(K, V) * newRoot = t->left;
     
    8787
    8888// balances a node that has balance factor -2 or 2
    89 forall(K | Comparable(K), V)
     89forall(otype K | Comparable(K), otype V)
    9090tree(K, V) * fix(tree(K, V) * t){
    9191  // ensure that t's balance factor is one of
     
    113113
    114114// attempt to fix the tree, if necessary
    115 forall(K | Comparable(K), V)
     115forall(otype K | Comparable(K), otype V)
    116116tree(K, V) * tryFix(tree(K, V) * t){
    117117  int b = calcBalance(t);
     
    126126
    127127// sets parent field of c to be p
    128 forall(K | Comparable(K), V)
     128forall(otype K | Comparable(K), otype V)
    129129void setParent(tree(K, V) * c, tree(K, V) * p){
    130130  if (! empty(c)){
  • tests/avltree/avl-private.h

    rc08c3cf r467c8b7  
    55
    66// attempt to fix the tree, if necessary
    7 forall(K | Comparable(K), V)
     7forall(otype K | Comparable(K), otype V)
    88tree(K, V) * tryFix(tree(K, V) * t);
    99
    1010// sets parent field of c to be p
    11 forall(K | Comparable(K), V)
     11forall(otype K | Comparable(K), otype V)
    1212void setParent(tree(K, V) * c, tree(K, V) * p);
    1313
    14 forall(K | Comparable(K), V)
     14forall(otype K | Comparable(K), otype V)
    1515int height(tree(K, V) * t);
  • tests/avltree/avl.h

    rc08c3cf r467c8b7  
    99// #include <lib.h>
    1010
    11 trait Comparable(T) {
     11trait Comparable(otype T) {
    1212  int ?<?(T, T);
    1313};
    1414
    15 forall(T | Comparable(T))
     15forall(otype T | Comparable(T))
    1616int ?==?(T t1, T t2);
    1717
    18 forall(T | Comparable(T))
     18forall(otype T | Comparable(T))
    1919int ?>?(T t1, T t2);
    2020
     
    4141
    4242// temporary: need forward decl to get around typedef problem
    43 forall(K | Comparable(K), V)
     43forall(otype K | Comparable(K), otype V)
    4444struct tree;
    4545
    46 forall(K | Comparable(K), V)
     46forall(otype K | Comparable(K), otype V)
    4747struct tree {
    4848  K key;
     
    5454};
    5555
    56 forall(K | Comparable(K), V)
     56forall(otype K | Comparable(K), otype V)
    5757void ?{}(tree(K, V) &t, K key, V value);
    5858
    59 forall(K | Comparable(K), V)
     59forall(otype K | Comparable(K), otype V)
    6060void ^?{}(tree(K, V) & t);
    6161
    62 forall(K | Comparable(K), V)
     62forall(otype K | Comparable(K), otype V)
    6363tree(K, V) * create(K key, V value);
    6464
    65 forall(K | Comparable(K), V)
     65forall(otype K | Comparable(K), otype V)
    6666V * find(tree(K, V) * t, K key);
    6767
    68 forall(K | Comparable(K), V)
     68forall(otype K | Comparable(K), otype V)
    6969int empty(tree(K, V) * t);
    7070
    7171// returns the root of the tree
    72 forall(K | Comparable(K), V)
     72forall(otype K | Comparable(K), otype V)
    7373int insert(tree(K, V) ** t, K key, V value);
    7474
    75 forall(K | Comparable(K), V)
     75forall(otype K | Comparable(K), otype V)
    7676int remove(tree(K, V) ** t, K key);
    7777
    78 forall(K | Comparable(K), V)
     78forall(otype K | Comparable(K), otype V)
    7979void copy(tree(K, V) * src, tree(K, V) ** ret);
    8080
    81 forall(K | Comparable(K), V)
     81forall(otype K | Comparable(K), otype V)
    8282void for_each(tree(K, V) * t, void (*func)(V));
    8383
  • tests/avltree/avl0.cfa

    rc08c3cf r467c8b7  
    11#include "avl.h"
    22
    3 forall(T | Comparable(T))
     3forall(otype T | Comparable(T))
    44int ?==?(T t1, T t2) {
    55  return !(t1 < t2) && !(t2 < t1);
    66}
    77
    8 forall(T | Comparable(T))
     8forall(otype T | Comparable(T))
    99int ?>?(T t1, T t2) {
    1010  return t2 < t1;
  • tests/avltree/avl1.cfa

    rc08c3cf r467c8b7  
    33#include <stdlib.hfa>
    44
    5 forall(K | Comparable(K), V)
     5forall(otype K | Comparable(K), otype V)
    66void ?{}(tree(K, V) &t, K key, V value){
    77  (t.key) { key };
     
    1313}
    1414
    15 forall(K| Comparable(K), V)
     15forall(otype K| Comparable(K), otype V)
    1616void ^?{}(tree(K, V) & t){
    1717  delete(t.left);
     
    2121}
    2222
    23 forall(K | Comparable(K), V)
     23forall(otype K | Comparable(K), otype V)
    2424tree(K, V) * create(K key, V value) {
    2525  // infinite loop trying to resolve ... t = malloc();
  • tests/avltree/avl2.cfa

    rc08c3cf r467c8b7  
    22#include "avl-private.h"
    33
    4 forall(K | Comparable(K), V)
     4forall(otype K | Comparable(K), otype V)
    55V * find(tree(K, V) * t, K key){
    66  if (empty(t)){
     
    1818}
    1919
    20 forall(K | Comparable(K), V)
     20forall(otype K | Comparable(K), otype V)
    2121int empty(tree(K, V) * t){
    2222  return t == NULL;
     
    2424
    2525// returns the root of the tree
    26 forall(K | Comparable(K), V)
     26forall(otype K | Comparable(K), otype V)
    2727int insert(tree(K, V) ** t, K key, V value) {
    2828  // handles a non-empty tree
  • tests/avltree/avl3.cfa

    rc08c3cf r467c8b7  
    44
    55// swaps the data within two tree nodes
    6 forall(K | Comparable(K), V)
     6forall(otype K | Comparable(K), otype V)
    77void node_swap(tree(K, V) * t, tree(K, V) * t2){
    88        swap( t->key,  t2->key);
     
    1111
    1212// go left as deep as possible from within the right subtree
    13 forall(K | Comparable(K), V)
     13forall(otype K | Comparable(K), otype V)
    1414tree(K, V) * find_successor(tree(K, V) * t){
    1515        tree(K, V) * find_successor_helper(tree(K, V) * t){
     
    2525
    2626// cleanup - don't want to deep delete, so set children to NULL first.
    27 forall(K | Comparable(K), V)
     27forall(otype K | Comparable(K), otype V)
    2828void deleteSingleNode(tree(K, V) * t) {
    2929        t->left = NULL;
     
    3333
    3434// does the actual remove operation once we've found the node in question
    35 forall(K | Comparable(K), V)
     35forall(otype K | Comparable(K), otype V)
    3636tree(K, V) * remove_node(tree(K, V) * t){
    3737        // is the node a leaf?
     
    8585
    8686// finds the node that needs to be removed
    87 forall(K | Comparable(K), V)
     87forall(otype K | Comparable(K), otype V)
    8888tree(K, V) * remove_helper(tree(K, V) * t, K key, int * worked){
    8989        if (empty(t)){
     
    106106}
    107107
    108 forall(K | Comparable(K), V)
     108forall(otype K | Comparable(K), otype V)
    109109int remove(tree(K, V) ** t, K key){
    110110        int worked = 0;
  • tests/avltree/avl4.cfa

    rc08c3cf r467c8b7  
    44// Perform a shallow copy of src, return the
    55// new tree in ret
    6 forall(K | Comparable(K), V)
     6forall(otype K | Comparable(K), otype V)
    77int copy(tree(K, V) * src, tree(K, V) ** ret){
    88  tree(K, V) * helper(tree(K, V) * t, int * worked){
     
    3535
    3636// Apply func to every value element in t, using an in order traversal
    37 forall(K | Comparable(K), V)
     37forall(otype K | Comparable(K), otype V)
    3838void for_each(tree(K, V) * t, int (*func)(V)) {
    3939  if (t == NULL) {
  • tests/bugs/10.cfa

    rc08c3cf r467c8b7  
    22// https://cforall.uwaterloo.ca/trac/ticket/10
    33
    4 forall(T)
     4forall(otype T)
    55struct result {
    66      union {
  • tests/bugs/104.cfa

    rc08c3cf r467c8b7  
    44[ float, float ] modf_( float x );
    55
    6 forall(T | { [T, T] modf_(T); })
     6forall(otype T | { [T, T] modf_(T); })
    77void modf(T);
    88
  • tests/bugs/194.cfa

    rc08c3cf r467c8b7  
    22// https://cforall.uwaterloo.ca/trac/ticket/194
    33
    4 forall( T & | sized(T) ) T * foo( void ) {
     4forall( dtype T | sized(T) ) T * foo( void ) {
    55      printf( "foo1\n" );
    66        return (T *)0;
    77}
    8 forall( T & | sized(T) ) T & foo( void ) {
     8forall( dtype T | sized(T) ) T & foo( void ) {
    99        printf( "foo2\n" );
    1010        return (T &)*(T *)0;
  • tests/bugs/196.cfa

    rc08c3cf r467c8b7  
    22// https://cforall.uwaterloo.ca/trac/ticket/196
    33
    4 forall(T &)
     4forall(dtype T)
    55struct link;
    66
    7 forall(T &)
     7forall(dtype T)
    88struct link {
    99        link(T) * next;
     
    1212// -----
    1313
    14 forall(T &)
     14forall(dtype T)
    1515struct foo;
    1616
    17 forall(U &)
     17forall(dtype U)
    1818struct bar {
    1919        foo(U) * data;
    2020};
    2121
    22 forall(T &)
     22forall(dtype T)
    2323struct foo {};
    2424
  • tests/bugs/203-2.cfa

    rc08c3cf r467c8b7  
    11// Trac ticket: https://cforall.uwaterloo.ca/trac/ticket/203
    22
    3 forall(A &)
     3forall(dtype A)
    44struct empty {
    55        // Nothing.
    66};
    77
    8 forall(C &)
     8forall(dtype C)
    99struct wrap_e {
    1010        empty(C) field;
  • tests/bugs/203-7.cfa

    rc08c3cf r467c8b7  
    11// Trac ticket: https://cforall.uwaterloo.ca/trac/ticket/203
    22
    3 forall(A &)
     3forall(dtype A)
    44struct empty {
    55        // Nothing.
    66};
    77
    8 forall(C &)
     8forall(dtype C)
    99struct wrap_e {
    1010        empty(C) field;
  • tests/bugs/203-9.cfa

    rc08c3cf r467c8b7  
    11// Trac ticket: https://cforall.uwaterloo.ca/trac/ticket/203
    22
    3 forall(A &)
     3forall(dtype A)
    44struct empty {
    55        // Nothing.
    66};
    77
    8 forall(C &)
     8forall(dtype C)
    99struct wrap_e {
    1010        empty(C) field;
  • tests/bugs/7.cfa

    rc08c3cf r467c8b7  
    88
    99// (Bug 1 unresolved as of this test.)
    10 forall(T)
     10forall(otype T)
    1111struct stack_node;
    1212
    13 forall(T)
     13forall(otype T)
    1414struct stack_node {
    1515    stack_node(T) * next;
     
    1717};
    1818
    19 forall(T)
     19forall(otype T)
    2020struct stack {
    2121    stack_node(T) * head;
    2222};
    2323
    24 trait stack_errors(T) {
     24trait stack_errors(otype T) {
    2525    T emptyStackHandler (stack(T) * this);
    2626};
    2727
    28 forall(T | stack_errors(T))
     28forall(otype T | stack_errors(T))
    2929T pop (stack(T) * this) {
    3030    return (T){};
  • tests/castError.cfa

    rc08c3cf r467c8b7  
    1414//
    1515
    16 forall(T) struct S { T p; };
     16forall(otype T) struct S { T p; };
    1717int f;
    1818S(int) sint;
  • tests/concurrent/examples/boundedBufferEXT.cfa

    rc08c3cf r467c8b7  
    2424enum { BufferSize = 50 };
    2525
    26 forall( T ) {
     26forall( otype T ) {
    2727        monitor Buffer {
    2828                int front, back, count;
  • tests/concurrent/examples/boundedBufferINT.cfa

    rc08c3cf r467c8b7  
    2424enum { BufferSize = 50 };
    2525
    26 forall( T ) {
     26forall( otype T ) {
    2727        monitor Buffer {
    2828                condition full, empty;
  • tests/concurrent/examples/quickSort.generic.cfa

    rc08c3cf r467c8b7  
    2121#include <string.h>                                                                             // strcmp
    2222
    23 forall( T | { int ?<?( T, T ); } ) {
     23forall( otype T | { int ?<?( T, T ); } ) {
    2424        thread Quicksort {
    2525                T * values;                                                                             // communication variables
  • tests/concurrent/multi-monitor.cfa

    rc08c3cf r467c8b7  
    3838}
    3939
    40 forall(T & | sized(T) | { void ^?{}(T & mutex); })
     40forall(dtype T | sized(T) | { void ^?{}(T & mutex); })
    4141void delete_mutex(T * x) {
    4242        ^(*x){};
  • tests/concurrent/thread.cfa

    rc08c3cf r467c8b7  
    11#include <fstream.hfa>
    22#include <kernel.hfa>
    3 #include <locks.hfa>
    43#include <stdlib.hfa>
    54#include <thread.hfa>
  • tests/errors/completeType.cfa

    rc08c3cf r467c8b7  
    11void foo(int *) {}
    22void bar(void *) {}
    3 forall(T) void baz(T *);
    4 forall(T &) void qux(T *);
    5 forall(T & | sized(T)) void quux(T *);
     3forall(otype T) void baz(T *);
     4forall(dtype T) void qux(T *);
     5forall(dtype T | sized(T)) void quux(T *);
    66
    77struct A;       // incomplete
     
    3939
    4040
    41 forall(T)
     41forall(otype T)
    4242void baz(T * x) {
    4343        // okay
     
    4949}
    5050
    51 forall(T &)
     51forall(dtype T)
    5252void qux(T * y) {
    5353        // okay
     
    6161}
    6262
    63 forall(T & | sized(T))
     63forall(dtype T | sized(T))
    6464void quux(T * z) {
    6565        // okay
  • tests/exceptions/defaults.cfa

    rc08c3cf r467c8b7  
    5555
    5656void unhandled_test(void) {
    57         forall(T &, V & | is_exception(T, V))
     57        forall(dtype T, dtype V | is_exception(T, V))
    5858        void defaultTerminationHandler(T &) {
    5959                throw (unhandled_exception){};
  • tests/exceptions/polymorphic.cfa

    rc08c3cf r467c8b7  
    33#include <exception.hfa>
    44
    5 FORALL_TRIVIAL_EXCEPTION(proxy, (T), (T));
    6 FORALL_TRIVIAL_INSTANCE(proxy, (U), (U))
     5FORALL_TRIVIAL_EXCEPTION(proxy, (otype T), (T));
     6FORALL_TRIVIAL_INSTANCE(proxy, (otype U), (U))
    77
    88const char * msg(proxy(int) * this) { return "proxy(int)"; }
     
    3333}
    3434
    35 FORALL_DATA_EXCEPTION(cell, (T), (T))(
     35FORALL_DATA_EXCEPTION(cell, (otype T), (T))(
    3636        T data;
    3737);
    3838
    39 FORALL_DATA_INSTANCE(cell, (T), (T))
     39FORALL_DATA_INSTANCE(cell, (otype T), (T))
    4040
    4141const char * msg(cell(int) * this) { return "cell(int)"; }
  • tests/exceptions/virtual-poly.cfa

    rc08c3cf r467c8b7  
    1616};
    1717
    18 forall(T)
     18forall(otype T)
    1919struct mono_child_vtable {
    2020        mono_base_vtable const * const parent;
    2121};
    2222
    23 forall(T)
     23forall(otype T)
    2424struct mono_child {
    2525        mono_child_vtable(T) const * virtual_table;
     
    3737}
    3838
    39 forall(U)
     39forall(otype U)
    4040struct poly_base_vtable {
    4141        poly_base_vtable(U) const * const parent;
    4242};
    4343
    44 forall(U)
     44forall(otype U)
    4545struct poly_base {
    4646        poly_base_vtable(U) const * virtual_table;
    4747};
    4848
    49 forall(V)
     49forall(otype V)
    5050struct poly_child_vtable {
    5151        poly_base_vtable(V) const * const parent;
    5252};
    5353
    54 forall(V)
     54forall(otype V)
    5555struct poly_child {
    5656        poly_child_vtable(V) const * virtual_table;
  • tests/forall.cfa

    rc08c3cf r467c8b7  
    1515
    1616void g1() {
    17         forall( T ) T f( T ) {};
     17        forall( otype T ) T f( T ) {};
    1818        void f( int ) {};
    1919        void h( void (*p)(void) ) {};
     
    3232
    3333void g2() {
    34         forall( T ) void f( T, T ) {}
    35         forall( T, U ) void f( T, U ) {}
     34        forall( otype T ) void f( T, T ) {}
     35        forall( otype T, otype U ) void f( T, U ) {}
    3636
    3737        int x;
     
    4545}
    4646
    47 typedef forall ( T ) int (* f)( int );
    48 
    49 forall( T )
     47typedef forall ( otype T ) int (* f)( int );
     48
     49forall( otype T )
    5050void swap( T left, T right ) {
    5151        T temp = left;
     
    5454}
    5555
    56 trait sumable( T ) {
     56trait sumable( otype T ) {
    5757        void ?{}( T &, zero_t );                                                        // 0 literal constructor
    5858        T ?+?( T, T );                                                                          // assortment of additions
     
    6262}; // sumable
    6363
    64 forall( T | sumable( T ) )                                              // use trait
     64forall( otype T | sumable( T ) )                                                // use trait
    6565T sum( size_t size, T a[] ) {
    6666        T total = 0;                                                                            // initialize by 0 constructor
     
    7070} // sum
    7171
    72 forall( T | { T ?+?( T, T ); T ?++( T & ); [T] ?+=?( T &,T ); } )
     72forall( otype T | { T ?+?( T, T ); T ?++( T & ); [T] ?+=?( T &,T ); } )
    7373T twice( T t ) {
    7474        return t + t;
    7575}
    7676
    77 forall( T | { int ?<?(T, T); } )
     77forall( otype T | { int ?<?(T, T); } )
    7878T min( T t1, T t2 ) {
    7979        return t1 < t2 ? t1 : t2;
     
    9191
    9292// Multiple forall
    93 forall( T ) forall( S ) struct { int i; };
    94 forall( T ) struct { int i; } forall( S );
    95 struct { int i; } forall( T ) forall( S );
    96 forall( W ) struct { int i; } forall( T ) forall( S );
     93forall( otype T ) forall( otype S ) struct { int i; };
     94forall( otype T ) struct { int i; } forall( otype S );
     95struct { int i; } forall( otype T ) forall( otype S );
     96forall( otype W ) struct { int i; } forall( otype T ) forall( otype S );
    9797
    9898// Distribution
    9999struct P { int i; };
    100 forall( T ) struct Q { T i; };
    101 forall( T ) struct { int i; };
     100forall( otype T ) struct Q { T i; };
     101forall( otype T ) struct { int i; };
    102102struct KK { int i; };
    103103inline static {
    104104        void RT1() {}
    105105}
    106 forall( T ) {
     106forall( otype T ) {
    107107        T RT2( T ) {
    108108                typedef int TD1;
    109109                struct S1 { T t; };
    110110        }
    111         forall( X ) {
     111        forall( otype X ) {
    112112                typedef int TD2;
    113113                struct S2 {};
     
    117117        }
    118118        extern "C" {
    119                 forall( W ) {
     119                forall( otype W ) {
    120120                        W RT3( W ) {}
    121121                        struct S3 {};
     
    123123        }
    124124        void RT4() {
    125                 forall( W ) struct S4 {};
     125                forall( otype W ) struct S4 {};
    126126                typedef int TD3;
    127127        }
     
    147147
    148148static inline {
    149         forall( T ) {
     149        forall( otype T ) {
    150150                int RT6( T p );
    151151        }
    152         forall( T, U ) {
     152        forall( otype T, otype U ) {
    153153                int RT7( T, U );
    154154        }
    155155}
    156 static forall( T ) {
     156static forall( otype T ) {
    157157        int RT8( T );
    158158}
    159 forall( T ) inline static {
     159forall( otype T ) inline static {
    160160        int RT9( T ) { T t; return 3; }
    161161}
    162162
    163 forall( T | { T ?+?( T, T ); } ) {
    164         forall( S | { T ?+?( T, S ); } ) {
    165                 forall( W ) T bar( T t, S s ) { return t + s; }
    166                 forall( W | { W ?+?( T, W ); } ) W baz( T t, S s, W w ) { return t + s + w; }
     163forall( otype T | { T ?+?( T, T ); } ) {
     164        forall( otype S | { T ?+?( T, S ); } ) {
     165                forall( otype W ) T bar( T t, S s ) { return t + s; }
     166                forall( otype W | { W ?+?( T, W ); } ) W baz( T t, S s, W w ) { return t + s + w; }
    167167                struct W { T t; } (int,int) ww;
    168168                struct P pp;
     
    170170}
    171171
    172 forall( T | { T ?+?( T, T ); } ) forall( S | { T ?+?( T, S ); } )
     172forall( otype T | { T ?+?( T, T ); } ) forall( otype S | { T ?+?( T, S ); } )
    173173struct XW { T t; };
    174174XW(int,int) xww;
    175175
    176 forall( T ) struct S { T t; } (int) x, y, z;
    177 forall( T ) struct { T t; } (int) a, b, c;
    178 
    179 forall( T ) static forall( S ) {
    180     forall( X ) struct U {
     176forall( otype T ) struct S { T t; } (int) x, y, z;
     177forall( otype T ) struct { T t; } (int) a, b, c;
     178
     179forall( otype T ) static forall( otype S ) {
     180    forall( otype X ) struct U {
    181181                T x;
    182182    };
    183183}
    184184
    185 forall( T ) {
     185forall( otype T ) {
    186186        extern "C" {
    187187                struct SS { T t; };
  • tests/function-operator.cfa

    rc08c3cf r467c8b7  
    2222
    2323// STL-like Algorithms
    24 trait Assignable(T &, U &) { T ?=?(T &, U); };
    25 trait Copyable(T &) { void ?{}(T &, T); };
    26 trait Destructable(T &) { void ^?{}(T &); };
     24trait Assignable(dtype T, dtype U) { T ?=?(T &, U); };
     25trait Copyable(dtype T) { void ?{}(T &, T); };
     26trait Destructable(dtype T) { void ^?{}(T &); };
    2727
    28 trait Iterator(iter & | sized(iter) | Copyable(iter) | Destructable(iter), T) {
     28trait Iterator(dtype iter | sized(iter) | Copyable(iter) | Destructable(iter), otype T) {
    2929        T & *?(iter);
    3030        iter ++?(iter &);
     
    3232};
    3333
    34 forall(Tin, Input & | Iterator(Input, Tin), Tout, Output & | Iterator(Output, Tout) | Assignable(Tout, Tin))
     34forall(otype Tin, dtype Input | Iterator(Input, Tin), otype Tout, dtype Output | Iterator(Output, Tout) | Assignable(Tout, Tin))
    3535Output copy(Input first, Input last, Output result) {
    3636        while (first != last) {
     
    4242
    4343// test ?()(T *, ...) -- ?() with function call-by-pointer
    44 forall(Tin, Input & | Iterator(Input, Tin), Tout, Output & | Iterator(Output, Tout), FuncRet, Func & | { FuncRet ?()(Func *, Tin); } | Assignable(Tout, FuncRet))
     44forall(otype Tin, dtype Input | Iterator(Input, Tin), otype Tout, dtype Output | Iterator(Output, Tout), otype FuncRet, dtype Func | { FuncRet ?()(Func *, Tin); } | Assignable(Tout, FuncRet))
    4545Output transform (Input first, Input last, Output result, Func * op) {
    4646        while (first != last) {
     
    5252
    5353// test ?()(T, ...) -- ?() with function call-by-value
    54 forall(Iter &, T | Iterator(Iter, T), Pred | { int ?()(Pred, T); })
     54forall(dtype Iter, otype T | Iterator(Iter, T), otype Pred | { int ?()(Pred, T); })
    5555Iter find_if (Iter first, Iter last, Pred pred) {
    5656        while (first != last) {
     
    6262
    6363// test ?()(T, ...) -- ?() with function call-by-reference
    64 forall(Generator, GenRet | { GenRet ?()(Generator &); }, Iter &, T | Iterator(Iter, T) | Assignable(T, GenRet))
     64forall(otype Generator, otype GenRet | { GenRet ?()(Generator &); }, dtype Iter, otype T | Iterator(Iter, T) | Assignable(T, GenRet))
    6565void generate(Iter first, Iter last, Generator & gen) {
    6666        int i = 0;
     
    108108}
    109109
    110 forall(T | { int ?==?(T, T); })
     110forall(otype T | { int ?==?(T, T); })
    111111struct Equals {
    112112        T val;
    113113};
    114114
    115 forall(T | { int ?==?(T, T); })
     115forall(otype T | { int ?==?(T, T); })
    116116int ?()(Equals(T) eq, T x) {
    117117        return eq.val == x;
    118118}
    119119
    120 forall(T | { T ?*?(T, T); })
     120forall(otype T | { T ?*?(T, T); })
    121121struct Multiply {
    122122        T val;
    123123};
    124124
    125 forall(T | { T ?*?(T, T); })
     125forall(otype T | { T ?*?(T, T); })
    126126T ?()(Multiply(T) * mult, T x) {
    127127        return mult->val * x;
     
    130130// TODO: generalize to ttype return; doesn't work yet
    131131// like std::function
    132 forall(Return, Args...)
     132forall(otype Return, ttype Args)
    133133struct function {
    134134        Return (*f)(Args);
  • tests/genericUnion.cfa

    rc08c3cf r467c8b7  
    1616#include <limits.hfa>
    1717
    18 forall(T)
     18forall(otype T)
    1919union ByteView {
    2020        T val;
     
    2222};
    2323
    24 forall(T)
     24forall(otype T)
    2525void print(ByteView(T) x) {
    2626        for (int i = 0; i < sizeof(int); i++) {                         // want to change to sizeof(T)
     
    2929}
    3030
    31 forall(T)
     31forall(otype T)
    3232void f(ByteView(T) x, T val) {
    3333        print(x);
  • tests/global-monomorph.cfa

    rc08c3cf r467c8b7  
    11// Create monomorphic instances of polymorphic types at global scope.
    22
    3 forall(T &)
     3forall(dtype T)
    44void poly0(T &) {}
    55
    6 forall(T & | sized(T))
     6forall(dtype T | sized(T))
    77void poly1(T &) {}
    88
    9 forall(T)
     9forall(otype T)
    1010void poly2(T &) {}
    1111
  • tests/identity.cfa

    rc08c3cf r467c8b7  
    1616#include <fstream.hfa>
    1717
    18 forall( T )
     18forall( otype T )
    1919T identity( T t ) {
    2020        return t;
  • tests/init1.cfa

    rc08c3cf r467c8b7  
    120120}
    121121
    122 forall (T &, S &)
     122forall (dtype T, dtype S)
    123123T & anycvt( S & s ) {
    124124    return s;               // mismatched referenced type
    125125}
    126126
    127 forall (T &, S &)
     127forall (dtype T, dtype S)
    128128T * anycvt( S * s ) {
    129129    return s;               // mismatched referenced type
  • tests/nested-types.cfa

    rc08c3cf r467c8b7  
    1616typedef int N;
    1717struct A {
    18         forall(T)
     18        forall(otype T)
    1919        struct N {
    2020                T x;
  • tests/poly-d-cycle.cfa

    rc08c3cf r467c8b7  
    11// Check that a cycle of polymorphic dtype structures can be instancated.
    22
    3 forall(T &)
     3forall(dtype T)
    44struct func_table;
    55
    6 forall(U &)
     6forall(dtype U)
    77struct object {
    88        func_table(U) * virtual_table;
    99};
    1010
    11 forall(T &)
     11forall(dtype T)
    1212struct func_table {
    1313        void (*object_func)(object(T) *);
  • tests/poly-o-cycle.cfa

    rc08c3cf r467c8b7  
    11// Check that a cycle of polymorphic otype structures can be instancated.
    22
    3 forall(T)
     3forall(otype T)
    44struct func_table;
    55
    6 forall(U)
     6forall(otype U)
    77struct object {
    88        func_table(U) * virtual_table;
    99};
    1010
    11 forall(T)
     11forall(otype T)
    1212struct func_table {
    1313        void (*object_func)(object(T) *);
  • tests/poly-selection.cfa

    rc08c3cf r467c8b7  
    1616
    1717void testSpecializationFromGenericOverBareTyvar() {
    18     forall( T & )
     18    forall( dtype T )
    1919    void friend( T & ) {
    2020        printf("friending generically\n");
    2121    }
    2222
    23     forall(T &)
     23    forall(dtype T)
    2424    struct thing {
    2525        int x;
    2626    };
    2727
    28     forall( T & )
     28    forall( dtype T )
    2929    void friend( thing(T) & ) {
    3030        printf("friending specifically\n");
     
    3737void testSpecializationFromGenericAccessibleWithExtraTyvars() {
    3838
    39     forall( T &, U & )
     39    forall( dtype T, dtype U )
    4040    struct map {};
    4141
    42     forall( T & )
     42    forall( dtype T )
    4343    void f( T & ) {
    4444        printf("f-generic\n");
    4545    }
    4646
    47     forall( T & )
     47    forall( dtype T )
    4848    void f( map(T, T) & ) {
    4949        printf("f-specific\n");
  • tests/polymorphism.cfa

    rc08c3cf r467c8b7  
    1818#include <fstream.hfa>
    1919
    20 forall(T)
     20forall(otype T)
    2121T f(T x, T y) {
    2222        x = y;
     
    2424}
    2525
    26 forall(T) T ident(T x) {
     26forall(otype T) T ident(T x) {
    2727        return x;
    2828}
    2929
    30 forall( T, U )
     30forall( otype T, otype U )
    3131size_t struct_size( T i, U j ) {
    3232        struct S { T i; U j; };
     
    3434}
    3535
    36 forall( T, U )
     36forall( otype T, otype U )
    3737size_t union_size( T i, U j ) {
    3838        union B { T i; U j; };
     
    4141
    4242// perform some simple operations on aggregates of T and U
    43 forall( T | { void print(T); int ?==?(T, T); }, U | { void print(U); U ?=?(U&, zero_t); } )
     43forall( otype T | { void print(T); int ?==?(T, T); }, otype U | { void print(U); U ?=?(U&, zero_t); } )
    4444U foo(T i, U j) {
    4545        struct S { T i; U j; };
  • tests/raii/ctor-autogen.cfa

    rc08c3cf r467c8b7  
    3333
    3434// dtype-static generic type is otype
    35 forall(T &)
     35forall(dtype T)
    3636struct DtypeStaticStruct {
    3737  T * data;
     
    3939};
    4040
    41 forall(T &)
     41forall(dtype T)
    4242union DtypeStaticUnion {
    4343  T * data;
     
    4646
    4747// dynamic generic type is otype
    48 forall(T)
     48forall(otype T)
    4949struct DynamicStruct {
    5050        T x;
    5151};
    5252
    53 forall(T)
     53forall(otype T)
    5454union DynamicUnion {
    5555        T x;
     
    8080
    8181
    82 forall(T)
     82forall(otype T)
    8383T identity(T x) { return x; }
    8484
  • tests/simpleGenericTriple.cfa

    rc08c3cf r467c8b7  
    1414//
    1515
    16 forall(T)
     16forall(otype T)
    1717struct T3 {
    1818        T f0, f1, f2;
    1919};
    2020
    21 forall(T | { T ?+?(T, T); })
     21forall(otype T | { T ?+?(T, T); })
    2222T3(T) ?+?(T3(T) x, T3(T) y) {
    2323        T3(T) z = { x.f0+y.f0, x.f1+y.f1, x.f2+y.f2 };
  • tests/sum.cfa

    rc08c3cf r467c8b7  
    1818#include <stdlib.hfa>
    1919
    20 trait sumable( T ) {
     20trait sumable( otype T ) {
    2121        void ?{}( T &, zero_t );                                                        // 0 literal constructor
    2222        T ?+?( T, T );                                                                          // assortment of additions
     
    2626}; // sumable
    2727
    28 forall( T | sumable( T ) )                                              // use trait
     28forall( otype T | sumable( T ) )                                                // use trait
    2929T sum( size_t size, T a[] ) {
    3030        T total = 0;                                                                            // initialize by 0 constructor
     
    107107                 | sum( size, (S *)a ) | ", check" | (S)s;
    108108
    109         forall( Impl | sumable( Impl ) )
     109        forall( otype Impl | sumable( Impl ) )
    110110        struct GS {
    111111                Impl * x, * y;
     
    194194                 sum( size, (S *)a ).[i, j], s.[i, j] );
    195195
    196         forall( Impl | sumable( Impl ) )
     196        forall( otype Impl | sumable( Impl ) )
    197197        struct GS {
    198198                Impl * x, * y;
  • tests/tuple/tuplePolymorphism.cfa

    rc08c3cf r467c8b7  
    2929// ensure that f is a viable candidate for g, even though its parameter structure does not exactly match
    3030[A] f([A, B] x, B y) { printf("%g %c %g %lld %c %lld %lld %c %lld\n", x.0.[x,y,z], x.1.[x,y,z], y.[x,y,z]); return x.0; }
    31 forall(T, U | { T f(T, U, U); })
     31forall(otype T, otype U | { T f(T, U, U); })
    3232void g(T x, U y) { f(x, y, y); }
    3333
    3434// add two triples
    35 forall(T | { T ?+?(T, T); })
     35forall(otype T | { T ?+?(T, T); })
    3636[T, T, T] ?+?([T, T, T] x, [T, T, T] y) {
    3737        return [x.0+y.0, x.1+y.1, x.2+y.2];
     
    6464}
    6565
    66 forall(T)
     66forall(otype T)
    6767[T, T] foo([T, T] y) {
    6868        [T, T] x;
  • tests/tuple/tupleVariadic.cfa

    rc08c3cf r467c8b7  
    1919        printf("called func(void)\n");
    2020}
    21 forall(T, Params... | { void process(T); void func(Params); })
     21forall(otype T, ttype Params | { void process(T); void func(Params); })
    2222void func(T arg1, Params p) {
    2323        process(arg1);
     
    9292}
    9393
    94 forall(T)
     94forall(otype T)
    9595T * copy(T x) {
    9696        // test calling new inside a polymorphic function
     
    9898}
    9999
    100 forall(T... | { void foo(T); }) void bar(T x) {}
     100forall(ttype T | { void foo(T); }) void bar(T x) {}
    101101void foo(int) {}
    102102
  • tests/zombies/ArrayN.c

    rc08c3cf r467c8b7  
    66// }
    77
    8 forall(index_t)
     8forall(otype index_t)
    99index_t offset_to_index(unsigned offset, index_t size) {
    1010    return [offset / size.0, offset % size.1];
  • tests/zombies/Members.c

    rc08c3cf r467c8b7  
    22int ?=?( int*, int );
    33float ?=?( float*, float );
    4 forall( DT & ) DT * ?=?( DT**, DT* );
    5 forall(T) lvalue T *?( T* );
     4forall( dtype DT ) DT * ?=?( DT**, DT* );
     5forall(otype T) lvalue T *?( T* );
    66char *__builtin_memcpy();
    77
  • tests/zombies/Rank2.c

    rc08c3cf r467c8b7  
    11int ?=?( int &, int );
    2 forall(DT &) DT * ?=?( DT *&, DT * );
     2forall(dtype DT) DT * ?=?( DT *&, DT * );
    33
    44void a() {
    5         forall( T ) void f( T );
    6         void g( forall( U ) void p( U ) );
     5        forall( otype T ) void f( T );
     6        void g( forall( otype U ) void p( U ) );
    77        g( f );
    88}
     
    1010void g() {
    1111        void h( int *null );
    12         forall( T ) T id( T );
     12        forall( otype T ) T id( T );
    1313//      forall( dtype T ) T *0;
    1414//      int 0;
  • tests/zombies/abstype.c

    rc08c3cf r467c8b7  
    2121}
    2222
    23 forall( T ) T *?( T * );
     23forall( otype T ) T *?( T * );
    2424int ?++( int * );
    2525int ?=?( int *, int );
    26 forall( DT & ) DT * ?=?( DT **, DT * );
     26forall( dtype DT ) DT * ?=?( DT **, DT * );
    2727
    2828otype U = int *;
  • tests/zombies/context.cfa

    rc08c3cf r467c8b7  
    11// trait declaration
    22
    3 trait has_q( T ) {
     3trait has_q( otype T ) {
    44        T q( T );
    55};
    66
    7 forall( z | has_q( z ) ) void f() {
    8         trait has_r( T, U ) {
     7forall( otype z | has_q( z ) ) void f() {
     8        trait has_r( otype T, otype U ) {
    99                T r( T, T (T,U) );
    1010        };
  • tests/zombies/gc_no_raii/bug-repro/blockers/explicit_cast.c

    rc08c3cf r467c8b7  
    99};
    1010
    11 forall(T)
     11forall(otype T)
    1212struct gcpointer
    1313{
     
    1515};
    1616
    17 forall(T)
     17forall(otype T)
    1818static inline gcpointer(T) gcmalloc()
    1919{
  • tests/zombies/gc_no_raii/bug-repro/blockers/recursive_realloc.c

    rc08c3cf r467c8b7  
    33#include <stdlib.hfa>
    44
    5 trait allocator_c(T, allocator_t)
     5trait allocator_c(otype T, otype allocator_t)
    66{
    77        void realloc(allocator_t* const, size_t);
    88};
    99
    10 forall(T)
     10forall(otype T)
    1111struct heap_allocator
    1212{
     
    1515};
    1616
    17 forall(T)
     17forall(otype T)
    1818inline void realloc(heap_allocator(T) *const this, size_t size)
    1919{
  • tests/zombies/gc_no_raii/bug-repro/deref.c

    rc08c3cf r467c8b7  
    1     forall(T)
     1    forall(otype T)
    22    struct wrap
    33    {
     
    55    };
    66
    7     forall(T)
     7    forall(otype T)
    88    T *? (wrap(T) rhs)
    99    {
  • tests/zombies/gc_no_raii/bug-repro/field.c

    rc08c3cf r467c8b7  
    88//------------------------------------------------------------------------------
    99//Declaration
    10 trait allocator_c(T, allocator_t)
     10trait allocator_c(otype T, otype allocator_t)
    1111{
    1212        void ctor(allocator_t* const);
     
    1616};
    1717
    18 forall(T, allocator_t | allocator_c(T, allocator_t))
     18forall(otype T, otype allocator_t | allocator_c(T, allocator_t))
    1919struct vector
    2020{
  • tests/zombies/gc_no_raii/bug-repro/malloc.c

    rc08c3cf r467c8b7  
    1 forall(T)
     1forall(otype T)
    22struct wrapper
    33{
     
    55};
    66
    7 forall(T)
     7forall(otype T)
    88void ctor(wrapper(T)* this)
    99{
     
    1111}
    1212
    13 forall(T)
     13forall(otype T)
    1414wrapper(T) gcmalloc()
    1515{
     
    1919}
    2020
    21 forall(T)
     21forall(otype T)
    2222wrapper(T)* ?=? (wrapper(T)* lhs, wrapper(T)* rhs)
    2323{
  • tests/zombies/gc_no_raii/bug-repro/oddtype.c

    rc08c3cf r467c8b7  
    1 forall(T &)
     1forall(dtype T)
    22struct wrap {
    33        int i;
    44};
    55
    6 forall(T) void ?{}(wrap(T)* this) {}
    7 forall(T) void ?=?(wrap(T)* this) {}
    8 forall(T) void ^?{}(wrap(T)* this) {}
     6forall(otype T) void ?{}(wrap(T)* this) {}
     7forall(otype T) void ?=?(wrap(T)* this) {}
     8forall(otype T) void ^?{}(wrap(T)* this) {}
    99
    1010struct List_t {
  • tests/zombies/gc_no_raii/bug-repro/push_back.h

    rc08c3cf r467c8b7  
    11//------------------------------------------------------------------------------
    22//Declaration
    3 trait allocator_c(T, allocator_t) {
     3trait allocator_c(otype T, otype allocator_t) {
    44        void ctor(allocator_t* const);
    55        void dtor(allocator_t* const);
     
    88};
    99
    10 forall(T, allocator_t | allocator_c(T, allocator_t))
     10forall(otype T, otype allocator_t | allocator_c(T, allocator_t))
    1111struct vector
    1212{
     
    1717//------------------------------------------------------------------------------
    1818//Initialization
    19 forall(T, allocator_t | allocator_c(T, allocator_t))
     19forall(otype T, otype allocator_t | allocator_c(T, allocator_t))
    2020void vector_ctor(vector(T, allocator_t) *const this);
    2121
    22 forall(T, allocator_t | allocator_c(T, allocator_t))
     22forall(otype T, otype allocator_t | allocator_c(T, allocator_t))
    2323void dtor(vector(T, allocator_t) *const this);
    2424
    2525//------------------------------------------------------------------------------
    2626//Allocator
    27 forall(T)
     27forall(otype T)
    2828struct heap_allocator
    2929{
     
    3232};
    3333
    34 forall(T)
     34forall(otype T)
    3535void ctor(heap_allocator(T) *const this);
    3636
    37 forall(T)
     37forall(otype T)
    3838void dtor(heap_allocator(T) *const this);
    3939
    40 forall(T)
     40forall(otype T)
    4141void realloc(heap_allocator(T) *const this, size_t size);
    4242
    43 forall(T)
     43forall(otype T)
    4444inline T* data(heap_allocator(T) *const this)
    4545{
     
    4949//------------------------------------------------------------------------------
    5050//Capacity
    51 forall(T, allocator_t | allocator_c(T, allocator_t))
     51forall(otype T, otype allocator_t | allocator_c(T, allocator_t))
    5252inline bool empty(vector(T, allocator_t) *const this)
    5353{
     
    5555}
    5656
    57 forall(T, allocator_t | allocator_c(T, allocator_t))
     57forall(otype T, otype allocator_t | allocator_c(T, allocator_t))
    5858inline bool size(vector(T, allocator_t) *const this)
    5959{
     
    6161}
    6262
    63 forall(T, allocator_t | allocator_c(T, allocator_t))
     63forall(otype T, otype allocator_t | allocator_c(T, allocator_t))
    6464inline void reserve(vector(T, allocator_t) *const this, size_t size)
    6565{
     
    6969//------------------------------------------------------------------------------
    7070//Modifiers
    71 forall(T, allocator_t | allocator_c(T, allocator_t))
     71forall(otype T, otype allocator_t | allocator_c(T, allocator_t))
    7272void push_back(vector(T, allocator_t) *const this, T value);
  • tests/zombies/gc_no_raii/bug-repro/realloc.c

    rc08c3cf r467c8b7  
    11void* realloc(void*, unsigned long int);
    22
    3 forall(T)
     3forall(otype T)
    44struct wrap
    55{
     
    77};
    88
    9 forall(T)
     9forall(otype T)
    1010static inline void realloc(wrap(T) *const this, unsigned long int size)
    1111{
  • tests/zombies/gc_no_raii/bug-repro/return.c

    rc08c3cf r467c8b7  
    1 forall(T)
     1forall(otype T)
    22struct wrapper
    33{
     
    55};
    66
    7 forall(T)
     7forall(otype T)
    88wrapper(T) create()
    99{
     
    1212}
    1313
    14 forall(T)
     14forall(otype T)
    1515wrapper(T)* ?=?(wrapper(T)* lhs, wrapper(T)* rhs)
    1616{
  • tests/zombies/gc_no_raii/bug-repro/return_template.c

    rc08c3cf r467c8b7  
    1 forall(T)
     1forall(otype T)
    22struct wrap
    33{
     
    55};
    66
    7 forall(T) void ?{}(wrap(T)* this);
    8 forall(T) void ?{}(wrap(T)* this, wrap(T)* rhs);
    9 forall(T) void ^?{}(wrap(T)* this);
    10 forall(T) void ?=?(wrap(T)* this, wrap(T)* rhs);
     7forall(otype T) void ?{}(wrap(T)* this);
     8forall(otype T) void ?{}(wrap(T)* this, wrap(T)* rhs);
     9forall(otype T) void ^?{}(wrap(T)* this);
     10forall(otype T) void ?=?(wrap(T)* this, wrap(T)* rhs);
    1111
    12 forall(T)
     12forall(otype T)
    1313wrap(T) test()
    1414{
  • tests/zombies/gc_no_raii/bug-repro/slow_malloc.c

    rc08c3cf r467c8b7  
    11#include <stdlib.hfa>
    22
    3 forall(T)
     3forall(otype T)
    44struct heap_allocator
    55{
  • tests/zombies/gc_no_raii/bug-repro/zero.c

    rc08c3cf r467c8b7  
    1 forall(T)
     1forall(otype T)
    22struct wrap
    33{
     
    55};
    66
    7 forall(T)
     7forall(otype T)
    88int ?==? (wrap(T) lhs, wrap(T) rhs)
    99{
     
    1414struct wrap(int) 0;
    1515/*/
    16 forall(T)
     16forall(otype T)
    1717struct wrap(T) 0;
    1818//*/
  • tests/zombies/gc_no_raii/src/gc.h

    rc08c3cf r467c8b7  
    1313// }
    1414
    15 forall(T)
     15forall(otype T)
    1616static inline void gcmalloc(gcpointer(T)* ptr)
    1717{
  • tests/zombies/gc_no_raii/src/gcpointers.c

    rc08c3cf r467c8b7  
    113113#endif
    114114
    115 forall(T) void ?{}(gcpointer(T)* this) {
     115forall(otype T) void ?{}(gcpointer(T)* this) {
    116116        (&this->internal) {};
    117117}
    118118
    119 forall(T) void ?{}(gcpointer(T)* this, void* address) {
     119forall(otype T) void ?{}(gcpointer(T)* this, void* address) {
    120120        (&this->internal) { address };
    121121}
    122122
    123 forall(T) void ?{}(gcpointer(T)* this, gcpointer(T) other) {
     123forall(otype T) void ?{}(gcpointer(T)* this, gcpointer(T) other) {
    124124        (&this->internal) { other.internal };
    125125}
    126126
    127 forall(T) void ^?{}(gcpointer(T)* this) {
     127forall(otype T) void ^?{}(gcpointer(T)* this) {
    128128        ^?{}(&this->internal);
    129129}
    130130
    131 forall(T) gcpointer(T) ?=?(gcpointer(T)* this, gcpointer(T) rhs) {
     131forall(otype T) gcpointer(T) ?=?(gcpointer(T)* this, gcpointer(T) rhs) {
    132132        this->internal = rhs.internal;
    133133        return *this;
     
    136136// forall(otype T) T *?(gcpointer(T) this);
    137137
    138 forall(T) T* get(gcpointer(T)* this) {
     138forall(otype T) T* get(gcpointer(T)* this) {
    139139        return (T*)this->internal.ptr;
    140140}
    141141//
    142142// //Logical operators
    143 forall(T) int ?!=?(gcpointer(T) this, int zero) {
     143forall(otype T) int ?!=?(gcpointer(T) this, int zero) {
    144144        return this.internal.ptr != 0;
    145145}
  • tests/zombies/gc_no_raii/src/gcpointers.h

    rc08c3cf r467c8b7  
    44#include <stdint.h>
    55
    6 forall(T &)
     6forall(dtype T)
    77struct gcpointer;
    88
     
    2929#endif
    3030
    31 forall(T &)
     31forall(dtype T)
    3232struct gcpointer
    3333{
     
    3636
    3737//
    38 forall(T) void ?{}(gcpointer(T)* this);
    39 forall(T) void ?{}(gcpointer(T)* this, void* address);
    40 forall(T) void ?{}(gcpointer(T)* this, gcpointer(T) other);
    41 forall(T) void ^?{}(gcpointer(T)* this);
    42 forall(T) gcpointer(T) ?=?(gcpointer(T)* this, gcpointer(T) rhs);
     38forall(otype T) void ?{}(gcpointer(T)* this);
     39forall(otype T) void ?{}(gcpointer(T)* this, void* address);
     40forall(otype T) void ?{}(gcpointer(T)* this, gcpointer(T) other);
     41forall(otype T) void ^?{}(gcpointer(T)* this);
     42forall(otype T) gcpointer(T) ?=?(gcpointer(T)* this, gcpointer(T) rhs);
    4343
    4444
    4545// forall(otype T) T *?(gcpointer(T) this);
    46 forall(T) T* get(gcpointer(T)* this);
     46forall(otype T) T* get(gcpointer(T)* this);
    4747
    4848//Logical operators
    49 forall(T) int ?!=?(gcpointer(T) this, int zero);
    50 forall(T) int ?!=?(gcpointer(T) this, gcpointer(T) rhs);
    51 forall(T) int ?==?(gcpointer(T) this, gcpointer(T) rhs);
     49forall(otype T) int ?!=?(gcpointer(T) this, int zero);
     50forall(otype T) int ?!=?(gcpointer(T) this, gcpointer(T) rhs);
     51forall(otype T) int ?==?(gcpointer(T) this, gcpointer(T) rhs);
  • tests/zombies/gc_no_raii/src/tools.h

    rc08c3cf r467c8b7  
    1212// }
    1313
    14 trait has_equal(T)
     14trait has_equal(otype T)
    1515{
    1616        signed int ?==?(T a, T b);
    1717};
    1818
    19 trait InputIterator_t(T, InputIterator)
     19trait InputIterator_t(otype T, otype InputIterator)
    2020{
    2121        signed int ?==?(InputIterator a, InputIterator b);
     
    2626};
    2727
    28 forall(T | has_equal(T), InputIterator | InputIterator_t(T, InputIterator))
     28forall(otype T | has_equal(T), otype InputIterator | InputIterator_t(T, InputIterator))
    2929static inline InputIterator find( InputIterator first, const InputIterator* const last, T val)
    3030{
  • tests/zombies/hashtable.cfa

    rc08c3cf r467c8b7  
    1414
    1515
    16 trait has_hash( K ) {
     16trait has_hash( otype K ) {
    1717    size_t hash(K);
    1818    int ?==?( K, K );
    1919};
    2020
    21 trait hkey( K, tN & | has_hash(K) ) {
     21trait hkey( otype K, dtype tN | has_hash(K) ) {
    2222    K key(tN &);
    2323};
    2424
    25 forall( K, tN &, tE & | $dlistable(tN, tE) | hkey(K, tN) ) {
     25forall( otype K, dtype tN, dtype tE | $dlistable(tN, tE) | hkey(K, tN) ) {
    2626
    2727    struct hashtable {
     
    3939}
    4040
    41 forall( K, tN &, tE & | $dlistable(tN, tE) | hkey(K, tN) | { void defaultResumptionHandler(ht_fill_limit_crossed &); } ) {
     41forall( otype K, dtype tN, dtype tE | $dlistable(tN, tE) | hkey(K, tN) | { void defaultResumptionHandler(ht_fill_limit_crossed &); } ) {
    4242
    4343    void ?{}( hashtable(K, tN, tE) & this, size_t n_buckets, dlist(tN, tE) *buckets ) {
     
    5757}
    5858
    59 forall( K, tN &, tE & | $dlistable(tN, tE) | hkey(K, tN) ) {
     59forall( otype K, dtype tN, dtype tE | $dlistable(tN, tE) | hkey(K, tN) ) {
    6060
    6161    float fill_frac( hashtable(K, tN, tE) & this ) with(this) {
     
    124124
    125125
    126 trait heaped(T &) {
     126trait heaped(dtype T) {
    127127    T * alloc( size_t );
    128128    void free( void * );
     
    133133}
    134134
    135 forall( K, tN &, tE & | $dlistable(tN, tE) | hkey(K, tN) | heaped( dlist(tN, tE) ) ) {
     135forall( otype K, dtype tN, dtype tE | $dlistable(tN, tE) | hkey(K, tN) | heaped( dlist(tN, tE) ) ) {
    136136
    137137    struct hashtable_dynamic {
  • tests/zombies/hashtable2.cfa

    rc08c3cf r467c8b7  
    6969
    7070
    71 trait pretendsToMatter( TTT & ) {
     71trait pretendsToMatter( dtype TTT ) {
    7272    void actsmart(TTT &);
    7373};
    7474
    75 forall( TTTx & )
     75forall( dtype TTTx )
    7676void actsmart(TTTx &) {}
    7777
     
    8686//   2. shows up in -CFA output as hashtable_rbs(), which is bad C; expecting hashtable_rbs*
    8787
    88 forall( Tt_unused | pretendsToMatter(Tt_unused) ) {
     88forall( otype Tt_unused | pretendsToMatter(Tt_unused) ) {
    8989
    9090    // hashtable of request by source
     
    104104}
    105105
    106 forall( Tt_unused | pretendsToMatter(Tt_unused) | { void defaultResumptionHandler(ht_fill_limit_crossed &); } ) {
     106forall( otype Tt_unused | pretendsToMatter(Tt_unused) | { void defaultResumptionHandler(ht_fill_limit_crossed &); } ) {
    107107
    108108    void ?{}( hashtable_rbs(Tt_unused) & this, size_t n_buckets, dlist(request_in_ht_by_src, request) *buckets,
     
    135135void defaultResumptionHandler( ht_auto_resize_pending & ex );
    136136
    137 forall( Tt_unused | pretendsToMatter(Tt_unused) ) {
     137forall( otype Tt_unused | pretendsToMatter(Tt_unused) ) {
    138138
    139139    float fill_frac( hashtable_rbs(Tt_unused) & this ) with(this) {
     
    221221
    222222
    223 trait heaped(T &) {
     223trait heaped(dtype T) {
    224224    T * alloc( size_t );
    225225    void free( void * );
     
    228228void __dynamic_defaultResumptionHandler(ht_fill_limit_crossed &);
    229229
    230 forall( Tt_unused ) {
     230forall( otype Tt_unused ) {
    231231
    232232    struct hashtable_rbs_dynamic {
     
    263263
    264264
    265 forall( Tt_unused | heaped( dlist(request_in_ht_by_src, request) ) ) {
     265forall( otype Tt_unused | heaped( dlist(request_in_ht_by_src, request) ) ) {
    266266
    267267    void ?{}( hashtable_rbs_dynamic(Tt_unused).resize_policy & this, size_t nbuckets_floor ) {
     
    325325}
    326326
    327 forall( Tt_unused ) {
     327forall( otype Tt_unused ) {
    328328    void rehashToLarger_STEP( hashtable_rbs_dynamic(Tt_unused) & this, size_t new_n_buckets ) with (this) {
    329329        rehashToLarger( this, new_n_buckets );
  • tests/zombies/huge.c

    rc08c3cf r467c8b7  
    1414//
    1515
    16 int huge( int n, forall( T ) T (*f)( T ) ) {
     16int huge( int n, forall( otype T ) T (*f)( T ) ) {
    1717        if ( n <= 0 )
    1818                return f( 0 );
  • tests/zombies/it_out.c

    rc08c3cf r467c8b7  
    1616typedef unsigned long streamsize_type;
    1717
    18 trait ostream( os_type & ) {
     18trait ostream( dtype os_type ) {
    1919        os_type *write( os_type *, const char *, streamsize_type );
    2020        int fail( os_type * );
    2121};
    2222
    23 trait writeable( T ) {
    24         forall( os_type & | ostream( os_type ) ) os_type * ?<<?( os_type *, T );
     23trait writeable( otype T ) {
     24        forall( dtype os_type | ostream( os_type ) ) os_type * ?<<?( os_type *, T );
    2525};
    2626
    27 forall( os_type & | ostream( os_type ) ) os_type * ?<<?( os_type *, char );
    28 forall( os_type & | ostream( os_type ) ) os_type * ?<<?( os_type *, int );
    29 forall( os_type & | ostream( os_type ) ) os_type * ?<<?( os_type *, const char * );
     27forall( dtype os_type | ostream( os_type ) ) os_type * ?<<?( os_type *, char );
     28forall( dtype os_type | ostream( os_type ) ) os_type * ?<<?( os_type *, int );
     29forall( dtype os_type | ostream( os_type ) ) os_type * ?<<?( os_type *, const char * );
    3030
    31 trait istream( is_type & ) {
     31trait istream( dtype is_type ) {
    3232        is_type *read( is_type *, char *, streamsize_type );
    3333        is_type *unread( is_type *, char );
     
    3636};
    3737
    38 trait readable( T ) {
    39         forall( is_type & | istream( is_type ) ) is_type * ?<<?( is_type *, T );
     38trait readable( otype T ) {
     39        forall( dtype is_type | istream( is_type ) ) is_type * ?<<?( is_type *, T );
    4040};
    4141
    42 forall( is_type & | istream( is_type ) ) is_type * ?>>?( is_type *, char* );
    43 forall( is_type & | istream( is_type ) ) is_type * ?>>?( is_type *, int* );
     42forall( dtype is_type | istream( is_type ) ) is_type * ?>>?( is_type *, char* );
     43forall( dtype is_type | istream( is_type ) ) is_type * ?>>?( is_type *, int* );
    4444
    45 trait iterator( iterator_type, elt_type ) {
     45trait iterator( otype iterator_type, otype elt_type ) {
    4646        iterator_type ?++( iterator_type* );
    4747        iterator_type ++?( iterator_type* );
     
    5252};
    5353
    54 forall( elt_type | writeable( elt_type ),
    55                 iterator_type | iterator( iterator_type, elt_type ),
    56                 os_type & | ostream( os_type ) )
     54forall( otype elt_type | writeable( elt_type ),
     55                otype iterator_type | iterator( iterator_type, elt_type ),
     56                dtype os_type | ostream( os_type ) )
    5757void write_all( iterator_type begin, iterator_type end, os_type *os );
    5858
    59 forall( elt_type | writeable( elt_type ),
    60                 iterator_type | iterator( iterator_type, elt_type ),
    61                 os_type & | ostream( os_type ) )
     59forall( otype elt_type | writeable( elt_type ),
     60                otype iterator_type | iterator( iterator_type, elt_type ),
     61                dtype os_type | ostream( os_type ) )
    6262void write_all( elt_type begin, iterator_type end, os_type *os ) {
    6363        os << begin;
  • tests/zombies/new.c

    rc08c3cf r467c8b7  
    1414//
    1515
    16 forall( T )
     16forall( otype T )
    1717void f( T *t ) {
    1818        t--;
  • tests/zombies/occursError.cfa

    rc08c3cf r467c8b7  
    1 forall( T ) void f( void (*)( T, T * ) );
    2 forall( U ) void g( U,  U * );
    3 forall( U ) void h( U *, U );
     1forall( otype T ) void f( void (*)( T, T * ) );
     2forall( otype U ) void g( U,  U * );
     3forall( otype U ) void h( U *, U );
    44
    55void test() {
  • tests/zombies/prolog.c

    rc08c3cf r467c8b7  
    2525void is_integer( int x ) {}
    2626
    27 trait ArithmeticType( T ) {
     27trait ArithmeticType( otype T ) {
    2828        void is_arithmetic( T );
    2929};
    3030
    31 trait IntegralType( T | ArithmeticType( T ) ) {
     31trait IntegralType( otype T | ArithmeticType( T ) ) {
    3232        void is_integer( T );
    3333};
    3434
    35 forall( T | IntegralType( T ) | { void printResult( T ); } )
     35forall( otype T | IntegralType( T ) | { void printResult( T ); } )
    3636void hornclause( T param ) {
    3737        printResult( param );
  • tests/zombies/quad.c

    rc08c3cf r467c8b7  
    1616#include <fstream.hfa>
    1717
    18 forall( T | { T ?*?( T, T ); } )
     18forall( otype T | { T ?*?( T, T ); } )
    1919T square( T t ) {
    2020        return t * t;
    2121}
    2222
    23 forall( U | { U square( U ); } )
     23forall( otype U | { U square( U ); } )
    2424U quad( U u ) {
    2525        return square( square( u ) );
  • tests/zombies/scope.cfa

    rc08c3cf r467c8b7  
    2020y p;
    2121
    22 trait has_u( z ) {
     22trait has_u( otype z ) {
    2323        z u(z);
    2424};
    2525
    26 forall( t | has_u( t ) )
     26forall( otype t | has_u( t ) )
    2727y q( t the_t ) {
    2828        t y = u( the_t );
  • tests/zombies/simplePoly.c

    rc08c3cf r467c8b7  
    1414//
    1515
    16 forall( T, U | { T f( T, U ); } )
     16forall( otype T, otype U | { T f( T, U ); } )
    1717T q( T t, U u ) {
    1818        return f( t, u );
  • tests/zombies/simpler.c

    rc08c3cf r467c8b7  
    1414//
    1515
    16 forall( T ) T id( T, T );
     16forall( otype T ) T id( T, T );
    1717
    1818int main() {
  • tests/zombies/specialize.c

    rc08c3cf r467c8b7  
    3939}
    4040
    41 forall( T ) T f( T t )
     41forall( otype T ) T f( T t )
    4242{
    4343        printf( "in f; sizeof T is %d\n", sizeof( T ) );
  • tests/zombies/square.c

    rc08c3cf r467c8b7  
    1616#include <fstream.hfa>
    1717
    18 forall( T | { T ?*?( T, T ); } )
     18forall( otype T | { T ?*?( T, T ); } )
    1919T square( T t ) {
    2020        return t * t;
  • tests/zombies/structMember.cfa

    rc08c3cf r467c8b7  
    6666        S.T;
    6767        .S.T;
    68         forall( S, T ) struct W {
     68        forall( otype S, otype T ) struct W {
    6969                struct X {};
    7070        };
  • tests/zombies/subrange.cfa

    rc08c3cf r467c8b7  
    11// A small context defining the notion of an ordered otype.  (The standard
    22// library should probably contain a context for this purpose.)
    3 trait ordered(T) {
     3trait ordered(otype T) {
    44    int ?<?(T, T), ?<=?(T, T);
    55};
     
    77// A subrange otype resembling an Ada subotype with a base otype and a range
    88// constraint.
    9 otype subrange(base_t | ordered(base_t), base_t low = 0, base_t high = 8) = base_t;
     9otype subrange(otype base_t | ordered(base_t), base_t low = 0, base_t high = 8) = base_t;
    1010
    1111// Note that subrange() can be applied to floating-point and pointer otypes, not
     
    2828
    2929// Convenient access to subrange bounds, for instance for iteration:
    30 forall (T, T low, T high)
     30forall (otype T, T low, T high)
    3131T lbound( subrange(T, low, high) v) {
    3232    return low;
    3333}
    3434
    35 forall (T, T low, T high)
     35forall (otype T, T low, T high)
    3636T hbound( subrange(T, low, high) v) {
    3737    return high;
     
    4444// of exception handling here.  Inlining allows the compiler to eliminate
    4545// bounds checks.
    46 forall (T | ordered(T), T low, T high)
     46forall (otype T | ordered(T), T low, T high)
    4747inline subrange(T, low, high) ?=?(subrange(T, low, high)* target, T source) {
    4848    if (low <= source && source <= high) *((T*)target) = source;
     
    5454// compares range bounds so that the compiler can optimize checks away when the
    5555// ranges are known to overlap.
    56 forall (T | ordered(T), T t_low, T t_high, T s_low, T s_high)
     56forall (otype T | ordered(T), T t_low, T t_high, T s_low, T s_high)
    5757inline subrange(T, t_low, t_high) ?=?(subrange(T, t_low, t_high)* target,
    5858                                      subrange(T, s_low, s_high) source) {
  • tests/zombies/twice.c

    rc08c3cf r467c8b7  
    1616#include <fstream.hfa>
    1717
    18 forall( T | { T ?+?( T, T ); } )
     18forall( otype T | { T ?+?( T, T ); } )
    1919T twice( const T t ) {
    2020        return t + t;
  • tests/zombies/typeGenerator.cfa

    rc08c3cf r467c8b7  
    1 context addable( T ) {
     1context addable( otype T ) {
    22        T ?+?( T,T );
    33        T ?=?( T*, T);
    44};
    55
    6 otype List1( T | addable( T ) ) = struct { T data; List1( T ) *next; } *;
     6otype List1( otype T | addable( T ) ) = struct { T data; List1( T ) *next; } *;
    77typedef List1( int ) ListOfIntegers;
    88//List1( int ) li;
     
    1111[int] h( * List1( int ) p );                                                    // new declaration syntax
    1212
    13 struct( T ) S2 { T i; };                                                        // actual definition
     13struct( otype T ) S2 { T i; };                                                  // actual definition
    1414struct( int ) S3 v1, *p;                                                                // expansion and instantiation
    15 struct( T )( int ) S24 { T i; } v2;                             // actual definition, expansion and instantiation
    16 struct( T )( int ) { T i; } v2;                                 // anonymous actual definition, expansion and instantiation
     15struct( otype T )( int ) S24 { T i; } v2;                               // actual definition, expansion and instantiation
     16struct( otype T )( int ) { T i; } v2;                                   // anonymous actual definition, expansion and instantiation
    1717
    18 struct( T | addable( T ) ) node { T data; struct( T ) node *next; };
    19 otype List( T ) = struct( T ) node *;
     18struct( otype T | addable( T ) ) node { T data; struct( T ) node *next; };
     19otype List( otype T ) = struct( T ) node *;
    2020List( int ) my_list;
    2121
  • tests/zombies/withStatement.cfa

    rc08c3cf r467c8b7  
    5454}
    5555
    56 forall( T )
     56forall( otype T )
    5757struct Box {
    5858        T x;
    5959};
    6060
    61 forall( T )
     61forall( otype T )
    6262void ?{}( Box(T) & this ) with( this ) { // with clause in polymorphic function
    6363        x{};
     
    6666void print( int i ) { sout | i; }
    6767
    68 forall( T | { void print( T ); })
     68forall( otype T | { void print( T ); })
    6969void foo( T t ) {
    7070        Box( T ) b = { t };
  • tests/zombies/wrapper/src/pointer.h

    rc08c3cf r467c8b7  
    88// type safe malloc / free
    99
    10 forall(T)
     10forall(otype T)
    1111T* new()
    1212{
     
    1616}
    1717
    18 forall(T)
     18forall(otype T)
    1919void delete(T* p)
    2020{
Note: See TracChangeset for help on using the changeset viewer.