Changeset 59e86eb


Ignore:
Timestamp:
Jul 17, 2017, 2:24:00 PM (7 years ago)
Author:
Peter A. Buhr <pabuhr@…>
Branches:
ADT, aaron-thesis, arm-eh, ast-experimental, cleanup-dtors, deferred_resn, demangler, enum, forall-pointer-decay, jacob/cs343-translation, jenkins-sandbox, master, new-ast, new-ast-unique-expr, new-env, no_list, persistent-indexer, pthread-emulation, qualifiedEnum, resolv-new, with_gc
Children:
5688056, 5bd0aad
Parents:
4d84cb2
Message:

document exponentiation operator, formatting, update indexing

File:
1 edited

Legend:

Unmodified
Added
Removed
  • doc/user/user.tex

    r4d84cb2 r59e86eb  
    1111%% Created On       : Wed Apr  6 14:53:29 2016
    1212%% Last Modified By : Peter A. Buhr
    13 %% Last Modified On : Thu Jul 13 11:44:57 2017
    14 %% Update Count     : 2690
     13%% Last Modified On : Mon Jul 17 13:06:40 2017
     14%% Update Count     : 2825
    1515%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
    1616
     
    353353The 1999 C standard plus GNU extensions.
    354354\item
    355 {\lstset{deletekeywords={inline}}
    356 \Indexc{-fgnu89-inline}\index{compilation option!-fgnu89-inline@{©-fgnu89-inline©}}
     355\Indexc[deletekeywords=inline]{-fgnu89-inline}\index{compilation option!-fgnu89-inline@{\lstinline[deletekeywords=inline]$-fgnu89-inline$}}
    357356Use the traditional GNU semantics for inline routines in C99 mode, which allows inline routines in header files.
    358 }%
    359357\end{description}
    360358The following new \CFA options are available:
     
    479477\end{cfa}
    480478Existing C programs with keyword clashes can be converted by enclosing keyword identifiers in backquotes, and eventually the identifier name can be changed to a non-keyword name.
    481 \VRef[Figure]{f:InterpositionHeaderFile} shows how clashes in C header files (see~\VRef{s:StandardHeaders}) can be handled using preprocessor \newterm{interposition}: ©#include_next© and ©-I filename©:
     479\VRef[Figure]{f:HeaderFileInterposition} shows how clashes in C header files (see~\VRef{s:StandardHeaders}) can be handled using preprocessor \newterm{interposition}: ©#include_next© and ©-I filename©:
    482480
    483481\begin{figure}
     
    487485#define otype ®`®otype®`®               §\C{// make keyword an identifier}§
    488486#define __CFA_BFD_H__
    489 #endif // ! otype
    490 
    491 #®include_next® <bfd.h>                 §\C{// must have internal check for multiple expansion}§
    492 
     487#endif
     488
     489®#include_next <bfd.h>                  §\C{// must have internal check for multiple expansion}§
     490®
    493491#if defined( otype ) && defined( __CFA_BFD_H__ )        §\C{// reset only if set}§
    494492#undef otype
    495493#undef __CFA_BFD_H__
    496 #endif // otype && __CFA_BFD_H__
    497 \end{cfa}
    498 \caption{Interposition of Header File}
    499 \label{f:InterpositionHeaderFile}
     494#endif
     495\end{cfa}
     496\caption{Header-File Interposition}
     497\label{f:HeaderFileInterposition}
    500498\end{figure}
     499
     500
     501\section{Exponentiation Operator}
     502
     503C, \CC, and Java (and many other programming languages) have no exponentiation operator\index{exponentiation!operator}\index{operator!exponentiation}, \ie $x^y$, and instead use a routine, like \Indexc{pow}, to perform the exponentiation operation.
     504\CFA extends the basic operators with the exponentiation operator ©?\?©\index{?\\?@\lstinline$?\?$} and ©?\=?©\index{?\\=?@\lstinline$?\=?$}, as in, ©x \ y© and ©x \= y©, which means $x^y$ and $x \leftarrow x^y$.
     505The priority of the exponentiation operator is between the cast and multiplicative operators, so that ©w * (int)x \ (int)y * z© is parenthesized as ©((w * (((int)x) \ ((int)y))) * z)©.
     506
     507As for \Index{division}, there are exponentiation operators for integral and floating-point types, including the builtin \Index{complex} types.
     508Unsigned integral exponentiation\index{exponentiation!unsigned integral} is performed with repeated multiplication (or shifting if the base is 2).
     509Signed integral exponentiation\index{exponentiation!signed integral} is performed with repeated multiplication (or shifting if the base is 2), but yields a floating-point result because $b^{-e}=1/b^e$.
     510Hence, it is important to designate exponent integral-constants as unsigned or signed: ©3 \ 3u© return an integral result, while ©3 \ 3© returns a floating-point result.
     511Floating-point exponentiation\index{exponentiation!floating point} is performed using \Index{logarithm}s\index{exponentiation!logarithm}, so the base cannot be negative.
     512\begin{cfa}
     513sout | 2 ®\® 8u | 4 ®\® 3u | -4 ®\® 3u | 4 ®\® -3 | -4 ®\® -3 | 4.0 ®\® 2.1 | (1.0f+2.0fi) ®\® (3.0f+2.0fi) | endl;
     514256 64 -64 0.015625 -0.015625 18.3791736799526 0.264715-1.1922i
     515\end{cfa}
     516Parenthesis are necessary for the complex constants or the expresion is parsed as ©1.0f+(2.0fi \ 3.0f)+2.0fi©.
     517The exponentiation operator is available for all the basic types, but for user-defined types, only the integral version is available, if the user type defines multiplication, ©*©, and one, ©1©.
    501518
    502519
     
    922939        int i, j;
    923940        int mem() {              ®// implicit "this" parameter
    924                 i = 1;          ®// this->i
     941®               i = 1;          ®// this->i
    925942®               j = 3;          ®// this->j
    926943®       }
     
    929946Since CFA is non-object-oriented, the equivalent object-oriented program looks like:
    930947\begin{cfa}
    931 struct C {
    932         int i, j;
    933 };
    934 int mem( C &this ) {    // explicit "this" parameter
     948struct S { int i, j; };
     949int mem( S &this ) {    // explicit "this" parameter
    935950        ®this.®i = 1;                     // "this" is not elided
    936951        ®this.®j = 2;
     
    938953\end{cfa}
    939954but it is cumbersome having to write "©this.©" many times in a member.
    940 \CFA provides a ©with© clause/statement to elided the "©this.©".
    941 \begin{cfa}
    942 int mem( C &this ) ®with this® {
     955
     956\CFA provides a ©with© clause/statement to elided the "©this.©" by opening a scope containing field identifiers and changing the qualified fields into variables, giving an opportunity for optimizing qualified references.\footnote{
     957The ©with© statement comes from Pascal~\cite[\S~4.F]{Pascal}.}
     958\begin{cfa}
     959int mem( S &this ) ®with this® {
    943960        i = 1;                  ®// this.i
    944961®       j = 2;                  ®// this.j
     
    947964which extends to multiple routine parameters:
    948965\begin{cfa}
    949 struct D {
    950         double m, n;
    951 };
    952 int mem2( C &this1, D &this2 ) ®with this1, this2® {
     966struct T { double m, n; };
     967int mem2( S &this1, T &this2 ) ®with this1, this2® {
    953968        i = 1; j = 2;
    954969        m = 1.0; n = 2.0;
    955970}
    956971\end{cfa}
    957 The ©with© clause/statement comes from Pascal~\cite[\S~4.F]{Pascal}.
    958972
    959973The statement form is used within a block:
     
    965979                // access fields of s1 without qualification
    966980                ®with s2® {  // nesting
    967                         // access fields of s2 without qualification
     981                        // access fields of s1 and s2 without qualification
    968982                }
    969983        }
     
    974988\end{cfa}
    975989
    976 Names clashes when opening multiple structures are ambiguous.
    977 \begin{cfa}
    978 struct A { int i; int j; } a, c;
    979 struct B { int i; int k; } b, c;
     990When opening multiple structures, fields with the same name and type are ambiguous and must be fully qualified.
     991For fields with the same name but different type, context/cast can be used to disambiguate.
     992\begin{cfa}
     993struct S { int i; int j; double m; } a, c;
     994struct T { int i; int k; int m } b, c;
    980995®with a, b® {
    981         j + k;                                          §\C{// unambiguous}§
    982         i;                                                      §\C{// ambiguous}§
    983         a.i + b.i;                                      §\C{// unambiguous}§
    984 }
    985 ®with c® {                                              §\C{// ambiguous}§
    986         // ...
    987 }
     996        j + k;                                          §\C{// unambiguous, unique names define unique type}§
     997        i;                                                      §\C{// ambiguous, same name and type}§
     998        a.i + b.i;                                      §\C{// unambiguous, qualification defines unique type}§
     999        m;                                                      §\C{// ambiguous, no context to define unique type}§
     1000        m = 5.0;                                        §\C{// unambiguous, context defines unique type}§
     1001        m = 1;                                          §\C{// unambiguous, context defines unique type}§
     1002}
     1003®with c® { ... }                                §\C{// ambiguous, no context}§
     1004®with (S)c® { ... }                             §\C{// unambiguous, cast defines unique type}§
    9881005\end{cfa}
    9891006
    9901007
    9911008\section{Exception Handling}
     1009\label{s:ExceptionHandling}
    9921010
    9931011Exception handling provides two mechanism: change of control flow from a raise to a handler, and communication from the raise to the handler.
    994 \begin{cfa}
    995 exception void h( int i );
    996 exception int h( int i, double d );
    997 
     1012Transfer of control can be local, within a routine, or non-local, among routines.
     1013Non-local transfer can cause stack unwinding, i.e., non-local routine termination, depending on the kind of raise.
     1014\begin{cfa}
     1015exception_t E {};                               §\C{// exception type}§
    9981016void f(...) {
    999         ... throw h( 3 );
    1000         ... i = resume h( 3, 5.1 );
    1001 }
    1002 
     1017        ... throw E{}; ...                      §\C{// termination}§
     1018        ... throwResume E{}; ...        §\C{// resumption}§
     1019}
    10031020try {
    10041021        f(...);
    1005 } catch h( int w ) {
    1006         // reset
    1007 } resume h( int p, double x ) {
    1008         return 17;  // recover
     1022} catch( E e : §boolean-predicate§ ) {                  §\C{// termination handler}§
     1023        // recover and continue
     1024} catchResume( E e : §boolean-predicate§ ) {    §\C{// resumption handler}§
     1025        // repair and return
    10091026} finally {
    1010 }
    1011 \end{cfa}
    1012 So the type raised would be the mangled name of the exception prototype and that name would be matched at the handler clauses by comparing the strings.
    1013 The arguments for the call would have to be packed in a message and unpacked at handler clause and then a call made to the handler.
     1027        // always executed
     1028}
     1029\end{cfa}
     1030The kind of raise and handler match: ©throw© with ©catch© and @throwResume@ with @catchResume@.
     1031Then the exception type must match along with any additonal predicate must be true.
     1032The ©catch© and ©catchResume© handlers may appear in any oder.
     1033However, the ©finally© clause must
    10141034
    10151035
     
    15711591
    15721592\item
    1573 lvalue to reference conversion: \lstinline[deletekeywords={lvalue}]@lvalue-type cv1 T@ converts to ©cv2 T &©, which allows implicitly converting variables to references.
     1593lvalue to reference conversion: \lstinline[deletekeywords=lvalue]$lvalue-type cv1 T$ converts to ©cv2 T &©, which allows implicitly converting variables to references.
    15741594\begin{cfa}
    15751595int x, &r = ®x®, f( int & p ); // lvalue variable (int) convert to reference (int &)
     
    26802700\begin{cfa}[belowskip=0pt]
    26812701char store[®sepSize®];                                          §\C{// sepSize is the maximum separator size}§
    2682 strcpy( store, sepGet( sout ) );
    2683 sepSet( sout, "_" );
     2702strcpy( store, sepGet( sout ) );                          §\C{// copy current separator}§
     2703sepSet( sout, "_" );                                            §\C{// change separator to underscore}§
    26842704sout | 1 | 2 | 3 | endl;
    26852705\end{cfa}
     
    26882708\end{cfa}
    26892709\begin{cfa}[belowskip=0pt]
    2690 sepSet( sout, store );
     2710sepSet( sout, store );                                          §\C{// change separator back to original}§
    26912711sout | 1 | 2 | 3 | endl;
    26922712\end{cfa}
     
    55635583\Celeven prescribes the following standard header-files~\cite[\S~7.1.2]{C11} and \CFA adds to this list:
    55645584\begin{quote2}
    5565 \lstset{deletekeywords={float}}
    5566 \begin{tabular}{@{}llll|l@{}}
    5567 \multicolumn{4}{c|}{C11} & \multicolumn{1}{c}{\CFA}             \\
     5585\begin{tabular}{@{}lllll|l@{}}
     5586\multicolumn{5}{c|}{C11} & \multicolumn{1}{c}{\CFA}             \\
    55685587\hline
    55695588\begin{tabular}{@{}l@{}}
     
    55735592\Indexc{errno.h}                \\
    55745593\Indexc{fenv.h}                 \\
    5575 \Indexc{float.h}                \\
    5576 \Indexc{inttypes.h}             \\
    5577 \Indexc{iso646.h}               \\
     5594\Indexc[deletekeywords=float]{float.h} \\
    55785595\end{tabular}
    55795596&
    55805597\begin{tabular}{@{}l@{}}
     5598\Indexc{inttypes.h}             \\
     5599\Indexc{iso646.h}               \\
    55815600\Indexc{limits.h}               \\
    55825601\Indexc{locale.h}               \\
    55835602\Indexc{math.h}                 \\
    55845603\Indexc{setjmp.h}               \\
     5604\end{tabular}
     5605&
     5606\begin{tabular}{@{}l@{}}
    55855607\Indexc{signal.h}               \\
    55865608\Indexc{stdalign.h}             \\
    55875609\Indexc{stdarg.h}               \\
    55885610\Indexc{stdatomic.h}    \\
     5611\Indexc{stdbool.h}              \\
     5612\Indexc{stddef.h}               \\
    55895613\end{tabular}
    55905614&
    55915615\begin{tabular}{@{}l@{}}
    5592 \Indexc{stdbool.h}              \\
    5593 \Indexc{stddef.h}               \\
    55945616\Indexc{stdint.h}               \\
    55955617\Indexc{stdio.h}                \\
     
    56075629\Indexc{wctype.h}               \\
    56085630                                                \\
    5609                                                 \\
    5610                                                 \\
    56115631\end{tabular}
    56125632&
     
    56145634\Indexc{unistd.h}               \\
    56155635\Indexc{gmp.h}                  \\
    5616                                                 \\
    5617                                                 \\
    56185636                                                \\
    56195637                                                \\
     
    56555673The table shows allocation routines supporting different combinations of storage-management capabilities:
    56565674\begin{center}
    5657 \begin{tabular}{@{}lr|l|l|l|l@{}}
    5658                 &                                       & \multicolumn{1}{c|}{fill}     & resize        & alignment     & array \\
     5675\begin{tabular}{@{}r|r|l|l|l|l@{}}
     5676\multicolumn{1}{c}{}&           & \multicolumn{1}{c|}{fill}     & resize        & alignment     & array \\
    56595677\hline
    56605678C               & ©malloc©                      & no                    & no            & no            & no    \\
     
    56635681                & ©memalign©            & no                    & no            & yes           & no    \\
    56645682                & ©posix_memalign©      & no                    & no            & yes           & no    \\
     5683\hline
    56655684C11             & ©aligned_alloc©       & no                    & no            & yes           & no    \\
     5685\hline
    56665686\CFA    & ©alloc©                       & no/copy/yes   & no/yes        & no            & yes   \\
    56675687                & ©align_alloc©         & no/yes                & no            & yes           & yes   \\
Note: See TracChangeset for help on using the changeset viewer.