Changes in / [fbfb38e:dc2e7e0]


Ignore:
Files:
3 deleted
15 edited

Legend:

Unmodified
Added
Removed
  • doc/user/Makefile

    rfbfb38e rdc2e7e0  
    1212
    1313FIGURES = ${addsuffix .tex, \
    14 Cdecl \
    1514}
    1615
  • doc/user/user.tex

    rfbfb38e rdc2e7e0  
    1111%% Created On       : Wed Apr  6 14:53:29 2016
    1212%% Last Modified By : Peter A. Buhr
    13 %% Last Modified On : Thu Apr 21 08:15:37 2016
    14 %% Update Count     : 131
     13%% Last Modified On : Sun Apr 10 22:50:15 2016
     14%% Update Count     : 72
    1515%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
    1616
     
    2626\usepackage{upquote}
    2727\usepackage{fullpage,times}
    28 \usepackage{epic,eepic}
    2928\usepackage{xspace}
    3029\usepackage{varioref}
     
    4948% Names used in the document.
    5049
    51 \newcommand{\Version}{1.0.0}
    5250\newcommand{\CS}{C\raisebox{-0.9ex}{\large$^\sharp$}\xspace}
    5351
     
    107105The syntax of the \CFA language builds from C, and should look immediately familiar to C programmers.
    108106% 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 C performance.
     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.
    110108Like C, \CFA is a statically typed, procedural language with a low-overhead runtime, meaning there is no global garbage-collection.
    111109The primary new features include parametric-polymorphism routines and types, exceptions, concurrency, and modules.
     
    226224
    227225
    228 \section{Compiling \CFA Program}
     226\section{Compiling \CFA}
    229227
    230228The command \lstinline@cfa@ is used to compile \CFA program(s).
     
    233231cfa [ gcc-options ] C/@{\CFA}@-files [ assembler/loader-files ]
    234232\end{lstlisting}
    235 \index{cfa@\lstinline$cfa$}\index{compilation!cfa@\lstinline$cfa$}
    236233By default, \CFA programs having the following \lstinline@gcc@ flags turned on:
    237234\begin{description}
    238235\item
    239236\hspace*{-4pt}\lstinline@-std=gnu99@
    240 \index{-std=gnu99@{\lstinline$-std=gnu99$}}\index{compilation option!-std=gnu99@{\lstinline$-std=gnu99$}}
    241237The 1999 C standard plus GNU extensions.
    242 \item
    243 \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.
    246238\end{description}
    247239The following new \CFA option is available:
     
    249241\item
    250242\hspace*{-4pt}\lstinline@-CFA@
    251 \index{-CFA@{\lstinline$-CFA$}}\index{compilation option!-CFA@{\lstinline$-CFA$}}
    252243Only 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.
    253244\end{description}
    254 
    255 The following preprocessor variables are available:
    256 \begin{description}
    257 \item
    258 \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 \item
    265 \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 \item
    270 \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 \item
    275 \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 file
    285 #else
    286 #include <fstream>              // @\CFA{}@ header file
    287 #endif
    288 \end{lstlisting}
    289 which conditionally includes the correct header file, if the program is compiled using \lstinline@gcc@ or \lstinline@cfa@.
    290245
    291246
     
    329284C declaration syntax is notoriously confusing and error prone.
    330285For 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}
     287int *x[ 10 ]
     288\end{lstlisting}
     289Is this a pointer to an array of 10 integers or an array of 10 pointers to integers?
    341290Another 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.
    342291For example, a routine returning a pointer to an array of integers is defined and used in the following way:
    343292\begin{lstlisting}
    344 int (*f())[ 5 ] {...};  // definition mimics usage
    345 ... (*f())[ 3 ] += 1;
     293int (*f())[ 10 ] {...};
     294... (*f())[  3 ] += 1;  // definition mimics usage
    346295\end{lstlisting}
    347296Essentially, the return type is wrapped around the routine name in successive layers (like an onion).
     
    373322\multicolumn{1}{c@{\hspace{30pt}}}{\textbf{\CFA}}       & \multicolumn{1}{c@{\hspace{20pt}}}{\textbf{C}}        \\
    374323\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;
    378327struct s {
    379328        int f0:3;
    380329        * int f1;
    381         [ 5 ] * int f2;
     330        [ 10 ] * int f2;
    382331};
    383332\end{lstlisting}
    384333&
    385334\begin{lstlisting}
    386 int z[ 5 ];
    387 char *w[ 5 ];
    388 double (*v)[ 5 ];
     335int z[ 10 ];
     336char *w[ 10 ];
     337double (*v)[ 10 ];
    389338struct s {
    390339        int f0:3;
    391340        int *f1;
    392         int *f2[ 5 ]
     341        int *f2[ 10 ]
    393342};
    394343\end{lstlisting}
    395344&
    396345\begin{lstlisting}
    397 // array of 5 integers
    398 // array of 5 pointers to char
    399 // pointer to array of 5 doubles
     346// array of 10 integers
     347// array of 10 pointers to char
     348// pointer to array of 10 doubles
    400349
    401350// common bit field syntax
     
    413362\begin{lstlisting}
    414363const * const int x;
    415 const * [ 5 ] const int y;
     364const * [ 10 ] const int y;
    416365\end{lstlisting}
    417366&
    418367\begin{lstlisting}
    419368int const * const x;
    420 const int (* const y)[ 5 ]
     369const int (* const y)[ 10 ]
    421370\end{lstlisting}
    422371&
    423372\begin{lstlisting}
    424373// const pointer to const integer
    425 // const pointer to array of 5 const integers
     374// const pointer to array of 10 const integers
    426375\end{lstlisting}
    427376\end{tabular}
     
    433382\multicolumn{1}{c@{\hspace{30pt}}}{\textbf{\CFA}}       & \multicolumn{1}{c@{\hspace{20pt}}}{\textbf{C}}        \\
    434383\begin{lstlisting}
    435 extern [ 5 ] int x;
     384extern [ 10 ] int x;
    436385static * const int y;
    437386\end{lstlisting}
    438387&
    439388\begin{lstlisting}
    440 int extern x[ 5 ];
     389int extern x[ 10 ];
    441390const int static *y;
    442391\end{lstlisting}
    443392&
    444393\begin{lstlisting}
    445 // externally visible array of 5 integers
     394// externally visible array of 10 integers
    446395// internally visible pointer to constant int
    447396\end{lstlisting}
     
    472421\begin{lstlisting}
    473422y = (* int)x;
    474 i = sizeof([ 5 ] * int);
     423i = sizeof([ 10 ] * int);
    475424\end{lstlisting}
    476425&
    477426\begin{lstlisting}
    478427y = (int *)x;
    479 i = sizeof(int *[ 5 ]);
     428i = sizeof(int *[ 10 ]);
    480429\end{lstlisting}
    481430\end{tabular}
     
    517466\CFA style declarations cannot be used to declare parameters for K\&R style routine definitions because of the following ambiguity:
    518467\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 5 integers.
     468int (*f(x))[ 10 ] int x; {}
     469\end{lstlisting}
     470The 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.
    522471Since the strings overlap starting with the open bracket, \lstinline@[@, there is an ambiguous interpretation for the string.
    523472As well, \CFA-style declarations cannot be used to declare parameters for C-style routine-definitions because of the following ambiguity:
     
    538487\begin{lstlisting}
    539488#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 ] )
     489int f( ptoa(p,10) ) ...         // expands to int f( int (*p)[ 10 ] )
     490[ int ] f( ptoa(p,10) ) ...     // expands to [ int ] f( int (*p)[ 10 ] )
    542491\end{lstlisting}
    543492Again, programmers are highly encouraged to use one declaration form or the other, rather than mixing the forms.
     
    858807which can be used to sort in ascending and descending order by locally redefining the less-than operator into greater-than.
    859808\begin{lstlisting}
    860 const unsigned int size = 5;
     809const unsigned int size = 10;
    861810int ia[size];
    862811...                                             // assign values to array ia
     
    925874[ double, double, double ]
    926875[ * int, int * ]                // mix of CFA and ANSI
    927 [ * [ 5 ] int, * * char, * [ [ int, int ] ] (int, int) ]
     876[ * [ 10 ] int, * * char, * [ [ int, int ] ] (int, int) ]
    928877\end{lstlisting}
    929878Like 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.
     
    22672216
    22682217        try {
    2269                 throw 13;
     2218        throw 13;
    22702219        }
    22712220        catch(int e) {
    2272                 printf(.caught an exception: %d\n., e);
     2221        printf(.caught an exception: %d\n., e);
    22732222        }
    22742223\end{lstlisting}
  • src/ResolvExpr/CastCost.cc

    rfbfb38e rdc2e7e0  
    6969                PointerType *destAsPointer = dynamic_cast< PointerType* >( dest );
    7070                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;
    7373                } else {
    7474                        ConversionCost::visit( basicType );
     
    8989                                } else if ( castResult < 0 ) {
    9090                                        cost = Cost::infinity;
     91                                        //cost = Cost( 1, 0, 0 );
    9192                                } // if
    9293                        } // if
    9394                } else if ( BasicType *destAsBasic = dynamic_cast< BasicType* >( dest ) ) {
    9495                        if ( destAsBasic->isInteger() ) {
    95                                 // necessary for, e.g. void* => unsigned long
    96                                 cost = Cost( 1, 0, 0 );
     96                                //cost = Cost( 1, 0, 0 );
     97                                cost = Cost::infinity;
    9798                        } // if
    9899                }
  • src/SymTab/Indexer.cc

    rfbfb38e rdc2e7e0  
    511511        }
    512512
    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 {
    514514                if ( ! tables ) return false;
    515                 if ( tables->scope < scope ) return false;
    516515
    517516                IdTable::const_iterator decls = tables->idTable.find( id );
     
    525524                }
    526525
    527                 return tables->base.hasIncompatibleCDecl( id, mangleName, scope );
     526                return tables->base.hasIncompatibleCDecl( id, mangleName );
    528527        }
    529528       
     
    618617                DeclarationWithType *existing = lookupIdAtScope( name, mangleName, scope );
    619618                if ( ! existing || ! addedIdConflicts( existing, decl ) ) {
    620                         // this ensures that no two declarations with the same unmangled name at the same scope both have C linkage
    621                         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 ) ) {
    622621                                throw SemanticError( "invalid overload of C function ", decl );
    623622                        } // NOTE this is broken in Richard's original code in such a way that it never triggers (it
     
    784783            using std::cerr;
    785784
    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 );
    807797        }
    808798} // namespace SymTab
  • src/SymTab/Indexer.h

    rfbfb38e rdc2e7e0  
    9999                DeclarationWithType *lookupIdAtScope( const std::string &id, const std::string &mangleName, unsigned long scope ) const;
    100100                /// 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;
    102102                // equivalents to lookup functions that only look at tables at scope `scope` (which should be >= tables->scope)
    103103                NamedTypeDecl *lookupTypeAtScope( const std::string &id, unsigned long scope ) const;
  • src/SymTab/Validate.cc

    rfbfb38e rdc2e7e0  
    515515                                }
    516516                                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());
    519518                        } // if
    520519                        delete typeInst;
  • src/driver/cfa.cc

    rfbfb38e rdc2e7e0  
    1010// Created On       : Tue Aug 20 13:44:49 2002
    1111// Last Modified By : Peter A. Buhr
    12 // Last Modified On : Wed Apr 20 18:31:28 2016
    13 // Update Count     : 133
     12// Last Modified On : Wed Apr  6 14:04:22 2016
     13// Update Count     : 132
    1414//
    1515
     
    310310                        nargs += 1;
    311311                } // if
    312                 args[nargs] = "-fgnu89-inline";
    313                 nargs += 1;
    314312                args[nargs] = ( *new string( string("-B") + Bprefix + "/" ) ).c_str();
    315313                nargs += 1;
  • src/examples/io.c

    rfbfb38e rdc2e7e0  
    1111// Created On       : Wed Mar  2 16:56:02 2016
    1212// Last Modified By : Peter A. Buhr
    13 // Last Modified On : Wed Apr 13 23:03:14 2016
    14 // Update Count     : 22
     13// Last Modified On : Wed Apr  6 14:58:27 2016
     14// Update Count     : 15
    1515//
    1616
     
    3636
    3737        ifstream in;                                                                                            // create / open file
    38         open( &in, "io.data", "r" );
     38        open( &in, "input.data", "r" );
    3939
    4040        &in | &c                                                                                                        // character
     
    5959                 | fc | dc | ldc | endl                                                                 // complex without separator
    6060                 | s1 | s2 | endl;
    61         sout | endl;
    62         sepSet( sout, " " );
    63 
    64         sout
    65                 // opening delimiters
    66                 | "v(" | 27
    67                 | "v[" | 27
    68                 | "v{" | 27
    69                 | "$" | 27
    70                 | "£" | 27
    71                 | "¥" | 27
    72                 | "¿" | 27
    73                 | "«" | 27
    74                 | endl
    75                 // closing delimiters
    76                 | 25 | ","
    77                 | 25 | "."
    78                 | 25 | ":"
    79                 | 25 | ";"
    80                 | 25 | "!"
    81                 | 25 | "?"
    82                 | 25 | ")"
    83                 | 25 | "]"
    84                 | 25 | "}"
    85                 | 25 | "%"
    86                 | 25 | "¢"
    87                 | 25 | "»"
    88                 | endl
    89                 // opening-closing delimiters
    90                 | 25 | "'" | 27
    91                 | 25 | "`" | 27
    92                 | 25 | "\"" | 27
    93                 | 25 | "\f" | 27
    94                 | 25 | "\n" | 27
    95                 | 25 | "\r" | 27
    96                 | 25 | "\t" | 27
    97                 | 25 | "\v" | 27
    98                 | endl;
    9961}
    10062
  • src/examples/swap.c

    rfbfb38e rdc2e7e0  
    1010// Created On       : Wed May 27 17:56:53 2015
    1111// Last Modified By : Peter A. Buhr
    12 // Last Modified On : Thu Apr 21 08:10:41 2016
    13 // Update Count     : 69
     12// Last Modified On : Wed Mar  2 16:15:11 2016
     13// Update Count     : 65
    1414//
    1515
     
    2424
    2525        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 ";
    2727        swap( &i1, &i2 );
    28         sout | '\t' | i1 | i2 | endl;
     28        sout | '\t' | i1 | ' ' | i2 | endl;
    2929
    3030        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 ";
    3232        swap( &ui1, &ui2 );
    33         sout | '\t' | ui1 | ui2 | endl;
     33        sout | '\t' | ui1 | ' ' | ui2 | endl;
    3434
    3535        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 ";
    3737        swap( &li1, &li2 );
    38         sout | '\t' | li1 | li2 | endl;
     38        sout | '\t' | li1 | ' ' | li2 | endl;
    3939
    4040        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 ";
    4242        swap( &uli1, &uli2 );
    43         sout | '\t' | uli1 | uli2 | endl;
     43        sout | '\t' | uli1 | ' ' | uli2 | endl;
    4444
    4545        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 ";
    4747        swap( &lli1, &lli2 );
    48         sout | '\t' | lli1 | lli2 | endl;
     48        sout | '\t' | lli1 | ' ' | lli2 | endl;
    4949
    5050        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 ";
    5252        swap( &ulli1, &ulli2 );
    53         sout | '\t' | ulli1 | ulli2 | endl;
     53        sout | '\t' | ulli1 | ' ' | ulli2 | endl;
    5454
    5555        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 ";
    5757        swap( &f1, &f2 );
    58         sout | '\t' | f1 | f2 | endl;
     58        sout | '\t' | f1 | ' ' | f2 | endl;
    5959
    6060        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 ";
    6262        swap( &d1, &d2 );
    63         sout | '\t' | d1 | d2 | endl;
     63        sout | '\t' | d1 | ' ' | d2 | endl;
    6464
    6565        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 ";
    6767        swap( &ld1, &ld2 );
    68         sout | '\t' | ld1 | ld2 | endl;
     68        sout | '\t' | ld1 | ' ' | ld2 | endl;
    6969
    7070        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 ";
    7272        swap( &fc1, &fc2 );
    73         sout | '\t' | fc1 | fc2 | endl;
     73        sout | '\t' | fc1 | ' ' | fc2 | endl;
    7474
    7575        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 ";
    7777        swap( &dc1, &dc2 );
    78         sout | '\t' | dc1 | dc2 | endl;
     78        sout | '\t' | dc1 | ' ' | dc2 | endl;
    7979
    8080        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 ";
    8282        swap( &ldc1, &ldc2 );
    83         sout | '\t' | ldc1 | ldc2 | endl;
     83        sout | '\t' | ldc1 | ' ' | ldc2 | endl;
    8484
    8585        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 ";
    8888        swap( &s1, &s2 );
    89         sout | '\t' | s1 | "," | s2 | endl;
     89        sout | '\t' | s1 | "  " | s2 | endl;
    9090} // main
    9191
  • src/libcfa/Makefile.am

    rfbfb38e rdc2e7e0  
    1111## Created On       : Sun May 31 08:54:01 2015
    1212## Last Modified By : Peter A. Buhr
    13 ## Last Modified On : Tue Apr 19 22:30:17 2016
    14 ## Update Count     : 124
     13## Last Modified On : Wed Apr  6 21:10:44 2016
     14## Update Count     : 123
    1515###############################################################################
    1616
     
    6060        ${CC} ${CFLAGS} -c -o $@ $<
    6161
    62 libs = limits stdlib math iostream fstream iterator rational
     62libs = limits stdlib iostream fstream iterator rational
    6363libcfa_a_SOURCES = libcfa-prelude.c ${libs:=.c}
    6464
  • src/libcfa/Makefile.in

    rfbfb38e rdc2e7e0  
    8383libcfa_a_AR = $(AR) $(ARFLAGS)
    8484libcfa_a_LIBADD =
    85 am__objects_1 = limits.$(OBJEXT) stdlib.$(OBJEXT) math.$(OBJEXT) \
    86         iostream.$(OBJEXT) fstream.$(OBJEXT) iterator.$(OBJEXT) \
    87         rational.$(OBJEXT)
     85am__objects_1 = limits.$(OBJEXT) stdlib.$(OBJEXT) iostream.$(OBJEXT) \
     86        fstream.$(OBJEXT) iterator.$(OBJEXT) rational.$(OBJEXT)
    8887am_libcfa_a_OBJECTS = libcfa-prelude.$(OBJEXT) $(am__objects_1)
    8988libcfa_a_OBJECTS = $(am_libcfa_a_OBJECTS)
     
    214213MAINTAINERCLEANFILES = ${addprefix ${libdir}/,${cfalib_DATA}} \
    215214        ${addprefix ${libdir}/,${lib_LIBRARIES}} ${includedir}/*
    216 libs = limits stdlib math iostream fstream iterator rational
     215libs = limits stdlib iostream fstream iterator rational
    217216libcfa_a_SOURCES = libcfa-prelude.c ${libs:=.c}
    218217cheaders = # expat
     
    300299@AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/libcfa-prelude.Po@am__quote@
    301300@AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/limits.Po@am__quote@
    302 @AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/math.Po@am__quote@
    303301@AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/rational.Po@am__quote@
    304302@AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/stdlib.Po@am__quote@
  • src/libcfa/fstream

    rfbfb38e rdc2e7e0  
    1010// Created On       : Wed May 27 17:56:53 2015
    1111// Last Modified By : Peter A. Buhr
    12 // Last Modified On : Tue Apr 19 20:44:10 2016
    13 // Update Count     : 84
     12// Last Modified On : Tue Apr  5 22:37:12 2016
     13// Update Count     : 82
    1414//
    1515
     
    2222struct ofstream {
    2323        void *file;
    24         int sepDefault;
    25         int sepOnOff;
     24        _Bool sepDefault;
     25        _Bool sepOnOff;
    2626        char separator[separateSize];
    2727}; // ofstream
  • src/libcfa/rational.c

    rfbfb38e rdc2e7e0  
    1111// Created On       : Wed Apr  6 17:54:28 2016
    1212// Last Modified By : Peter A. Buhr
    13 // Last Modified On : Thu Apr 21 07:33:03 2016
    14 // Update Count     : 22
     13// Last Modified On : Tue Apr 12 21:26:42 2016
     14// Update Count     : 21
    1515//
    1616
     
    1818#include "fstream"
    1919#include "stdlib"
    20 #include "math"                                                                                 // floor
    2120
    2221
  • src/libcfa/stdlib

    rfbfb38e rdc2e7e0  
    1010// Created On       : Thu Jan 28 17:12:35 2016
    1111// Last Modified By : Peter A. Buhr
    12 // Last Modified On : Thu Apr 21 07:55:21 2016
    13 // Update Count     : 95
     12// Last Modified On : Wed Apr 13 14:45:53 2016
     13// Update Count     : 85
    1414//
    1515
     
    2828#endif // ! EXIT_FAILURE
    2929void exit( int rc );
    30 void abort( void );
    3130} // extern "C"
    3231
    3332//---------------------------------------
    3433
    35 extern "C" { void * malloc( size_t ); }                                 // use default C routine for void *
     34extern "C" {
     35void * malloc( size_t );                                                                // use default C routine for void *
     36} // extern "C"
    3637forall( otype T ) T * malloc( void );
    3738forall( otype T ) T * malloc( char fill );
    3839forall( otype T ) T * malloc( T * ptr, size_t size );
    3940forall( 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 *
     41extern "C" {
     42void * calloc( size_t nmemb, size_t size );                             // use default C routine for void *
     43} // extern "C"
    4144forall( otype T ) T * calloc( size_t nmemb );
    42 extern "C" { void * realloc( void * ptr, size_t size ); } // use default C routine for void *
     45extern "C" {
     46void * realloc( void * ptr, size_t size );                              // use default C routine for void *
     47} // extern "C"
    4348forall( otype T ) T * realloc( T * ptr, size_t size );
    4449forall( otype T ) T * realloc( T * ptr, size_t size, unsigned char fill );
    4550
    4651forall( otype T ) T * aligned_alloc( size_t alignment );
    47 forall( otype T ) T * memalign( size_t alignment );
     52forall( otype T ) T * memalign( size_t alignment );             // deprecated
    4853forall( otype T ) int posix_memalign( T ** ptr, size_t alignment );
    4954
    50 extern "C" {
    51 void * memset( void * ptr, int fill, size_t size );
    52 void free( void * ptr );
    53 } // extern "C"
     55forall( otype T ) T * memset( T * ptr, unsigned char fill ); // use default value '\0' for fill
     56forall( otype T ) T * memset( T * ptr );                                // remove when default value available
    5457
    5558//---------------------------------------
     
    97100
    98101char abs( char );
    99 extern "C" { int abs( int ); }                                                  // use default C routine for int
     102extern "C" {
     103int abs( int );                                                                                 // use default C routine for int
     104} // extern "C"
    100105long int abs( long int );
    101106long long int abs( long long int );
     
    103108double abs( double );
    104109long double abs( long double );
    105 float abs( float _Complex );
    106 double abs( double _Complex );
    107 long double abs( long double _Complex );
     110float _Complex abs( float _Complex );
     111double _Complex abs( double _Complex );
     112long double _Complex abs( long double _Complex );
     113
     114//---------------------------------------
     115
     116float floor( float );
     117extern "C" {
     118double floor( double );                                                                 // use C routine for double
     119} // extern "C"
     120long double floor( long double );
     121
     122float ceil( float );
     123extern "C" {
     124double ceil( double );                                                                  // use C routine for double
     125} // extern "C"
     126long double ceil( long double );
    108127
    109128//---------------------------------------
  • src/libcfa/stdlib.c

    rfbfb38e rdc2e7e0  
    1010// Created On       : Thu Jan 28 17:10:29 2016
    1111// Last Modified By : Peter A. Buhr
    12 // Last Modified On : Thu Apr 21 07:58:29 2016
    13 // Update Count     : 165
     12// Last Modified On : Wed Apr 13 14:49:58 2016
     13// Update Count     : 155
    1414//
    1515
     
    2424#include <malloc.h>                                                                             // malloc_usable_size
    2525#include <math.h>                                                                               // fabsf, fabs, fabsl
    26 #include <complex.h>                                                                    // _Complex_I
     26#include <complex.h>                                                                    // _Complex_I, cabsf, cabs, cabsl
    2727} // extern "C"
    2828
     
    3434        //printf( "malloc3\n" );
    3535        T * ptr = (T *)malloc( sizeof(T) );
    36     return memset( ptr, (int)fill, sizeof(T) );
     36    return memset( ptr );
    3737} // malloc
    3838
     
    7878} // posix_memalign
    7979
     80forall( 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
     84forall( 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
    8089//---------------------------------------
    8190
    8291int ato( const char * ptr ) {
    8392        int i;
    84         if ( sscanf( ptr, "%d", &i ) == EOF ) {}
     93        if ( sscanf( ptr, "%d", &i ) == EOF ) {}                        // check return code
    8594        return i;
    8695}
    8796unsigned int ato( const char * ptr ) {
    8897        unsigned int ui;
    89         if ( sscanf( ptr, "%u", &ui ) == EOF ) {}
     98        if ( sscanf( ptr, "%u", &ui ) == EOF ) {}                       // check return code
    9099        return ui;
    91100}
    92101long int ato( const char * ptr ) {
    93102        long int li;
    94         if ( sscanf( ptr, "%ld", &li ) == EOF ) {}
     103        if ( sscanf( ptr, "%ld", &li ) == EOF ) {}                      // check return code
    95104        return li;
    96105}
    97106unsigned long int ato( const char * ptr ) {
    98107        unsigned long int uli;
    99         if ( sscanf( ptr, "%lu", &uli ) == EOF ) {}
     108        if ( sscanf( ptr, "%lu", &uli ) == EOF ) {}                     // check return code
    100109        return uli;
    101110}
    102111long long int ato( const char * ptr ) {
    103112        long long int lli;
    104         if ( sscanf( ptr, "%lld", &lli ) == EOF ) {}
     113        if ( sscanf( ptr, "%lld", &lli ) == EOF ) {}            // check return code
    105114        return lli;
    106115}
    107116unsigned long long int ato( const char * ptr ) {
    108117        unsigned long long int ulli;
    109         if ( sscanf( ptr, "%llu", &ulli ) == EOF ) {}
     118        if ( sscanf( ptr, "%llu", &ulli ) == EOF ) {}           // check return code
    110119        return ulli;
    111120}
     
    113122float ato( const char * ptr ) {
    114123        float f;
    115         if ( sscanf( ptr, "%f", &f ) == EOF ) {}
     124        if ( sscanf( ptr, "%f", &f ) == EOF ) {}                        // check return code
    116125        return f;
    117126}
    118127double ato( const char * ptr ) {
    119128        double d;
    120         if ( sscanf( ptr, "%lf", &d ) == EOF ) {}
     129        if ( sscanf( ptr, "%lf", &d ) == EOF ) {}                       // check return code
    121130        return d;
    122131}
    123132long double ato( const char * ptr ) {
    124133        long double ld;
    125         if ( sscanf( ptr, "%Lf", &ld ) == EOF ) {}
     134        if ( sscanf( ptr, "%Lf", &ld ) == EOF ) {}                      // check return code
    126135        return ld;
    127136}
     
    129138float _Complex ato( const char * ptr ) {
    130139        float re, im;
    131         if ( sscanf( ptr, "%g%gi", &re, &im ) == EOF ) {}
     140        if ( sscanf( ptr, "%g%gi", &re, &im ) == EOF ) {}       // check return code
    132141        return re + im * _Complex_I;
    133142}
    134143double _Complex ato( const char * ptr ) {
    135144        double re, im;
    136         if ( sscanf( ptr, "%lf%lfi", &re, &im ) == EOF ) {}
     145        if ( sscanf( ptr, "%lf%lfi", &re, &im ) == EOF ) {} // check return code
    137146        return re + im * _Complex_I;
    138147}
    139148long double _Complex ato( const char * ptr ) {
    140149        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
    142151        return re + im * _Complex_I;
    143152}       
     
    221230long int abs( long int v ) { return labs( v ); }
    222231long 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 ); }
     232float abs( float v ) { return fabsf( v ); }
     233double abs( double v ) { return fabs( v ); }
     234long double abs( long double v ) { return fabsl( v ); }
     235float _Complex abs( float _Complex v ) { return cabsf( v ); }
     236double _Complex abs( double _Complex v ) { return cabs( v ); }
     237long double _Complex abs( long double _Complex v ) { return cabsl( v ); }
     238
     239//---------------------------------------
     240
     241float floor( float v ) { return floorf( v ); }
     242long double floor( long double v ) { return floorl( v ); }
     243
     244float ceil( float v ) { return ceilf( v ); }
     245long double ceil( long double v ) { return ceill( v ); }
    229246
    230247//---------------------------------------
Note: See TracChangeset for help on using the changeset viewer.