Changeset c58f4ab


Ignore:
Timestamp:
Mar 23, 2017, 11:30:42 AM (7 years ago)
Author:
Thierry Delisle <tdelisle@…>
Branches:
ADT, aaron-thesis, arm-eh, ast-experimental, cleanup-dtors, deferred_resn, demangler, enum, forall-pointer-decay, jacob/cs343-translation, jenkins-sandbox, master, new-ast, new-ast-unique-expr, new-env, no_list, persistent-indexer, pthread-emulation, qualifiedEnum, resolv-new, with_gc
Children:
578b637
Parents:
9fcdfa3 (diff), 27cc24e (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.
Message:

Merge branch 'master' of plg.uwaterloo.ca:software/cfa/cfa-cc

Files:
1 added
13 edited

Legend:

Unmodified
Added
Removed
  • doc/generic_types/generic_types.tex

    r9fcdfa3 rc58f4ab  
    139139\begin{lstlisting}
    140140forall(otype T)
    141 T identity(T x) {is_
     141T identity(T x) {
    142142    return x;
    143143}
     
    294294Since @pair(T*, T*)@ is a concrete type, there are no added implicit parameters to @lexcmp@, so the code generated by \CFA{} will be effectively identical to a version of this written in standard C using @void*@, yet the \CFA{} version will be type-checked to ensure that the fields of both pairs and the arguments to the comparison function match in type.
    295295
    296 \TODO{} The second is zero-cost ``tag'' structs.
     296Another useful pattern enabled by re-used dtype-static type instantiations is zero-cost ``tag'' structs. Sometimes a particular bit of information is only useful for type-checking, and can be omitted at runtime. Tag structs can be used to provide this information to the compiler without further runtime overhead, as in the following example:
     297\begin{lstlisting}
     298forall(dtype Unit) struct scalar { unsigned long value; };
     299
     300struct metres {};
     301struct litres {};
     302
     303forall(dtype U)
     304scalar(U) ?+?(scalar(U) a, scalar(U) b) {
     305        return (scalar(U)){ a.value + b.value };
     306}
     307
     308scalar(metres) half_marathon = { 21093 };
     309scalar(litres) swimming_pool = { 2500000 };
     310
     311scalar(metres) marathon = half_marathon + half_marathon;
     312scalar(litres) two_pools = swimming_pool + swimming_pool;
     313marathon + swimming_pool; // ERRORv -- caught by compiler
     314\end{lstlisting}
     315@scalar@ is a dtype-static type, so all uses of it will use a single struct definition, containing only a single @unsigned long@, and can share the same implementations of common routines like @?+?@ -- these implementations may even be separately compiled, unlike \CC{} template functions. However, the \CFA{} type-checker will ensure that matching types are used by all calls to @?+?@, preventing nonsensical computations like adding the length of a marathon to the volume of an olympic pool.
    297316
    298317\section{Tuples}
  • doc/user/user.tex

    r9fcdfa3 rc58f4ab  
    1111%% Created On       : Wed Apr  6 14:53:29 2016
    1212%% Last Modified By : Peter A. Buhr
    13 %% Last Modified On : Mon Feb 20 12:35:48 2017
    14 %% Update Count     : 1377
     13%% Last Modified On : Thu Mar 23 09:53:57 2017
     14%% Update Count     : 1399
    1515%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
    1616
     
    9191}% title
    9292
    93 \author{\huge
    94 Peter A. Buhr and ...
     93\author{
     94\huge \CFA Team \medskip \\
     95\Large Peter A. Buhr, Richard Bilson, Thierry Delisle, \smallskip \\
     96\Large Glen Ditchfield, Rodolfo G. Esteves, Aaron Moss, Rob Schluntz
    9597}% author
    9698
     
    46574659which is a local mechanism to disable insertion of the separator character.
    46584660\item
    4659 A separator does not appear before a C string starting with the (extended) \Index{ASCII}\index{ASCII!extended} characters: \lstinline[mathescape=off]@([{$£¥¡¿«@
     4661A separator does not appear before a C string starting with the (extended) \Index{ASCII}\index{ASCII!extended} characters: \lstinline[mathescape=off]@([{=$£¥¡¿«@
    46604662%$
    46614663\begin{lstlisting}[mathescape=off]
    4662 sout | "x (" | 1 | "x [" | 2 | "x {" | 3 | "x $" | 4 | "x £" | 5 | "x ¥" | 6 | "x ¡" | 7
    4663          | "x ¿" | 8 | "x «" | 9 | endl;
     4664sout | "x (" | 1 | "x [" | 2 | "x {" | 3 | "x =" | 4 | "x $" | 5 | "x £" | 6 | "x ¥" | 7
     4665         | "x ¡" | 8 | "x ¿" | 9 | "x «" | 10 | endl;
    46644666\end{lstlisting}
    46654667%$
    46664668\begin{lstlisting}[mathescape=off,showspaces=true,aboveskip=0pt,belowskip=0pt]
    4667 x (1 x [2 x {3 x $4 x £5 x ¥6 x ¡7 x ¿8 x «9
     4669x (1 x [2 x {3 x =4 x $5 x £6 x ¥7 x ¡8 x ¿9 x «10
    46684670\end{lstlisting}
    46694671%$
    46704672\item
     4673{\lstset{deletedelim=**[is][]{¢}{¢}}
    46714674A seperator does not appear after a C string ending with the (extended) \Index{ASCII}\index{ASCII!extended} characters: ©,.:;!?)]}%¢»©
    46724675\begin{lstlisting}[belowskip=0pt]
    4673 sout | 1 | ", x" | 2 | ". x" | 3 | ": x" | 4 | "; x" | 5 | "! x" | 6 | "? x" | 7
    4674          | ") x" | 8 | "] x" | 9 | "} x" | 10 | "% x" | 11 | "¢ x" | 12 | "» x" | endl;
     4676sout | 1 | ", x" | 2 | ". x" | 3 | ": x" | 4 | "; x" | 5 | "! x" | 6 | "? x" | 7 | "% x"
     4677         | 8 | "¢ x" | 9 | "» x" | 10 | ") x" | 11 | "] x" | 12 | "} x" | endl;
    46754678\end{lstlisting}
    46764679\begin{lstlisting}[mathescape=off,showspaces=true,aboveskip=0pt,belowskip=0pt]
    4677 1, x 2. x 3: x 4; x 5! x 6? x 7) x 8] x 9} x 10% x 11¢ 12»
    4678 \end{lstlisting}
     46801, x 2. x 3: x 4; x 5! x 6? x 7% x 8¢ x 9» x 10) x 11] x 12} x
     4681\end{lstlisting}}%
    46794682\item
    46804683A seperator does not appear before or after a C string begining/ending with the \Index{ASCII} quote or whitespace characters: \lstinline[showspaces=true]@`'" \t\v\f\r\n@
     
    46944697\end{lstlisting}
    46954698\begin{lstlisting}[mathescape=off,aboveskip=0pt,belowskip=0pt]
    4696 sout | 1 | sepOff | 2 | 3 | endl;                       §\C{// turn off implicit separator temporarily}§
     4699sout | 1 | sepOff | 2 | 3 | endl;                       §\C{// turn off implicit separator locally}§
    46974700\end{lstlisting}
    46984701\begin{lstlisting}[mathescape=off,showspaces=true,aboveskip=0pt,belowskip=0pt]
     
    47004703\end{lstlisting}
    47014704\begin{lstlisting}[mathescape=off,aboveskip=0pt,belowskip=0pt]
    4702 sout | sepDisable | 1 | 2 | 3 | endl;           §\C{// turn off implicit separation, affects all subsequent prints
     4705sout | sepDisable | 1 | 2 | 3 | endl;           §\C{// turn off implicit separation globally
    47034706\end{lstlisting}
    47044707\begin{lstlisting}[mathescape=off,showspaces=true,aboveskip=0pt,belowskip=0pt]
     
    47064709\end{lstlisting}
    47074710\begin{lstlisting}[mathescape=off,aboveskip=0pt,belowskip=0pt]
    4708 sout | 1 | sepOn | 2 | 3 | endl;                        §\C{// turn on implicit separator temporarily}§
     4711sout | 1 | sepOn | 2 | 3 | endl;                        §\C{// turn on implicit separator locally}§
    47094712\end{lstlisting}
    47104713\begin{lstlisting}[mathescape=off,showspaces=true,aboveskip=0pt,belowskip=0pt]
     
    47124715\end{lstlisting}
    47134716\begin{lstlisting}[mathescape=off,aboveskip=0pt,belowskip=0pt]
    4714 sout | sepEnable | 1 | 2 | 3 | endl;            §\C{// turn on implicit separation, affects all subsequent prints
     4717sout | sepEnable | 1 | 2 | 3 | endl;            §\C{// turn on implicit separation globally
    47154718\end{lstlisting}
    47164719\begin{lstlisting}[mathescape=off,showspaces=true,aboveskip=0pt,belowskip=0pt]
     
    47304733
    47314734int main() {
    4732         int x = 3, y = 5, z = 7;
    4733         sout | x * 3 | y + 1 | z << 2 | x == y | (x | y) | (x || y) | (x > z ? 1 : 2) | endl;
     4735        int x = 0, y = 1, z = 2;
     4736        sout | x * 3 | y + 1 | z << 2 | x == y | (x | y) | (x || y) | (x > z ? 1 : 2) | endl | endl;
    47344737        sout | 1 | 2 | 3 | endl;
    47354738        sout | '1' | '2' | '3' | endl;
    47364739        sout | 1 | "" | 2 | "" | 3 | endl;
    4737         sout | "x (" | 1 | "x [" | 2 | "x {" | 3 | "x $" | 4 | "x £" | 5 | "x ¥" | 6 | "x ¡" | 7 | "x ¿" | 8 | "x «" | 9 | endl;
    4738         sout | 1 | ", x" | 2 | ". x" | 3 | ": x" | 4 | "; x" | 5 | "! x" | 6 | "? x" | 7 | ") x" | 8 | "] x" | 9 | "} x"
    4739                  | 10 | "% x" | 11 | "¢ x" | 12 | "» x" | endl;
     4740        sout | "x (" | 1 | "x [" | 2 | "x {" | 3 | "x =" | 4 | "x $" | 5 | "x £" | 6 | "x ¥" | 7
     4741                | "x ¡" | 8 | "x ¿" | 9 | "x «" | 10 | endl;
     4742        sout | 1 | ", x" | 2 | ". x" | 3 | ": x" | 4 | "; x" | 5 | "! x" | 6 | "? x" | 7 | "% x"
     4743                | 8 | "¢ x" | 9 | "» x" | 10 | ") x" | 11 | "] x" | 12 | "} x" | endl;
    47404744        sout | "x`" | 1 | "`x'" | 2 | "'x\"" | 3 | "\"x" | "x " | 4 | " x" | "x\t" | 1 | "\tx" | endl;
    47414745        sout | sepOn | 1 | 2 | 3 | sepOn | endl;        // separator at start of line
  • src/libcfa/Makefile.am

    r9fcdfa3 rc58f4ab  
    3535         ${AM_V_GEN}@BACKEND_CC@ @CFA_FLAGS@ -D__CFA_DEBUG__ -O0 -c -o $@ $<
    3636
    37 EXTRA_FLAGS = -g -Wall -Wno-unused-function -I${abs_top_srcdir}/src/libcfa/libhdr -imacros libcfa-prelude.c @CFA_FLAGS@
     37EXTRA_FLAGS = -g -Wall -Werror -Wno-unused-function -I${abs_top_srcdir}/src/libcfa/libhdr -imacros libcfa-prelude.c @CFA_FLAGS@
    3838
    3939AM_CCASFLAGS = @CFA_FLAGS@
  • src/libcfa/Makefile.in

    r9fcdfa3 rc58f4ab  
    305305AUTOMAKE_OPTIONS = subdir-objects
    306306lib_LIBRARIES = $(am__append_1) $(am__append_2)
    307 EXTRA_FLAGS = -g -Wall -Wno-unused-function -I${abs_top_srcdir}/src/libcfa/libhdr -imacros libcfa-prelude.c @CFA_FLAGS@
     307EXTRA_FLAGS = -g -Wall -Werror -Wno-unused-function -I${abs_top_srcdir}/src/libcfa/libhdr -imacros libcfa-prelude.c @CFA_FLAGS@
    308308AM_CCASFLAGS = @CFA_FLAGS@
    309309headers = limits stdlib math iostream fstream iterator rational assert \
  • src/libcfa/fstream

    r9fcdfa3 rc58f4ab  
    1010// Created On       : Wed May 27 17:56:53 2015
    1111// Last Modified By : Peter A. Buhr
    12 // Last Modified On : Tue Mar  7 14:48:08 2017
    13 // Update Count     : 91
     12// Last Modified On : Tue Mar 21 15:57:24 2017
     13// Update Count     : 102
    1414//
    1515
     
    2121enum { separateSize = 16 };
    2222struct ofstream {
    23         void *file;
     23        void * file;
    2424        _Bool sepDefault;
    2525        _Bool sepOnOff;
     26        const char * sepCur;
    2627        char separator[separateSize];
     28        char tupleSeparator[separateSize];
    2729}; // ofstream
    2830
     
    3234void sepReset( ofstream * );
    3335void sepReset( ofstream *, _Bool );
     36const char * sepGetCur( ofstream * );
     37void sepSetCur( ofstream *, const char * );
    3438const char * sepGet( ofstream * );
    3539void sepSet( ofstream *, const char * );
     40const char * sepGetTuple( ofstream * );
     41void sepSetTuple( ofstream *, const char * );
    3642_Bool sepDisable( ofstream * );
    3743_Bool sepEnable( ofstream * );
     
    4248void close( ofstream * );
    4349ofstream * write( ofstream *, const char * data, unsigned long int size );
    44 int prtfmt( ofstream *, const char fmt[], ... );
     50int fmt( ofstream *, const char fmt[], ... );
     51
     52void ?{}( ofstream * );
    4553
    4654extern ofstream * sout, * serr;
     
    4856// implement context istream
    4957struct ifstream {
    50         void *file;
     58        void * file;
    5159}; // ifstream
    5260
     
    5765ifstream * read( ifstream * is, char * data, unsigned long int size );
    5866ifstream * ungetc( ifstream * is, char c );
    59 int scanfmt( ifstream *, const char fmt[], ... );
     67int fmt( ifstream *, const char fmt[], ... );
    6068
    61 extern ifstream *sin;
     69extern ifstream * sin;
    6270
    6371#endif // __FSTREAM_H__
  • src/libcfa/fstream.c

    r9fcdfa3 rc58f4ab  
    1010// Created On       : Wed May 27 17:56:53 2015
    1111// Last Modified By : Peter A. Buhr
    12 // Last Modified On : Tue Mar  7 14:48:09 2017
    13 // Update Count     : 192
     12// Last Modified On : Thu Mar 23 08:20:41 2017
     13// Update Count     : 226
    1414//
    1515
     
    2525#include <complex.h>                                                                    // creal, cimag
    2626}
     27#include "assert"
    2728
    2829#define IO_MSG "I/O error: "
     30
     31void ?{}( ofstream * this, void * file, _Bool sepDefault, _Bool sepOnOff, const char * separator, const char * tupleSeparator ) {
     32        this->file = file;
     33        this->sepDefault = sepDefault;
     34        this->sepOnOff = sepOnOff;
     35        sepSet( this, separator );
     36        sepSetCur( this, sepGet( this ) );
     37        sepSetTuple( this, tupleSeparator );
     38}
    2939
    3040_Bool sepPrt( ofstream * os ) { return os->sepOnOff; }
     
    3343void sepReset( ofstream * os ) { os->sepOnOff = os->sepDefault; }
    3444void sepReset( ofstream * os, _Bool reset ) { os->sepDefault = reset; os->sepOnOff = os->sepDefault; }
    35 const char * sepGet( ofstream * os ) { return &(os->separator[0]); }
     45
     46const char * sepGetCur( ofstream * os ) { return os->sepCur; }
     47void sepSetCur( ofstream * os, const char * sepCur ) { os->sepCur = sepCur; }
     48
     49const char * sepGet( ofstream * os ) { return os->separator; }
    3650
    3751void sepSet( ofstream * os, const char * s ) {
    38         strncpy( &(os->separator[0]), s, separateSize - 1 );
     52        assert( s );
     53        strncpy( os->separator, s, separateSize - 1 );
    3954        os->separator[separateSize - 1] = '\0';
     55} // sepSet
     56
     57const char * sepGetTuple( ofstream * os ) { return os->tupleSeparator; }
     58
     59void sepSetTuple( ofstream * os, const char * s ) {
     60        assert( s );
     61        strncpy( os->tupleSeparator, s, separateSize - 1 );
     62        os->tupleSeparator[separateSize - 1] = '\0';
    4063} // sepSet
    4164
     
    6992                exit( EXIT_FAILURE );
    7093        } // if
    71         os->file = file;
    72         sepOff( os );
    73         sepSet( os, " " );
     94        ?{}( os, file, 1, 0, " ", ", " );
    7495} // open
    7596
     
    95116} // write
    96117
    97 int prtfmt( ofstream * os, const char fmt[], ... ) {
     118int fmt( ofstream * os, const char format[], ... ) {
    98119        va_list args;
    99         va_start( args, fmt );
    100         int len = vfprintf( (FILE *)(os->file), fmt, args );
     120        va_start( args, format );
     121        int len = vfprintf( (FILE *)(os->file), format, args );
    101122        if ( len == EOF ) {
    102123                if ( ferror( (FILE *)(os->file) ) ) {
     
    109130        sepReset( os );                                                                         // reset separator
    110131        return len;
    111 } // prtfmt
    112 
    113 
    114 static ofstream soutFile = { (FILE *)(&_IO_2_1_stdout_), 1, 0, { ' ', '\0' } };
     132} // fmt
     133
     134static ofstream soutFile = { (FILE *)(&_IO_2_1_stdout_), 1, 0, " ", ", " };
    115135ofstream *sout = &soutFile;
    116 static ofstream serrFile = { (FILE *)(&_IO_2_1_stderr_), 1, 0, { ' ', '\0' } };
     136static ofstream serrFile = { (FILE *)(&_IO_2_1_stderr_), 1, 0, " ", ", " };
    117137ofstream *serr = &serrFile;
    118138
     
    173193} // ungetc
    174194
    175 int scanfmt( ifstream * is, const char fmt[], ... ) {
     195int fmt( ifstream * is, const char format[], ... ) {
    176196        va_list args;
    177197
    178         va_start( args, fmt );
    179         int len = vfscanf( (FILE *)(is->file), fmt, args );
     198        va_start( args, format );
     199        int len = vfscanf( (FILE *)(is->file), format, args );
    180200        if ( len == EOF ) {
    181201                if ( ferror( (FILE *)(is->file) ) ) {
     
    186206        va_end( args );
    187207        return len;
    188 } // prtfmt
     208} // fmt
    189209
    190210
  • src/libcfa/iostream

    r9fcdfa3 rc58f4ab  
    1010// Created On       : Wed May 27 17:56:53 2015
    1111// Last Modified By : Peter A. Buhr
    12 // Last Modified On : Mon Mar  6 20:51:35 2017
    13 // Update Count     : 98
     12// Last Modified On : Tue Mar 21 15:57:29 2017
     13// Update Count     : 104
    1414//
    1515
     
    2525        void sepReset( ostype * );                                                      // set separator state to default state
    2626        void sepReset( ostype *, _Bool );                                       // set separator and default state
     27        const char * sepGetCur( ostype * );                                     // get current separator string
     28        void sepSetCur( ostype *, const char * );                       // set current separator string
     29        const char * sepGet( ostype * );                                        // get separator string
    2730        void sepSet( ostype *, const char * );                          // set separator to string (15 character maximum)
    28         const char * sepGet( ostype * );                                        // get separator string
     31        const char * sepGetTuple( ostype * );                           // get tuple separator string
     32        void sepSetTuple( ostype *, const char * );                     // set tuple separator to string (15 character maximum)
    2933        _Bool sepDisable( ostype * );                                           // set default state to off, and return previous state
    3034        _Bool sepEnable( ostype * );                                            // set default state to on, and return previous state
     
    3539        void close( ostype * os );
    3640        ostype * write( ostype *, const char *, unsigned long int );
    37         int prtfmt( ostype *, const char fmt[], ... );
     41        int fmt( ostype *, const char fmt[], ... );
    3842};
    3943
     
    9599        istype * read( istype *, char *, unsigned long int );
    96100        istype * ungetc( istype *, char );
    97         int scanfmt( istype *, const char fmt[], ... );
     101        int fmt( istype *, const char fmt[], ... );
    98102};
    99103
  • src/libcfa/iostream.c

    r9fcdfa3 rc58f4ab  
    1010// Created On       : Wed May 27 17:56:53 2015
    1111// Last Modified By : Peter A. Buhr
    12 // Last Modified On : Mon Mar  6 20:52:02 2017
    13 // Update Count     : 313
     12// Last Modified On : Thu Mar 23 08:20:40 2017
     13// Update Count     : 367
    1414//
    1515
     
    2424
    2525forall( dtype ostype | ostream( ostype ) )
    26 ostype * ?|?( ostype *os, char c ) {
    27         prtfmt( os, "%c", c );
     26ostype * ?|?( ostype * os, char c ) {
     27        fmt( os, "%c", c );
    2828        sepOff( os );
    2929        return os;
     
    3131
    3232forall( dtype ostype | ostream( ostype ) )
    33 ostype * ?|?( ostype *os, signed char c ) {
    34         prtfmt( os, "%hhd", c );
     33ostype * ?|?( ostype * os, signed char c ) {
     34        fmt( os, "%hhd", c );
    3535        sepOff( os );
    3636        return os;
     
    3838
    3939forall( dtype ostype | ostream( ostype ) )
    40 ostype * ?|?( ostype *os, unsigned char c ) {
    41         prtfmt( os, "%hhu", c );
     40ostype * ?|?( ostype * os, unsigned char c ) {
     41        fmt( os, "%hhu", c );
    4242        sepOff( os );
    4343        return os;
     
    4545
    4646forall( dtype ostype | ostream( ostype ) )
    47 ostype * ?|?( ostype *os, short int si ) {
    48         if ( sepPrt( os ) ) prtfmt( os, "%s", sepGet( os ) );
    49         prtfmt( os, "%hd", si );
    50         return os;
    51 } // ?|?
    52 
    53 forall( dtype ostype | ostream( ostype ) )
    54 ostype * ?|?( ostype *os, unsigned short int usi ) {
    55         if ( sepPrt( os ) ) prtfmt( os, "%s", sepGet( os ) );
    56         prtfmt( os, "%hu", usi );
    57         return os;
    58 } // ?|?
    59 
    60 forall( dtype ostype | ostream( ostype ) )
    61 ostype * ?|?( ostype *os, int i ) {
    62         if ( sepPrt( os ) ) prtfmt( os, "%s", sepGet( os ) );
    63         prtfmt( os, "%d", i );
    64         return os;
    65 } // ?|?
    66 
    67 forall( dtype ostype | ostream( ostype ) )
    68 ostype * ?|?( ostype *os, unsigned int ui ) {
    69         if ( sepPrt( os ) ) prtfmt( os, "%s", sepGet( os ) );
    70         prtfmt( os, "%u", ui );
    71         return os;
    72 } // ?|?
    73 
    74 forall( dtype ostype | ostream( ostype ) )
    75 ostype * ?|?( ostype *os, long int li ) {
    76         if ( sepPrt( os ) ) prtfmt( os, "%s", sepGet( os ) );
    77         prtfmt( os, "%ld", li );
    78         return os;
    79 } // ?|?
    80 
    81 forall( dtype ostype | ostream( ostype ) )
    82 ostype * ?|?( ostype *os, unsigned long int uli ) {
    83         if ( sepPrt( os ) ) prtfmt( os, "%s", sepGet( os ) );
    84         prtfmt( os, "%lu", uli );
    85         return os;
    86 } // ?|?
    87 
    88 forall( dtype ostype | ostream( ostype ) )
    89 ostype * ?|?( ostype *os, long long int lli ) {
    90         if ( sepPrt( os ) ) prtfmt( os, "%s", sepGet( os ) );
    91         prtfmt( os, "%lld", lli );
    92         return os;
    93 } // ?|?
    94 
    95 forall( dtype ostype | ostream( ostype ) )
    96 ostype * ?|?( ostype *os, unsigned long long int ulli ) {
    97         if ( sepPrt( os ) ) prtfmt( os, "%s", sepGet( os ) );
    98         prtfmt( os, "%llu", ulli );
    99         return os;
    100 } // ?|?
    101 
    102 forall( dtype ostype | ostream( ostype ) )
    103 ostype * ?|?( ostype *os, float f ) {
    104         if ( sepPrt( os ) ) prtfmt( os, "%s", sepGet( os ) );
    105         prtfmt( os, "%g", f );
    106         return os;
    107 } // ?|?
    108 
    109 forall( dtype ostype | ostream( ostype ) )
    110 ostype * ?|?( ostype *os, double d ) {
    111         if ( sepPrt( os ) ) prtfmt( os, "%s", sepGet( os ) );
    112         prtfmt( os, "%.*lg", DBL_DIG, d );
    113         return os;
    114 } // ?|?
    115 
    116 forall( dtype ostype | ostream( ostype ) )
    117 ostype * ?|?( ostype *os, long double ld ) {
    118         if ( sepPrt( os ) ) prtfmt( os, "%s", sepGet( os ) );
    119         prtfmt( os, "%.*Lg", LDBL_DIG, ld );
    120         return os;
    121 } // ?|?
    122 
    123 forall( dtype ostype | ostream( ostype ) )
    124 ostype * ?|?( ostype *os, float _Complex fc ) {
     47ostype * ?|?( ostype * os, short int si ) {
     48        if ( sepPrt( os ) ) fmt( os, "%s", sepGetCur( os ) );
     49        fmt( os, "%hd", si );
     50        return os;
     51} // ?|?
     52
     53forall( dtype ostype | ostream( ostype ) )
     54ostype * ?|?( ostype * os, unsigned short int usi ) {
     55        if ( sepPrt( os ) ) fmt( os, "%s", sepGetCur( os ) );
     56        fmt( os, "%hu", usi );
     57        return os;
     58} // ?|?
     59
     60forall( dtype ostype | ostream( ostype ) )
     61ostype * ?|?( ostype * os, int i ) {
     62        if ( sepPrt( os ) ) fmt( os, "%s", sepGetCur( os ) );
     63        fmt( os, "%d", i );
     64        return os;
     65} // ?|?
     66
     67forall( dtype ostype | ostream( ostype ) )
     68ostype * ?|?( ostype * os, unsigned int ui ) {
     69        if ( sepPrt( os ) ) fmt( os, "%s", sepGetCur( os ) );
     70        fmt( os, "%u", ui );
     71        return os;
     72} // ?|?
     73
     74forall( dtype ostype | ostream( ostype ) )
     75ostype * ?|?( ostype * os, long int li ) {
     76        if ( sepPrt( os ) ) fmt( os, "%s", sepGetCur( os ) );
     77        fmt( os, "%ld", li );
     78        return os;
     79} // ?|?
     80
     81forall( dtype ostype | ostream( ostype ) )
     82ostype * ?|?( ostype * os, unsigned long int uli ) {
     83        if ( sepPrt( os ) ) fmt( os, "%s", sepGetCur( os ) );
     84        fmt( os, "%lu", uli );
     85        return os;
     86} // ?|?
     87
     88forall( dtype ostype | ostream( ostype ) )
     89ostype * ?|?( ostype * os, long long int lli ) {
     90        if ( sepPrt( os ) ) fmt( os, "%s", sepGetCur( os ) );
     91        fmt( os, "%lld", lli );
     92        return os;
     93} // ?|?
     94
     95forall( dtype ostype | ostream( ostype ) )
     96ostype * ?|?( ostype * os, unsigned long long int ulli ) {
     97        if ( sepPrt( os ) ) fmt( os, "%s", sepGetCur( os ) );
     98        fmt( os, "%llu", ulli );
     99        return os;
     100} // ?|?
     101
     102forall( dtype ostype | ostream( ostype ) )
     103ostype * ?|?( ostype * os, float f ) {
     104        if ( sepPrt( os ) ) fmt( os, "%s", sepGetCur( os ) );
     105        fmt( os, "%g", f );
     106        return os;
     107} // ?|?
     108
     109forall( dtype ostype | ostream( ostype ) )
     110ostype * ?|?( ostype * os, double d ) {
     111        if ( sepPrt( os ) ) fmt( os, "%s", sepGetCur( os ) );
     112        fmt( os, "%.*lg", DBL_DIG, d );
     113        return os;
     114} // ?|?
     115
     116forall( dtype ostype | ostream( ostype ) )
     117ostype * ?|?( ostype * os, long double ld ) {
     118        if ( sepPrt( os ) ) fmt( os, "%s", sepGetCur( os ) );
     119        fmt( os, "%.*Lg", LDBL_DIG, ld );
     120        return os;
     121} // ?|?
     122
     123forall( dtype ostype | ostream( ostype ) )
     124ostype * ?|?( ostype * os, float _Complex fc ) {
    125125        os | crealf( fc );
    126126        _Bool temp = sepDisable( os );                                          // disable separators within complex value
     
    132132
    133133forall( dtype ostype | ostream( ostype ) )
    134 ostype * ?|?( ostype *os, double _Complex dc ) {
     134ostype * ?|?( ostype * os, double _Complex dc ) {
    135135        os | creal( dc );
    136136        _Bool temp = sepDisable( os );                                          // disable separators within complex value
     
    142142
    143143forall( dtype ostype | ostream( ostype ) )
    144 ostype * ?|?( ostype *os, long double _Complex ldc ) {
     144ostype * ?|?( ostype * os, long double _Complex ldc ) {
    145145        os | creall( ldc );
    146146        _Bool temp = sepDisable( os );                                          // disable separators within complex value
     
    152152
    153153forall( dtype ostype | ostream( ostype ) )
    154 ostype * ?|?( ostype *os, const char *cp ) {
     154ostype * ?|?( ostype * os, const char * cp ) {
    155155        enum { Open = 1, Close, OpenClose };
    156156        static const unsigned char mask[256] = {
    157157                // opening delimiters, no space after
    158158                ['('] : Open, ['['] : Open, ['{'] : Open,
    159                 ['$'] : Open, ['='] : Open, [(unsigned char)'£'] : Open, [(unsigned char)'¥'] : Open,
     159                ['='] : Open, ['$'] : Open, [(unsigned char)'£'] : Open, [(unsigned char)'¥'] : Open,
    160160                [(unsigned char)'¡'] : Open, [(unsigned char)'¿'] : Open, [(unsigned char)'«'] : Open,
    161161                // closing delimiters, no space before
    162162                [','] : Close, ['.'] : Close, [':'] : Close, [';'] : Close, ['!'] : Close, ['?'] : Close,
     163                ['%'] : Close, [(unsigned char)'¢'] : Close, [(unsigned char)'»'] : Close,
    163164                [')'] : Close, [']'] : Close, ['}'] : Close,
    164                 ['%'] : Close, [(unsigned char)'¢'] : Close, [(unsigned char)'»'] : Close,
    165165                // opening-closing delimiters, no space before or after
    166166                ['\''] : OpenClose, ['`'] : OpenClose, ['"'] : OpenClose,
     
    173173        unsigned char ch = cp[0];                                                       // must make unsigned
    174174        if ( sepPrt( os ) && mask[ ch ] != Close && mask[ ch ] != OpenClose ) {
    175                 prtfmt( os, "%s", sepGet( os ) );
     175                fmt( os, "%s", sepGetCur( os ) );
    176176        } // if
    177177
     
    191191
    192192forall( dtype ostype | ostream( ostype ) )
    193 ostype * ?|?( ostype *os, const void *p ) {
    194         if ( sepPrt( os ) ) prtfmt( os, "%s", sepGet( os ) );
    195         prtfmt( os, "%p", p );
     193ostype * ?|?( ostype * os, const void * p ) {
     194        if ( sepPrt( os ) ) fmt( os, "%s", sepGetCur( os ) );
     195        fmt( os, "%p", p );
    196196        return os;
    197197} // ?|?
     
    201201forall( dtype ostype, otype T, ttype Params | ostream( ostype ) | writeable( T ) | { ostype * ?|?( ostype *, Params ); } )
    202202ostype * ?|?( ostype * os, T arg, Params rest ) {
    203         os | arg | ", ";
    204         os | rest;
     203        sepSetCur( os, sepGetTuple( os ) );                                     // switch to tuple separator
     204        os | arg;                                                                                       // print first argument
     205        os | rest;                                                                                      // print remaining arguments
     206        sepSetCur( os, sepGet( os ) );                                          // switch to regular separator
    205207        return os;
    206208} // ?|?
     
    217219        os | '\n';
    218220        flush( os );
    219         sepOff( os );
     221        sepOff( os );                                                                           // prepare for next line
    220222        return os;
    221223} // endl
     
    248250
    249251forall( otype elttype | writeable( elttype ), otype iteratortype | iterator( iteratortype, elttype ), dtype ostype | ostream( ostype ) )
    250 void write( iteratortype begin, iteratortype end, ostype *os ) {
     252void write( iteratortype begin, iteratortype end, ostype * os ) {
    251253        void print( elttype i ) { os | i; }
    252254        for_each( begin, end, print );
     
    254256
    255257forall( otype elttype | writeable( elttype ), otype iteratortype | iterator( iteratortype, elttype ), dtype ostype | ostream( ostype ) )
    256 void write_reverse( iteratortype begin, iteratortype end, ostype *os ) {
     258void write_reverse( iteratortype begin, iteratortype end, ostype * os ) {
    257259        void print( elttype i ) { os | i; }
    258260        for_each_reverse( begin, end, print );
     
    263265forall( dtype istype | istream( istype ) )
    264266istype * ?|?( istype * is, char * c ) {
    265         scanfmt( is, "%c", c );
     267        fmt( is, "%c", c );
    266268        return is;
    267269} // ?|?
     
    269271forall( dtype istype | istream( istype ) )
    270272istype * ?|?( istype * is, short int * si ) {
    271         scanfmt( is, "%hd", si );
     273        fmt( is, "%hd", si );
    272274        return is;
    273275} // ?|?
     
    275277forall( dtype istype | istream( istype ) )
    276278istype * ?|?( istype * is, unsigned short int * usi ) {
    277         scanfmt( is, "%hu", usi );
     279        fmt( is, "%hu", usi );
    278280        return is;
    279281} // ?|?
     
    281283forall( dtype istype | istream( istype ) )
    282284istype * ?|?( istype * is, int * i ) {
    283         scanfmt( is, "%d", i );
     285        fmt( is, "%d", i );
    284286        return is;
    285287} // ?|?
     
    287289forall( dtype istype | istream( istype ) )
    288290istype * ?|?( istype * is, unsigned int * ui ) {
    289         scanfmt( is, "%u", ui );
     291        fmt( is, "%u", ui );
    290292        return is;
    291293} // ?|?
     
    293295forall( dtype istype | istream( istype ) )
    294296istype * ?|?( istype * is, long int * li ) {
    295         scanfmt( is, "%ld", li );
     297        fmt( is, "%ld", li );
    296298        return is;
    297299} // ?|?
     
    299301forall( dtype istype | istream( istype ) )
    300302istype * ?|?( istype * is, unsigned long int * ulli ) {
    301         scanfmt( is, "%lu", ulli );
     303        fmt( is, "%lu", ulli );
    302304        return is;
    303305} // ?|?
     
    305307forall( dtype istype | istream( istype ) )
    306308istype * ?|?( istype * is, long long int * lli ) {
    307         scanfmt( is, "%lld", lli );
     309        fmt( is, "%lld", lli );
    308310        return is;
    309311} // ?|?
     
    311313forall( dtype istype | istream( istype ) )
    312314istype * ?|?( istype * is, unsigned long long int * ulli ) {
    313         scanfmt( is, "%llu", ulli );
     315        fmt( is, "%llu", ulli );
    314316        return is;
    315317} // ?|?
     
    318320forall( dtype istype | istream( istype ) )
    319321istype * ?|?( istype * is, float * f ) {
    320         scanfmt( is, "%f", f );
     322        fmt( is, "%f", f );
    321323        return is;
    322324} // ?|?
     
    324326forall( dtype istype | istream( istype ) )
    325327istype * ?|?( istype * is, double * d ) {
    326         scanfmt( is, "%lf", d );
     328        fmt( is, "%lf", d );
    327329        return is;
    328330} // ?|?
     
    330332forall( dtype istype | istream( istype ) )
    331333istype * ?|?( istype * is, long double * ld ) {
    332         scanfmt( is, "%Lf", ld );
     334        fmt( is, "%Lf", ld );
    333335        return is;
    334336} // ?|?
     
    338340istype * ?|?( istype * is, float _Complex * fc ) {
    339341        float re, im;
    340         scanfmt( is, "%g%gi", &re, &im );
     342        fmt( is, "%g%gi", &re, &im );
    341343        *fc = re + im * _Complex_I;
    342344        return is;
     
    346348istype * ?|?( istype * is, double _Complex * dc ) {
    347349        double re, im;
    348         scanfmt( is, "%lf%lfi", &re, &im );
     350        fmt( is, "%lf%lfi", &re, &im );
    349351        *dc = re + im * _Complex_I;
    350352        return is;
     
    354356istype * ?|?( istype * is, long double _Complex * ldc ) {
    355357        long double re, im;
    356         scanfmt( is, "%Lf%Lfi", &re, &im );
     358        fmt( is, "%Lf%Lfi", &re, &im );
    357359        *ldc = re + im * _Complex_I;
    358360        return is;
     
    362364forall( dtype istype | istream( istype ) )
    363365istype * ?|?( istype * is, _Istream_cstrUC cstr ) {
    364         scanfmt( is, "%s", cstr.s );
     366        fmt( is, "%s", cstr.s );
    365367        return is;
    366368} // cstr
     
    371373        char buf[16];
    372374        sprintf( buf, "%%%ds", cstr.size );
    373         scanfmt( is, buf, cstr.s );
     375        fmt( is, buf, cstr.s );
    374376        return is;
    375377} // cstr
  • src/tests/.expect/io.txt

    r9fcdfa3 rc58f4ab  
    1818abc, $xyz
    1919
    20 v(27 v[27 v{27 $27 £27 ¥27 ¡27 ¿27 «27
    21 25, 25. 25: 25; 25! 25? 25) 25] 25} 25% 25¢ 25»
     20v(27 v[27 v{27 $27 =27 £27 ¥27 ¡27 ¿27 «27
     2125, 25. 25: 25; 25! 25? 25% 25¢ 25» 25) 25] 25}
    222225'27 25`27 25"27 25 27 25
    232327 25
     
    252527 25   27 25
    262627
     273, 4, a, 7.2
     283, 4, a, 7.2
     293 4 a 7.2
     30 3 4 a 7.234a7.2 3 4 a 7.2
     313-4-a-7.2^3^4-3-4-a-7.2
  • src/tests/Makefile.am

    r9fcdfa3 rc58f4ab  
    5151        @+python test.py --list --concurrent=${concurrent}
    5252
     53.dummy : .dummy.c
     54        ${CC} ${CFLAGS} -XCFA -n ${<} -o ${@}
     55
    5356constant0-1DP : constant0-1.c
    5457        ${CC} ${CFLAGS} -DDUPS ${<} -o ${@}
  • src/tests/Makefile.in

    r9fcdfa3 rc58f4ab  
    669669        @+python test.py --list --concurrent=${concurrent}
    670670
     671.dummy : .dummy.c
     672        ${CC} ${CFLAGS} -XCFA -n ${<} -o ${@}
     673
    671674constant0-1DP : constant0-1.c
    672675        ${CC} ${CFLAGS} -DDUPS ${<} -o ${@}
  • src/tests/io.c

    r9fcdfa3 rc58f4ab  
    1010// Created On       : Wed Mar  2 16:56:02 2016
    1111// Last Modified By : Peter A. Buhr
    12 // Last Modified On : Tue Jul  5 18:29:23 2016
    13 // Update Count     : 31
     12// Last Modified On : Tue Mar 21 22:36:06 2017
     13// Update Count     : 48
    1414//
    1515
     
    6262
    6363        sepSet( sout, ", $" );                                                                          // change separator, maximum of 15 characters
    64         sout | f | d | ld | endl                                                                        // floating point without separator
    65                  | fc | dc | ldc | endl                                                                 // complex without separator
     64        sout | f | d | ld | endl
     65                 | fc | dc | ldc | endl
    6666                 | s1 | s2 | endl;
    6767        sout | endl;
     
    7474                | "v{" | 27
    7575                | "$" | 27
     76                | "=" | 27
    7677                | "£" | 27
    7778                | "¥" | 27
     
    8788                | 25 | "!"
    8889                | 25 | "?"
     90                | 25 | "%"
     91                | 25 | "¢"
     92                | 25 | "»"
    8993                | 25 | ")"
    9094                | 25 | "]"
    9195                | 25 | "}"
    92                 | 25 | "%"
    93                 | 25 | "¢"
    94                 | 25 | "»"
    9596                | endl
    9697                // opening-closing delimiters
     
    105106                | 25 | "\v" | 27
    106107                | endl;
     108
     109        [int, int, const char *, double] t = { 3, 4, "a", 7.2 };
     110        sout | [ 3, 4, "a", 7.2 ] | endl;
     111        sout | t | endl;
     112        sepSetTuple( sout, " " );
     113        sout | t | endl;
     114        sout | sepOn | t | sepDisable | t | sepEnable | t | endl;
     115        sepSet( sout, "^" );
     116        sepSetTuple( sout, "-" );
     117        sout | t | 3 | 4 | t | endl;
    107118}
    108119
  • src/tests/test.py

    r9fcdfa3 rc58f4ab  
    2525# parses the Makefile to find the machine type (32-bit / 64-bit)
    2626def getMachineType():
    27         sh('echo "int main() { return 0; }" > .dummy.c')
     27        sh('echo "void ?{}(int*a,int b){}int main(){return 0;}" > .dummy.c')
    2828        sh("make .dummy", print2stdout=False)
    2929        _, out = sh("file .dummy", print2stdout=False)
Note: See TracChangeset for help on using the changeset viewer.