Changeset 6b224a52 for src/libcfa


Ignore:
Timestamp:
Aug 25, 2017, 12:11:53 PM (8 years ago)
Author:
Thierry Delisle <tdelisle@…>
Branches:
ADT, aaron-thesis, arm-eh, ast-experimental, cleanup-dtors, deferred_resn, demangler, enum, forall-pointer-decay, jacob/cs343-translation, jenkins-sandbox, master, new-ast, new-ast-unique-expr, new-env, no_list, persistent-indexer, pthread-emulation, qualifiedEnum, resolv-new, with_gc
Children:
bf7b9da7
Parents:
135b431 (diff), f676b84 (diff)
Note: this is a merge changeset, the changes displayed below correspond to the merge itself.
Use the (diff) links above to see all the changes relative to each parent.
Message:

Merge branch 'master' of plg.uwaterloo.ca:software/cfa/cfa-cc

Location:
src/libcfa
Files:
31 edited

Legend:

Unmodified
Added
Removed
  • src/libcfa/concurrency/alarm.c

    r135b431 r6b224a52  
    4040__cfa_time_t zero_time = { 0 };
    4141
    42 void ?{}( __cfa_time_t * this ) { this->val = 0; }
    43 void ?{}( __cfa_time_t * this, zero_t zero ) { this->val = 0; }
    44 
    45 void ?{}( itimerval * this, __cfa_time_t * alarm ) {
    46         this->it_value.tv_sec = alarm->val / one_second;                        // seconds
    47         this->it_value.tv_usec = max( (alarm->val % one_second) / one_microsecond, 1000 ); // microseconds
    48         this->it_interval.tv_sec = 0;
    49         this->it_interval.tv_usec = 0;
    50 }
    51 
    52 
    53 void ?{}( __cfa_time_t * this, timespec * curr ) {
     42void ?{}( __cfa_time_t & this ) { this.val = 0; }
     43void ?{}( __cfa_time_t & this, zero_t zero ) { this.val = 0; }
     44
     45void ?{}( itimerval & this, __cfa_time_t * alarm ) {
     46        this.it_value.tv_sec = alarm->val / one_second;                 // seconds
     47        this.it_value.tv_usec = max( (alarm->val % one_second) / one_microsecond, 1000 ); // microseconds
     48        this.it_interval.tv_sec = 0;
     49        this.it_interval.tv_usec = 0;
     50}
     51
     52
     53void ?{}( __cfa_time_t & this, timespec * curr ) {
    5454        uint64_t secs  = curr->tv_sec;
    5555        uint64_t nsecs = curr->tv_nsec;
    56         this->val = (secs * one_second) + nsecs;
    57 }
    58 
    59 __cfa_time_t ?=?( __cfa_time_t * this, zero_t rhs ) {
    60         this->val = 0;
    61         return *this;
     56        this.val = (secs * one_second) + nsecs;
     57}
     58
     59__cfa_time_t ?=?( __cfa_time_t & this, zero_t rhs ) {
     60        this.val = 0;
     61        return this;
    6262}
    6363
     
    8686//=============================================================================================
    8787
    88 void ?{}( alarm_node_t * this, thread_desc * thrd, __cfa_time_t alarm = zero_time, __cfa_time_t period = zero_time ) {
    89         this->thrd = thrd;
    90         this->alarm = alarm;
    91         this->period = period;
    92         this->next = 0;
    93         this->set = false;
    94         this->kernel_alarm = false;
    95 }
    96 
    97 void ?{}( alarm_node_t * this, processor   * proc, __cfa_time_t alarm = zero_time, __cfa_time_t period = zero_time ) {
    98         this->proc = proc;
    99         this->alarm = alarm;
    100         this->period = period;
    101         this->next = 0;
    102         this->set = false;
    103         this->kernel_alarm = true;
    104 }
    105 
    106 void ^?{}( alarm_node_t * this ) {
    107         if( this->set ) {
    108                 unregister_self( this );
     88void ?{}( alarm_node_t & this, thread_desc * thrd, __cfa_time_t alarm = zero_time, __cfa_time_t period = zero_time ) {
     89        this.thrd = thrd;
     90        this.alarm = alarm;
     91        this.period = period;
     92        this.next = 0;
     93        this.set = false;
     94        this.kernel_alarm = false;
     95}
     96
     97void ?{}( alarm_node_t & this, processor   * proc, __cfa_time_t alarm = zero_time, __cfa_time_t period = zero_time ) {
     98        this.proc = proc;
     99        this.alarm = alarm;
     100        this.period = period;
     101        this.next = 0;
     102        this.set = false;
     103        this.kernel_alarm = true;
     104}
     105
     106void ^?{}( alarm_node_t & this ) {
     107        if( this.set ) {
     108                unregister_self( &this );
    109109        }
    110110}
  • src/libcfa/concurrency/alarm.h

    r135b431 r6b224a52  
    3636
    3737// ctors
    38 void ?{}( __cfa_time_t * this );
    39 void ?{}( __cfa_time_t * this, zero_t zero );
    40 void ?{}( __cfa_time_t * this, timespec * curr );
    41 void ?{}( itimerval * this, __cfa_time_t * alarm );
     38void ?{}( __cfa_time_t & this );
     39void ?{}( __cfa_time_t & this, zero_t zero );
     40void ?{}( __cfa_time_t & this, timespec * curr );
     41void ?{}( itimerval & this, __cfa_time_t * alarm );
    4242
    43 __cfa_time_t ?=?( __cfa_time_t * this, zero_t rhs );
     43__cfa_time_t ?=?( __cfa_time_t & this, zero_t rhs );
    4444
    4545// logical ops
     
    105105typedef alarm_node_t ** __alarm_it_t;
    106106
    107 void ?{}( alarm_node_t * this, thread_desc * thrd, __cfa_time_t alarm = zero_time, __cfa_time_t period = zero_time );
    108 void ?{}( alarm_node_t * this, processor   * proc, __cfa_time_t alarm = zero_time, __cfa_time_t period = zero_time );
    109 void ^?{}( alarm_node_t * this );
     107void ?{}( alarm_node_t & this, thread_desc * thrd, __cfa_time_t alarm = zero_time, __cfa_time_t period = zero_time );
     108void ?{}( alarm_node_t & this, processor   * proc, __cfa_time_t alarm = zero_time, __cfa_time_t period = zero_time );
     109void ^?{}( alarm_node_t & this );
    110110
    111111struct alarm_list_t {
     
    114114};
    115115
    116 static inline void ?{}( alarm_list_t * this ) {
    117         this->head = 0;
    118         this->tail = &this->head;
     116static inline void ?{}( alarm_list_t & this ) {
     117        this.head = 0;
     118        this.tail = &this.head;
    119119}
    120120
  • src/libcfa/concurrency/coroutine

    r135b431 r6b224a52  
    2525// Anything that is resumed is a coroutine.
    2626trait is_coroutine(dtype T) {
    27       void main(T * this);
    28       coroutine_desc * get_coroutine(T * this);
     27      void main(T & this);
     28      coroutine_desc * get_coroutine(T & this);
    2929};
    3030
    31 #define DECL_COROUTINE(X) static inline coroutine_desc* get_coroutine(X* this) { return &this->__cor; } void main(X* this)
     31#define DECL_COROUTINE(X) static inline coroutine_desc* get_coroutine(X& this) { return &this.__cor; } void main(X& this)
    3232
    3333//-----------------------------------------------------------------------------
    3434// Ctors and dtors
    35 void ?{}(coStack_t * this);
    36 void ?{}(coroutine_desc * this);
    37 void ?{}(coroutine_desc * this, const char * name);
    38 void ^?{}(coStack_t * this);
    39 void ^?{}(coroutine_desc * this);
     35void ?{}(coStack_t & this);
     36void ?{}(coroutine_desc & this);
     37void ?{}(coroutine_desc & this, const char * name);
     38void ^?{}(coStack_t & this);
     39void ^?{}(coroutine_desc & this);
    4040
    4141//-----------------------------------------------------------------------------
     
    4444
    4545forall(dtype T | is_coroutine(T))
    46 static inline void resume(T * cor);
     46static inline void resume(T & cor);
    4747
    4848forall(dtype T | is_coroutine(T))
    49 void prime(T * cor);
     49void prime(T & cor);
    5050
    5151//-----------------------------------------------------------------------------
     
    8686// Resume implementation inlined for performance
    8787forall(dtype T | is_coroutine(T))
    88 static inline void resume(T * cor) {
     88static inline void resume(T & cor) {
    8989        coroutine_desc * src = this_coroutine;          // optimization
    9090        coroutine_desc * dst = get_coroutine(cor);
     
    9292        if( unlikely(!dst->stack.base) ) {
    9393                create_stack(&dst->stack, dst->stack.size);
    94                 CtxStart(cor, CtxInvokeCoroutine);
     94                CtxStart(&cor, CtxInvokeCoroutine);
    9595        }
    9696
  • src/libcfa/concurrency/coroutine.c

    r135b431 r6b224a52  
    4040//-----------------------------------------------------------------------------
    4141// Coroutine ctors and dtors
    42 void ?{}(coStack_t* this) {
    43         this->size              = 65000;        // size of stack
    44         this->storage   = NULL; // pointer to stack
    45         this->limit             = NULL; // stack grows towards stack limit
    46         this->base              = NULL; // base of stack
    47         this->context   = NULL; // address of cfa_context_t
    48         this->top               = NULL; // address of top of storage
    49         this->userStack = false;
     42void ?{}(coStack_t& this) {
     43        this.size               = 65000;        // size of stack
     44        this.storage    = NULL; // pointer to stack
     45        this.limit              = NULL; // stack grows towards stack limit
     46        this.base               = NULL; // base of stack
     47        this.context    = NULL; // address of cfa_context_t
     48        this.top                = NULL; // address of top of storage
     49        this.userStack  = false;
    5050}
    5151
    52 void ?{}(coStack_t* this, size_t size) {
     52void ?{}(coStack_t& this, size_t size) {
    5353        this{};
    54         this->size = size;
     54        this.size = size;
    5555
    56         create_stack(this, this->size);
     56        create_stack(&this, this.size);
    5757}
    5858
    59 void ?{}(coroutine_desc* this) {
     59void ?{}(coroutine_desc& this) {
    6060        this{ "Anonymous Coroutine" };
    6161}
    6262
    63 void ?{}(coroutine_desc* this, const char * name) {
    64         this->name = name;
    65         this->errno_ = 0;
    66         this->state = Start;
    67         this->starter = NULL;
    68         this->last = NULL;
     63void ?{}(coroutine_desc& this, const char * name) {
     64        this.name = name;
     65        this.errno_ = 0;
     66        this.state = Start;
     67        this.starter = NULL;
     68        this.last = NULL;
    6969}
    7070
    71 void ?{}(coroutine_desc* this, size_t size) {
     71void ?{}(coroutine_desc& this, size_t size) {
    7272        this{};
    73         (&this->stack){size};
     73        (this.stack){size};
    7474}
    7575
    76 void ^?{}(coStack_t* this) {
    77         if ( ! this->userStack ) {
     76void ^?{}(coStack_t& this) {
     77        if ( ! this.userStack ) {
    7878                LIB_DEBUG_DO(
    79                         if ( mprotect( this->storage, pageSize, PROT_READ | PROT_WRITE ) == -1 ) {
    80                                 abortf( "(coStack_t *)%p.^?{}() : internal error, mprotect failure, error(%d) %s.", this, errno, strerror( errno ) );
     79                        if ( mprotect( this.storage, pageSize, PROT_READ | PROT_WRITE ) == -1 ) {
     80                                abortf( "(coStack_t *)%p.^?{}() : internal error, mprotect failure, error(%d) %s.", &this, errno, strerror( errno ) );
    8181                        }
    8282                );
    83                 free( this->storage );
     83                free( this.storage );
    8484        }
    8585}
    8686
    87 void ^?{}(coroutine_desc* this) {}
     87void ^?{}(coroutine_desc& this) {}
    8888
    8989// Part of the Public API
    9090// Not inline since only ever called once per coroutine
    9191forall(dtype T | is_coroutine(T))
    92 void prime(T* cor) {
     92void prime(T& cor) {
    9393        coroutine_desc* this = get_coroutine(cor);
    9494        assert(this->state == Start);
  • src/libcfa/concurrency/invoke.h

    r135b431 r6b224a52  
    4949      #ifdef __CFORALL__
    5050      extern "Cforall" {
    51             void ?{}( struct __thread_queue_t * );
     51            void ?{}( struct __thread_queue_t & );
    5252            void append( struct __thread_queue_t *, struct thread_desc * );
    5353            struct thread_desc * pop_head( struct __thread_queue_t * );
    5454            struct thread_desc * remove( struct __thread_queue_t *, struct thread_desc ** );
    5555
    56             void ?{}( struct __condition_stack_t * );
     56            void ?{}( struct __condition_stack_t & );
    5757            void push( struct __condition_stack_t *, struct __condition_criterion_t * );
    5858            struct __condition_criterion_t * pop( struct __condition_stack_t * );
    5959
    60             void ?{}(spinlock * this);
    61             void ^?{}(spinlock * this);
     60            void ?{}(spinlock & this);
     61            void ^?{}(spinlock & this);
    6262      }
    6363      #endif
  • src/libcfa/concurrency/kernel

    r135b431 r6b224a52  
    3737};
    3838
    39 void  ?{}(semaphore * this, int count = 1);
    40 void ^?{}(semaphore * this);
     39void  ?{}(semaphore & this, int count = 1);
     40void ^?{}(semaphore & this);
    4141void P(semaphore * this);
    4242void V(semaphore * this);
     
    5151};
    5252
    53 void ?{}(cluster * this);
    54 void ^?{}(cluster * this);
     53void ?{}(cluster & this);
     54void ^?{}(cluster & this);
    5555
    5656//-----------------------------------------------------------------------------
     
    6868        unsigned short thrd_count;
    6969};
    70 static inline void ?{}(FinishAction * this) {
    71         this->action_code = No_Action;
    72         this->thrd = NULL;
    73         this->lock = NULL;
     70static inline void ?{}(FinishAction & this) {
     71        this.action_code = No_Action;
     72        this.thrd = NULL;
     73        this.lock = NULL;
    7474}
    75 static inline void ^?{}(FinishAction * this) {}
     75static inline void ^?{}(FinishAction & this) {}
    7676
    7777// Processor
     
    9999};
    100100
    101 void ?{}(processor * this);
    102 void ?{}(processor * this, cluster * cltr);
    103 void ^?{}(processor * this);
     101void ?{}(processor & this);
     102void ?{}(processor & this, cluster * cltr);
     103void ^?{}(processor & this);
    104104
    105105// Local Variables: //
  • src/libcfa/concurrency/kernel.c

    r135b431 r6b224a52  
    7373};
    7474
    75 void ?{}( current_stack_info_t * this ) {
    76         CtxGet( this->ctx );
    77         this->base = this->ctx.FP;
    78         this->storage = this->ctx.SP;
     75void ?{}( current_stack_info_t & this ) {
     76        CtxGet( this.ctx );
     77        this.base = this.ctx.FP;
     78        this.storage = this.ctx.SP;
    7979
    8080        rlimit r;
    8181        getrlimit( RLIMIT_STACK, &r);
    82         this->size = r.rlim_cur;
    83 
    84         this->limit = (void *)(((intptr_t)this->base) - this->size);
    85         this->context = &storage_mainThreadCtx;
    86         this->top = this->base;
    87 }
    88 
    89 void ?{}( coStack_t * this, current_stack_info_t * info) {
    90         this->size = info->size;
    91         this->storage = info->storage;
    92         this->limit = info->limit;
    93         this->base = info->base;
    94         this->context = info->context;
    95         this->top = info->top;
    96         this->userStack = true;
    97 }
    98 
    99 void ?{}( coroutine_desc * this, current_stack_info_t * info) {
    100         (&this->stack){ info };
    101         this->name = "Main Thread";
    102         this->errno_ = 0;
    103         this->state = Start;
    104 }
    105 
    106 void ?{}( thread_desc * this, current_stack_info_t * info) {
    107         (&this->cor){ info };
     82        this.size = r.rlim_cur;
     83
     84        this.limit = (void *)(((intptr_t)this.base) - this.size);
     85        this.context = &storage_mainThreadCtx;
     86        this.top = this.base;
     87}
     88
     89void ?{}( coStack_t & this, current_stack_info_t * info) {
     90        this.size = info->size;
     91        this.storage = info->storage;
     92        this.limit = info->limit;
     93        this.base = info->base;
     94        this.context = info->context;
     95        this.top = info->top;
     96        this.userStack = true;
     97}
     98
     99void ?{}( coroutine_desc & this, current_stack_info_t * info) {
     100        (this.stack){ info };
     101        this.name = "Main Thread";
     102        this.errno_ = 0;
     103        this.state = Start;
     104}
     105
     106void ?{}( thread_desc & this, current_stack_info_t * info) {
     107        (this.cor){ info };
    108108}
    109109
    110110//-----------------------------------------------------------------------------
    111111// Processor coroutine
    112 void ?{}(processorCtx_t * this, processor * proc) {
    113         (&this->__cor){ "Processor" };
    114         this->proc = proc;
    115         proc->runner = this;
    116 }
    117 
    118 void ?{}(processorCtx_t * this, processor * proc, current_stack_info_t * info) {
    119         (&this->__cor){ info };
    120         this->proc = proc;
    121         proc->runner = this;
    122 }
    123 
    124 void ?{}(processor * this) {
     112void ?{}(processorCtx_t & this, processor * proc) {
     113        (this.__cor){ "Processor" };
     114        this.proc = proc;
     115        proc->runner = &this;
     116}
     117
     118void ?{}(processorCtx_t & this, processor * proc, current_stack_info_t * info) {
     119        (this.__cor){ info };
     120        this.proc = proc;
     121        proc->runner = &this;
     122}
     123
     124void ?{}(processor & this) {
    125125        this{ mainCluster };
    126126}
    127127
    128 void ?{}(processor * this, cluster * cltr) {
    129         this->cltr = cltr;
    130         (&this->terminated){ 0 };
    131         this->do_terminate = false;
    132         this->preemption_alarm = NULL;
    133         this->pending_preemption = false;
    134 
    135         start( this );
    136 }
    137 
    138 void ?{}(processor * this, cluster * cltr, processorCtx_t * runner) {
    139         this->cltr = cltr;
    140         (&this->terminated){ 0 };
    141         this->do_terminate = false;
    142         this->preemption_alarm = NULL;
    143         this->pending_preemption = false;
    144         this->kernel_thread = pthread_self();
    145 
    146         this->runner = runner;
    147         LIB_DEBUG_PRINT_SAFE("Kernel : constructing main processor context %p\n", runner);
    148         runner{ this };
    149 }
    150 
    151 void ^?{}(processor * this) {
    152         if( ! this->do_terminate ) {
    153                 LIB_DEBUG_PRINT_SAFE("Kernel : core %p signaling termination\n", this);
    154                 this->do_terminate = true;
    155                 P( &this->terminated );
    156                 pthread_join( this->kernel_thread, NULL );
    157         }
    158 }
    159 
    160 void ?{}(cluster * this) {
    161         ( &this->ready_queue ){};
    162         ( &this->ready_queue_lock ){};
    163 
    164         this->preemption = default_preemption();
    165 }
    166 
    167 void ^?{}(cluster * this) {
     128void ?{}(processor & this, cluster * cltr) {
     129        this.cltr = cltr;
     130        (this.terminated){ 0 };
     131        this.do_terminate = false;
     132        this.preemption_alarm = NULL;
     133        this.pending_preemption = false;
     134
     135        start( &this );
     136}
     137
     138void ?{}(processor & this, cluster * cltr, processorCtx_t & runner) {
     139        this.cltr = cltr;
     140        (this.terminated){ 0 };
     141        this.do_terminate = false;
     142        this.preemption_alarm = NULL;
     143        this.pending_preemption = false;
     144        this.kernel_thread = pthread_self();
     145
     146        this.runner = &runner;
     147        LIB_DEBUG_PRINT_SAFE("Kernel : constructing main processor context %p\n", &runner);
     148        runner{ &this };
     149}
     150
     151void ^?{}(processor & this) {
     152        if( ! this.do_terminate ) {
     153                LIB_DEBUG_PRINT_SAFE("Kernel : core %p signaling termination\n", &this);
     154                this.do_terminate = true;
     155                P( &this.terminated );
     156                pthread_join( this.kernel_thread, NULL );
     157        }
     158}
     159
     160void ?{}(cluster & this) {
     161        ( this.ready_queue ){};
     162        ( this.ready_queue_lock ){};
     163
     164        this.preemption = default_preemption();
     165}
     166
     167void ^?{}(cluster & this) {
    168168
    169169}
     
    173173//=============================================================================================
    174174//Main of the processor contexts
    175 void main(processorCtx_t * runner) {
    176         processor * this = runner->proc;
     175void main(processorCtx_t & runner) {
     176        processor * this = runner.proc;
    177177
    178178        LIB_DEBUG_PRINT_SAFE("Kernel : core %p starting\n", this);
     
    219219// from the processor coroutine to the target thread
    220220void runThread(processor * this, thread_desc * dst) {
    221         coroutine_desc * proc_cor = get_coroutine(this->runner);
     221        coroutine_desc * proc_cor = get_coroutine(*this->runner);
    222222        coroutine_desc * thrd_cor = get_coroutine(dst);
    223223
     
    301301        // appropriate stack.
    302302        proc_cor_storage.__cor.state = Active;
    303         main( &proc_cor_storage );
     303        main( proc_cor_storage );
    304304        proc_cor_storage.__cor.state = Halted;
    305305
     
    443443        mainThread = (thread_desc *)&storage_mainThread;
    444444        current_stack_info_t info;
    445         mainThread{ &info };
     445        (*mainThread){ &info };
    446446
    447447        LIB_DEBUG_PRINT_SAFE("Kernel : Main thread ready\n");
     
    449449        // Initialize the main cluster
    450450        mainCluster = (cluster *)&storage_mainCluster;
    451         mainCluster{};
     451        (*mainCluster){};
    452452
    453453        LIB_DEBUG_PRINT_SAFE("Kernel : main cluster ready\n");
     
    456456        // (the coroutine that contains the processing control flow)
    457457        mainProcessor = (processor *)&storage_mainProcessor;
    458         mainProcessor{ mainCluster, (processorCtx_t *)&storage_mainProcessorCtx };
     458        (*mainProcessor){ mainCluster, *(processorCtx_t *)&storage_mainProcessorCtx };
    459459
    460460        //initialize the global state variables
     
    473473        // context. Hence, the main thread does not begin through CtxInvokeThread, like all other threads. The trick here is that
    474474        // mainThread is on the ready queue when this call is made.
    475         resume( mainProcessor->runner );
     475        resume( *mainProcessor->runner );
    476476
    477477
     
    501501        // Destroy the main processor and its context in reverse order of construction
    502502        // These were manually constructed so we need manually destroy them
    503         ^(mainProcessor->runner){};
     503        ^(*mainProcessor->runner){};
    504504        ^(mainProcessor){};
    505505
     
    569569//-----------------------------------------------------------------------------
    570570// Locks
    571 void ?{}( spinlock * this ) {
    572         this->lock = 0;
    573 }
    574 void ^?{}( spinlock * this ) {
     571void ?{}( spinlock & this ) {
     572        this.lock = 0;
     573}
     574void ^?{}( spinlock & this ) {
    575575
    576576}
     
    606606}
    607607
    608 void  ?{}( semaphore * this, int count = 1 ) {
    609         (&this->lock){};
    610         this->count = count;
    611         (&this->waiting){};
    612 }
    613 void ^?{}(semaphore * this) {}
     608void  ?{}( semaphore & this, int count = 1 ) {
     609        (this.lock){};
     610        this.count = count;
     611        (this.waiting){};
     612}
     613void ^?{}(semaphore & this) {}
    614614
    615615void P(semaphore * this) {
     
    645645//-----------------------------------------------------------------------------
    646646// Queues
    647 void ?{}( __thread_queue_t * this ) {
    648         this->head = NULL;
    649         this->tail = &this->head;
     647void ?{}( __thread_queue_t & this ) {
     648        this.head = NULL;
     649        this.tail = &this.head;
    650650}
    651651
     
    685685}
    686686
    687 
    688 
    689 void ?{}( __condition_stack_t * this ) {
    690         this->top = NULL;
     687void ?{}( __condition_stack_t & this ) {
     688        this.top = NULL;
    691689}
    692690
  • src/libcfa/concurrency/monitor

    r135b431 r6b224a52  
    2222#include "stdlib"
    2323
    24 static inline void ?{}(monitor_desc * this) {
    25         (&this->lock){};
    26         this->owner = NULL;
    27         (&this->entry_queue){};
    28         (&this->signal_stack){};
    29         this->recursion = 0;
    30         this->acceptables = NULL;
    31         this->acceptable_count = 0;
    32         this->accepted_index = -1;
     24static inline void ?{}(monitor_desc & this) {
     25        (this.lock){};
     26        this.owner = NULL;
     27        (this.entry_queue){};
     28        (this.signal_stack){};
     29        this.recursion = 0;
     30        this.acceptables = NULL;
     31        this.acceptable_count = 0;
     32        this.accepted_index = -1;
    3333}
    3434
     
    4545}
    4646
    47 void ?{}( monitor_guard_t * this, monitor_desc ** m, int count, void (*func)() );
    48 void ^?{}( monitor_guard_t * this );
     47void ?{}( monitor_guard_t & this, monitor_desc ** m, int count );
     48void ^?{}( monitor_guard_t & this );
    4949
    5050//-----------------------------------------------------------------------------
     
    7171};
    7272
    73 void ?{}( __condition_blocked_queue_t * );
     73void ?{}( __condition_blocked_queue_t & );
    7474void append( __condition_blocked_queue_t *, __condition_node_t * );
    7575__condition_node_t * pop_head( __condition_blocked_queue_t * );
     
    8181};
    8282
    83 static inline void ?{}( condition * this ) {
    84         this->monitors = NULL;
    85         this->monitor_count = 0;
     83static inline void ?{}( condition & this ) {
     84        this.monitors = NULL;
     85        this.monitor_count = 0;
    8686}
    8787
    88 static inline void ^?{}( condition * this ) {
    89         free( this->monitors );
     88static inline void ^?{}( condition & this ) {
     89        free( this.monitors );
    9090}
    9191
  • src/libcfa/concurrency/monitor.c

    r135b431 r6b224a52  
    194194// Ctor for monitor guard
    195195// Sorts monitors before entering
    196 void ?{}( monitor_guard_t * this, monitor_desc ** m, int count, void (*func)() ) {
     196void ?{}( monitor_guard_t & this, monitor_desc ** m, int count, void (*func)() ) {
    197197        // Store current array
    198         this->m = m;
    199         this->count = count;
     198        this.m = m;
     199        this.count = count;
    200200
    201201        // Sort monitors based on address -> TODO use a sort specialized for small numbers
    202         qsort(this->m, count);
     202        qsort(this.m, count);
    203203
    204204        // Save previous thread context
    205         this->prev_mntrs = this_thread->current_monitors;
    206         this->prev_count = this_thread->current_monitor_count;
    207         this->prev_func  = this_thread->current_monitor_func;
     205        this.prev_mntrs = this_thread->current_monitors;
     206        this.prev_count = this_thread->current_monitor_count;
     207        this.prev_func  = this_thread->current_monitor_func;
    208208
    209209        // Update thread context (needed for conditions)
     
    213213
    214214        // Enter the monitors in order
    215         enter( this->m, this->count, func );
    216 }
     215        enter( this.m, this.count, func );
     216}
     217
    217218
    218219// Dtor for monitor guard
    219 void ^?{}( monitor_guard_t * this ) {
     220void ^?{}( monitor_guard_t & this ) {
    220221        // Leave the monitors in order
    221         leave( this->m, this->count );
     222        leave( this.m, this.count );
    222223
    223224        // Restore thread context
    224         this_thread->current_monitors      = this->prev_mntrs;
    225         this_thread->current_monitor_count = this->prev_count;
    226         this_thread->current_monitor_func  = this->prev_func;
     225        this_thread->current_monitors      = this.prev_mntrs;
     226        this_thread->current_monitor_count = this.prev_count;
     227        this_thread->current_monitor_func  = this.prev_func;
    227228}
    228229
    229230//-----------------------------------------------------------------------------
    230231// Internal scheduling types
    231 
    232 void ?{}(__condition_node_t * this, thread_desc * waiting_thread, unsigned short count, uintptr_t user_info ) {
    233         this->waiting_thread = waiting_thread;
    234         this->count = count;
    235         this->next = NULL;
    236         this->user_info = user_info;
    237 }
    238 
    239 void ?{}(__condition_criterion_t * this ) {
    240         this->ready  = false;
    241         this->target = NULL;
    242         this->owner  = NULL;
    243         this->next   = NULL;
    244 }
    245 
    246 void ?{}(__condition_criterion_t * this, monitor_desc * target, __condition_node_t * owner ) {
    247         this->ready  = false;
    248         this->target = target;
    249         this->owner  = owner;
    250         this->next   = NULL;
     232void ?{}(__condition_node_t & this, thread_desc * waiting_thread, unsigned short count, uintptr_t user_info ) {
     233        this.waiting_thread = waiting_thread;
     234        this.count = count;
     235        this.next = NULL;
     236        this.user_info = user_info;
     237}
     238
     239void ?{}(__condition_criterion_t & this ) {
     240        this.ready  = false;
     241        this.target = NULL;
     242        this.owner  = NULL;
     243        this.next   = NULL;
     244}
     245
     246void ?{}(__condition_criterion_t & this, monitor_desc * target, __condition_node_t * owner ) {
     247        this.ready  = false;
     248        this.target = target;
     249        this.owner  = owner;
     250        this.next   = NULL;
    251251}
    252252
     
    523523static inline void init( int count, monitor_desc ** monitors, __condition_node_t * waiter, __condition_criterion_t * criteria ) {
    524524        for(int i = 0; i < count; i++) {
    525                 (&criteria[i]){ monitors[i], waiter };
     525                (criteria[i]){ monitors[i], waiter };
    526526        }
    527527
     
    531531static inline void init_push( int count, monitor_desc ** monitors, __condition_node_t * waiter, __condition_criterion_t * criteria ) {
    532532        for(int i = 0; i < count; i++) {
    533                 (&criteria[i]){ monitors[i], waiter };
     533                (criteria[i]){ monitors[i], waiter };
    534534                push( &criteria[i].target->signal_stack, &criteria[i] );
    535535        }
     
    627627        return end + 1;
    628628}
     629
    629630
    630631static inline bool match( __acceptable_t * acc, thread_desc * thrd ) {
     
    660661        return NULL;
    661662}
    662 
    663 void ?{}( __condition_blocked_queue_t * this ) {
    664         this->head = NULL;
    665         this->tail = &this->head;
     663void ?{}( __condition_blocked_queue_t & this ) {
     664        this.head = NULL;
     665        this.tail = &this.head;
    666666}
    667667
  • src/libcfa/concurrency/preemption.c

    r135b431 r6b224a52  
    7171static pthread_t alarm_thread;                        // pthread handle to alarm thread
    7272
    73 void ?{}(event_kernel_t * this) {
    74         (&this->alarms){};
    75         (&this->lock){};
     73void ?{}(event_kernel_t & this) {
     74        (this.alarms){};
     75        (this.lock){};
    7676}
    7777
     
    240240        // Initialize the event kernel
    241241        event_kernel = (event_kernel_t *)&storage_event_kernel;
    242         event_kernel{};
     242        (*event_kernel){};
    243243
    244244        // Setup proper signal handlers
     
    276276// Raii ctor/dtor for the preemption_scope
    277277// Used by thread to control when they want to receive preemption signals
    278 void ?{}( preemption_scope * this, processor * proc ) {
    279         (&this->alarm){ proc, zero_time, zero_time };
    280         this->proc = proc;
    281         this->proc->preemption_alarm = &this->alarm;
    282 
    283         update_preemption( this->proc, from_us(this->proc->cltr->preemption) );
    284 }
    285 
    286 void ^?{}( preemption_scope * this ) {
     278void ?{}( preemption_scope & this, processor * proc ) {
     279        (this.alarm){ proc, zero_time, zero_time };
     280        this.proc = proc;
     281        this.proc->preemption_alarm = &this.alarm;
     282
     283        update_preemption( this.proc, from_us(this.proc->cltr->preemption) );
     284}
     285
     286void ^?{}( preemption_scope & this ) {
    287287        disable_interrupts();
    288288
    289         update_preemption( this->proc, zero_time );
     289        update_preemption( this.proc, zero_time );
    290290}
    291291
  • src/libcfa/concurrency/preemption.h

    r135b431 r6b224a52  
    3030};
    3131
    32 void ?{}( preemption_scope * this, processor * proc );
    33 void ^?{}( preemption_scope * this );
     32void ?{}( preemption_scope & this, processor * proc );
     33void ^?{}( preemption_scope & this );
    3434
    3535// Local Variables: //
  • src/libcfa/concurrency/thread

    r135b431 r6b224a52  
    2727// Anything that is resumed is a coroutine.
    2828trait is_thread(dtype T) {
    29       void ^?{}(T* mutex this);
    30       void main(T* this);
    31       thread_desc* get_thread(T* this);
     29      void ^?{}(T& mutex this);
     30      void main(T& this);
     31      thread_desc* get_thread(T& this);
    3232};
    3333
    34 #define DECL_THREAD(X) thread_desc* get_thread(X* this) { return &this->__thrd; } void main(X* this)
     34#define DECL_THREAD(X) thread_desc* get_thread(X& this) { return &this.__thrd; } void main(X& this)
    3535
    3636forall( dtype T | is_thread(T) )
    37 static inline coroutine_desc* get_coroutine(T* this) {
     37static inline coroutine_desc* get_coroutine(T & this) {
    3838        return &get_thread(this)->cor;
    3939}
    4040
    4141forall( dtype T | is_thread(T) )
    42 static inline monitor_desc* get_monitor(T * this) {
     42static inline monitor_desc* get_monitor(T & this) {
    4343        return &get_thread(this)->mon;
    4444}
     
    5555
    5656forall( dtype T | is_thread(T) )
    57 void __thrd_start( T* this );
     57void __thrd_start( T & this );
    5858
    5959//-----------------------------------------------------------------------------
    6060// Ctors and dtors
    61 void ?{}(thread_desc* this);
    62 void ^?{}(thread_desc* this);
     61void ?{}(thread_desc& this);
     62void ^?{}(thread_desc& this);
    6363
    6464//-----------------------------------------------------------------------------
     
    7070};
    7171
    72 forall( dtype T | sized(T) | is_thread(T) | { void ?{}(T*); } )
    73 void ?{}( scoped(T)* this );
     72forall( dtype T | sized(T) | is_thread(T) | { void ?{}(T&); } )
     73void ?{}( scoped(T)& this );
    7474
    75 forall( dtype T, ttype P | sized(T) | is_thread(T) | { void ?{}(T*, P); } )
    76 void ?{}( scoped(T)* this, P params );
     75forall( dtype T, ttype P | sized(T) | is_thread(T) | { void ?{}(T&, P); } )
     76void ?{}( scoped(T)& this, P params );
    7777
    7878forall( dtype T | sized(T) | is_thread(T) )
    79 void ^?{}( scoped(T)* this );
     79void ^?{}( scoped(T)& this );
    8080
    8181void yield();
  • src/libcfa/concurrency/thread.c

    r135b431 r6b224a52  
    3232// Thread ctors and dtors
    3333
    34 void ?{}(thread_desc* this) {
    35         (&this->cor){};
    36         this->cor.name = "Anonymous Coroutine";
    37         this->mon.owner = this;
    38         this->mon.recursion = 1;
    39         this->next = NULL;
     34void ?{}(thread_desc& this) {
     35        (this.cor){};
     36        this.cor.name = "Anonymous Coroutine";
     37        this.mon.owner = &this;
     38        this.mon.recursion = 1;
     39        this.next = NULL;
    4040
    41         this->current_monitors      = &this->mon;
    42         this->current_monitor_count = 1;
     41        this.current_monitors      = &this.mon;
     42        this.current_monitor_count = 1;
    4343}
    4444
    45 void ^?{}(thread_desc* this) {
    46         ^(&this->cor){};
     45void ^?{}(thread_desc& this) {
     46        ^(this.cor){};
    4747}
    4848
    49 forall( dtype T | sized(T) | is_thread(T) | { void ?{}(T*); } )
    50 void ?{}( scoped(T)* this ) {
    51         (&this->handle){};
    52         __thrd_start(&this->handle);
     49forall( dtype T | sized(T) | is_thread(T) | { void ?{}(T&); } )
     50void ?{}( scoped(T)& this ) {
     51        (this.handle){};
     52        __thrd_start(this.handle);
    5353}
    5454
    55 forall( dtype T, ttype P | sized(T) | is_thread(T) | { void ?{}(T*, P); } )
    56 void ?{}( scoped(T)* this, P params ) {
    57         (&this->handle){ params };
    58         __thrd_start(&this->handle);
     55forall( dtype T, ttype P | sized(T) | is_thread(T) | { void ?{}(T&, P); } )
     56void ?{}( scoped(T)& this, P params ) {
     57        (this.handle){ params };
     58        __thrd_start(this.handle);
    5959}
    6060
    6161forall( dtype T | sized(T) | is_thread(T) )
    62 void ^?{}( scoped(T)* this ) {
    63         ^(&this->handle){};
     62void ^?{}( scoped(T)& this ) {
     63        ^(this.handle){};
    6464}
    6565
     
    6767// Starting and stopping threads
    6868forall( dtype T | is_thread(T) )
    69 void __thrd_start( T* this ) {
     69void __thrd_start( T& this ) {
    7070        coroutine_desc* thrd_c = get_coroutine(this);
    7171        thread_desc*  thrd_h = get_thread   (this);
     
    7777        create_stack(&thrd_c->stack, thrd_c->stack.size);
    7878        this_coroutine = thrd_c;
    79         CtxStart(this, CtxInvokeThread);
     79        CtxStart(&this, CtxInvokeThread);
    8080        assert( thrd_c->last->stack.context );
    8181        CtxSwitch( thrd_c->last->stack.context, thrd_c->stack.context );
  • src/libcfa/containers/maybe

    r135b431 r6b224a52  
    2727
    2828forall(otype T)
    29 void ?{}(maybe(T) * this);
     29void ?{}(maybe(T) & this);
    3030
    3131forall(otype T)
    32 void ?{}(maybe(T) * this, T value);
     32void ?{}(maybe(T) & this, T value);
    3333
    3434forall(otype T)
    35 void ?{}(maybe(T) * this, maybe(T) other);
     35void ?{}(maybe(T) & this, maybe(T) other);
    3636
    3737forall(otype T)
    38 void ^?{}(maybe(T) * this);
     38void ^?{}(maybe(T) & this);
    3939
    4040forall(otype T)
    41 maybe(T) ?=?(maybe(T) * this, maybe(T) other);
     41maybe(T) ?=?(maybe(T) & this, maybe(T) other);
    4242
    4343forall(otype T)
  • src/libcfa/containers/maybe.c

    r135b431 r6b224a52  
    1919
    2020forall(otype T)
    21 void ?{}(maybe(T) * this) {
    22         this->has_value = false;
     21void ?{}(maybe(T) & this) {
     22        this.has_value = false;
    2323}
    2424
    2525forall(otype T)
    26 void ?{}(maybe(T) * this, T value) {
    27         this->has_value = true;
    28         (&this->value){value};
     26void ?{}(maybe(T) & this, T value) {
     27        this.has_value = true;
     28        (this.value){value};
    2929}
    3030
    3131forall(otype T)
    32 void ?{}(maybe(T) * this, maybe(T) other) {
    33         this->has_value = other.has_value;
     32void ?{}(maybe(T) & this, maybe(T) other) {
     33        this.has_value = other.has_value;
    3434        if (other.has_value) {
    35                 (&this->value){other.value};
     35                (this.value){other.value};
    3636        }
    3737}
    3838
    3939forall(otype T)
    40 maybe(T) ?=?(maybe(T) * this, maybe(T) that) {
    41         if (this->has_value & that.has_value) {
    42                 this->value = that.value;
    43         } else if (this->has_value) {
    44                 ^(&this->value){};
    45                 this->has_value = false;
     40maybe(T) ?=?(maybe(T) & this, maybe(T) that) {
     41        if (this.has_value & that.has_value) {
     42                this.value = that.value;
     43        } else if (this.has_value) {
     44                ^(this.value){};
     45                this.has_value = false;
    4646        } else if (that.has_value) {
    47                 this->has_value = true;
    48                 (&this->value){that.value};
     47                this.has_value = true;
     48                (this.value){that.value};
    4949        }
     50        return this;
    5051}
    5152
    5253forall(otype T)
    53 void ^?{}(maybe(T) * this) {
    54         if (this->has_value) {
    55                 ^(&this->value){};
     54void ^?{}(maybe(T) & this) {
     55        if (this.has_value) {
     56                ^(this.value){};
    5657        }
    5758}
     
    8990        } else {
    9091                this->has_value = true;
    91                 (&this->value){value};
     92                (this->value){value};
    9293        }
    9394}
     
    9798        if (this->has_value) {
    9899                this->has_value = false;
    99                 ^(&this->value){};
     100                ^(this->value){};
    100101        }
    101102}
  • src/libcfa/containers/result

    r135b431 r6b224a52  
    3333
    3434forall(otype T, otype E)
    35 void ?{}(result(T, E) * this);
     35void ?{}(result(T, E) & this);
    3636
    3737forall(otype T, otype E)
    38 void ?{}(result(T, E) * this, one_t, T value);
     38void ?{}(result(T, E) & this, one_t, T value);
    3939
    4040forall(otype T, otype E)
    41 void ?{}(result(T, E) * this, zero_t, E error);
     41void ?{}(result(T, E) & this, zero_t, E error);
    4242
    4343forall(otype T, otype E)
    44 void ?{}(result(T, E) * this, result(T, E) other);
     44void ?{}(result(T, E) & this, result(T, E) other);
    4545
    4646forall(otype T, otype E)
    47 void ^?{}(result(T, E) * this);
     47void ^?{}(result(T, E) & this);
    4848
    4949forall(otype T, otype E)
    50 result(T, E) ?=?(result(T, E) * this, result(T, E) other);
     50result(T, E) ?=?(result(T, E) & this, result(T, E) other);
    5151
    5252forall(otype T, otype E)
  • src/libcfa/containers/result.c

    r135b431 r6b224a52  
    1919
    2020forall(otype T, otype E)
    21 void ?{}(result(T, E) * this) {
    22         this->has_value = false;
    23         (&this->error){};
     21void ?{}(result(T, E) & this) {
     22        this.has_value = false;
     23        (this.error){};
    2424}
    2525
    2626forall(otype T, otype E)
    27 void ?{}(result(T, E) * this, one_t, T value) {
    28         this->has_value = true;
    29         (&this->value){value};
     27void ?{}(result(T, E) & this, one_t, T value) {
     28        this.has_value = true;
     29        (this.value){value};
    3030}
    3131
    3232forall(otype T, otype E)
    33 void ?{}(result(T, E) * this, zero_t, E error) {
    34         this->has_value = false;
    35         (&this->error){error};
     33void ?{}(result(T, E) & this, zero_t, E error) {
     34        this.has_value = false;
     35        (this.error){error};
    3636}
    3737
    3838forall(otype T, otype E)
    39 void ?{}(result(T, E) * this, result(T, E) other) {
    40         this->has_value = other.has_value;
     39void ?{}(result(T, E) & this, result(T, E) other) {
     40        this.has_value = other.has_value;
    4141        if (other.has_value) {
    42                 (&this->value){other.value};
     42                (this.value){other.value};
    4343        } else {
    44                 (&this->error){other.error};
     44                (this.error){other.error};
    4545        }
    4646}
    4747
    4848forall(otype T, otype E)
    49 result(T, E) ?=?(result(T, E) * this, result(T, E) that) {
    50         if (this->has_value & that.has_value) {
    51                 this->value = that.value;
    52         } else if (this->has_value) {
    53                 ^(&this->value){};
    54                 this->has_value = false;
    55                 (&this->error){that.error};
     49result(T, E) ?=?(result(T, E) & this, result(T, E) that) {
     50        if (this.has_value & that.has_value) {
     51                this.value = that.value;
     52        } else if (this.has_value) {
     53                ^(this.value){};
     54                this.has_value = false;
     55                (this.error){that.error};
    5656        } else if (that.has_value) {
    57                 ^(&this->error){};
    58                 this->has_value = true;
    59                 (&this->value){that.value};
     57                ^(this.error){};
     58                this.has_value = true;
     59                (this.value){that.value};
    6060        } else {
    61                 this->error = that.error;
     61                this.error = that.error;
    6262        }
    6363}
    6464
    6565forall(otype T, otype E)
    66 void ^?{}(result(T, E) * this) {
    67         if (this->has_value) {
    68                 ^(&this->value){};
     66void ^?{}(result(T, E) & this) {
     67        if (this.has_value) {
     68                ^(this.value){};
    6969        } else {
    70                 ^(&this->error){};
     70                ^(this.error){};
    7171        }
    7272}
     
    109109                this->value = value;
    110110        } else {
    111                 ^(&this->error){};
     111                ^(this->error){};
    112112                this->has_value = true;
    113                 (&this->value){value};
     113                (this->value){value};
    114114        }
    115115}
     
    118118void set_error(result(T, E) * this, E error) {
    119119        if (this->has_value) {
    120                 ^(&this->value){};
     120                ^(this->value){};
    121121                this->has_value = false;
    122                 (&this->error){error};
     122                (this->error){error};
    123123        } else {
    124124                this->error = error;
  • src/libcfa/containers/vector

    r135b431 r6b224a52  
    3030
    3131forall(otype T)
    32 void ?{}(heap_allocator(T)* this);
     32void ?{}(heap_allocator(T)& this);
    3333
    3434forall(otype T)
    35 void ?{}(heap_allocator(T)* this, heap_allocator(T) rhs);
     35void ?{}(heap_allocator(T)& this, heap_allocator(T) rhs);
    3636
    3737forall(otype T)
    38 heap_allocator(T) ?=?(heap_allocator(T)* this, heap_allocator(T) rhs);
     38heap_allocator(T) ?=?(heap_allocator(T)& this, heap_allocator(T) rhs);
    3939
    4040forall(otype T)
    41 void ^?{}(heap_allocator(T)* this);
     41void ^?{}(heap_allocator(T)& this);
    4242
    4343forall(otype T)
     
    6464//Initialization
    6565forall(otype T, otype allocator_t | allocator_c(T, allocator_t))
    66 void ?{}(vector(T, allocator_t)* this);
     66void ?{}(vector(T, allocator_t)& this);
    6767
    6868forall(otype T, otype allocator_t | allocator_c(T, allocator_t))
    69 void ?{}(vector(T, allocator_t)* this, vector(T, allocator_t) rhs);
     69void ?{}(vector(T, allocator_t)& this, vector(T, allocator_t) rhs);
    7070
    7171forall(otype T, otype allocator_t | allocator_c(T, allocator_t))
    72 vector(T, allocator_t) ?=?(vector(T, allocator_t)* this, vector(T, allocator_t) rhs);
     72vector(T, allocator_t) ?=?(vector(T, allocator_t)& this, vector(T, allocator_t) rhs);
    7373
    7474forall(otype T, otype allocator_t | allocator_c(T, allocator_t))
    75 void ^?{}(vector(T, allocator_t)* this);
     75void ^?{}(vector(T, allocator_t)& this);
    7676
    7777forall(otype T, otype allocator_t = heap_allocator(T) | allocator_c(T, allocator_t))
  • src/libcfa/containers/vector.c

    r135b431 r6b224a52  
    2424//Initialization
    2525forall(otype T, otype allocator_t | allocator_c(T, allocator_t))
    26 void ?{}(vector(T, allocator_t)* this)
     26void ?{}(vector(T, allocator_t)& this)
    2727{
    28         (&this->storage){};
    29         this->size = 0;
     28        (this.storage){};
     29        this.size = 0;
    3030}
    3131
    3232forall(otype T, otype allocator_t | allocator_c(T, allocator_t))
    33 void ?{}(vector(T, allocator_t)* this, vector(T, allocator_t) rhs)
     33void ?{}(vector(T, allocator_t)& this, vector(T, allocator_t) rhs)
    3434{
    35         (&this->storage){ rhs.storage };
    36         copy_internal(this, &rhs);
     35        (this.storage){ rhs.storage };
     36        copy_internal(&this, &rhs);
    3737}
    3838
     
    4646
    4747forall(otype T, otype allocator_t | allocator_c(T, allocator_t))
    48 void ^?{}(vector(T, allocator_t)* this)
     48void ^?{}(vector(T, allocator_t)& this)
    4949{
    50         clear(this);
    51         ^(&this->storage){};
     50        clear(&this);
     51        ^(this.storage){};
    5252}
    5353
     
    6666{
    6767        this->size--;
    68         ^(&data(&this->storage)[this->size]){};
     68        ^(data(&this->storage)[this->size]){};
    6969}
    7070
     
    7474        for(size_t i = 0; i < this->size; i++)
    7575        {
    76                 ^(&data(&this->storage)[this->size]){};
     76                ^(data(&this->storage)[this->size]){};
    7777        }
    7878        this->size = 0;
     
    8787        this->size = other->size;
    8888        for(size_t i = 0; i < this->size; i++) {
    89                 (&data(&this->storage)[this->size]){ data(&other->storage)[other->size] };
     89                (data(&this->storage)[this->size]){ data(&other->storage)[other->size] };
    9090        }
    9191}
     
    9494//Allocator
    9595forall(otype T)
    96 void ?{}(heap_allocator(T)* this)
     96void ?{}(heap_allocator(T)& this)
    9797{
    98         this->storage = 0;
    99         this->capacity = 0;
     98        this.storage = 0;
     99        this.capacity = 0;
    100100}
    101101
    102102forall(otype T)
    103 void ?{}(heap_allocator(T)* this, heap_allocator(T) rhs)
     103void ?{}(heap_allocator(T)& this, heap_allocator(T) rhs)
    104104{
    105         this->capacity = rhs.capacity;
    106         this->storage = (T*)realloc((void*)this->storage, this->capacity * sizeof(T));
     105        this.capacity = rhs.capacity;
     106        this.storage = (T*)realloc((void*)this.storage, this.capacity * sizeof(T));
    107107}
    108108
    109109forall(otype T)
    110 heap_allocator(T) ?=?(heap_allocator(T)* this, heap_allocator(T) rhs)
     110heap_allocator(T) ?=?(heap_allocator(T)& this, heap_allocator(T) rhs)
    111111{
    112         this->capacity = rhs.capacity;
    113         this->storage = (T*)realloc((void*)this->storage, this->capacity * sizeof(T));
    114         return *this;
     112        this.capacity = rhs.capacity;
     113        this.storage = (T*)realloc((void*)this.storage, this.capacity * sizeof(T));
     114        return this;
    115115}
    116116
    117117forall(otype T)
    118 void ^?{}(heap_allocator(T)* this)
     118void ^?{}(heap_allocator(T)& this)
    119119{
    120         free(this->storage);
     120        free(this.storage);
    121121}
    122122
  • src/libcfa/exception.h

    r135b431 r6b224a52  
    2929                     struct __cfaehm__base_exception_t * other);
    3030        void (*free)(struct __cfaehm__base_exception_t *this);
    31         const char (*msg)(struct __cfaehm__base_exception_t *this);
     31        const char * (*msg)(struct __cfaehm__base_exception_t *this);
    3232};
    3333struct __cfaehm__base_exception_t {
  • src/libcfa/fstream

    r135b431 r6b224a52  
    5656int fmt( ofstream *, const char fmt[], ... );
    5757
    58 void ?{}( ofstream * );
     58void ?{}( ofstream & );
    5959
    6060extern ofstream * sout, * serr;
  • src/libcfa/fstream.c

    r135b431 r6b224a52  
    2727#define IO_MSG "I/O error: "
    2828
    29 void ?{}( ofstream * this, void * file, _Bool sepDefault, _Bool sepOnOff, const char * separator, const char * tupleSeparator ) {
    30         this->file = file;
    31         this->sepDefault = sepDefault;
    32         this->sepOnOff = sepOnOff;
    33         sepSet( this, separator );
    34         sepSetCur( this, sepGet( this ) );
    35         sepSetTuple( this, tupleSeparator );
     29void ?{}( ofstream & this, void * file, _Bool sepDefault, _Bool sepOnOff, const char * separator, const char * tupleSeparator ) {
     30        this.file = file;
     31        this.sepDefault = sepDefault;
     32        this.sepOnOff = sepOnOff;
     33        sepSet( &this, separator );
     34        sepSetCur( &this, sepGet( &this ) );
     35        sepSetTuple( &this, tupleSeparator );
    3636}
    3737
     
    9292                exit( EXIT_FAILURE );
    9393        } // if
    94         ?{}( os, file, true, false, " ", ", " );
     94        ?{}( *os, file, true, false, " ", ", " );
    9595} // open
    9696
  • src/libcfa/gmp

    r135b431 r6b224a52  
    1 // 
     1//
    22// Cforall Version 1.0.0 Copyright (C) 2016 University of Waterloo
    33//
    44// The contents of this file are covered under the licence agreement in the
    55// file "LICENCE" distributed with Cforall.
    6 // 
    7 // gmp -- 
    8 // 
     6//
     7// gmp --
     8//
    99// Author           : Peter A. Buhr
    1010// Created On       : Tue Apr 19 08:43:43 2016
    1111// Last Modified By : Peter A. Buhr
    12 // Last Modified On : Fri Jul  7 09:33:20 2017
    13 // Update Count     : 15
    14 // 
     12// Last Modified On : Thu Aug 24 09:24:51 2017
     13// Update Count     : 16
     14//
    1515
    1616// https://gmplib.org/gmp-man-6.1.1.pdf
     
    2424
    2525// constructor
    26 static inline void ?{}( Int * this ) { mpz_init( this->mpz ); }
    27 static inline void ?{}( Int * this, Int init ) { mpz_init_set( this->mpz, init.mpz ); }
    28 static inline void ?{}( Int * this, zero_t ) { mpz_init_set_si( this->mpz, 0 ); }
    29 static inline void ?{}( Int * this, one_t ) { mpz_init_set_si( this->mpz, 1 ); }
    30 static inline void ?{}( Int * this, signed long int init ) { mpz_init_set_si( this->mpz, init ); }
    31 static inline void ?{}( Int * this, unsigned long int init ) { mpz_init_set_ui( this->mpz, init ); }
    32 static inline void ?{}( Int * this, const char * val ) { if ( mpz_init_set_str( this->mpz, val, 0 ) ) abort(); }
    33 static inline void ^?{}( Int * this ) { mpz_clear( this->mpz ); }
     26static inline void ?{}( Int & this ) { mpz_init( this.mpz ); }
     27static inline void ?{}( Int & this, Int init ) { mpz_init_set( this.mpz, init.mpz ); }
     28static inline void ?{}( Int & this, zero_t ) { mpz_init_set_si( this.mpz, 0 ); }
     29static inline void ?{}( Int & this, one_t ) { mpz_init_set_si( this.mpz, 1 ); }
     30static inline void ?{}( Int & this, signed long int init ) { mpz_init_set_si( this.mpz, init ); }
     31static inline void ?{}( Int & this, unsigned long int init ) { mpz_init_set_ui( this.mpz, init ); }
     32static inline void ?{}( Int & this, const char * val ) { if ( mpz_init_set_str( this.mpz, val, 0 ) ) abort(); }
     33static inline void ^?{}( Int & this ) { mpz_clear( this.mpz ); }
    3434
    3535// assignment
    36 static inline Int ?=?( Int * lhs, Int rhs ) { mpz_set( lhs->mpz, rhs.mpz ); return *lhs; }
    37 static inline Int ?=?( Int * lhs, long int rhs ) { mpz_set_si( lhs->mpz, rhs ); return *lhs; }
    38 static inline Int ?=?( Int * lhs, unsigned long int rhs ) { mpz_set_ui( lhs->mpz, rhs ); return *lhs; }
    39 static inline Int ?=?( Int * lhs, const char * rhs ) { if ( mpz_set_str( lhs->mpz, rhs, 0 ) ) { printf( "invalid string conversion\n" ); abort(); } return *lhs; }
    40 
    41 static inline char ?=?( char * lhs, Int rhs ) { char val = mpz_get_si( rhs.mpz ); *lhs = val; return val; }
    42 static inline short int ?=?( short int * lhs, Int rhs ) { short int val = mpz_get_si( rhs.mpz ); *lhs = val; return val; }
    43 static inline int ?=?( int * lhs, Int rhs ) { int val = mpz_get_si( rhs.mpz ); *lhs = val; return val; }
    44 static inline long int ?=?( long int * lhs, Int rhs ) { long int val = mpz_get_si( rhs.mpz ); *lhs = val; return val; }
    45 static inline unsigned char ?=?( unsigned char * lhs, Int rhs ) { unsigned char val = mpz_get_ui( rhs.mpz ); *lhs = val; return val; }
    46 static inline unsigned short int ?=?( unsigned short int * lhs, Int rhs ) { unsigned short int val = mpz_get_ui( rhs.mpz ); *lhs = val; return val; }
    47 static inline unsigned int ?=?( unsigned int * lhs, Int rhs ) { unsigned int val = mpz_get_ui( rhs.mpz ); *lhs = val; return val; }
    48 static inline unsigned long int ?=?( unsigned long int * lhs, Int rhs ) { unsigned long int val = mpz_get_ui( rhs.mpz ); *lhs = val; return val; }
     36static inline Int ?=?( Int & lhs, Int rhs ) { mpz_set( lhs.mpz, rhs.mpz ); return lhs; }
     37static inline Int ?=?( Int & lhs, long int rhs ) { mpz_set_si( lhs.mpz, rhs ); return lhs; }
     38static inline Int ?=?( Int & lhs, unsigned long int rhs ) { mpz_set_ui( lhs.mpz, rhs ); return lhs; }
     39static inline Int ?=?( Int & lhs, const char * rhs ) { if ( mpz_set_str( lhs.mpz, rhs, 0 ) ) { printf( "invalid string conversion\n" ); abort(); } return lhs; }
     40
     41static inline char ?=?( char & lhs, Int rhs ) { char val = mpz_get_si( rhs.mpz ); lhs = val; return lhs; }
     42static inline short int ?=?( short int & lhs, Int rhs ) { short int val = mpz_get_si( rhs.mpz ); lhs = val; return lhs; }
     43static inline int ?=?( int & lhs, Int rhs ) { int val = mpz_get_si( rhs.mpz ); lhs = val; return lhs; }
     44static inline long int ?=?( long int & lhs, Int rhs ) { long int val = mpz_get_si( rhs.mpz ); lhs = val; return lhs; }
     45static inline unsigned char ?=?( unsigned char & lhs, Int rhs ) { unsigned char val = mpz_get_ui( rhs.mpz ); lhs = val; return lhs; }
     46static inline unsigned short int ?=?( unsigned short int & lhs, Int rhs ) { unsigned short int val = mpz_get_ui( rhs.mpz ); lhs = val; return lhs; }
     47static inline unsigned int ?=?( unsigned int & lhs, Int rhs ) { unsigned int val = mpz_get_ui( rhs.mpz ); lhs = val; return lhs; }
     48static inline unsigned long int ?=?( unsigned long int & lhs, Int rhs ) { unsigned long int val = mpz_get_ui( rhs.mpz ); lhs = val; return lhs; }
    4949
    5050// conversions
     
    9999static inline Int ?&?( Int oper1, unsigned long int oper2 ) { Int conjunction, temp; mpz_set_ui( temp.mpz, oper2 ); mpz_and( conjunction.mpz, oper1.mpz, temp.mpz ); return conjunction; }
    100100static inline Int ?&?( unsigned long int oper1, Int oper2 ) { Int conjunction, temp; mpz_set_ui( temp.mpz, oper1 ); mpz_and( conjunction.mpz, temp.mpz, oper2.mpz ); return conjunction; }
    101 static inline Int ?&=?( Int * lhs, Int rhs ) { return *lhs = *lhs & rhs; }
     101static inline Int ?&=?( Int & lhs, Int rhs ) { return lhs = lhs & rhs; }
    102102
    103103static inline Int ?|?( Int oper1, Int oper2 ) { Int disjunction; mpz_ior( disjunction.mpz, oper1.mpz, oper2.mpz ); return disjunction; }
     
    106106static inline Int ?|?( Int oper1, unsigned long int oper2 ) { Int disjunction, temp; mpz_set_ui( temp.mpz, oper2 ); mpz_ior( disjunction.mpz, oper1.mpz, temp.mpz ); return disjunction; }
    107107static inline Int ?|?( unsigned long int oper1, Int oper2 ) { Int disjunction, temp; mpz_set_ui( temp.mpz, oper1 ); mpz_ior( disjunction.mpz, temp.mpz, oper2.mpz ); return disjunction; }
    108 static inline Int ?|=?( Int * lhs, Int rhs ) { return *lhs = *lhs | rhs; }
     108static inline Int ?|=?( Int & lhs, Int rhs ) { return lhs = lhs | rhs; }
    109109
    110110static inline Int ?^?( Int oper1, Int oper2 ) { Int disjunction; mpz_xor( disjunction.mpz, oper1.mpz, oper2.mpz ); return disjunction; }
     
    113113static inline Int ?^?( Int oper1, unsigned long int oper2 ) { Int disjunction, temp; mpz_set_ui( temp.mpz, oper2 ); mpz_ior( disjunction.mpz, oper1.mpz, temp.mpz ); return disjunction; }
    114114static inline Int ?^?( unsigned long int oper1, Int oper2 ) { Int disjunction, temp; mpz_set_ui( temp.mpz, oper1 ); mpz_ior( disjunction.mpz, temp.mpz, oper2.mpz ); return disjunction; }
    115 static inline Int ?^=?( Int * lhs, Int rhs ) { return *lhs = *lhs ^ rhs; }
     115static inline Int ?^=?( Int & lhs, Int rhs ) { return lhs = lhs ^ rhs; }
    116116
    117117static inline Int ?+?( Int addend1, Int addend2 ) { Int sum; mpz_add( sum.mpz, addend1.mpz, addend2.mpz ); return sum; }
     
    120120static inline Int ?+?( Int addend1, unsigned long int addend2 ) { Int sum; mpz_add_ui( sum.mpz, addend1.mpz, addend2 ); return sum; }
    121121static inline Int ?+?( unsigned long int addend2, Int addend1 ) { Int sum; mpz_add_ui( sum.mpz, addend1.mpz, addend2 ); return sum; }
    122 static inline Int ?+=?( Int * lhs, Int rhs ) { return *lhs = *lhs + rhs; }
    123 static inline Int ?+=?( Int * lhs, long int rhs ) { return *lhs = *lhs + rhs; }
    124 static inline Int ?+=?( Int * lhs, unsigned long int rhs ) { return *lhs = *lhs + rhs; }
    125 static inline Int ++?( Int * lhs ) { return *lhs += 1; }
    126 static inline Int ?++( Int * lhs ) { Int ret = *lhs; *lhs += 1; return ret; }
     122static inline Int ?+=?( Int & lhs, Int rhs ) { return lhs = lhs + rhs; }
     123static inline Int ?+=?( Int & lhs, long int rhs ) { return lhs = lhs + rhs; }
     124static inline Int ?+=?( Int & lhs, unsigned long int rhs ) { return lhs = lhs + rhs; }
     125static inline Int ++?( Int & lhs ) { return lhs += 1; }
     126static inline Int ?++( Int & lhs ) { Int ret = lhs; lhs += 1; return ret; }
    127127
    128128static inline Int ?-?( Int minuend, Int subtrahend ) { Int diff; mpz_sub( diff.mpz, minuend.mpz, subtrahend.mpz ); return diff; }
     
    131131static inline Int ?-?( Int minuend, unsigned long int subtrahend ) { Int diff; mpz_sub_ui( diff.mpz, minuend.mpz, subtrahend ); return diff; }
    132132static inline Int ?-?( unsigned long int minuend, Int subtrahend ) { Int diff; mpz_ui_sub( diff.mpz, minuend, subtrahend.mpz ); return diff; }
    133 static inline Int ?-=?( Int * lhs, Int rhs ) { return *lhs = *lhs - rhs; }
    134 static inline Int ?-=?( Int * lhs, long int rhs ) { return *lhs = *lhs - rhs; }
    135 static inline Int ?-=?( Int * lhs, unsigned long int rhs ) { return *lhs = *lhs - rhs; }
    136 static inline Int --?( Int * lhs ) { return *lhs -= 1; }
    137 static inline Int ?--( Int * lhs ) { Int ret = *lhs; *lhs -= 1; return ret; }
     133static inline Int ?-=?( Int & lhs, Int rhs ) { return lhs = lhs - rhs; }
     134static inline Int ?-=?( Int & lhs, long int rhs ) { return lhs = lhs - rhs; }
     135static inline Int ?-=?( Int & lhs, unsigned long int rhs ) { return lhs = lhs - rhs; }
     136static inline Int --?( Int & lhs ) { return lhs -= 1; }
     137static inline Int ?--( Int & lhs ) { Int ret = lhs; lhs -= 1; return ret; }
    138138
    139139static inline Int ?*?( Int multiplicator, Int multiplicand ) { Int product; mpz_mul( product.mpz, multiplicator.mpz, multiplicand.mpz ); return product; }
     
    142142static inline Int ?*?( Int multiplicator, unsigned long int multiplicand ) { Int product; mpz_mul_ui( product.mpz, multiplicator.mpz, multiplicand ); return product; }
    143143static inline Int ?*?( unsigned long int multiplicand, Int multiplicator ) { Int product; mpz_mul_ui( product.mpz, multiplicator.mpz, multiplicand ); return product; }
    144 static inline Int ?*=?( Int * lhs, Int rhs ) { return *lhs = *lhs * rhs; }
    145 static inline Int ?*=?( Int * lhs, long int rhs ) { return *lhs = *lhs * rhs; }
    146 static inline Int ?*=?( Int * lhs, unsigned long int rhs ) { return *lhs = *lhs * rhs; }
     144static inline Int ?*=?( Int & lhs, Int rhs ) { return lhs = lhs * rhs; }
     145static inline Int ?*=?( Int & lhs, long int rhs ) { return lhs = lhs * rhs; }
     146static inline Int ?*=?( Int & lhs, unsigned long int rhs ) { return lhs = lhs * rhs; }
    147147
    148148// some code for operators "/" and "%" taken from g++ gmpxx.h
     
    187187        return quotient;
    188188} // ?/?
    189 static inline Int ?/=?( Int * lhs, Int rhs ) { return *lhs = *lhs / rhs; }
    190 static inline Int ?/=?( Int * lhs, long int rhs ) { return *lhs = *lhs / rhs; }
    191 static inline Int ?/=?( Int * lhs, unsigned long int rhs ) { return *lhs = *lhs / rhs; }
     189static inline Int ?/=?( Int & lhs, Int rhs ) { return lhs = lhs / rhs; }
     190static inline Int ?/=?( Int & lhs, long int rhs ) { return lhs = lhs / rhs; }
     191static inline Int ?/=?( Int & lhs, unsigned long int rhs ) { return lhs = lhs / rhs; }
    192192
    193193static inline [ Int, Int ] div( Int dividend, Int divisor ) { Int quotient, remainder; mpz_fdiv_qr( quotient.mpz, remainder.mpz, dividend.mpz, divisor.mpz ); return [ quotient, remainder ]; }
     
    228228        return remainder;
    229229} // ?%?
    230 static inline Int ?%=?( Int * lhs, Int rhs ) { return *lhs = *lhs % rhs; }
    231 static inline Int ?%=?( Int * lhs, long int rhs ) { return *lhs = *lhs % rhs; }
    232 static inline Int ?%=?( Int * lhs, unsigned long int rhs ) { return *lhs = *lhs % rhs; }
     230static inline Int ?%=?( Int & lhs, Int rhs ) { return lhs = lhs % rhs; }
     231static inline Int ?%=?( Int & lhs, long int rhs ) { return lhs = lhs % rhs; }
     232static inline Int ?%=?( Int & lhs, unsigned long int rhs ) { return lhs = lhs % rhs; }
    233233
    234234static inline Int ?<<?( Int shiften, mp_bitcnt_t shift ) { Int shifted; mpz_mul_2exp( shifted.mpz, shiften.mpz, shift ); return shifted; }
    235 static inline Int ?<<=?( Int * lhs, mp_bitcnt_t shift ) { return *lhs = *lhs << shift; }
     235static inline Int ?<<=?( Int & lhs, mp_bitcnt_t shift ) { return lhs = lhs << shift; }
    236236static inline Int ?>>?( Int shiften, mp_bitcnt_t shift ) { Int shifted; mpz_fdiv_q_2exp( shifted.mpz, shiften.mpz, shift ); return shifted; }
    237 static inline Int ?>>=?( Int * lhs, mp_bitcnt_t shift ) { return *lhs = *lhs >> shift; }
     237static inline Int ?>>=?( Int & lhs, mp_bitcnt_t shift ) { return lhs = lhs >> shift; }
    238238
    239239// number functions
     
    252252// I/O
    253253static inline forall( dtype istype | istream( istype ) )
    254 istype * ?|?( istype * is, Int * mp ) {
    255         gmp_scanf( "%Zd", mp );
     254istype * ?|?( istype * is, Int & mp ) {
     255        gmp_scanf( "%Zd", &mp );
    256256        return is;
    257257} // ?|?
  • src/libcfa/interpose.c

    r135b431 r6b224a52  
    4949
    5050        union { generic_fptr_t fptr; void* ptr; } originalFunc;
    51        
     51
    5252        #if defined( _GNU_SOURCE )
    5353                if ( version ) {
     
    5959                originalFunc.ptr = dlsym( library, symbol );
    6060        #endif // _GNU_SOURCE
    61        
     61
    6262        error = dlerror();
    63         if ( error ) abortf( "interpose_symbol : internal error, %s\n", error ); 
     63        if ( error ) abortf( "interpose_symbol : internal error, %s\n", error );
    6464
    6565        return originalFunc.fptr;
     
    7474forall(dtype T)
    7575static inline void assign_ptr( T** symbol_ptr, const char * symbol_name, const char * version) {
    76         union { 
     76        union {
    7777                generic_fptr_t gp;
    78                 T* tp; 
     78                T* tp;
    7979        } u;
    8080
  • src/libcfa/iostream

    r135b431 r6b224a52  
    1010// Created On       : Wed May 27 17:56:53 2015
    1111// Last Modified By : Peter A. Buhr
    12 // Last Modified On : Wed Aug  9 16:42:47 2017
    13 // Update Count     : 131
     12// Last Modified On : Thu Aug 24 08:14:29 2017
     13// Update Count     : 133
    1414//
    1515
     
    117117}; // readable
    118118
    119 forall( dtype istype | istream( istype ) ) istype * ?|?( istype *, char * );
     119forall( dtype istype | istream( istype ) ) istype * ?|?( istype *, char & );
    120120
    121 forall( dtype istype | istream( istype ) ) istype * ?|?( istype *, short int * );
    122 forall( dtype istype | istream( istype ) ) istype * ?|?( istype *, unsigned short int * );
    123 forall( dtype istype | istream( istype ) ) istype * ?|?( istype *, int * );
    124 forall( dtype istype | istream( istype ) ) istype * ?|?( istype *, unsigned int * );
    125 forall( dtype istype | istream( istype ) ) istype * ?|?( istype *, long int * );
    126 forall( dtype istype | istream( istype ) ) istype * ?|?( istype *, long long int * );
    127 forall( dtype istype | istream( istype ) ) istype * ?|?( istype *, unsigned long int * );
    128 forall( dtype istype | istream( istype ) ) istype * ?|?( istype *, unsigned long long int * );
     121forall( dtype istype | istream( istype ) ) istype * ?|?( istype *, short int & );
     122forall( dtype istype | istream( istype ) ) istype * ?|?( istype *, unsigned short int & );
     123forall( dtype istype | istream( istype ) ) istype * ?|?( istype *, int & );
     124forall( dtype istype | istream( istype ) ) istype * ?|?( istype *, unsigned int & );
     125forall( dtype istype | istream( istype ) ) istype * ?|?( istype *, long int & );
     126forall( dtype istype | istream( istype ) ) istype * ?|?( istype *, long long int & );
     127forall( dtype istype | istream( istype ) ) istype * ?|?( istype *, unsigned long int & );
     128forall( dtype istype | istream( istype ) ) istype * ?|?( istype *, unsigned long long int & );
    129129
    130 forall( dtype istype | istream( istype ) ) istype * ?|?( istype *, float * );
    131 forall( dtype istype | istream( istype ) ) istype * ?|?( istype *, double * );
    132 forall( dtype istype | istream( istype ) ) istype * ?|?( istype *, long double * );
     130forall( dtype istype | istream( istype ) ) istype * ?|?( istype *, float & );
     131forall( dtype istype | istream( istype ) ) istype * ?|?( istype *, double & );
     132forall( dtype istype | istream( istype ) ) istype * ?|?( istype *, long double & );
    133133
    134 forall( dtype istype | istream( istype ) ) istype * ?|?( istype *, float _Complex * );
    135 forall( dtype istype | istream( istype ) ) istype * ?|?( istype *, double _Complex * );
    136 forall( dtype istype | istream( istype ) ) istype * ?|?( istype *, long double _Complex * );
     134forall( dtype istype | istream( istype ) ) istype * ?|?( istype *, float _Complex & );
     135forall( dtype istype | istream( istype ) ) istype * ?|?( istype *, double _Complex & );
     136forall( dtype istype | istream( istype ) ) istype * ?|?( istype *, long double _Complex & );
    137137
    138138struct _Istream_cstrUC { char * s; };
  • src/libcfa/iostream.c

    r135b431 r6b224a52  
    1010// Created On       : Wed May 27 17:56:53 2015
    1111// Last Modified By : Peter A. Buhr
    12 // Last Modified On : Wed Aug  9 16:46:51 2017
    13 // Update Count     : 401
     12// Last Modified On : Thu Aug 24 08:41:53 2017
     13// Update Count     : 405
    1414//
    1515
     
    271271
    272272forall( dtype istype | istream( istype ) )
    273 istype * ?|?( istype * is, char * c ) {
    274         fmt( is, "%c", c );
    275         return is;
    276 } // ?|?
    277 
    278 forall( dtype istype | istream( istype ) )
    279 istype * ?|?( istype * is, short int * si ) {
    280         fmt( is, "%hd", si );
    281         return is;
    282 } // ?|?
    283 
    284 forall( dtype istype | istream( istype ) )
    285 istype * ?|?( istype * is, unsigned short int * usi ) {
    286         fmt( is, "%hu", usi );
    287         return is;
    288 } // ?|?
    289 
    290 forall( dtype istype | istream( istype ) )
    291 istype * ?|?( istype * is, int * i ) {
    292         fmt( is, "%d", i );
    293         return is;
    294 } // ?|?
    295 
    296 forall( dtype istype | istream( istype ) )
    297 istype * ?|?( istype * is, unsigned int * ui ) {
    298         fmt( is, "%u", ui );
    299         return is;
    300 } // ?|?
    301 
    302 forall( dtype istype | istream( istype ) )
    303 istype * ?|?( istype * is, long int * li ) {
    304         fmt( is, "%ld", li );
    305         return is;
    306 } // ?|?
    307 
    308 forall( dtype istype | istream( istype ) )
    309 istype * ?|?( istype * is, unsigned long int * ulli ) {
    310         fmt( is, "%lu", ulli );
    311         return is;
    312 } // ?|?
    313 
    314 forall( dtype istype | istream( istype ) )
    315 istype * ?|?( istype * is, long long int * lli ) {
    316         fmt( is, "%lld", lli );
    317         return is;
    318 } // ?|?
    319 
    320 forall( dtype istype | istream( istype ) )
    321 istype * ?|?( istype * is, unsigned long long int * ulli ) {
    322         fmt( is, "%llu", ulli );
    323         return is;
    324 } // ?|?
    325 
    326 
    327 forall( dtype istype | istream( istype ) )
    328 istype * ?|?( istype * is, float * f ) {
    329         fmt( is, "%f", f );
    330         return is;
    331 } // ?|?
    332 
    333 forall( dtype istype | istream( istype ) )
    334 istype * ?|?( istype * is, double * d ) {
    335         fmt( is, "%lf", d );
    336         return is;
    337 } // ?|?
    338 
    339 forall( dtype istype | istream( istype ) )
    340 istype * ?|?( istype * is, long double * ld ) {
    341         fmt( is, "%Lf", ld );
    342         return is;
    343 } // ?|?
    344 
    345 
    346 forall( dtype istype | istream( istype ) )
    347 istype * ?|?( istype * is, float _Complex * fc ) {
     273istype * ?|?( istype * is, char & c ) {
     274        fmt( is, "%c", &c );                                                            // must pass pointer through varg to fmt
     275        return is;
     276} // ?|?
     277
     278forall( dtype istype | istream( istype ) )
     279istype * ?|?( istype * is, short int & si ) {
     280        fmt( is, "%hd", &si );
     281        return is;
     282} // ?|?
     283
     284forall( dtype istype | istream( istype ) )
     285istype * ?|?( istype * is, unsigned short int & usi ) {
     286        fmt( is, "%hu", &usi );
     287        return is;
     288} // ?|?
     289
     290forall( dtype istype | istream( istype ) )
     291istype * ?|?( istype * is, int & i ) {
     292        fmt( is, "%d", &i );
     293        return is;
     294} // ?|?
     295
     296forall( dtype istype | istream( istype ) )
     297istype * ?|?( istype * is, unsigned int & ui ) {
     298        fmt( is, "%u", &ui );
     299        return is;
     300} // ?|?
     301
     302forall( dtype istype | istream( istype ) )
     303istype * ?|?( istype * is, long int & li ) {
     304        fmt( is, "%ld", &li );
     305        return is;
     306} // ?|?
     307
     308forall( dtype istype | istream( istype ) )
     309istype * ?|?( istype * is, unsigned long int & ulli ) {
     310        fmt( is, "%lu", &ulli );
     311        return is;
     312} // ?|?
     313
     314forall( dtype istype | istream( istype ) )
     315istype * ?|?( istype * is, long long int & lli ) {
     316        fmt( is, "%lld", &lli );
     317        return is;
     318} // ?|?
     319
     320forall( dtype istype | istream( istype ) )
     321istype * ?|?( istype * is, unsigned long long int & ulli ) {
     322        fmt( is, "%llu", &ulli );
     323        return is;
     324} // ?|?
     325
     326
     327forall( dtype istype | istream( istype ) )
     328istype * ?|?( istype * is, float & f ) {
     329        fmt( is, "%f", &f );
     330        return is;
     331} // ?|?
     332
     333forall( dtype istype | istream( istype ) )
     334istype * ?|?( istype * is, double & d ) {
     335        fmt( is, "%lf", &d );
     336        return is;
     337} // ?|?
     338
     339forall( dtype istype | istream( istype ) )
     340istype * ?|?( istype * is, long double & ld ) {
     341        fmt( is, "%Lf", &ld );
     342        return is;
     343} // ?|?
     344
     345
     346forall( dtype istype | istream( istype ) )
     347istype * ?|?( istype * is, float _Complex & fc ) {
    348348        float re, im;
    349349        fmt( is, "%g%gi", &re, &im );
    350         *fc = re + im * _Complex_I;
    351         return is;
    352 } // ?|?
    353 
    354 forall( dtype istype | istream( istype ) )
    355 istype * ?|?( istype * is, double _Complex * dc ) {
     350        fc = re + im * _Complex_I;
     351        return is;
     352} // ?|?
     353
     354forall( dtype istype | istream( istype ) )
     355istype * ?|?( istype * is, double _Complex & dc ) {
    356356        double re, im;
    357357        fmt( is, "%lf%lfi", &re, &im );
    358         *dc = re + im * _Complex_I;
    359         return is;
    360 } // ?|?
    361 
    362 forall( dtype istype | istream( istype ) )
    363 istype * ?|?( istype * is, long double _Complex * ldc ) {
     358        dc = re + im * _Complex_I;
     359        return is;
     360} // ?|?
     361
     362forall( dtype istype | istream( istype ) )
     363istype * ?|?( istype * is, long double _Complex & ldc ) {
    364364        long double re, im;
    365365        fmt( is, "%Lf%Lfi", &re, &im );
    366         *ldc = re + im * _Complex_I;
     366        ldc = re + im * _Complex_I;
    367367        return is;
    368368} // ?|?
  • src/libcfa/iterator

    r135b431 r6b224a52  
    1919trait iterator( otype iterator_type, otype elt_type ) {
    2020        // point to the next element
    21 //      iterator_type ?++( iterator_type * );
    22         iterator_type ++?( iterator_type * );
    23         iterator_type --?( iterator_type * );
     21//      iterator_type ?++( iterator_type & );
     22        iterator_type ++?( iterator_type & );
     23        iterator_type --?( iterator_type & );
    2424
    2525        // can be tested for equality with other iterators
     
    2828
    2929        // dereference to get the pointed-at element
    30         lvalue elt_type *?( iterator_type );
     30        elt_type & *?( iterator_type );
    3131};
    3232
  • src/libcfa/rational

    r135b431 r6b224a52  
    1212// Created On       : Wed Apr  6 17:56:25 2016
    1313// Last Modified By : Peter A. Buhr
    14 // Last Modified On : Fri Jul  7 09:34:33 2017
    15 // Update Count     : 93
     14// Last Modified On : Wed Aug 23 22:35:09 2017
     15// Update Count     : 95
    1616//
    1717
     
    3131        int ?>?( T, T );
    3232        int ?>=?( T, T );
    33         void ?{}( T *, zero_t );
    34         void ?{}( T *, one_t );
     33        void ?{}( T &, zero_t );
     34        void ?{}( T &, one_t );
    3535        T +?( T );
    3636        T -?( T );
     
    4040        T ?/?( T, T );
    4141        T ?%?( T, T );
    42         T ?/=?( T *, T );
     42        T ?/=?( T &, T );
    4343        T abs( T );
    4444};
     
    5454
    5555forall( otype RationalImpl | arithmetic( RationalImpl ) )
    56 void ?{}( Rational(RationalImpl) * r );
     56void ?{}( Rational(RationalImpl) & r );
    5757
    5858forall( otype RationalImpl | arithmetic( RationalImpl ) )
    59 void ?{}( Rational(RationalImpl) * r, RationalImpl n );
     59void ?{}( Rational(RationalImpl) & r, RationalImpl n );
    6060
    6161forall( otype RationalImpl | arithmetic( RationalImpl ) )
    62 void ?{}( Rational(RationalImpl) * r, RationalImpl n, RationalImpl d );
     62void ?{}( Rational(RationalImpl) & r, RationalImpl n, RationalImpl d );
    6363
    6464forall( otype RationalImpl | arithmetic( RationalImpl ) )
    65 void ?{}( Rational(RationalImpl) * r, zero_t );
     65void ?{}( Rational(RationalImpl) & r, zero_t );
    6666
    6767forall( otype RationalImpl | arithmetic( RationalImpl ) )
    68 void ?{}( Rational(RationalImpl) * r, one_t );
     68void ?{}( Rational(RationalImpl) & r, one_t );
    6969
    7070// numerator/denominator getter
     
    7777
    7878forall( otype RationalImpl | arithmetic( RationalImpl ) )
    79 [ RationalImpl, RationalImpl ] ?=?( * [ RationalImpl, RationalImpl ] dest, Rational(RationalImpl) src );
     79[ RationalImpl, RationalImpl ] ?=?( & [ RationalImpl, RationalImpl ] dest, Rational(RationalImpl) src );
    8080
    8181// numerator/denominator setter
     
    135135// I/O
    136136forall( otype RationalImpl | arithmetic( RationalImpl ) )
    137 forall( dtype istype | istream( istype ) | { istype * ?|?( istype *, RationalImpl * ); } )
    138 istype * ?|?( istype *, Rational(RationalImpl) * );
     137forall( dtype istype | istream( istype ) | { istype * ?|?( istype *, RationalImpl & ); } )
     138istype * ?|?( istype *, Rational(RationalImpl) & );
    139139
    140140forall( otype RationalImpl | arithmetic( RationalImpl ) )
  • src/libcfa/rational.c

    r135b431 r6b224a52  
    1 // 
     1//
    22// Cforall Version 1.0.0 Copyright (C) 2016 University of Waterloo
    33//
    44// The contents of this file are covered under the licence agreement in the
    55// file "LICENCE" distributed with Cforall.
    6 // 
    7 // rational.c -- 
    8 // 
     6//
     7// rational.c --
     8//
    99// Author           : Peter A. Buhr
    1010// Created On       : Wed Apr  6 17:54:28 2016
    1111// Last Modified By : Peter A. Buhr
    12 // Last Modified On : Tue May 16 18:35:36 2017
    13 // Update Count     : 150
    14 // 
     12// Last Modified On : Wed Aug 23 22:38:48 2017
     13// Update Count     : 154
     14//
    1515
    1616#include "rational"
     
    3434
    3535forall( otype RationalImpl | arithmetic( RationalImpl ) )
    36 static RationalImpl simplify( RationalImpl * n, RationalImpl * d ) {
    37         if ( *d == (RationalImpl){0} ) {
     36static RationalImpl simplify( RationalImpl & n, RationalImpl & d ) {
     37        if ( d == (RationalImpl){0} ) {
    3838                serr | "Invalid rational number construction: denominator cannot be equal to 0." | endl;
    3939                exit( EXIT_FAILURE );
    4040        } // exit
    41         if ( *d < (RationalImpl){0} ) { *d = -*d; *n = -*n; } // move sign to numerator
    42         return gcd( abs( *n ), *d );                                            // simplify
     41        if ( d < (RationalImpl){0} ) { d = -d; n = -n; }        // move sign to numerator
     42        return gcd( abs( n ), d );                                                      // simplify
    4343} // Rationalnumber::simplify
    4444
     
    4747
    4848forall( otype RationalImpl | arithmetic( RationalImpl ) )
    49 void ?{}( Rational(RationalImpl) * r ) {
     49void ?{}( Rational(RationalImpl) & r ) {
    5050        r{ (RationalImpl){0}, (RationalImpl){1} };
    5151} // rational
    5252
    5353forall( otype RationalImpl | arithmetic( RationalImpl ) )
    54 void ?{}( Rational(RationalImpl) * r, RationalImpl n ) {
     54void ?{}( Rational(RationalImpl) & r, RationalImpl n ) {
    5555        r{ n, (RationalImpl){1} };
    5656} // rational
    5757
    5858forall( otype RationalImpl | arithmetic( RationalImpl ) )
    59 void ?{}( Rational(RationalImpl) * r, RationalImpl n, RationalImpl d ) {
    60         RationalImpl t = simplify( &n, &d );                            // simplify
    61         r->numerator = n / t;
    62         r->denominator = d / t;
     59void ?{}( Rational(RationalImpl) & r, RationalImpl n, RationalImpl d ) {
     60        RationalImpl t = simplify( n, d );                                      // simplify
     61        r.numerator = n / t;
     62        r.denominator = d / t;
    6363} // rational
    6464
     
    7777
    7878forall( otype RationalImpl | arithmetic( RationalImpl ) )
    79 [ RationalImpl, RationalImpl ] ?=?( * [ RationalImpl, RationalImpl ] dest, Rational(RationalImpl) src ) {
    80         return *dest = src.[ numerator, denominator ];
     79[ RationalImpl, RationalImpl ] ?=?( & [ RationalImpl, RationalImpl ] dest, Rational(RationalImpl) src ) {
     80        return dest = src.[ numerator, denominator ];
    8181}
    8282
     
    9595RationalImpl denominator( Rational(RationalImpl) r, RationalImpl d ) {
    9696        RationalImpl prev = r.denominator;
    97         RationalImpl t = simplify( &r.numerator, &d );                  // simplify
     97        RationalImpl t = simplify( r.numerator, d );                    // simplify
    9898        r.numerator = r.numerator / t;
    9999        r.denominator = d / t;
     
    228228
    229229forall( otype RationalImpl | arithmetic( RationalImpl ) )
    230 forall( dtype istype | istream( istype ) | { istype * ?|?( istype *, RationalImpl * ); } )
    231 istype * ?|?( istype * is, Rational(RationalImpl) * r ) {
     230forall( dtype istype | istream( istype ) | { istype * ?|?( istype *, RationalImpl & ); } )
     231istype * ?|?( istype * is, Rational(RationalImpl) & r ) {
    232232        RationalImpl t;
    233         is | &(r->numerator) | &(r->denominator);
    234         t = simplify( &(r->numerator), &(r->denominator) );
    235         r->numerator /= t;
    236         r->denominator /= t;
     233        is | r.numerator | r.denominator;
     234        t = simplify( r.numerator, r.denominator );
     235        r.numerator /= t;
     236        r.denominator /= t;
    237237        return is;
    238238} // ?|?
  • src/libcfa/stdlib

    r135b431 r6b224a52  
    1010// Created On       : Thu Jan 28 17:12:35 2016
    1111// Last Modified By : Peter A. Buhr
    12 // Last Modified On : Mon Aug  7 11:19:07 2017
    13 // Update Count     : 223
     12// Last Modified On : Wed Aug 23 20:29:47 2017
     13// Update Count     : 224
    1414//
    1515
     
    132132
    133133// allocation/deallocation and constructor/destructor, non-array types
    134 forall( dtype T | sized(T), ttype Params | { void ?{}( T *, Params ); } ) T * new( Params p );
    135 forall( dtype T | { void ^?{}( T * ); } ) void delete( T * ptr );
    136 forall( dtype T, ttype Params | { void ^?{}( T * ); void delete( Params ); } ) void delete( T * ptr, Params rest );
     134forall( dtype T | sized(T), ttype Params | { void ?{}( T &, Params ); } ) T * new( Params p );
     135forall( dtype T | sized(T) | { void ^?{}( T & ); } ) void delete( T * ptr );
     136forall( dtype T, ttype Params | sized(T) | { void ^?{}( T & ); void delete( Params ); } ) void delete( T * ptr, Params rest );
    137137
    138138// allocation/deallocation and constructor/destructor, array types
    139 forall( dtype T | sized(T), ttype Params | { void ?{}( T *, Params ); } ) T * anew( size_t dim, Params p );
    140 forall( dtype T | sized(T) | { void ^?{}( T * ); } ) void adelete( size_t dim, T arr[] );
    141 forall( dtype T | sized(T) | { void ^?{}( T * ); }, ttype Params | { void adelete( Params ); } ) void adelete( size_t dim, T arr[], Params rest );
     139forall( dtype T | sized(T), ttype Params | { void ?{}( T &, Params ); } ) T * anew( size_t dim, Params p );
     140forall( dtype T | sized(T) | { void ^?{}( T & ); } ) void adelete( size_t dim, T arr[] );
     141forall( dtype T | sized(T) | { void ^?{}( T & ); }, ttype Params | { void adelete( Params ); } ) void adelete( size_t dim, T arr[], Params rest );
    142142
    143143//---------------------------------------
     
    201201double abs( double _Complex );
    202202long double abs( long double _Complex );
    203 forall( otype T | { void ?{}( T *, zero_t ); int ?<?( T, T ); T -?( T ); } )
     203forall( otype T | { void ?{}( T &, zero_t ); int ?<?( T, T ); T -?( T ); } )
    204204T abs( T );
    205205
     
    230230
    231231forall( otype T )
    232 void swap( T * t1, T * t2 );
     232void swap( T & t1, T & t2 );
    233233
    234234// Local Variables: //
  • src/libcfa/stdlib.c

    r135b431 r6b224a52  
    1010// Created On       : Thu Jan 28 17:10:29 2016
    1111// Last Modified By : Peter A. Buhr
    12 // Last Modified On : Tue Aug  8 17:31:13 2017
    13 // Update Count     : 291
     12// Last Modified On : Wed Aug 23 20:30:44 2017
     13// Update Count     : 292
    1414//
    1515
     
    3232        if ( nlen > olen ) {                                                            // larger ?
    3333                memset( nptr + olen, (int)fill, nlen - olen );  // initialize added storage
    34         } // 
     34        } //
    3535    return (T *)nptr;
    3636} // alloc
    3737
    3838// allocation/deallocation and constructor/destructor, non-array types
    39 forall( dtype T | sized(T), ttype Params | { void ?{}( T *, Params ); } )
     39forall( dtype T | sized(T), ttype Params | { void ?{}( T &, Params ); } )
    4040T * new( Params p ) {
    41         return (malloc()){ p };                                                         // run constructor
     41        return &(*malloc()){ p };                                                               // run constructor
    4242} // new
    4343
    44 forall( dtype T | { void ^?{}( T * ); } )
     44forall( dtype T | sized(T) | { void ^?{}( T & ); } )
    4545void delete( T * ptr ) {
    4646        if ( ptr ) {                                                                            // ignore null
    47                 ^ptr{};                                                                                 // run destructor
     47                ^(*ptr){};                                                                                      // run destructor
    4848                free( ptr );
    4949        } // if
    5050} // delete
    5151
    52 forall( dtype T, ttype Params | { void ^?{}( T * ); void delete( Params ); } )
     52forall( dtype T, ttype Params | sized(T) | { void ^?{}( T & ); void delete( Params ); } )
    5353void delete( T * ptr, Params rest ) {
    5454        if ( ptr ) {                                                                            // ignore null
    55                 ^ptr{};                                                                                 // run destructor
     55                ^(*ptr){};                                                                                      // run destructor
    5656                free( ptr );
    5757        } // if
     
    6161
    6262// allocation/deallocation and constructor/destructor, array types
    63 forall( dtype T | sized(T), ttype Params | { void ?{}( T *, Params ); } )
     63forall( dtype T | sized(T), ttype Params | { void ?{}( T &, Params ); } )
    6464T * anew( size_t dim, Params p ) {
    6565        T *arr = alloc( dim );
    6666        for ( unsigned int i = 0; i < dim; i += 1 ) {
    67                 (&arr[i]){ p };                                                                 // run constructor
     67                (arr[i]){ p };                                                                  // run constructor
    6868        } // for
    6969        return arr;
    7070} // anew
    7171
    72 forall( dtype T | sized(T) | { void ^?{}( T * ); } )
     72forall( dtype T | sized(T) | { void ^?{}( T & ); } )
    7373void adelete( size_t dim, T arr[] ) {
    7474        if ( arr ) {                                                                            // ignore null
    7575                for ( int i = dim - 1; i >= 0; i -= 1 ) {               // reverse allocation order, must be unsigned
    76                         ^(&arr[i]){};                                                           // run destructor
     76                        ^(arr[i]){};                                                            // run destructor
    7777                } // for
    7878                free( arr );
     
    8080} // adelete
    8181
    82 forall( dtype T | sized(T) | { void ^?{}( T * ); }, ttype Params | { void adelete( Params ); } )
     82forall( dtype T | sized(T) | { void ^?{}( T & ); }, ttype Params | { void adelete( Params ); } )
    8383void adelete( size_t dim, T arr[], Params rest ) {
    8484        if ( arr ) {                                                                            // ignore null
    8585                for ( int i = dim - 1; i >= 0; i -= 1 ) {               // reverse allocation order, must be unsigned
    86                         ^(&arr[i]){};                                                           // run destructor
     86                        ^(arr[i]){};                                                            // run destructor
    8787                } // for
    8888                free( arr );
     
    305305
    306306forall( otype T )
    307 void swap( T * t1, T * t2 ) {
    308         T temp = *t1;
    309         *t1 = *t2;
    310         *t2 = temp;
     307void swap( T & t1, T & t2 ) {
     308        T temp = t1;
     309        t1 = t2;
     310        t2 = temp;
    311311} // swap
    312312
Note: See TracChangeset for help on using the changeset viewer.