Changeset 5b4dacf


Ignore:
Timestamp:
Oct 2, 2023, 3:11:28 PM (8 months ago)
Author:
Peter A. Buhr <pabuhr@…>
Branches:
master
Children:
cfcbd03
Parents:
4e2a57ff
Message:

general updates to the Cforall user manual

File:
1 edited

Legend:

Unmodified
Added
Removed
  • doc/user/user.tex

    r4e2a57ff r5b4dacf  
    1111%% Created On       : Wed Apr  6 14:53:29 2016
    1212%% Last Modified By : Peter A. Buhr
    13 %% Last Modified On : Thu Sep 28 22:40:52 2023
    14 %% Update Count     : 5578
     13%% Last Modified On : Sat Sep 30 22:46:19 2023
     14%% Update Count     : 5658
    1515%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
    1616
     
    6565%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
    6666
    67 \setlength{\gcolumnposn}{3in}
    6867\CFAStyle                                                                                               % use default CFA format-style
     68\setgcolumn{2.25in}
    6969%\lstset{language=CFA}                                                                  % CFA default lnaguage
    7070\lstnewenvironment{C++}[1][]                            % use C++ style
     
    537537Keyword clashes are accommodated by syntactic transformations using the \CFA backquote escape-mechanism:
    538538\begin{cfa}
    539 int ®``®coroutine = 3; $\C{// make keyword an identifier}$
     539int ®``®coroutine = 3;                                  $\C{// make keyword an identifier}$
    540540double ®``®forall = 3.5;
    541541\end{cfa}
     
    547547\begin{cfa}
    548548// include file uses the CFA keyword "with".
    549 #if ! defined( with )                                                   $\C{// nesting ?}$
    550 #define with ®``®with                                                   $\C{// make keyword an identifier}$
     549#if ! defined( with )                                   $\C{// nesting ?}$
     550#define with ®``®with                                   $\C{// make keyword an identifier}$
    551551#define __CFA_BFD_H__
    552552#endif
    553 $\R{\#include\_next} <bfdlink.h>$                               $\C{// must have internal check for multiple expansion}$
     553$\R{\#include\_next} <bfdlink.h>$               $\C{// must have internal check for multiple expansion}$
    554554#if defined( with ) && defined( __CFA_BFD_H__ ) $\C{// reset only if set}$
    555555#undef with
     
    566566Numeric constants are extended to allow \Index{underscore}s\index{constant!underscore} as a separator, \eg:
    567567\begin{cfa}
    568 2®_®147®_®483®_®648; $\C{// decimal constant}$
    569 56®_®ul; $\C{// decimal unsigned long constant}$
    570 0®_®377; $\C{// octal constant}$
    571 0x®_®ff®_®ff; $\C{// hexadecimal constant}$
    572 0x®_®ef3d®_®aa5c; $\C{// hexadecimal constant}$
    573 3.141®_®592®_®654; $\C{// floating constant}$
    574 10®_®e®_®+1®_®00; $\C{// floating constant}$
    575 0x®_®ff®_®ff®_®p®_®3; $\C{// hexadecimal floating}$
    576 0x®_®1.ffff®_®ffff®_®p®_®128®_®l; $\C{// hexadecimal floating long constant}$
     5682®_®147®_®483®_®648;                                    $\C{// decimal constant}$
     56956®_®ul;                                                                $\C{// decimal unsigned long constant}$
     5700®_®377;                                                                $\C{// octal constant}$
     5710x®_®ff®_®ff;                                                   $\C{// hexadecimal constant}$
     5720x®_®ef3d®_®aa5c;                                               $\C{// hexadecimal constant}$
     5733.141®_®592®_®654;                                              $\C{// floating constant}$
     57410®_®e®_®+1®_®00;                                               $\C{// floating constant}$
     5750x®_®ff®_®ff®_®p®_®3;                                   $\C{// hexadecimal floating}$
     5760x®_®1.ffff®_®ffff®_®p®_®128®_®l;               $\C{// hexadecimal floating long constant}$
    577577L®_®$"\texttt{\textbackslash{x}}$®_®$\texttt{ff}$®_®$\texttt{ee}"$; $\C{// wide character constant}$
    578578\end{cfa}
     
    604604
    605605There are exponentiation operators for integral and floating types, including the builtin \Index{complex} types.
    606 Integral exponentiation\index{exponentiation!unsigned integral} is performed with repeated multiplication\footnote{The multiplication computation is $O(\log y)$.} (or shifting if the exponent is 2).
     606Integral exponentiation\index{exponentiation!unsigned integral} is performed with repeated multiplication ($O(\log y)$ multiplies or shifting if the exponent is 2).
    607607Overflow for a large exponent or negative exponent returns zero.
    608608Floating exponentiation\index{exponentiation!floating} is performed using \Index{logarithm}s\index{exponentiation!logarithm}, so the exponent cannot be negative.
    609609\begin{cfa}
    610 sout | 1 ®\® 0 | 1 ®\® 1 | 2 ®\® 8 | -4 ®\® 3 | 5 ®\® 3 | 5 ®\® 32 | 5L ®\® 32 | 5L ®\® 64 | -4 ®\® -3 | -4.0 ®\® -3 | 4.0 ®\® 2.1
    611            | (1.0f+2.0fi) ®\® (3.0f+2.0fi);
     610sout | 1 ®\® 0 | 1 ®\® 1 | 2 ®\® 8 | -4 ®\® 3 | 5 ®\® 3 | 5 ®\® 32 | 5L ®\® 32 | 5L ®\® 64 | -4 ®\® -3 | -4.0 ®\® -3 | 4.0 ®\® 2.1 | (1.0f+2.0fi) ®\® (3.0f+2.0fi);
    6126111 1 256 -64 125 ®0® 3273344365508751233 ®0® ®0® -0.015625 18.3791736799526 0.264715-1.1922i
    613612\end{cfa}
     
    622621T ?®\®?( T ep, unsigned long int y );
    623622\end{cfa}
    624 The user type ©T© must define multiplication, one (©1©), and ©*©.
     623A user type ©T© must define multiplication, one (©1©), and ©*©.
    625624
    626625
     
    636635Declarations in the \Indexc{do}-©while© condition are not useful because they appear after the loop body.}
    637636\begin{cfa}
    638 if ( ®int x = f()® ) ... $\C{// x != 0}$
    639 if ( ®int x = f(), y = g()® ) ... $\C{// x != 0 \&\& y != 0}$
     637if ( ®int x = f()® ) ...                        $\C{// x != 0}$
     638if ( ®int x = f(), y = g()® ) ...       $\C{// x != 0 \&\& y != 0}$
    640639if ( ®int x = f(), y = g(); x < y® ) ... $\C{// relational expression}$
    641640if ( ®struct S { int i; } x = { f() }; x.i < 4® ) $\C{// relational expression}$
    642641
    643 while ( ®int x = f()® ) ... $\C{// x != 0}$
     642while ( ®int x = f()® ) ...                     $\C{// x != 0}$
    644643while ( ®int x = f(), y = g()® ) ... $\C{// x != 0 \&\& y != 0}$
    645644while ( ®int x = f(), y = g(); x < y® ) ... $\C{// relational expression}$
     
    655654\label{s:caseClause}
    656655
    657 C restricts the \Indexc{case} clause of a \Indexc{switch} statement to a single value.
    658 For multiple ©case© clauses associated with the same statement, it is necessary to have multiple ©case© clauses rather than multiple values.
     656C restricts a \Indexc{case} clause in \Indexc{switch} statement to a single value.
     657For multiple ©case© clauses prefixing a statement within the ©switch© statement, it is necessary to have multiple ©case© clauses rather than multiple values.
    659658Requiring a ©case© clause for each value is not in the spirit of brevity normally associated with C.
    660659Therefore, the ©case© clause is extended with a list of values.
    661660\begin{cquote}
    662661\begin{tabular}{@{}l@{\hspace{3em}}l@{\hspace{2em}}l@{}}
    663 \multicolumn{1}{c@{\hspace{3em}}}{\textbf{\CFA}}        & \multicolumn{1}{c@{\hspace{2em}}}{\textbf{C}} \\
     662\multicolumn{1}{c@{\hspace{3em}}}{\textbf{C}}   & \multicolumn{1}{c@{\hspace{2em}}}{\textbf{\CFA}}      \\
     663\begin{cfa}
     664switch ( i ) {
     665  case 1: case 3 : case 5:
     666        ...
     667  case 2: case 4 : case 6:
     668        ...
     669}
     670\end{cfa}
     671&
    664672\begin{cfa}
    665673switch ( i ) {
     
    672680&
    673681\begin{cfa}
    674 switch ( i ) {
    675   case 1: case 3 : case 5:
    676         ...
    677   case 2: case 4 : case 6:
    678         ...
    679 }
    680 \end{cfa}
    681 &
    682 \begin{cfa}
    683682
    684683// odd values
     
    690689\end{tabular}
    691690\end{cquote}
    692 In addition, subranges are allowed to specify case values.\footnote{
    693 gcc has the same mechanism but awkward syntax, \lstinline{2 ...42}, because a space is required after a number, otherwise the period is a decimal point.}
     691In addition, subranges are allowed to specify case values.
     692\begin{cquote}
     693\begin{tabular}{@{}l@{\hspace{3em}}l@{\hspace{2em}}l@{\hspace{2em}}l@{}}
     694\multicolumn{1}{c@{\hspace{3em}}}{\textbf{C}}   & \multicolumn{1}{c@{\hspace{2em}}}{\textbf{\CFA}}      & \multicolumn{1}{c@{\hspace{2em}}}{\textbf{©gcc©}}     \\
    694695\begin{cfa}
    695696switch ( i ) {
    696   case ®1~5:® $\C{// 1, 2, 3, 4, 5}$
     697  case 1: case 2: case 3: case 4:
    697698        ...
    698   case ®10~15:® $\C{// 10, 11, 12, 13, 14, 15}$
     699  case 10: case 11: case 12: case 13:
    699700        ...
    700701}
    701702\end{cfa}
    702 Lists of subranges are also allowed.
     703&
     704\begin{cfa}
     705switch ( i ) {
     706  case ®1~4:®
     707        ...
     708  case ®10~13:®
     709        ...
     710}
     711\end{cfa}
     712&
     713\begin{cfa}
     714switch ( i ) {
     715  case 1$\R{\textvisiblespace}$®...®4:
     716        ...
     717  case 10$\R{\textvisiblespace}$®...®13:
     718        ...
     719}
     720\end{cfa}
     721&
     722\begin{cfa}
     723
     724// 1, 2, 3, 4
     725
     726// 10, 11, 12, 13
     727
     728
     729\end{cfa}
     730\end{tabular}
     731\end{cquote}
     732While ©gcc© has the same range mechanism, it has an awkward syntax, ©2©\R{\textvisiblespace}©...42©, because a space is required after a number, otherwise the period is a decimal point.
     733
     734\CFA also allows lists of subranges.
    703735\begin{cfa}
    704736case ®1~5, 12~21, 35~42®:
     
    771803This situation is better handled by a list of case values \see{\VRef{s:caseClause}}.
    772804While fall-through itself is not a problem, the problem occurs when fall-through is the default, as this semantics is unintuitive to many programmers and is different from most programming languages with a ©switch© statement.
    773 Hence, default fall-through semantics results in a large number of programming errors as programmers often \emph{forget} the ©break© statement at the end of a ©case© clause, resulting in inadvertent fall-through.
     805Hence, default fall-through semantics results in a many programming errors as programmers often \emph{forget} the ©break© statement at the end of a ©case© clause, resulting in inadvertent fall-through.
    774806
    775807\item
     
    848880and there is only a medium amount of fall-through from one ©case© clause to the next, and most of these result from a list of case values executing common code, rather than a sequence of case actions that compound.
    849881\end{itemize}
    850 These observations put into perspective the \CFA changes to the ©switch©.
     882These observations put into perspective the \CFA changes to the ©switch© statement.
    851883\begin{enumerate}
    852884\item
     
    890922\begin{cfa}
    891923switch ( x ) {
    892         ®int i = 0;® $\C{// allowed only at start}$
     924        ®int i = 0;®                                            $\C{// allowed only at start}$
    893925  case 0:
    894926        ...
    895         ®int j = 0;® $\C{// disallowed}$
     927        ®int j = 0;®                                            $\C{// disallowed}$
    896928  case 1:
    897929        {
    898                 ®int k = 0;® $\C{// allowed at different nesting levels}$
     930                ®int k = 0;®                                    $\C{// allowed at different nesting levels}$
    899931                ...
    900           ®case 2:® $\C{// disallow case in nested statements}$
     932          ®case 2:®                                                     $\C{// disallow case in nested statements}$
    901933        }
    902934  ...
     
    909941
    910942The \Indexc{fallthrough} clause may be non-terminating within a \Indexc{case} clause or have a target label to common code from multiple case clauses.
    911 \begin{center}
     943\begin{cquote}
    912944\begin{tabular}{@{}lll@{}}
    913945\begin{cfa}
     
    959991\end{cfa}
    960992\end{tabular}
    961 \end{center}
     993\end{cquote}
    962994The target label must be below the \Indexc{fallthrough} and may not be nested in a control structure, and
    963995the target label must be at the same or higher level as the containing \Indexc{case} clause and located at
     
    966998
    967999\begin{figure}
    968 \begin{tabular}{@{}l@{\hspace{40pt}}|l@{}}
    969 \multicolumn{1}{@{}c@{\hspace{40pt}}|}{loop control} & \multicolumn{1}{c@{}}{output} \\
     1000\begin{tabular}{@{}l@{\hspace{50pt}}|l@{}}
     1001\multicolumn{1}{@{}c@{\hspace{50pt}}|}{loop control} & \multicolumn{1}{c@{}}{output} \\
    9701002\hline
    9711003\begin{cfa}
     
    10851117The \Indexc{for}, \Indexc{while}, and \Indexc{do} loop-control allow an empty conditional, which implies a comparison value of ©1© (true).
    10861118\begin{cfa}
    1087 while ( ®/*empty*/®  )                  $\C{// while ( true )}$
    1088 for ( ®/*empty*/®  )                    $\C{// for ( ; true; )}$
    1089 do ... while ( ®/*empty*/®  )    $\C{// do ... while ( true )}$
     1119while ( ®/* empty */®  )                                $\C{// while ( true )}$
     1120for ( ®/* empty */®  )                                  $\C{// for ( ; true; )}$
     1121do ... while ( ®/* empty */®  )                 $\C{// do ... while ( true )}$
    10901122\end{cfa}
    10911123
     
    11171149If no type is specified for the loop index, it is the type of the high value H (when the low value is implicit) or the low value L.
    11181150\begin{cfa}
    1119 for ( ®5® )                                             $\C{// typeof(5) anonymous-index; 5 is high value}$
    1120 for ( i; ®1.5® ~ 5.5 )                  $\C{// typeof(1.5) i; 1.5 is low value}$
    1121 for ( ®int i®; 0 ~ 10 ~ 2 )             $\C{// int i; type is explicit}$
     1151for ( ®5® )                                                             $\C{// typeof(5) anonymous-index; 5 is high value}$
     1152for ( i; ®1.5® ~ 5.5 )                                  $\C{// typeof(1.5) i; 1.5 is low value}$
     1153for ( ®int i®; 0 ~ 10 ~ 2 )                             $\C{// int i; type is explicit}$
    11221154\end{cfa}
    11231155
     
    11271159H is implicit up-to exclusive range [0,H\R{)}.
    11281160\begin{cfa}
    1129 for ( ®5® )                                             $\C{// for ( typeof(5) i; i < 5; i += 1 )}$
     1161for ( ®5® )                                                             $\C{// for ( typeof(5) i; i < 5; i += 1 )}$
    11301162\end{cfa}
    11311163\item
    11321164©~=© H is implicit up-to inclusive range [0,H\R{]}.
    11331165\begin{cfa}
    1134 for ( ®~=® 5 )                                  $\C{// for ( typeof(5) i; i <= 5; i += 1 )}$
     1166for ( ®~=® 5 )                                                  $\C{// for ( typeof(5) i; i <= 5; i += 1 )}$
    11351167\end{cfa}
    11361168\item
    11371169L ©~©\index{~@©~©} H is explicit up-to exclusive range [L,H\R{)}.
    11381170\begin{cfa}
    1139 for ( 1 ®~® 5 )                                 $\C{// for ( typeof(1) i = 1; i < 5; i += 1 )}$
     1171for ( 1 ®~® 5 )                                                 $\C{// for ( typeof(1) i = 1; i < 5; i += 1 )}$
    11401172\end{cfa}
    11411173\item
    11421174L ©~=©\index{~=@©~=©} H is explicit up-to inclusive range [L,H\R{]}.
    11431175\begin{cfa}
    1144 for ( 1 ®~=® 5 )                                        $\C{// for ( typeof(1) i = 1; i <= 5; i += 1 )}$
     1176for ( 1 ®~=® 5 )                                                $\C{// for ( typeof(1) i = 1; i <= 5; i += 1 )}$
    11451177\end{cfa}
    11461178\item
    11471179L ©-~©\index{-~@©-~©} H is explicit down-to exclusive range [H,L\R{)}, where L and H are implicitly interchanged to make the range down-to.
    11481180\begin{cfa}
    1149 for ( 1 ®-~® 5 )                                        $\C{// for ( typeof(1) i = 5; i > 0; i -= 1 )}$
     1181for ( 1 ®-~® 5 )                                                $\C{// for ( typeof(1) i = 5; i > 0; i -= 1 )}$
    11501182\end{cfa}
    11511183\item
    11521184L ©-~=©\index{-~=@©-~=©} H is explicit down-to inclusive range [H,L\R{]}, where L and H are implicitly interchanged to make the range down-to.
    11531185\begin{cfa}
    1154 for ( 1 ®-~=® 5 )                                       $\C{// for ( typeof(1) i = 5; i >= 0; i -= 1 )}$
     1186for ( 1 ®-~=® 5 )                                               $\C{// for ( typeof(1) i = 5; i >= 0; i -= 1 )}$
    11551187\end{cfa}
    11561188\item
    11571189©@© means put nothing in this field.
    11581190\begin{cfa}
    1159 for ( i; 1 ~ ®@® ~ 2 )                  $\C{// for ( typeof(1) i = 1; \R{/* empty */}; i += 2 )}$
    1160 for ( i; 1 ~ 10 ~ ®@® )                 $\C{// for ( typeof(1) i = 1; i < 10; \R{/* empty */} )}$
    1161 for ( i; 1 ~ ®@® ~ ®@® )                $\C{// for ( typeof(1) i = 1; /*empty*/; \R{/* empty */} )}$
     1191for ( i; 1 ~ ®@® ~ 2 )                                  $\C{// for ( typeof(1) i = 1; \R{/* empty */}; i += 2 )}$
     1192for ( i; 1 ~ 10 ~ ®@® )                                 $\C{// for ( typeof(1) i = 1; i < 10; \R{/* empty */} )}$
     1193for ( i; 1 ~ ®@® ~ ®@® )                                $\C{// for ( typeof(1) i = 1; /*empty*/; \R{/* empty */} )}$
    11621194\end{cfa}
    11631195L cannot be elided for the up-to range, \lstinline{@ ~ 5}, and H for the down-to range, \lstinline{1 -~ @}, because then the loop index is uninitialized.
     
    11661198©:© means low another index.
    11671199\begin{cfa}
    1168 for ( i; 5 ®:® j; 2 ~ 12 ~ 3 )          $\C{// for ( typeof(i) i = 1, j = 2; i < 5 \&\& j < 12; i += 1, j += 3 )}$
     1200for ( i; 5 ®:® j; 2 ~ 12 ~ 3 )                  $\C{// for ( typeof(i) i = 1, j = 2; i < 5 \&\& j < 12; i += 1, j += 3 )}$
    11691201\end{cfa}
    11701202\end{itemize}
    11711203\R{Warning}: specifying the down-to range maybe unexpected because the loop control \emph{implicitly} switches the L and H values (and toggles the increment/decrement for I):
    11721204\begin{cfa}
    1173 for ( i; 1 ~ 10 )       ${\C[1.5in]{// up range}$
    1174 for ( i; 1 -~ 10 )      ${\C{// down range}$
    1175 for ( i; ®10 -~ 1® )    ${\C{// \R{WRONG down range!}}\CRT}$
     1205for ( i; 1 ~ 10 )                                               ${\C{// up range}$
     1206for ( i; 1 -~ 10 )                                              ${\C{// down range}$
     1207for ( i; ®10 -~ 1® )                                    ${\C{// \R{WRONG down range!}}}$
    11761208\end{cfa}
    11771209The reason for this semantics is that the range direction can be toggled by adding/removing the minus, ©'-'©, versus interchanging the L and H expressions, which has a greater chance of introducing errors.
     
    11901222
    11911223\begin{figure}
    1192 \centering
    11931224\begin{lrbox}{\myboxA}
    1194 \begin{cfa}[tabsize=3]
     1225\begin{cfa}[tabsize=4]
    11951226®Compound:® {
    11961227        ®Try:® try {
     
    12221253
    12231254\begin{lrbox}{\myboxB}
    1224 \begin{cfa}[tabsize=3]
     1255\begin{cfa}[tabsize=4]
    12251256{
    12261257
     
    12511282\end{lrbox}
    12521283
    1253 \subfloat[\CFA]{\label{f:CFibonacci}\usebox\myboxA}
     1284\subfloat[C]{\label{f:CFAFibonacciGen}\usebox\myboxB}
    12541285\hspace{3pt}
    12551286\vrule
    12561287\hspace{3pt}
    1257 \subfloat[C]{\label{f:CFAFibonacciGen}\usebox\myboxB}
     1288\subfloat[\CFA]{\label{f:CFibonacci}\usebox\myboxA}
    12581289\caption{Multi-level Exit}
    12591290\label{f:MultiLevelExit}
     
    12891320int a[10];
    12901321\end{cfa}
    1291 \begin{tabular}{@{}lll@{}}
     1322\begin{tabular}{@{}l@{\hspace{3em}}l@{\hspace{3em}}l@{}}
    12921323\begin{cfa}
    12931324
     
    13301361Grouping heterogeneous data into an \newterm{aggregate} (structure/union) is a common programming practice, and aggregates may be nested:
    13311362\begin{cfa}
    1332 struct Person {                                                         $\C{// aggregate}$
    1333         struct Name { char first[20], last[20]; } name $\C{// nesting}$
    1334         struct Address { ... } address                  $\C{// nesting}$
     1363struct Person {                                                 $\C{// aggregate}$
     1364        struct Name {                                           $\C{// nesting}$
     1365                char first[20], last[20];
     1366        } name;
     1367        struct Address {                                        $\C{// nesting}$
     1368                ...
     1369        } address;
    13351370        int sex;
    13361371};
     
    13391374\begin{cfa}
    13401375Person p
    1341 ®p.®name; ®p.®address; ®p.®sex; $\C{// access containing fields}$
     1376®p.®name; ®p.®address; ®p.®sex;                 $\C{// access containing fields}$
    13421377\end{cfa}
    13431378which extends to multiple levels of qualification for nested aggregates and multiple aggregates.
     
    13541389\begin{cfa}
    13551390struct S {
    1356         struct $\R{\LstCommentStyle{/* unnamed */}}$ { int g,  h; } __attribute__(( aligned(64) ));
     1391        struct $\R{\LstCommentStyle{/* unnamed */}}$  { int g,  h; } __attribute__(( aligned(64) ));
    13571392        int tag;
    1358         union $\R{\LstCommentStyle{/* unnamed */}}$ {
     1393        union $\R{\LstCommentStyle{/* unnamed */}}$  {
    13591394                struct { char c1,  c2; } __attribute__(( aligned(128) ));
    13601395                struct { int i1,  i2; };
     
    13701405struct S {
    13711406        char ®c®;   int ®i®;   double ®d®;
    1372         void f( /* S * this */ ) {                              $\C{// implicit ``this'' parameter}$
    1373                 ®c®;   ®i®;   ®d®;                                      $\C{// this->c; this->i; this->d;}$
     1407        void f( /* S * this */ ) {                      $\C{// implicit ``this'' parameter}$
     1408                ®c®;   ®i®;   ®d®;                              $\C{// this->c; this->i; this->d;}$
    13741409        }
    13751410}
     
    13791414\begin{cfa}
    13801415struct T {
    1381         char ®m®;   int ®i®;   double ®n®;              $\C{// derived class variables}$
     1416        char ®m®;   int ®i®;   double ®n®;      $\C{// derived class variables}$
    13821417};
    13831418struct S : public T {
    1384         char ®c®;   int ®i®;   double ®d®;              $\C{// class variables}$
     1419        char ®c®;   int ®i®;   double ®d®;      $\C{// class variables}$
    13851420        void g( double ®d®, T & t ) {
    1386                 d;   ®t®.m;   ®t®.i;   ®t®.n;           $\C{// function parameter}$
    1387                 c;   i;   ®this->®d;   ®S::®d;          $\C{// class S variables}$
    1388                 m;   ®T::®i;   n;                                       $\C{// class T variables}$
     1421                d;   ®t®.m;   ®t®.i;   ®t®.n;   $\C{// function parameter}$
     1422                c;   i;   ®this->®d;   ®S::®d;  $\C{// class S variables}$
     1423                m;   ®T::®i;   n;                               $\C{// class T variables}$
    13891424        }
    13901425};
     
    13961431Hence, the qualified fields become variables with the side-effect that it is simpler to write, easier to read, and optimize field references in a block.
    13971432\begin{cfa}
    1398 void f( S & this ) ®with ( this )® {            $\C{// with statement}$
    1399         ®c®;   ®i®;   ®d®;                                              $\C{// this.c, this.i, this.d}$
     1433void f( S & this ) ®with ( this )® {    $\C{// with statement}$
     1434        ®c®;   ®i®;   ®d®;                                      $\C{// this.c, this.i, this.d}$
    14001435}
    14011436\end{cfa}
    14021437with the generality of opening multiple aggregate-parameters:
    14031438\begin{cfa}
    1404 void g( S & s, T & t ) ®with ( s, t )® {        $\C{// multiple aggregate parameters}$
    1405         c;   ®s.®i;   d;                                                $\C{// s.c, s.i, s.d}$
    1406         m;   ®t.®i;   n;                                                $\C{// t.m, t.i, t.n}$
     1439void g( S & s, T & t ) ®with ( s, t )® {$\C{// multiple aggregate parameters}$
     1440        c;   ®s.®i;   d;                                        $\C{// s.c, s.i, s.d}$
     1441        m;   ®t.®i;   n;                                        $\C{// t.m, t.i, t.n}$
    14071442}
    14081443\end{cfa}
     
    14271462struct R { int ®i®; int j; double ®m®; } r, w;
    14281463with ( r, q ) {
    1429         j + k;                                                                  $\C{// unambiguous, r.j + q.k}$
    1430         m = 5.0;                                                                $\C{// unambiguous, q.m = 5.0}$
    1431         m = 1;                                                                  $\C{// unambiguous, r.m = 1}$
    1432         int a = m;                                                              $\C{// unambiguous, a = r.i }$
    1433         double b = m;                                                   $\C{// unambiguous, b = q.m}$
    1434         int c = r.i + q.i;                                              $\C{// disambiguate with qualification}$
    1435         (double)m;                                                              $\C{// disambiguate with cast}$
     1464        j + k;                                                          $\C{// unambiguous, r.j + q.k}$
     1465        m = 5.0;                                                        $\C{// unambiguous, q.m = 5.0}$
     1466        m = 1;                                                          $\C{// unambiguous, r.m = 1}$
     1467        int a = m;                                                      $\C{// unambiguous, a = r.i }$
     1468        double b = m;                                           $\C{// unambiguous, b = q.m}$
     1469        int c = r.i + q.i;                                      $\C{// disambiguate with qualification}$
     1470        (double)m;                                                      $\C{// disambiguate with cast}$
    14361471}
    14371472\end{cfa}
     
    14411476\begin{cfa}
    14421477with ( r ) {
    1443         i;                                                                              $\C{// unambiguous, r.i}$
     1478        i;                                                                      $\C{// unambiguous, r.i}$
    14441479        with ( q ) {
    1445                 i;                                                                      $\C{// unambiguous, q.i}$
     1480                i;                                                              $\C{// unambiguous, q.i}$
    14461481        }
    14471482}
     
    14501485A cast can also be used to disambiguate among overload variables in a ©with© \emph{expression}:
    14511486\begin{cfa}
    1452 with ( w ) { ... }                                                      $\C{// ambiguous, same name and no context}$
    1453 with ( (Q)w ) { ... }                                           $\C{// unambiguous, cast}$
     1487with ( w ) { ... }                                              $\C{// ambiguous, same name and no context}$
     1488with ( (Q)w ) { ... }                                   $\C{// unambiguous, cast}$
    14541489\end{cfa}
    14551490Because there is no left-side in the ©with© expression to implicitly disambiguate between the ©w© variables, it is necessary to explicitly disambiguate by casting ©w© to type ©Q© or ©R©.
     
    14581493\begin{cfa}
    14591494void f( S & s, char c ) with ( s ) {
    1460         ®s.c = c;®  i = 3;  d = 5.5;                    $\C{// initialize fields}$
     1495        ®s.c = c;®  i = 3;  d = 5.5;            $\C{// initialize fields}$
    14611496}
    14621497\end{cfa}
     
    14641499To solve this problem, parameters \emph{not} explicitly opened are treated like an initialized aggregate:
    14651500\begin{cfa}
    1466 struct Params {                                                         $\C{// s explicitly opened so S \& s elided}$
     1501struct Params {                                                 $\C{// s explicitly opened so S \& s elided}$
    14671502        char c;
    14681503} params;
     
    14831518Transfer of control can be local, within a routine, or non-local, among routines.
    14841519Non-local transfer can cause stack unwinding, \ie non-local routine termination, depending on the kind of raise.
     1520
     1521Currently, \CFA uses macros ©ExceptionDecl© and ©ExceptionInst© to declare and instantiate an exception.
     1522\begin{cfa}
     1523#include <Exception.hfa>
     1524®ExceptionDecl®( E,             // must be global scope
     1525        ... // exception fields
     1526);
     1527try {
     1528        ...
     1529        if ( ... ) ®throwResume® ®ExceptionInst®( E, /* intialization */ );
     1530        if ( ... ) ®throw® ®ExceptionInst®( E, /* intialization */ );
     1531        ...
     1532} ®catchResume®( E * ) { // must be pointer
     1533        ...
     1534} catch( E * ) {
     1535        ...
     1536}
     1537\end{cfa}
     1538
    14851539\begin{cfa}
    14861540exception_t E {}; $\C{// exception type}$
     
    14911545try {
    14921546        f(...);
    1493 } catch( E e ; $boolean-predicate$ ) {          $\C{// termination handler}$
     1547} catch( E e ; $boolean-predicate$ ) {  $\C{// termination handler}$
    14941548        // recover and continue
    14951549} catchResume( E e ; $boolean-predicate$ ) { $\C{// resumption handler}$
     
    15031557The ©catch© and ©catchResume© handlers may appear in any oder.
    15041558However, the ©finally© clause must appear at the end of the ©try© statement.
     1559
     1560
     1561\section{Non-local Exception}
     1562
     1563\begin{cfa}
     1564void main() {
     1565        try {
     1566                _Enable {
     1567                        ... resume(); ...
     1568                }
     1569        } ®catchResume®( E & ) { // should be reference
     1570                ...
     1571        } catch( E & ) {
     1572                ...
     1573        }
     1574}
     1575\end{cfa}
    15051576
    15061577
     
    15681639\begin{cquote}
    15691640\begin{tabular}{@{}l@{\hspace{3em}}l@{}}
    1570 \multicolumn{1}{c@{\hspace{3em}}}{\textbf{\CFA}}        & \multicolumn{1}{c}{\textbf{C}}        \\
     1641\multicolumn{1}{c@{\hspace{3em}}}{\textbf{C}}   & \multicolumn{1}{c}{\textbf{\CFA}}     \\
     1642\begin{cfa}[moredelim={**[is][\color{blue}]{\#}{\#}}]
     1643®int® #*# x1 #[5]#;
     1644®int® #(*#x2#)[5]#;
     1645#int (*#f®( int p )®#)[5]#;
     1646\end{cfa}
     1647&
    15711648\begin{cfa}[moredelim={**[is][\color{blue}]{\#}{\#}}]
    15721649#[5] *# ®int® x1;
    15731650#* [5]# ®int® x2;
    15741651#[* [5] int]# f®( int p )®;
    1575 \end{cfa}
    1576 &
    1577 \begin{cfa}[moredelim={**[is][\color{blue}]{\#}{\#}}]
    1578 ®int® #*# x1 #[5]#;
    1579 ®int® #(*#x2#)[5]#;
    1580 #int (*#f®( int p )®#)[5]#;
    15811652\end{cfa}
    15821653\end{tabular}
     
    15881659\begin{cquote}
    15891660\begin{tabular}{@{}l@{\hspace{3em}}l@{}}
    1590 \multicolumn{1}{c@{\hspace{3em}}}{\textbf{\CFA}}        & \multicolumn{1}{c}{\textbf{C}}        \\
     1661\multicolumn{1}{c@{\hspace{3em}}}{\textbf{C}}   & \multicolumn{1}{c}{\textbf{\CFA}}     \\
     1662\begin{cfa}
     1663int ®*®x, ®*®y;
     1664\end{cfa}
     1665&
    15911666\begin{cfa}
    15921667®*® int x, y;
    1593 \end{cfa}
    1594 &
    1595 \begin{cfa}
    1596 int ®*®x, ®*®y;
    15971668\end{cfa}
    15981669\end{tabular}
     
    16011672\begin{cquote}
    16021673\begin{tabular}{@{}l@{\hspace{3em}}l@{}}
    1603 \multicolumn{1}{c@{\hspace{3em}}}{\textbf{\CFA}}        & \multicolumn{1}{c}{\textbf{C}}        \\
     1674\multicolumn{1}{c@{\hspace{3em}}}{\textbf{C}}   & \multicolumn{1}{c}{\textbf{\CFA}}     \\
     1675\begin{cfa}
     1676int ®*®x, y;
     1677
     1678\end{cfa}
     1679&
    16041680\begin{cfa}
    16051681®*® int x;
    16061682int y;
    1607 \end{cfa}
    1608 &
    1609 \begin{cfa}
    1610 int ®*®x, y;
    1611 
    16121683\end{cfa}
    16131684\end{tabular}
     
    16171688\begin{cquote}
    16181689\begin{tabular}{@{}l@{\hspace{3em}}l@{\hspace{2em}}l@{}}
    1619 \multicolumn{1}{c@{\hspace{3em}}}{\textbf{\CFA}}        & \multicolumn{1}{c@{\hspace{2em}}}{\textbf{C}} \\
     1690\multicolumn{1}{c@{\hspace{3em}}}{\textbf{C}}   & \multicolumn{1}{c@{\hspace{2em}}}{\textbf{\CFA}}      \\
     1691\begin{cfa}
     1692int z[ 5 ];
     1693char * w[ 5 ];
     1694double (* v)[ 5 ];
     1695struct s {
     1696        int f0:3;
     1697        int * f1;
     1698        int * f2[ 5 ]
     1699};
     1700\end{cfa}
     1701&
    16201702\begin{cfa}
    16211703[ 5 ] int z;
     
    16301712&
    16311713\begin{cfa}
    1632 int z[ 5 ];
    1633 char * w[ 5 ];
    1634 double (* v)[ 5 ];
    1635 struct s {
    1636         int f0:3;
    1637         int * f1;
    1638         int * f2[ 5 ]
    1639 };
    1640 \end{cfa}
    1641 &
    1642 \begin{cfa}
    16431714// array of 5 integers
    16441715// array of 5 pointers to char
     
    16561727\begin{cquote}
    16571728\begin{tabular}{@{}l@{\hspace{1em}}l@{\hspace{1em}}l@{}}
    1658 \multicolumn{1}{c@{\hspace{1em}}}{\textbf{\CFA}}        & \multicolumn{1}{c@{\hspace{1em}}}{\textbf{C}} \\
     1729\multicolumn{1}{c@{\hspace{1em}}}{\textbf{C}}   & \multicolumn{1}{c@{\hspace{1em}}}{\textbf{\CFA}}      \\
     1730\begin{cfa}
     1731int const * const x;
     1732const int (* const y)[ 5 ]
     1733\end{cfa}
     1734&
    16591735\begin{cfa}
    16601736const * const int x;
    16611737const * [ 5 ] const int y;
    1662 \end{cfa}
    1663 &
    1664 \begin{cfa}
    1665 int const * const x;
    1666 const int (* const y)[ 5 ]
    16671738\end{cfa}
    16681739&
     
    16771748\begin{cquote}
    16781749\begin{tabular}{@{}l@{\hspace{3em}}l@{\hspace{2em}}l@{}}
    1679 \multicolumn{1}{c@{\hspace{3em}}}{\textbf{\CFA}}        & \multicolumn{1}{c@{\hspace{2em}}}{\textbf{C}} \\
     1750\multicolumn{1}{c@{\hspace{3em}}}{\textbf{C}}   & \multicolumn{1}{c@{\hspace{2em}}}{\textbf{\CFA}}      \\
     1751\begin{cfa}
     1752int extern x[ 5 ];
     1753const int static * y;
     1754\end{cfa}
     1755&
    16801756\begin{cfa}
    16811757extern [ 5 ] int x;
    16821758static * const int y;
    1683 \end{cfa}
    1684 &
    1685 \begin{cfa}
    1686 int extern x[ 5 ];
    1687 const int static * y;
    16881759\end{cfa}
    16891760&
     
    16981769\begin{cquote}
    16991770\begin{tabular}{@{}l@{\hspace{3em}}l@{}}
    1700 \multicolumn{1}{c@{\hspace{3em}}}{\textbf{\CFA}}        & \multicolumn{1}{c}{\textbf{C}}        \\
     1771\multicolumn{1}{c@{\hspace{3em}}}{\textbf{C}}   & \multicolumn{1}{c}{\textbf{\CFA}}     \\
     1772\begin{cfa}
     1773y = (int *)x;
     1774i = sizeof(int * [ 5 ]);
     1775\end{cfa}
     1776&
    17011777\begin{cfa}
    17021778y = (* int)x;
    17031779i = sizeof([ 5 ] * int);
    1704 \end{cfa}
    1705 &
    1706 \begin{cfa}
    1707 y = (int *)x;
    1708 i = sizeof(int * [ 5 ]);
    17091780\end{cfa}
    17101781\end{tabular}
     
    19011972\begin{cquote}
    19021973\begin{tabular}{@{}l@{\hspace{3em}}l@{}}
    1903 \multicolumn{1}{c@{\hspace{3em}}}{\textbf{\CFA}}        & \multicolumn{1}{c}{\textbf{C}}        \\
     1974\multicolumn{1}{c@{\hspace{3em}}}{\textbf{Cy}}  & \multicolumn{1}{c}{\textbf{\CFA}}     \\
     1975\begin{cfa}
     1976const int * ®const® * ®const® ccp;
     1977
     1978\end{cfa}
     1979&
    19041980\begin{cfa}
    19051981®const® * ®const® * const int ccp;
    19061982®const® & ®const® & const int ccr;
    1907 \end{cfa}
    1908 &
    1909 \begin{cfa}
    1910 const int * ®const® * ®const® ccp;
    1911 
    19121983\end{cfa}
    19131984\end{tabular}
     
    20702141\begin{cfa}
    20712142int x, &r = ®x®, f( int & p ); $\C{// lvalue variable (int) convert to reference (int \&)}$
    2072 f( ®x® ); $\C{// lvalue variable (int) convert to reference (int \&)}$
     2143f( ®x® ); $\C{// lvalue variable (int) convert to reference (int \&)}\CRT$
    20732144\end{cfa}
    20742145Conversion can restrict a type, where ©cv1© $\le$ ©cv2©, \eg passing an ©int© to a ©const volatile int &©, which has low cost.
     
    86308701\begin{cquote}
    86318702\begin{tabular}{@{}l@{\hspace{\parindentlnth}}|@{\hspace{\parindentlnth}}l@{}}
    8632 \multicolumn{1}{@{}c|@{\hspace{\parindentlnth}}}{\textbf{\CFA}} & \multicolumn{1}{@{\hspace{\parindentlnth}}c@{}}{\textbf{C}}   \\
     8703\multicolumn{1}{@{}c|@{\hspace{\parindentlnth}}}{\textbf{C}}    & \multicolumn{1}{@{\hspace{\parindentlnth}}c@{}}{\textbf{\CFA}}        \\
    86338704\hline
    8634 \begin{cfa}
    8635 #include <gmp.hfa>$\indexc{gmp}$
    8636 int main( void ) {
    8637         sout | "Factorial Numbers";
    8638         Int fact = 1;
    8639 
    8640         sout | 0 | fact;
    8641         for ( i; 40 ) {
    8642                 fact *= i;
    8643                 sout | i | fact;
    8644         }
    8645 }
    8646 \end{cfa}
    8647 &
    86488705\begin{cfa}
    86498706#include <gmp.h>$\indexc{gmp.h}$
     
    86568713                ®mpz_mul_ui®( fact, fact, i );
    86578714                ®gmp_printf®( "%d %Zd\n", i, fact );
     8715        }
     8716}
     8717\end{cfa}
     8718&
     8719\begin{cfa}
     8720#include <gmp.hfa>$\indexc{gmp}$
     8721int main( void ) {
     8722        sout | "Factorial Numbers";
     8723        Int fact = 1;
     8724
     8725        sout | 0 | fact;
     8726        for ( i; 40 ) {
     8727                fact *= i;
     8728                sout | i | fact;
    86588729        }
    86598730}
Note: See TracChangeset for help on using the changeset viewer.