Changeset fd54fef for libcfa/src


Ignore:
Timestamp:
Jan 19, 2021, 8:44:29 PM (5 years ago)
Author:
Michael Brooks <mlbrooks@…>
Branches:
ADT, arm-eh, ast-experimental, enum, forall-pointer-decay, jacob/cs343-translation, master, new-ast-unique-expr, pthread-emulation, qualifiedEnum
Children:
dafbde8
Parents:
2f47ea4
Message:

Converting the project to use the new syntax for otype, dtype and ttytpe.

Changed prelude (gen), libcfa and test suite to use it. Added a simple deprecation rule of the old syntax to the parser; we might wish to support both syntaxes "officially," like with an extra CLI switch, but this measure should serve as a simple reminder for our team to try the new syntax.

Location:
libcfa/src
Files:
50 edited

Legend:

Unmodified
Added
Removed
  • libcfa/src/bitmanip.hfa

    r2f47ea4 rfd54fef  
    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( otype T | { T ?&?( T, T ); T -?( T ); } )
     102        // forall( 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( otype T | { T floor2( T, T ); T -?( T ); } )
     117        // forall( 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

    r2f47ea4 rfd54fef  
    1717
    1818#ifdef SAFE_SORT
    19 forall( otype T | {  int ?<?( T, T ); int ?>?( T, T ); } ) static inline void __libcfa_small_sort2( T * arr );
    20 forall( otype T | {  int ?<?( T, T ); int ?>?( T, T ); } ) static inline void __libcfa_small_sort3( T * arr );
    21 forall( otype T | {  int ?<?( T, T ); int ?>?( T, T ); } ) static inline void __libcfa_small_sort4( T * arr );
    22 forall( otype T | {  int ?<?( T, T ); int ?>?( T, T ); } ) static inline void __libcfa_small_sort5( T * arr );
    23 forall( otype T | {  int ?<?( T, T ); int ?>?( T, T ); } ) static inline void __libcfa_small_sort6( T * arr );
    24 forall( otype T | {  int ?<?( T, T ); int ?>?( T, T ); } ) static inline void __libcfa_small_sortN( T * arr, size_t dim );
     19forall( T | {  int ?<?( T, T ); int ?>?( T, T ); } ) static inline void __libcfa_small_sort2( T * arr );
     20forall( T | {  int ?<?( T, T ); int ?>?( T, T ); } ) static inline void __libcfa_small_sort3( T * arr );
     21forall( T | {  int ?<?( T, T ); int ?>?( T, T ); } ) static inline void __libcfa_small_sort4( T * arr );
     22forall( T | {  int ?<?( T, T ); int ?>?( T, T ); } ) static inline void __libcfa_small_sort5( T * arr );
     23forall( T | {  int ?<?( T, T ); int ?>?( T, T ); } ) static inline void __libcfa_small_sort6( T * arr );
     24forall( T | {  int ?<?( T, T ); int ?>?( T, T ); } ) static inline void __libcfa_small_sortN( T * arr, size_t dim );
    2525
    26 forall( otype T | {  int ?<?( T, T ); int ?>?( T, T ); } )
     26forall( 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( otype T | {  int ?<?( T, T ); int ?>?( T, T ); } )
     43forall( T | {  int ?<?( T, T ); int ?>?( T, T ); } )
    4444static inline void __libcfa_small_sort2( T * arr ) {
    4545        SWAP(0, 1);
    4646}
    4747
    48 forall( otype T | {  int ?<?( T, T ); int ?>?( T, T ); } )
     48forall( T | {  int ?<?( T, T ); int ?>?( T, T ); } )
    4949static inline void __libcfa_small_sort3( T * arr ) {
    5050        SWAP(1, 2);
     
    5353}
    5454
    55 forall( otype T | {  int ?<?( T, T ); int ?>?( T, T ); } )
     55forall( T | {  int ?<?( T, T ); int ?>?( T, T ); } )
    5656static inline void __libcfa_small_sort4( T * arr ) {
    5757        SWAP(0, 1);
     
    6262}
    6363
    64 forall( otype T | {  int ?<?( T, T ); int ?>?( T, T ); } )
     64forall( T | {  int ?<?( T, T ); int ?>?( T, T ); } )
    6565static inline void __libcfa_small_sort5( T * arr ) {
    6666        SWAP(0, 1);
     
    7575}
    7676
    77 forall( otype T | {  int ?<?( T, T ); int ?>?( T, T ); } )
     77forall( T | {  int ?<?( T, T ); int ?>?( T, T ); } )
    7878static inline void __libcfa_small_sort6( T * arr ) {
    7979        SWAP(1, 2);
     
    9191}
    9292
    93 forall( otype T | {  int ?<?( T, T ); int ?>?( T, T ); } )
     93forall( 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( dtype T )
     114forall( T & )
    115115static inline void __libcfa_small_sort( T* * arr, size_t dim ) {
    116116        switch( dim ) {
  • libcfa/src/bits/collection.hfa

    r2f47ea4 rfd54fef  
    3131
    3232        // // wrappers to make Collection have T
    33         // forall( dtype T ) {
     33        // forall( T & ) {
    3434        //      T *& Next( T * n ) {
    3535        //              return (T *)Next( (Colable *)n );
     
    3838} // distribution
    3939
    40 forall( dtype T | { T *& Next ( T * ); } ) {
     40forall( T & | { T *& Next ( T * ); } ) {
    4141        bool listed( T * n ) {
    4242                return Next( n ) != 0p;
     
    7676        } // post: elts = null
    7777
    78         forall( dtype T ) {
     78        forall( T & ) {
    7979                T * Curr( ColIter & ci ) with( ci ) {
    8080                        return (T *)curr;
  • libcfa/src/bits/containers.hfa

    r2f47ea4 rfd54fef  
    2323
    2424#ifdef __cforall
    25         forall(dtype T)
     25        forall(T &)
    2626#else
    2727        #define T void
     
    4040
    4141#ifdef __cforall
    42         // forall(otype T | sized(T))
     42        // forall(T | sized(T))
    4343        // static inline void ?{}(__small_array(T) & this) {}
    4444
    45         forall(dtype T | sized(T))
     45        forall(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(dtype T | sized(T))
     50        forall(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(dtype T)
     55        forall(T &)
    5656        static inline T * begin( const __small_array(T) & this ) {
    5757                return ((typeof(this.data))this.data);
    5858        }
    5959
    60         forall(dtype T | sized(T))
     60        forall(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(dtype T) {
     71        trait is_node(T &) {
    7272                T *& get_next( T & );
    7373        };
     
    7878//-----------------------------------------------------------------------------
    7979#ifdef __cforall
    80         forall(dtype TYPE)
     80        forall(TYPE &)
    8181        #define T TYPE
    8282#else
     
    9595
    9696#ifdef __cforall
    97         forall(dtype T)
     97        forall(T &)
    9898        static inline void ?{}( __stack(T) & this ) {
    9999                (this.top){ 0p };
    100100        }
    101101
    102         static inline forall( dtype T | is_node(T) ) {
     102        static inline forall( T & | is_node(T) ) {
    103103                void push( __stack(T) & this, T * val ) {
    104104                        verify( !get_next( *val ) );
     
    126126//-----------------------------------------------------------------------------
    127127#ifdef __cforall
    128         forall(dtype TYPE)
     128        forall(TYPE &)
    129129        #define T TYPE
    130130#else
     
    144144
    145145#ifdef __cforall
    146         static inline forall( dtype T | is_node(T) ) {
     146        static inline forall( T & | is_node(T) ) {
    147147                void ?{}( __queue(T) & this ) with( this ) {
    148148                        (this.head){ 1p };
     
    215215//-----------------------------------------------------------------------------
    216216#ifdef __cforall
    217         forall(dtype TYPE)
     217        forall(TYPE &)
    218218        #define T TYPE
    219219        #define __getter_t * [T * & next, T * & prev] ( T & )
     
    237237
    238238#ifdef __cforall
    239         forall(dtype T )
     239        forall(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(dtype T) {
     247        static inline forall(T &) {
    248248                void push_front( __dllist(T) & this, T & node ) with( this ) {
    249249                        verify(__get);
  • libcfa/src/bits/queue.hfa

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

    r2f47ea4 rfd54fef  
    2929
    3030        // // wrappers to make Collection have T
    31         // forall( dtype T ) {
     31        // forall( 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( dtype T | { T *& Back ( T * ); T *& Next ( T * ); } ) {
     45forall( T & | { T *& Back ( T * ); T *& Next ( T * ); } ) {
    4646        struct Sequence {
    4747                inline Collection;                                                              // Plan 9 inheritance
     
    231231} // distribution
    232232
    233 forall( dtype T | { T *& Back ( T * ); T *& Next ( T * ); } ) {
     233forall( 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

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

    r2f47ea4 rfd54fef  
    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( otype T | { T ?/?( T, T ); T ?%?( T, T ); } )
     25forall( 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

    r2f47ea4 rfd54fef  
    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( otype T | { T ?/?( T, T ); T ?%?( T, T ); } )
     23forall( T | { T ?/?( T, T ); T ?%?( T, T ); } )
    2424[ T, T ] div( T num, T demon );
    2525
     
    6161} // distribution
    6262
    63 forall( otype T | { void ?{}( T &, zero_t ); int ?<?( T, T ); T -?( T ); } )
     63forall( 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( otype T | { int ?<?( T, T ); } )
     72        forall( 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( otype T | { int ?>?( T, T ); } )
     78        forall( T | { int ?>?( T, T ); } )
    7979        T max( T t1, T t2 ) { return t1 > t2 ? t1 : t2; }
    8080
    81         forall( otype T | { T min( T, T ); T max( T, T ); } )
     81        forall( 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( otype T )
     84        forall( T )
    8585        void swap( T & v1, T & v2 ) { T temp = v1; v1 = v2; v2 = temp; }
    8686} // distribution
  • libcfa/src/concurrency/coroutine.cfa

    r2f47ea4 rfd54fef  
    4646
    4747//-----------------------------------------------------------------------------
    48 FORALL_DATA_INSTANCE(CoroutineCancelled, (dtype coroutine_t), (coroutine_t))
    49 
    50 forall(dtype T)
     48FORALL_DATA_INSTANCE(CoroutineCancelled, (coroutine_t &), (coroutine_t))
     49
     50forall(T &)
    5151void mark_exception(CoroutineCancelled(T) *) {}
    5252
    53 forall(dtype T)
     53forall(T &)
    5454void copy(CoroutineCancelled(T) * dst, CoroutineCancelled(T) * src) {
    5555        dst->virtual_table = src->virtual_table;
     
    5858}
    5959
    60 forall(dtype T)
     60forall(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(dtype T | is_coroutine(T))
     66forall(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(dtype T | is_coroutine(T))
     150forall(T & | is_coroutine(T))
    151151void prime(T& cor) {
    152152        $coroutine* this = get_coroutine(cor);
  • libcfa/src/concurrency/coroutine.hfa

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

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

    r2f47ea4 rfd54fef  
    77//-----------------------------------------------------------------------------
    88// info_thread
    9 forall(dtype L | is_blocking_lock(L)) {
     9forall(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(dtype L | is_blocking_lock(L)) {
     197forall(L & | is_blocking_lock(L)) {
    198198        struct alarm_node_wrap {
    199199                alarm_node_t alarm_node;
     
    239239//-----------------------------------------------------------------------------
    240240// condition variable
    241 forall(dtype L | is_blocking_lock(L)) {
     241forall(L & | is_blocking_lock(L)) {
    242242
    243243        void ?{}( condition_variable(L) & this ){
  • libcfa/src/concurrency/locks.hfa

    r2f47ea4 rfd54fef  
    1313//-----------------------------------------------------------------------------
    1414// is_blocking_lock
    15 trait is_blocking_lock(dtype L | sized(L)) {
     15trait is_blocking_lock(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(dtype L | is_blocking_lock(L)) {
     33forall(L & | is_blocking_lock(L)) {
    3434        struct info_thread;
    3535
     
    120120//-----------------------------------------------------------------------------
    121121// Synchronization Locks
    122 forall(dtype L | is_blocking_lock(L)) {
     122forall(L & | is_blocking_lock(L)) {
    123123        struct condition_variable {
    124124                // Spin lock used for mutual exclusion
  • libcfa/src/concurrency/monitor.cfa

    r2f47ea4 rfd54fef  
    5050static inline [$thread *, int] search_entry_queue( const __waitfor_mask_t &, $monitor * monitors [], __lock_size_t count );
    5151
    52 forall(dtype T | sized( T ))
     52forall(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(dtype T | sized( T ))
     951forall(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

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

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

    r2f47ea4 rfd54fef  
    7070void unlock(recursive_mutex_lock & this) __attribute__((deprecated("use concurrency/locks.hfa instead")));
    7171
    72 trait is_lock(dtype L | sized(L)) {
     72trait is_lock(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(dtype L | is_lock(L))
     96forall(L & | is_lock(L))
    9797void wait(condition_variable & this, L & l) __attribute__((deprecated("use concurrency/locks.hfa instead")));
    9898
    9999//-----------------------------------------------------------------------------
    100100// Scopes
    101 forall(dtype L | is_lock(L)) {
     101forall(L & | is_lock(L)) {
    102102        #if !defined( __TUPLE_ARRAYS_EXIST__ )
    103103        void lock  ( L * locks [], size_t count);
  • libcfa/src/concurrency/thread.cfa

    r2f47ea4 rfd54fef  
    6262}
    6363
    64 FORALL_DATA_INSTANCE(ThreadCancelled, (dtype thread_t), (thread_t))
     64FORALL_DATA_INSTANCE(ThreadCancelled, (thread_t &), (thread_t))
    6565
    66 forall(dtype T)
     66forall(T &)
    6767void copy(ThreadCancelled(T) * dst, ThreadCancelled(T) * src) {
    6868        dst->virtual_table = src->virtual_table;
     
    7171}
    7272
    73 forall(dtype T)
     73forall(T &)
    7474const char * msg(ThreadCancelled(T) *) {
    7575        return "ThreadCancelled";
    7676}
    7777
    78 forall(dtype T)
     78forall(T &)
    7979static void default_thread_cancel_handler(ThreadCancelled(T) & ) {
    8080        abort( "Unhandled thread cancellation.\n" );
    8181}
    8282
    83 forall(dtype T | is_thread(T) | IS_EXCEPTION(ThreadCancelled, (T)))
     83forall(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( dtype T | is_thread(T) )
     126forall( 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( dtype T | sized(T) | is_thread(T) | { void ?{}(T&); } )
     142forall( T & | sized(T) | is_thread(T) | { void ?{}(T&); } )
    143143void ?{}( scoped(T)& this ) with( this ) {
    144144        handle{};
     
    146146}
    147147
    148 forall( dtype T, ttype P | sized(T) | is_thread(T) | { void ?{}(T&, P); } )
     148forall( T &, P... | sized(T) | is_thread(T) | { void ?{}(T&, P); } )
    149149void ?{}( scoped(T)& this, P params ) with( this ) {
    150150        handle{ params };
     
    152152}
    153153
    154 forall( dtype T | sized(T) | is_thread(T) )
     154forall( T & | sized(T) | is_thread(T) )
    155155void ^?{}( scoped(T)& this ) with( this ) {
    156156        ^handle{};
     
    158158
    159159//-----------------------------------------------------------------------------
    160 forall(dtype T | is_thread(T) | IS_RESUMPTION_EXCEPTION(ThreadCancelled, (T)))
     160forall(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

    r2f47ea4 rfd54fef  
    2626//-----------------------------------------------------------------------------
    2727// thread trait
    28 trait is_thread(dtype T) {
     28trait is_thread(T &) {
    2929        void ^?{}(T& mutex this);
    3030        void main(T& this);
     
    3232};
    3333
    34 FORALL_DATA_EXCEPTION(ThreadCancelled, (dtype thread_t), (thread_t)) (
     34FORALL_DATA_EXCEPTION(ThreadCancelled, (thread_t &), (thread_t)) (
    3535        thread_t * the_thread;
    3636        exception_t * the_exception;
    3737);
    3838
    39 forall(dtype T)
     39forall(T &)
    4040void copy(ThreadCancelled(T) * dst, ThreadCancelled(T) * src);
    4141
    42 forall(dtype T)
     42forall(T &)
    4343const char * msg(ThreadCancelled(T) *);
    4444
     
    4747
    4848// Inline getters for threads/coroutines/monitors
    49 forall( dtype T | is_thread(T) )
     49forall( T & | is_thread(T) )
    5050static inline $coroutine* get_coroutine(T & this) __attribute__((const)) { return &get_thread(this)->self_cor; }
    5151
    52 forall( dtype T | is_thread(T) )
     52forall( 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( dtype T | is_thread(T) )
     62forall( T & | is_thread(T) )
    6363void __thrd_start( T & this, void (*)(T &) );
    6464
     
    8282};
    8383
    84 forall( dtype T | is_thread(T) | IS_EXCEPTION(ThreadCancelled, (T)) )
     84forall( 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( dtype T | sized(T) | is_thread(T) )
     91forall( T & | sized(T) | is_thread(T) )
    9292struct scoped {
    9393        T handle;
    9494};
    9595
    96 forall( dtype T | sized(T) | is_thread(T) | { void ?{}(T&); } )
     96forall( T & | sized(T) | is_thread(T) | { void ?{}(T&); } )
    9797void ?{}( scoped(T)& this );
    9898
    99 forall( dtype T, ttype P | sized(T) | is_thread(T) | { void ?{}(T&, P); } )
     99forall( T &, P... | sized(T) | is_thread(T) | { void ?{}(T&, P); } )
    100100void ?{}( scoped(T)& this, P params );
    101101
    102 forall( dtype T | sized(T) | is_thread(T) )
     102forall( T & | sized(T) | is_thread(T) )
    103103void ^?{}( scoped(T)& this );
    104104
     
    115115void unpark( $thread * this );
    116116
    117 forall( dtype T | is_thread(T) )
     117forall( T & | is_thread(T) )
    118118static inline void unpark( T & this ) { if(!&this) return; unpark( get_thread( this ) );}
    119119
     
    128128//----------
    129129// join
    130 forall( dtype T | is_thread(T) | IS_RESUMPTION_EXCEPTION(ThreadCancelled, (T)) )
     130forall( T & | is_thread(T) | IS_RESUMPTION_EXCEPTION(ThreadCancelled, (T)) )
    131131T & join( T & this );
    132132
  • libcfa/src/containers/list.hfa

    r2f47ea4 rfd54fef  
    6666#define __DLISTED_MGD_JUSTIMPL(STRUCT)
    6767
    68 forall( dtype tE ) {
     68forall( tE & ) {
    6969        struct $mgd_link {
    7070                tE *elem;
     
    8383                (this.is_terminator){ 1 };
    8484        }
    85         forall ( otype tInit | { void ?{}( $mgd_link(tE) &, tInit); } )
     85        forall ( 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(dtype Tnode, dtype Telem) {
     117trait $dlistable(Tnode &, Telem &) {
    118118        $mgd_link(Telem) & $prev_link(Tnode &);
    119119        $mgd_link(Telem) & $next_link(Tnode &);
     
    125125};
    126126
    127 forall (dtype Tnode, dtype Telem | $dlistable(Tnode, Telem)) {
     127forall (Tnode &, Telem & | $dlistable(Tnode, Telem)) {
    128128
    129129        // implemented as a sentinel item in an underlying cicrular list
  • libcfa/src/containers/maybe.cfa

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

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

    r2f47ea4 rfd54fef  
    1313#include <containers/pair.hfa>
    1414
    15 forall(otype R, otype S
     15forall(R, S
    1616        | { int ?==?(R, R); int ?<?(R, R); int ?<?(S, S); })
    1717int ?<?(pair(R, S) p, pair(R, S) q) {
     
    1919}
    2020
    21 forall(otype R, otype S
     21forall(R, S
    2222        | { int ?==?(R, R); int ?<?(R, R); int ?<=?(S, S); })
    2323int ?<=?(pair(R, S) p, pair(R, S) q) {
     
    2525}
    2626
    27 forall(otype R, otype S | { int ?==?(R, R); int ?==?(S, S); })
     27forall(R, 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(otype R, otype S | { int ?!=?(R, R); int ?!=?(S, S); })
     32forall(R, 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(otype R, otype S
     37forall(R, S
    3838        | { int ?==?(R, R); int ?>?(R, R); int ?>?(S, S); })
    3939int ?>?(pair(R, S) p, pair(R, S) q) {
     
    4141}
    4242
    43 forall(otype R, otype S
     43forall(R, 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

    r2f47ea4 rfd54fef  
    1616#pragma once
    1717
    18 forall(otype R, otype S) struct pair {
     18forall(R, S) struct pair {
    1919        R first;
    2020        S second;
    2121};
    2222
    23 forall(otype R, otype S
     23forall(R, S
    2424        | { int ?==?(R, R); int ?<?(R, R); int ?<?(S, S); })
    2525int ?<?(pair(R, S) p, pair(R, S) q);
    2626
    27 forall(otype R, otype S
     27forall(R, S
    2828        | { int ?==?(R, R); int ?<?(R, R); int ?<=?(S, S); })
    2929int ?<=?(pair(R, S) p, pair(R, S) q);
    3030
    31 forall(otype R, otype S | { int ?==?(R, R); int ?==?(S, S); })
     31forall(R, S | { int ?==?(R, R); int ?==?(S, S); })
    3232int ?==?(pair(R, S) p, pair(R, S) q);
    3333
    34 forall(otype R, otype S | { int ?!=?(R, R); int ?!=?(S, S); })
     34forall(R, S | { int ?!=?(R, R); int ?!=?(S, S); })
    3535int ?!=?(pair(R, S) p, pair(R, S) q);
    3636
    37 forall(otype R, otype S
     37forall(R, S
    3838        | { int ?==?(R, R); int ?>?(R, R); int ?>?(S, S); })
    3939int ?>?(pair(R, S) p, pair(R, S) q);
    4040
    41 forall(otype R, otype S
     41forall(R, 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

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

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

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

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

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

    r2f47ea4 rfd54fef  
    101101// implemented in the .c file either so they all have to be inline.
    102102
    103 trait is_exception(dtype exceptT, dtype virtualT) {
     103trait is_exception(exceptT &, 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(dtype exceptT, dtype virtualT | is_exception(exceptT, virtualT)) {
     111trait is_termination_exception(exceptT &, virtualT & | is_exception(exceptT, virtualT)) {
    112112        void defaultTerminationHandler(exceptT &);
    113113};
    114114
    115 trait is_resumption_exception(dtype exceptT, dtype virtualT | is_exception(exceptT, virtualT)) {
     115trait is_resumption_exception(exceptT &, virtualT & | is_exception(exceptT, virtualT)) {
    116116        void defaultResumptionHandler(exceptT &);
    117117};
    118118
    119 forall(dtype exceptT, dtype virtualT | is_termination_exception(exceptT, virtualT))
     119forall(exceptT &, virtualT & | is_termination_exception(exceptT, virtualT))
    120120static inline void $throw(exceptT & except) {
    121121        __cfaehm_throw_terminate(
     
    125125}
    126126
    127 forall(dtype exceptT, dtype virtualT | is_resumption_exception(exceptT, virtualT))
     127forall(exceptT &, virtualT & | is_resumption_exception(exceptT, virtualT))
    128128static inline void $throwResume(exceptT & except) {
    129129        __cfaehm_throw_resume(
     
    133133}
    134134
    135 forall(dtype exceptT, dtype virtualT | is_exception(exceptT, virtualT))
     135forall(exceptT &, 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(dtype exceptT, dtype virtualT | is_exception(exceptT, virtualT))
     140forall(exceptT &, virtualT & | is_exception(exceptT, virtualT))
    141141static inline void defaultTerminationHandler(exceptT & except) {
    142142        return cancel_stack( except );
    143143}
    144144
    145 forall(dtype exceptT, dtype virtualT | is_exception(exceptT, virtualT))
     145forall(exceptT &, virtualT & | is_exception(exceptT, virtualT))
    146146static inline void defaultResumptionHandler(exceptT & except) {
    147147        throw except;
  • libcfa/src/executor.cfa

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

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

    r2f47ea4 rfd54fef  
    3636
    3737
    38 forall( dtype ostype | ostream( ostype ) ) {
     38forall( ostype & | ostream( ostype ) ) {
    3939        ostype & ?|?( ostype & os, bool b ) {
    4040                if ( $sepPrt( os ) ) fmt( os, "%s", $sepGetCur( os ) );
     
    402402
    403403// tuples
    404 forall( dtype ostype, otype T, ttype Params | writeable( T, ostype ) | { ostype & ?|?( ostype &, Params ); } ) {
     404forall( ostype &, T, Params... | writeable( T, ostype ) | { ostype & ?|?( ostype &, Params ); } ) {
    405405        ostype & ?|?( ostype & os, T arg, Params rest ) {
    406406                (ostype &)(os | arg);                                                   // print first argument
     
    421421
    422422// writes the range [begin, end) to the given stream
    423 forall( dtype ostype, otype elt_type | writeable( elt_type, ostype ), otype iterator_type | iterator( iterator_type, elt_type ) ) {
     423forall( ostype &, elt_type | writeable( elt_type, ostype ), iterator_type | iterator( iterator_type, elt_type ) ) {
    424424        void write( iterator_type begin, iterator_type end, ostype & os ) {
    425425                void print( elt_type i ) { os | i; }
     
    442442// Default prefix for non-decimal prints is 0b, 0, 0x.
    443443#define IntegralFMTImpl( T, IFMTNP, IFMTP ) \
    444 forall( dtype ostype | ostream( ostype ) ) { \
     444forall( ostype & | ostream( ostype ) ) { \
    445445        ostype & ?|?( ostype & os, _Ostream_Manip(T) f ) { \
    446446                if ( $sepPrt( os ) ) fmt( os, "%s", $sepGetCur( os ) ); \
     
    535535// Default prefix for non-decimal prints is 0b, 0, 0x.
    536536#define IntegralFMTImpl128( T, SIGNED, CODE, IFMTNP, IFMTP ) \
    537 forall( dtype ostype | ostream( ostype ) ) \
     537forall( ostype & | ostream( ostype ) ) \
    538538static void base10_128( ostype & os, _Ostream_Manip(T) f ) { \
    539539        if ( f.val > UINT64_MAX ) { \
     
    552552        } /* if */ \
    553553} /* base10_128 */ \
    554 forall( dtype ostype | ostream( ostype ) ) { \
     554forall( ostype & | ostream( ostype ) ) { \
    555555        ostype & ?|?( ostype & os, _Ostream_Manip(T) f ) { \
    556556                if ( $sepPrt( os ) ) fmt( os, "%s", $sepGetCur( os ) ); \
     
    654654#if defined( __SIZEOF_INT128__ )
    655655// Default prefix for non-decimal prints is 0b, 0, 0x.
    656 forall( dtype ostype | ostream( ostype ) )
     656forall( ostype & | ostream( ostype ) )
    657657static 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 ) {
    658658        int wd = 1;                                                                                     // f.wd is never 0 because 0 implies left-pad
     
    719719
    720720#define IntegralFMTImpl128( T ) \
    721 forall( dtype ostype | ostream( ostype ) ) { \
     721forall( ostype & | ostream( ostype ) ) { \
    722722        ostype & ?|?( ostype & os, _Ostream_Manip(T) f ) { \
    723723                _Ostream_Manip(uint64_t) fmt; \
     
    767767
    768768#define FloatingPointFMTImpl( T, DFMTNP, DFMTP ) \
    769 forall( dtype ostype | ostream( ostype ) ) { \
     769forall( ostype & | ostream( ostype ) ) { \
    770770        ostype & ?|?( ostype & os, _Ostream_Manip(T) f ) { \
    771771                if ( $sepPrt( os ) ) fmt( os, "%s", $sepGetCur( os ) ); \
     
    801801// *********************************** character ***********************************
    802802
    803 forall( dtype ostype | ostream( ostype ) ) {
     803forall( ostype & | ostream( ostype ) ) {
    804804        ostype & ?|?( ostype & os, _Ostream_Manip(char) f ) {
    805805                if ( f.base != 'c' ) {                                                  // bespoke binary/octal/hex format
     
    834834// *********************************** C string ***********************************
    835835
    836 forall( dtype ostype | ostream( ostype ) ) {
     836forall( ostype & | ostream( ostype ) ) {
    837837        ostype & ?|?( ostype & os, _Ostream_Manip(const char *) f ) {
    838838                if ( ! f.val ) return os;                                               // null pointer ?
     
    882882
    883883
    884 forall( dtype istype | istream( istype ) ) {
     884forall( istype & | istream( istype ) ) {
    885885        istype & ?|?( istype & is, bool & b ) {
    886886                char val[6];
     
    10481048// *********************************** manipulators ***********************************
    10491049
    1050 forall( dtype istype | istream( istype ) )
     1050forall( istype & | istream( istype ) )
    10511051istype & ?|?( istype & is, _Istream_Cstr f ) {
    10521052        // skip xxx
     
    10831083} // ?|?
    10841084
    1085 forall( dtype istype | istream( istype ) )
     1085forall( istype & | istream( istype ) )
    10861086istype & ?|?( istype & is, _Istream_Char f ) {
    10871087        fmt( is, "%*c" );                                                                       // argument variable unused
     
    10901090
    10911091#define InputFMTImpl( T, CODE ) \
    1092 forall( dtype istype | istream( istype ) ) \
     1092forall( istype & | istream( istype ) ) \
    10931093istype & ?|?( istype & is, _Istream_Manip(T) f ) { \
    10941094        enum { size = 16 }; \
     
    11191119InputFMTImpl( long double, "Lf" )
    11201120
    1121 forall( dtype istype | istream( istype ) )
     1121forall( istype & | istream( istype ) )
    11221122istype & ?|?( istype & is, _Istream_Manip(float _Complex) fc ) {
    11231123        float re, im;
     
    11301130} // ?|?
    11311131
    1132 forall( dtype istype | istream( istype ) )
     1132forall( istype & | istream( istype ) )
    11331133istype & ?|?( istype & is, _Istream_Manip(double _Complex) dc ) {
    11341134        double re, im;
     
    11411141} // ?|?
    11421142
    1143 forall( dtype istype | istream( istype ) )
     1143forall( istype & | istream( istype ) )
    11441144istype & ?|?( istype & is, _Istream_Manip(long double _Complex) ldc ) {
    11451145        long double re, im;
  • libcfa/src/iostream.hfa

    r2f47ea4 rfd54fef  
    2222
    2323
    24 trait ostream( dtype ostype ) {
     24trait ostream( ostype & ) {
    2525        // private
    2626        bool $sepPrt( ostype & );                                                       // get separator state (on/off)
     
    5656}; // ostream
    5757
    58 // trait writeable( otype T ) {
    59 //      forall( dtype ostype | ostream( ostype ) ) ostype & ?|?( ostype &, T );
     58// trait writeable( T ) {
     59//      forall( ostype & | ostream( ostype ) ) ostype & ?|?( ostype &, T );
    6060// }; // writeable
    6161
    62 trait writeable( otype T, dtype ostype | ostream( ostype ) ) {
     62trait writeable( T, ostype & | ostream( ostype ) ) {
    6363        ostype & ?|?( ostype &, T );
    6464}; // writeable
     
    6666// implement writable for intrinsic types
    6767
    68 forall( dtype ostype | ostream( ostype ) ) {
     68forall( ostype & | ostream( ostype ) ) {
    6969        ostype & ?|?( ostype &, bool );
    7070        void ?|?( ostype &, bool );
     
    140140
    141141// tuples
    142 forall( dtype ostype, otype T, ttype Params | writeable( T, ostype ) | { ostype & ?|?( ostype &, Params ); } ) {
     142forall( ostype &, T, Params... | writeable( T, ostype ) | { ostype & ?|?( ostype &, Params ); } ) {
    143143        ostype & ?|?( ostype & os, T arg, Params rest );
    144144        void ?|?( ostype & os, T arg, Params rest );
     
    146146
    147147// writes the range [begin, end) to the given stream
    148 forall( dtype ostype, otype elt_type | writeable( elt_type, ostype ), otype iterator_type | iterator( iterator_type, elt_type ) ) {
     148forall( ostype &, elt_type | writeable( elt_type, ostype ), iterator_type | iterator( iterator_type, elt_type ) ) {
    149149        void write( iterator_type begin, iterator_type end, ostype & os );
    150150        void write_reverse( iterator_type begin, iterator_type end, ostype & os );
     
    153153// *********************************** manipulators ***********************************
    154154
    155 forall( otype T )
     155forall( T )
    156156struct _Ostream_Manip {
    157157        T val;                                                                                          // polymorphic base-type
     
    193193        _Ostream_Manip(T) & sign( _Ostream_Manip(T) & fmt ) { fmt.flags.sign = true; return fmt; } \
    194194} /* distribution */ \
    195 forall( dtype ostype | ostream( ostype ) ) { \
     195forall( ostype & | ostream( ostype ) ) { \
    196196        ostype & ?|?( ostype & os, _Ostream_Manip(T) f ); \
    197197        void ?|?( ostype & os, _Ostream_Manip(T) f ); \
     
    234234        _Ostream_Manip(T) & nodp( _Ostream_Manip(T) & fmt ) { fmt.flags.nobsdp = true; return fmt; } \
    235235} /* distribution */ \
    236 forall( dtype ostype | ostream( ostype ) ) { \
     236forall( ostype & | ostream( ostype ) ) { \
    237237        ostype & ?|?( ostype & os, _Ostream_Manip(T) f ); \
    238238        void ?|?( ostype & os, _Ostream_Manip(T) f ); \
     
    254254        _Ostream_Manip(char) & nobase( _Ostream_Manip(char) & fmt ) { fmt.flags.nobsdp = true; return fmt; }
    255255} // distribution
    256 forall( dtype ostype | ostream( ostype ) ) {
     256forall( ostype & | ostream( ostype ) ) {
    257257        ostype & ?|?( ostype & os, _Ostream_Manip(char) f );
    258258        void ?|?( ostype & os, _Ostream_Manip(char) f );
     
    272272        _Ostream_Manip(const char *) & nobase( _Ostream_Manip(const char *) & fmt ) { fmt.flags.nobsdp = true; return fmt; }
    273273} // distribution
    274 forall( dtype ostype | ostream( ostype ) ) {
     274forall( ostype & | ostream( ostype ) ) {
    275275        ostype & ?|?( ostype & os, _Ostream_Manip(const char *) f );
    276276        void ?|?( ostype & os, _Ostream_Manip(const char *) f );
     
    281281
    282282
    283 trait istream( dtype istype ) {
     283trait istream( istype & ) {
    284284        void nlOn( istype & );                                                          // read newline
    285285        void nlOff( istype & );                                                         // scan newline
     
    294294}; // istream
    295295
    296 trait readable( otype T ) {
    297         forall( dtype istype | istream( istype ) ) istype & ?|?( istype &, T );
     296trait readable( T ) {
     297        forall( istype & | istream( istype ) ) istype & ?|?( istype &, T );
    298298}; // readable
    299299
    300 forall( dtype istype | istream( istype ) ) {
     300forall( istype & | istream( istype ) ) {
    301301        istype & ?|?( istype &, bool & );
    302302
     
    363363        _Istream_Cstr & wdi( unsigned int w, _Istream_Cstr & fmt ) { fmt.wd = w; return fmt; }
    364364} // distribution
    365 forall( dtype istype | istream( istype ) ) istype & ?|?( istype & is, _Istream_Cstr f );
     365forall( istype & | istream( istype ) ) istype & ?|?( istype & is, _Istream_Cstr f );
    366366
    367367struct _Istream_Char {
     
    373373        _Istream_Char & ignore( _Istream_Char & fmt ) { fmt.ignore = true; return fmt; }
    374374} // distribution
    375 forall( dtype istype | istream( istype ) ) istype & ?|?( istype & is, _Istream_Char f );
    376 
    377 forall( dtype T | sized( T ) )
     375forall( istype & | istream( istype ) ) istype & ?|?( istype & is, _Istream_Char f );
     376
     377forall( T & | sized( T ) )
    378378struct _Istream_Manip {
    379379        T & val;                                                                                        // polymorphic base-type
     
    389389        _Istream_Manip(T) & wdi( unsigned int w, _Istream_Manip(T) & fmt ) { fmt.wd = w; return fmt; } \
    390390} /* distribution */ \
    391 forall( dtype istype | istream( istype ) ) { \
     391forall( istype & | istream( istype ) ) { \
    392392        istype & ?|?( istype & is, _Istream_Manip(T) f ); \
    393393} // ?|?
     
    418418#include <time_t.hfa>                                                                   // Duration (constructors) / Time (constructors)
    419419
    420 forall( dtype ostype | ostream( ostype ) ) {
     420forall( ostype & | ostream( ostype ) ) {
    421421        ostype & ?|?( ostype & os, Duration dur );
    422422        void ?|?( ostype & os, Duration dur );
  • libcfa/src/iterator.cfa

    r2f47ea4 rfd54fef  
    1616#include "iterator.hfa"
    1717
    18 forall( otype iterator_type, otype elt_type | iterator( iterator_type, elt_type ) )
     18forall( iterator_type, 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( otype iterator_type, otype elt_type | iterator( iterator_type, elt_type ) )
     25forall( iterator_type, 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

    r2f47ea4 rfd54fef  
    1717
    1818// An iterator can be used to traverse a data structure.
    19 trait iterator( otype iterator_type, otype elt_type ) {
     19trait iterator( iterator_type, elt_type ) {
    2020        // point to the next element
    2121//      iterator_type ?++( iterator_type & );
     
    3131};
    3232
    33 trait iterator_for( otype iterator_type, otype collection_type, otype elt_type | iterator( iterator_type, elt_type ) ) {
     33trait iterator_for( iterator_type, collection_type, 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( otype iterator_type, otype elt_type | iterator( iterator_type, elt_type ) )
     39forall( iterator_type, elt_type | iterator( iterator_type, elt_type ) )
    4040void for_each( iterator_type begin, iterator_type end, void (* func)( elt_type ) );
    4141
    42 forall( otype iterator_type, otype elt_type | iterator( iterator_type, elt_type ) )
     42forall( iterator_type, 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

    r2f47ea4 rfd54fef  
    286286        unsigned long long int floor( unsigned long long int n, unsigned long long int align ) { return n / align * align; }
    287287
    288         // forall( otype T | { T ?/?( T, T ); T ?*?( T, T ); } )
     288        // forall( 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( otype T | { T ?+?( T, T ); T ?-?( T, T ); T ?%?( T, T ); } )
     302        // forall( 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( otype T | { void ?{}( T &, one_t ); T ?+?( T, T ); T ?-?( T, T ); T ?/?( T, T ); } )
     317        // forall( 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( otype T | { void ?{}( T &, one_t ); T ?+?( T, T ); T ?-?( T, T );T ?*?( T, T ); } )
     416        forall( 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( otype T | { void ?{}( T &, zero_t ); void ?{}( T &, one_t ); int ?<?( T, T ); } )
     419        forall( 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( otype T | { void ?{}( T &, int ); T clamp( T, T, T ); T ?-?( T, T ); T ?*?( T, T ); T ?/?( T, T ); } )
     422        forall( 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

    r2f47ea4 rfd54fef  
    1818
    1919// Internal data object.
    20 forall(dtype T | sized(T), ttype Args | { void ?{}(T &, Args); })
     20forall(T & | sized(T), Args... | { void ?{}(T &, Args); })
    2121void ?{}(counter_data(T) & this, Args args) {
    2222        (this.counter){1};
     
    2424}
    2525
    26 forall(dtype T | sized(T) | { void ^?{}(T &); })
     26forall(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(dtype T | sized(T))
     33forall(T & | sized(T))
    3434void ?{}(counter_ptr(T) & this) {
    3535        this.data = 0p;
    3636}
    3737
    38 forall(dtype T | sized(T))
     38forall(T & | sized(T))
    3939void ?{}(counter_ptr(T) & this, zero_t) {
    4040        this.data = 0p;
    4141}
    4242
    43 forall(dtype T | sized(T) | { void ^?{}(T &); })
     43forall(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(dtype T | sized(T))
     50forall(T & | sized(T))
    5151static void internal_copy(counter_ptr(T) & this, counter_ptr(T) & that) {
    5252        this.data = that.data;
     
    5656}
    5757
    58 forall(dtype T | sized(T) | { void ^?{}(T &); })
     58forall(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(dtype T | sized(T), ttype Args | { void ?{}(T&, Args); })
     66forall(T & | sized(T), Args... | { void ?{}(T&, Args); })
    6767void ?{}(counter_ptr(T) & this, Args args) {
    6868        this.data = (counter_data(T)*)new(args);
    6969}
    7070
    71 forall(dtype T | sized(T) | { void ^?{}(T &); })
     71forall(T & | sized(T) | { void ^?{}(T &); })
    7272void ^?{}(counter_ptr(T) & this) {
    7373        internal_decrement(this);
    7474}
    7575
    76 forall(dtype T | sized(T))
     76forall(T & | sized(T))
    7777T & *?(counter_ptr(T) & this) {
    7878        return *((this.data) ? &this.data->object : 0p);
    7979}
    8080
    81 forall(dtype T | sized(T) | { void ^?{}(T &); })
     81forall(T & | sized(T) | { void ^?{}(T &); })
    8282void ?=?(counter_ptr(T) & this, counter_ptr(T) that) {
    8383        if (this.data != that.data) {
     
    8787}
    8888
    89 forall(dtype T | sized(T) | { void ^?{}(T &); })
     89forall(T & | sized(T) | { void ^?{}(T &); })
    9090void ?=?(counter_ptr(T) & this, zero_t) {
    9191        internal_decrement(this);
     
    9393}
    9494
    95 forall(dtype T | sized(T))
     95forall(T & | sized(T))
    9696int ?==?(counter_ptr(T) const & this, counter_ptr(T) const & that) {
    9797        return this.data == that.data;
    9898}
    9999
    100 forall(dtype T | sized(T))
     100forall(T & | sized(T))
    101101int ?!=?(counter_ptr(T) const & this, counter_ptr(T) const & that) {
    102102        return !?==?(this, that);
    103103}
    104104
    105 forall(dtype T | sized(T))
     105forall(T & | sized(T))
    106106int ?==?(counter_ptr(T) const & this, zero_t) {
    107107        return this.data == 0;
    108108}
    109109
    110 forall(dtype T | sized(T))
     110forall(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(dtype T)
     116forall(T &)
    117117void ?{}(unique_ptr(T) & this) {
    118118        this.data = 0p;
    119119}
    120120
    121 forall(dtype T)
     121forall(T &)
    122122void ?{}(unique_ptr(T) & this, zero_t) {
    123123        this.data = 0p;
    124124}
    125125
    126 forall(dtype T | sized(T), ttype Args | { void ?{}(T &, Args); })
     126forall(T & | sized(T), Args... | { void ?{}(T &, Args); })
    127127void ?{}(unique_ptr(T) & this, Args args) {
    128128        this.data = (T *)new(args);
    129129}
    130130
    131 forall(dtype T | { void ^?{}(T &); })
     131forall(T & | { void ^?{}(T &); })
    132132void ^?{}(unique_ptr(T) & this) {
    133133        delete(this.data);
    134134}
    135135
    136 forall(dtype T)
     136forall(T &)
    137137T & *?(unique_ptr(T) & this) {
    138138        return *this.data;
    139139}
    140140
    141 forall(dtype T | { void ^?{}(T &); })
     141forall(T & | { void ^?{}(T &); })
    142142void ?=?(unique_ptr(T) & this, zero_t) {
    143143        delete(this.data);
     
    145145}
    146146
    147 forall(dtype T | { void ^?{}(T &); })
     147forall(T & | { void ^?{}(T &); })
    148148void move(unique_ptr(T) & this, unique_ptr(T) & that) {
    149149        delete(this.data);
     
    152152}
    153153
    154 forall(dtype T)
     154forall(T &)
    155155int ?==?(unique_ptr(T) const & this, unique_ptr(T) const & that) {
    156156        return this.data == that.data;
    157157}
    158158
    159 forall(dtype T)
     159forall(T &)
    160160int ?!=?(unique_ptr(T) const & this, unique_ptr(T) const & that) {
    161161        return !?==?(this, that);
    162162}
    163163
    164 forall(dtype T)
     164forall(T &)
    165165int ?==?(unique_ptr(T) const & this, zero_t) {
    166166        return this.data == 0;
    167167}
    168168
    169 forall(dtype T)
     169forall(T &)
    170170int ?!=?(unique_ptr(T) const & this, zero_t) {
    171171        return !?==?(this, (zero_t)0);
  • libcfa/src/memory.hfa

    r2f47ea4 rfd54fef  
    1717
    1818// Internal data object.
    19 forall(dtype T | sized(T)) {
     19forall(T & | sized(T)) {
    2020        struct counter_data {
    2121                unsigned int counter;
     
    2323        };
    2424
    25         forall(ttype Args | { void ?{}(T &, Args); })
     25        forall(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(dtype T | sized(T)) {
     33forall(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(ttype Args | { void ?{}(T&, Args); })
     42        forall(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(dtype T) {
     62forall(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), ttype Args | { void ?{}(T &, Args); })
     70        forall( | sized(T), Args... | { void ?{}(T &, Args); })
    7171        void ?{}(unique_ptr(T) & this, Args args);
    7272
  • libcfa/src/parseargs.hfa

    r2f47ea4 rfd54fef  
    1414static inline void ?{}( cfa_option & this ) {}
    1515
    16 forall(dtype T | { bool parse(const char *, T & ); })
     16forall(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(dtype T)
     26forall(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

    r2f47ea4 rfd54fef  
    1818#include "stdlib.hfa"
    1919
    20 forall( otype RationalImpl | arithmetic( RationalImpl ) ) {
     20forall( RationalImpl | arithmetic( RationalImpl ) ) {
    2121        // helper routines
    2222
     
    159159        // I/O
    160160
    161         forall( dtype istype | istream( istype ) | { istype & ?|?( istype &, RationalImpl & ); } )
     161        forall( istype & | istream( istype ) | { istype & ?|?( istype &, RationalImpl & ); } )
    162162        istype & ?|?( istype & is, Rational(RationalImpl) & r ) {
    163163                is | r.numerator | r.denominator;
     
    168168        } // ?|?
    169169
    170         forall( dtype ostype | ostream( ostype ) | { ostype & ?|?( ostype &, RationalImpl ); } ) {
     170        forall( 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( otype RationalImpl | arithmetic( RationalImpl ) | { RationalImpl ?\?( RationalImpl, unsigned long ); } )
     181forall( RationalImpl | arithmetic( RationalImpl ) | { RationalImpl ?\?( RationalImpl, unsigned long ); } )
    182182Rational(RationalImpl) ?\?( Rational(RationalImpl) x, long int y ) {
    183183        if ( y < 0 ) {
     
    190190// conversion
    191191
    192 forall( otype RationalImpl | arithmetic( RationalImpl ) | { double convert( RationalImpl ); } )
     192forall( RationalImpl | arithmetic( RationalImpl ) | { double convert( RationalImpl ); } )
    193193double widen( Rational(RationalImpl) r ) {
    194194        return convert( r.numerator ) / convert( r.denominator );
    195195} // widen
    196196
    197 forall( otype RationalImpl | arithmetic( RationalImpl ) | { double convert( RationalImpl ); RationalImpl convert( double ); } )
     197forall( 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

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

    r2f47ea4 rfd54fef  
    2828// Cforall allocation/deallocation and constructor/destructor, array types
    2929
    30 forall( dtype T | sized(T), ttype TT | { void ?{}( T &, TT ); } )
     30forall( T & | sized(T), TT... | { void ?{}( T &, TT ); } )
    3131T * anew( size_t dim, TT p ) {
    3232        T * arr = alloc( dim );
     
    3737} // anew
    3838
    39 forall( dtype T | sized(T) | { void ^?{}( T & ); } )
     39forall( T & | sized(T) | { void ^?{}( T & ); } )
    4040void adelete( T arr[] ) {
    4141        if ( arr ) {                                                                            // ignore null
     
    4848} // adelete
    4949
    50 forall( dtype T | sized(T) | { void ^?{}( T & ); }, ttype TT | { void adelete( TT ); } )
     50forall( T & | sized(T) | { void ^?{}( T & ); }, TT... | { void adelete( TT ); } )
    5151void adelete( T arr[], TT rest ) {
    5252        if ( arr ) {                                                                            // ignore null
     
    9797//---------------------------------------
    9898
    99 forall( otype E | { int ?<?( E, E ); } ) {
     99forall( 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( otype K, otype E | { int ?<?( K, K ); K getKey( const E & ); } ) {
     158forall( K, 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

    r2f47ea4 rfd54fef  
    4848        else return (T *)alignment( _Alignof(T), dim, sizeof(T) )
    4949
    50 static inline forall( dtype T | sized(T) ) {
     50static inline forall( 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( dtype T | sized(T) ) {
     110                forall( 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( dtype T ) {
     153forall( 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( dtype T | sized(T) ) {
     161static inline forall( T & | sized(T) ) {
    162162        S_fill(T) ?`fill ( T t ) {
    163163                S_fill(T) ret = { 't' };
     
    207207        } // $alloc_internal
    208208
    209         forall( ttype TT | { T * $alloc_internal( void *, T *, size_t, size_t, S_fill(T), TT ); } ) {
     209        forall( 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( dtype T | sized(T) ) {
     238static inline forall( 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( dtype T )                                                 // FIX ME, problems with 0p in list
     259static inline forall( T & )                                                     // FIX ME, problems with 0p in list
    260260void free( T * ptr ) {
    261261        free( (void *)ptr );                                                            // C free
    262262} // free
    263 static inline forall( dtype T, ttype TT | { void free( TT ); } )
     263static inline forall( T &, 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( dtype T | sized(T), ttype TT | { void ?{}( T &, TT ); } )
     270static inline forall( T & | sized(T), TT... | { void ?{}( T &, TT ); } )
    271271T * new( TT p ) {
    272272        return &(*(T *)malloc()){ p };                                                  // run constructor
    273273} // new
    274274
    275 static inline forall( dtype T | { void ^?{}( T & ); } )
     275static inline forall( 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( dtype T, ttype TT | { void ^?{}( T & ); void delete( TT ); } )
     283static inline forall( T &, 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( dtype T | sized(T), ttype TT | { void ?{}( T &, TT ); } ) T * anew( size_t dim, TT p );
    291 forall( dtype T | sized(T) | { void ^?{}( T & ); } ) void adelete( T arr[] );
    292 forall( dtype T | sized(T) | { void ^?{}( T & ); }, ttype TT | { void adelete( TT ); } ) void adelete( T arr[], TT rest );
     290forall( T & | sized(T), TT... | { void ?{}( T &, TT ); } ) T * anew( size_t dim, TT p );
     291forall( T & | sized(T) | { void ^?{}( T & ); } ) void adelete( T arr[] );
     292forall( T & | sized(T) | { void ^?{}( T & ); }, TT... | { void adelete( TT ); } ) void adelete( T arr[], TT rest );
    293293
    294294//---------------------------------------
     
    330330//---------------------------------------
    331331
    332 forall( otype E | { int ?<?( E, E ); } ) {
     332forall( 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( otype K, otype E | { int ?<?( K, K ); K getKey( const E & ); } ) {
     341forall( K, 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( otype E | { int ?<?( E, E ); } ) {
     350forall( E | { int ?<?( E, E ); } ) {
    351351        void qsort( E * vals, size_t dim );
    352352} // distribution
  • libcfa/src/time.cfa

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

    r2f47ea4 rfd54fef  
    1818#include <math.hfa>
    1919
    20 trait fromint(otype T) {
     20trait fromint(T) {
    2121    void ?{}(T&, int);
    2222};
    23 trait zeroinit(otype T) {
     23trait zeroinit(T) {
    2424    void ?{}(T&, zero_t);
    2525};
    26 trait zero_assign(otype T) {
     26trait zero_assign(T) {
    2727    T ?=?(T&, zero_t);
    2828};
    29 trait subtract(otype T) {
     29trait subtract(T) {
    3030    T ?-?(T, T);
    3131};
    32 trait negate(otype T) {
     32trait negate(T) {
    3333    T -?(T);
    3434};
    35 trait add(otype T) {
     35trait add(T) {
    3636    T ?+?(T, T);
    3737};
    38 trait multiply(otype T) {
     38trait multiply(T) {
    3939    T ?*?(T, T);
    4040};
    41 trait divide(otype T) {
     41trait divide(T) {
    4242    T ?/?(T, T);
    4343};
    44 trait lessthan(otype T) {
     44trait lessthan(T) {
    4545    int ?<?(T, T);
    4646};
    47 trait equality(otype T) {
     47trait equality(T) {
    4848    int ?==?(T, T);
    4949};
    50 trait sqrt(otype T) {
     50trait sqrt(T) {
    5151    T sqrt(T);
    5252};
     
    6868}
    6969
    70 trait dottable(otype V, otype T) {
     70trait dottable(V, T) {
    7171    T dot(V, V);
    7272};
     
    7474static inline {
    7575
    76 forall(otype T | sqrt(T), otype V | dottable(V, T))
     76forall(T | sqrt(T), V | dottable(V, T))
    7777T length(V v) {
    7878   return sqrt(dot(v, v));
    7979}
    8080
    81 forall(otype T, otype V | dottable(V, T))
     81forall(T, V | dottable(V, T))
    8282T length_squared(V v) {
    8383   return dot(v, v);
    8484}
    8585
    86 forall(otype T, otype V | { T length(V); } | subtract(V))
     86forall(T, V | { T length(V); } | subtract(V))
    8787T distance(V v1, V v2) {
    8888    return length(v1 - v2);
    8989}
    9090
    91 forall(otype T, otype V | { T length(V); V ?/?(V, T); })
     91forall(T, 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(otype T, otype V | dottable(V, T) | { V normalize(V); V ?*?(V, T); })
     97forall(T, 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(otype T | fromint(T), otype V | { V project(V, V); V ?*?(T, V); V ?-?(V,V); })
     104forall(T | fromint(T), 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(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); })
     113forall(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); })
    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(otype T | lessthan(T) | zeroinit(T), otype V | dottable(V, T) | negate(V))
     130forall(T | lessthan(T) | zeroinit(T), 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

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

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

    r2f47ea4 rfd54fef  
    1919#include "vec.hfa"
    2020
    21 forall (otype T) {
     21forall (T) {
    2222    struct vec4 {
    2323        T x, y, z, w;
     
    2525}
    2626
    27 forall (otype T) {
     27forall (T) {
    2828    static inline {
    2929
     
    283283}
    284284
    285 forall(dtype ostype, otype T | writeable(T, ostype)) {
     285forall(ostype &, T | writeable(T, ostype)) {
    286286    ostype & ?|?(ostype & os, vec4(T) v) with (v) {
    287287        return os | '<' | x | ',' | y | ',' | z | ',' | w | '>';
Note: See TracChangeset for help on using the changeset viewer.