Changes in / [fbfb38e:dc2e7e0]
- Files:
-
- 3 deleted
- 15 edited
-
doc/user/Cdecl.fig (deleted)
-
doc/user/Makefile (modified) (1 diff)
-
doc/user/user.tex (modified) (17 diffs)
-
src/ResolvExpr/CastCost.cc (modified) (2 diffs)
-
src/SymTab/Indexer.cc (modified) (4 diffs)
-
src/SymTab/Indexer.h (modified) (1 diff)
-
src/SymTab/Validate.cc (modified) (1 diff)
-
src/driver/cfa.cc (modified) (2 diffs)
-
src/examples/io.c (modified) (3 diffs)
-
src/examples/swap.c (modified) (2 diffs)
-
src/libcfa/Makefile.am (modified) (2 diffs)
-
src/libcfa/Makefile.in (modified) (3 diffs)
-
src/libcfa/fstream (modified) (2 diffs)
-
src/libcfa/math (deleted)
-
src/libcfa/math.c (deleted)
-
src/libcfa/rational.c (modified) (2 diffs)
-
src/libcfa/stdlib (modified) (4 diffs)
-
src/libcfa/stdlib.c (modified) (7 diffs)
Legend:
- Unmodified
- Added
- Removed
-
doc/user/Makefile
rfbfb38e rdc2e7e0 12 12 13 13 FIGURES = ${addsuffix .tex, \ 14 Cdecl \15 14 } 16 15 -
doc/user/user.tex
rfbfb38e rdc2e7e0 11 11 %% Created On : Wed Apr 6 14:53:29 2016 12 12 %% Last Modified By : Peter A. Buhr 13 %% Last Modified On : Thu Apr 21 08:15:37201614 %% Update Count : 13113 %% Last Modified On : Sun Apr 10 22:50:15 2016 14 %% Update Count : 72 15 15 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% 16 16 … … 26 26 \usepackage{upquote} 27 27 \usepackage{fullpage,times} 28 \usepackage{epic,eepic}29 28 \usepackage{xspace} 30 29 \usepackage{varioref} … … 49 48 % Names used in the document. 50 49 51 \newcommand{\Version}{1.0.0}52 50 \newcommand{\CS}{C\raisebox{-0.9ex}{\large$^\sharp$}\xspace} 53 51 … … 107 105 The syntax of the \CFA language builds from C, and should look immediately familiar to C programmers. 108 106 % Any language feature that is not described here can be assumed to be using the standard C11 syntax. 109 \CFA adds many modern programming-language features, which directly leads to increased safety and productivity, while maintaining interoperability with existing C programs and achieving Cperformance.107 \CFA adds many modern programming-language features, which directly leads to increased safety and productivity, while maintaining interoperability with existing C programs and maintaining C-like performance. 110 108 Like C, \CFA is a statically typed, procedural language with a low-overhead runtime, meaning there is no global garbage-collection. 111 109 The primary new features include parametric-polymorphism routines and types, exceptions, concurrency, and modules. … … 226 224 227 225 228 \section{Compiling \CFA Program}226 \section{Compiling \CFA} 229 227 230 228 The command \lstinline@cfa@ is used to compile \CFA program(s). … … 233 231 cfa [ gcc-options ] C/@{\CFA}@-files [ assembler/loader-files ] 234 232 \end{lstlisting} 235 \index{cfa@\lstinline$cfa$}\index{compilation!cfa@\lstinline$cfa$}236 233 By default, \CFA programs having the following \lstinline@gcc@ flags turned on: 237 234 \begin{description} 238 235 \item 239 236 \hspace*{-4pt}\lstinline@-std=gnu99@ 240 \index{-std=gnu99@{\lstinline$-std=gnu99$}}\index{compilation option!-std=gnu99@{\lstinline$-std=gnu99$}}241 237 The 1999 C standard plus GNU extensions. 242 \item243 \hspace*{-4pt}\lstinline@-fgnu89-inline@244 \index{-fgnu89-inline@{\lstinline$-fgnu89-inline$}}\index{compilation option!-fgnu89-inline@{\lstinline$-fgnu89-inline$}}245 Use the traditional GNU semantics for inline routines in C99 mode.246 238 \end{description} 247 239 The following new \CFA option is available: … … 249 241 \item 250 242 \hspace*{-4pt}\lstinline@-CFA@ 251 \index{-CFA@{\lstinline$-CFA$}}\index{compilation option!-CFA@{\lstinline$-CFA$}}252 243 Only the C preprocessor and the \CFA translator steps are performed and the transformed program is written to standard output, which makes it possible to examine the code generated by the \CFA translator. 253 244 \end{description} 254 255 The following preprocessor variables are available:256 \begin{description}257 \item258 \hspace*{-4pt}\lstinline$__CFA__$259 \index{__CFA__@{\lstinline$__CFA__$}}\index{preprocessor variables!__CFA__@{\lstinline$__CFA__$}}260 is always available during preprocessing and its value is the current major \Index{version number} of \CFA.\footnote{261 The C preprocessor allows only integer values in a preprocessor variable so a value like ``\Version'' is not allowed.262 Hence, the need to have three variables for the major, minor and patch version number.}263 264 \item265 \hspace*{-4pt}\lstinline$__CFA_MINOR__$266 \index{__CFA_MINOR__@{\lstinline$__CFA_MINOR__$}}\index{preprocessor variables!__CFA_MINOR__@{\lstinline$__CFA_MINOR__$}}267 is always available during preprocessing and its value is the current minor \Index{version number} of \CFA.268 269 \item270 \hspace*{-4pt}\lstinline$__CFA_PATCH__$271 \index{__CFA_PATCH__@%(__CFA_PATCH__%)}\index{preprocessor variables!__CFA_PATCH__@%(__CFA_PATCH__%)}272 is always available during preprocessing and its value is the current patch \Index{version number} of \CFA.273 274 \item275 \hspace*{-4pt}\lstinline$__CFORALL__$276 \index{__CFORALL__@%(__CFORALL__%)}\index{preprocessor variables!__CFORALL__@%(__CFORALL__%)}277 is always available during preprocessing and it has no value.278 \end{description}279 280 These preprocessor variables allow conditional compilation of programs that must work differently in these situations.281 For example, to toggle between C and \CFA extensions, using the following:282 \begin{lstlisting}283 #ifndef __CFORALL__284 #include <stdio.h> // C header file285 #else286 #include <fstream> // @\CFA{}@ header file287 #endif288 \end{lstlisting}289 which conditionally includes the correct header file, if the program is compiled using \lstinline@gcc@ or \lstinline@cfa@.290 245 291 246 … … 329 284 C declaration syntax is notoriously confusing and error prone. 330 285 For example, many C programmers are confused by a declaration as simple as: 331 \begin{quote2} 332 \begin{tabular}{@{}ll@{}} 333 \begin{lstlisting}[aboveskip=0pt,belowskip=0pt] 334 int *x[ 5 ] 335 \end{lstlisting} 336 & 337 \raisebox{-0.75\totalheight}{\input{Cdecl}} 338 \end{tabular} 339 \end{quote2} 340 Is this an array of 5 pointers to integers or a pointer to an array of 5 integers? 286 \begin{lstlisting} 287 int *x[ 10 ] 288 \end{lstlisting} 289 Is this a pointer to an array of 10 integers or an array of 10 pointers to integers? 341 290 Another example of confusion results from the fact that a routine name and its parameters are embedded within the return type, mimicking the way the return value is used at the routine's call site. 342 291 For example, a routine returning a pointer to an array of integers is defined and used in the following way: 343 292 \begin{lstlisting} 344 int (*f())[ 5 ] {...}; // definition mimics usage345 ... (*f())[ 3 ] += 1;293 int (*f())[ 10 ] {...}; 294 ... (*f())[ 3 ] += 1; // definition mimics usage 346 295 \end{lstlisting} 347 296 Essentially, the return type is wrapped around the routine name in successive layers (like an onion). … … 373 322 \multicolumn{1}{c@{\hspace{30pt}}}{\textbf{\CFA}} & \multicolumn{1}{c@{\hspace{20pt}}}{\textbf{C}} \\ 374 323 \begin{lstlisting} 375 [ 5] int z;376 [ 5] * char w;377 * [ 5] double v;324 [ 10 ] int z; 325 [ 10 ] * char w; 326 * [ 10 ] double v; 378 327 struct s { 379 328 int f0:3; 380 329 * int f1; 381 [ 5] * int f2;330 [ 10 ] * int f2; 382 331 }; 383 332 \end{lstlisting} 384 333 & 385 334 \begin{lstlisting} 386 int z[ 5];387 char *w[ 5];388 double (*v)[ 5];335 int z[ 10 ]; 336 char *w[ 10 ]; 337 double (*v)[ 10 ]; 389 338 struct s { 390 339 int f0:3; 391 340 int *f1; 392 int *f2[ 5]341 int *f2[ 10 ] 393 342 }; 394 343 \end{lstlisting} 395 344 & 396 345 \begin{lstlisting} 397 // array of 5integers398 // array of 5pointers to char399 // pointer to array of 5doubles346 // array of 10 integers 347 // array of 10 pointers to char 348 // pointer to array of 10 doubles 400 349 401 350 // common bit field syntax … … 413 362 \begin{lstlisting} 414 363 const * const int x; 415 const * [ 5] const int y;364 const * [ 10 ] const int y; 416 365 \end{lstlisting} 417 366 & 418 367 \begin{lstlisting} 419 368 int const * const x; 420 const int (* const y)[ 5]369 const int (* const y)[ 10 ] 421 370 \end{lstlisting} 422 371 & 423 372 \begin{lstlisting} 424 373 // const pointer to const integer 425 // const pointer to array of 5const integers374 // const pointer to array of 10 const integers 426 375 \end{lstlisting} 427 376 \end{tabular} … … 433 382 \multicolumn{1}{c@{\hspace{30pt}}}{\textbf{\CFA}} & \multicolumn{1}{c@{\hspace{20pt}}}{\textbf{C}} \\ 434 383 \begin{lstlisting} 435 extern [ 5] int x;384 extern [ 10 ] int x; 436 385 static * const int y; 437 386 \end{lstlisting} 438 387 & 439 388 \begin{lstlisting} 440 int extern x[ 5];389 int extern x[ 10 ]; 441 390 const int static *y; 442 391 \end{lstlisting} 443 392 & 444 393 \begin{lstlisting} 445 // externally visible array of 5integers394 // externally visible array of 10 integers 446 395 // internally visible pointer to constant int 447 396 \end{lstlisting} … … 472 421 \begin{lstlisting} 473 422 y = (* int)x; 474 i = sizeof([ 5] * int);423 i = sizeof([ 10 ] * int); 475 424 \end{lstlisting} 476 425 & 477 426 \begin{lstlisting} 478 427 y = (int *)x; 479 i = sizeof(int *[ 5]);428 i = sizeof(int *[ 10 ]); 480 429 \end{lstlisting} 481 430 \end{tabular} … … 517 466 \CFA style declarations cannot be used to declare parameters for K\&R style routine definitions because of the following ambiguity: 518 467 \begin{lstlisting} 519 int (*f(x))[ 5] int x; {}520 \end{lstlisting} 521 The string ``\lstinline@int (*f(x))[ 5 ]@'' declares a K\&R style routine of type returning a pointer to an array of 5 integers, while the string ``\lstinline@[ 5 ] int x@'' declares a \CFA style parameter x of type array of 5integers.468 int (*f(x))[ 10 ] int x; {} 469 \end{lstlisting} 470 The string ``\lstinline@int (*f(x))[ 10 ]@'' declares a K\&R style routine of type returning a pointer to an array of 10 integers, while the string ``\lstinline@[ 10 ] int x@'' declares a \CFA style parameter x of type array of 10 integers. 522 471 Since the strings overlap starting with the open bracket, \lstinline@[@, there is an ambiguous interpretation for the string. 523 472 As well, \CFA-style declarations cannot be used to declare parameters for C-style routine-definitions because of the following ambiguity: … … 538 487 \begin{lstlisting} 539 488 #define ptoa( n, d ) int (*n)[ d ] 540 int f( ptoa(p, 5) ) ... // expands to int f( int (*p)[ 5] )541 [ int ] f( ptoa(p, 5) ) ... // expands to [ int ] f( int (*p)[ 5] )489 int f( ptoa(p,10) ) ... // expands to int f( int (*p)[ 10 ] ) 490 [ int ] f( ptoa(p,10) ) ... // expands to [ int ] f( int (*p)[ 10 ] ) 542 491 \end{lstlisting} 543 492 Again, programmers are highly encouraged to use one declaration form or the other, rather than mixing the forms. … … 858 807 which can be used to sort in ascending and descending order by locally redefining the less-than operator into greater-than. 859 808 \begin{lstlisting} 860 const unsigned int size = 5;809 const unsigned int size = 10; 861 810 int ia[size]; 862 811 ... // assign values to array ia … … 925 874 [ double, double, double ] 926 875 [ * int, int * ] // mix of CFA and ANSI 927 [ * [ 5] int, * * char, * [ [ int, int ] ] (int, int) ]876 [ * [ 10 ] int, * * char, * [ [ int, int ] ] (int, int) ] 928 877 \end{lstlisting} 929 878 Like tuples, tuple types may be nested, such as \lstinline@[ [ int, int ], int ]@, which is a 2-element tuple type whose first element is itself a tuple type. … … 2267 2216 2268 2217 try { 2269 throw 13;2218 throw 13; 2270 2219 } 2271 2220 catch(int e) { 2272 printf(.caught an exception: %d\n., e);2221 printf(.caught an exception: %d\n., e); 2273 2222 } 2274 2223 \end{lstlisting} -
src/ResolvExpr/CastCost.cc
rfbfb38e rdc2e7e0 69 69 PointerType *destAsPointer = dynamic_cast< PointerType* >( dest ); 70 70 if ( destAsPointer && basicType->isInteger() ) { 71 // necessary for, e.g. unsigned long => void*72 cost = Cost ( 1, 0, 0 );71 //cost = Cost( 1, 0, 0 ); 72 cost = Cost::infinity; 73 73 } else { 74 74 ConversionCost::visit( basicType ); … … 89 89 } else if ( castResult < 0 ) { 90 90 cost = Cost::infinity; 91 //cost = Cost( 1, 0, 0 ); 91 92 } // if 92 93 } // if 93 94 } else if ( BasicType *destAsBasic = dynamic_cast< BasicType* >( dest ) ) { 94 95 if ( destAsBasic->isInteger() ) { 95 // necessary for, e.g. void* => unsigned long96 cost = Cost ( 1, 0, 0 );96 //cost = Cost( 1, 0, 0 ); 97 cost = Cost::infinity; 97 98 } // if 98 99 } -
src/SymTab/Indexer.cc
rfbfb38e rdc2e7e0 511 511 } 512 512 513 bool Indexer::hasIncompatibleCDecl( const std::string &id, const std::string &mangleName , unsigned long scope) const {513 bool Indexer::hasIncompatibleCDecl( const std::string &id, const std::string &mangleName ) const { 514 514 if ( ! tables ) return false; 515 if ( tables->scope < scope ) return false;516 515 517 516 IdTable::const_iterator decls = tables->idTable.find( id ); … … 525 524 } 526 525 527 return tables->base.hasIncompatibleCDecl( id, mangleName , scope);526 return tables->base.hasIncompatibleCDecl( id, mangleName ); 528 527 } 529 528 … … 618 617 DeclarationWithType *existing = lookupIdAtScope( name, mangleName, scope ); 619 618 if ( ! existing || ! addedIdConflicts( existing, decl ) ) { 620 // this ensures that no two declarations with the same unmangled name at the same scopeboth have C linkage621 if ( decl->get_linkage() == LinkageSpec::C && hasIncompatibleCDecl( name, mangleName , scope) ) {619 // this ensures that no two declarations with the same unmangled name both have C linkage 620 if ( decl->get_linkage() == LinkageSpec::C && hasIncompatibleCDecl( name, mangleName ) ) { 622 621 throw SemanticError( "invalid overload of C function ", decl ); 623 622 } // NOTE this is broken in Richard's original code in such a way that it never triggers (it … … 784 783 using std::cerr; 785 784 786 if ( tables ) { 787 os << "--- scope " << tables->scope << " ---" << std::endl; 788 789 os << "===idTable===" << std::endl; 790 dump( tables->idTable, os ); 791 os << "===typeTable===" << std::endl; 792 dump( tables->typeTable, os ); 793 os << "===structTable===" << std::endl; 794 dump( tables->structTable, os ); 795 os << "===enumTable===" << std::endl; 796 dump( tables->enumTable, os ); 797 os << "===unionTable===" << std::endl; 798 dump( tables->unionTable, os ); 799 os << "===contextTable===" << std::endl; 800 dump( tables->traitTable, os ); 801 802 tables->base.print( os, indent ); 803 } else { 804 os << "--- end ---" << std::endl; 805 } 806 785 cerr << "===idTable===" << std::endl; 786 if ( tables ) dump( tables->idTable, os ); 787 cerr << "===typeTable===" << std::endl; 788 if ( tables ) dump( tables->typeTable, os ); 789 cerr << "===structTable===" << std::endl; 790 if ( tables ) dump( tables->structTable, os ); 791 cerr << "===enumTable===" << std::endl; 792 if ( tables ) dump( tables->enumTable, os ); 793 cerr << "===unionTable===" << std::endl; 794 if ( tables ) dump( tables->unionTable, os ); 795 cerr << "===contextTable===" << std::endl; 796 if ( tables ) dump( tables->traitTable, os ); 807 797 } 808 798 } // namespace SymTab -
src/SymTab/Indexer.h
rfbfb38e rdc2e7e0 99 99 DeclarationWithType *lookupIdAtScope( const std::string &id, const std::string &mangleName, unsigned long scope ) const; 100 100 /// returns true if there exists a declaration with C linkage and the given name with a different mangled name 101 bool hasIncompatibleCDecl( const std::string &id, const std::string &mangleName , unsigned long scope) const;101 bool hasIncompatibleCDecl( const std::string &id, const std::string &mangleName ) const; 102 102 // equivalents to lookup functions that only look at tables at scope `scope` (which should be >= tables->scope) 103 103 NamedTypeDecl *lookupTypeAtScope( const std::string &id, unsigned long scope ) const; -
src/SymTab/Validate.cc
rfbfb38e rdc2e7e0 515 515 } 516 516 rtt->get_parameters().clear(); 517 cloneAll( typeInst->get_parameters(), rtt->get_parameters() ); 518 mutateAll( rtt->get_parameters(), *this ); // recursively fix typedefs on parameters 517 cloneAll(typeInst->get_parameters(), rtt->get_parameters()); 519 518 } // if 520 519 delete typeInst; -
src/driver/cfa.cc
rfbfb38e rdc2e7e0 10 10 // Created On : Tue Aug 20 13:44:49 2002 11 11 // Last Modified By : Peter A. Buhr 12 // Last Modified On : Wed Apr 20 18:31:28201613 // Update Count : 13 312 // Last Modified On : Wed Apr 6 14:04:22 2016 13 // Update Count : 132 14 14 // 15 15 … … 310 310 nargs += 1; 311 311 } // if 312 args[nargs] = "-fgnu89-inline";313 nargs += 1;314 312 args[nargs] = ( *new string( string("-B") + Bprefix + "/" ) ).c_str(); 315 313 nargs += 1; -
src/examples/io.c
rfbfb38e rdc2e7e0 11 11 // Created On : Wed Mar 2 16:56:02 2016 12 12 // Last Modified By : Peter A. Buhr 13 // Last Modified On : Wed Apr 13 23:03:14201614 // Update Count : 2213 // Last Modified On : Wed Apr 6 14:58:27 2016 14 // Update Count : 15 15 15 // 16 16 … … 36 36 37 37 ifstream in; // create / open file 38 open( &in, "i o.data", "r" );38 open( &in, "input.data", "r" ); 39 39 40 40 &in | &c // character … … 59 59 | fc | dc | ldc | endl // complex without separator 60 60 | s1 | s2 | endl; 61 sout | endl;62 sepSet( sout, " " );63 64 sout65 // opening delimiters66 | "v(" | 2767 | "v[" | 2768 | "v{" | 2769 | "$" | 2770 | "£" | 2771 | "¥" | 2772 | "¿" | 2773 | "«" | 2774 | endl75 // closing delimiters76 | 25 | ","77 | 25 | "."78 | 25 | ":"79 | 25 | ";"80 | 25 | "!"81 | 25 | "?"82 | 25 | ")"83 | 25 | "]"84 | 25 | "}"85 | 25 | "%"86 | 25 | "¢"87 | 25 | "»"88 | endl89 // opening-closing delimiters90 | 25 | "'" | 2791 | 25 | "`" | 2792 | 25 | "\"" | 2793 | 25 | "\f" | 2794 | 25 | "\n" | 2795 | 25 | "\r" | 2796 | 25 | "\t" | 2797 | 25 | "\v" | 2798 | endl;99 61 } 100 62 -
src/examples/swap.c
rfbfb38e rdc2e7e0 10 10 // Created On : Wed May 27 17:56:53 2015 11 11 // Last Modified By : Peter A. Buhr 12 // Last Modified On : Thu Apr 21 08:10:41 201613 // Update Count : 6 912 // Last Modified On : Wed Mar 2 16:15:11 2016 13 // Update Count : 65 14 14 // 15 15 … … 24 24 25 25 signed int i1 = -1, i2 = -2; 26 sout | "signed int\t\t" | i1 | i2 | "\t\t\tswap ";26 sout | "signed int\t\t" | i1 | ' ' | i2 | "\t\t\tswap "; 27 27 swap( &i1, &i2 ); 28 sout | '\t' | i1 | i2 | endl;28 sout | '\t' | i1 | ' ' | i2 | endl; 29 29 30 30 unsigned int ui1 = 1, ui2 = 2; 31 sout | "unsigned int\t\t" | ui1 | ui2 | "\t\t\tswap ";31 sout | "unsigned int\t\t" | ui1 | ' ' | ui2 | "\t\t\tswap "; 32 32 swap( &ui1, &ui2 ); 33 sout | '\t' | ui1 | ui2 | endl;33 sout | '\t' | ui1 | ' ' | ui2 | endl; 34 34 35 35 signed long int li1 = -1, li2 = -2; 36 sout | "signed long int\t\t" | li1 | li2 | "\t\t\tswap ";36 sout | "signed long int\t\t" | li1 | ' ' | li2 | "\t\t\tswap "; 37 37 swap( &li1, &li2 ); 38 sout | '\t' | li1 | li2 | endl;38 sout | '\t' | li1 | ' ' | li2 | endl; 39 39 40 40 unsigned long int uli1 = 1, uli2 = 2; 41 sout | "unsigned long int\t" | uli1 | uli2 | "\t\t\tswap ";41 sout | "unsigned long int\t" | uli1 | ' ' | uli2 | "\t\t\tswap "; 42 42 swap( &uli1, &uli2 ); 43 sout | '\t' | uli1 | uli2 | endl;43 sout | '\t' | uli1 | ' ' | uli2 | endl; 44 44 45 45 signed long long int lli1 = -1, lli2 = -2; 46 sout | "signed long long int\t" | lli1 | lli2 | "\t\t\tswap ";46 sout | "signed long long int\t" | lli1 | ' ' | lli2 | "\t\t\tswap "; 47 47 swap( &lli1, &lli2 ); 48 sout | '\t' | lli1 | lli2 | endl;48 sout | '\t' | lli1 | ' ' | lli2 | endl; 49 49 50 50 unsigned long long int ulli1 = 1, ulli2 = 2; 51 sout | "unsigned long long int\t" | ulli1 | ulli2 | "\t\t\tswap ";51 sout | "unsigned long long int\t" | ulli1 | ' ' | ulli2 | "\t\t\tswap "; 52 52 swap( &ulli1, &ulli2 ); 53 sout | '\t' | ulli1 | ulli2 | endl;53 sout | '\t' | ulli1 | ' ' | ulli2 | endl; 54 54 55 55 float f1 = 1.5, f2 = 2.5; 56 sout | "float\t\t\t" | f1 | f2 | "\t\t\tswap ";56 sout | "float\t\t\t" | f1 | ' ' | f2 | "\t\tswap "; 57 57 swap( &f1, &f2 ); 58 sout | '\t' | f1 | f2 | endl;58 sout | '\t' | f1 | ' ' | f2 | endl; 59 59 60 60 double d1 = 1.5, d2 = 2.5; 61 sout | "double\t\t\t" | d1 | d2 | "\t\t\tswap ";61 sout | "double\t\t\t" | d1 | ' ' | d2 | "\t\tswap "; 62 62 swap( &d1, &d2 ); 63 sout | '\t' | d1 | d2 | endl;63 sout | '\t' | d1 | ' ' | d2 | endl; 64 64 65 65 long double ld1 = 1.5, ld2 = 2.5; 66 sout | "long double\t\t" | ld1 | ld2 | "\t\t\tswap ";66 sout | "long double\t\t" | ld1 | ' ' | ld2 | "\t\tswap "; 67 67 swap( &ld1, &ld2 ); 68 sout | '\t' | ld1 | ld2 | endl;68 sout | '\t' | ld1 | ' ' | ld2 | endl; 69 69 70 70 float _Complex fc1 = 1.5f+1.5if, fc2 = 2.5f+2.5if; 71 sout | "float _Complex\t\t" | fc1 | fc2 | "\tswap ";71 sout | "float _Complex\t\t" | fc1 | ' ' | fc2 | "\tswap "; 72 72 swap( &fc1, &fc2 ); 73 sout | '\t' | fc1 | fc2 | endl;73 sout | '\t' | fc1 | ' ' | fc2 | endl; 74 74 75 75 double _Complex dc1 = 1.5d+1.5id, dc2 = 2.5d+2.5id; 76 sout | "double _Complex\t\t" | dc1 | dc2 | "\tswap ";76 sout | "double _Complex\t\t" | dc1 | ' ' | dc2 | "\tswap "; 77 77 swap( &dc1, &dc2 ); 78 sout | '\t' | dc1 | dc2 | endl;78 sout | '\t' | dc1 | ' ' | dc2 | endl; 79 79 80 80 long double _Complex ldc1 = 1.5d+1.5il, ldc2 = 2.5d+2.5il; 81 sout | "long double _Complex\t" | ldc1 | ldc2 | "\tswap ";81 sout | "long double _Complex\t" | ldc1 | ' ' | ldc2 | "\tswap "; 82 82 swap( &ldc1, &ldc2 ); 83 sout | '\t' | ldc1 | ldc2 | endl;83 sout | '\t' | ldc1 | ' ' | ldc2 | endl; 84 84 85 85 struct S { int i, j; } s1 = { 1, 2 }, s2 = { 2, 1 }; 86 ofstream * ?|?( ofstream * os, S s ) { return os | s.i | s.j; }87 sout | "struct S\t\t" | s1 | " ," | s2 | "\t\tswap ";86 ofstream * ?|?( ofstream * os, S s ) { return os | s.i | ' ' | s.j; } 87 sout | "struct S\t\t" | s1 | " " | s2 | "\t\tswap "; 88 88 swap( &s1, &s2 ); 89 sout | '\t' | s1 | " ," | s2 | endl;89 sout | '\t' | s1 | " " | s2 | endl; 90 90 } // main 91 91 -
src/libcfa/Makefile.am
rfbfb38e rdc2e7e0 11 11 ## Created On : Sun May 31 08:54:01 2015 12 12 ## Last Modified By : Peter A. Buhr 13 ## Last Modified On : Tue Apr 19 22:30:17201614 ## Update Count : 12 413 ## Last Modified On : Wed Apr 6 21:10:44 2016 14 ## Update Count : 123 15 15 ############################################################################### 16 16 … … 60 60 ${CC} ${CFLAGS} -c -o $@ $< 61 61 62 libs = limits stdlib mathiostream fstream iterator rational62 libs = limits stdlib iostream fstream iterator rational 63 63 libcfa_a_SOURCES = libcfa-prelude.c ${libs:=.c} 64 64 -
src/libcfa/Makefile.in
rfbfb38e rdc2e7e0 83 83 libcfa_a_AR = $(AR) $(ARFLAGS) 84 84 libcfa_a_LIBADD = 85 am__objects_1 = limits.$(OBJEXT) stdlib.$(OBJEXT) math.$(OBJEXT) \ 86 iostream.$(OBJEXT) fstream.$(OBJEXT) iterator.$(OBJEXT) \ 87 rational.$(OBJEXT) 85 am__objects_1 = limits.$(OBJEXT) stdlib.$(OBJEXT) iostream.$(OBJEXT) \ 86 fstream.$(OBJEXT) iterator.$(OBJEXT) rational.$(OBJEXT) 88 87 am_libcfa_a_OBJECTS = libcfa-prelude.$(OBJEXT) $(am__objects_1) 89 88 libcfa_a_OBJECTS = $(am_libcfa_a_OBJECTS) … … 214 213 MAINTAINERCLEANFILES = ${addprefix ${libdir}/,${cfalib_DATA}} \ 215 214 ${addprefix ${libdir}/,${lib_LIBRARIES}} ${includedir}/* 216 libs = limits stdlib mathiostream fstream iterator rational215 libs = limits stdlib iostream fstream iterator rational 217 216 libcfa_a_SOURCES = libcfa-prelude.c ${libs:=.c} 218 217 cheaders = # expat … … 300 299 @AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/libcfa-prelude.Po@am__quote@ 301 300 @AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/limits.Po@am__quote@ 302 @AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/math.Po@am__quote@303 301 @AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/rational.Po@am__quote@ 304 302 @AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/stdlib.Po@am__quote@ -
src/libcfa/fstream
rfbfb38e rdc2e7e0 10 10 // Created On : Wed May 27 17:56:53 2015 11 11 // Last Modified By : Peter A. Buhr 12 // Last Modified On : Tue Apr 19 20:44:10201613 // Update Count : 8 412 // Last Modified On : Tue Apr 5 22:37:12 2016 13 // Update Count : 82 14 14 // 15 15 … … 22 22 struct ofstream { 23 23 void *file; 24 intsepDefault;25 intsepOnOff;24 _Bool sepDefault; 25 _Bool sepOnOff; 26 26 char separator[separateSize]; 27 27 }; // ofstream -
src/libcfa/rational.c
rfbfb38e rdc2e7e0 11 11 // Created On : Wed Apr 6 17:54:28 2016 12 12 // Last Modified By : Peter A. Buhr 13 // Last Modified On : T hu Apr 21 07:33:03201614 // Update Count : 2 213 // Last Modified On : Tue Apr 12 21:26:42 2016 14 // Update Count : 21 15 15 // 16 16 … … 18 18 #include "fstream" 19 19 #include "stdlib" 20 #include "math" // floor21 20 22 21 -
src/libcfa/stdlib
rfbfb38e rdc2e7e0 10 10 // Created On : Thu Jan 28 17:12:35 2016 11 11 // Last Modified By : Peter A. Buhr 12 // Last Modified On : Thu Apr 21 07:55:21201613 // Update Count : 9512 // Last Modified On : Wed Apr 13 14:45:53 2016 13 // Update Count : 85 14 14 // 15 15 … … 28 28 #endif // ! EXIT_FAILURE 29 29 void exit( int rc ); 30 void abort( void );31 30 } // extern "C" 32 31 33 32 //--------------------------------------- 34 33 35 extern "C" { void * malloc( size_t ); } // use default C routine for void * 34 extern "C" { 35 void * malloc( size_t ); // use default C routine for void * 36 } // extern "C" 36 37 forall( otype T ) T * malloc( void ); 37 38 forall( otype T ) T * malloc( char fill ); 38 39 forall( otype T ) T * malloc( T * ptr, size_t size ); 39 40 forall( otype T ) T * malloc( T * ptr, size_t size, unsigned char fill ); 40 extern "C" { void * calloc( size_t nmemb, size_t size ); } // use default C routine for void * 41 extern "C" { 42 void * calloc( size_t nmemb, size_t size ); // use default C routine for void * 43 } // extern "C" 41 44 forall( otype T ) T * calloc( size_t nmemb ); 42 extern "C" { void * realloc( void * ptr, size_t size ); } // use default C routine for void * 45 extern "C" { 46 void * realloc( void * ptr, size_t size ); // use default C routine for void * 47 } // extern "C" 43 48 forall( otype T ) T * realloc( T * ptr, size_t size ); 44 49 forall( otype T ) T * realloc( T * ptr, size_t size, unsigned char fill ); 45 50 46 51 forall( otype T ) T * aligned_alloc( size_t alignment ); 47 forall( otype T ) T * memalign( size_t alignment ); 52 forall( otype T ) T * memalign( size_t alignment ); // deprecated 48 53 forall( otype T ) int posix_memalign( T ** ptr, size_t alignment ); 49 54 50 extern "C" { 51 void * memset( void * ptr, int fill, size_t size ); 52 void free( void * ptr ); 53 } // extern "C" 55 forall( otype T ) T * memset( T * ptr, unsigned char fill ); // use default value '\0' for fill 56 forall( otype T ) T * memset( T * ptr ); // remove when default value available 54 57 55 58 //--------------------------------------- … … 97 100 98 101 char abs( char ); 99 extern "C" { int abs( int ); } // use default C routine for int 102 extern "C" { 103 int abs( int ); // use default C routine for int 104 } // extern "C" 100 105 long int abs( long int ); 101 106 long long int abs( long long int ); … … 103 108 double abs( double ); 104 109 long double abs( long double ); 105 float abs( float _Complex ); 106 double abs( double _Complex ); 107 long double abs( long double _Complex ); 110 float _Complex abs( float _Complex ); 111 double _Complex abs( double _Complex ); 112 long double _Complex abs( long double _Complex ); 113 114 //--------------------------------------- 115 116 float floor( float ); 117 extern "C" { 118 double floor( double ); // use C routine for double 119 } // extern "C" 120 long double floor( long double ); 121 122 float ceil( float ); 123 extern "C" { 124 double ceil( double ); // use C routine for double 125 } // extern "C" 126 long double ceil( long double ); 108 127 109 128 //--------------------------------------- -
src/libcfa/stdlib.c
rfbfb38e rdc2e7e0 10 10 // Created On : Thu Jan 28 17:10:29 2016 11 11 // Last Modified By : Peter A. Buhr 12 // Last Modified On : Thu Apr 21 07:58:29201613 // Update Count : 1 6512 // Last Modified On : Wed Apr 13 14:49:58 2016 13 // Update Count : 155 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 26 #include <complex.h> // _Complex_I, cabsf, cabs, cabsl 27 27 } // extern "C" 28 28 … … 34 34 //printf( "malloc3\n" ); 35 35 T * ptr = (T *)malloc( sizeof(T) ); 36 return memset( ptr , (int)fill, sizeof(T));36 return memset( ptr ); 37 37 } // malloc 38 38 … … 78 78 } // posix_memalign 79 79 80 forall( otype T ) T * memset( T * ptr, unsigned char fill ) { // use default value '\0' for fill 81 //printf( "memset1\n" ); 82 return (T *)memset( ptr, (int)fill, malloc_usable_size( ptr ) ); 83 } // memset 84 forall( otype T ) T * memset( T * ptr ) { // remove when default value available 85 //printf( "memset2\n" ); 86 return (T *)memset( ptr, 0, malloc_usable_size( ptr ) ); 87 } // memset 88 80 89 //--------------------------------------- 81 90 82 91 int ato( const char * ptr ) { 83 92 int i; 84 if ( sscanf( ptr, "%d", &i ) == EOF ) {} 93 if ( sscanf( ptr, "%d", &i ) == EOF ) {} // check return code 85 94 return i; 86 95 } 87 96 unsigned int ato( const char * ptr ) { 88 97 unsigned int ui; 89 if ( sscanf( ptr, "%u", &ui ) == EOF ) {} 98 if ( sscanf( ptr, "%u", &ui ) == EOF ) {} // check return code 90 99 return ui; 91 100 } 92 101 long int ato( const char * ptr ) { 93 102 long int li; 94 if ( sscanf( ptr, "%ld", &li ) == EOF ) {} 103 if ( sscanf( ptr, "%ld", &li ) == EOF ) {} // check return code 95 104 return li; 96 105 } 97 106 unsigned long int ato( const char * ptr ) { 98 107 unsigned long int uli; 99 if ( sscanf( ptr, "%lu", &uli ) == EOF ) {} 108 if ( sscanf( ptr, "%lu", &uli ) == EOF ) {} // check return code 100 109 return uli; 101 110 } 102 111 long long int ato( const char * ptr ) { 103 112 long long int lli; 104 if ( sscanf( ptr, "%lld", &lli ) == EOF ) {} 113 if ( sscanf( ptr, "%lld", &lli ) == EOF ) {} // check return code 105 114 return lli; 106 115 } 107 116 unsigned long long int ato( const char * ptr ) { 108 117 unsigned long long int ulli; 109 if ( sscanf( ptr, "%llu", &ulli ) == EOF ) {} 118 if ( sscanf( ptr, "%llu", &ulli ) == EOF ) {} // check return code 110 119 return ulli; 111 120 } … … 113 122 float ato( const char * ptr ) { 114 123 float f; 115 if ( sscanf( ptr, "%f", &f ) == EOF ) {} 124 if ( sscanf( ptr, "%f", &f ) == EOF ) {} // check return code 116 125 return f; 117 126 } 118 127 double ato( const char * ptr ) { 119 128 double d; 120 if ( sscanf( ptr, "%lf", &d ) == EOF ) {} 129 if ( sscanf( ptr, "%lf", &d ) == EOF ) {} // check return code 121 130 return d; 122 131 } 123 132 long double ato( const char * ptr ) { 124 133 long double ld; 125 if ( sscanf( ptr, "%Lf", &ld ) == EOF ) {} 134 if ( sscanf( ptr, "%Lf", &ld ) == EOF ) {} // check return code 126 135 return ld; 127 136 } … … 129 138 float _Complex ato( const char * ptr ) { 130 139 float re, im; 131 if ( sscanf( ptr, "%g%gi", &re, &im ) == EOF ) {} 140 if ( sscanf( ptr, "%g%gi", &re, &im ) == EOF ) {} // check return code 132 141 return re + im * _Complex_I; 133 142 } 134 143 double _Complex ato( const char * ptr ) { 135 144 double re, im; 136 if ( sscanf( ptr, "%lf%lfi", &re, &im ) == EOF ) {} 145 if ( sscanf( ptr, "%lf%lfi", &re, &im ) == EOF ) {} // check return code 137 146 return re + im * _Complex_I; 138 147 } 139 148 long double _Complex ato( const char * ptr ) { 140 149 long double re, im; 141 if ( sscanf( ptr, "%Lf%Lfi", &re, &im ) == EOF ) {} 150 if ( sscanf( ptr, "%Lf%Lfi", &re, &im ) == EOF ) {} // check return code 142 151 return re + im * _Complex_I; 143 152 } … … 221 230 long int abs( long int v ) { return labs( v ); } 222 231 long long int abs( long long int v ) { return llabs( 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 ); } 232 float abs( float v ) { return fabsf( v ); } 233 double abs( double v ) { return fabs( v ); } 234 long double abs( long double v ) { return fabsl( v ); } 235 float _Complex abs( float _Complex v ) { return cabsf( v ); } 236 double _Complex abs( double _Complex v ) { return cabs( v ); } 237 long double _Complex abs( long double _Complex v ) { return cabsl( v ); } 238 239 //--------------------------------------- 240 241 float floor( float v ) { return floorf( v ); } 242 long double floor( long double v ) { return floorl( v ); } 243 244 float ceil( float v ) { return ceilf( v ); } 245 long double ceil( long double v ) { return ceill( v ); } 229 246 230 247 //---------------------------------------
Note:
See TracChangeset
for help on using the changeset viewer.