Changes in / [c41c2dbe:341aa39]


Ignore:
Files:
9 edited

Legend:

Unmodified
Added
Removed
  • doc/user/user.tex

    rc41c2dbe r341aa39  
    1111%% Created On       : Wed Apr  6 14:53:29 2016
    1212%% Last Modified By : Peter A. Buhr
    13 %% Last Modified On : Tue Apr 20 23:25:56 2021
    14 %% Update Count     : 4888
     13%% Last Modified On : Sat Mar 27 09:55:55 2021
     14%% Update Count     : 4796
    1515%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
    1616
     
    6666% math escape $...$ (dollar symbol)
    6767\input{common}                                          % common CFA document macros
    68 \setlength{\gcolumnposn}{3in}
    6968\CFAStyle                                                                                               % use default CFA format-style
    7069\lstset{language=CFA}                                                                   % CFA default lnaguage
     
    21672166\section{Enumeration}
    21682167
    2169 An \newterm{enumeration} is a compile-time mechanism to alias names to constants, like ©typedef© is a mechanism to alias names to types.
    2170 Its purpose is to define a restricted-value type providing code-readability and maintenance -- changing an enum's value automatically updates all name usages during compilation.
    2171 
    2172 An enumeration type is a set of names, each called an \newterm{enumeration constant} (shortened to \newterm{enum}) aliased to a fixed value (constant).
    2173 \begin{cfa}
    2174 enum Days { Mon, Tue, Wed, Thu, Fri, Sat, Sun }; // enumeration type definition, set of 7 names & values
     2168An \newterm{enumeration} is a compile-time mechanism to give names to constants.
     2169There is no runtime manifestation of an enumeration.
     2170Their purpose is code-readability and maintenance -- changing an enum's value automatically updates all name usages during compilation.
     2171
     2172An enumeration defines a type containing a set of names, each called an \newterm{enumeration constant} (shortened to \newterm{enum}) with a fixed (©const©) value.
     2173\begin{cfa}
     2174enum Days { Mon, Tue, Wed, Thu, Fri, Sat, Sun }; // enumeration type definition, set of 7 names
    21752175Days days = Mon; // enumeration type declaration and initialization
    21762176\end{cfa}
    2177 The set of enums are injected into the variable namespace at the definition scope.
     2177The set of enums are injected into the scope of the definition and use the variable namespace.
    21782178Hence, enums may be overloaded with enum/variable/function names.
    21792179\begin{cfa}
     
    21832183double Bar;                     $\C{// overload Foo.Bar, Goo.Bar}\CRT$
    21842184\end{cfa}
    2185 An anonymous enumeration injects enums with specific values into a scope.
     2185An anonymous enumeration is used to inject enums with specific values into a scope:
    21862186\begin{cfa}
    21872187enum { Prime = 103, BufferSize = 1024 };
    21882188\end{cfa}
    2189 An enumeration is better than using C \Index{preprocessor} or constant declarations.
    2190 \begin{cquote}
    2191 \begin{tabular}{@{}l@{\hspace{4em}}l@{}}
     2189An enumeration is better than using the C \Index{preprocessor}
    21922190\begin{cfa}
    21932191#define Mon 0
     
    21952193#define Sun 6
    21962194\end{cfa}
    2197 &
    2198 \begin{cfa}
    2199 const int Mon = 0,
    2200                          ...,
    2201                          Sun = 6;
    2202 \end{cfa}
    2203 \end{tabular}
    2204 \end{cquote}
     2195or C constant declarations
     2196\begin{cfa}
     2197const int Mon = 0, ..., Sun = 6;
     2198\end{cfa}
    22052199because the enumeration is succinct, has automatic numbering, can appear in ©case© labels, does not use storage, and is part of the language type-system.
    22062200Finally, the type of an enum is implicitly or explicitly specified and the constant value can be implicitly or explicitly specified.
     
    22102204\subsection{Enum type}
    22112205
    2212 The type of enums can be any type, and an enum's value comes from this type.
    2213 Because an enum is a constant, it cannot appear in a mutable context, \eg ©Mon = Sun© is disallowed, and has no address (it is an rvalue).
    2214 Therefore, an enum is automatically converted to its constant's base-type, \eg comparing/printing an enum compares/prints its value rather than the enum name;
    2215 there is no mechanism to print the enum name.
    2216 
     2206While an enumeration defines a new set-type of names, its underlying enums can be any ©const© type, and an enum's value comes from this type.
     2207\CFA provides an automatic conversion from an enum to its base type, \eg comparing/printing an enum compares/prints its value rather than the enum name.
    22172208The default enum type is ©int©.
    22182209Hence, ©Days© is the set type ©Mon©, ©Tue©, ...\,, ©Sun©, while the type of each enum is ©int© and each enum represents a fixed integral value.
    22192210If no values are specified for an integral enum type, the enums are automatically numbered by one from left to right starting at zero.
    22202211Hence, the value of enum ©Mon© is 0, ©Tue© is 1, ...\,, ©Sun© is 6.
    2221 If an enum value is specified, numbering continues by one from that value for subsequent unnumbered enums.
    2222 If an enum value is an expression, the compiler performs constant-folding to obtain a constant value.
    2223 
    2224 \CFA allows other integral types with associated values.
     2212If a value is specified, numbering continues by one from that value.
     2213It an enum value is an expression, the compiler performs constant-folding to obtain a constant value.
     2214
     2215Other integral types with associated values can be explicitly specified.
    22252216\begin{cfa}
    22262217enum( @char@ ) Letter { A @= 'A'@,  B,  C,  I @= 'I'@,  J,  K };
     
    22282219\end{cfa}
    22292220For enumeration ©Letter©, enum ©A©'s value is explicitly set to ©'A'©, with ©B© and ©C© implicitly numbered with increasing values from ©'A'©, and similarly for enums ©I©, ©J©, and ©K©.
    2230 
    2231 Non-integral enum types must be explicitly initialized, \eg ©double© is not automatically numbered by one.
     2221Note, an enum is an immutable constant, \ie ©A = B© is disallowed;
     2222by transitivity, an enum's type is implicitly ©const©.
     2223Hence, a constant/enum cannot appear in a mutuable context nor is a constant/enum addressable (rvalue).
     2224
     2225Non-integral enum types have the restriction that all enums \emph{must} be explicitly specified, \ie incrementing by one for the next enum is not done even if supported by the enum type, \eg ©double©.
    22322226\begin{cfa}
    22332227// non-integral numeric
    2234 enum( @double@ ) Math { PI_2 = 1.570796, PI = 3.141597,  E = 2.718282 }
     2228enum( double ) Math { PI_2 = 1.570796, PI = 3.141597,  E = 2.718282 }
    22352229// pointer
    2236 enum( @char *@ ) Name { Fred = "Fred",  Mary = "Mary",  Jane = "Jane" };
     2230enum( char * ) Name { Fred = "Fred",  Mary = "Mary",  Jane = "Jane" };
    22372231int i, j, k;
    2238 enum( @int *@ ) ptr { I = &i,  J = &j,  K = &k };
    2239 enum( @int &@ ) ref { I = i,  J = j,  K = k };
     2232enum( int * ) ptr { I = &i,  J = &j,  K = &k };
     2233enum( int & ) ref { I = i,  J = j,  K = k };
    22402234// tuple
    2241 enum( @[int, int]@ ) { T = [ 1, 2 ] };
     2235enum( [int, int] ) { T = [ 1, 2 ] };
    22422236// function
    22432237void f() {...}   void g() {...}
    2244 enum( @void (*)()@ ) funs { F = f,  F = g };
     2238enum( void (*)() ) funs { F = f,  F = g };
    22452239// aggregate
    22462240struct S { int i, j; };
    2247 enum( @S@ ) s { A = { 3,  4 }, B = { 7,  8 } };
     2241enum( S ) s { A = { 3,  4 }, B = { 7,  8 } };
    22482242// enumeration
    2249 enum( @Letter@ ) Greek { Alph = A, Beta = B, /* more enums */  }; // alphabet intersection
     2243enum( Letter ) Greek { Alph = A, Beta = B, /* more enums */  }; // alphabet intersection
    22502244\end{cfa}
    22512245Enumeration ©Greek© may have more or less enums than ©Letter©, but the enum values \emph{must} be from ©Letter©.
     
    22592253m = Alph;               $\C{// {\color{red}disallowed}}$
    22602254m = 3.141597;   $\C{// {\color{red}disallowed}}$
    2261 d = m;                  $\C{// allowed}$
     2255d = E;                  $\C{// allowed, conversion to base type}$
     2256d = m;                  $\C{// {\color{red}disallowed}}$
    22622257d = Alph;               $\C{// {\color{red}disallowed}}$
    22632258Letter l = A;   $\C{// allowed}$
     
    22682263
    22692264A constructor \emph{cannot} be used to initialize enums because a constructor executes at runtime.
    2270 A fallback is explicit C-style initialization using ©@=©.
    2271 \begin{cfa}
    2272 enum( struct vec3 ) Axis { Up $@$= { 1, 0, 0 }, Left $@$= { 0, 1, 0 }, Front $@$= { 0, 0, 1 } }
     2265A fallback is to substitute C-style initialization overriding the constructor with ©@=©.
     2266\begin{cfa}
     2267enum( struct vec3 ) Axis { Up $@$= { 1, 0, 0 }, Left $@$= ..., Front $@$= ... }
    22732268\end{cfa}
    22742269Finally, enumeration variables are assignable and comparable only if the appropriate operators are defined for its enum type.
     
    22792274\Index{Plan-9}\index{inheritance!enumeration} inheritance may be used with enumerations.
    22802275\begin{cfa}
    2281 enum( char * ) Name2 { @inline Name@, Jack = "Jack", Jill = "Jill" };
    2282 enum @/* inferred */@  Name3 { @inline Name2@, Sue = "Sue", Tom = "Tom" };
     2276enum( const char * ) Name2 { @inline Name@, Jack = "Jack", Jill = "Jill" };
     2277enum @/* inferred */@  Name3 { @inline Name@, @inline Name2@, Sue = "Sue", Tom = "Tom" };
    22832278\end{cfa}
    22842279Enumeration ©Name2© inherits all the enums and their values from enumeration ©Name© by containment, and a ©Name© enumeration is a subtype of enumeration ©Name2©.
     
    22862281The enum type for the inheriting type must be the same as the inherited type;
    22872282hence the enum type may be omitted for the inheriting enumeration and it is inferred from the inherited enumeration, as for ©Name3©.
    2288 When inheriting from integral types, automatic numbering may be used, so the inheritance placement left to right is important, \eg the placement of ©Sue© and ©Tom© before or after ©inline Name2©.
     2283When inheriting from integral types, automatic numbering may be used, so the inheritance placement left to right is important.
    22892284
    22902285Specifically, the inheritance relationship for ©Name©s is:
     
    23062301j( Fred );    j( Jill );    j( Sue );    j( 'W' );
    23072302\end{cfa}
    2308 Note, the validity of calls is the same for call-by-reference as for call-by-value, and ©const© restrictions are the same as for other types.
     2303Note, the validity of calls is the same for call by reference as for call by value, and ©const© restrictions are the same as for other types.
    23092304
    23102305Enums cannot be created at runtime, so inheritence problems, such as contra-variance do not apply.
     
    23182313\begin{cfa}
    23192314// Fred is a subset of char *
    2320 enum( char *) Fred { A = "A", B = "B", C = "C" };
     2315enum char * Fred { A = "A", B = "B", C = "C" };
    23212316// Jack is a subset of Fred
    2322 enum( enum Fred ) Jack { W = A, Y = C};
     2317enum enum Fred Jack { W = A, Y = C};
    23232318// Mary is a superset of Fred
    23242319enum Mary { inline Fred, D = "hello" };
     
    41734168
    41744169The format of numeric input values in the same as C constants without a trailing type suffix, as the input value-type is denoted by the input variable.
    4175 For ©bool© type, the constants are ©true© and ©false©.
     4170For ©_Bool© type, the constants are ©true© and ©false©.
    41764171For integral types, any number of digits, optionally preceded by a sign (©+© or ©-©), where a
    41774172\begin{itemize}
     
    45854580In C, the integer constants 0 and 1 suffice because the integer promotion rules can convert them to any arithmetic type, and the rules for pointer expressions treat constant expressions evaluating to 0 as a special case.
    45864581However, user-defined arithmetic types often need the equivalent of a 1 or 0 for their functions or operators, polymorphic functions often need 0 and 1 constants of a type matching their polymorphic parameters, and user-defined pointer-like types may need a null value.
    4587 Defining special constants for a user-defined type is more efficient than defining a conversion to the type from ©bool©.
     4582Defining special constants for a user-defined type is more efficient than defining a conversion to the type from ©_Bool©.
    45884583
    45894584Why just 0 and 1? Why not other integers? No other integers have special status in C.
     
    50505045\begin{figure}
    50515046\begin{cfa}
    5052 #include <fstream.hfa>
    5053 #include @<coroutine.hfa>@
    5054 
    5055 @coroutine@ Fibonacci {
     5047#include <fstream>
     5048#include <coroutine>
     5049
     5050coroutine Fibonacci {
    50565051        int fn; $\C{// used for communication}$
    50575052};
    5058 
    5059 void main( Fibonacci & fib ) with( fib ) { $\C{// called on first resume}$
     5053void ?{}( Fibonacci * this ) {
     5054        this->fn = 0;
     5055}
     5056void main( Fibonacci * this ) {
    50605057        int fn1, fn2; $\C{// retained between resumes}$
    5061         fn = 0;  fn1 = fn; $\C{// 1st case}$
    5062         @suspend;@ $\C{// restart last resume}$
    5063         fn = 1;  fn2 = fn1;  fn1 = fn; $\C{// 2nd case}$
    5064         @suspend;@ $\C{// restart last resume}$
    5065         for () {
    5066                 fn = fn1 + fn2;  fn2 = fn1;  fn1 = fn; $\C{// general case}$
    5067                 @suspend;@ $\C{// restart last resume}$
    5068         }
    5069 }
    5070 int next( Fibonacci & fib ) with( fib ) {
    5071         @resume( fib );@ $\C{// restart last suspend}$
    5072         return fn;
     5058        this->fn = 0; $\C{// case 0}$
     5059        fn1 = this->fn;
     5060        suspend(); $\C{// return to last resume}$
     5061
     5062        this->fn = 1; $\C{// case 1}$
     5063        fn2 = fn1;
     5064        fn1 = this->fn;
     5065        suspend(); $\C{// return to last resume}$
     5066
     5067        for ( ;; ) { $\C{// general case}$
     5068                this->fn = fn1 + fn2;
     5069                fn2 = fn1;
     5070                fn1 = this->fn;
     5071                suspend(); $\C{// return to last resume}$
     5072        } // for
     5073}
     5074int next( Fibonacci * this ) {
     5075        resume( this ); $\C{// transfer to last suspend}$
     5076        return this->fn;
    50735077}
    50745078int main() {
    50755079        Fibonacci f1, f2;
    5076         for ( 10 ) { $\C{// print N Fibonacci values}$
    5077                 sout | next( f1 ) | next( f2 );
    5078         }
    5079 }
    5080 \end{cfa}
    5081 \vspace*{-5pt}
     5080        for ( int i = 1; i <= 10; i += 1 ) {
     5081                sout | next( &f1 ) | ' ' | next( &f2 );
     5082        } // for
     5083}
     5084\end{cfa}
    50825085\caption{Fibonacci Coroutine}
    50835086\label{f:FibonacciCoroutine}
     
    51055108\begin{figure}
    51065109\begin{cfa}
    5107 #include <fstream.hfa>
    5108 #include @<thread.hfa>@
    5109 
    5110 @monitor@ AtomicCnt { int counter; };
    5111 void ?{}( AtomicCnt & c, int init = 0 ) with(c) { counter = init; }
    5112 int inc( AtomicCnt & @mutex@ c, int inc = 1 ) with(c) { return counter += inc; }
    5113 int dec( AtomicCnt & @mutex@ c, int dec = 1 ) with(c) { return counter -= dec; }
    5114 forall( ostype & | ostream( ostype ) ) { $\C{// print any stream}$
    5115         ostype & ?|?( ostype & os, AtomicCnt c ) { return os | c.counter; }
    5116         void ?|?( ostype & os, AtomicCnt c ) { (ostype &)(os | c.counter); ends( os ); }
    5117 }
    5118 
    5119 AtomicCnt global; $\C{// shared}$
     5110#include <fstream>
     5111#include <kernel>
     5112#include <monitor>
     5113#include <thread>
     5114
     5115monitor global_t {
     5116        int value;
     5117};
     5118
     5119void ?{}(global_t * this) {
     5120        this->value = 0;
     5121}
     5122
     5123static global_t global;
     5124
     5125void increment3( global_t * mutex this ) {
     5126        this->value += 1;
     5127}
     5128void increment2( global_t * mutex this ) {
     5129        increment3( this );
     5130}
     5131void increment( global_t * mutex this ) {
     5132        increment2( this );
     5133}
    51205134
    51215135thread MyThread {};
    5122 void main( MyThread & ) {
    5123         for ( i; 100_000 ) {
    5124                 inc( global );
    5125                 dec( global );
     5136
     5137void main( MyThread* this ) {
     5138        for(int i = 0; i < 1_000_000; i++) {
     5139                increment( &global );
    51265140        }
    51275141}
    5128 int main() {
    5129         enum { Threads = 4 };
    5130         processor p[Threads - 1]; $\C{// + starting processor}$
     5142int main(int argc, char* argv[]) {
     5143        processor p;
    51315144        {
    5132                 MyThread t[Threads];
     5145                MyThread f[4];
    51335146        }
    5134         sout | global; $\C{// print 0}$
     5147        sout | global.value;
    51355148}
    51365149\end{cfa}
    51375150\caption{Atomic-Counter Monitor}
    5138 \label{f:AtomicCounterMonitor}
     5151\caption{f:AtomicCounterMonitor}
    51395152\end{figure}
    51405153
     
    73077320[ int, long double ] remquo( long double, long double );
    73087321
     7322float div( float, float, int * );$\indexc{div}$ $\C{// alternative name for remquo}$
     7323double div( double, double, int * );
     7324long double div( long double, long double, int * );
    73097325[ int, float ] div( float, float );
    73107326[ int, double ] div( double, double );
     
    73677383long double _Complex log( long double _Complex );
    73687384
    7369 int log2( unsigned int );$\indexc{log2}$
    7370 long int log2( unsigned long int );
    7371 long long int log2( unsigned long long int )
    7372 float log2( float );
     7385float log2( float );$\indexc{log2}$
    73737386double log2( double );
    73747387long double log2( long double );
     
    75527565\leavevmode
    75537566\begin{cfa}[aboveskip=0pt,belowskip=0pt]
    7554 // n / align * align
    7555 signed char floor( signed char n, signed char align );
    7556 unsigned char floor( unsigned char n, unsigned char align );
    7557 short int floor( short int n, short int align );
    7558 unsigned short int floor( unsigned short int n, unsigned short int align );
    7559 int floor( int n, int align );
    7560 unsigned int floor( unsigned int n, unsigned int align );
    7561 long int floor( long int n, long int align );
    7562 unsigned long int floor( unsigned long int n, unsigned long int align );
    7563 long long int floor( long long int n, long long int align );
    7564 unsigned long long int floor( unsigned long long int n, unsigned long long int align );
    7565 
    7566 // (n + (align - 1)) / align
    7567 signed char ceiling_div( signed char n, char align );
    7568 unsigned char ceiling_div( unsigned char n, unsigned char align );
    7569 short int ceiling_div( short int n, short int align );
    7570 unsigned short int ceiling_div( unsigned short int n, unsigned short int align );
    7571 int ceiling_div( int n, int align );
    7572 unsigned int ceiling_div( unsigned int n, unsigned int align );
    7573 long int ceiling_div( long int n, long int align );
    7574 unsigned long int ceiling_div( unsigned long int n, unsigned long int align );
    7575 long long int ceiling_div( long long int n, long long int align );
    7576 unsigned long long int ceiling_div( unsigned long long int n, unsigned long long int align );
    7577 
    7578 // floor( n + (n % align != 0 ? align - 1 : 0), align )
    7579 signed char ceiling( signed char n, signed char align );
    7580 unsigned char ceiling( unsigned char n, unsigned char align );
    7581 short int ceiling( short int n, short int align );
    7582 unsigned short int ceiling( unsigned short int n, unsigned short int align );
    7583 int ceiling( int n, int align );
    7584 unsigned int ceiling( unsigned int n, unsigned int align );
    7585 long int ceiling( long int n, long int align );
    7586 unsigned long int ceiling( unsigned long int n, unsigned long int align );
    7587 long long int ceiling( long long int n, long long int align );
    7588 unsigned long long int ceiling( unsigned long long int n, unsigned long long int align );
    7589 
    75907567float floor( float );$\indexc{floor}$
    75917568double floor( double );
     
    76907667\begin{cfa}[aboveskip=0pt,belowskip=0pt]
    76917668struct Duration {
    7692         int64_t tn; $\C{// nanoseconds}$
     7669        int64_t tv; $\C{// nanoseconds}$
    76937670};
    76947671
    76957672void ?{}( Duration & dur );
    76967673void ?{}( Duration & dur, zero_t );
    7697 void ?{}( Duration & dur, timeval t )
    7698 void ?{}( Duration & dur, timespec t )
    76997674
    77007675Duration ?=?( Duration & dur, zero_t );
    7701 Duration ?=?( Duration & dur, timeval t )
    7702 Duration ?=?( Duration & dur, timespec t )
    77037676
    77047677Duration +?( Duration rhs );
     
    77227695Duration ?%=?( Duration & lhs, Duration rhs );
    77237696
    7724 bool ?==?( Duration lhs, zero_t );
    7725 bool ?!=?( Duration lhs, zero_t );
    7726 bool ?<? ( Duration lhs, zero_t );
    7727 bool ?<=?( Duration lhs, zero_t );
    7728 bool ?>? ( Duration lhs, zero_t );
    7729 bool ?>=?( Duration lhs, zero_t );
    7730 
    7731 bool ?==?( Duration lhs, Duration rhs );
    7732 bool ?!=?( Duration lhs, Duration rhs );
    7733 bool ?<? ( Duration lhs, Duration rhs );
    7734 bool ?<=?( Duration lhs, Duration rhs );
    7735 bool ?>? ( Duration lhs, Duration rhs );
    7736 bool ?>=?( Duration lhs, Duration rhs );
     7697_Bool ?==?( Duration lhs, Duration rhs );
     7698_Bool ?!=?( Duration lhs, Duration rhs );
     7699_Bool ?<? ( Duration lhs, Duration rhs );
     7700_Bool ?<=?( Duration lhs, Duration rhs );
     7701_Bool ?>? ( Duration lhs, Duration rhs );
     7702_Bool ?>=?( Duration lhs, Duration rhs );
     7703
     7704_Bool ?==?( Duration lhs, zero_t );
     7705_Bool ?!=?( Duration lhs, zero_t );
     7706_Bool ?<? ( Duration lhs, zero_t );
     7707_Bool ?<=?( Duration lhs, zero_t );
     7708_Bool ?>? ( Duration lhs, zero_t );
     7709_Bool ?>=?( Duration lhs, zero_t );
    77377710
    77387711Duration abs( Duration rhs );
     
    77617734int64_t ?`w( Duration dur );
    77627735
    7763 double ?`dns( Duration dur );
    7764 double ?`dus( Duration dur );
    7765 double ?`dms( Duration dur );
    7766 double ?`ds( Duration dur );
    7767 double ?`dm( Duration dur );
    7768 double ?`dh( Duration dur );
    7769 double ?`dd( Duration dur );
    7770 double ?`dw( Duration dur );
    7771 
    77727736Duration max( Duration lhs, Duration rhs );
    77737737Duration min( Duration lhs, Duration rhs );
    7774 
    7775 forall( ostype & | ostream( ostype ) ) ostype & ?|?( ostype & os, Duration dur );
    77767738\end{cfa}
    77777739
     
    77847746\begin{cfa}[aboveskip=0pt,belowskip=0pt]
    77857747void ?{}( timeval & t );
    7786 void ?{}( timeval & t, zero_t );
    77877748void ?{}( timeval & t, time_t sec, suseconds_t usec );
    77887749void ?{}( timeval & t, time_t sec );
     7750void ?{}( timeval & t, zero_t );
    77897751void ?{}( timeval & t, Time time );
    77907752
     
    77927754timeval ?+?( timeval & lhs, timeval rhs );
    77937755timeval ?-?( timeval & lhs, timeval rhs );
    7794 bool ?==?( timeval lhs, timeval rhs );
    7795 bool ?!=?( timeval lhs, timeval rhs );
     7756_Bool ?==?( timeval lhs, timeval rhs );
     7757_Bool ?!=?( timeval lhs, timeval rhs );
    77967758\end{cfa}
    77977759
     
    78047766\begin{cfa}[aboveskip=0pt,belowskip=0pt]
    78057767void ?{}( timespec & t );
    7806 void ?{}( timespec & t, zero_t );
    78077768void ?{}( timespec & t, time_t sec, __syscall_slong_t nsec );
    78087769void ?{}( timespec & t, time_t sec );
     7770void ?{}( timespec & t, zero_t );
    78097771void ?{}( timespec & t, Time time );
    78107772
     
    78127774timespec ?+?( timespec & lhs, timespec rhs );
    78137775timespec ?-?( timespec & lhs, timespec rhs );
    7814 bool ?==?( timespec lhs, timespec rhs );
    7815 bool ?!=?( timespec lhs, timespec rhs );
     7776_Bool ?==?( timespec lhs, timespec rhs );
     7777_Bool ?!=?( timespec lhs, timespec rhs );
    78167778\end{cfa}
    78177779
     
    78357797\begin{cfa}[aboveskip=0pt,belowskip=0pt]
    78367798struct Time {
    7837         uint64_t tn; $\C{// nanoseconds since UNIX epoch}$
     7799        uint64_t tv; $\C{// nanoseconds since UNIX epoch}$
    78387800};
    78397801
    78407802void ?{}( Time & time );
    78417803void ?{}( Time & time, zero_t );
     7804
     7805Time ?=?( Time & time, zero_t );
     7806
    78427807void ?{}( Time & time, timeval t );
     7808Time ?=?( Time & time, timeval t );
     7809
    78437810void ?{}( Time & time, timespec t );
    7844 
    7845 Time ?=?( Time & time, zero_t );
    7846 Time ?=?( Time & time, timeval t );
    78477811Time ?=?( Time & time, timespec t );
    78487812
     
    78547818Time ?-?( Time lhs, Duration rhs );
    78557819Time ?-=?( Time & lhs, Duration rhs );
    7856 bool ?==?( Time lhs, Time rhs );
    7857 bool ?!=?( Time lhs, Time rhs );
    7858 bool ?<?( Time lhs, Time rhs );
    7859 bool ?<=?( Time lhs, Time rhs );
    7860 bool ?>?( Time lhs, Time rhs );
    7861 bool ?>=?( Time lhs, Time rhs );
    7862 
    7863 int64_t ?`ns( Time t );
     7820_Bool ?==?( Time lhs, Time rhs );
     7821_Bool ?!=?( Time lhs, Time rhs );
     7822_Bool ?<?( Time lhs, Time rhs );
     7823_Bool ?<=?( Time lhs, Time rhs );
     7824_Bool ?>?( Time lhs, Time rhs );
     7825_Bool ?>=?( Time lhs, Time rhs );
    78647826
    78657827char * yy_mm_dd( Time time, char * buf );
    7866 char * ?`ymd( Time time, char * buf ); // short form
     7828char * ?`ymd( Time time, char * buf ) { // short form
     7829        return yy_mm_dd( time, buf );
     7830} // ymd
    78677831
    78687832char * mm_dd_yy( Time time, char * buf );
    7869 char * ?`mdy( Time time, char * buf ); // short form
     7833char * ?`mdy( Time time, char * buf ) { // short form
     7834        return mm_dd_yy( time, buf );
     7835} // mdy
    78707836
    78717837char * dd_mm_yy( Time time, char * buf );
    7872 char * ?`dmy( Time time, char * buf ); // short form
     7838char * ?`dmy( Time time, char * buf ) { // short form
     7839        return dd_mm_yy( time, buf );;
     7840} // dmy
    78737841
    78747842size_t strftime( char * buf, size_t size, const char * fmt, Time time );
    7875 
    7876 forall( ostype & | ostream( ostype ) ) ostype & ?|?( ostype & os, Time time );
     7843forall( dtype ostype | ostream( ostype ) ) ostype & ?|?( ostype & os, Time time );
    78777844\end{cfa}
    78787845
     
    79007867\leavevmode
    79017868\begin{cfa}[aboveskip=0pt,belowskip=0pt]
    7902 struct Clock { $\C{// virtual clock}$
    7903         Duration offset; $\C{// offset from computer real-time}$
     7869struct Clock {
     7870        Duration offset; $\C{// for virtual clock: contains offset from real-time}$
     7871        int clocktype; $\C{// implementation only -1 (virtual), CLOCK\_REALTIME}$
    79047872};
    79057873
    7906 void ?{}( Clock & clk ); $\C{// create no offset}$
    7907 void ?{}( Clock & clk, Duration adj ); $\C{// create with offset}$
    7908 void reset( Clock & clk, Duration adj ); $\C{// change offset}$
    7909 
    7910 Duration resolutionHi(); $\C{// clock resolution in nanoseconds (fine)}$
    7911 Duration resolution(); $\C{// clock resolution without nanoseconds (coarse)}$
    7912 
    7913 Time timeHiRes(); $\C{// real time with nanoseconds}$
    7914 Time time(); $\C{// real time without nanoseconds}$
    7915 Time time( Clock & clk ); $\C{// real time for given clock}$
    7916 Time ?()( Clock & clk ); $\C{//\ \ \ \ alternative syntax}$
    7917 timeval time( Clock & clk ); $\C{// convert to C time format}$
    7918 tm time( Clock & clk );
    7919 Duration processor(); $\C{// non-monotonic duration of kernel thread}$
    7920 Duration program(); $\C{// non-monotonic duration of program CPU}$
    7921 Duration boot(); $\C{// monotonic duration since computer boot}$
     7874void resetClock( Clock & clk );
     7875void resetClock( Clock & clk, Duration adj );
     7876void ?{}( Clock & clk );
     7877void ?{}( Clock & clk, Duration adj );
     7878
     7879Duration getResNsec(); $\C{// with nanoseconds}$
     7880Duration getRes(); $\C{// without nanoseconds}$
     7881
     7882Time getTimeNsec(); $\C{// with nanoseconds}$
     7883Time getTime(); $\C{// without nanoseconds}$
     7884Time getTime( Clock & clk );
     7885Time ?()( Clock & clk );
     7886timeval getTime( Clock & clk );
     7887tm getTime( Clock & clk );
    79227888\end{cfa}
    79237889
     
    80908056forall( dtype ostype | ostream( ostype ) ) ostype * ?|?( ostype * os, Int mp );
    80918057\end{cfa}
    8092 \VRef[Figure]{f:MultiPrecisionFactorials} shows \CFA and C factorial programs using the GMP interfaces.
     8058
     8059The following factorial programs contrast using GMP with the \CFA and C interfaces, where the output from these programs appears in \VRef[Figure]{f:MultiPrecisionFactorials}.
    80938060(Compile with flag \Indexc{-lgmp} to link with the GMP library.)
    8094 
    8095 \begin{figure}
    80968061\begin{cquote}
    80978062\begin{tabular}{@{}l@{\hspace{\parindentlnth}}|@{\hspace{\parindentlnth}}l@{}}
    8098 \multicolumn{1}{@{}c|@{\hspace{\parindentlnth}}}{\textbf{\CFA}} & \multicolumn{1}{@{\hspace{\parindentlnth}}c}{\textbf{C}@{}}   \\
     8063\multicolumn{1}{c|@{\hspace{\parindentlnth}}}{\textbf{\CFA}}    & \multicolumn{1}{@{\hspace{\parindentlnth}}c}{\textbf{C}}      \\
    80998064\hline
    81008065\begin{cfa}
     
    81058070
    81068071        sout | 0 | fact;
    8107         for ( i; 40 ) {
     8072        for ( unsigned int i = 1; i <= 40; i += 1 ) {
    81088073                fact *= i;
    81098074                sout | i | fact;
     
    81278092\end{tabular}
    81288093\end{cquote}
    8129 \small
     8094
     8095\begin{figure}
    81308096\begin{cfa}
    81318097Factorial Numbers
  • libcfa/src/fstream.cfa

    rc41c2dbe r341aa39  
    1010// Created On       : Wed May 27 17:56:53 2015
    1111// Last Modified By : Peter A. Buhr
    12 // Last Modified On : Tue Apr 20 19:04:46 2021
    13 // Update Count     : 425
     12// Last Modified On : Mon Mar  1 21:12:15 2021
     13// Update Count     : 424
    1414//
    1515
     
    3131
    3232void ?{}( ofstream & os, void * file ) {
    33         os.file$ = file;
    34         os.sepDefault$ = true;
    35         os.sepOnOff$ = false;
    36         os.nlOnOff$ = true;
    37         os.prt$ = false;
    38         os.sawNL$ = false;
    39         os.acquired$ = false;
    40         sepSetCur$( os, sepGet( os ) );
     33        os.$file = file;
     34        os.$sepDefault = true;
     35        os.$sepOnOff = false;
     36        os.$nlOnOff = true;
     37        os.$prt = false;
     38        os.$sawNL = false;
     39        os.$acquired = false;
     40        $sepSetCur( os, sepGet( os ) );
    4141        sepSet( os, " " );
    4242        sepSetTuple( os, ", " );
     
    4444
    4545// private
    46 bool sepPrt$( ofstream & os ) { setNL$( os, false ); return os.sepOnOff$; }
    47 void sepReset$( ofstream & os ) { os.sepOnOff$ = os.sepDefault$; }
    48 void sepReset$( ofstream & os, bool reset ) { os.sepDefault$ = reset; os.sepOnOff$ = os.sepDefault$; }
    49 const char * sepGetCur$( ofstream & os ) { return os.sepCur$; }
    50 void sepSetCur$( ofstream & os, const char sepCur[] ) { os.sepCur$ = sepCur; }
    51 bool getNL$( ofstream & os ) { return os.sawNL$; }
    52 void setNL$( ofstream & os, bool state ) { os.sawNL$ = state; }
    53 bool getANL$( ofstream & os ) { return os.nlOnOff$; }
    54 bool getPrt$( ofstream & os ) { return os.prt$; }
    55 void setPrt$( ofstream & os, bool state ) { os.prt$ = state; }
     46bool $sepPrt( ofstream & os ) { $setNL( os, false ); return os.$sepOnOff; }
     47void $sepReset( ofstream & os ) { os.$sepOnOff = os.$sepDefault; }
     48void $sepReset( ofstream & os, bool reset ) { os.$sepDefault = reset; os.$sepOnOff = os.$sepDefault; }
     49const char * $sepGetCur( ofstream & os ) { return os.$sepCur; }
     50void $sepSetCur( ofstream & os, const char sepCur[] ) { os.$sepCur = sepCur; }
     51bool $getNL( ofstream & os ) { return os.$sawNL; }
     52void $setNL( ofstream & os, bool state ) { os.$sawNL = state; }
     53bool $getANL( ofstream & os ) { return os.$nlOnOff; }
     54bool $getPrt( ofstream & os ) { return os.$prt; }
     55void $setPrt( ofstream & os, bool state ) { os.$prt = state; }
    5656
    5757// public
    58 void ?{}( ofstream & os ) { os.file$ = 0p; }
     58void ?{}( ofstream & os ) { os.$file = 0p; }
    5959
    6060void ?{}( ofstream & os, const char name[], const char mode[] ) {
     
    7070} // ^?{}
    7171
    72 void sepOn( ofstream & os ) { os.sepOnOff$ = ! getNL$( os ); }
    73 void sepOff( ofstream & os ) { os.sepOnOff$ = false; }
     72void sepOn( ofstream & os ) { os.$sepOnOff = ! $getNL( os ); }
     73void sepOff( ofstream & os ) { os.$sepOnOff = false; }
    7474
    7575bool sepDisable( ofstream & os ) {
    76         bool temp = os.sepDefault$;
    77         os.sepDefault$ = false;
    78         sepReset$( os );
     76        bool temp = os.$sepDefault;
     77        os.$sepDefault = false;
     78        $sepReset( os );
    7979        return temp;
    8080} // sepDisable
    8181
    8282bool sepEnable( ofstream & os ) {
    83         bool temp = os.sepDefault$;
    84         os.sepDefault$ = true;
    85         if ( os.sepOnOff$ ) sepReset$( os );                            // start of line ?
     83        bool temp = os.$sepDefault;
     84        os.$sepDefault = true;
     85        if ( os.$sepOnOff ) $sepReset( os );                            // start of line ?
    8686        return temp;
    8787} // sepEnable
    8888
    89 void nlOn( ofstream & os ) { os.nlOnOff$ = true; }
    90 void nlOff( ofstream & os ) { os.nlOnOff$ = false; }
    91 
    92 const char * sepGet( ofstream & os ) { return os.separator$; }
     89void nlOn( ofstream & os ) { os.$nlOnOff = true; }
     90void nlOff( ofstream & os ) { os.$nlOnOff = false; }
     91
     92const char * sepGet( ofstream & os ) { return os.$separator; }
    9393void sepSet( ofstream & os, const char s[] ) {
    9494        assert( s );
    95         strncpy( os.separator$, s, sepSize - 1 );
    96         os.separator$[sepSize - 1] = '\0';
     95        strncpy( os.$separator, s, sepSize - 1 );
     96        os.$separator[sepSize - 1] = '\0';
    9797} // sepSet
    9898
    99 const char * sepGetTuple( ofstream & os ) { return os.tupleSeparator$; }
     99const char * sepGetTuple( ofstream & os ) { return os.$tupleSeparator; }
    100100void sepSetTuple( ofstream & os, const char s[] ) {
    101101        assert( s );
    102         strncpy( os.tupleSeparator$, s, sepSize - 1 );
    103         os.tupleSeparator$[sepSize - 1] = '\0';
     102        strncpy( os.$tupleSeparator, s, sepSize - 1 );
     103        os.$tupleSeparator[sepSize - 1] = '\0';
    104104} // sepSet
    105105
    106106void ends( ofstream & os ) {
    107         if ( getANL$( os ) ) nl( os );
    108         else setPrt$( os, false );                                                      // turn off
     107        if ( $getANL( os ) ) nl( os );
     108        else $setPrt( os, false );                                                      // turn off
    109109        if ( &os == &exit ) exit( EXIT_FAILURE );
    110110        if ( &os == &abort ) abort();
    111         if ( os.acquired$ ) { os.acquired$ = false; release( os ); }
     111        if ( os.$acquired ) { os.$acquired = false; release( os ); }
    112112} // ends
    113113
    114114int fail( ofstream & os ) {
    115         return os.file$ == 0 || ferror( (FILE *)(os.file$) );
     115        return os.$file == 0 || ferror( (FILE *)(os.$file) );
    116116} // fail
    117117
    118118int flush( ofstream & os ) {
    119         return fflush( (FILE *)(os.file$) );
     119        return fflush( (FILE *)(os.$file) );
    120120} // flush
    121121
     
    136136
    137137void close( ofstream & os ) {
    138   if ( (FILE *)(os.file$) == 0p ) return;
    139   if ( (FILE *)(os.file$) == (FILE *)stdout || (FILE *)(os.file$) == (FILE *)stderr ) return;
    140 
    141         if ( fclose( (FILE *)(os.file$) ) == EOF ) {
     138  if ( (FILE *)(os.$file) == 0p ) return;
     139  if ( (FILE *)(os.$file) == (FILE *)stdout || (FILE *)(os.$file) == (FILE *)stderr ) return;
     140
     141        if ( fclose( (FILE *)(os.$file) ) == EOF ) {
    142142                abort | IO_MSG "close output" | nl | strerror( errno );
    143143        } // if
    144         os.file$ = 0p;
     144        os.$file = 0p;
    145145} // close
    146146
     
    150150        } // if
    151151
    152         if ( fwrite( data, 1, size, (FILE *)(os.file$) ) != size ) {
     152        if ( fwrite( data, 1, size, (FILE *)(os.$file) ) != size ) {
    153153                abort | IO_MSG "write" | nl | strerror( errno );
    154154        } // if
     
    159159        va_list args;
    160160        va_start( args, format );
    161         int len = vfprintf( (FILE *)(os.file$), format, args );
     161        int len = vfprintf( (FILE *)(os.$file), format, args );
    162162        if ( len == EOF ) {
    163                 if ( ferror( (FILE *)(os.file$) ) ) {
     163                if ( ferror( (FILE *)(os.$file) ) ) {
    164164                        abort | IO_MSG "invalid write";
    165165                } // if
     
    167167        va_end( args );
    168168
    169         setPrt$( os, true );                                                            // called in output cascade
    170         sepReset$( os );                                                                        // reset separator
     169        $setPrt( os, true );                                                            // called in output cascade
     170        $sepReset( os );                                                                        // reset separator
    171171        return len;
    172172} // fmt
    173173
    174174inline void acquire( ofstream & os ) {
    175         lock( os.lock$ );
    176         if ( ! os.acquired$ ) os.acquired$ = true;
    177         else unlock( os.lock$ );
     175        lock( os.$lock );
     176        if ( ! os.$acquired ) os.$acquired = true;
     177        else unlock( os.$lock );
    178178} // acquire
    179179
    180180inline void release( ofstream & os ) {
    181         unlock( os.lock$ );
     181        unlock( os.$lock );
    182182} // release
    183183
    184 void ?{}( osacquire & acq, ofstream & os ) { &acq.os = &os; lock( os.lock$ ); }
     184void ?{}( osacquire & acq, ofstream & os ) { &acq.os = &os; lock( os.$lock ); }
    185185void ^?{}( osacquire & acq ) { release( acq.os ); }
    186186
     
    204204// private
    205205void ?{}( ifstream & is, void * file ) {
    206         is.file$ = file;
    207         is.nlOnOff$ = false;
    208         is.acquired$ = false;
     206        is.$file = file;
     207        is.$nlOnOff = false;
     208        is.$acquired = false;
    209209} // ?{}
    210210
    211211// public
    212 void ?{}( ifstream & is ) { is.file$ = 0p; }
     212void ?{}( ifstream & is ) { is.$file = 0p; }
    213213
    214214void ?{}( ifstream & is, const char name[], const char mode[] ) {
     
    224224} // ^?{}
    225225
    226 void nlOn( ifstream & os ) { os.nlOnOff$ = true; }
    227 void nlOff( ifstream & os ) { os.nlOnOff$ = false; }
    228 bool getANL( ifstream & os ) { return os.nlOnOff$; }
     226void nlOn( ifstream & os ) { os.$nlOnOff = true; }
     227void nlOff( ifstream & os ) { os.$nlOnOff = false; }
     228bool getANL( ifstream & os ) { return os.$nlOnOff; }
    229229
    230230int fail( ifstream & is ) {
    231         return is.file$ == 0p || ferror( (FILE *)(is.file$) );
     231        return is.$file == 0p || ferror( (FILE *)(is.$file) );
    232232} // fail
    233233
    234234void ends( ifstream & is ) {
    235         if ( is.acquired$ ) { is.acquired$ = false; release( is ); }
     235        if ( is.$acquired ) { is.$acquired = false; release( is ); }
    236236} // ends
    237237
    238238int eof( ifstream & is ) {
    239         return feof( (FILE *)(is.file$) );
     239        return feof( (FILE *)(is.$file) );
    240240} // eof
    241241
     
    248248        } // if
    249249        #endif // __CFA_DEBUG__
    250         is.file$ = file;
     250        is.$file = file;
    251251} // open
    252252
     
    256256
    257257void close( ifstream & is ) {
    258   if ( (FILE *)(is.file$) == 0p ) return;
    259   if ( (FILE *)(is.file$) == (FILE *)stdin ) return;
    260 
    261         if ( fclose( (FILE *)(is.file$) ) == EOF ) {
     258  if ( (FILE *)(is.$file) == 0p ) return;
     259  if ( (FILE *)(is.$file) == (FILE *)stdin ) return;
     260
     261        if ( fclose( (FILE *)(is.$file) ) == EOF ) {
    262262                abort | IO_MSG "close input" | nl | strerror( errno );
    263263        } // if
    264         is.file$ = 0p;
     264        is.$file = 0p;
    265265} // close
    266266
     
    270270        } // if
    271271
    272         if ( fread( data, size, 1, (FILE *)(is.file$) ) == 0 ) {
     272        if ( fread( data, size, 1, (FILE *)(is.$file) ) == 0 ) {
    273273                abort | IO_MSG "read" | nl | strerror( errno );
    274274        } // if
     
    281281        } // if
    282282
    283         if ( ungetc( c, (FILE *)(is.file$) ) == EOF ) {
     283        if ( ungetc( c, (FILE *)(is.$file) ) == EOF ) {
    284284                abort | IO_MSG "ungetc" | nl | strerror( errno );
    285285        } // if
     
    291291
    292292        va_start( args, format );
    293         int len = vfscanf( (FILE *)(is.file$), format, args );
     293        int len = vfscanf( (FILE *)(is.$file), format, args );
    294294        if ( len == EOF ) {
    295                 if ( ferror( (FILE *)(is.file$) ) ) {
     295                if ( ferror( (FILE *)(is.$file) ) ) {
    296296                        abort | IO_MSG "invalid read";
    297297                } // if
     
    302302
    303303inline void acquire( ifstream & is ) {
    304         lock( is.lock$ );
    305         if ( ! is.acquired$ ) is.acquired$ = true;
    306         else unlock( is.lock$ );
     304        lock( is.$lock );
     305        if ( ! is.$acquired ) is.$acquired = true;
     306        else unlock( is.$lock );
    307307} // acquire
    308308
    309309inline void release( ifstream & is ) {
    310         unlock( is.lock$ );
     310        unlock( is.$lock );
    311311} // release
    312312
    313 void ?{}( isacquire & acq, ifstream & is ) { &acq.is = &is; lock( is.lock$ ); }
     313void ?{}( isacquire & acq, ifstream & is ) { &acq.is = &is; lock( is.$lock ); }
    314314void ^?{}( isacquire & acq ) { release( acq.is ); }
    315315
  • libcfa/src/fstream.hfa

    rc41c2dbe r341aa39  
    1010// Created On       : Wed May 27 17:56:53 2015
    1111// Last Modified By : Peter A. Buhr
    12 // Last Modified On : Tue Apr 20 19:04:12 2021
    13 // Update Count     : 218
     12// Last Modified On : Mon Mar  1 22:45:08 2021
     13// Update Count     : 217
    1414//
    1515
     
    2626enum { sepSize = 16 };
    2727struct ofstream {
    28         void * file$;
    29         bool sepDefault$;
    30         bool sepOnOff$;
    31         bool nlOnOff$;
    32         bool prt$;                                                                                      // print text
    33         bool sawNL$;
    34         const char * sepCur$;
    35         char separator$[sepSize];
    36         char tupleSeparator$[sepSize];
    37         multiple_acquisition_lock lock$;
    38         bool acquired$;
     28        void * $file;
     29        bool $sepDefault;
     30        bool $sepOnOff;
     31        bool $nlOnOff;
     32        bool $prt;                                                                                      // print text
     33        bool $sawNL;
     34        const char * $sepCur;
     35        char $separator[sepSize];
     36        char $tupleSeparator[sepSize];
     37        multiple_acquisition_lock $lock;
     38        bool $acquired;
    3939}; // ofstream
    4040
    4141// private
    42 bool sepPrt$( ofstream & );
    43 void sepReset$( ofstream & );
    44 void sepReset$( ofstream &, bool );
    45 const char * sepGetCur$( ofstream & );
    46 void sepSetCur$( ofstream &, const char [] );
    47 bool getNL$( ofstream & );
    48 void setNL$( ofstream &, bool );
    49 bool getANL$( ofstream & );
    50 bool getPrt$( ofstream & );
    51 void setPrt$( ofstream &, bool );
     42bool $sepPrt( ofstream & );
     43void $sepReset( ofstream & );
     44void $sepReset( ofstream &, bool );
     45const char * $sepGetCur( ofstream & );
     46void $sepSetCur( ofstream &, const char [] );
     47bool $getNL( ofstream & );
     48void $setNL( ofstream &, bool );
     49bool $getANL( ofstream & );
     50bool $getPrt( ofstream & );
     51void $setPrt( ofstream &, bool );
    5252
    5353// public
     
    9494
    9595struct ifstream {
    96         void * file$;
    97         bool nlOnOff$;
    98         multiple_acquisition_lock lock$;
    99         bool acquired$;
     96        void * $file;
     97        bool $nlOnOff;
     98        multiple_acquisition_lock $lock;
     99        bool $acquired;
    100100}; // ifstream
    101101
  • libcfa/src/gmp.hfa

    rc41c2dbe r341aa39  
    1010// Created On       : Tue Apr 19 08:43:43 2016
    1111// Last Modified By : Peter A. Buhr
    12 // Last Modified On : Tue Apr 20 20:59:21 2021
    13 // Update Count     : 32
     12// Last Modified On : Sun Feb  9 09:56:54 2020
     13// Update Count     : 31
    1414//
    1515
     
    263263        forall( ostype & | ostream( ostype ) ) {
    264264                ostype & ?|?( ostype & os, Int mp ) {
    265                         if ( sepPrt$( os ) ) fmt( os, "%s", sepGetCur$( os ) );
     265                        if ( $sepPrt( os ) ) fmt( os, "%s", $sepGetCur( os ) );
    266266                        gmp_printf( "%Zd", mp.mpz );
    267267                        sepOn( os );
  • libcfa/src/heap.cfa

    rc41c2dbe r341aa39  
    1010// Created On       : Tue Dec 19 21:58:35 2017
    1111// Last Modified By : Peter A. Buhr
    12 // Last Modified On : Tue Apr 20 21:20:48 2021
    13 // Update Count     : 1033
     12// Last Modified On : Sun Mar 14 10:39:24 2021
     13// Update Count     : 1032
    1414//
    1515
     
    11281128
    11291129        // Set the alignment for an the allocation and return previous alignment or 0 if no alignment.
    1130         size_t malloc_alignment_set$( void * addr, size_t alignment ) {
     1130        size_t $malloc_alignment_set( void * addr, size_t alignment ) {
    11311131          if ( unlikely( addr == 0p ) ) return libAlign();      // minimum alignment
    11321132                size_t ret;
     
    11391139                } // if
    11401140                return ret;
    1141         } // malloc_alignment_set$
     1141        } // $malloc_alignment_set
    11421142
    11431143
     
    11531153
    11541154        // Set allocation is zero filled and return previous zero filled.
    1155         bool malloc_zero_fill_set$( void * addr ) {
     1155        bool $malloc_zero_fill_set( void * addr ) {
    11561156          if ( unlikely( addr == 0p ) ) return false;           // null allocation is not zero fill
    11571157                HeapManager.Storage.Header * header = headerAddr( addr );
     
    11621162                header->kind.real.blockSize |= 2;                               // mark as zero filled
    11631163                return ret;
    1164         } // malloc_zero_fill_set$
     1164        } // $malloc_zero_fill_set
    11651165
    11661166
     
    11761176
    11771177        // Set allocation size and return previous size.
    1178         size_t malloc_size_set$( void * addr, size_t size ) {
     1178        size_t $malloc_size_set( void * addr, size_t size ) {
    11791179          if ( unlikely( addr == 0p ) ) return 0;                       // null allocation has 0 size
    11801180                HeapManager.Storage.Header * header = headerAddr( addr );
     
    11851185                header->kind.real.size = size;
    11861186                return ret;
    1187         } // malloc_size_set$
     1187        } // $malloc_size_set
    11881188
    11891189
  • libcfa/src/iostream.cfa

    rc41c2dbe r341aa39  
    1010// Created On       : Wed May 27 17:56:53 2015
    1111// Last Modified By : Peter A. Buhr
    12 // Last Modified On : Tue Apr 20 19:09:41 2021
    13 // Update Count     : 1325
     12// Last Modified On : Tue Apr 13 13:05:24 2021
     13// Update Count     : 1324
    1414//
    1515
     
    3838forall( ostype & | ostream( ostype ) ) {
    3939        ostype & ?|?( ostype & os, bool b ) {
    40                 if ( sepPrt$( os ) ) fmt( os, "%s", sepGetCur$( os ) );
     40                if ( $sepPrt( os ) ) fmt( os, "%s", $sepGetCur( os ) );
    4141                fmt( os, "%s", b ? "true" : "false" );
    4242                return os;
     
    4848        ostype & ?|?( ostype & os, char c ) {
    4949                fmt( os, "%c", c );
    50                 if ( c == '\n' ) setNL$( os, true );
     50                if ( c == '\n' ) $setNL( os, true );
    5151                return sepOff( os );
    5252        } // ?|?
     
    5656
    5757        ostype & ?|?( ostype & os, signed char sc ) {
    58                 if ( sepPrt$( os ) ) fmt( os, "%s", sepGetCur$( os ) );
     58                if ( $sepPrt( os ) ) fmt( os, "%s", $sepGetCur( os ) );
    5959                fmt( os, "%hhd", sc );
    6060                return os;
     
    6565
    6666        ostype & ?|?( ostype & os, unsigned char usc ) {
    67                 if ( sepPrt$( os ) ) fmt( os, "%s", sepGetCur$( os ) );
     67                if ( $sepPrt( os ) ) fmt( os, "%s", $sepGetCur( os ) );
    6868                fmt( os, "%hhu", usc );
    6969                return os;
     
    7474
    7575        ostype & ?|?( ostype & os, short int si ) {
    76                 if ( sepPrt$( os ) ) fmt( os, "%s", sepGetCur$( os ) );
     76                if ( $sepPrt( os ) ) fmt( os, "%s", $sepGetCur( os ) );
    7777                fmt( os, "%hd", si );
    7878                return os;
     
    8383
    8484        ostype & ?|?( ostype & os, unsigned short int usi ) {
    85                 if ( sepPrt$( os ) ) fmt( os, "%s", sepGetCur$( os ) );
     85                if ( $sepPrt( os ) ) fmt( os, "%s", $sepGetCur( os ) );
    8686                fmt( os, "%hu", usi );
    8787                return os;
     
    9292
    9393        ostype & ?|?( ostype & os, int i ) {
    94                 if ( sepPrt$( os ) ) fmt( os, "%s", sepGetCur$( os ) );
     94                if ( $sepPrt( os ) ) fmt( os, "%s", $sepGetCur( os ) );
    9595                fmt( os, "%d", i );
    9696                return os;
     
    101101
    102102        ostype & ?|?( ostype & os, unsigned int ui ) {
    103                 if ( sepPrt$( os ) ) fmt( os, "%s", sepGetCur$( os ) );
     103                if ( $sepPrt( os ) ) fmt( os, "%s", $sepGetCur( os ) );
    104104                fmt( os, "%u", ui );
    105105                return os;
     
    110110
    111111        ostype & ?|?( ostype & os, long int li ) {
    112                 if ( sepPrt$( os ) ) fmt( os, "%s", sepGetCur$( os ) );
     112                if ( $sepPrt( os ) ) fmt( os, "%s", $sepGetCur( os ) );
    113113                fmt( os, "%ld", li );
    114114                return os;
     
    119119
    120120        ostype & ?|?( ostype & os, unsigned long int uli ) {
    121                 if ( sepPrt$( os ) ) fmt( os, "%s", sepGetCur$( os ) );
     121                if ( $sepPrt( os ) ) fmt( os, "%s", $sepGetCur( os ) );
    122122                fmt( os, "%lu", uli );
    123123                return os;
     
    128128
    129129        ostype & ?|?( ostype & os, long long int lli ) {
    130                 if ( sepPrt$( os ) ) fmt( os, "%s", sepGetCur$( os ) );
     130                if ( $sepPrt( os ) ) fmt( os, "%s", $sepGetCur( os ) );
    131131                fmt( os, "%lld", lli );
    132132                return os;
     
    137137
    138138        ostype & ?|?( ostype & os, unsigned long long int ulli ) {
    139                 if ( sepPrt$( os ) ) fmt( os, "%s", sepGetCur$( os ) );
     139                if ( $sepPrt( os ) ) fmt( os, "%s", $sepGetCur( os ) );
    140140                fmt( os, "%llu", ulli );
    141141                return os;
     
    171171
    172172        ostype & ?|?( ostype & os, int128 llli ) {
    173                 if ( sepPrt$( os ) ) fmt( os, "%s", sepGetCur$( os ) );
     173                if ( $sepPrt( os ) ) fmt( os, "%s", $sepGetCur( os ) );
    174174                base10_128( os, llli );
    175175                return os;
     
    180180
    181181        ostype & ?|?( ostype & os, unsigned int128 ullli ) {
    182                 if ( sepPrt$( os ) ) fmt( os, "%s", sepGetCur$( os ) );
     182                if ( $sepPrt( os ) ) fmt( os, "%s", $sepGetCur( os ) );
    183183                base10_128( os, ullli );
    184184                return os;
     
    204204
    205205        ostype & ?|?( ostype & os, float f ) {
    206                 if ( sepPrt$( os ) ) fmt( os, "%s", sepGetCur$( os ) );
     206                if ( $sepPrt( os ) ) fmt( os, "%s", $sepGetCur( os ) );
    207207                PrintWithDP( os, "%g", f );
    208208                return os;
     
    213213
    214214        ostype & ?|?( ostype & os, double d ) {
    215                 if ( sepPrt$( os ) ) fmt( os, "%s", sepGetCur$( os ) );
     215                if ( $sepPrt( os ) ) fmt( os, "%s", $sepGetCur( os ) );
    216216                PrintWithDP( os, "%.*lg", d, DBL_DIG );
    217217                return os;
     
    222222
    223223        ostype & ?|?( ostype & os, long double ld ) {
    224                 if ( sepPrt$( os ) ) fmt( os, "%s", sepGetCur$( os ) );
     224                if ( $sepPrt( os ) ) fmt( os, "%s", $sepGetCur( os ) );
    225225                PrintWithDP( os, "%.*Lg", ld, LDBL_DIG );
    226226                return os;
     
    231231
    232232        ostype & ?|?( ostype & os, float _Complex fc ) {
    233                 if ( sepPrt$( os ) ) fmt( os, "%s", sepGetCur$( os ) );
     233                if ( $sepPrt( os ) ) fmt( os, "%s", $sepGetCur( os ) );
    234234//              os | crealf( fc ) | nonl;
    235235                PrintWithDP( os, "%g", crealf( fc ) );
     
    243243
    244244        ostype & ?|?( ostype & os, double _Complex dc ) {
    245                 if ( sepPrt$( os ) ) fmt( os, "%s", sepGetCur$( os ) );
     245                if ( $sepPrt( os ) ) fmt( os, "%s", $sepGetCur( os ) );
    246246//              os | creal( dc ) | nonl;
    247247                PrintWithDP( os, "%.*lg", creal( dc ), DBL_DIG );
     
    255255
    256256        ostype & ?|?( ostype & os, long double _Complex ldc ) {
    257                 if ( sepPrt$( os ) ) fmt( os, "%s", sepGetCur$( os ) );
     257                if ( $sepPrt( os ) ) fmt( os, "%s", $sepGetCur( os ) );
    258258//              os | creall( ldc ) || nonl;
    259259                PrintWithDP( os, "%.*Lg", creall( ldc ), LDBL_DIG );
     
    286286                // first character IS NOT spacing or closing punctuation => add left separator
    287287                unsigned char ch = s[0];                                                // must make unsigned
    288                 if ( sepPrt$( os ) && mask[ ch ] != Close && mask[ ch ] != OpenClose ) {
    289                         fmt( os, "%s", sepGetCur$( os ) );
     288                if ( $sepPrt( os ) && mask[ ch ] != Close && mask[ ch ] != OpenClose ) {
     289                        fmt( os, "%s", $sepGetCur( os ) );
    290290                } // if
    291291
    292292                // if string starts line, must reset to determine open state because separator is off
    293                 sepReset$( os );                                                                // reset separator
     293                $sepReset( os );                                                                // reset separator
    294294
    295295                // last character IS spacing or opening punctuation => turn off separator for next item
    296296                size_t len = strlen( s );
    297297                ch = s[len - 1];                                                                // must make unsigned
    298                 if ( sepPrt$( os ) && mask[ ch ] != Open && mask[ ch ] != OpenClose ) {
     298                if ( $sepPrt( os ) && mask[ ch ] != Open && mask[ ch ] != OpenClose ) {
    299299                        sepOn( os );
    300300                } else {
    301301                        sepOff( os );
    302302                } // if
    303                 if ( ch == '\n' ) setNL$( os, true );                   // check *AFTER* sepPrt$ call above as it resets NL flag
     303                if ( ch == '\n' ) $setNL( os, true );                   // check *AFTER* $sepPrt call above as it resets NL flag
    304304                return write( os, s, len );
    305305        } // ?|?
     
    309309
    310310//      ostype & ?|?( ostype & os, const char16_t * s ) {
    311 //              if ( sepPrt$( os ) ) fmt( os, "%s", sepGetCur$( os ) );
     311//              if ( $sepPrt( os ) ) fmt( os, "%s", $sepGetCur( os ) );
    312312//              fmt( os, "%ls", s );
    313313//              return os;
     
    316316// #if ! ( __ARM_ARCH_ISA_ARM == 1 && __ARM_32BIT_STATE == 1 ) // char32_t == wchar_t => ambiguous
    317317//      ostype & ?|?( ostype & os, const char32_t * s ) {
    318 //              if ( sepPrt$( os ) ) fmt( os, "%s", sepGetCur$( os ) );
     318//              if ( $sepPrt( os ) ) fmt( os, "%s", $sepGetCur( os ) );
    319319//              fmt( os, "%ls", s );
    320320//              return os;
     
    323323
    324324//      ostype & ?|?( ostype & os, const wchar_t * s ) {
    325 //              if ( sepPrt$( os ) ) fmt( os, "%s", sepGetCur$( os ) );
     325//              if ( $sepPrt( os ) ) fmt( os, "%s", $sepGetCur( os ) );
    326326//              fmt( os, "%ls", s );
    327327//              return os;
     
    329329
    330330        ostype & ?|?( ostype & os, const void * p ) {
    331                 if ( sepPrt$( os ) ) fmt( os, "%s", sepGetCur$( os ) );
     331                if ( $sepPrt( os ) ) fmt( os, "%s", $sepGetCur( os ) );
    332332                fmt( os, "%p", p );
    333333                return os;
     
    343343        void ?|?( ostype & os, ostype & (* manip)( ostype & ) ) {
    344344                manip( os );
    345                 if ( getPrt$( os ) ) ends( os );                                // something printed ?
    346                 setPrt$( os, false );                                                   // turn off
     345                if ( $getPrt( os ) ) ends( os );                                // something printed ?
     346                $setPrt( os, false );                                                   // turn off
    347347        } // ?|?
    348348
     
    357357        ostype & nl( ostype & os ) {
    358358                (ostype &)(os | '\n');
    359                 setPrt$( os, false );                                                   // turn off
    360                 setNL$( os, true );
     359                $setPrt( os, false );                                                   // turn off
     360                $setNL( os, true );
    361361                flush( os );
    362362                return sepOff( os );                                                    // prepare for next line
     
    364364
    365365        ostype & nonl( ostype & os ) {
    366                 setPrt$( os, false );                                                   // turn off
     366                $setPrt( os, false );                                                   // turn off
    367367                return os;
    368368        } // nonl
     
    408408        ostype & ?|?( ostype & os, T arg, Params rest ) {
    409409                (ostype &)(os | arg);                                                   // print first argument
    410                 sepSetCur$( os, sepGetTuple( os ) );                    // switch to tuple separator
     410                $sepSetCur( os, sepGetTuple( os ) );                    // switch to tuple separator
    411411                (ostype &)(os | rest);                                                  // print remaining arguments
    412                 sepSetCur$( os, sepGet( os ) );                                 // switch to regular separator
     412                $sepSetCur( os, sepGet( os ) );                                 // switch to regular separator
    413413                return os;
    414414        } // ?|?
     
    416416                // (ostype &)(?|?( os, arg, rest )); ends( os );
    417417                (ostype &)(os | arg);                                                   // print first argument
    418                 sepSetCur$( os, sepGetTuple( os ) );                    // switch to tuple separator
     418                $sepSetCur( os, sepGetTuple( os ) );                    // switch to tuple separator
    419419                (ostype &)(os | rest);                                                  // print remaining arguments
    420                 sepSetCur$( os, sepGet( os ) );                                 // switch to regular separator
     420                $sepSetCur( os, sepGet( os ) );                                 // switch to regular separator
    421421                ends( os );
    422422        } // ?|?
     
    447447forall( ostype & | ostream( ostype ) ) { \
    448448        ostype & ?|?( ostype & os, _Ostream_Manip(T) f ) { \
    449                 if ( sepPrt$( os ) ) fmt( os, "%s", sepGetCur$( os ) ); \
     449                if ( $sepPrt( os ) ) fmt( os, "%s", $sepGetCur( os ) ); \
    450450\
    451451                if ( f.base == 'b' || f.base == 'B' ) {                 /* bespoke binary format */ \
     
    691691                int bufbeg = 0, i, len; \
    692692\
    693                 if ( sepPrt$( os ) ) fmt( os, "%s", sepGetCur$( os ) ); \
     693                if ( $sepPrt( os ) ) fmt( os, "%s", $sepGetCur( os ) ); \
    694694                char fmtstr[sizeof(DFMTP) + 8];                                 /* sizeof includes '\0' */ \
    695695                if ( ! f.flags.pc ) memcpy( &fmtstr, DFMTNP, sizeof(DFMTNP) ); \
     
    734734                } // if
    735735
    736                 if ( sepPrt$( os ) ) fmt( os, "%s", sepGetCur$( os ) );
     736                if ( $sepPrt( os ) ) fmt( os, "%s", $sepGetCur( os ) );
    737737
    738738                #define CFMTNP "% * "
     
    772772                } // if
    773773
    774                 if ( sepPrt$( os ) ) fmt( os, "%s", sepGetCur$( os ) );
     774                if ( $sepPrt( os ) ) fmt( os, "%s", $sepGetCur( os ) );
    775775
    776776                #define SFMTNP "% * "
  • libcfa/src/iostream.hfa

    rc41c2dbe r341aa39  
    1010// Created On       : Wed May 27 17:56:53 2015
    1111// Last Modified By : Peter A. Buhr
    12 // Last Modified On : Tue Apr 20 19:09:44 2021
    13 // Update Count     : 385
     12// Last Modified On : Tue Apr 13 13:05:11 2021
     13// Update Count     : 384
    1414//
    1515
     
    2424trait ostream( ostype & ) {
    2525        // private
    26         bool sepPrt$( ostype & );                                                       // get separator state (on/off)
    27         void sepReset$( ostype & );                                                     // set separator state to default state
    28         void sepReset$( ostype &, bool );                                       // set separator and default state
    29         const char * sepGetCur$( ostype & );                            // get current separator string
    30         void sepSetCur$( ostype &, const char [] );                     // set current separator string
    31         bool getNL$( ostype & );                                                        // check newline
    32         void setNL$( ostype &, bool );                                          // saw newline
    33         bool getANL$( ostype & );                                                       // get auto newline (on/off)
    34         bool getPrt$( ostype & );                                                       // get fmt called in output cascade
    35         void setPrt$( ostype &, bool );                                         // set fmt called in output cascade
     26        bool $sepPrt( ostype & );                                                       // get separator state (on/off)
     27        void $sepReset( ostype & );                                                     // set separator state to default state
     28        void $sepReset( ostype &, bool );                                       // set separator and default state
     29        const char * $sepGetCur( ostype & );                            // get current separator string
     30        void $sepSetCur( ostype &, const char [] );                     // set current separator string
     31        bool $getNL( ostype & );                                                        // check newline
     32        void $setNL( ostype &, bool );                                          // saw newline
     33        bool $getANL( ostype & );                                                       // get auto newline (on/off)
     34        bool $getPrt( ostype & );                                                       // get fmt called in output cascade
     35        void $setPrt( ostype &, bool );                                         // set fmt called in output cascade
    3636        // public
    3737        void sepOn( ostype & );                                                         // turn separator state on
  • libcfa/src/stdlib.hfa

    rc41c2dbe r341aa39  
    1010// Created On       : Thu Jan 28 17:12:35 2016
    1111// Last Modified By : Peter A. Buhr
    12 // Last Modified On : Tue Apr 20 21:20:03 2021
    13 // Update Count     : 575
     12// Last Modified On : Thu Jan 21 22:02:13 2021
     13// Update Count     : 574
    1414//
    1515
     
    4444
    4545// Macro because of returns
    46 #define ARRAY_ALLOC$( allocation, alignment, dim ) \
     46#define $ARRAY_ALLOC( allocation, alignment, dim ) \
    4747        if ( _Alignof(T) <= libAlign() ) return (T *)(void *)allocation( dim, (size_t)sizeof(T) ); /* C allocation */ \
    4848        else return (T *)alignment( _Alignof(T), dim, sizeof(T) )
     
    5757
    5858        T * aalloc( size_t dim ) {
    59                 ARRAY_ALLOC$( aalloc, amemalign, dim );
     59                $ARRAY_ALLOC( aalloc, amemalign, dim );
    6060        } // aalloc
    6161
    6262        T * calloc( size_t dim ) {
    63                 ARRAY_ALLOC$( calloc, cmemalign, dim );
     63                $ARRAY_ALLOC( calloc, cmemalign, dim );
    6464        } // calloc
    6565
     
    119119                S_fill(T) ?`fill( T    a[], size_t nmemb )      { S_fill(T) ret = {'a', nmemb}; ret.fill.a = a; return ret; }
    120120
    121         3. Replace the alloc_internal$ function which is outside ttype forall-block with following function:
    122                 T * alloc_internal$( void * Resize, T * Realloc, size_t Align, size_t Dim, S_fill(T) Fill) {
     121        3. Replace the $alloc_internal function which is outside ttype forall-block with following function:
     122                T * $alloc_internal( void * Resize, T * Realloc, size_t Align, size_t Dim, S_fill(T) Fill) {
    123123                        T * ptr = NULL;
    124124                        size_t size = sizeof(T);
     
    145145
    146146                        return ptr;
    147                 } // alloc_internal$
     147                } // $alloc_internal
    148148*/
    149149
     
    175175        S_realloc(T)    ?`realloc ( T * a )                             { return (S_realloc(T)){a}; }
    176176
    177         T * alloc_internal$( void * Resize, T * Realloc, size_t Align, size_t Dim, S_fill(T) Fill ) {
     177        T * $alloc_internal( void * Resize, T * Realloc, size_t Align, size_t Dim, S_fill(T) Fill ) {
    178178                T * ptr = NULL;
    179179                size_t size = sizeof(T);
     
    206206
    207207                return ptr;
    208         } // alloc_internal$
    209 
    210         forall( TT... | { T * alloc_internal$( void *, T *, size_t, size_t, S_fill(T), TT ); } ) {
    211 
    212                 T * alloc_internal$( void *       , T * Realloc, size_t Align, size_t Dim, S_fill(T) Fill, T_resize Resize, TT rest) {
    213                 return alloc_internal$( Resize, (T*)0p, Align, Dim, Fill, rest);
    214                 }
    215 
    216                 T * alloc_internal$( void * Resize, T *        , size_t Align, size_t Dim, S_fill(T) Fill, S_realloc(T) Realloc, TT rest) {
    217                 return alloc_internal$( (void*)0p, Realloc, Align, Dim, Fill, rest);
    218                 }
    219 
    220                 T * alloc_internal$( void * Resize, T * Realloc, size_t      , size_t Dim, S_fill(T) Fill, T_align Align, TT rest) {
    221                 return alloc_internal$( Resize, Realloc, Align, Dim, Fill, rest);
    222                 }
    223 
    224                 T * alloc_internal$( void * Resize, T * Realloc, size_t Align, size_t Dim, S_fill(T)     , S_fill(T) Fill, TT rest) {
    225                 return alloc_internal$( Resize, Realloc, Align, Dim, Fill, rest);
     208        } // $alloc_internal
     209
     210        forall( TT... | { T * $alloc_internal( void *, T *, size_t, size_t, S_fill(T), TT ); } ) {
     211
     212                T * $alloc_internal( void *       , T * Realloc, size_t Align, size_t Dim, S_fill(T) Fill, T_resize Resize, TT rest) {
     213                return $alloc_internal( Resize, (T*)0p, Align, Dim, Fill, rest);
     214                }
     215
     216                T * $alloc_internal( void * Resize, T *        , size_t Align, size_t Dim, S_fill(T) Fill, S_realloc(T) Realloc, TT rest) {
     217                return $alloc_internal( (void*)0p, Realloc, Align, Dim, Fill, rest);
     218                }
     219
     220                T * $alloc_internal( void * Resize, T * Realloc, size_t      , size_t Dim, S_fill(T) Fill, T_align Align, TT rest) {
     221                return $alloc_internal( Resize, Realloc, Align, Dim, Fill, rest);
     222                }
     223
     224                T * $alloc_internal( void * Resize, T * Realloc, size_t Align, size_t Dim, S_fill(T)     , S_fill(T) Fill, TT rest) {
     225                return $alloc_internal( Resize, Realloc, Align, Dim, Fill, rest);
    226226                }
    227227
    228228            T * alloc( TT all ) {
    229                 return alloc_internal$( (void*)0p, (T*)0p, (_Alignof(T) > libAlign() ? _Alignof(T) : libAlign()), (size_t)1, (S_fill(T)){'0'}, all);
     229                return $alloc_internal( (void*)0p, (T*)0p, (_Alignof(T) > libAlign() ? _Alignof(T) : libAlign()), (size_t)1, (S_fill(T)){'0'}, all);
    230230            }
    231231
    232232            T * alloc( size_t dim, TT all ) {
    233                 return alloc_internal$( (void*)0p, (T*)0p, (_Alignof(T) > libAlign() ? _Alignof(T) : libAlign()), dim, (S_fill(T)){'0'}, all);
     233                return $alloc_internal( (void*)0p, (T*)0p, (_Alignof(T) > libAlign() ? _Alignof(T) : libAlign()), dim, (S_fill(T)){'0'}, all);
    234234            }
    235235
  • libcfa/src/time.hfa

    rc41c2dbe r341aa39  
    1010// Created On       : Wed Mar 14 23:18:57 2018
    1111// Last Modified By : Peter A. Buhr
    12 // Last Modified On : Wed Apr 21 06:32:31 2021
    13 // Update Count     : 667
     12// Last Modified On : Wed Apr 14 09:30:30 2021
     13// Update Count     : 664
    1414//
    1515
     
    2828
    2929static inline {
     30        Duration ?=?( Duration & dur, __attribute__((unused)) zero_t ) { return dur{ 0 }; }
     31
    3032        void ?{}( Duration & dur, timeval t ) with( dur ) { tn = (int64_t)t.tv_sec * TIMEGRAN + t.tv_usec * 1000; }
    31         void ?{}( Duration & dur, timespec t ) with( dur ) { tn = (int64_t)t.tv_sec * TIMEGRAN + t.tv_nsec; }
    32 
    33         Duration ?=?( Duration & dur, __attribute__((unused)) zero_t ) { return dur{ 0 }; }
    3433        Duration ?=?( Duration & dur, timeval t ) with( dur ) {
    3534                tn = (int64_t)t.tv_sec * TIMEGRAN + t.tv_usec * (TIMEGRAN / 1_000_000LL);
    3635                return dur;
    3736        } // ?=?
     37
     38        void ?{}( Duration & dur, timespec t ) with( dur ) { tn = (int64_t)t.tv_sec * TIMEGRAN + t.tv_nsec; }
    3839        Duration ?=?( Duration & dur, timespec t ) with( dur ) {
    3940                tn = (int64_t)t.tv_sec * TIMEGRAN + t.tv_nsec;
     
    6061        Duration ?%?( Duration lhs, Duration rhs ) { return (Duration)@{ lhs.tn % rhs.tn }; }
    6162        Duration ?%=?( Duration & lhs, Duration rhs ) { lhs = lhs % rhs; return lhs; }
     63
     64        bool ?==?( Duration lhs, Duration rhs ) { return lhs.tn == rhs.tn; }
     65        bool ?!=?( Duration lhs, Duration rhs ) { return lhs.tn != rhs.tn; }
     66        bool ?<? ( Duration lhs, Duration rhs ) { return lhs.tn <  rhs.tn; }
     67        bool ?<=?( Duration lhs, Duration rhs ) { return lhs.tn <= rhs.tn; }
     68        bool ?>? ( Duration lhs, Duration rhs ) { return lhs.tn >  rhs.tn; }
     69        bool ?>=?( Duration lhs, Duration rhs ) { return lhs.tn >= rhs.tn; }
    6270
    6371        bool ?==?( Duration lhs, __attribute__((unused)) zero_t ) { return lhs.tn == 0; }
     
    6775        bool ?>? ( Duration lhs, __attribute__((unused)) zero_t ) { return lhs.tn >  0; }
    6876        bool ?>=?( Duration lhs, __attribute__((unused)) zero_t ) { return lhs.tn >= 0; }
    69 
    70         bool ?==?( Duration lhs, Duration rhs ) { return lhs.tn == rhs.tn; }
    71         bool ?!=?( Duration lhs, Duration rhs ) { return lhs.tn != rhs.tn; }
    72         bool ?<? ( Duration lhs, Duration rhs ) { return lhs.tn <  rhs.tn; }
    73         bool ?<=?( Duration lhs, Duration rhs ) { return lhs.tn <= rhs.tn; }
    74         bool ?>? ( Duration lhs, Duration rhs ) { return lhs.tn >  rhs.tn; }
    75         bool ?>=?( Duration lhs, Duration rhs ) { return lhs.tn >= rhs.tn; }
    7677
    7778        Duration abs( Duration rhs ) { return rhs.tn >= 0 ? rhs : -rhs; }
     
    163164void ?{}( Time & time, int year, int month = 1, int day = 1, int hour = 0, int min = 0, int sec = 0, int64_t nsec = 0 );
    164165static inline {
     166        Time ?=?( Time & time, __attribute__((unused)) zero_t ) { return time{ 0 }; }
     167
    165168        void ?{}( Time & time, timeval t ) with( time ) { tn = (int64_t)t.tv_sec * TIMEGRAN + t.tv_usec * 1000; }
    166         void ?{}( Time & time, timespec t ) with( time ) { tn = (int64_t)t.tv_sec * TIMEGRAN + t.tv_nsec; }
    167 
    168         Time ?=?( Time & time, __attribute__((unused)) zero_t ) { return time{ 0 }; }
    169169        Time ?=?( Time & time, timeval t ) with( time ) {
    170170                tn = (int64_t)t.tv_sec * TIMEGRAN + t.tv_usec * (TIMEGRAN / 1_000_000LL);
    171171                return time;
    172172        } // ?=?
     173
     174        void ?{}( Time & time, timespec t ) with( time ) { tn = (int64_t)t.tv_sec * TIMEGRAN + t.tv_nsec; }
    173175        Time ?=?( Time & time, timespec t ) with( time ) {
    174176                tn = (int64_t)t.tv_sec * TIMEGRAN + t.tv_nsec;
Note: See TracChangeset for help on using the changeset viewer.