Changeset 1048b31 for src/libcfa
- Timestamp:
- May 2, 2016, 3:28:16 PM (10 years ago)
- Branches:
- ADT, aaron-thesis, arm-eh, ast-experimental, cleanup-dtors, ctor, deferred_resn, demangler, enum, forall-pointer-decay, gc_noraii, jacob/cs343-translation, jenkins-sandbox, master, memory, new-ast, new-ast-unique-expr, new-env, no_list, persistent-indexer, pthread-emulation, qualifiedEnum, resolv-new, with_gc
- Children:
- 1b7ea43
- Parents:
- 1f6e009 (diff), e945826 (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:
-
- 5 added
- 9 edited
-
Makefile.am (modified) (2 diffs)
-
Makefile.in (modified) (3 diffs)
-
fstream (modified) (3 diffs)
-
fstream.c (modified) (8 diffs)
-
iostream (modified) (4 diffs)
-
iostream.c (modified) (20 diffs)
-
limits (modified) (1 diff)
-
limits.c (added)
-
math (added)
-
math.c (added)
-
rational (added)
-
rational.c (added)
-
stdlib (modified) (5 diffs)
-
stdlib.c (modified) (7 diffs)
Legend:
- Unmodified
- Added
- Removed
-
src/libcfa/Makefile.am
r1f6e009 r1048b31 11 11 ## Created On : Sun May 31 08:54:01 2015 12 12 ## Last Modified By : Peter A. Buhr 13 ## Last Modified On : Wed Mar 2 22:59:23201614 ## Update Count : 1 1913 ## Last Modified On : Tue Apr 19 22:30:17 2016 14 ## Update Count : 124 15 15 ############################################################################### 16 16 … … 60 60 ${CC} ${CFLAGS} -c -o $@ $< 61 61 62 libs = stdlib iostream fstream iterator62 libs = limits stdlib math iostream fstream iterator rational 63 63 libcfa_a_SOURCES = libcfa-prelude.c ${libs:=.c} 64 64 65 cheaders = # expat66 cfaheaders = limits65 cheaders = # expat 66 cfaheaders = # limits 67 67 include_HEADERS = ${cheaders:=.h} ${libs} ${cfaheaders} 68 68 -
src/libcfa/Makefile.in
r1f6e009 r1048b31 83 83 libcfa_a_AR = $(AR) $(ARFLAGS) 84 84 libcfa_a_LIBADD = 85 am__objects_1 = stdlib.$(OBJEXT) iostream.$(OBJEXT) fstream.$(OBJEXT) \ 86 iterator.$(OBJEXT) 85 am__objects_1 = limits.$(OBJEXT) stdlib.$(OBJEXT) math.$(OBJEXT) \ 86 iostream.$(OBJEXT) fstream.$(OBJEXT) iterator.$(OBJEXT) \ 87 rational.$(OBJEXT) 87 88 am_libcfa_a_OBJECTS = libcfa-prelude.$(OBJEXT) $(am__objects_1) 88 89 libcfa_a_OBJECTS = $(am_libcfa_a_OBJECTS) … … 213 214 MAINTAINERCLEANFILES = ${addprefix ${libdir}/,${cfalib_DATA}} \ 214 215 ${addprefix ${libdir}/,${lib_LIBRARIES}} ${includedir}/* 215 libs = stdlib iostream fstream iterator216 libs = limits stdlib math iostream fstream iterator rational 216 217 libcfa_a_SOURCES = libcfa-prelude.c ${libs:=.c} 217 cheaders = # expat218 cfaheaders = limits218 cheaders = # expat 219 cfaheaders = # limits 219 220 include_HEADERS = ${cheaders:=.h} ${libs} ${cfaheaders} 220 221 all: all-am … … 297 298 @AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/iterator.Po@am__quote@ 298 299 @AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/libcfa-prelude.Po@am__quote@ 300 @AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/limits.Po@am__quote@ 301 @AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/math.Po@am__quote@ 302 @AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/rational.Po@am__quote@ 299 303 @AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/stdlib.Po@am__quote@ 300 304 -
src/libcfa/fstream
r1f6e009 r1048b31 10 10 // Created On : Wed May 27 17:56:53 2015 11 11 // Last Modified By : Peter A. Buhr 12 // Last Modified On : Wed Mar 2 15:08:14 201613 // Update Count : 7812 // Last Modified On : Thu Apr 28 08:08:04 2016 13 // Update Count : 88 14 14 // 15 15 … … 20 20 21 21 enum { separateSize = 16 }; 22 struct ofstream { void *file; int separate; char separator[separateSize]; }; 22 struct ofstream { 23 void *file; 24 _Bool sepDefault; 25 int sepOnOff; // FIX ME: type should be _Bool 26 char separator[separateSize]; 27 }; // ofstream 23 28 24 29 _Bool sepPrt( ofstream * ); 25 30 void sepOn( ofstream * ); 26 31 void sepOff( ofstream * ); 32 void sepReset( ofstream * ); 33 void sepReset( ofstream *, _Bool ); 27 34 void sepSet( ofstream *, const char * ); 28 35 const char * sepGet( ofstream * ); 29 voidsepDisable( ofstream * );30 voidsepEnable( ofstream * );36 _Bool sepDisable( ofstream * ); 37 _Bool sepEnable( ofstream * ); 31 38 int fail( ofstream * ); 32 39 int flush( ofstream * ); … … 39 46 40 47 // implement context istream 41 struct ifstream { void *file; }; 48 struct ifstream { 49 void *file; 50 }; // ifstream 42 51 43 52 int fail( ifstream * is ); -
src/libcfa/fstream.c
r1f6e009 r1048b31 10 10 // Created On : Wed May 27 17:56:53 2015 11 11 // Last Modified By : Peter A. Buhr 12 // Last Modified On : Mon Feb 29 18:41:10 201613 // Update Count : 1 6212 // Last Modified On : Wed Apr 27 18:20:30 2016 13 // Update Count : 187 14 14 // 15 15 … … 25 25 } 26 26 27 #define IO_MSG "I/O error "27 #define IO_MSG "I/O error: " 28 28 29 _Bool sepPrt( ofstream * os ) { return os->separate == 1; } 30 void sepOn( ofstream * os ) { if ( os->separate != 2 ) os->separate = 1; } 31 void sepOff( ofstream * os ) { if ( os->separate != 2 ) os->separate = 0; } 29 _Bool sepPrt( ofstream * os ) { return os->sepOnOff; } 30 void sepOn( ofstream * os ) { os->sepOnOff = 1; } 31 void sepOff( ofstream * os ) { os->sepOnOff = 0; } 32 void sepReset( ofstream * os ) { os->sepOnOff = os->sepDefault; } 33 void sepReset( ofstream * os, _Bool reset ) { os->sepDefault = reset; os->sepOnOff = os->sepDefault; } 32 34 void sepSet( ofstream * os, const char * s ) { 33 35 strncpy( &(os->separator[0]), s, separateSize - 1 ); … … 35 37 } // sepSet 36 38 const char * sepGet( ofstream * os ) { return &(os->separator[0]); } 37 void sepDisable( ofstream *os ) { os->separate = 2; } 38 void sepEnable( ofstream *os ) { os->separate = 0; } 39 _Bool sepDisable( ofstream *os ) { 40 _Bool temp = os->sepDefault; 41 os->sepDefault = 0; 42 sepReset( os ); 43 return temp; 44 } // sepDisable 45 _Bool sepEnable( ofstream *os ) { 46 _Bool temp = os->sepDefault; 47 os->sepDefault = 1; 48 sepReset( os ); 49 return temp; 50 } // sepEnable 39 51 40 52 int fail( ofstream * os ) { … … 49 61 FILE *file = fopen( name, mode ); 50 62 if ( file == 0 ) { // do not change unless successful 51 perror( IO_MSG "open output" ); 63 fprintf( stderr, IO_MSG "open output file \"%s\", ", name ); 64 perror( 0 ); 52 65 exit( EXIT_FAILURE ); 53 66 } // if … … 80 93 int prtfmt( ofstream * os, const char fmt[], ... ) { 81 94 va_list args; 82 83 95 va_start( args, fmt ); 84 96 int len = vfprintf( (FILE *)(os->file), fmt, args ); … … 90 102 } // if 91 103 va_end( args ); 104 105 sepReset( os ); // reset separator 92 106 return len; 93 107 } // prtfmt 94 108 95 109 96 static ofstream soutFile = { (FILE *)(&_IO_2_1_stdout_), 0, { ' ', '\0' } };110 static ofstream soutFile = { (FILE *)(&_IO_2_1_stdout_), 1, 0, { ' ', '\0' } }; 97 111 ofstream *sout = &soutFile; 98 static ofstream serrFile = { (FILE *)(&_IO_2_1_stderr_), 0, { ' ', '\0' } };112 static ofstream serrFile = { (FILE *)(&_IO_2_1_stderr_), 1, 0, { ' ', '\0' } }; 99 113 ofstream *serr = &serrFile; 100 114 … … 114 128 FILE *t = fopen( name, mode ); 115 129 if ( t == 0 ) { // do not change unless successful 116 perror( IO_MSG "open input" ); 130 fprintf( stderr, IO_MSG "open input file \"%s\", ", name ); 131 perror( 0 ); 117 132 exit( EXIT_FAILURE ); 118 133 } // if … … 175 190 // Local Variables: // 176 191 // tab-width: 4 // 177 // compile-command: "cfa fstream.c" //178 192 // End: // -
src/libcfa/iostream
r1f6e009 r1048b31 10 10 // Created On : Wed May 27 17:56:53 2015 11 11 // Last Modified By : Peter A. Buhr 12 // Last Modified On : Wed Mar 2 18:05:27201613 // Update Count : 8512 // Last Modified On : Sun Apr 10 23:00:12 2016 13 // Update Count : 92 14 14 // 15 15 … … 20 20 21 21 trait ostream( dtype ostype ) { 22 _Bool sepPrt( ostype * ); 23 void sepOn( ostype * ); 24 void sepOff( ostype * ); 25 void sepSet( ostype *, const char * ); 26 const char * sepGet( ostype * ); 27 void sepDisable( ostype * ); 28 void sepEnable( ostype * ); 22 _Bool sepPrt( ostype * ); // return separator state (on/off) 23 void sepOn( ostype * ); // turn separator state on 24 void sepOff( ostype * ); // turn separator state off 25 void sepReset( ostype * ); // set separator state to default state 26 void sepReset( ostype *, _Bool ); // set separator and default state 27 void sepSet( ostype *, const char * ); // set separator to string (15 character maximum) 28 const char * sepGet( ostype * ); // get separator string 29 _Bool sepDisable( ostype * ); // set default state to off, and return previous state 30 _Bool sepEnable( ostype * ); // set default state to on, and return previous state 31 29 32 int fail( ostype * ); 30 33 int flush( ostype * ); … … 67 70 forall( dtype ostype | ostream( ostype ) ) ostype * sepOn( ostype * ); 68 71 forall( dtype ostype | ostream( ostype ) ) ostype * sepOff( ostype * ); 72 forall( dtype ostype | ostream( ostype ) ) ostype * sepDisable( ostype * ); 73 forall( dtype ostype | ostream( ostype ) ) ostype * sepEnable( ostype * ); 69 74 70 75 // writes the range [begin, end) to the given stream … … 110 115 forall( dtype istype | istream( istype ) ) istype * ?|?( istype *, long double _Complex * ); 111 116 112 struct _Istream_ str1{ char * s; };113 _Istream_ str1str( char * );114 forall( dtype istype | istream( istype ) ) istype * ?|?( istype *, _Istream_ str1);117 struct _Istream_cstrUC { char * s; }; 118 _Istream_cstrUC cstr( char * ); 119 forall( dtype istype | istream( istype ) ) istype * ?|?( istype *, _Istream_cstrUC ); 115 120 116 struct _Istream_ str2{ char * s; int size; };117 _Istream_ str2str( char *, int size );118 forall( dtype istype | istream( istype ) ) istype * ?|?( istype *, _Istream_ str2);121 struct _Istream_cstrC { char * s; int size; }; 122 _Istream_cstrC cstr( char *, int size ); 123 forall( dtype istype | istream( istype ) ) istype * ?|?( istype *, _Istream_cstrC ); 119 124 120 125 #endif // __IOSTREAM_H__ -
src/libcfa/iostream.c
r1f6e009 r1048b31 10 10 // Created On : Wed May 27 17:56:53 2015 11 11 // Last Modified By : Peter A. Buhr 12 // Last Modified On : Mon Mar 7 13:51:23 201613 // Update Count : 22712 // Last Modified On : Sat Apr 30 14:00:53 2016 13 // Update Count : 302 14 14 // 15 15 … … 27 27 ostype * ?|?( ostype *os, char c ) { 28 28 prtfmt( os, "%c", c ); 29 sepOff( os ); 29 30 return os; 30 31 } // ?|? … … 32 33 forall( dtype ostype | ostream( ostype ) ) 33 34 ostype * ?|?( ostype *os, short int si ) { 34 if ( sepPrt( os ) ) prtfmt( os, "%s", sepGet( os ) ); else sepOn( os );35 if ( sepPrt( os ) ) prtfmt( os, "%s", sepGet( os ) ); 35 36 prtfmt( os, "%hd", si ); 36 37 return os; … … 39 40 forall( dtype ostype | ostream( ostype ) ) 40 41 ostype * ?|?( ostype *os, unsigned short int usi ) { 41 if ( sepPrt( os ) ) prtfmt( os, "%s", sepGet( os ) ); else sepOn( os );42 if ( sepPrt( os ) ) prtfmt( os, "%s", sepGet( os ) ); 42 43 prtfmt( os, "%hu", usi ); 43 44 return os; … … 46 47 forall( dtype ostype | ostream( ostype ) ) 47 48 ostype * ?|?( ostype *os, int i ) { 48 if ( sepPrt( os ) ) prtfmt( os, "%s", sepGet( os ) ); else sepOn( os );49 if ( sepPrt( os ) ) prtfmt( os, "%s", sepGet( os ) ); 49 50 prtfmt( os, "%d", i ); 50 51 return os; … … 53 54 forall( dtype ostype | ostream( ostype ) ) 54 55 ostype * ?|?( ostype *os, unsigned int ui ) { 55 if ( sepPrt( os ) ) prtfmt( os, "%s", sepGet( os ) ); else sepOn( os );56 if ( sepPrt( os ) ) prtfmt( os, "%s", sepGet( os ) ); 56 57 prtfmt( os, "%u", ui ); 57 58 return os; … … 60 61 forall( dtype ostype | ostream( ostype ) ) 61 62 ostype * ?|?( ostype *os, long int li ) { 62 if ( sepPrt( os ) ) prtfmt( os, "%s", sepGet( os ) ); else sepOn( os );63 if ( sepPrt( os ) ) prtfmt( os, "%s", sepGet( os ) ); 63 64 prtfmt( os, "%ld", li ); 64 65 return os; … … 67 68 forall( dtype ostype | ostream( ostype ) ) 68 69 ostype * ?|?( ostype *os, unsigned long int uli ) { 69 if ( sepPrt( os ) ) prtfmt( os, "%s", sepGet( os ) ); else sepOn( os );70 if ( sepPrt( os ) ) prtfmt( os, "%s", sepGet( os ) ); 70 71 prtfmt( os, "%lu", uli ); 71 72 return os; … … 74 75 forall( dtype ostype | ostream( ostype ) ) 75 76 ostype * ?|?( ostype *os, long long int lli ) { 76 if ( sepPrt( os ) ) prtfmt( os, "%s", sepGet( os ) ); else sepOn( os );77 if ( sepPrt( os ) ) prtfmt( os, "%s", sepGet( os ) ); 77 78 prtfmt( os, "%lld", lli ); 78 79 return os; … … 81 82 forall( dtype ostype | ostream( ostype ) ) 82 83 ostype * ?|?( ostype *os, unsigned long long int ulli ) { 83 if ( sepPrt( os ) ) prtfmt( os, "%s", sepGet( os ) ); else sepOn( os );84 if ( sepPrt( os ) ) prtfmt( os, "%s", sepGet( os ) ); 84 85 prtfmt( os, "%llu", ulli ); 85 86 return os; … … 88 89 forall( dtype ostype | ostream( ostype ) ) 89 90 ostype * ?|?( ostype *os, float f ) { 90 if ( sepPrt( os ) ) prtfmt( os, "%s", sepGet( os ) ); else sepOn( os );91 if ( sepPrt( os ) ) prtfmt( os, "%s", sepGet( os ) ); 91 92 prtfmt( os, "%g", f ); 92 93 return os; … … 95 96 forall( dtype ostype | ostream( ostype ) ) 96 97 ostype * ?|?( ostype *os, double d ) { 97 if ( sepPrt( os ) ) prtfmt( os, "%s", sepGet( os ) ); else sepOn( os );98 if ( sepPrt( os ) ) prtfmt( os, "%s", sepGet( os ) ); 98 99 prtfmt( os, "%.*lg", DBL_DIG, d ); 99 100 return os; … … 102 103 forall( dtype ostype | ostream( ostype ) ) 103 104 ostype * ?|?( ostype *os, long double ld ) { 104 if ( sepPrt( os ) ) prtfmt( os, "%s", sepGet( os ) ); else sepOn( os );105 if ( sepPrt( os ) ) prtfmt( os, "%s", sepGet( os ) ); 105 106 prtfmt( os, "%.*Lg", LDBL_DIG, ld ); 106 107 return os; … … 110 111 ostype * ?|?( ostype *os, float _Complex fc ) { 111 112 os | crealf( fc ); 112 if ( cimagf( fc ) >= 0 ) os | '+'; 113 os | "" | cimagf( fc ) | 'i'; 113 _Bool temp = sepDisable( os ); // disable separators within complex value 114 if ( cimagf( fc ) >= 0 ) os | '+'; // negative value prints '-' 115 os | cimagf( fc ) | 'i'; 116 sepReset( os, temp ); // reset separator 114 117 return os; 115 118 } // ?|? … … 118 121 ostype * ?|?( ostype *os, double _Complex dc ) { 119 122 os | creal( dc ); 120 if ( cimag( dc ) >= 0 ) os | '+'; 121 os | "" | cimag( dc ) | 'i'; 123 _Bool temp = sepDisable( os ); // disable separators within complex value 124 if ( cimag( dc ) >= 0 ) os | '+'; // negative value prints '-' 125 os | cimag( dc ) | 'i'; 126 sepReset( os, temp ); // reset separator 122 127 return os; 123 128 } // ?|? … … 126 131 ostype * ?|?( ostype *os, long double _Complex ldc ) { 127 132 os | creall( ldc ); 128 if ( cimagl( ldc ) >= 0 ) os | '+'; 129 os | "" | cimagl( ldc ) | 'i'; 133 _Bool temp = sepDisable( os ); // disable separators within complex value 134 if ( cimagl( ldc ) >= 0 ) os | '+'; // negative value prints '-' 135 os | cimagl( ldc ) | 'i'; 136 sepReset( os, temp ); // reset separator 130 137 return os; 131 138 } // ?|? … … 134 141 ostype * ?|?( ostype *os, const char *cp ) { 135 142 enum { Open = 1, Close, OpenClose }; 136 static const char mask[256] = {143 static const unsigned char mask[256] = { 137 144 // opening delimiters 138 145 ['('] : Open, ['['] : Open, ['{'] : Open, 139 ['$'] : Open, [L'£'] : Open, [L'¥'] : Open, [L'¢'] : Open, [L'¿'] : Open, [L'«'] : Open, 146 ['$'] : Open, [(unsigned char)'£'] : Open, [(unsigned char)'¥'] : Open, 147 [(unsigned char)'¡'] : Open, [(unsigned char)'¿'] : Open, [(unsigned char)'«'] : Open, 140 148 // closing delimiters 141 149 [','] : Close, ['.'] : Close, [':'] : Close, [';'] : Close, ['!'] : Close, ['?'] : Close, 142 150 [')'] : Close, [']'] : Close, ['}'] : Close, 143 ['%'] : Close, [ L'»'] : Close,151 ['%'] : Close, [(unsigned char)'¢'] : Close, [(unsigned char)'»'] : Close, 144 152 // opening-closing delimiters 145 153 ['\''] : OpenClose, ['`'] : OpenClose, ['"'] : OpenClose, 154 [' '] : OpenClose, ['\f'] : OpenClose, ['\n'] : OpenClose, ['\r'] : OpenClose, ['\t'] : OpenClose, ['\v'] : OpenClose, // isspace 146 155 }; // mask 147 156 148 int len = strlen( cp ); 149 // null string => no separator 150 if ( len == 0 ) { sepOff( os ); return os; } 151 // first character NOT spacing or closing punctuation => add left separator152 if ( sepPrt( os ) && isspace( cp[0] ) == 0 && mask[ cp[0] ] != Close && mask[ cp[0]] != OpenClose ) {157 if ( cp[0] == '\0' ) { sepOff( os ); return os; } // null string => no separator 158 159 // first character IS NOT spacing or closing punctuation => add left separator 160 unsigned char ch = cp[0]; // must make unsigned 161 if ( sepPrt( os ) && mask[ ch ] != Close && mask[ ch ] != OpenClose ) { 153 162 prtfmt( os, "%s", sepGet( os ) ); 154 163 } // if 164 165 // if string starts line, must reset to determine open state because separator is off 166 sepReset( os ); // reset separator 167 155 168 // last character IS spacing or opening punctuation => turn off separator for next item 156 unsigned int posn = len - 1; 157 if ( isspace( cp[posn] ) || mask[ cp[posn] ] == Open || mask[ cp[posn] ] == OpenClose ) { 169 unsigned int len = strlen( cp ), posn = len - 1; 170 ch = cp[posn]; // must make unsigned 171 if ( sepPrt( os ) && mask[ ch ] != Open && mask[ ch ] != OpenClose ) { 172 sepOn( os ); 173 } else { 158 174 sepOff( os ); 159 } else {160 sepOn( os );161 175 } // if 162 176 return write( os, cp, len ); … … 165 179 forall( dtype ostype | ostream( ostype ) ) 166 180 ostype * ?|?( ostype *os, const void *p ) { 167 if ( sepPrt( os ) ) prtfmt( os, "%s", sepGet( os ) ); else sepOn( os );181 if ( sepPrt( os ) ) prtfmt( os, "%s", sepGet( os ) ); 168 182 prtfmt( os, "%p", p ); 169 183 return os; 170 184 } // ?|? 171 172 185 173 186 forall( dtype ostype | ostream( ostype ) ) … … 196 209 } // sepOff 197 210 211 forall( dtype ostype | ostream( ostype ) ) 212 ostype * sepEnable( ostype * os ) { 213 sepEnable( os ); 214 return os; 215 } // sepEnable 216 217 forall( dtype ostype | ostream( ostype ) ) 218 ostype * sepDisable( ostype * os ) { 219 sepDisable( os ); 220 return os; 221 } // sepDisable 222 198 223 //--------------------------------------- 199 224 … … 310 335 } // ?|? 311 336 312 _Istream_ str1 str( char * s ) { _Istream_str1s = { s }; return s; }313 forall( dtype istype | istream( istype ) ) 314 istype * ?|?( istype * is, _Istream_ str1str ) {315 scanfmt( is, "%s", str.s );316 return is; 317 } // str318 319 _Istream_ str2 str( char * s, int size ) { _Istream_str2s = { s, size }; return s; }320 forall( dtype istype | istream( istype ) ) 321 istype * ?|?( istype * is, _Istream_ str2str ) {337 _Istream_cstrUC cstr( char * s ) { _Istream_cstrUC s = { s }; return s; } 338 forall( dtype istype | istream( istype ) ) 339 istype * ?|?( istype * is, _Istream_cstrUC cstr ) { 340 scanfmt( is, "%s", cstr.s ); 341 return is; 342 } // cstr 343 344 _Istream_cstrC cstr( char * s, int size ) { _Istream_cstrC s = { s, size }; return s; } 345 forall( dtype istype | istream( istype ) ) 346 istype * ?|?( istype * is, _Istream_cstrC cstr ) { 322 347 char buf[16]; 323 sprintf( buf, "%%%ds", str.size );324 scanfmt( is, buf, str.s );325 return is; 326 } // str348 sprintf( buf, "%%%ds", cstr.size ); 349 scanfmt( is, buf, cstr.s ); 350 return is; 351 } // cstr 327 352 328 353 // Local Variables: // -
src/libcfa/limits
r1f6e009 r1048b31 1 // 2 // Cforall Version 1.0.0 Copyright (C) 2016 University of Waterloo 3 // 4 // The contents of this file are covered under the licence agreement in the 5 // file "LICENCE" distributed with Cforall. 6 // 7 // limits -- 8 // 9 // Author : Peter A. Buhr 10 // Created On : Wed Apr 6 18:06:52 2016 11 // Last Modified By : Peter A. Buhr 12 // Last Modified On : Wed Apr 6 21:08:16 2016 13 // Update Count : 6 14 // 15 1 16 // Integral Constants 2 17 3 const short int MIN = -32768;4 const int MIN = -2147483648;5 const long int MIN = -9223372036854775807L - 1L;6 const long long int MIN = -9223372036854775807LL - 1LL;18 extern const short int MIN; 19 extern const int MIN; 20 extern const long int MIN; 21 extern const long long int MIN; 7 22 8 const short int MAX = 32767;9 const unsigned short int MAX = 65535;10 const int MAX = 2147483647;11 const unsigned int MAX = 4294967295_U;12 const long int MAX = 9223372036854775807_L;13 const unsigned long int MAX = 4294967295_U;14 const long long int MAX = 9223372036854775807_LL;15 const unsigned long long int MAX = 18446744073709551615_ULL;23 extern const short int MAX; 24 extern const unsigned short int MAX; 25 extern const int MAX; 26 extern const unsigned int MAX; 27 extern const long int MAX; 28 extern const unsigned long int MAX; 29 extern const long long int MAX; 30 extern const unsigned long long int MAX; 16 31 17 32 // Floating-Point Constants 18 33 19 const float PI = 3.141592_F;// pi20 const float PI_2 = 1.570796_F;// pi / 221 const float PI_4 = 0.7853981_F;// pi / 422 const float _1_PI = 0.3183098_F;// 1 / pi23 const float _2_PI = 0.6366197_F;// 2 / pi24 const float _2_SQRT_PI = 1.128379_F;// 2 / sqrt(pi)34 extern const float PI; // pi 35 extern const float PI_2; // pi / 2 36 extern const float PI_4; // pi / 4 37 extern const float _1_PI; // 1 / pi 38 extern const float _2_PI; // 2 / pi 39 extern const float _2_SQRT_PI; // 2 / sqrt(pi) 25 40 26 const double PI = 3.14159265358979323846_D;// pi27 const double PI_2 = 1.57079632679489661923_D;// pi / 228 const double PI_4 = 0.78539816339744830962_D;// pi / 429 const double _1_PI = 0.31830988618379067154_D;// 1 / pi30 const double _2_PI = 0.63661977236758134308_D;// 2 / pi31 const double _2_SQRT_PI = 1.12837916709551257390_D;// 2 / sqrt(pi)41 extern const double PI; // pi 42 extern const double PI_2; // pi / 2 43 extern const double PI_4; // pi / 4 44 extern const double _1_PI; // 1 / pi 45 extern const double _2_PI; // 2 / pi 46 extern const double _2_SQRT_PI; // 2 / sqrt(pi) 32 47 33 const long double PI = 3.1415926535897932384626433832795029_DL;// pi34 const long double PI_2 = 1.5707963267948966192313216916397514_DL;// pi / 235 const long double PI_4 = 0.7853981633974483096156608458198757_DL;// pi / 436 const long double _1_PI = 0.3183098861837906715377675267450287_DL;// 1 / pi37 const long double _2_PI = 0.6366197723675813430755350534900574_DL;// 2 / pi38 const long double _2_SQRT_PI = 1.1283791670955125738961589031215452_DL;// 2 / sqrt(pi)48 extern const long double PI; // pi 49 extern const long double PI_2; // pi / 2 50 extern const long double PI_4; // pi / 4 51 extern const long double _1_PI; // 1 / pi 52 extern const long double _2_PI; // 2 / pi 53 extern const long double _2_SQRT_PI; // 2 / sqrt(pi) 39 54 40 const _Complex PI = 3.14159265358979323846_D+0.0_iD;// pi41 const _Complex PI_2 = 1.57079632679489661923_D+0.0_iD;// pi / 242 const _Complex PI_4 = 0.78539816339744830962_D+0.0_iD;// pi / 443 const _Complex _1_PI = 0.31830988618379067154_D+0.0_iD;// 1 / pi44 const _Complex _2_PI = 0.63661977236758134308_D+0.0_iD;// 2 / pi45 const _Complex _2_SQRT_PI = 1.12837916709551257390_D+0.0_iD;// 2 / sqrt(pi)55 extern const _Complex PI; // pi 56 extern const _Complex PI_2; // pi / 2 57 extern const _Complex PI_4; // pi / 4 58 extern const _Complex _1_PI; // 1 / pi 59 extern const _Complex _2_PI; // 2 / pi 60 extern const _Complex _2_SQRT_PI; // 2 / sqrt(pi) 46 61 47 const long _Complex PI = 3.1415926535897932384626433832795029_L+0.0iL;// pi48 const long _Complex PI_2 = 1.5707963267948966192313216916397514_L+0.0iL;// pi / 249 const long _Complex PI_4 = 0.7853981633974483096156608458198757_L+0.0iL;// pi / 450 const long _Complex _1_PI = 0.3183098861837906715377675267450287_L+0.0iL;// 1 / pi51 const long _Complex _2_PI = 0.6366197723675813430755350534900574_L+0.0iL;// 2 / pi52 const long _Complex _2_SQRT_PI = 1.1283791670955125738961589031215452_L+0.0iL;// 2 / sqrt(pi)62 extern const long _Complex PI; // pi 63 extern const long _Complex PI_2; // pi / 2 64 extern const long _Complex PI_4; // pi / 4 65 extern const long _Complex _1_PI; // 1 / pi 66 extern const long _Complex _2_PI; // 2 / pi 67 extern const long _Complex _2_SQRT_PI; // 2 / sqrt(pi) 53 68 54 const float E = 2.718281;// e55 const float LOG2_E = 1.442695;// log_2(e)56 const float LOG10_E = 0.4342944;// log_10(e)57 const float LN_2 = 0.6931471;// log_e(2)58 const float LN_10 = 2.302585;// log_e(10)59 const float SQRT_2 = 1.414213;// sqrt(2)60 const float _1_SQRT_2 = 0.7071067;// 1 / sqrt(2)69 extern const float E; // e 70 extern const float LOG2_E; // log_2(e) 71 extern const float LOG10_E; // log_10(e) 72 extern const float LN_2; // log_e(2) 73 extern const float LN_10; // log_e(10) 74 extern const float SQRT_2; // sqrt(2) 75 extern const float _1_SQRT_2; // 1 / sqrt(2) 61 76 62 const double E = 2.7182818284590452354_D;// e63 const double LOG2_E = 1.4426950408889634074_D;// log_2(e)64 const double LOG10_E = 0.43429448190325182765_D;// log_10(e)65 const double LN_2 = 0.69314718055994530942_D;// log_e(2)66 const double LN_10 = 2.30258509299404568402_D;// log_e(10)67 const double SQRT_2 = 1.41421356237309504880_D;// sqrt(2)68 const double _1_SQRT_2 = 0.70710678118654752440_D;// 1 / sqrt(2)77 extern const double E; // e 78 extern const double LOG2_E; // log_2(e) 79 extern const double LOG10_E; // log_10(e) 80 extern const double LN_2; // log_e(2) 81 extern const double LN_10; // log_e(10) 82 extern const double SQRT_2; // sqrt(2) 83 extern const double _1_SQRT_2; // 1 / sqrt(2) 69 84 70 const long double E = 2.7182818284590452353602874713526625_DL;// e71 const long double LOG2_E = 1.4426950408889634073599246810018921_DL;// log_2(e)72 const long double LOG10_E = 0.4342944819032518276511289189166051_DL;// log_10(e)73 const long double LN_2 = 0.6931471805599453094172321214581766_DL;// log_e(2)74 const long double LN_10 = 2.3025850929940456840179914546843642_DL;// log_e(10)75 const long double SQRT_2 = 1.4142135623730950488016887242096981_DL;// sqrt(2)76 const long double _1_SQRT_2 = 0.7071067811865475244008443621048490_DL;// 1/sqrt(2)85 extern const long double E; // e 86 extern const long double LOG2_E; // log_2(e) 87 extern const long double LOG10_E; // log_10(e) 88 extern const long double LN_2; // log_e(2) 89 extern const long double LN_10; // log_e(10) 90 extern const long double SQRT_2; // sqrt(2) 91 extern const long double _1_SQRT_2; // 1/sqrt(2) 77 92 78 const _Complex E = 2.7182818284590452354_D+0.0_iD;// e79 const _Complex LOG2_E = 1.4426950408889634074_D+0.0_iD;// log_2(e)80 const _Complex LOG10_E = 0.43429448190325182765_D+0.0_iD;// log_10(e)81 const _Complex LN_2 = 0.69314718055994530942_D+0.0_iD;// log_e(2)82 const _Complex LN_10 = 2.30258509299404568402_D+0.0_iD;// log_e(10)83 const _Complex SQRT_2 = 1.41421356237309504880_D+0.0_iD;// sqrt(2)84 const _Complex _1_SQRT_2 = 0.70710678118654752440_D+0.0_iD;// 1 / sqrt(2)93 extern const _Complex E; // e 94 extern const _Complex LOG2_E; // log_2(e) 95 extern const _Complex LOG10_E; // log_10(e) 96 extern const _Complex LN_2; // log_e(2) 97 extern const _Complex LN_10; // log_e(10) 98 extern const _Complex SQRT_2; // sqrt(2) 99 extern const _Complex _1_SQRT_2; // 1 / sqrt(2) 85 100 86 const long _Complex E = 2.7182818284590452353602874713526625_L+0.0_iL; // e 87 const long _Complex LOG2_E = 1.4426950408889634073599246810018921_L+0.0_iL; // log_2(e) 88 const long _Complex LOG10_E = 0.4342944819032518276511289189166051_L+0.0_iL; // log_10(e) 89 const long _Complex LN_2 = 0.6931471805599453094172321214581766_L+0.0_iL; // log_e(2) 90 const long _Complex LN_10 = 2.3025850929940456840179914546843642_L+0.0_iL; // log_e(10) 91 const long _Complex SQRT_2 = 1.4142135623730950488016887242096981_L+0.0_iL; // sqrt(2) 92 const long _Complex _1_SQRT_2 = 0.7071067811865475244008443621048490_L+0.0_iL; // 1 / sqrt(2) 101 extern const long _Complex E; // e 102 extern const long _Complex LOG2_E; // log_2(e) 103 extern const long _Complex LOG10_E; // log_10(e) 104 extern const long _Complex LN_2; // log_e(2) 105 extern const long _Complex LN_10; // log_e(10) 106 extern const long _Complex SQRT_2; // sqrt(2) 107 extern const long _Complex _1_SQRT_2; // 1 / sqrt(2) 108 109 // Local Variables: // 110 // mode: c // 111 // tab-width: 4 // 112 // End: // -
src/libcfa/stdlib
r1f6e009 r1048b31 10 10 // Created On : Thu Jan 28 17:12:35 2016 11 11 // Last Modified By : Peter A. Buhr 12 // Last Modified On : Tue Mar 22 22:34:24201613 // Update Count : 6912 // Last Modified On : Wed Apr 27 22:03:29 2016 13 // Update Count : 96 14 14 // 15 15 … … 20 20 } // extern "C" 21 21 22 //--------------------------------------- 23 24 extern "C" { 25 #ifndef EXIT_FAILURE 26 #define EXIT_FAILURE 1 // failing exit status 27 #define EXIT_SUCCESS 0 // successful exit status 28 #endif // ! EXIT_FAILURE 29 void exit( int rc ); 30 void abort( void ); 31 } // extern "C" 32 33 //--------------------------------------- 34 35 extern "C" { void * malloc( size_t ); } // use default C routine for void * 22 36 forall( otype T ) T * malloc( void ); 23 37 forall( otype T ) T * malloc( char fill ); 24 38 forall( otype T ) T * malloc( T * ptr, size_t size ); 25 39 forall( otype T ) T * malloc( T * ptr, size_t size, unsigned char fill ); 26 forall( otype T ) T * calloc( size_t size ); 40 extern "C" { void * calloc( size_t nmemb, size_t size ); } // use default C routine for void * 41 forall( otype T ) T * calloc( size_t nmemb ); 42 extern "C" { void * realloc( void * ptr, size_t size ); } // use default C routine for void * 27 43 forall( otype T ) T * realloc( T * ptr, size_t size ); 28 44 forall( otype T ) T * realloc( T * ptr, size_t size, unsigned char fill ); … … 32 48 forall( otype T ) int posix_memalign( T ** ptr, size_t alignment ); 33 49 34 forall( otype T ) T * memset( T * ptr, unsigned char fill ); // use default value '\0' for fill 35 forall( otype T ) T * memset( T * ptr ); // remove when default value available 50 extern "C" { 51 void * memset( void * ptr, int fill, size_t size ); 52 void free( void * ptr ); 53 } // extern "C" 36 54 37 55 //--------------------------------------- … … 79 97 80 98 char abs( char ); 81 extern "C" { 82 int abs( int ); // use default C routine for int 83 } // extern 99 extern "C" { int abs( int ); } // use default C routine for int 84 100 long int abs( long int ); 85 101 long long int abs( long long int ); … … 87 103 double abs( double ); 88 104 long double abs( long double ); 89 float _Complexabs( float _Complex );90 double _Complexabs( double _Complex );91 long double _Complexabs( long double _Complex );105 float abs( float _Complex ); 106 double abs( double _Complex ); 107 long double abs( long double _Complex ); 92 108 93 109 //--------------------------------------- -
src/libcfa/stdlib.c
r1f6e009 r1048b31 10 10 // Created On : Thu Jan 28 17:10:29 2016 11 11 // Last Modified By : Peter A. Buhr 12 // Last Modified On : Wed Mar 23 13:26:42201613 // Update Count : 1 4612 // Last Modified On : Thu Apr 28 07:54:21 2016 13 // Update Count : 166 14 14 // 15 15 … … 24 24 #include <malloc.h> // malloc_usable_size 25 25 #include <math.h> // fabsf, fabs, fabsl 26 #include <complex.h> // _Complex_I , cabsf, cabs, cabsl26 #include <complex.h> // _Complex_I 27 27 } // extern "C" 28 28 29 29 forall( otype T ) T * malloc( void ) { 30 printf( "malloc1\n" );30 //printf( "malloc1\n" ); 31 31 return (T *)malloc( sizeof(T) ); 32 32 } // malloc 33 forall( otype T ) T * malloc( size_t size ) {34 printf( "malloc2\n" );35 return (T *)(void *)malloc( size );36 } // malloc37 33 forall( otype T ) T * malloc( char fill ) { 38 printf( "malloc3\n" );34 //printf( "malloc3\n" ); 39 35 T * ptr = (T *)malloc( sizeof(T) ); 40 return memset( ptr );41 } // malloc 42 43 forall( otype T ) T * calloc( size_t size) {44 printf( "calloc\n" );45 return (T *)calloc( size, sizeof(T) );36 return memset( ptr, (int)fill, sizeof(T) ); 37 } // malloc 38 39 forall( otype T ) T * calloc( size_t nmemb ) { 40 //printf( "calloc\n" ); 41 return (T *)calloc( nmemb, sizeof(T) ); 46 42 } // calloc 47 43 48 44 forall( otype T ) T * realloc( T * ptr, size_t size ) { 49 printf( "realloc1\n" );45 //printf( "realloc1\n" ); 50 46 return (T *)(void *)realloc( (void *)ptr, size ); 51 47 } // realloc 52 48 forall( otype T ) T * realloc( T * ptr, size_t size, unsigned char fill ) { 53 printf( "realloc2\n" );49 //printf( "realloc2\n" ); 54 50 char * nptr = (T *)(void *)realloc( (void *)ptr, size ); 55 51 size_t unused = malloc_usable_size( nptr ); … … 59 55 60 56 forall( otype T ) T * malloc( T * ptr, size_t size ) { 61 printf( "malloc4\n" );57 //printf( "malloc4\n" ); 62 58 return (T *)realloc( ptr, size ); 63 59 } // malloc 64 60 forall( otype T ) T * malloc( T * ptr, size_t size, unsigned char fill ) { 65 printf( "malloc5\n" );61 //printf( "malloc5\n" ); 66 62 return (T *)realloc( ptr, size, fill ); 67 63 } // malloc 68 64 69 65 forall( otype T ) T * aligned_alloc( size_t alignment ) { 70 printf( "aligned_alloc\n" );66 //printf( "aligned_alloc\n" ); 71 67 return (T *)memalign( alignment, sizeof(T) ); 72 68 } // aligned_alloc 73 69 74 70 forall( otype T ) T * memalign( size_t alignment ) { 75 printf( "memalign\n" );71 //printf( "memalign\n" ); 76 72 return (T *)memalign( alignment, sizeof(T) ); 77 73 } // memalign 78 74 79 75 forall( otype T ) int posix_memalign( T ** ptr, size_t alignment ) { 80 printf( "posix_memalign\n" );76 //printf( "posix_memalign\n" ); 81 77 return posix_memalign( (void **)ptr, alignment, sizeof(T) ); 82 78 } // posix_memalign 83 79 84 forall( otype T ) T * memset( T * ptr, unsigned char fill ) { // use default value '\0' for fill85 printf( "memset1\n" );86 return (T *)memset( ptr, (int)fill, malloc_usable_size( ptr ) );87 } // memset88 forall( otype T ) T * memset( T * ptr ) { // remove when default value available89 printf( "memset2\n" );90 return (T *)memset( ptr, 0, malloc_usable_size( ptr ) );91 } // memset92 93 80 //--------------------------------------- 94 81 95 82 int ato( const char * ptr ) { 96 83 int i; 97 if ( sscanf( ptr, "%d", &i ) == EOF ) {} // check return code84 if ( sscanf( ptr, "%d", &i ) == EOF ) {} 98 85 return i; 99 86 } 100 87 unsigned int ato( const char * ptr ) { 101 88 unsigned int ui; 102 if ( sscanf( ptr, "%u", &ui ) == EOF ) {} // check return code89 if ( sscanf( ptr, "%u", &ui ) == EOF ) {} 103 90 return ui; 104 91 } 105 92 long int ato( const char * ptr ) { 106 93 long int li; 107 if ( sscanf( ptr, "%ld", &li ) == EOF ) {} // check return code94 if ( sscanf( ptr, "%ld", &li ) == EOF ) {} 108 95 return li; 109 96 } 110 97 unsigned long int ato( const char * ptr ) { 111 98 unsigned long int uli; 112 if ( sscanf( ptr, "%lu", &uli ) == EOF ) {} // check return code99 if ( sscanf( ptr, "%lu", &uli ) == EOF ) {} 113 100 return uli; 114 101 } 115 102 long long int ato( const char * ptr ) { 116 103 long long int lli; 117 if ( sscanf( ptr, "%lld", &lli ) == EOF ) {} // check return code104 if ( sscanf( ptr, "%lld", &lli ) == EOF ) {} 118 105 return lli; 119 106 } 120 107 unsigned long long int ato( const char * ptr ) { 121 108 unsigned long long int ulli; 122 if ( sscanf( ptr, "%llu", &ulli ) == EOF ) {} // check return code109 if ( sscanf( ptr, "%llu", &ulli ) == EOF ) {} 123 110 return ulli; 124 111 } … … 126 113 float ato( const char * ptr ) { 127 114 float f; 128 if ( sscanf( ptr, "%f", &f ) == EOF ) {} // check return code115 if ( sscanf( ptr, "%f", &f ) == EOF ) {} 129 116 return f; 130 117 } 131 118 double ato( const char * ptr ) { 132 119 double d; 133 if ( sscanf( ptr, "%lf", &d ) == EOF ) {} // check return code120 if ( sscanf( ptr, "%lf", &d ) == EOF ) {} 134 121 return d; 135 122 } 136 123 long double ato( const char * ptr ) { 137 124 long double ld; 138 if ( sscanf( ptr, "%Lf", &ld ) == EOF ) {} // check return code125 if ( sscanf( ptr, "%Lf", &ld ) == EOF ) {} 139 126 return ld; 140 127 } … … 142 129 float _Complex ato( const char * ptr ) { 143 130 float re, im; 144 if ( sscanf( ptr, "%g%gi", &re, &im ) == EOF ) {} // check return code131 if ( sscanf( ptr, "%g%gi", &re, &im ) == EOF ) {} 145 132 return re + im * _Complex_I; 146 133 } 147 134 double _Complex ato( const char * ptr ) { 148 135 double re, im; 149 if ( sscanf( ptr, "%lf%lfi", &re, &im ) == EOF ) {} // check return code136 if ( sscanf( ptr, "%lf%lfi", &re, &im ) == EOF ) {} 150 137 return re + im * _Complex_I; 151 138 } 152 139 long double _Complex ato( const char * ptr ) { 153 140 long double re, im; 154 if ( sscanf( ptr, "%Lf%Lfi", &re, &im ) == EOF ) {} // check return code141 if ( sscanf( ptr, "%Lf%Lfi", &re, &im ) == EOF ) {} 155 142 return re + im * _Complex_I; 156 143 } … … 226 213 //--------------------------------------- 227 214 228 forall( otype T | { T ?/?( T, T ); T ?%?( T, T ); } )229 [ T, T ] div( T t1, T t2 ) { /* return [ t1 / t2, t1 % t2 ]; */}215 // forall( otype T | { T ?/?( T, T ); T ?%?( T, T ); } ) 216 // [ T, T ] div( T t1, T t2 ) { return [ t1 / t2, t1 % t2 ]; } 230 217 231 218 //--------------------------------------- … … 234 221 long int abs( long int v ) { return labs( v ); } 235 222 long long int abs( long long int v ) { return llabs( v ); } 236 float abs( float v ) { return fabsf( v); }237 double abs( double v ) { return fabs( v); }238 long double abs( long double v ) { return fabsl( v); }239 float _Complex abs( float _Complex v ) { return cabsf( v); }240 double _Complex abs( double _Complex v ) { return cabs( v); }241 long double _Complex abs( long double _Complex v ) { return cabsl( v); }223 float abs( float x ) { return fabsf( x ); } 224 double abs( double x ) { return fabs( x ); } 225 long double abs( long double x ) { return fabsl( x ); } 226 float abs( float _Complex x ) { return cabsf( x ); } 227 double abs( double _Complex x ) { return cabs( x ); } 228 long double abs( long double _Complex x ) { return cabsl( x ); } 242 229 243 230 //---------------------------------------
Note:
See TracChangeset
for help on using the changeset viewer.