Changeset f53acdf8 for libcfa/src
- Timestamp:
- Jul 19, 2019, 2:16:01 PM (7 years ago)
- Branches:
- ADT, arm-eh, ast-experimental, enum, forall-pointer-decay, jacob/cs343-translation, master, new-ast, new-ast-unique-expr, pthread-emulation, qualifiedEnum, stuck-waitfor-destruct
- Children:
- 4eb43fa
- Parents:
- 1f1c102 (diff), 8ac3b0e (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:
- libcfa/src
- Files:
-
- 1 added
- 1 deleted
- 26 edited
-
Makefile.am (modified) (6 diffs)
-
Makefile.in (modified) (13 diffs)
-
bits/containers.hfa (modified) (8 diffs)
-
bits/debug.cfa (modified) (2 diffs)
-
bits/defs.hfa (modified) (1 diff)
-
bits/locks.hfa (modified) (1 diff)
-
concurrency/alarm.cfa (modified) (1 diff)
-
concurrency/coroutine.cfa (modified) (2 diffs)
-
concurrency/invoke.c (modified) (2 diffs)
-
concurrency/invoke.h (modified) (1 diff)
-
concurrency/kernel.cfa (modified) (2 diffs)
-
concurrency/kernel_private.hfa (modified) (1 diff)
-
concurrency/monitor.cfa (modified) (1 diff)
-
concurrency/mutex.cfa (modified) (1 diff)
-
concurrency/preemption.cfa (modified) (1 diff)
-
concurrency/thread.cfa (modified) (1 diff)
-
executor.cfa (added)
-
expat.h (deleted)
-
fstream.cfa (modified) (18 diffs)
-
fstream.hfa (modified) (5 diffs)
-
gmp.hfa (modified) (2 diffs)
-
interpose.cfa (modified) (6 diffs)
-
iostream.cfa (modified) (40 diffs)
-
iostream.hfa (modified) (13 diffs)
-
rational.cfa (modified) (3 diffs)
-
stdlib.cfa (modified) (3 diffs)
-
stdlib.hfa (modified) (2 diffs)
-
time.cfa (modified) (10 diffs)
Legend:
- Unmodified
- Added
- Removed
-
libcfa/src/Makefile.am
r1f1c102 rf53acdf8 11 11 ## Created On : Sun May 31 08:54:01 2015 12 12 ## Last Modified By : Peter A. Buhr 13 ## Last Modified On : Tue Jul 24 17:25:39 201814 ## Update Count : 24 013 ## Last Modified On : Mon Jul 15 22:43:27 2019 14 ## Update Count : 241 15 15 ############################################################################### 16 16 … … 22 22 23 23 libdir = ${CFA_LIBDIR} 24 lib_LTLIBRARIES = libcfa.la24 lib_LTLIBRARIES = libcfa.la libcfathread.la 25 25 26 26 VPATH += :../prelude … … 41 41 containers/maybe.hfa containers/pair.hfa containers/result.hfa containers/vector.hfa 42 42 43 # not all platforms support concurrency, add option do disable it44 headers_nosrc += concurrency/invoke.h45 headers += concurrency/coroutine.hfa concurrency/thread.hfa concurrency/kernel.hfa concurrency/monitor.hfa concurrency/mutex.hfa46 47 43 libsrc = startup.cfa interpose.cfa bits/debug.cfa assert.cfa exception.c virtual.c heap.cfa ${headers:.hfa=.cfa} 48 44 49 45 # not all platforms support concurrency, add option do disable it 50 libsrc += concurrency/CtxSwitch-@ARCHITECTURE@.S concurrency/alarm.cfa concurrency/invoke.c concurrency/preemption.cfa 46 thread_headers_nosrc = concurrency/invoke.h 47 thread_headers = concurrency/coroutine.hfa concurrency/thread.hfa concurrency/kernel.hfa concurrency/monitor.hfa concurrency/mutex.hfa 48 thread_libsrc = concurrency/CtxSwitch-@ARCHITECTURE@.S concurrency/alarm.cfa concurrency/invoke.c concurrency/preemption.cfa ${thread_headers:.hfa=.cfa} 51 49 else 52 50 headers = 51 thread_headers = 53 52 headers_nosrc = 53 thread_headers_nosrc = 54 54 libsrc = 55 55 endif … … 64 64 $(libobjs) : @CFACC@ @CFACPP@ prelude.cfa 65 65 66 thread_libobjs = $(addsuffix .lo, $(basename $(filter %.cfa,$(thread_libsrc)))) 67 $(thread_libobjs) : @CFACC@ @CFACPP@ prelude.cfa 68 66 69 67 70 # .deps inclusion is not done automatically by automake for new languages … … 72 75 73 76 -include $(libdeps) 77 78 thread_libdeps = $(join \ 79 $(addsuffix $(DEPDIR)/ , $(dir $(thread_libobjs) ) ), \ 80 $(notdir ${thread_libobjs:.lo=.Plo}) \ 81 ) 82 83 -include $(thread_libdeps) 84 74 85 75 86 prelude.o : prelude.cfa extras.cf gcc-builtins.cf builtins.cf @CFACC@ @CFACPP@ … … 85 96 libcfa_la_LDFLAGS = -version-info @CFA_VERSION@ 86 97 98 libcfathread_la_SOURCES = ${thread_libsrc} 99 libcfathread_la_LDFLAGS = -version-info @CFA_VERSION@ 100 87 101 stdhdr = $(shell find $(srcdir)/stdhdr -type f -printf "%p ") 88 102 89 103 cfa_includedir = $(CFA_INCDIR) 90 nobase_cfa_include_HEADERS = ${stdhdr} ${headers} ${headers_nosrc} 104 nobase_cfa_include_HEADERS = ${stdhdr} ${headers} ${headers_nosrc} ${thread_headers} ${thread_headers_nosrc} 91 105 92 106 #---------------------------------------------------------------------------------------------------------------- -
libcfa/src/Makefile.in
r1f1c102 rf53acdf8 142 142 time.cfa stdlib.cfa common.cfa containers/maybe.cfa \ 143 143 containers/pair.cfa containers/result.cfa \ 144 containers/vector.cfa concurrency/coroutine.cfa \ 145 concurrency/thread.cfa concurrency/kernel.cfa \ 146 concurrency/monitor.cfa concurrency/mutex.cfa \ 147 concurrency/CtxSwitch-@ARCHITECTURE@.S concurrency/alarm.cfa \ 148 concurrency/invoke.c concurrency/preemption.cfa 144 containers/vector.cfa 149 145 am__dirstamp = $(am__leading_dot)dirstamp 150 146 @BUILDLIB_TRUE@am__objects_1 = fstream.lo iostream.lo iterator.lo \ … … 152 148 @BUILDLIB_TRUE@ common.lo containers/maybe.lo \ 153 149 @BUILDLIB_TRUE@ containers/pair.lo containers/result.lo \ 154 @BUILDLIB_TRUE@ containers/vector.lo concurrency/coroutine.lo \ 155 @BUILDLIB_TRUE@ concurrency/thread.lo concurrency/kernel.lo \ 156 @BUILDLIB_TRUE@ concurrency/monitor.lo concurrency/mutex.lo 150 @BUILDLIB_TRUE@ containers/vector.lo 157 151 @BUILDLIB_TRUE@am__objects_2 = startup.lo interpose.lo bits/debug.lo \ 158 152 @BUILDLIB_TRUE@ assert.lo exception.lo virtual.lo heap.lo \ 159 @BUILDLIB_TRUE@ $(am__objects_1) \ 160 @BUILDLIB_TRUE@ concurrency/CtxSwitch-@ARCHITECTURE@.lo \ 161 @BUILDLIB_TRUE@ concurrency/alarm.lo concurrency/invoke.lo \ 162 @BUILDLIB_TRUE@ concurrency/preemption.lo 153 @BUILDLIB_TRUE@ $(am__objects_1) 163 154 am_libcfa_la_OBJECTS = prelude.lo $(am__objects_2) 164 155 libcfa_la_OBJECTS = $(am_libcfa_la_OBJECTS) … … 170 161 $(LIBTOOLFLAGS) --mode=link $(CCLD) $(AM_CFLAGS) $(CFLAGS) \ 171 162 $(libcfa_la_LDFLAGS) $(LDFLAGS) -o $@ 163 libcfathread_la_LIBADD = 164 am__libcfathread_la_SOURCES_DIST = \ 165 concurrency/CtxSwitch-@ARCHITECTURE@.S concurrency/alarm.cfa \ 166 concurrency/invoke.c concurrency/preemption.cfa \ 167 concurrency/coroutine.cfa concurrency/thread.cfa \ 168 concurrency/kernel.cfa concurrency/monitor.cfa \ 169 concurrency/mutex.cfa 170 @BUILDLIB_TRUE@am__objects_3 = concurrency/coroutine.lo \ 171 @BUILDLIB_TRUE@ concurrency/thread.lo concurrency/kernel.lo \ 172 @BUILDLIB_TRUE@ concurrency/monitor.lo concurrency/mutex.lo 173 @BUILDLIB_TRUE@am__objects_4 = \ 174 @BUILDLIB_TRUE@ concurrency/CtxSwitch-@ARCHITECTURE@.lo \ 175 @BUILDLIB_TRUE@ concurrency/alarm.lo concurrency/invoke.lo \ 176 @BUILDLIB_TRUE@ concurrency/preemption.lo $(am__objects_3) 177 am_libcfathread_la_OBJECTS = $(am__objects_4) 178 libcfathread_la_OBJECTS = $(am_libcfathread_la_OBJECTS) 179 libcfathread_la_LINK = $(LIBTOOL) $(AM_V_lt) --tag=CC \ 180 $(AM_LIBTOOLFLAGS) $(LIBTOOLFLAGS) --mode=link $(CCLD) \ 181 $(AM_CFLAGS) $(CFLAGS) $(libcfathread_la_LDFLAGS) $(LDFLAGS) \ 182 -o $@ 172 183 AM_V_P = $(am__v_P_@AM_V@) 173 184 am__v_P_ = $(am__v_P_@AM_DEFAULT_V@) … … 214 225 am__v_CCLD_0 = @echo " CCLD " $@; 215 226 am__v_CCLD_1 = 216 SOURCES = $(libcfa_la_SOURCES) 217 DIST_SOURCES = $(am__libcfa_la_SOURCES_DIST) 227 SOURCES = $(libcfa_la_SOURCES) $(libcfathread_la_SOURCES) 228 DIST_SOURCES = $(am__libcfa_la_SOURCES_DIST) \ 229 $(am__libcfathread_la_SOURCES_DIST) 218 230 am__can_run_installinfo = \ 219 231 case $$AM_UPDATE_INFO_DIR in \ … … 225 237 limits.hfa rational.hfa time.hfa stdlib.hfa common.hfa \ 226 238 containers/maybe.hfa containers/pair.hfa containers/result.hfa \ 227 containers/vector.hfa concurrency/coroutine.hfa \ 239 containers/vector.hfa math.hfa gmp.hfa time_t.hfa \ 240 bits/align.hfa bits/containers.hfa bits/defs.hfa \ 241 bits/debug.hfa bits/locks.hfa concurrency/coroutine.hfa \ 228 242 concurrency/thread.hfa concurrency/kernel.hfa \ 229 concurrency/monitor.hfa concurrency/mutex.hfa math.hfa gmp.hfa \ 230 time_t.hfa bits/align.hfa bits/containers.hfa bits/defs.hfa \ 231 bits/debug.hfa bits/locks.hfa concurrency/invoke.h 243 concurrency/monitor.hfa concurrency/mutex.hfa \ 244 concurrency/invoke.h 232 245 HEADERS = $(nobase_cfa_include_HEADERS) 233 246 am__tagged_files = $(HEADERS) $(SOURCES) $(TAGS_FILES) $(LISP) … … 421 434 am__v_UPP_0 = @echo " UPP " $@; 422 435 am__v_UPP_1 = 423 lib_LTLIBRARIES = libcfa.la 436 lib_LTLIBRARIES = libcfa.la libcfathread.la 424 437 425 438 # AM_CFLAGS for all cfa source … … 433 446 434 447 #---------------------------------------------------------------------------------------------------------------- 448 @BUILDLIB_TRUE@headers_nosrc = math.hfa gmp.hfa time_t.hfa bits/align.hfa bits/containers.hfa bits/defs.hfa bits/debug.hfa bits/locks.hfa 449 @BUILDLIB_FALSE@headers = 450 @BUILDLIB_TRUE@headers = fstream.hfa iostream.hfa iterator.hfa limits.hfa rational.hfa time.hfa stdlib.hfa common.hfa \ 451 @BUILDLIB_TRUE@ containers/maybe.hfa containers/pair.hfa containers/result.hfa containers/vector.hfa 452 453 @BUILDLIB_FALSE@libsrc = 454 @BUILDLIB_TRUE@libsrc = startup.cfa interpose.cfa bits/debug.cfa assert.cfa exception.c virtual.c heap.cfa ${headers:.hfa=.cfa} 455 @BUILDLIB_FALSE@thread_headers_nosrc = 435 456 436 457 # not all platforms support concurrency, add option do disable it 437 @BUILDLIB_TRUE@headers_nosrc = math.hfa gmp.hfa time_t.hfa \ 438 @BUILDLIB_TRUE@ bits/align.hfa bits/containers.hfa \ 439 @BUILDLIB_TRUE@ bits/defs.hfa bits/debug.hfa bits/locks.hfa \ 440 @BUILDLIB_TRUE@ concurrency/invoke.h 441 @BUILDLIB_FALSE@headers = 442 @BUILDLIB_TRUE@headers = fstream.hfa iostream.hfa iterator.hfa \ 443 @BUILDLIB_TRUE@ limits.hfa rational.hfa time.hfa stdlib.hfa \ 444 @BUILDLIB_TRUE@ common.hfa containers/maybe.hfa \ 445 @BUILDLIB_TRUE@ containers/pair.hfa containers/result.hfa \ 446 @BUILDLIB_TRUE@ containers/vector.hfa concurrency/coroutine.hfa \ 447 @BUILDLIB_TRUE@ concurrency/thread.hfa concurrency/kernel.hfa \ 448 @BUILDLIB_TRUE@ concurrency/monitor.hfa concurrency/mutex.hfa 449 @BUILDLIB_FALSE@libsrc = 450 451 # not all platforms support concurrency, add option do disable it 452 @BUILDLIB_TRUE@libsrc = startup.cfa interpose.cfa bits/debug.cfa \ 453 @BUILDLIB_TRUE@ assert.cfa exception.c virtual.c heap.cfa \ 454 @BUILDLIB_TRUE@ ${headers:.hfa=.cfa} \ 455 @BUILDLIB_TRUE@ concurrency/CtxSwitch-@ARCHITECTURE@.S \ 456 @BUILDLIB_TRUE@ concurrency/alarm.cfa concurrency/invoke.c \ 457 @BUILDLIB_TRUE@ concurrency/preemption.cfa 458 @BUILDLIB_TRUE@thread_headers_nosrc = concurrency/invoke.h 459 @BUILDLIB_FALSE@thread_headers = 460 @BUILDLIB_TRUE@thread_headers = concurrency/coroutine.hfa concurrency/thread.hfa concurrency/kernel.hfa concurrency/monitor.hfa concurrency/mutex.hfa 461 @BUILDLIB_TRUE@thread_libsrc = concurrency/CtxSwitch-@ARCHITECTURE@.S concurrency/alarm.cfa concurrency/invoke.c concurrency/preemption.cfa ${thread_headers:.hfa=.cfa} 458 462 459 463 #---------------------------------------------------------------------------------------------------------------- … … 463 467 # add dependency of cfa files 464 468 libobjs = $(addsuffix .lo, $(basename $(filter %.cfa,$(libsrc)))) 469 thread_libobjs = $(addsuffix .lo, $(basename $(filter %.cfa,$(thread_libsrc)))) 465 470 466 471 # .deps inclusion is not done automatically by automake for new languages … … 470 475 ) 471 476 477 thread_libdeps = $(join \ 478 $(addsuffix $(DEPDIR)/ , $(dir $(thread_libobjs) ) ), \ 479 $(notdir ${thread_libobjs:.lo=.Plo}) \ 480 ) 481 472 482 473 483 #---------------------------------------------------------------------------------------------------------------- 474 484 libcfa_la_SOURCES = prelude.cfa ${libsrc} 475 485 libcfa_la_LDFLAGS = -version-info @CFA_VERSION@ 486 libcfathread_la_SOURCES = ${thread_libsrc} 487 libcfathread_la_LDFLAGS = -version-info @CFA_VERSION@ 476 488 stdhdr = $(shell find $(srcdir)/stdhdr -type f -printf "%p ") 477 489 cfa_includedir = $(CFA_INCDIR) 478 nobase_cfa_include_HEADERS = ${stdhdr} ${headers} ${headers_nosrc} 490 nobase_cfa_include_HEADERS = ${stdhdr} ${headers} ${headers_nosrc} ${thread_headers} ${thread_headers_nosrc} 479 491 all: all-am 480 492 … … 567 579 containers/vector.lo: containers/$(am__dirstamp) \ 568 580 containers/$(DEPDIR)/$(am__dirstamp) 581 582 libcfa.la: $(libcfa_la_OBJECTS) $(libcfa_la_DEPENDENCIES) $(EXTRA_libcfa_la_DEPENDENCIES) 583 $(AM_V_CCLD)$(libcfa_la_LINK) -rpath $(libdir) $(libcfa_la_OBJECTS) $(libcfa_la_LIBADD) $(LIBS) 569 584 concurrency/$(am__dirstamp): 570 585 @$(MKDIR_P) concurrency … … 573 588 @$(MKDIR_P) concurrency/$(DEPDIR) 574 589 @: > concurrency/$(DEPDIR)/$(am__dirstamp) 590 concurrency/CtxSwitch-@ARCHITECTURE@.lo: concurrency/$(am__dirstamp) \ 591 concurrency/$(DEPDIR)/$(am__dirstamp) 592 concurrency/alarm.lo: concurrency/$(am__dirstamp) \ 593 concurrency/$(DEPDIR)/$(am__dirstamp) 594 concurrency/invoke.lo: concurrency/$(am__dirstamp) \ 595 concurrency/$(DEPDIR)/$(am__dirstamp) 596 concurrency/preemption.lo: concurrency/$(am__dirstamp) \ 597 concurrency/$(DEPDIR)/$(am__dirstamp) 575 598 concurrency/coroutine.lo: concurrency/$(am__dirstamp) \ 576 599 concurrency/$(DEPDIR)/$(am__dirstamp) … … 583 606 concurrency/mutex.lo: concurrency/$(am__dirstamp) \ 584 607 concurrency/$(DEPDIR)/$(am__dirstamp) 585 concurrency/CtxSwitch-@ARCHITECTURE@.lo: concurrency/$(am__dirstamp) \ 586 concurrency/$(DEPDIR)/$(am__dirstamp) 587 concurrency/alarm.lo: concurrency/$(am__dirstamp) \ 588 concurrency/$(DEPDIR)/$(am__dirstamp) 589 concurrency/invoke.lo: concurrency/$(am__dirstamp) \ 590 concurrency/$(DEPDIR)/$(am__dirstamp) 591 concurrency/preemption.lo: concurrency/$(am__dirstamp) \ 592 concurrency/$(DEPDIR)/$(am__dirstamp) 593 594 libcfa.la: $(libcfa_la_OBJECTS) $(libcfa_la_DEPENDENCIES) $(EXTRA_libcfa_la_DEPENDENCIES) 595 $(AM_V_CCLD)$(libcfa_la_LINK) -rpath $(libdir) $(libcfa_la_OBJECTS) $(libcfa_la_LIBADD) $(LIBS) 608 609 libcfathread.la: $(libcfathread_la_OBJECTS) $(libcfathread_la_DEPENDENCIES) $(EXTRA_libcfathread_la_DEPENDENCIES) 610 $(AM_V_CCLD)$(libcfathread_la_LINK) -rpath $(libdir) $(libcfathread_la_OBJECTS) $(libcfathread_la_LIBADD) $(LIBS) 596 611 597 612 mostlyclean-compile: … … 922 937 $(am__mv) $$depbase.Tpo $$depbase.Plo 923 938 $(libobjs) : @CFACC@ @CFACPP@ prelude.cfa 939 $(thread_libobjs) : @CFACC@ @CFACPP@ prelude.cfa 924 940 925 941 -include $(libdeps) 942 943 -include $(thread_libdeps) 926 944 927 945 prelude.o : prelude.cfa extras.cf gcc-builtins.cf builtins.cf @CFACC@ @CFACPP@ -
libcfa/src/bits/containers.hfa
r1f1c102 rf53acdf8 9 9 // Author : Thierry Delisle 10 10 // Created On : Tue Oct 31 16:38:50 2017 11 // Last Modified By : --12 // Last Modified On : --13 // Update Count : 011 // Last Modified By : Peter A. Buhr 12 // Last Modified On : Wed Jun 26 08:52:20 2019 13 // Update Count : 4 14 14 15 15 #pragma once … … 78 78 //----------------------------------------------------------------------------- 79 79 #ifdef __cforall 80 forall(dtype TYPE | is_node(TYPE))80 forall(dtype TYPE) 81 81 #define T TYPE 82 82 #else … … 95 95 96 96 #ifdef __cforall 97 forall(dtype T | is_node(T))97 forall(dtype T) 98 98 static inline void ?{}( __stack(T) & this ) { 99 99 (this.top){ NULL }; … … 116 116 return top; 117 117 } 118 119 forall(dtype T | is_node(T)) 120 static inline int ?!=?( const __stack(T) & this, __attribute__((unused)) zero_t zero ) { 121 return this.top != 0; 122 } 118 123 #endif 119 124 … … 122 127 //----------------------------------------------------------------------------- 123 128 #ifdef __cforall 124 forall(dtype TYPE | is_node(TYPE))129 forall(dtype TYPE) 125 130 #define T TYPE 126 131 #else … … 141 146 #ifdef __cforall 142 147 143 forall(dtype T | is_node(T))148 forall(dtype T) 144 149 static inline void ?{}( __queue(T) & this ) with( this ) { 145 150 head{ NULL }; … … 186 191 187 192 forall(dtype T | is_node(T)) 188 static inline bool ?!=?(__queue(T) & this, __attribute__((unused)) zero_t zero ) {193 static inline int ?!=?( const __queue(T) & this, __attribute__((unused)) zero_t zero ) { 189 194 return this.head != 0; 190 195 } … … 268 273 269 274 forall(dtype T | sized(T)) 270 static inline bool ?!=?(__dllist(T) & this, __attribute__((unused)) zero_t zero ) {275 static inline int ?!=?( const __dllist(T) & this, __attribute__((unused)) zero_t zero ) { 271 276 return this.head != 0; 272 277 } -
libcfa/src/bits/debug.cfa
r1f1c102 rf53acdf8 9 9 // Author : Thierry Delisle 10 10 // Created On : Thu Mar 30 12:30:01 2017 11 // Last Modified By : 12 // Last Modified On : 13 // Update Count : 111 // Last Modified By : Peter A. Buhr 12 // Last Modified On : Sun Jul 14 22:17:35 2019 13 // Update Count : 4 14 14 // 15 15 … … 23 23 } 24 24 25 enum { buffer_size = 512};25 enum { buffer_size = 4096 }; 26 26 static char buffer[ buffer_size ]; 27 27 -
libcfa/src/bits/defs.hfa
r1f1c102 rf53acdf8 41 41 } 42 42 #endif 43 44 #if defined(__cforall_thread__) 45 #define OPTIONAL_THREAD 46 #else 47 #define OPTIONAL_THREAD __attribute__((weak)) 48 #endif -
libcfa/src/bits/locks.hfa
r1f1c102 rf53acdf8 50 50 #ifdef __cforall 51 51 extern "C" { 52 extern void disable_interrupts() ;53 extern void enable_interrupts_noPoll() ;52 extern void disable_interrupts() OPTIONAL_THREAD; 53 extern void enable_interrupts_noPoll() OPTIONAL_THREAD; 54 54 55 55 #ifdef __CFA_DEBUG__ -
libcfa/src/concurrency/alarm.cfa
r1f1c102 rf53acdf8 13 13 // Update Count : 67 14 14 // 15 16 #define __cforall_thread__ 15 17 16 18 extern "C" { -
libcfa/src/concurrency/coroutine.cfa
r1f1c102 rf53acdf8 13 13 // Update Count : 9 14 14 // 15 16 #define __cforall_thread__ 15 17 16 18 #include "coroutine.hfa" … … 98 100 99 101 void ^?{}(coroutine_desc& this) { 100 if(this.state != Halted && this.state != Start ) {102 if(this.state != Halted && this.state != Start && this.state != Primed) { 101 103 coroutine_desc * src = TL_GET( this_thread )->curr_cor; 102 104 coroutine_desc * dst = &this; -
libcfa/src/concurrency/invoke.c
r1f1c102 rf53acdf8 13 13 // Update Count : 5 14 14 // 15 16 #define __cforall_thread__ 15 17 16 18 #include <stdbool.h> … … 31 33 extern void __finish_creation( struct thread_desc * ); 32 34 extern void __leave_thread_monitor( struct thread_desc * this ); 33 extern void disable_interrupts() ;35 extern void disable_interrupts() OPTIONAL_THREAD; 34 36 extern void enable_interrupts( __cfaabi_dbg_ctx_param ); 35 37 -
libcfa/src/concurrency/invoke.h
r1f1c102 rf53acdf8 46 46 #ifdef __cforall 47 47 extern "Cforall" { 48 static inline struct thread_desc *& get_next( struct thread_desc & this );49 static inline struct __condition_criterion_t *& get_next( struct __condition_criterion_t & this );50 51 48 extern thread_local struct KernelThreadData { 52 49 struct thread_desc * volatile this_thread; -
libcfa/src/concurrency/kernel.cfa
r1f1c102 rf53acdf8 13 13 // Update Count : 25 14 14 // 15 16 #define __cforall_thread__ 15 17 16 18 //C Includes … … 943 945 } 944 946 ) 947 948 //----------------------------------------------------------------------------- 949 // Debug 950 bool threading_enabled(void) { 951 return true; 952 } 945 953 // Local Variables: // 946 954 // mode: c // -
libcfa/src/concurrency/kernel_private.hfa
r1f1c102 rf53acdf8 26 26 27 27 extern "C" { 28 void disable_interrupts() ;28 void disable_interrupts() OPTIONAL_THREAD; 29 29 void enable_interrupts_noPoll(); 30 30 void enable_interrupts( __cfaabi_dbg_ctx_param ); -
libcfa/src/concurrency/monitor.cfa
r1f1c102 rf53acdf8 13 13 // Update Count : 9 14 14 // 15 16 #define __cforall_thread__ 15 17 16 18 #include "monitor.hfa" -
libcfa/src/concurrency/mutex.cfa
r1f1c102 rf53acdf8 15 15 // Update Count : 0 16 16 // 17 18 #define __cforall_thread__ 17 19 18 20 #include "mutex.hfa" -
libcfa/src/concurrency/preemption.cfa
r1f1c102 rf53acdf8 13 13 // Update Count : 37 14 14 // 15 16 #define __cforall_thread__ 15 17 16 18 #include "preemption.hfa" -
libcfa/src/concurrency/thread.cfa
r1f1c102 rf53acdf8 13 13 // Update Count : 8 14 14 // 15 16 #define __cforall_thread__ 15 17 16 18 #include "thread.hfa" -
libcfa/src/fstream.cfa
r1f1c102 rf53acdf8 10 10 // Created On : Wed May 27 17:56:53 2015 11 11 // Last Modified By : Peter A. Buhr 12 // Last Modified On : Thu May 16 08:33:28201913 // Update Count : 3 2812 // Last Modified On : Mon Jul 15 18:11:26 2019 13 // Update Count : 349 14 14 // 15 15 … … 24 24 #include <assert.h> 25 25 #include <errno.h> // errno 26 27 28 //*********************************** ofstream *********************************** 29 26 30 27 31 #define IO_MSG "I/O error: " … … 37 41 sepSetCur( os, sepGet( os ) ); 38 42 sepSetTuple( os, ", " ); 39 } 43 } // ?{} 40 44 41 45 // private … … 56 60 void ?{}( ofstream & os, const char * name, const char * mode ) { 57 61 open( os, name, mode ); 58 } 62 } // ?{} 63 59 64 void ?{}( ofstream & os, const char * name ) { 60 65 open( os, name, "w" ); 61 } 66 } // ?{} 62 67 63 68 void sepOn( ofstream & os ) { os.sepOnOff = ! getNL( os ); } … … 95 100 } // sepSet 96 101 102 void ends( ofstream & os ) { 103 if ( getANL( os ) ) nl( os ); 104 else setPrt( os, false ); // turn off 105 if ( &os == &exit ) exit( EXIT_FAILURE ); 106 if ( &os == &abort ) abort(); 107 } // ends 108 97 109 int fail( ofstream & os ) { 98 110 return os.file == 0 || ferror( (FILE *)(os.file) ); … … 107 119 #ifdef __CFA_DEBUG__ 108 120 if ( file == 0 ) { 109 abort ( IO_MSG "open output file \"%s\", %s", name, strerror( errno ));121 abort | IO_MSG "open output file \"" | name | "\"" | nl | strerror( errno ); 110 122 } // if 111 123 #endif // __CFA_DEBUG__ … … 121 133 122 134 if ( fclose( (FILE *)(os.file) ) == EOF ) { 123 abort ( IO_MSG "close output %s", strerror( errno ));135 abort | IO_MSG "close output" | nl | strerror( errno ); 124 136 } // if 125 137 } // close … … 127 139 ofstream & write( ofstream & os, const char * data, size_t size ) { 128 140 if ( fail( os ) ) { 129 abort ( "attempt write I/O on failed stream\n" );141 abort | IO_MSG "attempt write I/O on failed stream"; 130 142 } // if 131 143 132 144 if ( fwrite( data, 1, size, (FILE *)(os.file) ) != size ) { 133 abort ( IO_MSG "write %s", strerror( errno ));145 abort | IO_MSG "write" | nl | strerror( errno ); 134 146 } // if 135 147 return os; … … 142 154 if ( len == EOF ) { 143 155 if ( ferror( (FILE *)(os.file) ) ) { 144 abort ( "invalid write\n" );156 abort | IO_MSG "invalid write"; 145 157 } // if 146 158 } // if … … 153 165 154 166 static ofstream soutFile = { (FILE *)(&_IO_2_1_stdout_) }; 155 ofstream & sout = soutFile ;167 ofstream & sout = soutFile, & stdout = soutFile; 156 168 static ofstream serrFile = { (FILE *)(&_IO_2_1_stderr_) }; 157 ofstream & serr = serrFile; 158 159 // static ofstream sexitFile = { (FILE *)(&_IO_2_1_stdout_) }; 160 // ofstream & sexit = sexitFile; 161 // static ofstream sabortFile = { (FILE *)(&_IO_2_1_stderr_) }; 162 // ofstream & sabort = sabortFile; 163 164 void nl( ofstream & os ) { 165 if ( getANL( os ) ) (ofstream &)(nl( os )); // implementation only 166 else setPrt( os, false ); // turn off 167 } 168 169 //--------------------------------------- 169 ofstream & serr = serrFile, & stderr = serrFile; 170 171 static ofstream exitFile = { (FILE *)(&_IO_2_1_stdout_) }; 172 ofstream & exit = exitFile; 173 static ofstream abortFile = { (FILE *)(&_IO_2_1_stderr_) }; 174 ofstream & abort = abortFile; 175 176 177 //*********************************** ifstream *********************************** 178 170 179 171 180 // private … … 173 182 is.file = file; 174 183 is.nlOnOff = false; 175 } 184 } // ?{} 176 185 177 186 // public … … 180 189 void ?{}( ifstream & is, const char * name, const char * mode ) { 181 190 open( is, name, mode ); 182 } 191 } // ?{} 192 183 193 void ?{}( ifstream & is, const char * name ) { 184 194 open( is, name, "r" ); 185 } 195 } // ?{} 186 196 187 197 void nlOn( ifstream & os ) { os.nlOnOff = true; } … … 201 211 #ifdef __CFA_DEBUG__ 202 212 if ( file == 0 ) { 203 abort ( IO_MSG "open input file \"%s\", %s\n", name, strerror( errno ));213 abort | IO_MSG "open input file \"" | name | "\"" | nl | strerror( errno ); 204 214 } // if 205 215 #endif // __CFA_DEBUG__ … … 215 225 216 226 if ( fclose( (FILE *)(is.file) ) == EOF ) { 217 abort ( IO_MSG "close input %s", strerror( errno ));227 abort | IO_MSG "close input" | nl | strerror( errno ); 218 228 } // if 219 229 } // close … … 221 231 ifstream & read( ifstream & is, char * data, size_t size ) { 222 232 if ( fail( is ) ) { 223 abort ( "attempt read I/O on failed stream\n" );233 abort | IO_MSG "attempt read I/O on failed stream"; 224 234 } // if 225 235 226 236 if ( fread( data, size, 1, (FILE *)(is.file) ) == 0 ) { 227 abort ( IO_MSG "read %s", strerror( errno ));237 abort | IO_MSG "read" | nl | strerror( errno ); 228 238 } // if 229 239 return is; … … 232 242 ifstream &ungetc( ifstream & is, char c ) { 233 243 if ( fail( is ) ) { 234 abort ( "attempt ungetc I/O on failed stream\n" );244 abort | IO_MSG "attempt ungetc I/O on failed stream"; 235 245 } // if 236 246 237 247 if ( ungetc( c, (FILE *)(is.file) ) == EOF ) { 238 abort ( IO_MSG "ungetc %s", strerror( errno ));248 abort | IO_MSG "ungetc" | nl | strerror( errno ); 239 249 } // if 240 250 return is; … … 248 258 if ( len == EOF ) { 249 259 if ( ferror( (FILE *)(is.file) ) ) { 250 abort ( "invalid read\n" );260 abort | IO_MSG "invalid read"; 251 261 } // if 252 262 } // if … … 257 267 258 268 static ifstream sinFile = { (FILE *)(&_IO_2_1_stdin_) }; 259 ifstream & sin = sinFile ;269 ifstream & sin = sinFile, & stdin = sinFile; 260 270 261 271 // Local Variables: // -
libcfa/src/fstream.hfa
r1f1c102 rf53acdf8 10 10 // Created On : Wed May 27 17:56:53 2015 11 11 // Last Modified By : Peter A. Buhr 12 // Last Modified On : Thu May 16 08:34:10201913 // Update Count : 1 5712 // Last Modified On : Mon Jul 15 18:10:23 2019 13 // Update Count : 167 14 14 // 15 15 … … 17 17 18 18 #include "iostream.hfa" 19 20 21 //*********************************** ofstream *********************************** 22 19 23 20 24 enum { sepSize = 16 }; … … 56 60 void sepSetTuple( ofstream &, const char * ); 57 61 62 void ends( ofstream & os ); 58 63 int fail( ofstream & ); 59 64 int flush( ofstream & ); … … 68 73 void ?{}( ofstream & os, const char * name ); 69 74 70 extern ofstream & sout, & serr; 75 extern ofstream & sout, & stdout, & serr, & stderr; // aliases 76 extern ofstream & exit, & abort; 71 77 72 // extern ofstream & sout, & serr, & sexit, & sabort; 73 // void nl( ofstream & os );78 79 //*********************************** ifstream *********************************** 74 80 75 81 … … 96 102 void ?{}( ifstream & is, const char * name ); 97 103 98 extern ifstream & sin ;104 extern ifstream & sin, & stdin; // aliases 99 105 100 106 // Local Variables: // -
libcfa/src/gmp.hfa
r1f1c102 rf53acdf8 10 10 // Created On : Tue Apr 19 08:43:43 2016 11 11 // Last Modified By : Peter A. Buhr 12 // Last Modified On : Sat Apr 20 09:01:52201913 // Update Count : 2 412 // Last Modified On : Sat Jul 13 15:25:05 2019 13 // Update Count : 27 14 14 // 15 15 … … 19 19 20 20 #include <gmp.h> // GNU multi-precise integers 21 #include <fstream.hfa> // sout21 #include <fstream.hfa> // sout 22 22 23 23 struct Int { mpz_t mpz; }; // wrap GMP implementation 24 24 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 ); } 34 35 // literal 36 static inline Int ?`mp( signed long int init ) { return (Int){ init }; } 37 static inline Int ?`mp( unsigned long int init ) { return (Int){ init }; } 38 static inline Int ?`mp( const char * init ) { return (Int){ init }; } 39 40 // assignment 41 static inline Int ?=?( Int & lhs, Int rhs ) { mpz_set( lhs.mpz, rhs.mpz ); return lhs; } 42 static inline Int ?=?( Int & lhs, long int rhs ) { mpz_set_si( lhs.mpz, rhs ); return lhs; } 43 static inline Int ?=?( Int & lhs, unsigned long int rhs ) { mpz_set_ui( lhs.mpz, rhs ); return lhs; } 44 static inline Int ?=?( Int & lhs, const char * rhs ) { if ( mpz_set_str( lhs.mpz, rhs, 0 ) ) { printf( "invalid string conversion\n" ); abort(); } return lhs; } 45 46 static inline char ?=?( char & lhs, Int rhs ) { char val = mpz_get_si( rhs.mpz ); lhs = val; return lhs; } 47 static inline short int ?=?( short int & lhs, Int rhs ) { short int val = mpz_get_si( rhs.mpz ); lhs = val; return lhs; } 48 static inline int ?=?( int & lhs, Int rhs ) { int val = mpz_get_si( rhs.mpz ); lhs = val; return lhs; } 49 static inline long int ?=?( long int & lhs, Int rhs ) { long int val = mpz_get_si( rhs.mpz ); lhs = val; return lhs; } 50 static inline unsigned char ?=?( unsigned char & lhs, Int rhs ) { unsigned char val = mpz_get_ui( rhs.mpz ); lhs = val; return lhs; } 51 static inline unsigned short int ?=?( unsigned short int & lhs, Int rhs ) { unsigned short int val = mpz_get_ui( rhs.mpz ); lhs = val; return lhs; } 52 static inline unsigned int ?=?( unsigned int & lhs, Int rhs ) { unsigned int val = mpz_get_ui( rhs.mpz ); lhs = val; return lhs; } 53 static inline unsigned long int ?=?( unsigned long int & lhs, Int rhs ) { unsigned long int val = mpz_get_ui( rhs.mpz ); lhs = val; return lhs; } 54 55 // conversions 56 static inline long int narrow( Int val ) { return mpz_get_si( val.mpz ); } 57 static inline unsigned long int narrow( Int val ) { return mpz_get_ui( val.mpz ); } 58 59 // comparison 60 static inline int ?==?( Int oper1, Int oper2 ) { return mpz_cmp( oper1.mpz, oper2.mpz ) == 0; } 61 static inline int ?==?( Int oper1, long int oper2 ) { return mpz_cmp_si( oper1.mpz, oper2 ) == 0; } 62 static inline int ?==?( long int oper2, Int oper1 ) { return mpz_cmp_si( oper1.mpz, oper2 ) == 0; } 63 static inline int ?==?( Int oper1, unsigned long int oper2 ) { return mpz_cmp_ui( oper1.mpz, oper2 ) == 0; } 64 static inline int ?==?( unsigned long int oper2, Int oper1 ) { return mpz_cmp_ui( oper1.mpz, oper2 ) == 0; } 65 66 static inline int ?!=?( Int oper1, Int oper2 ) { return ! ( oper1 == oper2 ); } 67 static inline int ?!=?( Int oper1, long int oper2 ) { return ! ( oper1 == oper2 ); } 68 static inline int ?!=?( long int oper1, Int oper2 ) { return ! ( oper1 == oper2 ); } 69 static inline int ?!=?( Int oper1, unsigned long int oper2 ) { return ! ( oper1 == oper2 ); } 70 static inline int ?!=?( unsigned long int oper1, Int oper2 ) { return ! ( oper1 == oper2 ); } 71 72 static inline int ?<?( Int oper1, Int oper2 ) { return mpz_cmp( oper1.mpz, oper2.mpz ) < 0; } 73 static inline int ?<?( Int oper1, long int oper2 ) { return mpz_cmp_si( oper1.mpz, oper2 ) < 0; } 74 static inline int ?<?( long int oper2, Int oper1 ) { return mpz_cmp_si( oper1.mpz, oper2 ) < 0; } 75 static inline int ?<?( Int oper1, unsigned long int oper2 ) { return mpz_cmp_ui( oper1.mpz, oper2 ) < 0; } 76 static inline int ?<?( unsigned long int oper2, Int oper1 ) { return mpz_cmp_ui( oper1.mpz, oper2 ) < 0; } 77 78 static inline int ?<=?( Int oper1, Int oper2 ) { return mpz_cmp( oper1.mpz, oper2.mpz ) <= 0; } 79 static inline int ?<=?( Int oper1, long int oper2 ) { return mpz_cmp_si( oper1.mpz, oper2 ) <= 0; } 80 static inline int ?<=?( long int oper2, Int oper1 ) { return mpz_cmp_si( oper1.mpz, oper2 ) <= 0; } 81 static inline int ?<=?( Int oper1, unsigned long int oper2 ) { return mpz_cmp_ui( oper1.mpz, oper2 ) <= 0; } 82 static inline int ?<=?( unsigned long int oper2, Int oper1 ) { return mpz_cmp_ui( oper1.mpz, oper2 ) <= 0; } 83 84 static inline int ?>?( Int oper1, Int oper2 ) { return ! ( oper1 <= oper2 ); } 85 static inline int ?>?( Int oper1, long int oper2 ) { return ! ( oper1 <= oper2 ); } 86 static inline int ?>?( long int oper1, Int oper2 ) { return ! ( oper1 <= oper2 ); } 87 static inline int ?>?( Int oper1, unsigned long int oper2 ) { return ! ( oper1 <= oper2 ); } 88 static inline int ?>?( unsigned long int oper1, Int oper2 ) { return ! ( oper1 <= oper2 ); } 89 90 static inline int ?>=?( Int oper1, Int oper2 ) { return ! ( oper1 < oper2 ); } 91 static inline int ?>=?( Int oper1, long int oper2 ) { return ! ( oper1 < oper2 ); } 92 static inline int ?>=?( long int oper1, Int oper2 ) { return ! ( oper1 < oper2 ); } 93 static inline int ?>=?( Int oper1, unsigned long int oper2 ) { return ! ( oper1 < oper2 ); } 94 static inline int ?>=?( unsigned long int oper1, Int oper2 ) { return ! ( oper1 < oper2 ); } 95 96 // arithmetic 97 static inline Int +?( Int oper ) { Int pos; mpz_set( pos.mpz, oper.mpz ); return pos; } 98 static inline Int -?( Int oper ) { Int neg; mpz_neg( neg.mpz, oper.mpz ); return neg; } 99 static inline Int ~?( Int oper ) { Int comp; mpz_com( comp.mpz, oper.mpz ); return comp; } 100 101 static inline Int ?&?( Int oper1, Int oper2 ) { Int conjunction; mpz_and( conjunction.mpz, oper1.mpz, oper2.mpz ); return conjunction; } 102 static inline Int ?&?( Int oper1, long int oper2 ) { Int conjunction, temp; mpz_set_si( temp.mpz, oper2 ); mpz_and( conjunction.mpz, oper1.mpz, temp.mpz ); return conjunction; } 103 static inline Int ?&?( long int oper1, Int oper2 ) { Int conjunction, temp; mpz_set_si( temp.mpz, oper1 ); mpz_and( conjunction.mpz, temp.mpz, oper2.mpz ); return conjunction; } 104 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; } 105 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; } 106 static inline Int ?&=?( Int & lhs, Int rhs ) { return lhs = lhs & rhs; } 107 108 static inline Int ?|?( Int oper1, Int oper2 ) { Int disjunction; mpz_ior( disjunction.mpz, oper1.mpz, oper2.mpz ); return disjunction; } 109 static inline Int ?|?( Int oper1, long int oper2 ) { Int disjunction, temp; mpz_set_si( temp.mpz, oper2 ); mpz_ior( disjunction.mpz, oper1.mpz, temp.mpz ); return disjunction; } 110 static inline Int ?|?( long int oper1, Int oper2 ) { Int disjunction, temp; mpz_set_si( temp.mpz, oper1 ); mpz_ior( disjunction.mpz, temp.mpz, oper2.mpz ); return disjunction; } 111 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; } 112 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; } 113 static inline Int ?|=?( Int & lhs, Int rhs ) { return lhs = lhs | rhs; } 114 115 static inline Int ?^?( Int oper1, Int oper2 ) { Int disjunction; mpz_xor( disjunction.mpz, oper1.mpz, oper2.mpz ); return disjunction; } 116 static inline Int ?^?( Int oper1, long int oper2 ) { Int disjunction, temp; mpz_set_si( temp.mpz, oper2 ); mpz_ior( disjunction.mpz, oper1.mpz, temp.mpz ); return disjunction; } 117 static inline Int ?^?( long int oper1, Int oper2 ) { Int disjunction, temp; mpz_set_si( temp.mpz, oper1 ); mpz_ior( disjunction.mpz, temp.mpz, oper2.mpz ); return disjunction; } 118 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; } 119 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; } 120 static inline Int ?^=?( Int & lhs, Int rhs ) { return lhs = lhs ^ rhs; } 121 122 static inline Int ?+?( Int addend1, Int addend2 ) { Int sum; mpz_add( sum.mpz, addend1.mpz, addend2.mpz ); return sum; } 123 static inline Int ?+?( Int addend1, long int addend2 ) { Int sum; if ( addend2 >= 0 ) mpz_add_ui( sum.mpz, addend1.mpz, addend2 ); else mpz_sub_ui( sum.mpz, addend1.mpz, -addend2 ); return sum; } 124 static inline Int ?+?( long int addend2, Int addend1 ) { Int sum; if ( addend2 >= 0 ) mpz_add_ui( sum.mpz, addend1.mpz, addend2 ); else mpz_sub_ui( sum.mpz, addend1.mpz, -addend2 ); return sum; } 125 static inline Int ?+?( Int addend1, unsigned long int addend2 ) { Int sum; mpz_add_ui( sum.mpz, addend1.mpz, addend2 ); return sum; } 126 static inline Int ?+?( unsigned long int addend2, Int addend1 ) { Int sum; mpz_add_ui( sum.mpz, addend1.mpz, addend2 ); return sum; } 127 static inline Int ?+=?( Int & lhs, Int rhs ) { return lhs = lhs + rhs; } 128 static inline Int ?+=?( Int & lhs, long int rhs ) { return lhs = lhs + rhs; } 129 static inline Int ?+=?( Int & lhs, unsigned long int rhs ) { return lhs = lhs + rhs; } 130 static inline Int ++?( Int & lhs ) { return lhs += 1; } 131 static inline Int ?++( Int & lhs ) { Int ret = lhs; lhs += 1; return ret; } 132 133 static inline Int ?-?( Int minuend, Int subtrahend ) { Int diff; mpz_sub( diff.mpz, minuend.mpz, subtrahend.mpz ); return diff; } 134 static inline Int ?-?( Int minuend, long int subtrahend ) { Int diff; if ( subtrahend >= 0 ) mpz_sub_ui( diff.mpz, minuend.mpz, subtrahend ); else mpz_add_ui( diff.mpz, minuend.mpz, -subtrahend ); return diff; } 135 static inline Int ?-?( long int minuend, Int subtrahend ) { Int diff; if ( subtrahend >= 0 ) mpz_ui_sub( diff.mpz, minuend, subtrahend.mpz ); else { mpz_add_ui( diff.mpz, subtrahend.mpz, -minuend ); mpz_neg( diff.mpz, diff.mpz ); } return diff; } 136 static inline Int ?-?( Int minuend, unsigned long int subtrahend ) { Int diff; mpz_sub_ui( diff.mpz, minuend.mpz, subtrahend ); return diff; } 137 static inline Int ?-?( unsigned long int minuend, Int subtrahend ) { Int diff; mpz_ui_sub( diff.mpz, minuend, subtrahend.mpz ); return diff; } 138 static inline Int ?-=?( Int & lhs, Int rhs ) { return lhs = lhs - rhs; } 139 static inline Int ?-=?( Int & lhs, long int rhs ) { return lhs = lhs - rhs; } 140 static inline Int ?-=?( Int & lhs, unsigned long int rhs ) { return lhs = lhs - rhs; } 141 static inline Int --?( Int & lhs ) { return lhs -= 1; } 142 static inline Int ?--( Int & lhs ) { Int ret = lhs; lhs -= 1; return ret; } 143 144 static inline Int ?*?( Int multiplicator, Int multiplicand ) { Int product; mpz_mul( product.mpz, multiplicator.mpz, multiplicand.mpz ); return product; } 145 static inline Int ?*?( Int multiplicator, long int multiplicand ) { Int product; mpz_mul_si( product.mpz, multiplicator.mpz, multiplicand ); return product; } 146 static inline Int ?*?( long int multiplicand, Int multiplicator ) { Int product; mpz_mul_si( product.mpz, multiplicator.mpz, multiplicand ); return product; } 147 static inline Int ?*?( Int multiplicator, unsigned long int multiplicand ) { Int product; mpz_mul_ui( product.mpz, multiplicator.mpz, multiplicand ); return product; } 148 static inline Int ?*?( unsigned long int multiplicand, Int multiplicator ) { Int product; mpz_mul_ui( product.mpz, multiplicator.mpz, multiplicand ); return product; } 149 static inline Int ?*=?( Int & lhs, Int rhs ) { return lhs = lhs * rhs; } 150 static inline Int ?*=?( Int & lhs, long int rhs ) { return lhs = lhs * rhs; } 151 static inline Int ?*=?( Int & lhs, unsigned long int rhs ) { return lhs = lhs * rhs; } 152 153 // some code for operators "/" and "%" taken from g++ gmpxx.h 154 static inline Int ?/?( Int dividend, Int divisor ) { Int quotient; mpz_tdiv_q( quotient.mpz, dividend.mpz, divisor.mpz ); return quotient; } 155 static inline Int ?/?( Int dividend, unsigned long int divisor ) { Int quotient; mpz_tdiv_q_ui( quotient.mpz, dividend.mpz, divisor ); return quotient; } 156 static inline Int ?/?( unsigned long int dividend, Int divisor ) { 157 Int quotient; 158 if ( mpz_sgn( divisor.mpz ) >= 0 ) { 159 if ( mpz_fits_ulong_p( divisor.mpz ) ) 160 mpz_set_ui( quotient.mpz, dividend / mpz_get_ui( divisor.mpz ) ); 161 else 162 mpz_set_ui( quotient.mpz, 0 ); 163 } else { 164 mpz_neg( quotient.mpz, divisor.mpz ); 165 if ( mpz_fits_ulong_p( quotient.mpz ) ) { 166 mpz_set_ui( quotient.mpz, dividend / mpz_get_ui( quotient.mpz ) ); 25 static inline { 26 // constructor 27 void ?{}( Int & this ) { mpz_init( this.mpz ); } 28 void ?{}( Int & this, Int init ) { mpz_init_set( this.mpz, init.mpz ); } 29 void ?{}( Int & this, zero_t ) { mpz_init_set_si( this.mpz, 0 ); } 30 void ?{}( Int & this, one_t ) { mpz_init_set_si( this.mpz, 1 ); } 31 void ?{}( Int & this, signed long int init ) { mpz_init_set_si( this.mpz, init ); } 32 void ?{}( Int & this, unsigned long int init ) { mpz_init_set_ui( this.mpz, init ); } 33 void ?{}( Int & this, const char * val ) { if ( mpz_init_set_str( this.mpz, val, 0 ) ) abort(); } 34 void ^?{}( Int & this ) { mpz_clear( this.mpz ); } 35 36 // literal 37 Int ?`mp( signed long int init ) { return (Int){ init }; } 38 Int ?`mp( unsigned long int init ) { return (Int){ init }; } 39 Int ?`mp( const char * init ) { return (Int){ init }; } 40 41 // assignment 42 Int ?=?( Int & lhs, Int rhs ) { mpz_set( lhs.mpz, rhs.mpz ); return lhs; } 43 Int ?=?( Int & lhs, long int rhs ) { mpz_set_si( lhs.mpz, rhs ); return lhs; } 44 Int ?=?( Int & lhs, unsigned long int rhs ) { mpz_set_ui( lhs.mpz, rhs ); return lhs; } 45 Int ?=?( Int & lhs, const char * rhs ) { if ( mpz_set_str( lhs.mpz, rhs, 0 ) ) { abort | "invalid string conversion"; } return lhs; } 46 47 char ?=?( char & lhs, Int rhs ) { char val = mpz_get_si( rhs.mpz ); lhs = val; return lhs; } 48 short int ?=?( short int & lhs, Int rhs ) { short int val = mpz_get_si( rhs.mpz ); lhs = val; return lhs; } 49 int ?=?( int & lhs, Int rhs ) { int val = mpz_get_si( rhs.mpz ); lhs = val; return lhs; } 50 long int ?=?( long int & lhs, Int rhs ) { long int val = mpz_get_si( rhs.mpz ); lhs = val; return lhs; } 51 unsigned char ?=?( unsigned char & lhs, Int rhs ) { unsigned char val = mpz_get_ui( rhs.mpz ); lhs = val; return lhs; } 52 unsigned short int ?=?( unsigned short int & lhs, Int rhs ) { unsigned short int val = mpz_get_ui( rhs.mpz ); lhs = val; return lhs; } 53 unsigned int ?=?( unsigned int & lhs, Int rhs ) { unsigned int val = mpz_get_ui( rhs.mpz ); lhs = val; return lhs; } 54 unsigned long int ?=?( unsigned long int & lhs, Int rhs ) { unsigned long int val = mpz_get_ui( rhs.mpz ); lhs = val; return lhs; } 55 56 // conversions 57 long int narrow( Int val ) { return mpz_get_si( val.mpz ); } 58 unsigned long int narrow( Int val ) { return mpz_get_ui( val.mpz ); } 59 60 // comparison 61 int ?==?( Int oper1, Int oper2 ) { return mpz_cmp( oper1.mpz, oper2.mpz ) == 0; } 62 int ?==?( Int oper1, long int oper2 ) { return mpz_cmp_si( oper1.mpz, oper2 ) == 0; } 63 int ?==?( long int oper2, Int oper1 ) { return mpz_cmp_si( oper1.mpz, oper2 ) == 0; } 64 int ?==?( Int oper1, unsigned long int oper2 ) { return mpz_cmp_ui( oper1.mpz, oper2 ) == 0; } 65 int ?==?( unsigned long int oper2, Int oper1 ) { return mpz_cmp_ui( oper1.mpz, oper2 ) == 0; } 66 67 int ?!=?( Int oper1, Int oper2 ) { return ! ( oper1 == oper2 ); } 68 int ?!=?( Int oper1, long int oper2 ) { return ! ( oper1 == oper2 ); } 69 int ?!=?( long int oper1, Int oper2 ) { return ! ( oper1 == oper2 ); } 70 int ?!=?( Int oper1, unsigned long int oper2 ) { return ! ( oper1 == oper2 ); } 71 int ?!=?( unsigned long int oper1, Int oper2 ) { return ! ( oper1 == oper2 ); } 72 73 int ?<?( Int oper1, Int oper2 ) { return mpz_cmp( oper1.mpz, oper2.mpz ) < 0; } 74 int ?<?( Int oper1, long int oper2 ) { return mpz_cmp_si( oper1.mpz, oper2 ) < 0; } 75 int ?<?( long int oper2, Int oper1 ) { return mpz_cmp_si( oper1.mpz, oper2 ) < 0; } 76 int ?<?( Int oper1, unsigned long int oper2 ) { return mpz_cmp_ui( oper1.mpz, oper2 ) < 0; } 77 int ?<?( unsigned long int oper2, Int oper1 ) { return mpz_cmp_ui( oper1.mpz, oper2 ) < 0; } 78 79 int ?<=?( Int oper1, Int oper2 ) { return mpz_cmp( oper1.mpz, oper2.mpz ) <= 0; } 80 int ?<=?( Int oper1, long int oper2 ) { return mpz_cmp_si( oper1.mpz, oper2 ) <= 0; } 81 int ?<=?( long int oper2, Int oper1 ) { return mpz_cmp_si( oper1.mpz, oper2 ) <= 0; } 82 int ?<=?( Int oper1, unsigned long int oper2 ) { return mpz_cmp_ui( oper1.mpz, oper2 ) <= 0; } 83 int ?<=?( unsigned long int oper2, Int oper1 ) { return mpz_cmp_ui( oper1.mpz, oper2 ) <= 0; } 84 85 int ?>?( Int oper1, Int oper2 ) { return ! ( oper1 <= oper2 ); } 86 int ?>?( Int oper1, long int oper2 ) { return ! ( oper1 <= oper2 ); } 87 int ?>?( long int oper1, Int oper2 ) { return ! ( oper1 <= oper2 ); } 88 int ?>?( Int oper1, unsigned long int oper2 ) { return ! ( oper1 <= oper2 ); } 89 int ?>?( unsigned long int oper1, Int oper2 ) { return ! ( oper1 <= oper2 ); } 90 91 int ?>=?( Int oper1, Int oper2 ) { return ! ( oper1 < oper2 ); } 92 int ?>=?( Int oper1, long int oper2 ) { return ! ( oper1 < oper2 ); } 93 int ?>=?( long int oper1, Int oper2 ) { return ! ( oper1 < oper2 ); } 94 int ?>=?( Int oper1, unsigned long int oper2 ) { return ! ( oper1 < oper2 ); } 95 int ?>=?( unsigned long int oper1, Int oper2 ) { return ! ( oper1 < oper2 ); } 96 97 // arithmetic 98 Int +?( Int oper ) { Int pos; mpz_set( pos.mpz, oper.mpz ); return pos; } 99 Int -?( Int oper ) { Int neg; mpz_neg( neg.mpz, oper.mpz ); return neg; } 100 Int ~?( Int oper ) { Int comp; mpz_com( comp.mpz, oper.mpz ); return comp; } 101 102 Int ?&?( Int oper1, Int oper2 ) { Int conjunction; mpz_and( conjunction.mpz, oper1.mpz, oper2.mpz ); return conjunction; } 103 Int ?&?( Int oper1, long int oper2 ) { Int conjunction, temp; mpz_set_si( temp.mpz, oper2 ); mpz_and( conjunction.mpz, oper1.mpz, temp.mpz ); return conjunction; } 104 Int ?&?( long int oper1, Int oper2 ) { Int conjunction, temp; mpz_set_si( temp.mpz, oper1 ); mpz_and( conjunction.mpz, temp.mpz, oper2.mpz ); return conjunction; } 105 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; } 106 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; } 107 Int ?&=?( Int & lhs, Int rhs ) { return lhs = lhs & rhs; } 108 109 Int ?|?( Int oper1, Int oper2 ) { Int disjunction; mpz_ior( disjunction.mpz, oper1.mpz, oper2.mpz ); return disjunction; } 110 Int ?|?( Int oper1, long int oper2 ) { Int disjunction, temp; mpz_set_si( temp.mpz, oper2 ); mpz_ior( disjunction.mpz, oper1.mpz, temp.mpz ); return disjunction; } 111 Int ?|?( long int oper1, Int oper2 ) { Int disjunction, temp; mpz_set_si( temp.mpz, oper1 ); mpz_ior( disjunction.mpz, temp.mpz, oper2.mpz ); return disjunction; } 112 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; } 113 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; } 114 Int ?|=?( Int & lhs, Int rhs ) { return lhs = lhs | rhs; } 115 116 Int ?^?( Int oper1, Int oper2 ) { Int disjunction; mpz_xor( disjunction.mpz, oper1.mpz, oper2.mpz ); return disjunction; } 117 Int ?^?( Int oper1, long int oper2 ) { Int disjunction, temp; mpz_set_si( temp.mpz, oper2 ); mpz_ior( disjunction.mpz, oper1.mpz, temp.mpz ); return disjunction; } 118 Int ?^?( long int oper1, Int oper2 ) { Int disjunction, temp; mpz_set_si( temp.mpz, oper1 ); mpz_ior( disjunction.mpz, temp.mpz, oper2.mpz ); return disjunction; } 119 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; } 120 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; } 121 Int ?^=?( Int & lhs, Int rhs ) { return lhs = lhs ^ rhs; } 122 123 Int ?+?( Int addend1, Int addend2 ) { Int sum; mpz_add( sum.mpz, addend1.mpz, addend2.mpz ); return sum; } 124 Int ?+?( Int addend1, long int addend2 ) { Int sum; if ( addend2 >= 0 ) mpz_add_ui( sum.mpz, addend1.mpz, addend2 ); else mpz_sub_ui( sum.mpz, addend1.mpz, -addend2 ); return sum; } 125 Int ?+?( long int addend2, Int addend1 ) { Int sum; if ( addend2 >= 0 ) mpz_add_ui( sum.mpz, addend1.mpz, addend2 ); else mpz_sub_ui( sum.mpz, addend1.mpz, -addend2 ); return sum; } 126 Int ?+?( Int addend1, unsigned long int addend2 ) { Int sum; mpz_add_ui( sum.mpz, addend1.mpz, addend2 ); return sum; } 127 Int ?+?( unsigned long int addend2, Int addend1 ) { Int sum; mpz_add_ui( sum.mpz, addend1.mpz, addend2 ); return sum; } 128 Int ?+=?( Int & lhs, Int rhs ) { return lhs = lhs + rhs; } 129 Int ?+=?( Int & lhs, long int rhs ) { return lhs = lhs + rhs; } 130 Int ?+=?( Int & lhs, unsigned long int rhs ) { return lhs = lhs + rhs; } 131 Int ++?( Int & lhs ) { return lhs += 1; } 132 Int ?++( Int & lhs ) { Int ret = lhs; lhs += 1; return ret; } 133 134 Int ?-?( Int minuend, Int subtrahend ) { Int diff; mpz_sub( diff.mpz, minuend.mpz, subtrahend.mpz ); return diff; } 135 Int ?-?( Int minuend, long int subtrahend ) { Int diff; if ( subtrahend >= 0 ) mpz_sub_ui( diff.mpz, minuend.mpz, subtrahend ); else mpz_add_ui( diff.mpz, minuend.mpz, -subtrahend ); return diff; } 136 Int ?-?( long int minuend, Int subtrahend ) { Int diff; if ( subtrahend >= 0 ) mpz_ui_sub( diff.mpz, minuend, subtrahend.mpz ); else { mpz_add_ui( diff.mpz, subtrahend.mpz, -minuend ); mpz_neg( diff.mpz, diff.mpz ); } return diff; } 137 Int ?-?( Int minuend, unsigned long int subtrahend ) { Int diff; mpz_sub_ui( diff.mpz, minuend.mpz, subtrahend ); return diff; } 138 Int ?-?( unsigned long int minuend, Int subtrahend ) { Int diff; mpz_ui_sub( diff.mpz, minuend, subtrahend.mpz ); return diff; } 139 Int ?-=?( Int & lhs, Int rhs ) { return lhs = lhs - rhs; } 140 Int ?-=?( Int & lhs, long int rhs ) { return lhs = lhs - rhs; } 141 Int ?-=?( Int & lhs, unsigned long int rhs ) { return lhs = lhs - rhs; } 142 Int --?( Int & lhs ) { return lhs -= 1; } 143 Int ?--( Int & lhs ) { Int ret = lhs; lhs -= 1; return ret; } 144 145 Int ?*?( Int multiplicator, Int multiplicand ) { Int product; mpz_mul( product.mpz, multiplicator.mpz, multiplicand.mpz ); return product; } 146 Int ?*?( Int multiplicator, long int multiplicand ) { Int product; mpz_mul_si( product.mpz, multiplicator.mpz, multiplicand ); return product; } 147 Int ?*?( long int multiplicand, Int multiplicator ) { Int product; mpz_mul_si( product.mpz, multiplicator.mpz, multiplicand ); return product; } 148 Int ?*?( Int multiplicator, unsigned long int multiplicand ) { Int product; mpz_mul_ui( product.mpz, multiplicator.mpz, multiplicand ); return product; } 149 Int ?*?( unsigned long int multiplicand, Int multiplicator ) { Int product; mpz_mul_ui( product.mpz, multiplicator.mpz, multiplicand ); return product; } 150 Int ?*=?( Int & lhs, Int rhs ) { return lhs = lhs * rhs; } 151 Int ?*=?( Int & lhs, long int rhs ) { return lhs = lhs * rhs; } 152 Int ?*=?( Int & lhs, unsigned long int rhs ) { return lhs = lhs * rhs; } 153 154 // some code for operators "/" and "%" taken from g++ gmpxx.h 155 Int ?/?( Int dividend, Int divisor ) { Int quotient; mpz_tdiv_q( quotient.mpz, dividend.mpz, divisor.mpz ); return quotient; } 156 Int ?/?( Int dividend, unsigned long int divisor ) { Int quotient; mpz_tdiv_q_ui( quotient.mpz, dividend.mpz, divisor ); return quotient; } 157 Int ?/?( unsigned long int dividend, Int divisor ) { 158 Int quotient; 159 if ( mpz_sgn( divisor.mpz ) >= 0 ) { 160 if ( mpz_fits_ulong_p( divisor.mpz ) ) 161 mpz_set_ui( quotient.mpz, dividend / mpz_get_ui( divisor.mpz ) ); 162 else 163 mpz_set_ui( quotient.mpz, 0 ); 164 } else { 165 mpz_neg( quotient.mpz, divisor.mpz ); 166 if ( mpz_fits_ulong_p( quotient.mpz ) ) { 167 mpz_set_ui( quotient.mpz, dividend / mpz_get_ui( quotient.mpz ) ); 168 mpz_neg( quotient.mpz, quotient.mpz ); 169 } else 170 mpz_set_ui( quotient.mpz, 0 ); 171 } // if 172 return quotient; 173 } // ?/? 174 Int ?/?( Int dividend, long int divisor ) { 175 Int quotient; 176 if ( divisor >= 0 ) 177 mpz_tdiv_q_ui( quotient.mpz, dividend.mpz, divisor ); 178 else { 179 mpz_tdiv_q_ui( quotient.mpz, dividend.mpz, -divisor ); 167 180 mpz_neg( quotient.mpz, quotient.mpz ); 168 } else 169 mpz_set_ui( quotient.mpz, 0 ); 170 } // if 171 return quotient; 172 } // ?/? 173 static inline Int ?/?( Int dividend, long int divisor ) { 174 Int quotient; 175 if ( divisor >= 0 ) 176 mpz_tdiv_q_ui( quotient.mpz, dividend.mpz, divisor ); 177 else { 178 mpz_tdiv_q_ui( quotient.mpz, dividend.mpz, -divisor ); 179 mpz_neg( quotient.mpz, quotient.mpz ); 180 } // if 181 return quotient; 182 } // ?/? 183 static inline Int ?/?( long int dividend, Int divisor ) { 184 Int quotient; 185 if ( mpz_fits_slong_p( divisor.mpz ) ) 186 mpz_set_si( quotient.mpz, dividend / mpz_get_si( divisor.mpz ) ); 187 else { 188 // if divisor is bigger than a long then the quotient must be zero, unless dividend==LONG_MIN and 189 // dividend==-LONG_MIN in which case the quotient is -1 190 mpz_set_si( quotient.mpz, mpz_cmpabs_ui( divisor.mpz, (dividend >= 0 ? dividend : -dividend)) == 0 ? -1 : 0 ); 191 } // if 192 return quotient; 193 } // ?/? 194 static inline Int ?/=?( Int & lhs, Int rhs ) { return lhs = lhs / rhs; } 195 static inline Int ?/=?( Int & lhs, long int rhs ) { return lhs = lhs / rhs; } 196 static inline Int ?/=?( Int & lhs, unsigned long int rhs ) { return lhs = lhs / rhs; } 197 198 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 ]; } 199 static inline [ Int, Int ] div( Int dividend, unsigned long int divisor ) { Int quotient, remainder; mpz_fdiv_qr_ui( quotient.mpz, remainder.mpz, dividend.mpz, divisor ); return [ quotient, remainder ]; } 200 201 static inline Int ?%?( Int dividend, Int divisor ) { Int remainder; mpz_tdiv_r( remainder.mpz, dividend.mpz, divisor.mpz ); return remainder; } 202 static inline Int ?%?( Int dividend, unsigned long int divisor ) { Int remainder; mpz_tdiv_r_ui( remainder.mpz, dividend.mpz, divisor ); return remainder; } 203 static inline Int ?%?( unsigned long int dividend, Int divisor ) { 204 Int remainder; 205 if ( mpz_sgn( divisor.mpz ) >= 0 ) { 206 if ( mpz_fits_ulong_p( divisor.mpz ) ) 207 mpz_set_ui( remainder.mpz, dividend % mpz_get_ui( divisor.mpz ) ); 208 else 209 mpz_set_ui( remainder.mpz, dividend ); 210 } else { 211 mpz_neg( remainder.mpz, divisor.mpz ); 212 if ( mpz_fits_ulong_p( remainder.mpz ) ) 213 mpz_set_ui( remainder.mpz, dividend % mpz_get_ui( remainder.mpz ) ); 214 else 215 mpz_set_ui( remainder.mpz, dividend ); 216 } // if 217 return remainder; 218 } // ?%? 219 static inline Int ?%?( Int dividend, long int divisor ) { 220 Int remainder; 221 mpz_tdiv_r_ui( remainder.mpz, dividend.mpz, (divisor >= 0 ? divisor : -divisor)); 222 return remainder; 223 } // ?%? 224 static inline Int ?%?( long int dividend, Int divisor ) { 225 Int remainder; 226 if ( mpz_fits_slong_p( divisor.mpz ) ) 227 mpz_set_si( remainder.mpz, dividend % mpz_get_si( divisor.mpz ) ); 228 else { 229 // if divisor is bigger than a long then the remainder is dividend unchanged, unless dividend==LONG_MIN and 230 // dividend==-LONG_MIN in which case the remainder is 0 231 mpz_set_si( remainder.mpz, mpz_cmpabs_ui( divisor.mpz, (dividend >= 0 ? dividend : -dividend)) == 0 ? 0 : dividend); 232 } // if 233 return remainder; 234 } // ?%? 235 static inline Int ?%=?( Int & lhs, Int rhs ) { return lhs = lhs % rhs; } 236 static inline Int ?%=?( Int & lhs, long int rhs ) { return lhs = lhs % rhs; } 237 static inline Int ?%=?( Int & lhs, unsigned long int rhs ) { return lhs = lhs % rhs; } 238 239 static inline Int ?<<?( Int shiften, mp_bitcnt_t shift ) { Int shifted; mpz_mul_2exp( shifted.mpz, shiften.mpz, shift ); return shifted; } 240 static inline Int ?<<=?( Int & lhs, mp_bitcnt_t shift ) { return lhs = lhs << shift; } 241 static inline Int ?>>?( Int shiften, mp_bitcnt_t shift ) { Int shifted; mpz_fdiv_q_2exp( shifted.mpz, shiften.mpz, shift ); return shifted; } 242 static inline Int ?>>=?( Int & lhs, mp_bitcnt_t shift ) { return lhs = lhs >> shift; } 243 244 // number functions 245 static inline Int abs( Int oper ) { Int positive; mpz_abs( positive.mpz, oper.mpz ); return positive; } 246 static inline Int fact( unsigned long int N ) { Int factorial; mpz_fac_ui( factorial.mpz, N ); return factorial; } 247 static inline Int gcd( Int oper1, Int oper2 ) { Int gcdret; mpz_gcd( gcdret.mpz, oper1.mpz, oper2.mpz ); return gcdret; } 248 static inline Int pow( Int base, unsigned long int exponent ) { Int power; mpz_pow_ui( power.mpz, base.mpz, exponent ); return power; } 249 static inline Int pow( unsigned long int base, unsigned long int exponent ) { Int power; mpz_ui_pow_ui( power.mpz, base, exponent ); return power; } 250 static inline void srandom( gmp_randstate_t state ) { gmp_randinit_default( state ); } 251 static inline Int random( gmp_randstate_t state, mp_bitcnt_t n ) { Int rand; mpz_urandomb( rand.mpz, state, n ); return rand; } 252 static inline Int random( gmp_randstate_t state, Int n ) { Int rand; mpz_urandomm( rand.mpz, state, n.mpz ); return rand; } 253 static inline Int random( gmp_randstate_t state, mp_size_t max_size ) { Int rand; mpz_random( rand.mpz, max_size ); return rand; } 254 static inline int sgn( Int oper ) { return mpz_sgn( oper.mpz ); } 255 static inline Int sqrt( Int oper ) { Int root; mpz_sqrt( root.mpz, oper.mpz ); return root; } 256 257 // I/O 258 static inline forall( dtype istype | istream( istype ) ) 259 istype & ?|?( istype & is, Int & mp ) { 260 gmp_scanf( "%Zd", &mp ); 261 return is; 262 } // ?|? 263 264 static inline forall( dtype ostype | ostream( ostype ) ) { 265 ostype & ?|?( ostype & os, Int mp ) { 266 if ( sepPrt( os ) ) fmt( os, "%s", sepGetCur( os ) ); 267 gmp_printf( "%Zd", mp.mpz ); 268 sepOn( os ); 269 return os; 181 } // if 182 return quotient; 183 } // ?/? 184 Int ?/?( long int dividend, Int divisor ) { 185 Int quotient; 186 if ( mpz_fits_slong_p( divisor.mpz ) ) 187 mpz_set_si( quotient.mpz, dividend / mpz_get_si( divisor.mpz ) ); 188 else { 189 // if divisor is bigger than a long then the quotient must be zero, unless dividend==LONG_MIN and 190 // dividend==-LONG_MIN in which case the quotient is -1 191 mpz_set_si( quotient.mpz, mpz_cmpabs_ui( divisor.mpz, (dividend >= 0 ? dividend : -dividend)) == 0 ? -1 : 0 ); 192 } // if 193 return quotient; 194 } // ?/? 195 Int ?/=?( Int & lhs, Int rhs ) { return lhs = lhs / rhs; } 196 Int ?/=?( Int & lhs, long int rhs ) { return lhs = lhs / rhs; } 197 Int ?/=?( Int & lhs, unsigned long int rhs ) { return lhs = lhs / rhs; } 198 199 [ Int, Int ] div( Int dividend, Int divisor ) { Int quotient, remainder; mpz_fdiv_qr( quotient.mpz, remainder.mpz, dividend.mpz, divisor.mpz ); return [ quotient, remainder ]; } 200 [ Int, Int ] div( Int dividend, unsigned long int divisor ) { Int quotient, remainder; mpz_fdiv_qr_ui( quotient.mpz, remainder.mpz, dividend.mpz, divisor ); return [ quotient, remainder ]; } 201 202 Int ?%?( Int dividend, Int divisor ) { Int remainder; mpz_tdiv_r( remainder.mpz, dividend.mpz, divisor.mpz ); return remainder; } 203 Int ?%?( Int dividend, unsigned long int divisor ) { Int remainder; mpz_tdiv_r_ui( remainder.mpz, dividend.mpz, divisor ); return remainder; } 204 Int ?%?( unsigned long int dividend, Int divisor ) { 205 Int remainder; 206 if ( mpz_sgn( divisor.mpz ) >= 0 ) { 207 if ( mpz_fits_ulong_p( divisor.mpz ) ) 208 mpz_set_ui( remainder.mpz, dividend % mpz_get_ui( divisor.mpz ) ); 209 else 210 mpz_set_ui( remainder.mpz, dividend ); 211 } else { 212 mpz_neg( remainder.mpz, divisor.mpz ); 213 if ( mpz_fits_ulong_p( remainder.mpz ) ) 214 mpz_set_ui( remainder.mpz, dividend % mpz_get_ui( remainder.mpz ) ); 215 else 216 mpz_set_ui( remainder.mpz, dividend ); 217 } // if 218 return remainder; 219 } // ?%? 220 Int ?%?( Int dividend, long int divisor ) { 221 Int remainder; 222 mpz_tdiv_r_ui( remainder.mpz, dividend.mpz, (divisor >= 0 ? divisor : -divisor)); 223 return remainder; 224 } // ?%? 225 Int ?%?( long int dividend, Int divisor ) { 226 Int remainder; 227 if ( mpz_fits_slong_p( divisor.mpz ) ) 228 mpz_set_si( remainder.mpz, dividend % mpz_get_si( divisor.mpz ) ); 229 else { 230 // if divisor is bigger than a long then the remainder is dividend unchanged, unless dividend==LONG_MIN and 231 // dividend==-LONG_MIN in which case the remainder is 0 232 mpz_set_si( remainder.mpz, mpz_cmpabs_ui( divisor.mpz, (dividend >= 0 ? dividend : -dividend)) == 0 ? 0 : dividend); 233 } // if 234 return remainder; 235 } // ?%? 236 Int ?%=?( Int & lhs, Int rhs ) { return lhs = lhs % rhs; } 237 Int ?%=?( Int & lhs, long int rhs ) { return lhs = lhs % rhs; } 238 Int ?%=?( Int & lhs, unsigned long int rhs ) { return lhs = lhs % rhs; } 239 240 Int ?<<?( Int shiften, mp_bitcnt_t shift ) { Int shifted; mpz_mul_2exp( shifted.mpz, shiften.mpz, shift ); return shifted; } 241 Int ?<<=?( Int & lhs, mp_bitcnt_t shift ) { return lhs = lhs << shift; } 242 Int ?>>?( Int shiften, mp_bitcnt_t shift ) { Int shifted; mpz_fdiv_q_2exp( shifted.mpz, shiften.mpz, shift ); return shifted; } 243 Int ?>>=?( Int & lhs, mp_bitcnt_t shift ) { return lhs = lhs >> shift; } 244 245 // number functions 246 Int abs( Int oper ) { Int positive; mpz_abs( positive.mpz, oper.mpz ); return positive; } 247 Int fact( unsigned long int N ) { Int factorial; mpz_fac_ui( factorial.mpz, N ); return factorial; } 248 Int gcd( Int oper1, Int oper2 ) { Int gcdret; mpz_gcd( gcdret.mpz, oper1.mpz, oper2.mpz ); return gcdret; } 249 Int pow( Int base, unsigned long int exponent ) { Int power; mpz_pow_ui( power.mpz, base.mpz, exponent ); return power; } 250 Int pow( unsigned long int base, unsigned long int exponent ) { Int power; mpz_ui_pow_ui( power.mpz, base, exponent ); return power; } 251 void srandom( gmp_randstate_t state ) { gmp_randinit_default( state ); } 252 Int random( gmp_randstate_t state, mp_bitcnt_t n ) { Int rand; mpz_urandomb( rand.mpz, state, n ); return rand; } 253 Int random( gmp_randstate_t state, Int n ) { Int rand; mpz_urandomm( rand.mpz, state, n.mpz ); return rand; } 254 Int random( gmp_randstate_t state, mp_size_t max_size ) { Int rand; mpz_random( rand.mpz, max_size ); return rand; } 255 int sgn( Int oper ) { return mpz_sgn( oper.mpz ); } 256 Int sqrt( Int oper ) { Int root; mpz_sqrt( root.mpz, oper.mpz ); return root; } 257 258 // I/O 259 forall( dtype istype | istream( istype ) ) 260 istype & ?|?( istype & is, Int & mp ) { 261 gmp_scanf( "%Zd", &mp ); 262 return is; 270 263 } // ?|? 271 264 272 void ?|?( ostype & os, Int mp ) { 273 (ostype)(os | mp); nl( os ); 274 } // ?|? 265 forall( dtype ostype | ostream( ostype ) ) { 266 ostype & ?|?( ostype & os, Int mp ) { 267 if ( sepPrt( os ) ) fmt( os, "%s", sepGetCur( os ) ); 268 gmp_printf( "%Zd", mp.mpz ); 269 sepOn( os ); 270 return os; 271 } // ?|? 272 273 void ?|?( ostype & os, Int mp ) { 274 (ostype)(os | mp); ends( os ); 275 } // ?|? 276 } // distribution 275 277 } // distribution 276 278 -
libcfa/src/interpose.cfa
r1f1c102 rf53acdf8 10 10 // Created On : Wed Mar 29 16:10:31 2017 11 11 // Last Modified By : Peter A. Buhr 12 // Last Modified On : S at May 5 11:37:35 201813 // Update Count : 11 112 // Last Modified On : Sun Jul 14 22:57:16 2019 13 // Update Count : 116 14 14 // 15 15 … … 81 81 //============================================================================================= 82 82 83 void sigHandler_segv ( __CFA_SIGPARMS__ );84 void sigHandler_ill ( __CFA_SIGPARMS__ );85 void sigHandler_fpe ( __CFA_SIGPARMS__ );86 void sigHandler_ab ort( __CFA_SIGPARMS__ );87 void sigHandler_term ( __CFA_SIGPARMS__ );83 void sigHandler_segv( __CFA_SIGPARMS__ ); 84 void sigHandler_ill ( __CFA_SIGPARMS__ ); 85 void sigHandler_fpe ( __CFA_SIGPARMS__ ); 86 void sigHandler_abrt( __CFA_SIGPARMS__ ); 87 void sigHandler_term( __CFA_SIGPARMS__ ); 88 88 89 89 struct { … … 110 110 __cfaabi_sigaction( SIGILL , sigHandler_ill , SA_SIGINFO ); 111 111 __cfaabi_sigaction( SIGFPE , sigHandler_fpe , SA_SIGINFO ); 112 __cfaabi_sigaction( SIGABRT, sigHandler_ab ort, SA_SIGINFO | SA_RESETHAND);112 __cfaabi_sigaction( SIGABRT, sigHandler_abrt, SA_SIGINFO | SA_RESETHAND); 113 113 __cfaabi_sigaction( SIGTERM, sigHandler_term , SA_SIGINFO ); 114 114 __cfaabi_sigaction( SIGINT , sigHandler_term , SA_SIGINFO ); … … 204 204 if ( *p == '(' ) { 205 205 name = p; 206 } 207 else if ( *p == '+' ) { 206 } else if ( *p == '+' ) { 208 207 offset_begin = p; 209 } 210 else if ( *p == ')' ) { 208 } else if ( *p == ')' ) { 211 209 offset_end = p; 212 210 break; … … 223 221 224 222 __cfaabi_dbg_bits_print_nolock( "(%i) %s : %s + %s %s\n", frameNo, messages[i], name, offset_begin, offset_end); 225 } 226 // otherwise, print the whole line 227 else { 223 } else { // otherwise, print the whole line 228 224 __cfaabi_dbg_bits_print_nolock( "(%i) %s\n", frameNo, messages[i] ); 229 225 } … … 258 254 } 259 255 260 void sigHandler_ab ort( __CFA_SIGPARMS__ ) {256 void sigHandler_abrt( __CFA_SIGPARMS__ ) { 261 257 __cfaabi_backtrace(); 262 258 -
libcfa/src/iostream.cfa
r1f1c102 rf53acdf8 10 10 // Created On : Wed May 27 17:56:53 2015 11 11 // Last Modified By : Peter A. Buhr 12 // Last Modified On : Thu Jun 13 17:21:10201913 // Update Count : 8 1212 // Last Modified On : Sat Jul 13 08:07:59 2019 13 // Update Count : 821 14 14 // 15 15 … … 30 30 31 31 32 //*********************************** Ostream ***********************************32 //*********************************** ostream *********************************** 33 33 34 34 … … 40 40 } // ?|? 41 41 void ?|?( ostype & os, zero_t z ) { 42 (ostype &)(os | z); nl( os );42 (ostype &)(os | z); ends( os ); 43 43 } // ?|? 44 44 … … 49 49 } // ?|? 50 50 void ?|?( ostype & os, one_t o ) { 51 (ostype &)(os | o); nl( os );51 (ostype &)(os | o); ends( os ); 52 52 } // ?|? 53 53 … … 58 58 } // ?|? 59 59 void ?|?( ostype & os, bool b ) { 60 (ostype &)(os | b); nl( os );60 (ostype &)(os | b); ends( os ); 61 61 } // ?|? 62 62 … … 67 67 } // ?|? 68 68 void ?|?( ostype & os, char c ) { 69 (ostype &)(os | c); nl( os );69 (ostype &)(os | c); ends( os ); 70 70 } // ?|? 71 71 … … 76 76 } // ?|? 77 77 void ?|?( ostype & os, signed char sc ) { 78 (ostype &)(os | sc); nl( os );78 (ostype &)(os | sc); ends( os ); 79 79 } // ?|? 80 80 … … 85 85 } // ?|? 86 86 void ?|?( ostype & os, unsigned char usc ) { 87 (ostype &)(os | usc); nl( os );87 (ostype &)(os | usc); ends( os ); 88 88 } // ?|? 89 89 … … 94 94 } // ?|? 95 95 void & ?|?( ostype & os, short int si ) { 96 (ostype &)(os | si); nl( os );96 (ostype &)(os | si); ends( os ); 97 97 } // ?|? 98 98 … … 103 103 } // ?|? 104 104 void & ?|?( ostype & os, unsigned short int usi ) { 105 (ostype &)(os | usi); nl( os );105 (ostype &)(os | usi); ends( os ); 106 106 } // ?|? 107 107 … … 112 112 } // ?|? 113 113 void & ?|?( ostype & os, int i ) { 114 (ostype &)(os | i); nl( os );114 (ostype &)(os | i); ends( os ); 115 115 } // ?|? 116 116 … … 121 121 } // ?|? 122 122 void & ?|?( ostype & os, unsigned int ui ) { 123 (ostype &)(os | ui); nl( os );123 (ostype &)(os | ui); ends( os ); 124 124 } // ?|? 125 125 … … 130 130 } // ?|? 131 131 void & ?|?( ostype & os, long int li ) { 132 (ostype &)(os | li); nl( os );132 (ostype &)(os | li); ends( os ); 133 133 } // ?|? 134 134 … … 139 139 } // ?|? 140 140 void & ?|?( ostype & os, unsigned long int uli ) { 141 (ostype &)(os | uli); nl( os );141 (ostype &)(os | uli); ends( os ); 142 142 } // ?|? 143 143 … … 148 148 } // ?|? 149 149 void & ?|?( ostype & os, long long int lli ) { 150 (ostype &)(os | lli); nl( os );150 (ostype &)(os | lli); ends( os ); 151 151 } // ?|? 152 152 … … 157 157 } // ?|? 158 158 void & ?|?( ostype & os, unsigned long long int ulli ) { 159 (ostype &)(os | ulli); nl( os );159 (ostype &)(os | ulli); ends( os ); 160 160 } // ?|? 161 161 … … 180 180 } // ?|? 181 181 void & ?|?( ostype & os, float f ) { 182 (ostype &)(os | f); nl( os );182 (ostype &)(os | f); ends( os ); 183 183 } // ?|? 184 184 … … 189 189 } // ?|? 190 190 void & ?|?( ostype & os, double d ) { 191 (ostype &)(os | d); nl( os );191 (ostype &)(os | d); ends( os ); 192 192 } // ?|? 193 193 … … 198 198 } // ?|? 199 199 void & ?|?( ostype & os, long double ld ) { 200 (ostype &)(os | ld); nl( os );200 (ostype &)(os | ld); ends( os ); 201 201 } // ?|? 202 202 … … 210 210 } // ?|? 211 211 void & ?|?( ostype & os, float _Complex fc ) { 212 (ostype &)(os | fc); nl( os );212 (ostype &)(os | fc); ends( os ); 213 213 } // ?|? 214 214 … … 222 222 } // ?|? 223 223 void & ?|?( ostype & os, double _Complex dc ) { 224 (ostype &)(os | dc); nl( os );224 (ostype &)(os | dc); ends( os ); 225 225 } // ?|? 226 226 … … 234 234 } // ?|? 235 235 void & ?|?( ostype & os, long double _Complex ldc ) { 236 (ostype &)(os | ldc); nl( os );236 (ostype &)(os | ldc); ends( os ); 237 237 } // ?|? 238 238 … … 276 276 } // ?|? 277 277 void ?|?( ostype & os, const char * str ) { 278 (ostype &)(os | str); nl( os );278 (ostype &)(os | str); ends( os ); 279 279 } // ?|? 280 280 … … 305 305 } // ?|? 306 306 void ?|?( ostype & os, const void * p ) { 307 (ostype &)(os | p); nl( os );307 (ostype &)(os | p); ends( os ); 308 308 } // ?|? 309 309 … … 315 315 void ?|?( ostype & os, ostype & (* manip)( ostype & ) ) { 316 316 (ostype &)(manip( os )); 317 if ( getPrt( os ) ) nl( os ); // something printed ?317 if ( getPrt( os ) ) ends( os ); // something printed ? 318 318 setPrt( os, false ); // turn off 319 319 } // ?|? … … 335 335 } // nl 336 336 337 void nl( ostype & os ) {338 if ( getANL( os ) ) (ostype &)(nl( os )); // implementation only339 else setPrt( os, false ); // turn off340 } // nl341 342 337 ostype & nonl( ostype & os ) { 343 338 setPrt( os, false ); // turn off … … 386 381 } // ?|? 387 382 void ?|?( ostype & os, T arg, Params rest ) { 388 // (ostype &)(?|?( os, arg, rest )); nl( os );383 // (ostype &)(?|?( os, arg, rest )); ends( os ); 389 384 (ostype &)(os | arg); // print first argument 390 385 sepSetCur( os, sepGetTuple( os ) ); // switch to tuple separator 391 386 (ostype &)(os | rest); // print remaining arguments 392 387 sepSetCur( os, sepGet( os ) ); // switch to regular separator 393 nl( os );388 ends( os ); 394 389 } // ?|? 395 390 } // distribution … … 408 403 } // distribution 409 404 410 //*********************************** Manipulators ***********************************411 412 //*********************************** Integral ***********************************405 //*********************************** manipulators *********************************** 406 407 //*********************************** integral *********************************** 413 408 414 409 static const char * shortbin[] = { "0", "1", "10", "11", "100", "101", "110", "111", "1000", "1001", "1010", "1011", "1100", "1101", "1110", "1111" }; … … 478 473 return os; \ 479 474 } /* ?|? */ \ 480 void ?|?( ostype & os, _Ostream_Manip(T) f ) { (ostype &)(os | f); nl( os ); } \475 void ?|?( ostype & os, _Ostream_Manip(T) f ) { (ostype &)(os | f); ends( os ); } \ 481 476 } // distribution 482 477 … … 492 487 IntegralFMTImpl( unsigned long long int, 'u', "% *ll ", "% *.*ll " ) 493 488 494 //*********************************** Floating Point ***********************************489 //*********************************** floating point *********************************** 495 490 496 491 #define PrintWithDP2( os, format, val, ... ) \ … … 504 499 if ( ! f.flags.left ) { \ 505 500 buf[i] = '.'; buf[i + 1] = '\0'; \ 506 if ( buf[0] == ' ' ) bufbeg = 1; /* decimal point within width */ \501 if ( buf[0] == ' ' ) bufbeg = 1; /* decimal point within width */ \ 507 502 } else { \ 508 503 for ( i = 0; i < len && buf[i] != ' '; i += 1 ); /* trailing blank ? */ \ … … 541 536 return os; \ 542 537 } /* ?|? */ \ 543 void ?|?( ostype & os, _Ostream_Manip(T) f ) { (ostype &)(os | f); nl( os ); } \538 void ?|?( ostype & os, _Ostream_Manip(T) f ) { (ostype &)(os | f); ends( os ); } \ 544 539 } // distribution 545 540 … … 547 542 FloatingPointFMTImpl( long double, "% *L ", "% *.*L " ) 548 543 549 //*********************************** Character ***********************************544 //*********************************** character *********************************** 550 545 551 546 forall( dtype ostype | ostream( ostype ) ) { 552 547 ostype & ?|?( ostype & os, _Ostream_Manip(char) f ) { 553 if ( f.base != 'c' ) { // bespoke binary/octal/hex format548 if ( f.base != 'c' ) { // bespoke binary/octal/hex format 554 549 _Ostream_Manip(unsigned char) fmtuc @= { f.val, f.wd, f.pc, f.base, {'\0'} }; 555 550 fmtuc.flags.pc = f.flags.pc; … … 563 558 564 559 #define CFMTNP "% * " 565 char fmtstr[sizeof(CFMTNP)]; // sizeof includes '\0'560 char fmtstr[sizeof(CFMTNP)]; // sizeof includes '\0' 566 561 memcpy( &fmtstr, CFMTNP, sizeof(CFMTNP) ); 567 int star = 1; // position before first '*'562 int star = 1; // position before first '*' 568 563 569 564 // Insert flags into spaces before '*', from right to left. … … 571 566 fmtstr[star] = '%'; 572 567 573 fmtstr[sizeof(CFMTNP)-2] = f.base; // sizeof includes '\0'568 fmtstr[sizeof(CFMTNP)-2] = f.base; // sizeof includes '\0' 574 569 // printf( "%d %s\n", f.wd, &fmtstr[star] ); 575 570 fmt( os, &fmtstr[star], f.wd, f.val ); 576 571 return os; 577 572 } // ?|? 578 void ?|?( ostype & os, _Ostream_Manip(char) f ) { (ostype &)(os | f); nl( os ); }573 void ?|?( ostype & os, _Ostream_Manip(char) f ) { (ostype &)(os | f); ends( os ); } 579 574 } // distribution 580 575 581 //*********************************** C String ***********************************576 //*********************************** C string *********************************** 582 577 583 578 forall( dtype ostype | ostream( ostype ) ) { … … 621 616 return os; 622 617 } // ?|? 623 void ?|?( ostype & os, _Ostream_Manip(const char *) f ) { (ostype &)(os | f); nl( os ); }618 void ?|?( ostype & os, _Ostream_Manip(const char *) f ) { (ostype &)(os | f); ends( os ); } 624 619 } // distribution 625 620 626 621 627 //*********************************** Istream ***********************************622 //*********************************** istream *********************************** 628 623 629 624 … … 636 631 else { 637 632 fprintf( stderr, "invalid Boolean constant\n" ); 638 abort(); 633 abort(); // cannot use abort stream 639 634 } // if 640 635 return is; … … 644 639 char temp; 645 640 for () { 646 fmt( is, "%c", &temp ); // must pass pointer through varg to fmt641 fmt( is, "%c", &temp ); // must pass pointer through varg to fmt 647 642 // do not overwrite parameter with newline unless appropriate 648 643 if ( temp != '\n' || getANL( is ) ) { c = temp; break; } … … 771 766 } // distribution 772 767 773 //*********************************** Manipulators ***********************************768 //*********************************** manipulators *********************************** 774 769 775 770 forall( dtype istype | istream( istype ) ) … … 778 773 if ( ! f.s ) { 779 774 // printf( "skip %s %d\n", f.scanset, f.wd ); 780 if ( f.wd == -1 ) fmt( is, f.scanset, "" ); // no input arguments775 if ( f.wd == -1 ) fmt( is, f.scanset, "" ); // no input arguments 781 776 else for ( f.wd ) fmt( is, "%*c" ); 782 777 return is; -
libcfa/src/iostream.hfa
r1f1c102 rf53acdf8 10 10 // Created On : Wed May 27 17:56:53 2015 11 11 // Last Modified By : Peter A. Buhr 12 // Last Modified On : Thu Jun 13 17:20:21201913 // Update Count : 3 2512 // Last Modified On : Fri Jul 12 12:08:38 2019 13 // Update Count : 334 14 14 // 15 15 … … 19 19 20 20 21 //*********************************** Ostream ***********************************21 //*********************************** ostream *********************************** 22 22 23 23 … … 47 47 void sepSetTuple( ostype &, const char * ); // set tuple separator to string (15 character maximum) 48 48 49 void ends( ostype & os ); // end of output statement 49 50 int fail( ostype & ); 50 51 int flush( ostype & ); … … 98 99 void ?|?( ostype &, unsigned long long int ); 99 100 100 ostype & ?|?( ostype &, float ); // FIX ME: should not be required101 void ?|?( ostype &, float ); // FIX ME: should not be required101 ostype & ?|?( ostype &, float ); 102 void ?|?( ostype &, float ); 102 103 ostype & ?|?( ostype &, double ); 103 104 void ?|?( ostype &, double ); … … 126 127 void ?|?( ostype &, ostype & (*)( ostype & ) ); 127 128 ostype & nl( ostype & ); 128 void nl( ostype & );129 129 ostype & nonl( ostype & ); 130 130 ostype & sep( ostype & ); … … 150 150 } // distribution 151 151 152 //*********************************** Manipulators ***********************************152 //*********************************** manipulators *********************************** 153 153 154 154 forall( otype T ) … … 169 169 }; // _Ostream_Manip 170 170 171 //*********************************** Integral ***********************************171 //*********************************** integral *********************************** 172 172 173 173 // See 6.7.9. 19) The initialization shall occur in initializer list order, each initializer provided for a particular … … 207 207 IntegralFMTDecl( unsigned long long int, 'u' ) 208 208 209 //*********************************** Floating Point ***********************************209 //*********************************** floating point *********************************** 210 210 211 211 // Default suffix for values with no fraction is "." … … 236 236 FloatingPointFMTDecl( long double ) 237 237 238 //*********************************** Character ***********************************238 //*********************************** character *********************************** 239 239 240 240 static inline { … … 253 253 } // ?|? 254 254 255 //*********************************** C String ***********************************255 //*********************************** C string *********************************** 256 256 257 257 static inline { … … 272 272 273 273 274 //*********************************** Istream ***********************************274 //*********************************** istream *********************************** 275 275 276 276 … … 326 326 } // distribution 327 327 328 //*********************************** Manipulators ***********************************328 //*********************************** manipulators *********************************** 329 329 330 330 struct _Istream_Cstr { … … 403 403 404 404 405 //*********************************** Time ***********************************405 //*********************************** time *********************************** 406 406 407 407 -
libcfa/src/rational.cfa
r1f1c102 rf53acdf8 10 10 // Created On : Wed Apr 6 17:54:28 2016 11 11 // Last Modified By : Peter A. Buhr 12 // Last Modified On : Thu Mar 28 17:33:03201913 // Update Count : 18 112 // Last Modified On : Fri Jul 12 18:12:08 2019 13 // Update Count : 184 14 14 // 15 15 … … 35 35 static RationalImpl simplify( RationalImpl & n, RationalImpl & d ) { 36 36 if ( d == (RationalImpl){0} ) { 37 abort ( "Invalid rational number construction: denominator cannot be equal to 0.\n" );37 abort | "Invalid rational number construction: denominator cannot be equal to 0."; 38 38 } // exit 39 39 if ( d < (RationalImpl){0} ) { d = -d; n = -n; } // move sign to numerator … … 167 167 168 168 void ?|?( ostype & os, Rational(RationalImpl) r ) { 169 (ostype &)(os | r); nl( os );169 (ostype &)(os | r); ends( os ); 170 170 } // ?|? 171 171 } // distribution -
libcfa/src/stdlib.cfa
r1f1c102 rf53acdf8 10 10 // Created On : Thu Jan 28 17:10:29 2016 11 11 // Last Modified By : Peter A. Buhr 12 // Last Modified On : Thu Jul 12 08:03:59 201813 // Update Count : 4 5812 // Last Modified On : Mon Jun 24 17:34:44 2019 13 // Update Count : 462 14 14 // 15 15 … … 65 65 forall( dtype T | sized(T), ttype Params | { void ?{}( T &, Params ); } ) 66 66 T * anew( size_t dim, Params p ) { 67 T * arr = alloc( dim );67 T * arr = alloc( dim ); 68 68 for ( unsigned int i = 0; i < dim; i += 1 ) { 69 69 (arr[i]){ p }; // run constructor … … 252 252 long double _Complex random( void ) { return (long double)drand48() + (long double _Complex)(drand48() * _Complex_I); } 253 253 254 //--------------------------------------- 255 256 bool threading_enabled(void) __attribute__((weak)) { 257 return false; 258 } 254 259 255 260 // Local Variables: // -
libcfa/src/stdlib.hfa
r1f1c102 rf53acdf8 15 15 16 16 #pragma once 17 18 #include "bits/defs.hfa" 17 19 18 20 #include <stdlib.h> // *alloc, strto*, ato* … … 246 248 #include "common.hfa" 247 249 250 //--------------------------------------- 251 252 extern bool threading_enabled(void) OPTIONAL_THREAD; 253 248 254 // Local Variables: // 249 255 // mode: c // -
libcfa/src/time.cfa
r1f1c102 rf53acdf8 10 10 // Created On : Tue Mar 27 13:33:14 2018 11 11 // Last Modified By : Peter A. Buhr 12 // Last Modified On : S un Dec 23 22:57:48 201813 // Update Count : 5712 // Last Modified On : Sat Jul 13 08:41:55 2019 13 // Update Count : 65 14 14 // 15 15 16 16 #include "time.hfa" 17 #include " iostream.hfa"17 #include "fstream.hfa" 18 18 #include <stdio.h> // snprintf 19 19 #include <assert.h> … … 37 37 if ( ns != 0 ) { // some ? 38 38 char buf[16]; 39 (ostype &)(os | nanomsd( ns, buf )); // print nanoseconds39 (ostype &)(os | nanomsd( ns, buf )); // print nanoseconds 40 40 } // if 41 41 return os; … … 43 43 44 44 void ?|?( ostype & os, Duration dur ) with( dur ) { 45 (ostype &)(os | dur); nl( os );45 (ostype &)(os | dur); ends( os ); 46 46 } // ?|? 47 47 } // distribution … … 52 52 53 53 #ifdef __CFA_DEBUG__ 54 #define CreateFmt "Attempt to create Time( year=%d (>=1970), month=%d (1-12), day=%d (1-31), hour=%d (0-23), min=%d (0-59), sec=%d (0-60), nsec=%d (0-999_999_999), " \ 55 "which exceeds range 00:00:00 UTC, January 1, 1970 to 03:14:07 UTC, January 19, 2038." 54 static void tabort( int year, int month, int day, int hour, int min, int sec, int nsec ) { 55 abort | "Attempt to create Time( year=" | year | "(>=1970), month=" | month | "(1-12), day=" | day | "(1-31), hour=" | hour | "(0-23), min=" | min | "(0-59), sec=" | sec 56 | "(0-60), nsec=" | nsec | "(0-999_999_999), which exceeds range 00:00:00 UTC, January 1, 1970 to 03:14:07 UTC, January 19, 2038."; 57 } // tabort 56 58 #endif // __CFA_DEBUG__ 57 59 … … 63 65 #ifdef __CFA_DEBUG__ 64 66 if ( month < 1 || 12 < month ) { 65 abort( CreateFmt, year, month, day, hour, (int)min, sec, nsec );67 tabort( year, month, day, hour, min, sec, nsec ); 66 68 } // if 67 69 #endif // __CFA_DEBUG__ … … 69 71 #ifdef __CFA_DEBUG__ 70 72 if ( day < 1 || 31 < day ) { 71 abort( CreateFmt, year, month, day, hour, (int)min, sec, nsec );73 tabort( year, month, day, hour, min, sec, nsec ); 72 74 } // if 73 75 #endif // __CFA_DEBUG__ … … 79 81 #ifdef __CFA_DEBUG__ 80 82 if ( epochsec == (time_t)-1 ) { 81 abort( CreateFmt, year, month, day, hour, (int)min, sec, nsec );83 tabort( year, month, day, hour, min, sec, nsec ); 82 84 } // if 83 85 #endif // __CFA_DEBUG__ … … 85 87 #ifdef __CFA_DEBUG__ 86 88 if ( tv > 2147483647LL * TIMEGRAN ) { // between 00:00:00 UTC, January 1, 1970 and 03:14:07 UTC, January 19, 2038. 87 abort( CreateFmt, year, month, day, hour, (int)min, sec, nsec );89 tabort( year, month, day, hour, min, sec, nsec ); 88 90 } // if 89 91 #endif // __CFA_DEBUG__ … … 150 152 long int ns = (tv < 0 ? -tv : tv) % TIMEGRAN; // compute nanoseconds 151 153 if ( ns == 0 ) { // none ? 152 (ostype &)(os | buf); // print date/time/year154 (ostype &)(os | buf); // print date/time/year 153 155 } else { 154 156 buf[19] = '\0'; // truncate to "Wed Jun 30 21:49:08" 155 157 char buf2[16]; 156 158 nanomsd( ns, buf2 ); // compute nanoseconds 157 (ostype &)(os | buf | buf2 | ' ' | &buf[20]); // print date/time, nanoseconds and year159 (ostype &)(os | buf | buf2 | ' ' | &buf[20]); // print date/time, nanoseconds and year 158 160 } // if 159 161 return os; … … 161 163 162 164 void ?|?( ostype & os, Time time ) with( time ) { 163 (ostype &)(os | time); nl( os );165 (ostype &)(os | time); ends( os ); 164 166 } // ?|? 165 167 } // distribution
Note:
See TracChangeset
for help on using the changeset viewer.