Changeset dabc428


Ignore:
Timestamp:
Apr 20, 2021, 11:40:40 PM (8 weeks ago)
Author:
Peter A. Buhr <pabuhr@…>
Branches:
arm-eh, jacob/cs343-translation, master
Children:
e638266
Parents:
6f6b844
Message:

update sections enumeration, coroutine, monitor, math, duration, time, clock

File:
1 edited

Legend:

Unmodified
Added
Removed
  • doc/user/user.tex

    r6f6b844 rdabc428  
    1111%% Created On       : Wed Apr  6 14:53:29 2016
    1212%% Last Modified By : Peter A. Buhr
    13 %% Last Modified On : Sat Mar 27 09:55:55 2021
    14 %% Update Count     : 4796
     13%% Last Modified On : Tue Apr 20 23:25:56 2021
     14%% Update Count     : 4888
    1515%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
    1616
     
    6666% math escape $...$ (dollar symbol)
    6767\input{common}                                          % common CFA document macros
     68\setlength{\gcolumnposn}{3in}
    6869\CFAStyle                                                                                               % use default CFA format-style
    6970\lstset{language=CFA}                                                                   % CFA default lnaguage
     
    21662167\section{Enumeration}
    21672168
    2168 An \newterm{enumeration} is a compile-time mechanism to give names to constants.
    2169 There is no runtime manifestation of an enumeration.
    2170 Their purpose is code-readability and maintenance -- changing an enum's value automatically updates all name usages during compilation.
    2171 
    2172 An 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}
    2174 enum Days { Mon, Tue, Wed, Thu, Fri, Sat, Sun }; // enumeration type definition, set of 7 names
     2169An \newterm{enumeration} is a compile-time mechanism to alias names to constants, like ©typedef© is a mechanism to alias names to types.
     2170Its 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
     2172An 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}
     2174enum Days { Mon, Tue, Wed, Thu, Fri, Sat, Sun }; // enumeration type definition, set of 7 names & values
    21752175Days days = Mon; // enumeration type declaration and initialization
    21762176\end{cfa}
    2177 The set of enums are injected into the scope of the definition and use the variable namespace.
     2177The set of enums are injected into the variable namespace at the definition scope.
    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 is used to inject enums with specific values into a scope:
     2185An anonymous enumeration injects 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 the C \Index{preprocessor}
     2189An enumeration is better than using C \Index{preprocessor} or constant declarations.
     2190\begin{cquote}
     2191\begin{tabular}{@{}l@{\hspace{4em}}l@{}}
    21902192\begin{cfa}
    21912193#define Mon 0
     
    21932195#define Sun 6
    21942196\end{cfa}
    2195 or C constant declarations
    2196 \begin{cfa}
    2197 const int Mon = 0, ..., Sun = 6;
    2198 \end{cfa}
     2197&
     2198\begin{cfa}
     2199const int Mon = 0,
     2200                         ...,
     2201                         Sun = 6;
     2202\end{cfa}
     2203\end{tabular}
     2204\end{cquote}
    21992205because the enumeration is succinct, has automatic numbering, can appear in ©case© labels, does not use storage, and is part of the language type-system.
    22002206Finally, the type of an enum is implicitly or explicitly specified and the constant value can be implicitly or explicitly specified.
     
    22042210\subsection{Enum type}
    22052211
    2206 While 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.
     2212The type of enums can be any type, and an enum's value comes from this type.
     2213Because 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).
     2214Therefore, 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;
     2215there is no mechanism to print the enum name.
     2216
    22082217The default enum type is ©int©.
    22092218Hence, ©Days© is the set type ©Mon©, ©Tue©, ...\,, ©Sun©, while the type of each enum is ©int© and each enum represents a fixed integral value.
    22102219If no values are specified for an integral enum type, the enums are automatically numbered by one from left to right starting at zero.
    22112220Hence, the value of enum ©Mon© is 0, ©Tue© is 1, ...\,, ©Sun© is 6.
    2212 If a value is specified, numbering continues by one from that value.
    2213 It an enum value is an expression, the compiler performs constant-folding to obtain a constant value.
    2214 
    2215 Other integral types with associated values can be explicitly specified.
     2221If an enum value is specified, numbering continues by one from that value for subsequent unnumbered enums.
     2222If 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.
    22162225\begin{cfa}
    22172226enum( @char@ ) Letter { A @= 'A'@,  B,  C,  I @= 'I'@,  J,  K };
     
    22192228\end{cfa}
    22202229For 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©.
    2221 Note, an enum is an immutable constant, \ie ©A = B© is disallowed;
    2222 by transitivity, an enum's type is implicitly ©const©.
    2223 Hence, a constant/enum cannot appear in a mutuable context nor is a constant/enum addressable (rvalue).
    2224 
    2225 Non-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©.
     2230
     2231Non-integral enum types must be explicitly initialized, \eg ©double© is not automatically numbered by one.
    22262232\begin{cfa}
    22272233// non-integral numeric
    2228 enum( double ) Math { PI_2 = 1.570796, PI = 3.141597,  E = 2.718282 }
     2234enum( @double@ ) Math { PI_2 = 1.570796, PI = 3.141597,  E = 2.718282 }
    22292235// pointer
    2230 enum( char * ) Name { Fred = "Fred",  Mary = "Mary",  Jane = "Jane" };
     2236enum( @char *@ ) Name { Fred = "Fred",  Mary = "Mary",  Jane = "Jane" };
    22312237int i, j, k;
    2232 enum( int * ) ptr { I = &i,  J = &j,  K = &k };
    2233 enum( int & ) ref { I = i,  J = j,  K = k };
     2238enum( @int *@ ) ptr { I = &i,  J = &j,  K = &k };
     2239enum( @int &@ ) ref { I = i,  J = j,  K = k };
    22342240// tuple
    2235 enum( [int, int] ) { T = [ 1, 2 ] };
     2241enum( @[int, int]@ ) { T = [ 1, 2 ] };
    22362242// function
    22372243void f() {...}   void g() {...}
    2238 enum( void (*)() ) funs { F = f,  F = g };
     2244enum( @void (*)()@ ) funs { F = f,  F = g };
    22392245// aggregate
    22402246struct S { int i, j; };
    2241 enum( S ) s { A = { 3,  4 }, B = { 7,  8 } };
     2247enum( @S@ ) s { A = { 3,  4 }, B = { 7,  8 } };
    22422248// enumeration
    2243 enum( Letter ) Greek { Alph = A, Beta = B, /* more enums */  }; // alphabet intersection
     2249enum( @Letter@ ) Greek { Alph = A, Beta = B, /* more enums */  }; // alphabet intersection
    22442250\end{cfa}
    22452251Enumeration ©Greek© may have more or less enums than ©Letter©, but the enum values \emph{must} be from ©Letter©.
     
    22532259m = Alph;               $\C{// {\color{red}disallowed}}$
    22542260m = 3.141597;   $\C{// {\color{red}disallowed}}$
    2255 d = E;                  $\C{// allowed, conversion to base type}$
    2256 d = m;                  $\C{// {\color{red}disallowed}}$
     2261d = m;                  $\C{// allowed}$
    22572262d = Alph;               $\C{// {\color{red}disallowed}}$
    22582263Letter l = A;   $\C{// allowed}$
     
    22632268
    22642269A constructor \emph{cannot} be used to initialize enums because a constructor executes at runtime.
    2265 A fallback is to substitute C-style initialization overriding the constructor with ©@=©.
    2266 \begin{cfa}
    2267 enum( struct vec3 ) Axis { Up $@$= { 1, 0, 0 }, Left $@$= ..., Front $@$= ... }
     2270A fallback is explicit C-style initialization using ©@=©.
     2271\begin{cfa}
     2272enum( struct vec3 ) Axis { Up $@$= { 1, 0, 0 }, Left $@$= { 0, 1, 0 }, Front $@$= { 0, 0, 1 } }
    22682273\end{cfa}
    22692274Finally, enumeration variables are assignable and comparable only if the appropriate operators are defined for its enum type.
     
    22742279\Index{Plan-9}\index{inheritance!enumeration} inheritance may be used with enumerations.
    22752280\begin{cfa}
    2276 enum( const char * ) Name2 { @inline Name@, Jack = "Jack", Jill = "Jill" };
    2277 enum @/* inferred */@  Name3 { @inline Name@, @inline Name2@, Sue = "Sue", Tom = "Tom" };
     2281enum( char * ) Name2 { @inline Name@, Jack = "Jack", Jill = "Jill" };
     2282enum @/* inferred */@  Name3 { @inline Name2@, Sue = "Sue", Tom = "Tom" };
    22782283\end{cfa}
    22792284Enumeration ©Name2© inherits all the enums and their values from enumeration ©Name© by containment, and a ©Name© enumeration is a subtype of enumeration ©Name2©.
     
    22812286The enum type for the inheriting type must be the same as the inherited type;
    22822287hence the enum type may be omitted for the inheriting enumeration and it is inferred from the inherited enumeration, as for ©Name3©.
    2283 When inheriting from integral types, automatic numbering may be used, so the inheritance placement left to right is important.
     2288When 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©.
    22842289
    22852290Specifically, the inheritance relationship for ©Name©s is:
     
    23012306j( Fred );    j( Jill );    j( Sue );    j( 'W' );
    23022307\end{cfa}
    2303 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.
     2308Note, 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.
    23042309
    23052310Enums cannot be created at runtime, so inheritence problems, such as contra-variance do not apply.
     
    23132318\begin{cfa}
    23142319// Fred is a subset of char *
    2315 enum char * Fred { A = "A", B = "B", C = "C" };
     2320enum( char *) Fred { A = "A", B = "B", C = "C" };
    23162321// Jack is a subset of Fred
    2317 enum enum Fred Jack { W = A, Y = C};
     2322enum( enum Fred ) Jack { W = A, Y = C};
    23182323// Mary is a superset of Fred
    23192324enum Mary { inline Fred, D = "hello" };
     
    41684173
    41694174The 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.
    4170 For ©_Bool© type, the constants are ©true© and ©false©.
     4175For ©bool© type, the constants are ©true© and ©false©.
    41714176For integral types, any number of digits, optionally preceded by a sign (©+© or ©-©), where a
    41724177\begin{itemize}
     
    45804585In 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.
    45814586However, 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.
    4582 Defining special constants for a user-defined type is more efficient than defining a conversion to the type from ©_Bool©.
     4587Defining special constants for a user-defined type is more efficient than defining a conversion to the type from ©bool©.
    45834588
    45844589Why just 0 and 1? Why not other integers? No other integers have special status in C.
     
    50455050\begin{figure}
    50465051\begin{cfa}
    5047 #include <fstream>
    5048 #include <coroutine>
    5049 
    5050 coroutine Fibonacci {
     5052#include <fstream.hfa>
     5053#include @<coroutine.hfa>@
     5054
     5055@coroutine@ Fibonacci {
    50515056        int fn; $\C{// used for communication}$
    50525057};
    5053 void ?{}( Fibonacci * this ) {
    5054         this->fn = 0;
    5055 }
    5056 void main( Fibonacci * this ) {
     5058
     5059void main( Fibonacci & fib ) with( fib ) { $\C{// called on first resume}$
    50575060        int fn1, fn2; $\C{// retained between resumes}$
    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 }
    5074 int next( Fibonacci * this ) {
    5075         resume( this ); $\C{// transfer to last suspend}$
    5076         return this->fn;
     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}
     5070int next( Fibonacci & fib ) with( fib ) {
     5071        @resume( fib );@ $\C{// restart last suspend}$
     5072        return fn;
    50775073}
    50785074int main() {
    50795075        Fibonacci f1, f2;
    5080         for ( int i = 1; i <= 10; i += 1 ) {
    5081                 sout | next( &f1 ) | ' ' | next( &f2 );
    5082         } // for
    5083 }
    5084 \end{cfa}
     5076        for ( 10 ) { $\C{// print N Fibonacci values}$
     5077                sout | next( f1 ) | next( f2 );
     5078        }
     5079}
     5080\end{cfa}
     5081\vspace*{-5pt}
    50855082\caption{Fibonacci Coroutine}
    50865083\label{f:FibonacciCoroutine}
     
    51085105\begin{figure}
    51095106\begin{cfa}
    5110 #include <fstream>
    5111 #include <kernel>
    5112 #include <monitor>
    5113 #include <thread>
    5114 
    5115 monitor global_t {
    5116         int value;
    5117 };
    5118 
    5119 void ?{}(global_t * this) {
    5120         this->value = 0;
    5121 }
    5122 
    5123 static global_t global;
    5124 
    5125 void increment3( global_t * mutex this ) {
    5126         this->value += 1;
    5127 }
    5128 void increment2( global_t * mutex this ) {
    5129         increment3( this );
    5130 }
    5131 void increment( global_t * mutex this ) {
    5132         increment2( this );
    5133 }
     5107#include <fstream.hfa>
     5108#include @<thread.hfa>@
     5109
     5110@monitor@ AtomicCnt { int counter; };
     5111void ?{}( AtomicCnt & c, int init = 0 ) with(c) { counter = init; }
     5112int inc( AtomicCnt & @mutex@ c, int inc = 1 ) with(c) { return counter += inc; }
     5113int dec( AtomicCnt & @mutex@ c, int dec = 1 ) with(c) { return counter -= dec; }
     5114forall( 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
     5119AtomicCnt global; $\C{// shared}$
    51345120
    51355121thread MyThread {};
    5136 
    5137 void main( MyThread* this ) {
    5138         for(int i = 0; i < 1_000_000; i++) {
    5139                 increment( &global );
     5122void main( MyThread & ) {
     5123        for ( i; 100_000 ) {
     5124                inc( global );
     5125                dec( global );
    51405126        }
    51415127}
    5142 int main(int argc, char* argv[]) {
    5143         processor p;
     5128int main() {
     5129        enum { Threads = 4 };
     5130        processor p[Threads - 1]; $\C{// + starting processor}$
    51445131        {
    5145                 MyThread f[4];
     5132                MyThread t[Threads];
    51465133        }
    5147         sout | global.value;
     5134        sout | global; $\C{// print 0}$
    51485135}
    51495136\end{cfa}
    51505137\caption{Atomic-Counter Monitor}
    5151 \caption{f:AtomicCounterMonitor}
     5138\label{f:AtomicCounterMonitor}
    51525139\end{figure}
    51535140
     
    73207307[ int, long double ] remquo( long double, long double );
    73217308
    7322 float div( float, float, int * );$\indexc{div}$ $\C{// alternative name for remquo}$
    7323 double div( double, double, int * );
    7324 long double div( long double, long double, int * );
    73257309[ int, float ] div( float, float );
    73267310[ int, double ] div( double, double );
     
    73837367long double _Complex log( long double _Complex );
    73847368
    7385 float log2( float );$\indexc{log2}$
     7369int log2( unsigned int );$\indexc{log2}$
     7370long int log2( unsigned long int );
     7371long long int log2( unsigned long long int )
     7372float log2( float );
    73867373double log2( double );
    73877374long double log2( long double );
     
    75657552\leavevmode
    75667553\begin{cfa}[aboveskip=0pt,belowskip=0pt]
     7554// n / align * align
     7555signed char floor( signed char n, signed char align );
     7556unsigned char floor( unsigned char n, unsigned char align );
     7557short int floor( short int n, short int align );
     7558unsigned short int floor( unsigned short int n, unsigned short int align );
     7559int floor( int n, int align );
     7560unsigned int floor( unsigned int n, unsigned int align );
     7561long int floor( long int n, long int align );
     7562unsigned long int floor( unsigned long int n, unsigned long int align );
     7563long long int floor( long long int n, long long int align );
     7564unsigned long long int floor( unsigned long long int n, unsigned long long int align );
     7565
     7566// (n + (align - 1)) / align
     7567signed char ceiling_div( signed char n, char align );
     7568unsigned char ceiling_div( unsigned char n, unsigned char align );
     7569short int ceiling_div( short int n, short int align );
     7570unsigned short int ceiling_div( unsigned short int n, unsigned short int align );
     7571int ceiling_div( int n, int align );
     7572unsigned int ceiling_div( unsigned int n, unsigned int align );
     7573long int ceiling_div( long int n, long int align );
     7574unsigned long int ceiling_div( unsigned long int n, unsigned long int align );
     7575long long int ceiling_div( long long int n, long long int align );
     7576unsigned 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 )
     7579signed char ceiling( signed char n, signed char align );
     7580unsigned char ceiling( unsigned char n, unsigned char align );
     7581short int ceiling( short int n, short int align );
     7582unsigned short int ceiling( unsigned short int n, unsigned short int align );
     7583int ceiling( int n, int align );
     7584unsigned int ceiling( unsigned int n, unsigned int align );
     7585long int ceiling( long int n, long int align );
     7586unsigned long int ceiling( unsigned long int n, unsigned long int align );
     7587long long int ceiling( long long int n, long long int align );
     7588unsigned long long int ceiling( unsigned long long int n, unsigned long long int align );
     7589
    75677590float floor( float );$\indexc{floor}$
    75687591double floor( double );
     
    76677690\begin{cfa}[aboveskip=0pt,belowskip=0pt]
    76687691struct Duration {
    7669         int64_t tv; $\C{// nanoseconds}$
     7692        int64_t tn; $\C{// nanoseconds}$
    76707693};
    76717694
    76727695void ?{}( Duration & dur );
    76737696void ?{}( Duration & dur, zero_t );
     7697void ?{}( Duration & dur, timeval t )
     7698void ?{}( Duration & dur, timespec t )
    76747699
    76757700Duration ?=?( Duration & dur, zero_t );
     7701Duration ?=?( Duration & dur, timeval t )
     7702Duration ?=?( Duration & dur, timespec t )
    76767703
    76777704Duration +?( Duration rhs );
     
    76957722Duration ?%=?( Duration & lhs, Duration rhs );
    76967723
    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 );
     7724bool ?==?( Duration lhs, zero_t );
     7725bool ?!=?( Duration lhs, zero_t );
     7726bool ?<? ( Duration lhs, zero_t );
     7727bool ?<=?( Duration lhs, zero_t );
     7728bool ?>? ( Duration lhs, zero_t );
     7729bool ?>=?( Duration lhs, zero_t );
     7730
     7731bool ?==?( Duration lhs, Duration rhs );
     7732bool ?!=?( Duration lhs, Duration rhs );
     7733bool ?<? ( Duration lhs, Duration rhs );
     7734bool ?<=?( Duration lhs, Duration rhs );
     7735bool ?>? ( Duration lhs, Duration rhs );
     7736bool ?>=?( Duration lhs, Duration rhs );
    77107737
    77117738Duration abs( Duration rhs );
     
    77347761int64_t ?`w( Duration dur );
    77357762
     7763double ?`dns( Duration dur );
     7764double ?`dus( Duration dur );
     7765double ?`dms( Duration dur );
     7766double ?`ds( Duration dur );
     7767double ?`dm( Duration dur );
     7768double ?`dh( Duration dur );
     7769double ?`dd( Duration dur );
     7770double ?`dw( Duration dur );
     7771
    77367772Duration max( Duration lhs, Duration rhs );
    77377773Duration min( Duration lhs, Duration rhs );
     7774
     7775forall( ostype & | ostream( ostype ) ) ostype & ?|?( ostype & os, Duration dur );
    77387776\end{cfa}
    77397777
     
    77467784\begin{cfa}[aboveskip=0pt,belowskip=0pt]
    77477785void ?{}( timeval & t );
     7786void ?{}( timeval & t, zero_t );
    77487787void ?{}( timeval & t, time_t sec, suseconds_t usec );
    77497788void ?{}( timeval & t, time_t sec );
    7750 void ?{}( timeval & t, zero_t );
    77517789void ?{}( timeval & t, Time time );
    77527790
     
    77547792timeval ?+?( timeval & lhs, timeval rhs );
    77557793timeval ?-?( timeval & lhs, timeval rhs );
    7756 _Bool ?==?( timeval lhs, timeval rhs );
    7757 _Bool ?!=?( timeval lhs, timeval rhs );
     7794bool ?==?( timeval lhs, timeval rhs );
     7795bool ?!=?( timeval lhs, timeval rhs );
    77587796\end{cfa}
    77597797
     
    77667804\begin{cfa}[aboveskip=0pt,belowskip=0pt]
    77677805void ?{}( timespec & t );
     7806void ?{}( timespec & t, zero_t );
    77687807void ?{}( timespec & t, time_t sec, __syscall_slong_t nsec );
    77697808void ?{}( timespec & t, time_t sec );
    7770 void ?{}( timespec & t, zero_t );
    77717809void ?{}( timespec & t, Time time );
    77727810
     
    77747812timespec ?+?( timespec & lhs, timespec rhs );
    77757813timespec ?-?( timespec & lhs, timespec rhs );
    7776 _Bool ?==?( timespec lhs, timespec rhs );
    7777 _Bool ?!=?( timespec lhs, timespec rhs );
     7814bool ?==?( timespec lhs, timespec rhs );
     7815bool ?!=?( timespec lhs, timespec rhs );
    77787816\end{cfa}
    77797817
     
    77977835\begin{cfa}[aboveskip=0pt,belowskip=0pt]
    77987836struct Time {
    7799         uint64_t tv; $\C{// nanoseconds since UNIX epoch}$
     7837        uint64_t tn; $\C{// nanoseconds since UNIX epoch}$
    78007838};
    78017839
    78027840void ?{}( Time & time );
    78037841void ?{}( Time & time, zero_t );
     7842void ?{}( Time & time, timeval t );
     7843void ?{}( Time & time, timespec t );
    78047844
    78057845Time ?=?( Time & time, zero_t );
    7806 
    7807 void ?{}( Time & time, timeval t );
    78087846Time ?=?( Time & time, timeval t );
    7809 
    7810 void ?{}( Time & time, timespec t );
    78117847Time ?=?( Time & time, timespec t );
    78127848
     
    78187854Time ?-?( Time lhs, Duration rhs );
    78197855Time ?-=?( Time & lhs, Duration rhs );
    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 );
     7856bool ?==?( Time lhs, Time rhs );
     7857bool ?!=?( Time lhs, Time rhs );
     7858bool ?<?( Time lhs, Time rhs );
     7859bool ?<=?( Time lhs, Time rhs );
     7860bool ?>?( Time lhs, Time rhs );
     7861bool ?>=?( Time lhs, Time rhs );
     7862
     7863int64_t ?`ns( Time t );
    78267864
    78277865char * yy_mm_dd( Time time, char * buf );
    7828 char * ?`ymd( Time time, char * buf ) { // short form
    7829         return yy_mm_dd( time, buf );
    7830 } // ymd
     7866char * ?`ymd( Time time, char * buf ); // short form
    78317867
    78327868char * mm_dd_yy( Time time, char * buf );
    7833 char * ?`mdy( Time time, char * buf ) { // short form
    7834         return mm_dd_yy( time, buf );
    7835 } // mdy
     7869char * ?`mdy( Time time, char * buf ); // short form
    78367870
    78377871char * dd_mm_yy( Time time, char * buf );
    7838 char * ?`dmy( Time time, char * buf ) { // short form
    7839         return dd_mm_yy( time, buf );;
    7840 } // dmy
     7872char * ?`dmy( Time time, char * buf ); // short form
    78417873
    78427874size_t strftime( char * buf, size_t size, const char * fmt, Time time );
    7843 forall( dtype ostype | ostream( ostype ) ) ostype & ?|?( ostype & os, Time time );
     7875
     7876forall( ostype & | ostream( ostype ) ) ostype & ?|?( ostype & os, Time time );
    78447877\end{cfa}
    78457878
     
    78677900\leavevmode
    78687901\begin{cfa}[aboveskip=0pt,belowskip=0pt]
    7869 struct Clock {
    7870         Duration offset; $\C{// for virtual clock: contains offset from real-time}$
    7871         int clocktype; $\C{// implementation only -1 (virtual), CLOCK\_REALTIME}$
     7902struct Clock { $\C{// virtual clock}$
     7903        Duration offset; $\C{// offset from computer real-time}$
    78727904};
    78737905
    7874 void resetClock( Clock & clk );
    7875 void resetClock( Clock & clk, Duration adj );
    7876 void ?{}( Clock & clk );
    7877 void ?{}( Clock & clk, Duration adj );
    7878 
    7879 Duration getResNsec(); $\C{// with nanoseconds}$
    7880 Duration getRes(); $\C{// without nanoseconds}$
    7881 
    7882 Time getTimeNsec(); $\C{// with nanoseconds}$
    7883 Time getTime(); $\C{// without nanoseconds}$
    7884 Time getTime( Clock & clk );
    7885 Time ?()( Clock & clk );
    7886 timeval getTime( Clock & clk );
    7887 tm getTime( Clock & clk );
     7906void ?{}( Clock & clk ); $\C{// create no offset}$
     7907void ?{}( Clock & clk, Duration adj ); $\C{// create with offset}$
     7908void reset( Clock & clk, Duration adj ); $\C{// change offset}$
     7909
     7910Duration resolutionHi(); $\C{// clock resolution in nanoseconds (fine)}$
     7911Duration resolution(); $\C{// clock resolution without nanoseconds (coarse)}$
     7912
     7913Time timeHiRes(); $\C{// real time with nanoseconds}$
     7914Time time(); $\C{// real time without nanoseconds}$
     7915Time time( Clock & clk ); $\C{// real time for given clock}$
     7916Time ?()( Clock & clk ); $\C{//\ \ \ \ alternative syntax}$
     7917timeval time( Clock & clk ); $\C{// convert to C time format}$
     7918tm time( Clock & clk );
     7919Duration processor(); $\C{// non-monotonic duration of kernel thread}$
     7920Duration program(); $\C{// non-monotonic duration of program CPU}$
     7921Duration boot(); $\C{// monotonic duration since computer boot}$
    78887922\end{cfa}
    78897923
     
    80568090forall( dtype ostype | ostream( ostype ) ) ostype * ?|?( ostype * os, Int mp );
    80578091\end{cfa}
    8058 
    8059 The following factorial programs contrast using GMP with the \CFA and C interfaces, where the output from these programs appears in \VRef[Figure]{f:MultiPrecisionFactorials}.
     8092\VRef[Figure]{f:MultiPrecisionFactorials} shows \CFA and C factorial programs using the GMP interfaces.
    80608093(Compile with flag \Indexc{-lgmp} to link with the GMP library.)
     8094
     8095\begin{figure}
    80618096\begin{cquote}
    80628097\begin{tabular}{@{}l@{\hspace{\parindentlnth}}|@{\hspace{\parindentlnth}}l@{}}
    8063 \multicolumn{1}{c|@{\hspace{\parindentlnth}}}{\textbf{\CFA}}    & \multicolumn{1}{@{\hspace{\parindentlnth}}c}{\textbf{C}}      \\
     8098\multicolumn{1}{@{}c|@{\hspace{\parindentlnth}}}{\textbf{\CFA}} & \multicolumn{1}{@{\hspace{\parindentlnth}}c}{\textbf{C}@{}}   \\
    80648099\hline
    80658100\begin{cfa}
     
    80708105
    80718106        sout | 0 | fact;
    8072         for ( unsigned int i = 1; i <= 40; i += 1 ) {
     8107        for ( i; 40 ) {
    80738108                fact *= i;
    80748109                sout | i | fact;
     
    80928127\end{tabular}
    80938128\end{cquote}
    8094 
    8095 \begin{figure}
     8129\small
    80968130\begin{cfa}
    80978131Factorial Numbers
Note: See TracChangeset for help on using the changeset viewer.