Changeset 6b224a52 for src/libcfa
- Timestamp:
- Aug 25, 2017, 12:11:53 PM (8 years ago)
- 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. - Location:
- src/libcfa
- Files:
-
- 31 edited
-
concurrency/alarm.c (modified) (2 diffs)
-
concurrency/alarm.h (modified) (3 diffs)
-
concurrency/coroutine (modified) (4 diffs)
-
concurrency/coroutine.c (modified) (1 diff)
-
concurrency/invoke.h (modified) (1 diff)
-
concurrency/kernel (modified) (4 diffs)
-
concurrency/kernel.c (modified) (13 diffs)
-
concurrency/monitor (modified) (4 diffs)
-
concurrency/monitor.c (modified) (6 diffs)
-
concurrency/preemption.c (modified) (3 diffs)
-
concurrency/preemption.h (modified) (1 diff)
-
concurrency/thread (modified) (3 diffs)
-
concurrency/thread.c (modified) (3 diffs)
-
containers/maybe (modified) (1 diff)
-
containers/maybe.c (modified) (3 diffs)
-
containers/result (modified) (1 diff)
-
containers/result.c (modified) (3 diffs)
-
containers/vector (modified) (2 diffs)
-
containers/vector.c (modified) (6 diffs)
-
exception.h (modified) (1 diff)
-
fstream (modified) (1 diff)
-
fstream.c (modified) (2 diffs)
-
gmp (modified) (11 diffs)
-
interpose.c (modified) (3 diffs)
-
iostream (modified) (2 diffs)
-
iostream.c (modified) (2 diffs)
-
iterator (modified) (2 diffs)
-
rational (modified) (6 diffs)
-
rational.c (modified) (6 diffs)
-
stdlib (modified) (4 diffs)
-
stdlib.c (modified) (5 diffs)
Legend:
- Unmodified
- Added
- Removed
-
src/libcfa/concurrency/alarm.c
r135b431 r6b224a52 40 40 __cfa_time_t zero_time = { 0 }; 41 41 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; // seconds47 this ->it_value.tv_usec = max( (alarm->val % one_second) / one_microsecond, 1000 ); // microseconds48 this ->it_interval.tv_sec = 0;49 this ->it_interval.tv_usec = 0;50 } 51 52 53 void ?{}( __cfa_time_t *this, timespec * curr ) {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 ) { 54 54 uint64_t secs = curr->tv_sec; 55 55 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; 62 62 } 63 63 … … 86 86 //============================================================================================= 87 87 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 );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 ); 109 109 } 110 110 } -
src/libcfa/concurrency/alarm.h
r135b431 r6b224a52 36 36 37 37 // 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 );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 ); 42 42 43 __cfa_time_t ?=?( __cfa_time_t *this, zero_t rhs );43 __cfa_time_t ?=?( __cfa_time_t & this, zero_t rhs ); 44 44 45 45 // logical ops … … 105 105 typedef alarm_node_t ** __alarm_it_t; 106 106 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 );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 ); 110 110 111 111 struct alarm_list_t { … … 114 114 }; 115 115 116 static inline void ?{}( alarm_list_t *this ) {117 this ->head = 0;118 this ->tail = &this->head;116 static inline void ?{}( alarm_list_t & this ) { 117 this.head = 0; 118 this.tail = &this.head; 119 119 } 120 120 -
src/libcfa/concurrency/coroutine
r135b431 r6b224a52 25 25 // Anything that is resumed is a coroutine. 26 26 trait 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); 29 29 }; 30 30 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) 32 32 33 33 //----------------------------------------------------------------------------- 34 34 // 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);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); 40 40 41 41 //----------------------------------------------------------------------------- … … 44 44 45 45 forall(dtype T | is_coroutine(T)) 46 static inline void resume(T *cor);46 static inline void resume(T & cor); 47 47 48 48 forall(dtype T | is_coroutine(T)) 49 void prime(T *cor);49 void prime(T & cor); 50 50 51 51 //----------------------------------------------------------------------------- … … 86 86 // Resume implementation inlined for performance 87 87 forall(dtype T | is_coroutine(T)) 88 static inline void resume(T *cor) {88 static inline void resume(T & cor) { 89 89 coroutine_desc * src = this_coroutine; // optimization 90 90 coroutine_desc * dst = get_coroutine(cor); … … 92 92 if( unlikely(!dst->stack.base) ) { 93 93 create_stack(&dst->stack, dst->stack.size); 94 CtxStart( cor, CtxInvokeCoroutine);94 CtxStart(&cor, CtxInvokeCoroutine); 95 95 } 96 96 -
src/libcfa/concurrency/coroutine.c
r135b431 r6b224a52 40 40 //----------------------------------------------------------------------------- 41 41 // Coroutine ctors and dtors 42 void ?{}(coStack_t *this) {43 this ->size = 65000; // size of stack44 this ->storage = NULL; // pointer to stack45 this ->limit = NULL; // stack grows towards stack limit46 this ->base = NULL; // base of stack47 this ->context = NULL; // address of cfa_context_t48 this ->top = NULL; // address of top of storage49 this ->userStack = false;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; 50 50 } 51 51 52 void ?{}(coStack_t *this, size_t size) {52 void ?{}(coStack_t& this, size_t size) { 53 53 this{}; 54 this ->size = size;54 this.size = size; 55 55 56 create_stack( this, this->size);56 create_stack(&this, this.size); 57 57 } 58 58 59 void ?{}(coroutine_desc *this) {59 void ?{}(coroutine_desc& this) { 60 60 this{ "Anonymous Coroutine" }; 61 61 } 62 62 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;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; 69 69 } 70 70 71 void ?{}(coroutine_desc *this, size_t size) {71 void ?{}(coroutine_desc& this, size_t size) { 72 72 this{}; 73 ( &this->stack){size};73 (this.stack){size}; 74 74 } 75 75 76 void ^?{}(coStack_t *this) {77 if ( ! this ->userStack ) {76 void ^?{}(coStack_t& this) { 77 if ( ! this.userStack ) { 78 78 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 ) ); 81 81 } 82 82 ); 83 free( this ->storage );83 free( this.storage ); 84 84 } 85 85 } 86 86 87 void ^?{}(coroutine_desc *this) {}87 void ^?{}(coroutine_desc& this) {} 88 88 89 89 // Part of the Public API 90 90 // Not inline since only ever called once per coroutine 91 91 forall(dtype T | is_coroutine(T)) 92 void prime(T *cor) {92 void prime(T& cor) { 93 93 coroutine_desc* this = get_coroutine(cor); 94 94 assert(this->state == Start); -
src/libcfa/concurrency/invoke.h
r135b431 r6b224a52 49 49 #ifdef __CFORALL__ 50 50 extern "Cforall" { 51 void ?{}( struct __thread_queue_t *);51 void ?{}( struct __thread_queue_t & ); 52 52 void append( struct __thread_queue_t *, struct thread_desc * ); 53 53 struct thread_desc * pop_head( struct __thread_queue_t * ); 54 54 struct thread_desc * remove( struct __thread_queue_t *, struct thread_desc ** ); 55 55 56 void ?{}( struct __condition_stack_t *);56 void ?{}( struct __condition_stack_t & ); 57 57 void push( struct __condition_stack_t *, struct __condition_criterion_t * ); 58 58 struct __condition_criterion_t * pop( struct __condition_stack_t * ); 59 59 60 void ?{}(spinlock *this);61 void ^?{}(spinlock *this);60 void ?{}(spinlock & this); 61 void ^?{}(spinlock & this); 62 62 } 63 63 #endif -
src/libcfa/concurrency/kernel
r135b431 r6b224a52 37 37 }; 38 38 39 void ?{}(semaphore *this, int count = 1);40 void ^?{}(semaphore *this);39 void ?{}(semaphore & this, int count = 1); 40 void ^?{}(semaphore & this); 41 41 void P(semaphore * this); 42 42 void V(semaphore * this); … … 51 51 }; 52 52 53 void ?{}(cluster *this);54 void ^?{}(cluster *this);53 void ?{}(cluster & this); 54 void ^?{}(cluster & this); 55 55 56 56 //----------------------------------------------------------------------------- … … 68 68 unsigned short thrd_count; 69 69 }; 70 static inline void ?{}(FinishAction *this) {71 this ->action_code = No_Action;72 this ->thrd = NULL;73 this ->lock = NULL;70 static inline void ?{}(FinishAction & this) { 71 this.action_code = No_Action; 72 this.thrd = NULL; 73 this.lock = NULL; 74 74 } 75 static inline void ^?{}(FinishAction *this) {}75 static inline void ^?{}(FinishAction & this) {} 76 76 77 77 // Processor … … 99 99 }; 100 100 101 void ?{}(processor *this);102 void ?{}(processor *this, cluster * cltr);103 void ^?{}(processor *this);101 void ?{}(processor & this); 102 void ?{}(processor & this, cluster * cltr); 103 void ^?{}(processor & this); 104 104 105 105 // Local Variables: // -
src/libcfa/concurrency/kernel.c
r135b431 r6b224a52 73 73 }; 74 74 75 void ?{}( current_stack_info_t *this ) {76 CtxGet( this ->ctx );77 this ->base = this->ctx.FP;78 this ->storage = this->ctx.SP;75 void ?{}( current_stack_info_t & this ) { 76 CtxGet( this.ctx ); 77 this.base = this.ctx.FP; 78 this.storage = this.ctx.SP; 79 79 80 80 rlimit r; 81 81 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 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 }; 108 108 } 109 109 110 110 //----------------------------------------------------------------------------- 111 111 // 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) {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) { 125 125 this{ mainCluster }; 126 126 } 127 127 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) {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) { 168 168 169 169 } … … 173 173 //============================================================================================= 174 174 //Main of the processor contexts 175 void main(processorCtx_t *runner) {176 processor * this = runner ->proc;175 void main(processorCtx_t & runner) { 176 processor * this = runner.proc; 177 177 178 178 LIB_DEBUG_PRINT_SAFE("Kernel : core %p starting\n", this); … … 219 219 // from the processor coroutine to the target thread 220 220 void runThread(processor * this, thread_desc * dst) { 221 coroutine_desc * proc_cor = get_coroutine( this->runner);221 coroutine_desc * proc_cor = get_coroutine(*this->runner); 222 222 coroutine_desc * thrd_cor = get_coroutine(dst); 223 223 … … 301 301 // appropriate stack. 302 302 proc_cor_storage.__cor.state = Active; 303 main( &proc_cor_storage );303 main( proc_cor_storage ); 304 304 proc_cor_storage.__cor.state = Halted; 305 305 … … 443 443 mainThread = (thread_desc *)&storage_mainThread; 444 444 current_stack_info_t info; 445 mainThread{ &info };445 (*mainThread){ &info }; 446 446 447 447 LIB_DEBUG_PRINT_SAFE("Kernel : Main thread ready\n"); … … 449 449 // Initialize the main cluster 450 450 mainCluster = (cluster *)&storage_mainCluster; 451 mainCluster{};451 (*mainCluster){}; 452 452 453 453 LIB_DEBUG_PRINT_SAFE("Kernel : main cluster ready\n"); … … 456 456 // (the coroutine that contains the processing control flow) 457 457 mainProcessor = (processor *)&storage_mainProcessor; 458 mainProcessor{ mainCluster,(processorCtx_t *)&storage_mainProcessorCtx };458 (*mainProcessor){ mainCluster, *(processorCtx_t *)&storage_mainProcessorCtx }; 459 459 460 460 //initialize the global state variables … … 473 473 // context. Hence, the main thread does not begin through CtxInvokeThread, like all other threads. The trick here is that 474 474 // mainThread is on the ready queue when this call is made. 475 resume( mainProcessor->runner );475 resume( *mainProcessor->runner ); 476 476 477 477 … … 501 501 // Destroy the main processor and its context in reverse order of construction 502 502 // These were manually constructed so we need manually destroy them 503 ^( mainProcessor->runner){};503 ^(*mainProcessor->runner){}; 504 504 ^(mainProcessor){}; 505 505 … … 569 569 //----------------------------------------------------------------------------- 570 570 // Locks 571 void ?{}( spinlock *this ) {572 this ->lock = 0;573 } 574 void ^?{}( spinlock *this ) {571 void ?{}( spinlock & this ) { 572 this.lock = 0; 573 } 574 void ^?{}( spinlock & this ) { 575 575 576 576 } … … 606 606 } 607 607 608 void ?{}( semaphore *this, int count = 1 ) {609 ( &this->lock){};610 this ->count = count;611 ( &this->waiting){};612 } 613 void ^?{}(semaphore *this) {}608 void ?{}( semaphore & this, int count = 1 ) { 609 (this.lock){}; 610 this.count = count; 611 (this.waiting){}; 612 } 613 void ^?{}(semaphore & this) {} 614 614 615 615 void P(semaphore * this) { … … 645 645 //----------------------------------------------------------------------------- 646 646 // Queues 647 void ?{}( __thread_queue_t *this ) {648 this ->head = NULL;649 this ->tail = &this->head;647 void ?{}( __thread_queue_t & this ) { 648 this.head = NULL; 649 this.tail = &this.head; 650 650 } 651 651 … … 685 685 } 686 686 687 688 689 void ?{}( __condition_stack_t * this ) { 690 this->top = NULL; 687 void ?{}( __condition_stack_t & this ) { 688 this.top = NULL; 691 689 } 692 690 -
src/libcfa/concurrency/monitor
r135b431 r6b224a52 22 22 #include "stdlib" 23 23 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;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; 33 33 } 34 34 … … 45 45 } 46 46 47 void ?{}( monitor_guard_t * this, monitor_desc ** m, int count, void (*func)());48 void ^?{}( monitor_guard_t *this );47 void ?{}( monitor_guard_t & this, monitor_desc ** m, int count ); 48 void ^?{}( monitor_guard_t & this ); 49 49 50 50 //----------------------------------------------------------------------------- … … 71 71 }; 72 72 73 void ?{}( __condition_blocked_queue_t *);73 void ?{}( __condition_blocked_queue_t & ); 74 74 void append( __condition_blocked_queue_t *, __condition_node_t * ); 75 75 __condition_node_t * pop_head( __condition_blocked_queue_t * ); … … 81 81 }; 82 82 83 static inline void ?{}( condition *this ) {84 this ->monitors = NULL;85 this ->monitor_count = 0;83 static inline void ?{}( condition & this ) { 84 this.monitors = NULL; 85 this.monitor_count = 0; 86 86 } 87 87 88 static inline void ^?{}( condition *this ) {89 free( this ->monitors );88 static inline void ^?{}( condition & this ) { 89 free( this.monitors ); 90 90 } 91 91 -
src/libcfa/concurrency/monitor.c
r135b431 r6b224a52 194 194 // Ctor for monitor guard 195 195 // Sorts monitors before entering 196 void ?{}( monitor_guard_t *this, monitor_desc ** m, int count, void (*func)() ) {196 void ?{}( monitor_guard_t & this, monitor_desc ** m, int count, void (*func)() ) { 197 197 // Store current array 198 this ->m = m;199 this ->count = count;198 this.m = m; 199 this.count = count; 200 200 201 201 // Sort monitors based on address -> TODO use a sort specialized for small numbers 202 qsort(this ->m, count);202 qsort(this.m, count); 203 203 204 204 // 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; 208 208 209 209 // Update thread context (needed for conditions) … … 213 213 214 214 // Enter the monitors in order 215 enter( this->m, this->count, func ); 216 } 215 enter( this.m, this.count, func ); 216 } 217 217 218 218 219 // Dtor for monitor guard 219 void ^?{}( monitor_guard_t *this ) {220 void ^?{}( monitor_guard_t & this ) { 220 221 // Leave the monitors in order 221 leave( this ->m, this->count );222 leave( this.m, this.count ); 222 223 223 224 // 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; 227 228 } 228 229 229 230 //----------------------------------------------------------------------------- 230 231 // 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; 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; 251 251 } 252 252 … … 523 523 static inline void init( int count, monitor_desc ** monitors, __condition_node_t * waiter, __condition_criterion_t * criteria ) { 524 524 for(int i = 0; i < count; i++) { 525 ( &criteria[i]){ monitors[i], waiter };525 (criteria[i]){ monitors[i], waiter }; 526 526 } 527 527 … … 531 531 static inline void init_push( int count, monitor_desc ** monitors, __condition_node_t * waiter, __condition_criterion_t * criteria ) { 532 532 for(int i = 0; i < count; i++) { 533 ( &criteria[i]){ monitors[i], waiter };533 (criteria[i]){ monitors[i], waiter }; 534 534 push( &criteria[i].target->signal_stack, &criteria[i] ); 535 535 } … … 627 627 return end + 1; 628 628 } 629 629 630 630 631 static inline bool match( __acceptable_t * acc, thread_desc * thrd ) { … … 660 661 return NULL; 661 662 } 662 663 void ?{}( __condition_blocked_queue_t * this ) { 664 this->head = NULL; 665 this->tail = &this->head; 663 void ?{}( __condition_blocked_queue_t & this ) { 664 this.head = NULL; 665 this.tail = &this.head; 666 666 } 667 667 -
src/libcfa/concurrency/preemption.c
r135b431 r6b224a52 71 71 static pthread_t alarm_thread; // pthread handle to alarm thread 72 72 73 void ?{}(event_kernel_t *this) {74 ( &this->alarms){};75 ( &this->lock){};73 void ?{}(event_kernel_t & this) { 74 (this.alarms){}; 75 (this.lock){}; 76 76 } 77 77 … … 240 240 // Initialize the event kernel 241 241 event_kernel = (event_kernel_t *)&storage_event_kernel; 242 event_kernel{};242 (*event_kernel){}; 243 243 244 244 // Setup proper signal handlers … … 276 276 // Raii ctor/dtor for the preemption_scope 277 277 // 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 ) {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 ) { 287 287 disable_interrupts(); 288 288 289 update_preemption( this ->proc, zero_time );289 update_preemption( this.proc, zero_time ); 290 290 } 291 291 -
src/libcfa/concurrency/preemption.h
r135b431 r6b224a52 30 30 }; 31 31 32 void ?{}( preemption_scope *this, processor * proc );33 void ^?{}( preemption_scope *this );32 void ?{}( preemption_scope & this, processor * proc ); 33 void ^?{}( preemption_scope & this ); 34 34 35 35 // Local Variables: // -
src/libcfa/concurrency/thread
r135b431 r6b224a52 27 27 // Anything that is resumed is a coroutine. 28 28 trait 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); 32 32 }; 33 33 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) 35 35 36 36 forall( dtype T | is_thread(T) ) 37 static inline coroutine_desc* get_coroutine(T *this) {37 static inline coroutine_desc* get_coroutine(T & this) { 38 38 return &get_thread(this)->cor; 39 39 } 40 40 41 41 forall( dtype T | is_thread(T) ) 42 static inline monitor_desc* get_monitor(T *this) {42 static inline monitor_desc* get_monitor(T & this) { 43 43 return &get_thread(this)->mon; 44 44 } … … 55 55 56 56 forall( dtype T | is_thread(T) ) 57 void __thrd_start( T *this );57 void __thrd_start( T & this ); 58 58 59 59 //----------------------------------------------------------------------------- 60 60 // Ctors and dtors 61 void ?{}(thread_desc *this);62 void ^?{}(thread_desc *this);61 void ?{}(thread_desc& this); 62 void ^?{}(thread_desc& this); 63 63 64 64 //----------------------------------------------------------------------------- … … 70 70 }; 71 71 72 forall( dtype T | sized(T) | is_thread(T) | { void ?{}(T *); } )73 void ?{}( scoped(T) *this );72 forall( dtype T | sized(T) | is_thread(T) | { void ?{}(T&); } ) 73 void ?{}( scoped(T)& this ); 74 74 75 forall( dtype T, ttype P | sized(T) | is_thread(T) | { void ?{}(T *, P); } )76 void ?{}( scoped(T) *this, P params );75 forall( dtype T, ttype P | sized(T) | is_thread(T) | { void ?{}(T&, P); } ) 76 void ?{}( scoped(T)& this, P params ); 77 77 78 78 forall( dtype T | sized(T) | is_thread(T) ) 79 void ^?{}( scoped(T) *this );79 void ^?{}( scoped(T)& this ); 80 80 81 81 void yield(); -
src/libcfa/concurrency/thread.c
r135b431 r6b224a52 32 32 // Thread ctors and dtors 33 33 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;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; 40 40 41 this ->current_monitors = &this->mon;42 this ->current_monitor_count = 1;41 this.current_monitors = &this.mon; 42 this.current_monitor_count = 1; 43 43 } 44 44 45 void ^?{}(thread_desc *this) {46 ^( &this->cor){};45 void ^?{}(thread_desc& this) { 46 ^(this.cor){}; 47 47 } 48 48 49 forall( dtype T | sized(T) | is_thread(T) | { void ?{}(T *); } )50 void ?{}( scoped(T) *this ) {51 ( &this->handle){};52 __thrd_start( &this->handle);49 forall( dtype T | sized(T) | is_thread(T) | { void ?{}(T&); } ) 50 void ?{}( scoped(T)& this ) { 51 (this.handle){}; 52 __thrd_start(this.handle); 53 53 } 54 54 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);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); 59 59 } 60 60 61 61 forall( dtype T | sized(T) | is_thread(T) ) 62 void ^?{}( scoped(T) *this ) {63 ^( &this->handle){};62 void ^?{}( scoped(T)& this ) { 63 ^(this.handle){}; 64 64 } 65 65 … … 67 67 // Starting and stopping threads 68 68 forall( dtype T | is_thread(T) ) 69 void __thrd_start( T *this ) {69 void __thrd_start( T& this ) { 70 70 coroutine_desc* thrd_c = get_coroutine(this); 71 71 thread_desc* thrd_h = get_thread (this); … … 77 77 create_stack(&thrd_c->stack, thrd_c->stack.size); 78 78 this_coroutine = thrd_c; 79 CtxStart( this, CtxInvokeThread);79 CtxStart(&this, CtxInvokeThread); 80 80 assert( thrd_c->last->stack.context ); 81 81 CtxSwitch( thrd_c->last->stack.context, thrd_c->stack.context ); -
src/libcfa/containers/maybe
r135b431 r6b224a52 27 27 28 28 forall(otype T) 29 void ?{}(maybe(T) *this);29 void ?{}(maybe(T) & this); 30 30 31 31 forall(otype T) 32 void ?{}(maybe(T) *this, T value);32 void ?{}(maybe(T) & this, T value); 33 33 34 34 forall(otype T) 35 void ?{}(maybe(T) *this, maybe(T) other);35 void ?{}(maybe(T) & this, maybe(T) other); 36 36 37 37 forall(otype T) 38 void ^?{}(maybe(T) *this);38 void ^?{}(maybe(T) & this); 39 39 40 40 forall(otype T) 41 maybe(T) ?=?(maybe(T) *this, maybe(T) other);41 maybe(T) ?=?(maybe(T) & this, maybe(T) other); 42 42 43 43 forall(otype T) -
src/libcfa/containers/maybe.c
r135b431 r6b224a52 19 19 20 20 forall(otype T) 21 void ?{}(maybe(T) *this) {22 this ->has_value = false;21 void ?{}(maybe(T) & this) { 22 this.has_value = false; 23 23 } 24 24 25 25 forall(otype T) 26 void ?{}(maybe(T) *this, T value) {27 this ->has_value = true;28 ( &this->value){value};26 void ?{}(maybe(T) & this, T value) { 27 this.has_value = true; 28 (this.value){value}; 29 29 } 30 30 31 31 forall(otype T) 32 void ?{}(maybe(T) *this, maybe(T) other) {33 this ->has_value = other.has_value;32 void ?{}(maybe(T) & this, maybe(T) other) { 33 this.has_value = other.has_value; 34 34 if (other.has_value) { 35 ( &this->value){other.value};35 (this.value){other.value}; 36 36 } 37 37 } 38 38 39 39 forall(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;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; 46 46 } 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}; 49 49 } 50 return this; 50 51 } 51 52 52 53 forall(otype T) 53 void ^?{}(maybe(T) *this) {54 if (this ->has_value) {55 ^( &this->value){};54 void ^?{}(maybe(T) & this) { 55 if (this.has_value) { 56 ^(this.value){}; 56 57 } 57 58 } … … 89 90 } else { 90 91 this->has_value = true; 91 ( &this->value){value};92 (this->value){value}; 92 93 } 93 94 } … … 97 98 if (this->has_value) { 98 99 this->has_value = false; 99 ^( &this->value){};100 ^(this->value){}; 100 101 } 101 102 } -
src/libcfa/containers/result
r135b431 r6b224a52 33 33 34 34 forall(otype T, otype E) 35 void ?{}(result(T, E) *this);35 void ?{}(result(T, E) & this); 36 36 37 37 forall(otype T, otype E) 38 void ?{}(result(T, E) *this, one_t, T value);38 void ?{}(result(T, E) & this, one_t, T value); 39 39 40 40 forall(otype T, otype E) 41 void ?{}(result(T, E) *this, zero_t, E error);41 void ?{}(result(T, E) & this, zero_t, E error); 42 42 43 43 forall(otype T, otype E) 44 void ?{}(result(T, E) *this, result(T, E) other);44 void ?{}(result(T, E) & this, result(T, E) other); 45 45 46 46 forall(otype T, otype E) 47 void ^?{}(result(T, E) *this);47 void ^?{}(result(T, E) & this); 48 48 49 49 forall(otype T, otype E) 50 result(T, E) ?=?(result(T, E) *this, result(T, E) other);50 result(T, E) ?=?(result(T, E) & this, result(T, E) other); 51 51 52 52 forall(otype T, otype E) -
src/libcfa/containers/result.c
r135b431 r6b224a52 19 19 20 20 forall(otype T, otype E) 21 void ?{}(result(T, E) *this) {22 this ->has_value = false;23 ( &this->error){};21 void ?{}(result(T, E) & this) { 22 this.has_value = false; 23 (this.error){}; 24 24 } 25 25 26 26 forall(otype T, otype E) 27 void ?{}(result(T, E) *this, one_t, T value) {28 this ->has_value = true;29 ( &this->value){value};27 void ?{}(result(T, E) & this, one_t, T value) { 28 this.has_value = true; 29 (this.value){value}; 30 30 } 31 31 32 32 forall(otype T, otype E) 33 void ?{}(result(T, E) *this, zero_t, E error) {34 this ->has_value = false;35 ( &this->error){error};33 void ?{}(result(T, E) & this, zero_t, E error) { 34 this.has_value = false; 35 (this.error){error}; 36 36 } 37 37 38 38 forall(otype T, otype E) 39 void ?{}(result(T, E) *this, result(T, E) other) {40 this ->has_value = other.has_value;39 void ?{}(result(T, E) & this, result(T, E) other) { 40 this.has_value = other.has_value; 41 41 if (other.has_value) { 42 ( &this->value){other.value};42 (this.value){other.value}; 43 43 } else { 44 ( &this->error){other.error};44 (this.error){other.error}; 45 45 } 46 46 } 47 47 48 48 forall(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};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}; 56 56 } 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}; 60 60 } else { 61 this ->error = that.error;61 this.error = that.error; 62 62 } 63 63 } 64 64 65 65 forall(otype T, otype E) 66 void ^?{}(result(T, E) *this) {67 if (this ->has_value) {68 ^( &this->value){};66 void ^?{}(result(T, E) & this) { 67 if (this.has_value) { 68 ^(this.value){}; 69 69 } else { 70 ^( &this->error){};70 ^(this.error){}; 71 71 } 72 72 } … … 109 109 this->value = value; 110 110 } else { 111 ^( &this->error){};111 ^(this->error){}; 112 112 this->has_value = true; 113 ( &this->value){value};113 (this->value){value}; 114 114 } 115 115 } … … 118 118 void set_error(result(T, E) * this, E error) { 119 119 if (this->has_value) { 120 ^( &this->value){};120 ^(this->value){}; 121 121 this->has_value = false; 122 ( &this->error){error};122 (this->error){error}; 123 123 } else { 124 124 this->error = error; -
src/libcfa/containers/vector
r135b431 r6b224a52 30 30 31 31 forall(otype T) 32 void ?{}(heap_allocator(T) *this);32 void ?{}(heap_allocator(T)& this); 33 33 34 34 forall(otype T) 35 void ?{}(heap_allocator(T) *this, heap_allocator(T) rhs);35 void ?{}(heap_allocator(T)& this, heap_allocator(T) rhs); 36 36 37 37 forall(otype T) 38 heap_allocator(T) ?=?(heap_allocator(T) *this, heap_allocator(T) rhs);38 heap_allocator(T) ?=?(heap_allocator(T)& this, heap_allocator(T) rhs); 39 39 40 40 forall(otype T) 41 void ^?{}(heap_allocator(T) *this);41 void ^?{}(heap_allocator(T)& this); 42 42 43 43 forall(otype T) … … 64 64 //Initialization 65 65 forall(otype T, otype allocator_t | allocator_c(T, allocator_t)) 66 void ?{}(vector(T, allocator_t) *this);66 void ?{}(vector(T, allocator_t)& this); 67 67 68 68 forall(otype T, otype allocator_t | allocator_c(T, allocator_t)) 69 void ?{}(vector(T, allocator_t) *this, vector(T, allocator_t) rhs);69 void ?{}(vector(T, allocator_t)& this, vector(T, allocator_t) rhs); 70 70 71 71 forall(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);72 vector(T, allocator_t) ?=?(vector(T, allocator_t)& this, vector(T, allocator_t) rhs); 73 73 74 74 forall(otype T, otype allocator_t | allocator_c(T, allocator_t)) 75 void ^?{}(vector(T, allocator_t) *this);75 void ^?{}(vector(T, allocator_t)& this); 76 76 77 77 forall(otype T, otype allocator_t = heap_allocator(T) | allocator_c(T, allocator_t)) -
src/libcfa/containers/vector.c
r135b431 r6b224a52 24 24 //Initialization 25 25 forall(otype T, otype allocator_t | allocator_c(T, allocator_t)) 26 void ?{}(vector(T, allocator_t) *this)26 void ?{}(vector(T, allocator_t)& this) 27 27 { 28 ( &this->storage){};29 this ->size = 0;28 (this.storage){}; 29 this.size = 0; 30 30 } 31 31 32 32 forall(otype T, otype allocator_t | allocator_c(T, allocator_t)) 33 void ?{}(vector(T, allocator_t) *this, vector(T, allocator_t) rhs)33 void ?{}(vector(T, allocator_t)& this, vector(T, allocator_t) rhs) 34 34 { 35 ( &this->storage){ rhs.storage };36 copy_internal( this, &rhs);35 (this.storage){ rhs.storage }; 36 copy_internal(&this, &rhs); 37 37 } 38 38 … … 46 46 47 47 forall(otype T, otype allocator_t | allocator_c(T, allocator_t)) 48 void ^?{}(vector(T, allocator_t) *this)48 void ^?{}(vector(T, allocator_t)& this) 49 49 { 50 clear( this);51 ^( &this->storage){};50 clear(&this); 51 ^(this.storage){}; 52 52 } 53 53 … … 66 66 { 67 67 this->size--; 68 ^( &data(&this->storage)[this->size]){};68 ^(data(&this->storage)[this->size]){}; 69 69 } 70 70 … … 74 74 for(size_t i = 0; i < this->size; i++) 75 75 { 76 ^( &data(&this->storage)[this->size]){};76 ^(data(&this->storage)[this->size]){}; 77 77 } 78 78 this->size = 0; … … 87 87 this->size = other->size; 88 88 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] }; 90 90 } 91 91 } … … 94 94 //Allocator 95 95 forall(otype T) 96 void ?{}(heap_allocator(T) *this)96 void ?{}(heap_allocator(T)& this) 97 97 { 98 this ->storage = 0;99 this ->capacity = 0;98 this.storage = 0; 99 this.capacity = 0; 100 100 } 101 101 102 102 forall(otype T) 103 void ?{}(heap_allocator(T) *this, heap_allocator(T) rhs)103 void ?{}(heap_allocator(T)& this, heap_allocator(T) rhs) 104 104 { 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)); 107 107 } 108 108 109 109 forall(otype T) 110 heap_allocator(T) ?=?(heap_allocator(T) *this, heap_allocator(T) rhs)110 heap_allocator(T) ?=?(heap_allocator(T)& this, heap_allocator(T) rhs) 111 111 { 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; 115 115 } 116 116 117 117 forall(otype T) 118 void ^?{}(heap_allocator(T) *this)118 void ^?{}(heap_allocator(T)& this) 119 119 { 120 free(this ->storage);120 free(this.storage); 121 121 } 122 122 -
src/libcfa/exception.h
r135b431 r6b224a52 29 29 struct __cfaehm__base_exception_t * other); 30 30 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); 32 32 }; 33 33 struct __cfaehm__base_exception_t { -
src/libcfa/fstream
r135b431 r6b224a52 56 56 int fmt( ofstream *, const char fmt[], ... ); 57 57 58 void ?{}( ofstream *);58 void ?{}( ofstream & ); 59 59 60 60 extern ofstream * sout, * serr; -
src/libcfa/fstream.c
r135b431 r6b224a52 27 27 #define IO_MSG "I/O error: " 28 28 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 );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 ); 36 36 } 37 37 … … 92 92 exit( EXIT_FAILURE ); 93 93 } // if 94 ?{}( os, file, true, false, " ", ", " );94 ?{}( *os, file, true, false, " ", ", " ); 95 95 } // open 96 96 -
src/libcfa/gmp
r135b431 r6b224a52 1 // 1 // 2 2 // Cforall Version 1.0.0 Copyright (C) 2016 University of Waterloo 3 3 // 4 4 // The contents of this file are covered under the licence agreement in the 5 5 // file "LICENCE" distributed with Cforall. 6 // 7 // gmp -- 8 // 6 // 7 // gmp -- 8 // 9 9 // Author : Peter A. Buhr 10 10 // Created On : Tue Apr 19 08:43:43 2016 11 11 // Last Modified By : Peter A. Buhr 12 // Last Modified On : Fri Jul 7 09:33:20201713 // Update Count : 1 514 // 12 // Last Modified On : Thu Aug 24 09:24:51 2017 13 // Update Count : 16 14 // 15 15 16 16 // https://gmplib.org/gmp-man-6.1.1.pdf … … 24 24 25 25 // 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 ); }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 ); } 34 34 35 35 // 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; }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 lhs; } 42 static inline short int ?=?( short int & lhs, Int rhs ) { short int val = mpz_get_si( rhs.mpz ); lhs = val; return lhs; } 43 static inline int ?=?( int & lhs, Int rhs ) { int val = mpz_get_si( rhs.mpz ); lhs = val; return lhs; } 44 static inline long int ?=?( long int & lhs, Int rhs ) { long int val = mpz_get_si( rhs.mpz ); lhs = val; return lhs; } 45 static inline unsigned char ?=?( unsigned char & lhs, Int rhs ) { unsigned char val = mpz_get_ui( rhs.mpz ); lhs = val; return lhs; } 46 static inline unsigned short int ?=?( unsigned short int & lhs, Int rhs ) { unsigned short int val = mpz_get_ui( rhs.mpz ); lhs = val; return lhs; } 47 static inline unsigned int ?=?( unsigned int & lhs, Int rhs ) { unsigned int val = mpz_get_ui( rhs.mpz ); lhs = val; return lhs; } 48 static inline unsigned long int ?=?( unsigned long int & lhs, Int rhs ) { unsigned long int val = mpz_get_ui( rhs.mpz ); lhs = val; return lhs; } 49 49 50 50 // conversions … … 99 99 static 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; } 100 100 static 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; }101 static inline Int ?&=?( Int & lhs, Int rhs ) { return lhs = lhs & rhs; } 102 102 103 103 static inline Int ?|?( Int oper1, Int oper2 ) { Int disjunction; mpz_ior( disjunction.mpz, oper1.mpz, oper2.mpz ); return disjunction; } … … 106 106 static 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; } 107 107 static 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; }108 static inline Int ?|=?( Int & lhs, Int rhs ) { return lhs = lhs | rhs; } 109 109 110 110 static inline Int ?^?( Int oper1, Int oper2 ) { Int disjunction; mpz_xor( disjunction.mpz, oper1.mpz, oper2.mpz ); return disjunction; } … … 113 113 static 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; } 114 114 static 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; }115 static inline Int ?^=?( Int & lhs, Int rhs ) { return lhs = lhs ^ rhs; } 116 116 117 117 static inline Int ?+?( Int addend1, Int addend2 ) { Int sum; mpz_add( sum.mpz, addend1.mpz, addend2.mpz ); return sum; } … … 120 120 static inline Int ?+?( Int addend1, unsigned long int addend2 ) { Int sum; mpz_add_ui( sum.mpz, addend1.mpz, addend2 ); return sum; } 121 121 static 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; }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; } 127 127 128 128 static inline Int ?-?( Int minuend, Int subtrahend ) { Int diff; mpz_sub( diff.mpz, minuend.mpz, subtrahend.mpz ); return diff; } … … 131 131 static inline Int ?-?( Int minuend, unsigned long int subtrahend ) { Int diff; mpz_sub_ui( diff.mpz, minuend.mpz, subtrahend ); return diff; } 132 132 static 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; }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; } 138 138 139 139 static inline Int ?*?( Int multiplicator, Int multiplicand ) { Int product; mpz_mul( product.mpz, multiplicator.mpz, multiplicand.mpz ); return product; } … … 142 142 static inline Int ?*?( Int multiplicator, unsigned long int multiplicand ) { Int product; mpz_mul_ui( product.mpz, multiplicator.mpz, multiplicand ); return product; } 143 143 static 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; }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; } 147 147 148 148 // some code for operators "/" and "%" taken from g++ gmpxx.h … … 187 187 return quotient; 188 188 } // ?/? 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; }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; } 192 192 193 193 static 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 ]; } … … 228 228 return remainder; 229 229 } // ?%? 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; }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; } 233 233 234 234 static 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; }235 static inline Int ?<<=?( Int & lhs, mp_bitcnt_t shift ) { return lhs = lhs << shift; } 236 236 static 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; }237 static inline Int ?>>=?( Int & lhs, mp_bitcnt_t shift ) { return lhs = lhs >> shift; } 238 238 239 239 // number functions … … 252 252 // I/O 253 253 static inline forall( dtype istype | istream( istype ) ) 254 istype * ?|?( istype * is, Int *mp ) {255 gmp_scanf( "%Zd", mp );254 istype * ?|?( istype * is, Int & mp ) { 255 gmp_scanf( "%Zd", &mp ); 256 256 return is; 257 257 } // ?|? -
src/libcfa/interpose.c
r135b431 r6b224a52 49 49 50 50 union { generic_fptr_t fptr; void* ptr; } originalFunc; 51 51 52 52 #if defined( _GNU_SOURCE ) 53 53 if ( version ) { … … 59 59 originalFunc.ptr = dlsym( library, symbol ); 60 60 #endif // _GNU_SOURCE 61 61 62 62 error = dlerror(); 63 if ( error ) abortf( "interpose_symbol : internal error, %s\n", error ); 63 if ( error ) abortf( "interpose_symbol : internal error, %s\n", error ); 64 64 65 65 return originalFunc.fptr; … … 74 74 forall(dtype T) 75 75 static inline void assign_ptr( T** symbol_ptr, const char * symbol_name, const char * version) { 76 union { 76 union { 77 77 generic_fptr_t gp; 78 T* tp; 78 T* tp; 79 79 } u; 80 80 -
src/libcfa/iostream
r135b431 r6b224a52 10 10 // Created On : Wed May 27 17:56:53 2015 11 11 // Last Modified By : Peter A. Buhr 12 // Last Modified On : Wed Aug 9 16:42:47201713 // Update Count : 13 112 // Last Modified On : Thu Aug 24 08:14:29 2017 13 // Update Count : 133 14 14 // 15 15 … … 117 117 }; // readable 118 118 119 forall( dtype istype | istream( istype ) ) istype * ?|?( istype *, char *);119 forall( dtype istype | istream( istype ) ) istype * ?|?( istype *, char & ); 120 120 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 *);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 & ); 129 129 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 *);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 & ); 133 133 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 *);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 & ); 137 137 138 138 struct _Istream_cstrUC { char * s; }; -
src/libcfa/iostream.c
r135b431 r6b224a52 10 10 // Created On : Wed May 27 17:56:53 2015 11 11 // Last Modified By : Peter A. Buhr 12 // Last Modified On : Wed Aug 9 16:46:51201713 // Update Count : 40 112 // Last Modified On : Thu Aug 24 08:41:53 2017 13 // Update Count : 405 14 14 // 15 15 … … 271 271 272 272 forall( 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 ) {273 istype * ?|?( istype * is, char & c ) { 274 fmt( is, "%c", &c ); // must pass pointer through varg to fmt 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 ) { 348 348 float re, im; 349 349 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 354 forall( dtype istype | istream( istype ) ) 355 istype * ?|?( istype * is, double _Complex & dc ) { 356 356 double re, im; 357 357 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 362 forall( dtype istype | istream( istype ) ) 363 istype * ?|?( istype * is, long double _Complex & ldc ) { 364 364 long double re, im; 365 365 fmt( is, "%Lf%Lfi", &re, &im ); 366 *ldc = re + im * _Complex_I;366 ldc = re + im * _Complex_I; 367 367 return is; 368 368 } // ?|? -
src/libcfa/iterator
r135b431 r6b224a52 19 19 trait iterator( otype iterator_type, otype elt_type ) { 20 20 // 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 & ); 24 24 25 25 // can be tested for equality with other iterators … … 28 28 29 29 // dereference to get the pointed-at element 30 lvalue elt_type*?( iterator_type );30 elt_type & *?( iterator_type ); 31 31 }; 32 32 -
src/libcfa/rational
r135b431 r6b224a52 12 12 // Created On : Wed Apr 6 17:56:25 2016 13 13 // Last Modified By : Peter A. Buhr 14 // Last Modified On : Fri Jul 7 09:34:33201715 // Update Count : 9 314 // Last Modified On : Wed Aug 23 22:35:09 2017 15 // Update Count : 95 16 16 // 17 17 … … 31 31 int ?>?( T, T ); 32 32 int ?>=?( T, T ); 33 void ?{}( T *, zero_t );34 void ?{}( T *, one_t );33 void ?{}( T &, zero_t ); 34 void ?{}( T &, one_t ); 35 35 T +?( T ); 36 36 T -?( T ); … … 40 40 T ?/?( T, T ); 41 41 T ?%?( T, T ); 42 T ?/=?( T *, T );42 T ?/=?( T &, T ); 43 43 T abs( T ); 44 44 }; … … 54 54 55 55 forall( otype RationalImpl | arithmetic( RationalImpl ) ) 56 void ?{}( Rational(RationalImpl) *r );56 void ?{}( Rational(RationalImpl) & r ); 57 57 58 58 forall( otype RationalImpl | arithmetic( RationalImpl ) ) 59 void ?{}( Rational(RationalImpl) *r, RationalImpl n );59 void ?{}( Rational(RationalImpl) & r, RationalImpl n ); 60 60 61 61 forall( otype RationalImpl | arithmetic( RationalImpl ) ) 62 void ?{}( Rational(RationalImpl) *r, RationalImpl n, RationalImpl d );62 void ?{}( Rational(RationalImpl) & r, RationalImpl n, RationalImpl d ); 63 63 64 64 forall( otype RationalImpl | arithmetic( RationalImpl ) ) 65 void ?{}( Rational(RationalImpl) *r, zero_t );65 void ?{}( Rational(RationalImpl) & r, zero_t ); 66 66 67 67 forall( otype RationalImpl | arithmetic( RationalImpl ) ) 68 void ?{}( Rational(RationalImpl) *r, one_t );68 void ?{}( Rational(RationalImpl) & r, one_t ); 69 69 70 70 // numerator/denominator getter … … 77 77 78 78 forall( otype RationalImpl | arithmetic( RationalImpl ) ) 79 [ RationalImpl, RationalImpl ] ?=?( *[ RationalImpl, RationalImpl ] dest, Rational(RationalImpl) src );79 [ RationalImpl, RationalImpl ] ?=?( & [ RationalImpl, RationalImpl ] dest, Rational(RationalImpl) src ); 80 80 81 81 // numerator/denominator setter … … 135 135 // I/O 136 136 forall( otype RationalImpl | arithmetic( RationalImpl ) ) 137 forall( dtype istype | istream( istype ) | { istype * ?|?( istype *, RationalImpl *); } )138 istype * ?|?( istype *, Rational(RationalImpl) *);137 forall( dtype istype | istream( istype ) | { istype * ?|?( istype *, RationalImpl & ); } ) 138 istype * ?|?( istype *, Rational(RationalImpl) & ); 139 139 140 140 forall( otype RationalImpl | arithmetic( RationalImpl ) ) -
src/libcfa/rational.c
r135b431 r6b224a52 1 // 1 // 2 2 // Cforall Version 1.0.0 Copyright (C) 2016 University of Waterloo 3 3 // 4 4 // The contents of this file are covered under the licence agreement in the 5 5 // file "LICENCE" distributed with Cforall. 6 // 7 // rational.c -- 8 // 6 // 7 // rational.c -- 8 // 9 9 // Author : Peter A. Buhr 10 10 // Created On : Wed Apr 6 17:54:28 2016 11 11 // Last Modified By : Peter A. Buhr 12 // Last Modified On : Tue May 16 18:35:36201713 // Update Count : 15 014 // 12 // Last Modified On : Wed Aug 23 22:38:48 2017 13 // Update Count : 154 14 // 15 15 16 16 #include "rational" … … 34 34 35 35 forall( otype RationalImpl | arithmetic( RationalImpl ) ) 36 static RationalImpl simplify( RationalImpl * n, RationalImpl *d ) {37 if ( *d == (RationalImpl){0} ) {36 static RationalImpl simplify( RationalImpl & n, RationalImpl & d ) { 37 if ( d == (RationalImpl){0} ) { 38 38 serr | "Invalid rational number construction: denominator cannot be equal to 0." | endl; 39 39 exit( EXIT_FAILURE ); 40 40 } // exit 41 if ( *d < (RationalImpl){0} ) { *d = -*d; *n = -*n; }// move sign to numerator42 return gcd( abs( *n ), *d );// simplify41 if ( d < (RationalImpl){0} ) { d = -d; n = -n; } // move sign to numerator 42 return gcd( abs( n ), d ); // simplify 43 43 } // Rationalnumber::simplify 44 44 … … 47 47 48 48 forall( otype RationalImpl | arithmetic( RationalImpl ) ) 49 void ?{}( Rational(RationalImpl) *r ) {49 void ?{}( Rational(RationalImpl) & r ) { 50 50 r{ (RationalImpl){0}, (RationalImpl){1} }; 51 51 } // rational 52 52 53 53 forall( otype RationalImpl | arithmetic( RationalImpl ) ) 54 void ?{}( Rational(RationalImpl) *r, RationalImpl n ) {54 void ?{}( Rational(RationalImpl) & r, RationalImpl n ) { 55 55 r{ n, (RationalImpl){1} }; 56 56 } // rational 57 57 58 58 forall( otype RationalImpl | arithmetic( RationalImpl ) ) 59 void ?{}( Rational(RationalImpl) *r, RationalImpl n, RationalImpl d ) {60 RationalImpl t = simplify( &n, &d );// simplify61 r ->numerator = n / t;62 r ->denominator = d / t;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; 63 63 } // rational 64 64 … … 77 77 78 78 forall( 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 ]; 81 81 } 82 82 … … 95 95 RationalImpl denominator( Rational(RationalImpl) r, RationalImpl d ) { 96 96 RationalImpl prev = r.denominator; 97 RationalImpl t = simplify( &r.numerator, &d ); // simplify97 RationalImpl t = simplify( r.numerator, d ); // simplify 98 98 r.numerator = r.numerator / t; 99 99 r.denominator = d / t; … … 228 228 229 229 forall( otype RationalImpl | arithmetic( RationalImpl ) ) 230 forall( dtype istype | istream( istype ) | { istype * ?|?( istype *, RationalImpl *); } )231 istype * ?|?( istype * is, Rational(RationalImpl) *r ) {230 forall( dtype istype | istream( istype ) | { istype * ?|?( istype *, RationalImpl & ); } ) 231 istype * ?|?( istype * is, Rational(RationalImpl) & r ) { 232 232 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; 237 237 return is; 238 238 } // ?|? -
src/libcfa/stdlib
r135b431 r6b224a52 10 10 // Created On : Thu Jan 28 17:12:35 2016 11 11 // Last Modified By : Peter A. Buhr 12 // Last Modified On : Mon Aug 7 11:19:07 201713 // Update Count : 22 312 // Last Modified On : Wed Aug 23 20:29:47 2017 13 // Update Count : 224 14 14 // 15 15 … … 132 132 133 133 // 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 );134 forall( dtype T | sized(T), ttype Params | { void ?{}( T &, Params ); } ) T * new( Params p ); 135 forall( dtype T | sized(T) | { void ^?{}( T & ); } ) void delete( T * ptr ); 136 forall( dtype T, ttype Params | sized(T) | { void ^?{}( T & ); void delete( Params ); } ) void delete( T * ptr, Params rest ); 137 137 138 138 // 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 );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 ); 142 142 143 143 //--------------------------------------- … … 201 201 double abs( double _Complex ); 202 202 long double abs( long double _Complex ); 203 forall( otype T | { void ?{}( T *, zero_t ); int ?<?( T, T ); T -?( T ); } )203 forall( otype T | { void ?{}( T &, zero_t ); int ?<?( T, T ); T -?( T ); } ) 204 204 T abs( T ); 205 205 … … 230 230 231 231 forall( otype T ) 232 void swap( T * t1, T *t2 );232 void swap( T & t1, T & t2 ); 233 233 234 234 // Local Variables: // -
src/libcfa/stdlib.c
r135b431 r6b224a52 10 10 // Created On : Thu Jan 28 17:10:29 2016 11 11 // Last Modified By : Peter A. Buhr 12 // Last Modified On : Tue Aug 8 17:31:13201713 // Update Count : 29 112 // Last Modified On : Wed Aug 23 20:30:44 2017 13 // Update Count : 292 14 14 // 15 15 … … 32 32 if ( nlen > olen ) { // larger ? 33 33 memset( nptr + olen, (int)fill, nlen - olen ); // initialize added storage 34 } // 34 } // 35 35 return (T *)nptr; 36 36 } // alloc 37 37 38 38 // allocation/deallocation and constructor/destructor, non-array types 39 forall( dtype T | sized(T), ttype Params | { void ?{}( T *, Params ); } )39 forall( dtype T | sized(T), ttype Params | { void ?{}( T &, Params ); } ) 40 40 T * new( Params p ) { 41 return (malloc()){ p }; // run constructor41 return &(*malloc()){ p }; // run constructor 42 42 } // new 43 43 44 forall( dtype T | { void ^?{}( T *); } )44 forall( dtype T | sized(T) | { void ^?{}( T & ); } ) 45 45 void delete( T * ptr ) { 46 46 if ( ptr ) { // ignore null 47 ^ ptr{}; // run destructor47 ^(*ptr){}; // run destructor 48 48 free( ptr ); 49 49 } // if 50 50 } // delete 51 51 52 forall( dtype T, ttype Params | { void ^?{}( T *); void delete( Params ); } )52 forall( dtype T, ttype Params | sized(T) | { void ^?{}( T & ); void delete( Params ); } ) 53 53 void delete( T * ptr, Params rest ) { 54 54 if ( ptr ) { // ignore null 55 ^ ptr{}; // run destructor55 ^(*ptr){}; // run destructor 56 56 free( ptr ); 57 57 } // if … … 61 61 62 62 // allocation/deallocation and constructor/destructor, array types 63 forall( dtype T | sized(T), ttype Params | { void ?{}( T *, Params ); } )63 forall( dtype T | sized(T), ttype Params | { void ?{}( T &, Params ); } ) 64 64 T * anew( size_t dim, Params p ) { 65 65 T *arr = alloc( dim ); 66 66 for ( unsigned int i = 0; i < dim; i += 1 ) { 67 ( &arr[i]){ p }; // run constructor67 (arr[i]){ p }; // run constructor 68 68 } // for 69 69 return arr; 70 70 } // anew 71 71 72 forall( dtype T | sized(T) | { void ^?{}( T *); } )72 forall( dtype T | sized(T) | { void ^?{}( T & ); } ) 73 73 void adelete( size_t dim, T arr[] ) { 74 74 if ( arr ) { // ignore null 75 75 for ( int i = dim - 1; i >= 0; i -= 1 ) { // reverse allocation order, must be unsigned 76 ^( &arr[i]){}; // run destructor76 ^(arr[i]){}; // run destructor 77 77 } // for 78 78 free( arr ); … … 80 80 } // adelete 81 81 82 forall( dtype T | sized(T) | { void ^?{}( T *); }, ttype Params | { void adelete( Params ); } )82 forall( dtype T | sized(T) | { void ^?{}( T & ); }, ttype Params | { void adelete( Params ); } ) 83 83 void adelete( size_t dim, T arr[], Params rest ) { 84 84 if ( arr ) { // ignore null 85 85 for ( int i = dim - 1; i >= 0; i -= 1 ) { // reverse allocation order, must be unsigned 86 ^( &arr[i]){}; // run destructor86 ^(arr[i]){}; // run destructor 87 87 } // for 88 88 free( arr ); … … 305 305 306 306 forall( otype T ) 307 void swap( T * t1, T *t2 ) {308 T temp = *t1;309 *t1 = *t2;310 *t2 = temp;307 void swap( T & t1, T & t2 ) { 308 T temp = t1; 309 t1 = t2; 310 t2 = temp; 311 311 } // swap 312 312
Note:
See TracChangeset
for help on using the changeset viewer.