Changes in / [95b3a9c:5e99a9a]


Ignore:
Files:
11 deleted
30 edited

Legend:

Unmodified
Added
Removed
  • doc/LaTeXmacros/common.tex

    r95b3a9c r5e99a9a  
    1111%% Created On       : Sat Apr  9 10:06:17 2016
    1212%% Last Modified By : Peter A. Buhr
    13 %% Last Modified On : Sun Feb 14 15:52:46 2021
    14 %% Update Count     : 524
     13%% Last Modified On : Thu Jan 28 19:01:57 2021
     14%% Update Count     : 494
    1515%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
    1616
     
    3737
    3838\usepackage{xspace}
    39 \newcommand{\CFAIcon}{\textsf{C}\raisebox{\depth}{\rotatebox{180}{\textsf{A}}}} % Cforall icon
    40 \newcommand{\CFA}{\protect\CFAIcon\xspace}                      % CFA symbolic name
    41 \newcommand{\CFL}{\textrm{Cforall}\xspace}                      % Cforall non-icon name
    42 \newcommand{\Celeven}{\textrm{C11}\xspace}                      % C11 symbolic name
    43 \newcommand{\CCIcon}{\textrm{C}\kern-.1em\hbox{+\kern-.25em+}} % C++ icon
    44 \newcommand{\CC}{\protect\CCIcon\xspace}                        % C++ symbolic name
    45 % numbers disallowed in latex variables names => use number names
    46 \newcommand{\CCeleven}{\protect\CCIcon{11}\xspace}      % C++11 symbolic name
    47 \newcommand{\CCfourteen}{\protect\CCIcon{14}\xspace} % C++14 symbolic name
    48 \newcommand{\CCseventeen}{\protect\CCIcon{17}\xspace} % C++17 symbolic name
    49 \newcommand{\CCtwenty}{\protect\CCIcon{20}\xspace}      % C++20 symbolic name
     39\newcommand{\CFAIcon}{\textsf{C}\raisebox{\depth}{\rotatebox{180}{\textsf{A}}}\xspace} % Cforall symbolic name
     40\newcommand{\CFA}{\protect\CFAIcon}             % safe for section/caption
     41\newcommand{\CFL}{\textrm{Cforall}\xspace} % Cforall symbolic name
     42\newcommand{\Celeven}{\textrm{C11}\xspace} % C11 symbolic name
     43\newcommand{\CC}{\textrm{C}\kern-.1em\hbox{+\kern-.25em+}\xspace} % C++ symbolic name
     44\newcommand{\CCeleven}{\textrm{C}\kern-.1em\hbox{+\kern-.25em+}11\xspace} % C++11 symbolic name
     45\newcommand{\CCfourteen}{\textrm{C}\kern-.1em\hbox{+\kern-.25em+}14\xspace} % C++14 symbolic name
     46\newcommand{\CCseventeen}{\textrm{C}\kern-.1em\hbox{+\kern-.25em+}17\xspace} % C++17 symbolic name
     47\newcommand{\CCtwenty}{\textrm{C}\kern-.1em\hbox{+\kern-.25em+}20\xspace} % C++20 symbolic name
    5048\newcommand{\Csharp}{C\raisebox{-0.7ex}{\Large$^\sharp$}\xspace} % C# symbolic name
    5149
    5250%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
    5351
    54 % remove special-character warning in PDF side-bar names
    5552\makeatletter
    56 \@ifpackageloaded{hyperref}{
    57   \pdfstringdefDisableCommands{
    58   \def\CFA{\CFL}
    59   \def\Celeven{C11\xspace}
    60   \def\CC{C++\xspace}
    61   \def\CCeleven{C++11\xspace}
    62   \def\CCfourteen{C++14\xspace}
    63   \def\CCseventeen{C++17\xspace}
    64   \def\CCtwenty{C++20\xspace}
    65   \def\Csharp{C\#\xspace}
    66   \def\lstinline{\xspace}% must use {} as delimiters, e.g., \lstinline{...}
    67   }{}
    68 }
    69 
    7053% parindent is relative, i.e., toggled on/off in environments like itemize, so store the value for
    7154% use rather than use \parident directly.
     
    9881    \vskip 50\p@
    9982  }}
    100 \renewcommand\section{\@startsection{section}{1}{\z@}{-3.0ex \@plus -1ex \@minus -.2ex}{1.5ex \@plus .2ex}{\normalfont\large\bfseries}}
    101 \renewcommand\subsection{\@startsection{subsection}{2}{\z@}{-2.75ex \@plus -1ex \@minus -.2ex}{1.25ex \@plus .2ex}{\normalfont\normalsize\bfseries}}
     83\renewcommand\section{\@startsection{section}{1}{\z@}{-3.5ex \@plus -1ex \@minus -.2ex}{1.75ex \@plus .2ex}{\normalfont\large\bfseries}}
     84\renewcommand\subsection{\@startsection{subsection}{2}{\z@}{-3.25ex \@plus -1ex \@minus -.2ex}{1.5ex \@plus .2ex}{\normalfont\normalsize\bfseries}}
    10285\renewcommand\subsubsection{\@startsection{subsubsection}{3}{\z@}{-2.5ex \@plus -1ex \@minus -.2ex}{1.0ex \@plus .2ex}{\normalfont\normalsize\bfseries}}
    10386\renewcommand\paragraph{\@startsection{paragraph}{4}{\z@}{-2.0ex \@plus -1ex \@minus -.2ex}{-1em}{\normalfont\normalsize\bfseries}}
     
    146129% The star version does not lowercase the index information, e.g., \newterm*{IBM}.
    147130\newcommand{\newtermFontInline}{\emph}
    148 \newcommand{\newterm}{\protect\@ifstar\@snewterm\@newterm}
     131\newcommand{\newterm}{\@ifstar\@snewterm\@newterm}
    149132\newcommand{\@newterm}[2][\@empty]{\lowercase{\def\temp{#2}}{\newtermFontInline{#2}}\ifx#1\@empty\index{\temp}\else\index{#1@{\protect#2}}\fi}
    150133\newcommand{\@snewterm}[2][\@empty]{{\newtermFontInline{#2}}\ifx#1\@empty\index{#2}\else\index{#1@{\protect#2}}\fi}
     
    252235\newcommand{\LstKeywordStyle}[1]{{\lst@basicstyle{\lst@keywordstyle{#1}}}}
    253236\newcommand{\LstCommentStyle}[1]{{\lst@basicstyle{\lst@commentstyle{#1}}}}
    254 \newcommand{\LstStringStyle}[1]{{\lst@basicstyle{\lst@stringstyle{#1}}}}
    255237
    256238\newlength{\gcolumnposn}                                % temporary hack because lstlisting does not handle tabs correctly
     
    278260xleftmargin=\parindentlnth,                             % indent code to paragraph indentation
    279261extendedchars=true,                                             % allow ASCII characters in the range 128-255
    280 escapechar=\$,                                                  % LaTeX escape in CFA code §...§ (section symbol), emacs: C-q M-'
    281 mathescape=false,                                               % LaTeX math escape in CFA code $...$
     262escapechar=§,                                                   % LaTeX escape in CFA code §...§ (section symbol), emacs: C-q M-'
     263mathescape=true,                                                % LaTeX math escape in CFA code $...$
    282264keepspaces=true,                                                %
    283265showstringspaces=false,                                 % do not show spaces with cup
    284266showlines=true,                                                 % show blank lines at end of code
    285267aboveskip=4pt,                                                  % spacing above/below code block
    286 belowskip=0pt,
     268belowskip=-2pt,
    287269numberstyle=\footnotesize\sf,                   % numbering style
    288270% replace/adjust listing characters that look bad in sanserif
     
    294276
    295277\ifdefined\CFALatin% extra Latin-1 escape characters
    296 \lstnewenvironment{cfa}[1][]{% necessary
     278\lstnewenvironment{cfa}[1][]{
    297279\lstset{
    298280language=CFA,
    299 moredelim=**[is][\color{red}]{@}{@},    % red highlighting @...@
    300 %moredelim=**[is][\color{red}]{®}{®},   % red highlighting ®...® (registered trademark symbol) emacs: C-q M-.
    301 %moredelim=**[is][\color{blue}]{ß}{ß},  % blue highlighting ß...ß (sharp s symbol) emacs: C-q M-_
    302 %moredelim=**[is][\color{OliveGreen}]{¢}{¢}, % green highlighting ¢...¢ (cent symbol) emacs: C-q M-"
    303 %moredelim=[is][\lstset{keywords={}}]{¶}{¶}, % keyword escape ¶...¶ (pilcrow symbol) emacs: C-q M-^
     281moredelim=**[is][\color{red}]{®}{®},    % red highlighting ®...® (registered trademark symbol) emacs: C-q M-.
     282moredelim=**[is][\color{blue}]{ß}{ß},   % blue highlighting ß...ß (sharp s symbol) emacs: C-q M-_
     283moredelim=**[is][\color{OliveGreen}]{¢}{¢}, % green highlighting ¢...¢ (cent symbol) emacs: C-q M-"
     284moredelim=[is][\lstset{keywords={}}]{¶}{¶}, % keyword escape ¶...¶ (pilcrow symbol) emacs: C-q M-^
     285% replace/adjust listing characters that look bad in sanserif
     286add to literate={`}{\ttfamily\upshape\hspace*{-0.1ex}`}1
    304287}% lstset
    305 \lstset{#1}% necessary
     288\lstset{#1}
    306289}{}
    307290% inline code ©...© (copyright symbol) emacs: C-q M-)
    308291\lstMakeShortInline©                                    % single-character for \lstinline
    309292\else% regular ASCI characters
    310 \lstnewenvironment{cfa}[1][]{% necessary
     293\lstnewenvironment{cfa}[1][]{
    311294\lstset{
    312295language=CFA,
     
    315298moredelim=**[is][\color{red}]{@}{@},    % red highlighting @...@
    316299}% lstset
    317 \lstset{#1}% necessary
     300\lstset{#1}
    318301}{}
    319302% inline code @...@ (at symbol)
  • doc/papers/concurrency/mail2

    r95b3a9c r5e99a9a  
    12881288
    12891289
    1290 From: "Wiley Online Proofing" <onlineproofing@eproofing.in>
    1291 To: pabuhr@uwaterloo.ca
    1292 Reply-To: eproofing@wiley.com
    1293 Date: 3 Nov 2020 08:25:06 +0000
    1294 Subject: Action: Proof of SPE_EV_SPE2925 for Software: Practice And Experience ready for review
    1295 
    1296 Dear Dr. Peter Buhr,
    1297 
    1298 The proof of your Software: Practice And Experience article Advanced control-flow in Cforall is now available for review:
    1299 
    1300 Edit Article https://wiley.eproofing.in/Proof.aspx?token=ab7739d5678447fbbe5036f3bcba2445081500061
    1301 
    1302 To review your article, please complete the following steps, ideally within 48 hours*, so we can publish your article as quickly as possible.
    1303 
    1304 1. Open your proof in the online proofing system using the button above.
    1305 2. Check the article for correctness and respond to all queries.For instructions on using the system, please see the "Help" menu in the upper right corner.
    1306 3. Submit your changes by clicking the "Submit" button in the proofing system.
    1307 
    1308 Helpful Tips
    1309 
    1310 *  Your manuscript has been formatted following the style requirements for the journal. Any requested changes that go against journal style will not be made.
    1311 *  Your proof will include queries. These must be replied to using the system before the proof can be submitted.
    1312 *  The only acceptable changes at this stage are corrections to grammatical errors or data accuracy, or to provide higher resolution figure files (if requested by the typesetter).
    1313 *  Any changes to scientific content or authorship will require editorial review and approval.
    1314 *  Once your changes are complete, submit the article after which no additional corrections can be requested.
    1315 *  Most authors complete their corrections within 48 hours. Returning any corrections promptly will accelerate publication of your article.
    1316 
    1317 If you encounter any problems or have questions, please contact the production office at (SPEproofs@wiley.com). For the quickest response, include the journal name and your article ID (found in the subject line) in all correspondence.
    1318 
    1319 Best regards,
    1320 Software: Practice And Experience Production Office
    1321 
    1322 * We appreciate that the COVID-19 pandemic may create conditions for you that make it difficult for you to review your proof within standard timeframes. If you have any problems keeping to this schedule, please reach out to me at (SPEproofs@wiley.com) to discuss alternatives.
    1323 
    1324 
    1325 
    13261290From: "Pacaanas, Joel -" <jpacaanas@wiley.com>
    13271291To: "Peter A. Buhr" <pabuhr@uwaterloo.ca>
     
    13811345
    13821346Since the proof was reset, your added corrections before has also been removed. Please add them back.
     1347
    13831348Please return your corrections at your earliest convenience.
    13841349
     
    14191384Best regards,
    14201385Joel Pacaanas
    1421 
    1422 
    1423 
    1424 Date: Wed, 2 Dec 2020 08:49:52 +0000
    1425 From: <cs-author@wiley.com>
    1426 To: <pabuhr@uwaterloo.ca>
    1427 Subject: Published: Your article is now published in Early View!
    1428 
    1429 Dear Peter Buhr,
    1430 
    1431 Your article Advanced Control-flow and Concurrency in C A in Software: Practice and Experience has the following publication status: Published as Early View
    1432 
    1433 To access your article, please click the following link to register or log in:
    1434 
    1435   https://authorservices.wiley.com/index.html#register
    1436 
    1437 You can also access your published article via this link: http://dx.doi.org/10.1002/spe.2925
    1438 
    1439 If you need any assistance, please click here https://hub.wiley.com/community/support/authorservices to view our Help section.
    1440 
    1441 Sincerely,                                                                                 
    1442 Wiley Author Services
    1443 
    1444 
    1445 Date: Wed, 2 Dec 2020 02:16:23 -0500
    1446 From: <no-reply@copyright.com>
    1447 To: <pabuhr@uwaterloo.ca>
    1448 CC: <SPEproofs@wiley.com>
    1449 Subject: Please submit your publication fee(s) SPE2925
    1450  
    1451 John Wiley and Sons
    1452 Please submit your selection and payment for publication fee(s).
    1453 
    1454 Dear Peter A. Buhr,
    1455 
    1456 Congratulations, your article in Software: Practice and Experience has published online:
    1457 
    1458 Manuscript DOI: 10.1002/spe.2925
    1459 Manuscript ID: SPE2925
    1460 Manuscript Title: Advanced control-flow in Cforall
    1461 Published by: John Wiley and Sons
    1462 
    1463 Please carefully review your publication options. If you wish your colour
    1464 figures to be printed in colour, you must select and pay for that option now
    1465 using the RightsLink e-commerce solution from CCC.
    1466 
    1467   Review my options & pay charges 
    1468   https://oa.copyright.com/apc-payment-ui/overview?id=f46ba36a-2565-4c8d-8865-693bb94d87e5&chargeset=CHARGES 
    1469 
    1470 To review and pay your charge(s), please click here
    1471 <https://oa.copyright.com/apc-payment-ui/overview?id=f46ba36a-2565-4c8d-8865-693bb94d87e5&chargeset=CHARGES>. You
    1472 can also forward this link to another party for processing.
    1473 
    1474 To complete a secure transaction, you will need a RightsLink account
    1475 <https://oa.copyright.com/apc-payment-ui/registration?id=f46ba36a-2565-4c8d-8865-693bb94d87e5&chargeset=CHARGES>. If
    1476 you do not have one already, you will be prompted to register as you are
    1477 checking out your author charges. This is a very quick process; the majority of
    1478 your registration form will be pre-populated automatically with information we
    1479 have already supplied to RightsLink.
    1480 
    1481 If you have any questions about these charges, please contact CCC Customer
    1482 Service <wileysupport@copyright.com> using the information below. Please do not
    1483 reply directly to this email as this is an automated email notification sent
    1484 from an unmonitored account.
    1485 
    1486 Sincerely,
    1487 John Wiley and Sons
    1488        
    1489 Tel.: +1-877-622-5543 / +1-978-646-2777
    1490 wileysupport@copyright.com
    1491 www.copyright.com
    1492        
    1493 Copyright Clearance Center
    1494 RightsLink
    1495        
    1496 This message (including attachments) is confidential, unless marked
    1497 otherwise. It is intended for the addressee(s) only. If you are not an intended
    1498 recipient, please delete it without further distribution and reply to the
    1499 sender that you have received the message in error.
    1500 
    1501 
    1502 
    1503 From: "Pacaanas, Joel -" <jpacaanas@wiley.com>
    1504 To: "Peter A. Buhr" <pabuhr@uwaterloo.ca>
    1505 Subject: RE: Please submit your publication fee(s) SPE2925
    1506 Date: Thu, 3 Dec 2020 08:45:10 +0000
    1507 
    1508 Dear Dr Buhr,
    1509 
    1510 Thank you for your email and concern with regard to the RightsLink account. As
    1511 you have mentioned that all figures will be printed as black and white, then I
    1512 have selected it manually from the system to proceed further.
    1513 
    1514 Best regards,
    1515 Joel
    1516 
    1517 Joel Q. Pacaanas
    1518 Production Editor
    1519 On behalf of Wiley
    1520 Manila
    1521 We partner with global experts to further innovative research.
    1522 
    1523 E-mail: jpacaanas@wiley.com
    1524 Tel: +632 88558618
    1525 Fax: +632 5325 0768
    1526 
    1527 -----Original Message-----
    1528 From: Peter A. Buhr [mailto:pabuhr@uwaterloo.ca]
    1529 Sent: Thursday, December 3, 2020 12:28 AM
    1530 To: SPE Proofs <speproofs@wiley.com>
    1531 Subject: Re: Please submit your publication fee(s) SPE2925
    1532 
    1533 I am trying to complete the forms to submit my publication fee.
    1534 
    1535 I clicked all the boxs to print in Black and White, so there is no fee.
    1536 
    1537 I then am asked to create RightsLink account, which I did.
    1538 
    1539 However, it requires that I click a box agreeing to:
    1540 
    1541    I consent to have my contact information shared with my publisher and/or
    1542    funding organization, as needed, to facilitate APC payment(s), reporting and
    1543    customer care.
    1544 
    1545 I do not agree to this sharing and will not click this button.
    1546 
    1547 How would you like to proceed?
    1548 
    1549 
    1550 
    1551 From: "Pacaanas, Joel -" <jpacaanas@wiley.com>
    1552 To: "Peter A. Buhr" <pabuhr@uwaterloo.ca>
    1553 Subject: RE: Please submit your publication fee(s) SPE2925
    1554 Date: Fri, 4 Dec 2020 07:55:59 +0000
    1555 
    1556 Dear Peter,
    1557 
    1558 Yes, you are now done with this selection.
    1559 
    1560 Thank you.
    1561 
    1562 Best regards,
    1563 Joel
    1564 
    1565 Joel Q. Pacaanas
    1566 Production Editor
    1567 On behalf of Wiley
    1568 Manila
    1569 We partner with global experts to further innovative research.
    1570 
    1571 E-mail: jpacaanas@wiley.com
    1572 Tel: +632 88558618
    1573 Fax: +632 5325 0768
    1574 
    1575 -----Original Message-----
    1576 From: Peter A. Buhr [mailto:pabuhr@uwaterloo.ca]
    1577 Sent: Thursday, December 3, 2020 10:29 PM
    1578 To: Pacaanas, Joel - <jpacaanas@wiley.com>
    1579 Subject: Re: Please submit your publication fee(s) SPE2925
    1580 
    1581     Thank you for your email and concern with regard to the RightsLink
    1582     account. As you have mentioned that all figures will be printed as black and
    1583     white, then I have selected it manually from the system to proceed further.
    1584 
    1585 Just be clear, am I done? Meaning I do not have to go back to that web-page again.
  • doc/theses/andrew_beach_MMath/existing.tex

    r95b3a9c r5e99a9a  
    1 \chapter{\CFA Existing Features}
     1\chapter{\texorpdfstring{\CFA Existing Features}{Cforall Existing Features}}
    22
    33\CFA (C-for-all)~\cite{Cforall} is an open-source project extending ISO C with
     
    1212obvious to the reader.
    1313
    14 \section{Overloading and \lstinline{extern}}
     14\section{\texorpdfstring{Overloading and \lstinline|extern|}{Overloading and extern}}
    1515\CFA has extensive overloading, allowing multiple definitions of the same name
    1616to be defined.~\cite{Moss18}
     
    4242
    4343\section{Reference Type}
    44 \CFA adds a rebindable reference type to C, but more expressive than the \Cpp
     44\CFA adds a rebindable reference type to C, but more expressive than the \CC
    4545reference.  Multi-level references are allowed and act like auto-dereferenced
    4646pointers using the ampersand (@&@) instead of the pointer asterisk (@*@). \CFA
     
    5959
    6060Both constructors and destructors are operators, which means they are just
    61 functions with special operator names rather than type names in \Cpp. The
     61functions with special operator names rather than type names in \CC. The
    6262special operator names may be used to call the functions explicitly (not
    63 allowed in \Cpp for constructors).
     63allowed in \CC for constructors).
    6464
    6565In general, operator names in \CFA are constructed by bracketing an operator
     
    8888matching overloaded destructor @void ^?{}(T &);@ is called.  Without explicit
    8989definition, \CFA creates a default and copy constructor, destructor and
    90 assignment (like \Cpp). It is possible to define constructors/destructors for
     90assignment (like \CC). It is possible to define constructors/destructors for
    9191basic and existing types.
    9292
     
    9494\CFA uses parametric polymorphism to create functions and types that are
    9595defined over multiple types. \CFA polymorphic declarations serve the same role
    96 as \Cpp templates or Java generics. The ``parametric'' means the polymorphism is
     96as \CC templates or Java generics. The ``parametric'' means the polymorphism is
    9797accomplished by passing argument operations to associate \emph{parameters} at
    9898the call site, and these parameters are used in the function to differentiate
     
    134134
    135135Note, a function named @do_once@ is not required in the scope of @do_twice@ to
    136 compile it, unlike \Cpp template expansion. Furthermore, call-site inferencing
     136compile it, unlike \CC template expansion. Furthermore, call-site inferencing
    137137allows local replacement of the most specific parametric functions needs for a
    138138call.
     
    178178}
    179179\end{cfa}
    180 The generic type @node(T)@ is an example of a polymorphic-type usage.  Like \Cpp
     180The generic type @node(T)@ is an example of a polymorphic-type usage.  Like \CC
    181181templates usage, a polymorphic-type usage must specify a type parameter.
    182182
  • doc/theses/andrew_beach_MMath/features.tex

    r95b3a9c r5e99a9a  
    55
    66\section{Virtuals}
    7 Virtual types and casts are not part of the exception system nor are they
    8 required for an exception system. But an object-oriented style hierarchy is a
    9 great way of organizing exceptions so a minimal virtual system has been added
    10 to \CFA.
    11 
    12 The pattern of a simple hierarchy was borrowed from object-oriented
    13 programming was chosen for several reasons.
    14 The first is that it allows new exceptions to be added in user code
    15 and in libraries independently of each other. Another is it allows for
    16 different levels of exception grouping (all exceptions, all IO exceptions or
    17 a particular IO exception). Also it also provides a simple way of passing
    18 data back and forth across the throw.
    19 
    207Virtual types and casts are not required for a basic exception-system but are
    218useful for advanced exception features. However, \CFA is not object-oriented so
    22 there is no obvious concept of virtuals. Hence, to create advanced exception
    23 features for this work, I needed to design and implement a virtual-like
     9there is no obvious concept of virtuals.  Hence, to create advanced exception
     10features for this work, I needed to designed and implemented a virtual-like
    2411system for \CFA.
    2512
    26 % NOTE: Maybe we should but less of the rational here.
    2713Object-oriented languages often organized exceptions into a simple hierarchy,
    2814\eg Java.
     
    4430\end{center}
    4531The hierarchy provides the ability to handle an exception at different degrees
    46 of specificity (left to right). Hence, it is possible to catch a more general
     32of specificity (left to right).  Hence, it is possible to catch a more general
    4733exception-type in higher-level code where the implementation details are
    4834unknown, which reduces tight coupling to the lower-level implementation.
     
    7561While much of the virtual infrastructure is created, it is currently only used
    7662internally for exception handling. The only user-level feature is the virtual
    77 cast, which is the same as the \Cpp \lstinline[language=C++]|dynamic_cast|.
     63cast, which is the same as the \CC \lstinline[language=C++]|dynamic_cast|.
    7864\label{p:VirtualCast}
    7965\begin{cfa}
    8066(virtual TYPE)EXPRESSION
    8167\end{cfa}
    82 Note, the syntax and semantics matches a C-cast, rather than the function-like
    83 \Cpp syntax for special casts. Both the type of @EXPRESSION@ and @TYPE@ must be
    84 a pointer to a virtual type.
    85 The cast dynamically checks if the @EXPRESSION@ type is the same or a subtype
    86 of @TYPE@, and if true, returns a pointer to the
     68Note, the syntax and semantics matches a C-cast, rather than the unusual \CC
     69syntax for special casts. Both the type of @EXPRESSION@ and @TYPE@ must be a
     70pointer to a virtual type. The cast dynamically checks if the @EXPRESSION@ type
     71is the same or a subtype of @TYPE@, and if true, returns a pointer to the
    8772@EXPRESSION@ object, otherwise it returns @0p@ (null pointer).
    8873
     
    9378
    9479Exceptions are defined by the trait system; there are a series of traits, and
    95 if a type satisfies them, then it can be used as an exception. The following
     80if a type satisfies them, then it can be used as an exception.  The following
    9681is the base trait all exceptions need to match.
    9782\begin{cfa}
    9883trait is_exception(exceptT &, virtualT &) {
    99         virtualT const & get_exception_vtable(exceptT *);
     84        virtualT const & @get_exception_vtable@(exceptT *);
    10085};
    10186\end{cfa}
    102 The trait is defined over two types, the exception type and the virtual table
    103 type. This should be one-to-one, each exception type has only one virtual
    104 table type and vice versa. The only assertion in the trait is
    105 @get_exception_vtable@, which takes a pointer of the exception type and
    106 returns a reference to the virtual table type instance.
    107 
    108 The function @get_exception_vtable@ is actually a constant function.
    109 Recardless of the value passed in (including the null pointer) it should
    110 return a reference to the virtual table instance for that type.
    111 The reason it is a function instead of a constant is that it make type
    112 annotations easier to write as you can use the exception type instead of the
    113 virtual table type; which usually has a mangled name.
    114 % Also \CFA's trait system handles functions better than constants and doing
    115 % it this way reduce the amount of boiler plate we need.
    116 
    117 % I did have a note about how it is the programmer's responsibility to make
    118 % sure the function is implemented correctly. But this is true of every
    119 % similar system I know of (except Agda's I guess) so I took it out.
    120 
    121 There are two more traits for exceptions @is_termination_exception@ and
    122 @is_resumption_exception@. They are defined as follows:
    123 
     87The function takes any pointer, including the null pointer, and returns a
     88reference to the virtual-table object. Defining this function also establishes
     89the virtual type and a virtual-table pair to the \CFA type-resolver and
     90promises @exceptT@ is a virtual type and a child of the base exception-type.
     91
     92\PAB{I do not understand this paragraph.}
     93One odd thing about @get_exception_vtable@ is that it should always be a
     94constant function, returning the same value regardless of its argument.  A
     95pointer or reference to the virtual table instance could be used instead,
     96however using a function has some ease of implementation advantages and allows
     97for easier disambiguation because the virtual type name (or the address of an
     98instance that is in scope) can be used instead of the mangled virtual table
     99name.  Also note the use of the word ``promise'' in the trait
     100description. Currently, \CFA cannot check to see if either @exceptT@ or
     101@virtualT@ match the layout requirements. This is considered part of
     102@get_exception_vtable@'s correct implementation.
     103
     104\section{Raise}
     105\CFA provides two kinds of exception raise: termination
     106\see{\VRef{s:Termination}} and resumption \see{\VRef{s:Resumption}}, which are
     107specified with the following traits.
    124108\begin{cfa}
    125109trait is_termination_exception(
    126110                exceptT &, virtualT & | is_exception(exceptT, virtualT)) {
    127         void defaultTerminationHandler(exceptT &);
     111        void @defaultTerminationHandler@(exceptT &);
    128112};
    129 
     113\end{cfa}
     114The function is required to allow a termination raise, but is only called if a
     115termination raise does not find an appropriate handler.
     116
     117Allowing a resumption raise is similar.
     118\begin{cfa}
    130119trait is_resumption_exception(
    131120                exceptT &, virtualT & | is_exception(exceptT, virtualT)) {
    132         void defaultResumptionHandler(exceptT &);
     121        void @defaultResumptionHandler@(exceptT &);
    133122};
    134123\end{cfa}
    135 
    136 In other words they make sure that a given type and virtual type is an
    137 exception and defines one of the two default handlers. These default handlers
    138 are used in the main exception handling operations \see{Exception Handling}
    139 and their use will be detailed there.
    140 
    141 However all three of these traits can be trickly to use directly.
    142 There is a bit of repetition required but
    143 the largest issue is that the virtual table type is mangled and not in a user
    144 facing way. So there are three macros that can be used to wrap these traits
    145 when you need to refer to the names:
    146 @IS_EXCEPTION@, @IS_TERMINATION_EXCEPTION@ and @IS_RESUMPTION_EXCEPTION@.
    147 
    148 All take one or two arguments. The first argument is the name of the
    149 exception type. Its unmangled and mangled form are passed to the trait.
    150 The second (optional) argument is a parenthesized list of polymorphic
    151 arguments. This argument should only with polymorphic exceptions and the
    152 list will be passed to both types.
    153 In the current set-up the base name and the polymorphic arguments have to
    154 match so these macros can be used without losing flexability.
    155 
    156 For example consider a function that is polymorphic over types that have a
    157 defined arithmetic exception:
    158 \begin{cfa}
    159 forall(Num | IS_EXCEPTION(Arithmetic, (Num)))
    160 void some_math_function(Num & left, Num & right);
    161 \end{cfa}
    162 
    163 \section{Exception Handling}
    164 \CFA provides two kinds of exception handling, termination and resumption.
    165 These twin operations are the core of the exception handling mechanism and
    166 are the reason for the features of exceptions.
    167 This section will cover the general patterns shared by the two operations and
    168 then go on to cover the details each individual operation.
    169 
    170 Both operations follow the same set of steps to do their operation. They both
    171 start with the user preforming a throw on an exception.
    172 Then there is the search for a handler, if one is found than the exception
    173 is caught and the handler is run. After that control returns to normal
    174 execution.
    175 
    176 If the search fails a default handler is run and then control
    177 returns to normal execution immediately. That is where the default handlers
    178 @defaultTermiationHandler@ and @defaultResumptionHandler@ are used.
     124The function is required to allow a resumption raise, but is only called if a
     125resumption raise does not find an appropriate handler.
     126
     127Finally there are three convenience macros for referring to the these traits:
     128@IS_EXCEPTION@, @IS_TERMINATION_EXCEPTION@ and @IS_RESUMPTION_EXCEPTION@.  Each
     129takes the virtual type's name, and for polymorphic types only, the
     130parenthesized list of polymorphic arguments. These macros do the name mangling
     131to get the virtual-table name and provide the arguments to both sides
     132\PAB{What's a ``side''?}
    179133
    180134\subsection{Termination}
    181135\label{s:Termination}
    182136
    183 Termination handling is more familiar kind and used in most programming
    184 languages with exception handling.
    185 It is dynamic, non-local goto. If a throw is successful then the stack will
    186 be unwound and control will (usually) continue in a different function on
    187 the call stack. They are commonly used when an error has occured and recovery
    188 is impossible in the current function.
    189 
    190 % (usually) Control can continue in the current function but then a different
    191 % control flow construct should be used.
    192 
    193 A termination throw is started with the @throw@ statement:
     137Termination raise, called ``throw'', is familiar and used in most programming
     138languages with exception handling. The semantics of termination is: search the
     139stack for a matching handler, unwind the stack frames to the matching handler,
     140execute the handler, and continue execution after the handler. Termination is
     141used when execution \emph{cannot} return to the throw. To continue execution,
     142the program must \emph{recover} in the handler from the failed (unwound)
     143execution at the raise to safely proceed after the handler.
     144
     145A termination raise is started with the @throw@ statement:
    194146\begin{cfa}
    195147throw EXPRESSION;
    196148\end{cfa}
    197 The expression must return a reference to a termination exception, where the
    198 termination exception is any type that satifies @is_termination_exception@
    199 at the call site.
    200 Through \CFA's trait system the functions in the traits are passed into the
    201 throw code. A new @defaultTerminationHandler@ can be defined in any scope to
    202 change the throw's behavior (see below).
    203 
    204 The throw will copy the provided exception into managed memory. It is the
    205 user's responcibility to ensure the original exception is cleaned up if the
    206 stack is unwound (allocating it on the stack should be sufficient).
    207 
    208 Then the exception system searches the stack using the copied exception.
    209 It starts starts from the throw and proceeds to the base of the stack,
    210 from callee to caller.
    211 At each stack frame, a check is made for resumption handlers defined by the
    212 @catch@ clauses of a @try@ statement.
     149The expression must return a termination-exception reference, where the
     150termination exception has a type with a @void defaultTerminationHandler(T &)@
     151(default handler) defined. The handler is found at the call site using \CFA's
     152trait system and passed into the exception system along with the exception
     153itself.
     154
     155At runtime, a representation of the exception type and an instance of the
     156exception type is copied into managed memory (heap) to ensure it remains in
     157scope during unwinding. It is the user's responsibility to ensure the original
     158exception object at the throw is freed when it goes out of scope. Being
     159allocated on the stack is sufficient for this.
     160
     161Then the exception system searches the stack starting from the throw and
     162proceeding towards the base of the stack, from callee to caller. At each stack
     163frame, a check is made for termination handlers defined by the @catch@ clauses
     164of a @try@ statement.
    213165\begin{cfa}
    214166try {
    215167        GUARDED_BLOCK
    216 } catch (EXCEPTION_TYPE$\(_1\)$ * NAME$\(_1\)$) {
     168} @catch (EXCEPTION_TYPE$\(_1\)$ * NAME)@ { // termination handler 1
    217169        HANDLER_BLOCK$\(_1\)$
    218 } catch (EXCEPTION_TYPE$\(_2\)$ * NAME$\(_2\)$) {
     170} @catch (EXCEPTION_TYPE$\(_2\)$ * NAME)@ { // termination handler 2
    219171        HANDLER_BLOCK$\(_2\)$
    220172}
    221173\end{cfa}
    222 When viewed on its own a try statement will simply exceute the statements in
    223 @GUARDED_BLOCK@ and when those are finished the try statement finishes.
    224 
    225 However, while the guarded statements are being executed, including any
    226 functions they invoke, all the handlers following the try block are now
    227 or any functions invoked from those
    228 statements, throws an exception, and the exception
     174The statements in the @GUARDED_BLOCK@ are executed. If those statements, or any
     175functions invoked from those statements, throws an exception, and the exception
    229176is not handled by a try statement further up the stack, the termination
    230177handlers are searched for a matching exception type from top to bottom.
     
    232179Exception matching checks the representation of the thrown exception-type is
    233180the same or a descendant type of the exception types in the handler clauses. If
    234 it is the same of a descendent of @EXCEPTION_TYPE@$_i$ then @NAME@$_i$ is
    235 bound to a pointer to the exception and the statements in @HANDLER_BLOCK@$_i$
    236 are executed. If control reaches the end of the handler, the exception is
    237 freed and control continues after the try statement.
    238 
    239 If no handler is found during the search then the default handler is run.
    240 Through \CFA's trait system the best match at the throw sight will be used.
    241 This function is run and is passed the copied exception. After the default
    242 handler is run control continues after the throw statement.
    243 
    244 There is a global @defaultTerminationHandler@ that cancels the current stack
    245 with the copied exception. However it is generic over all exception types so
    246 new default handlers can be defined for different exception types and so
    247 different exception types can have different default handlers.
     181there is a match, a pointer to the exception object created at the throw is
     182bound to @NAME@ and the statements in the associated @HANDLER_BLOCK@ are
     183executed. If control reaches the end of the handler, the exception is freed,
     184and control continues after the try statement.
     185
     186The default handler visible at the throw statement is used if no matching
     187termination handler is found after the entire stack is searched. At that point,
     188the default handler is called with a reference to the exception object
     189generated at the throw. If the default handler returns, the system default
     190action is executed, which often terminates the program. This feature allows
     191each exception type to define its own action, such as printing an informative
     192error message, when an exception is not handled in the program.
    248193
    249194\subsection{Resumption}
    250195\label{s:Resumption}
    251196
    252 Resumption exception handling is a less common form than termination but is
    253 just as old~\cite{Goodenough75} and is in some sense simpler.
    254 It is a dynamic, non-local function call. If the throw is successful a
    255 closure will be taken from up the stack and executed, after which the throwing
    256 function will continue executing.
    257 These are most often used when an error occured and if the error is repaired
    258 then the function can continue.
     197Resumption raise, called ``resume'', is as old as termination
     198raise~\cite{Goodenough75} but is less popular. In many ways, resumption is
     199simpler and easier to understand, as it is simply a dynamic call (as in
     200Lisp). The semantics of resumption is: search the stack for a matching handler,
     201execute the handler, and continue execution after the resume. Notice, the stack
     202cannot be unwound because execution returns to the raise point. Resumption is
     203used used when execution \emph{can} return to the resume. To continue
     204execution, the program must \emph{correct} in the handler for the failed
     205execution at the raise so execution can safely continue after the resume.
    259206
    260207A resumption raise is started with the @throwResume@ statement:
     
    263210\end{cfa}
    264211The semantics of the @throwResume@ statement are like the @throw@, but the
    265 expression has return a reference a type that satifies the trait
    266 @is_resumption_exception@. The assertions from this trait are available to
    267 the exception system while handling the exception.
    268 
    269 At runtime, no copies are made. As the stack is not unwound the exception and
    270 any values on the stack will remain in scope while the resumption is handled.
    271 
    272 Then the exception system searches the stack using the provided exception.
    273 It starts starts from the throw and proceeds to the base of the stack,
    274 from callee to caller.
    275 At each stack frame, a check is made for resumption handlers defined by the
    276 @catchResume@ clauses of a @try@ statement.
     212expression has a type with a @void defaultResumptionHandler(T &)@ (default
     213handler) defined, where the handler is found at the call site by the type
     214system.  At runtime, a representation of the exception type and an instance of
     215the exception type is \emph{not} copied because the stack is maintained during
     216the handler search.
     217
     218Then the exception system searches the stack starting from the resume and
     219proceeding towards the base of the stack, from callee to caller. At each stack
     220frame, a check is made for resumption handlers defined by the @catchResume@
     221clauses of a @try@ statement.
    277222\begin{cfa}
    278223try {
    279224        GUARDED_BLOCK
    280 } catchResume (EXCEPTION_TYPE$\(_1\)$ * NAME$\(_1\)$) {
     225} @catchResume (EXCEPTION_TYPE$\(_1\)$ * NAME)@ { // resumption handler 1
    281226        HANDLER_BLOCK$\(_1\)$
    282 } catchResume (EXCEPTION_TYPE$\(_2\)$ * NAME$\(_2\)$) {
     227} @catchResume (EXCEPTION_TYPE$\(_2\)$ * NAME)@ { // resumption handler 2
    283228        HANDLER_BLOCK$\(_2\)$
    284229}
    285230\end{cfa}
    286 If the handlers are not involved in a search this will simply execute the
    287 @GUARDED_BLOCK@ and then continue to the next statement.
    288 Its purpose is to add handlers onto the stack.
    289 (Note, termination and resumption handlers may be intermixed in a @try@
    290 statement but the kind of throw must be the same as the handler for it to be
    291 considered as a possible match.)
    292 
    293 If a search for a resumption handler reaches a try block it will check each
    294 @catchResume@ clause, top-to-bottom.
    295 At each handler if the thrown exception is or is a child type of
    296 @EXCEPTION_TYPE@$_i$ then the a pointer to the exception is bound to
    297 @NAME@$_i$ and then @HANDLER_BLOCK@$_i$ is executed. After the block is
    298 finished control will return to the @throwResume@ statement.
     231The statements in the @GUARDED_BLOCK@ are executed. If those statements, or any
     232functions invoked from those statements, resumes an exception, and the
     233exception is not handled by a try statement further up the stack, the
     234resumption handlers are searched for a matching exception type from top to
     235bottom. (Note, termination and resumption handlers may be intermixed in a @try@
     236statement but the kind of raise (throw/resume) only matches with the
     237corresponding kind of handler clause.)
     238
     239The exception search and matching for resumption is the same as for
     240termination, including exception inheritance. The difference is when control
     241reaches the end of the handler: the resumption handler returns after the resume
     242rather than after the try statement. The resume point assumes the handler has
     243corrected the problem so execution can safely continue.
    299244
    300245Like termination, if no resumption handler is found, the default handler
    301 visible at the throw statement is called. It will use the best match at the
    302 call sight according to \CFA's overloading rules. The default handler is
    303 passed the exception given to the throw. When the default handler finishes
    304 execution continues after the throw statement.
    305 
    306 There is a global @defaultResumptionHandler@ is polymorphic over all
    307 termination exceptions and preforms a termination throw on the exception.
    308 The @defaultTerminationHandler@ for that throw is matched at the original
    309 throw statement (the resumption @throwResume@) and it can be customized by
    310 introducing a new or better match as well.
    311 
    312 % \subsubsection?
    313 
    314 A key difference between resumption and termination is that resumption does
    315 not unwind the stack. A side effect that is that when a handler is matched
    316 and run it's try block (the guarded statements) and every try statement
    317 searched before it are still on the stack. This can lead to the recursive
    318 resumption problem.
    319 
    320 The recursive resumption problem is any situation where a resumption handler
    321 ends up being called while it is running.
    322 Consider a trivial case:
    323 \begin{cfa}
    324 try {
    325         throwResume (E &){};
    326 } catchResume(E *) {
    327         throwResume (E &){};
    328 }
    329 \end{cfa}
    330 When this code is executed the guarded @throwResume@ will throw, start a
    331 search and match the handler in the @catchResume@ clause. This will be
    332 call and placed on the stack on top of the try-block. The second throw then
    333 throws and will seach the same try block and put call another instance of the
    334 same handler leading to an infinite loop.
    335 
    336 This situation is trivial and easy to avoid, but much more complex cycles
    337 can form with multiple handlers and different exception types.
    338 
    339 To prevent all of these cases we mask sections of the stack, or equvilantly
    340 the try statements on the stack, so that the resumption seach skips over
    341 them and continues with the next unmasked section of the stack.
    342 
    343 A section of the stack is marked when it is searched to see if it contains
    344 a handler for an exception and unmarked when that exception has been handled
    345 or the search was completed without finding a handler.
     246visible at the resume statement is called, and the system default action is
     247executed.
     248
     249For resumption, the exception system uses stack marking to partition the
     250resumption search. If another resumption exception is raised in a resumption
     251handler, the second exception search does not start at the point of the
     252original raise. (Remember the stack is not unwound and the current handler is
     253at the top of the stack.) The search for the second resumption starts at the
     254current point on the stack because new try statements may have been pushed by
     255the handler or functions called from the handler. If there is no match back to
     256the point of the current handler, the search skips\label{p:searchskip} the stack frames already
     257searched by the first resume and continues after the try statement. The default
     258handler always continues from default handler associated with the point where
     259the exception is created.
    346260
    347261% This might need a diagram. But it is an important part of the justification
     
    362276\end{verbatim}
    363277
    364 The rules can be remembered as thinking about what would be searched in
    365 termination. So when a throw happens in a handler; a termination handler
    366 skips everything from the original throw to the original catch because that
    367 part of the stack has been unwound, a resumption handler skips the same
    368 section of stack because it has been masked.
    369 A throw in a default handler will preform the same search as the original
    370 throw because; for termination nothing has been unwound, for resumption
    371 the mask will be the same.
    372 
    373 The symmetry with termination is why this pattern was picked. Other patterns,
    374 such as marking just the handlers that caught, also work but lack the
    375 symmetry whih means there is more to remember.
     278This resumption search-pattern reflect the one for termination, which matches
     279with programmer expectations. However, it avoids the \emph{recursive
     280resumption} problem. If parts of the stack are searched multiple times, loops
     281can easily form resulting in infinite recursion.
     282
     283Consider the trivial case:
     284\begin{cfa}
     285try {
     286        throwResume$\(_1\)$ (E &){};
     287} catch( E * ) {
     288        throwResume;
     289}
     290\end{cfa}
     291Based on termination semantics, programmer expectation is for the re-resume to
     292continue searching the stack frames after the try statement. However, the
     293current try statement is still on the stack below the handler issuing the
     294reresume \see{\VRef{s:Reraise}}. Hence, the try statement catches the re-raise
     295again and does another re-raise \emph{ad infinitum}, which is confusing and
     296difficult to debug. The \CFA resumption search-pattern skips the try statement
     297so the reresume search continues after the try, mathcing programmer
     298expectation.
    376299
    377300\section{Conditional Catch}
    378 Both termination and resumption handler clauses can be given an additional
    379 condition to further control which exceptions they handle:
    380 \begin{cfa}
    381 catch (EXCEPTION_TYPE * NAME ; CONDITION)
     301Both termination and resumption handler-clauses may perform conditional matching:
     302\begin{cfa}
     303catch (EXCEPTION_TYPE * NAME ; @CONDITION@)
    382304\end{cfa}
    383305First, the same semantics is used to match the exception type. Second, if the
    384306exception matches, @CONDITION@ is executed. The condition expression may
    385307reference all names in scope at the beginning of the try block and @NAME@
    386 introduced in the handler clause. If the condition is true, then the handler
    387 matches. Otherwise, the exception search continues as if the exception type
    388 did not match.
     308introduced in the handler clause.  If the condition is true, then the handler
     309matches. Otherwise, the exception search continues at the next appropriate kind
     310of handler clause in the try block.
    389311\begin{cfa}
    390312try {
     
    400322remaining handlers in the current try statement.
    401323
    402 \section{Rethrowing}
    403 \colour{red}{From Andrew: I recomend we talk about why the language doesn't
    404 have rethrows/reraises instead.}
    405 
    406 \label{s:Rethrowing}
     324\section{Reraise}
     325\label{s:Reraise}
    407326Within the handler block or functions called from the handler block, it is
    408327possible to reraise the most recently caught exception with @throw@ or
    409 @throwResume@, respectively.
    410 \begin{cfa}
    411 try {
    412         ...
    413 } catch( ... ) {
    414         ... throw;
     328@throwResume@, respective.
     329\begin{cfa}
     330catch( ... ) {
     331        ... throw; // rethrow
    415332} catchResume( ... ) {
    416         ... throwResume;
     333        ... throwResume; // reresume
    417334}
    418335\end{cfa}
     
    424341handler is generated that does a program-level abort.
    425342
     343
    426344\section{Finally Clauses}
    427 Finally clauses are used to preform unconditional clean-up when leaving a
    428 scope. They are placed at the end of a try statement:
     345A @finally@ clause may be placed at the end of a @try@ statement.
    429346\begin{cfa}
    430347try {
    431348        GUARDED_BLOCK
    432 } ... // any number or kind of handler clauses
    433 ... finally {
     349} ...   // any number or kind of handler clauses
     350} finally {
    434351        FINALLY_BLOCK
    435352}
    436353\end{cfa}
    437 The @FINALLY_BLOCK@ is executed when the try statement is removed from the
    438 stack, including when the @GUARDED_BLOCK@ finishes, any termination handler
    439 finishes or during an unwind.
    440 The only time the block is not executed is if the program is exited before
    441 the stack is unwound.
     354The @FINALLY_BLOCK@ is executed when the try statement is unwound from the
     355stack, \ie when the @GUARDED_BLOCK@ or any handler clause finishes. Hence, the
     356finally block is always executed.
    442357
    443358Execution of the finally block should always finish, meaning control runs off
    444359the end of the block. This requirement ensures always continues as if the
    445360finally clause is not present, \ie finally is for cleanup not changing control
    446 flow. Because of this requirement, local control flow out of the finally block
    447 is forbidden. The compiler precludes any @break@, @continue@, @fallthru@ or
     361flow.  Because of this requirement, local control flow out of the finally block
     362is forbidden.  The compiler precludes any @break@, @continue@, @fallthru@ or
    448363@return@ that causes control to leave the finally block. Other ways to leave
    449364the finally block, such as a long jump or termination are much harder to check,
    450 and at best requiring additional run-time overhead, and so are mearly
    451 discouraged.
    452 
    453 Not all languages with exceptions have finally clauses. Notably \Cpp does
    454 without it as descructors serve a similar role. Although destructors and
    455 finally clauses can be used in many of the same areas they have their own
    456 use cases like top-level functions and lambda functions with closures.
    457 Destructors take a bit more work to set up but are much easier to reuse while
    458 finally clauses are good for once offs and can include local information.
     365and at best requiring additional run-time overhead, and so are discouraged.
    459366
    460367\section{Cancellation}
     
    463370possible forwards the cancellation exception to a different stack.
    464371
    465 Cancellation is not an exception operation like termination or resumption.
    466372There is no special statement for starting a cancellation; instead the standard
    467 library function @cancel_stack@ is called passing an exception. Unlike a
    468 throw, this exception is not used in matching only to pass information about
     373library function @cancel_stack@ is called passing an exception.  Unlike a
     374raise, this exception is not used in matching only to pass information about
    469375the cause of the cancellation.
    470 (This also means matching cannot fail so there is no default handler either.)
    471 
    472 After @cancel_stack@ is called the exception is copied into the exception
    473 handling mechanism's memory. Then the entirety of the current stack is
    474 unwound. After that it depends one which stack is being cancelled.
     376
     377Handling of a cancellation depends on which stack is being cancelled.
    475378\begin{description}
    476379\item[Main Stack:]
    477380The main stack is the one used by the program main at the start of execution,
    478 and is the only stack in a sequential program. Even in a concurrent program
    479 the main stack is only dependent on the environment that started the program.
    480 Hence, when the main stack is cancelled there is nowhere else in the program
    481 to notify. After the stack is unwound, there is a program-level abort.
     381and is the only stack in a sequential program.  Hence, when cancellation is
     382forwarded to the main stack, there is no other forwarding stack, so after the
     383stack is unwound, there is a program-level abort.
    482384
    483385\item[Thread Stack:]
    484386A thread stack is created for a @thread@ object or object that satisfies the
    485 @is_thread@ trait. A thread only has two points of communication that must
     387@is_thread@ trait.  A thread only has two points of communication that must
    486388happen: start and join. As the thread must be running to perform a
    487 cancellation, it must occur after start and before join, so join is used
    488 for communication here.
    489 After the stack is unwound, the thread halts and waits for
    490 another thread to join with it. The joining thread checks for a cancellation,
     389cancellation, it must occur after start and before join, so join is a
     390cancellation point.  After the stack is unwound, the thread halts and waits for
     391another thread to join with it. The joining thread, checks for a cancellation,
    491392and if present, resumes exception @ThreadCancelled@.
    492393
     
    496397the exception is not caught. The implicit join does a program abort instead.
    497398
    498 This semantics is for safety. If an unwind is triggered while another unwind
    499 is underway only one of them can proceed as they both want to ``consume'' the
    500 stack. Letting both try to proceed leads to very undefined behaviour.
    501 Both termination and cancellation involve unwinding and, since the default
    502 @defaultResumptionHandler@ preforms a termination that could more easily
    503 happen in an implicate join inside a destructor. So there is an error message
    504 and an abort instead.
    505 \todo{Perhaps have a more general disucssion of unwind collisions before
    506 this point.}
    507 
    508 The recommended way to avoid the abort is to handle the intial resumption
    509 from the implicate join. If required you may put an explicate join inside a
    510 finally clause to disable the check and use the local
    511 @defaultResumptionHandler@ instead.
     399This semantics is for safety. One difficult problem for any exception system is
     400defining semantics when an exception is raised during an exception search:
     401which exception has priority, the original or new exception? No matter which
     402exception is selected, it is possible for the selected one to disrupt or
     403destroy the context required for the other. \PAB{I do not understand the
     404following sentences.} This loss of information can happen with join but as the
     405thread destructor is always run when the stack is being unwound and one
     406termination/cancellation is already active. Also since they are implicit they
     407are easier to forget about.
    512408
    513409\item[Coroutine Stack:] A coroutine stack is created for a @coroutine@ object
    514 or object that satisfies the @is_coroutine@ trait. A coroutine only knows of
    515 two other coroutines, its starter and its last resumer. Of the two the last
    516 resumer has the tightest coupling to the coroutine it activated and the most
    517 up-to-date information.
    518 
    519 Hence, cancellation of the active coroutine is forwarded to the last resumer
    520 after the stack is unwound. When the resumer restarts, it resumes exception
     410or object that satisfies the @is_coroutine@ trait.  A coroutine only knows of
     411two other coroutines, its starter and its last resumer.  The last resumer has
     412the tightest coupling to the coroutine it activated.  Hence, cancellation of
     413the active coroutine is forwarded to the last resumer after the stack is
     414unwound, as the last resumer has the most precise knowledge about the current
     415execution. When the resumer restarts, it resumes exception
    521416@CoroutineCancelled@, which is polymorphic over the coroutine type and has a
    522417pointer to the cancelled coroutine.
  • doc/theses/andrew_beach_MMath/future.tex

    r95b3a9c r5e99a9a  
    1010\item
    1111The implementation of termination is not portable because it includes
    12 hand-crafted assembly statements. These sections must be ported by hand to
    13 support more hardware architectures, such as the ARM processor.
     12hand-crafted assembly statements. These sections must be generalized to support
     13more hardware architectures, \eg ARM processor.
    1414\item
    1515Due to a type-system problem, the catch clause cannot bind the exception to a
     
    2424scope of the @try@ statement, where the local control-flow transfers are
    2525meaningful.
    26 \item
    27 There is no detection of colliding unwinds. It is possible for clean-up code
    28 run during an unwind to trigger another unwind that escapes the clean-up code
    29 itself; such as a termination exception caught further down the stack or a
    30 cancellation. There do exist ways to handle this but currently they are not
    31 even detected and the first unwind will simply be forgotten, often leaving
    32 it in a bad state.
    33 \item
    34 Also the exception system did not have a lot of time to be tried and tested.
    35 So just letting people use the exception system more will reveal new
    36 quality of life upgrades that can be made with time.
    3726\end{itemize}
    3827
  • doc/theses/andrew_beach_MMath/implement.tex

    r95b3a9c r5e99a9a  
    278278@_URC_END_OF_STACK@.
    279279
    280 Second, when a handler is matched, raise exception continues onto the cleanup
    281 phase.
     280Second, when a handler is matched, raise exception continues onto the cleanup phase.
    282281Once again, it calls the personality functions of each stack frame from newest
    283282to oldest. This pass stops at the stack frame containing the matching handler.
  • doc/theses/andrew_beach_MMath/thesis-frontpgs.tex

    r95b3a9c r5e99a9a  
    3636
    3737        A thesis \\
    38         presented to the University of Waterloo \\
     38        presented to the University of Waterloo \\ 
    3939        in fulfillment of the \\
    4040        thesis requirement for the degree of \\
     
    6464\cleardoublepage
    6565
    66 
     66 
    6767%----------------------------------------------------------------------
    6868% EXAMINING COMMITTEE (Required for Ph.D. theses only)
     
    7171\begin{center}\textbf{Examining Committee Membership}\end{center}
    7272  \noindent
    73 The following served on the Examining Committee for this thesis. The decision
    74 of the Examining Committee is by majority vote.
    75   \bigskip
    76 
    77   \noindent
    78 \begin{tabbing}
    79 Internal-External Member: \=  \kill % using longest text to define tab length
    80 External Examiner: \>  Bruce Bruce \\
     73The following served on the Examining Committee for this thesis. The decision of the Examining Committee is by majority vote.
     74  \bigskip
     75 
     76  \noindent
     77\begin{tabbing}
     78Internal-External Member: \=  \kill % using longest text to define tab length
     79External Examiner: \>  Bruce Bruce \\
    8180\> Professor, Dept. of Philosophy of Zoology, University of Wallamaloo \\
    82 \end{tabbing}
    83   \bigskip
    84 
     81\end{tabbing} 
     82  \bigskip
     83 
    8584  \noindent
    8685\begin{tabbing}
     
    9291\end{tabbing}
    9392  \bigskip
    94 
     93 
    9594  \noindent
    9695  \begin{tabbing}
     
    10099\end{tabbing}
    101100  \bigskip
    102 
     101 
    103102  \noindent
    104103\begin{tabbing}
     
    108107\end{tabbing}
    109108  \bigskip
    110 
     109 
    111110  \noindent
    112111\begin{tabbing}
     
    124123  % December 13th, 2006.  It is designed for an electronic thesis.
    125124  \noindent
    126 I hereby declare that I am the sole author of this thesis. This is a true copy
    127 of the thesis, including any required final revisions, as accepted by my
    128 examiners.
    129 
    130   \bigskip
    131 
     125I hereby declare that I am the sole author of this thesis. This is a true copy of the thesis, including any required final revisions, as accepted by my examiners.
     126
     127  \bigskip
     128 
    132129  \noindent
    133130I understand that my thesis may be made electronically available to the public.
  • doc/theses/andrew_beach_MMath/thesis.tex

    r95b3a9c r5e99a9a  
    4545% FRONT MATERIAL
    4646%----------------------------------------------------------------------
    47 \input{thesis-frontpgs}
     47\input{thesis-frontpgs} 
    4848
    4949%----------------------------------------------------------------------
     
    6565A \gls{computer} could compute $\pi$ all day long. In fact, subsets of digits
    6666of $\pi$'s decimal approximation would make a good source for psuedo-random
    67 vectors, \gls{rvec} .
     67vectors, \gls{rvec} . 
    6868
    6969%----------------------------------------------------------------------
     
    9696
    9797\begin{itemize}
    98 \item A well-prepared PDF should be
     98\item A well-prepared PDF should be 
    9999  \begin{enumerate}
    100100    \item Of reasonable size, {\it i.e.} photos cropped and compressed.
    101     \item Scalable, to allow enlargment of text and drawings.
    102   \end{enumerate}
     101    \item Scalable, to allow enlargment of text and drawings. 
     102  \end{enumerate} 
    103103\item Photos must be bit maps, and so are not scaleable by definition. TIFF and
    104104BMP are uncompressed formats, while JPEG is compressed. Most photos can be
    105105compressed without losing their illustrative value.
    106 \item Drawings that you make should be scalable vector graphics, \emph{not}
     106\item Drawings that you make should be scalable vector graphics, \emph{not} 
    107107bit maps. Some scalable vector file formats are: EPS, SVG, PNG, WMF. These can
    108 all be converted into PNG or PDF, that pdflatex recognizes. Your drawing
    109 package probably can export to one of these formats directly. Otherwise, a
    110 common procedure is to print-to-file through a Postscript printer driver to
    111 create a PS file, then convert that to EPS (encapsulated PS, which has a
    112 bounding box to describe its exact size rather than a whole page).
     108all be converted into PNG or PDF, that pdflatex recognizes. Your drawing 
     109package probably can export to one of these formats directly. Otherwise, a 
     110common procedure is to print-to-file through a Postscript printer driver to 
     111create a PS file, then convert that to EPS (encapsulated PS, which has a 
     112bounding box to describe its exact size rather than a whole page). 
    113113Programs such as GSView (a Ghostscript GUI) can create both EPS and PDF from
    114114PS files. Appendix~\ref{AppendixA} shows how to generate properly sized Matlab
    115115plots and save them as PDF.
    116116\item It's important to crop your photos and draw your figures to the size that
    117 you want to appear in your thesis. Scaling photos with the
    118 includegraphics command will cause loss of resolution. And scaling down
     117you want to appear in your thesis. Scaling photos with the 
     118includegraphics command will cause loss of resolution. And scaling down 
    119119drawings may cause any text annotations to become too small.
    120120\end{itemize}
    121 
     121 
    122122For more information on \LaTeX\, see the uWaterloo Skills for the
    123 Academic Workplace \href{https://uwaterloo.ca/information-systems-technology/services/electronic-thesis-preparation-and-submission-support/ethesis-guide/creating-pdf-version-your-thesis/creating-pdf-files-using-latex/latex-ethesis-and-large-documents}{course notes}.
     123Academic Workplace \href{https://uwaterloo.ca/information-systems-technology/services/electronic-thesis-preparation-and-submission-support/ethesis-guide/creating-pdf-version-your-thesis/creating-pdf-files-using-latex/latex-ethesis-and-large-documents}{course notes}. 
    124124\footnote{
    125125Note that while it is possible to include hyperlinks to external documents,
    126 it is not wise to do so, since anything you can't control may change over time.
    127 It \emph{would} be appropriate and necessary to provide external links to
    128 additional resources for a multimedia ``enhanced'' thesis.
    129 But also note that if the \package{hyperref} package is not included,
    130 as for the print-optimized option in this thesis template, any \cmmd{href}
     126it is not wise to do so, since anything you can't control may change over time. 
     127It \emph{would} be appropriate and necessary to provide external links to 
     128additional resources for a multimedia ``enhanced'' thesis. 
     129But also note that if the \package{hyperref} package is not included, 
     130as for the print-optimized option in this thesis template, any \cmmd{href} 
    131131commands in your logical document are no longer defined.
    132132A work-around employed by this thesis template is to define a dummy
    133 \cmmd{href} command (which does nothing) in the preamble of the document,
    134 before the \package{hyperref} package is included.
     133\cmmd{href} command (which does nothing) in the preamble of the document, 
     134before the \package{hyperref} package is included. 
    135135The dummy definition is then redifined by the
    136136\package{hyperref} package when it is included.
     
    138138
    139139The classic book by Leslie Lamport \cite{lamport.book}, author of \LaTeX , is
    140 worth a look too, and the many available add-on packages are described by
     140worth a look too, and the many available add-on packages are described by 
    141141Goossens \textit{et al} \cite{goossens.book}.
    142142
     
    180180Export Setup button in the figure Property Editor.
    181181
    182 \section{From the Command Line}
     182\section{From the Command Line} 
    183183All figure properties can also be manipulated from the command line. Here's an
    184 example:
     184example: 
    185185\begin{verbatim}
    186186x=[0:0.1:pi];
  • doc/theses/andrew_beach_MMath/unwinding.tex

    r95b3a9c r5e99a9a  
    1 \chapter{Unwinding in \CFA}
     1\chapter{\texorpdfstring{Unwinding in \CFA}{Unwinding in Cforall}}
    22
    33Stack unwinding is the process of removing stack frames (activations) from the
     
    110110alternate transfers of control.
    111111
    112 \section{\CFA Implementation}
     112\section{\texorpdfstring{\CFA Implementation}{Cforall Implementation}}
    113113
    114114To use libunwind, \CFA provides several wrappers, its own storage, personality
  • doc/theses/andrew_beach_MMath/uw-ethesis-frontpgs.tex

    r95b3a9c r5e99a9a  
    1313        \vspace*{1.0cm}
    1414
    15         {\Huge\bf Exception Handling in \CFA}
     15        \Huge
     16        {\bf Exception Handling in \CFA}
    1617
    1718        \vspace*{1.0cm}
    1819
     20        \normalsize
    1921        by \\
    2022
    2123        \vspace*{1.0cm}
    2224
    23         {\Large Andrew James Beach} \\
     25        \Large
     26        Andrew James Beach \\
    2427
    2528        \vspace*{3.0cm}
    2629
     30        \normalsize
    2731        A thesis \\
    28         presented to the University of Waterloo \\
     32        presented to the University of Waterloo \\ 
    2933        in fulfillment of the \\
    3034        thesis requirement for the degree of \\
     
    3943        \vspace*{1.0cm}
    4044
    41         \copyright{} Andrew James Beach \the\year \\
     45        \copyright\ Andrew James Beach \the\year \\
    4246        \end{center}
    4347\end{titlepage}
    4448
    45 % The rest of the front pages should contain no headers and be numbered using
    46 % Roman numerals starting with `ii'.
     49% The rest of the front pages should contain no headers and be numbered using Roman numerals starting with `ii'
    4750\pagestyle{plain}
    4851\setcounter{page}{2}
    4952
    50 \cleardoublepage % Ends the current page and causes all figures and tables
    51 % that have so far appeared in the input to be printed. In a two-sided
    52 % printing style, it also makes the next page a right-hand (odd-numbered)
    53 % page, producing a blank page if necessary.
     53\cleardoublepage % Ends the current page and causes all figures and tables that have so far appeared in the input to be printed.
     54% In a two-sided printing style, it also makes the next page a right-hand (odd-numbered) page, producing a blank page if necessary.
    5455
    55 \begin{comment}
     56\begin{comment} 
    5657% E X A M I N I N G   C O M M I T T E E (Required for Ph.D. theses only)
    5758% Remove or comment out the lines below to remove this page
    5859\begin{center}\textbf{Examining Committee Membership}\end{center}
    5960  \noindent
    60 The following served on the Examining Committee for this thesis.
    61 The decision of the Examining Committee is by majority vote.
     61The following served on the Examining Committee for this thesis. The decision of the Examining Committee is by majority vote.
    6262  \bigskip
    63 
     63 
    6464  \noindent
    6565\begin{tabbing}
    6666Internal-External Member: \=  \kill % using longest text to define tab length
    67 External Examiner: \>  Bruce Bruce \\
     67External Examiner: \>  Bruce Bruce \\ 
    6868\> Professor, Dept. of Philosophy of Zoology, University of Wallamaloo \\
    69 \end{tabbing}
     69\end{tabbing} 
    7070  \bigskip
    71 
     71 
    7272  \noindent
    7373\begin{tabbing}
     
    7979\end{tabbing}
    8080  \bigskip
    81 
     81 
    8282  \noindent
    8383  \begin{tabbing}
     
    8787\end{tabbing}
    8888  \bigskip
    89 
     89 
    9090  \noindent
    9191\begin{tabbing}
     
    9595\end{tabbing}
    9696  \bigskip
    97 
     97 
    9898  \noindent
    9999\begin{tabbing}
     
    111111  % December 13th, 2006.  It is designed for an electronic thesis.
    112112 \begin{center}\textbf{Author's Declaration}\end{center}
    113 
     113 
    114114 \noindent
    115 I hereby declare that I am the sole author of this thesis. This is a true copy
    116 of the thesis, including any required final revisions, as accepted by my
    117 examiners.
     115I hereby declare that I am the sole author of this thesis. This is a true copy of the thesis, including any required final revisions, as accepted by my examiners.
    118116
    119117  \bigskip
    120 
     118 
    121119  \noindent
    122120I understand that my thesis may be made electronically available to the public.
  • doc/theses/andrew_beach_MMath/uw-ethesis.tex

    r95b3a9c r5e99a9a  
    11%======================================================================
    2 % University of Waterloo Thesis Template for LaTeX
    3 % Last Updated November, 2020
    4 % by Stephen Carr, IST Client Services,
     2% University of Waterloo Thesis Template for LaTeX 
     3% Last Updated November, 2020 
     4% by Stephen Carr, IST Client Services, 
    55% University of Waterloo, 200 University Ave. W., Waterloo, Ontario, Canada
    66% FOR ASSISTANCE, please send mail to request@uwaterloo.ca
    77
    88% DISCLAIMER
    9 % To the best of our knowledge, this template satisfies the current uWaterloo
    10 % thesis requirements. However, it is your responsibility to assure that you
    11 % have met all requirements of the University and your particular department.
    12 
    13 % Many thanks for the feedback from many graduates who assisted the
    14 % development of this template. Also note that there are explanatory comments
    15 % and tips throughout this template.
     9% To the best of our knowledge, this template satisfies the current uWaterloo thesis requirements.
     10% However, it is your responsibility to assure that you have met all requirements of the University and your particular department.
     11
     12% Many thanks for the feedback from many graduates who assisted the development of this template.
     13% Also note that there are explanatory comments and tips throughout this template.
    1614%======================================================================
    1715% Some important notes on using this template and making it your own...
    1816
    19 % The University of Waterloo has required electronic thesis submission since
    20 % October 2006. See the uWaterloo thesis regulations at:
    21 %   https://uwaterloo.ca/graduate-studies/thesis.
    22 % This thesis template is geared towards generating a PDF version optimized
    23 % for viewing on an electronic display, including hyperlinks within the PDF.
    24 
    25 % DON'T FORGET TO ADD YOUR OWN NAME AND TITLE in the "hyperref" package
    26 % configuration below. THIS INFORMATION GETS EMBEDDED IN THE FINAL PDF
    27 % DOCUMENT. You can view the information if you view properties of the PDF.
    28 
    29 % Many faculties/departments also require one or more printed copies.
    30 % This template attempts to satisfy both types of output.
     17% The University of Waterloo has required electronic thesis submission since October 2006.
     18% See the uWaterloo thesis regulations at
     19% https://uwaterloo.ca/graduate-studies/thesis.
     20% This thesis template is geared towards generating a PDF version optimized for viewing on an electronic display, including hyperlinks within the PDF.
     21
     22% DON'T FORGET TO ADD YOUR OWN NAME AND TITLE in the "hyperref" package configuration below.
     23% THIS INFORMATION GETS EMBEDDED IN THE PDF FINAL PDF DOCUMENT.
     24% You can view the information if you view properties of the PDF document.
     25
     26% Many faculties/departments also require one or more printed copies.
     27% This template attempts to satisfy both types of output.
    3128% See additional notes below.
    32 % It is based on the standard "book" document class which provides all
    33 % necessary sectioning structures and allows multi-part theses.
    34 
    35 % If you are using this template in Overleaf (cloud-based collaboration
    36 % service), then it is automatically processed and previewed for you as you
    37 % edit.
    38 
    39 % For people who prefer to install their own LaTeX distributions on their own
    40 % computers, and process the source files manually, the following notes
    41 % provide the sequence of tasks:
    42 
     29% It is based on the standard "book" document class which provides all necessary sectioning structures and allows multi-part theses.
     30
     31% If you are using this template in Overleaf (cloud-based collaboration service), then it is automatically processed and previewed for you as you edit.
     32
     33% For people who prefer to install their own LaTeX distributions on their own computers, and process the source files manually, the following notes provide the sequence of tasks:
     34 
    4335% E.g. to process a thesis called "mythesis.tex" based on this template, run:
    4436
    4537% pdflatex mythesis     -- first pass of the pdflatex processor
    4638% bibtex mythesis       -- generates bibliography from .bib data file(s)
    47 % makeindex         -- should be run only if an index is used
    48 % pdflatex mythesis     -- fixes numbering in cross-references, bibliographic
    49 %                      references, glossaries, index, etc.
    50 % pdflatex mythesis     -- it takes a couple of passes to completely process all
    51 %                      cross-references
    52 
    53 % If you use the recommended LaTeX editor, Texmaker, you would open the
    54 % mythesis.tex file, then click the PDFLaTeX button. Then run BibTeX (under
    55 % the Tools menu). Then click the PDFLaTeX button two more times.
    56 % If you have an index as well, you'll need to run MakeIndex from the Tools
    57 % menu as well, before running pdflatex the last two times.
    58 
    59 % N.B. The "pdftex" program allows graphics in the following formats to be
    60 % included with the "\includegraphics" command: PNG, PDF, JPEG, TIFF
    61 % Tip: Generate your figures and photos in the size you want them to appear
    62 % in your thesis, rather than scaling them with \includegraphics options.
    63 % Tip: Any drawings you do should be in scalable vector graphic formats: SVG,
    64 % PNG, WMF, EPS and then converted to PNG or PDF, so they are scalable in the
    65 % final PDF as well.
     39% makeindex         -- should be run only if an index is used
     40% pdflatex mythesis     -- fixes numbering in cross-references, bibliographic references, glossaries, index, etc.
     41% pdflatex mythesis     -- it takes a couple of passes to completely process all cross-references
     42
     43% If you use the recommended LaTeX editor, Texmaker, you would open the mythesis.tex file, then click the PDFLaTeX button. Then run BibTeX (under the Tools menu).
     44% Then click the PDFLaTeX button two more times.
     45% If you have an index as well,you'll need to run MakeIndex from the Tools menu as well, before running pdflatex
     46% the last two times.
     47
     48% N.B. The "pdftex" program allows graphics in the following formats to be included with the "\includegraphics" command: PNG, PDF, JPEG, TIFF
     49% Tip: Generate your figures and photos in the size you want them to appear in your thesis, rather than scaling them with \includegraphics options.
     50% Tip: Any drawings you do should be in scalable vector graphic formats: SVG, PNG, WMF, EPS and then converted to PNG or PDF, so they are scalable in the final PDF as well.
    6651% Tip: Photographs should be cropped and compressed so as not to be too large.
    6752
    68 % To create a PDF output that is optimized for double-sided printing:
    69 % 1) comment-out the \documentclass statement in the preamble below, and
    70 %    un-comment the second \documentclass line.
    71 % 2) change the value assigned below to the boolean variable "PrintVersion"
    72 %    from "false" to "true".
    73 
    74 % ======================================================================
     53% To create a PDF output that is optimized for double-sided printing:
     54% 1) comment-out the \documentclass statement in the preamble below, and un-comment the second \documentclass line.
     55% 2) change the value assigned below to the boolean variable "PrintVersion" from " false" to "true".
     56
     57%======================================================================
    7558%   D O C U M E N T   P R E A M B L E
    76 % Specify the document class, default style attributes, page dimensions, etc.
     59% Specify the document class, default style attributes, and page dimensions, etc.
    7760% For hyperlinked PDF, suitable for viewing on a computer, use this:
    7861\documentclass[letterpaper,12pt,titlepage,oneside,final]{book}
    7962
    80 % For PDF, suitable for double-sided printing, change the PrintVersion
    81 % variable below to "true" and use this \documentclass line instead of the
    82 % one above:
     63% For PDF, suitable for double-sided printing, change the PrintVersion variable below to "true" and use this \documentclass line instead of the one above:
    8364%\documentclass[letterpaper,12pt,titlepage,openright,twoside,final]{book}
    8465
    85 \usepackage{etoolbox}
    86 
    8766% Some LaTeX commands I define for my own nomenclature.
    88 % If you have to, it's easier to make changes to nomenclature once here than
    89 % in a million places throughout your thesis!
     67% If you have to, it's easier to make changes to nomenclature once here than in a million places throughout your thesis!
    9068\newcommand{\package}[1]{\textbf{#1}} % package names in bold text
    91 \newcommand{\cmmd}[1]{\textbackslash\texttt{#1}} % command name in tt font
    92 \newcommand{\href}[1]{#1} % does nothing, but defines the command so the
    93 % print-optimized version will ignore \href tags (redefined by hyperref pkg).
     69\newcommand{\cmmd}[1]{\textbackslash\texttt{#1}} % command name in tt font 
     70\newcommand{\href}[1]{#1} % does nothing, but defines the command so the print-optimized version will ignore \href tags (redefined by hyperref pkg).
     71%\newcommand{\texorpdfstring}[2]{#1} % does nothing, but defines the command
    9472% Anything defined here may be redefined by packages added below...
    9573
     
    9876\newboolean{PrintVersion}
    9977\setboolean{PrintVersion}{false}
    100 % CHANGE THIS VALUE TO "true" as necessary, to improve printed results for
    101 % hard copies by overriding some options of the hyperref package, called below.
     78% CHANGE THIS VALUE TO "true" as necessary, to improve printed results for hard copies by overriding some options of the hyperref package, called below.
    10279
    10380%\usepackage{nomencl} % For a nomenclature (optional; available from ctan.org)
    104 % Lots of math symbols and environments
    105 \usepackage{amsmath,amssymb,amstext}
    106 % For including graphics N.B. pdftex graphics driver
    107 \usepackage[pdftex]{graphicx}
    108 % Removes large sections of the document.
    109 \usepackage{comment}
    110 % Adds todos (Must be included after comment.)
    111 \usepackage{todonotes}
    112 
     81\usepackage{amsmath,amssymb,amstext} % Lots of math symbols and environments
     82\usepackage[pdftex]{graphicx} % For including graphics N.B. pdftex graphics driver
    11383
    11484% Hyperlinks make it very easy to navigate an electronic document.
    115 % In addition, this is where you should specify the thesis title and author as
    116 % they appear in the properties of the PDF document.
     85% In addition, this is where you should specify the thesis title and author as they appear in the properties of the PDF document.
    11786% Use the "hyperref" package
    11887% N.B. HYPERREF MUST BE THE LAST PACKAGE LOADED; ADD ADDITIONAL PKGS ABOVE
    11988\usepackage[pdftex,pagebackref=true]{hyperref} % with basic options
    12089%\usepackage[pdftex,pagebackref=true]{hyperref}
    121 % N.B. pagebackref=true provides links back from the References to the body
    122 % text. This can cause trouble for printing.
     90                % N.B. pagebackref=true provides links back from the References to the body text. This can cause trouble for printing.
    12391\hypersetup{
    12492    plainpages=false,       % needed if Roman numbers in frontpages
     
    12896    pdffitwindow=false,     % window fit to page when opened
    12997    pdfstartview={FitH},    % fits the width of the page to the window
    130 %    pdftitle={uWaterloo\ LaTeX\ Thesis\ Template}, % title: CHANGE THIS TEXT!
     98%    pdftitle={uWaterloo\ LaTeX\ Thesis\ Template},    % title: CHANGE THIS TEXT!
    13199%    pdfauthor={Author},    % author: CHANGE THIS TEXT! and uncomment this line
    132100%    pdfsubject={Subject},  % subject: CHANGE THIS TEXT! and uncomment this line
    133 %    pdfkeywords={keyword1} {key2} {key3}, % optional list of keywords
     101%    pdfkeywords={keyword1} {key2} {key3}, % list of keywords, and uncomment this line if desired
    134102    pdfnewwindow=true,      % links in new window
    135103    colorlinks=true,        % false: boxed links; true: colored links
     
    139107    urlcolor=cyan           % color of external links
    140108}
    141 % for improved print quality, change some hyperref options
    142 \ifthenelse{\boolean{PrintVersion}}{
     109\ifthenelse{\boolean{PrintVersion}}{   % for improved print quality, change some hyperref options
    143110\hypersetup{    % override some previously defined hyperref options
    144111%    colorlinks,%
     
    149116}{} % end of ifthenelse (no else)
    150117
    151 % Exception to the rule of hyperref being the last add-on package
    152 \usepackage[automake,toc,abbreviations]{glossaries-extra}
    153 % If glossaries-extra is not in your LaTeX distribution, get it from CTAN
    154 % (http://ctan.org/pkg/glossaries-extra), although it's supposed to be in
    155 % both the TeX Live and MikTeX distributions. There are also documentation
    156 % and installation instructions there.
     118\usepackage[automake,toc,abbreviations]{glossaries-extra} % Exception to the rule of hyperref being the last add-on package
     119% If glossaries-extra is not in your LaTeX distribution, get it from CTAN (http://ctan.org/pkg/glossaries-extra),
     120% although it's supposed to be in both the TeX Live and MikTeX distributions. There are also documentation and
     121% installation instructions there.
    157122
    158123% Setting up the page margins...
    159 \setlength{\textheight}{9in}
    160 \setlength{\topmargin}{-0.45in}
    161 \setlength{\headsep}{0.25in}
    162 % uWaterloo thesis requirements specify a minimum of 1 inch (72pt) margin at
    163 % the top, bottom, and outside page edges and a 1.125 in. (81pt) gutter margin
    164 % (on binding side). While this is not an issue for electronic viewing, a PDF
    165 % may be printed, and so we have the same page layout for both printed and
    166 % electronic versions, we leave the gutter margin in. Set margins to minimum
    167 % permitted by uWaterloo thesis regulations:
     124\setlength{\textheight}{9in}\setlength{\topmargin}{-0.45in}\setlength{\headsep}{0.25in}
     125% uWaterloo thesis requirements specify a minimum of 1 inch (72pt) margin at the
     126% top, bottom, and outside page edges and a 1.125 in. (81pt) gutter margin (on binding side).
     127% While this is not an issue for electronic viewing, a PDF may be printed, and so we have the same page layout for both printed and electronic versions, we leave the gutter margin in.
     128% Set margins to minimum permitted by uWaterloo thesis regulations:
    168129\setlength{\marginparwidth}{0pt} % width of margin notes
    169130% N.B. If margin notes are used, you must adjust \textwidth, \marginparwidth
    170131% and \marginparsep so that the space left between the margin notes and page
    171132% edge is less than 15 mm (0.6 in.)
    172 % width of space between body text and margin notes
    173 \setlength{\marginparsep}{0pt}
    174 % Adds 1/8 in. to binding side of all
     133\setlength{\marginparsep}{0pt} % width of space between body text and margin notes
     134\setlength{\evensidemargin}{0.125in} % Adds 1/8 in. to binding side of all
    175135% even-numbered pages when the "twoside" printing option is selected
    176 \setlength{\evensidemargin}{0.125in}
    177 % Adds 1/8 in. to the left of all pages when "oneside" printing is selected,
    178 % and to the left of all odd-numbered pages when "twoside" printing is selected
    179 \setlength{\oddsidemargin}{0.125in}
    180 % assuming US letter paper (8.5 in. x 11 in.) and side margins as above
    181 \setlength{\textwidth}{6.375in}
     136\setlength{\oddsidemargin}{0.125in} % Adds 1/8 in. to the left of all pages when "oneside" printing is selected, and to the left of all odd-numbered pages when "twoside" printing is selected
     137\setlength{\textwidth}{6.375in} % assuming US letter paper (8.5 in. x 11 in.) and side margins as above
    182138\raggedbottom
    183139
    184 % The following statement specifies the amount of space between paragraphs.
    185 % Other reasonable specifications are \bigskipamount and \smallskipamount.
     140% The following statement specifies the amount of space between paragraphs. Other reasonable specifications are \bigskipamount and \smallskipamount.
    186141\setlength{\parskip}{\medskipamount}
    187142
    188 % The following statement controls the line spacing.
    189 % The default spacing corresponds to good typographic conventions and only
    190 % slight changes (e.g., perhaps "1.2"), if any, should be made.
     143% The following statement controls the line spacing. 
     144% The default spacing corresponds to good typographic conventions and only slight changes (e.g., perhaps "1.2"), if any, should be made.
    191145\renewcommand{\baselinestretch}{1} % this is the default line space setting
    192146
    193147% By default, each chapter will start on a recto (right-hand side) page.
    194 % We also force each section of the front pages to start on a recto page by
    195 % inserting \cleardoublepage commands. In many cases, this will require that
    196 % the verso (left-hand) page be blank, and while it should be counted, a page
    197 % number should not be printed. The following statements ensure a page number
    198 % is not printed on an otherwise blank verso page.
     148% We also force each section of the front pages to start on a recto page by inserting \cleardoublepage commands.
     149% In many cases, this will require that the verso (left-hand) page be blank, and while it should be counted, a page number should not be printed.
     150% The following statements ensure a page number is not printed on an otherwise blank verso page.
    199151\let\origdoublepage\cleardoublepage
    200152\newcommand{\clearemptydoublepage}{%
     
    202154\let\cleardoublepage\clearemptydoublepage
    203155
    204 % Define Glossary terms (This is properly done here, in the preamble and
    205 % could also be \input{} from a separate file...)
     156% Define Glossary terms (This is properly done here, in the preamble and could also be \input{} from a separate file...)
    206157\input{glossaries}
    207158\makeglossaries
    208159
     160\usepackage{comment}
    209161% cfa macros used in the document
    210162%\usepackage{cfalab}
    211 % I'm going to bring back eventually.
    212 \makeatletter
    213 % Combines all \CC* commands:
    214 \newrobustcmd*\Cpp[1][\xspace]{\cfalab@Cpp#1}
    215 \newcommand\cfalab@Cpp{C\kern-.1em\hbox{+\kern-.25em+}}
    216 % Optional arguments do not work with pdf string. (Some fix-up required.)
    217 \pdfstringdefDisableCommands{\def\Cpp{C++}}
    218 
    219 % Colour text, formatted in LaTeX style instead of TeX style.
    220 \newcommand*\colour[2]{{\color{#1}#2}}
    221 \makeatother
    222 
    223163\input{common}
    224 % CFA code-style for all languages
    225 \CFAStyle
    226 % CFA default lnaguage
    227 \lstset{language=CFA,basicstyle=\linespread{0.9}\tt}
    228 % Annotations from Peter:
     164\CFAStyle                                               % CFA code-style for all languages
     165\lstset{language=CFA,basicstyle=\linespread{0.9}\tt}    % CFA default lnaguage
    229166\newcommand{\PAB}[1]{{\color{blue}PAB: #1}}
    230 % Change the style of abbreviations:
    231 \renewcommand{\abbrevFont}{}
    232167
    233168%======================================================================
    234169%   L O G I C A L    D O C U M E N T
    235170% The logical document contains the main content of your thesis.
    236 % Being a large document, it is a good idea to divide your thesis into several
    237 % files, each one containing one chapter or other significant chunk of content,
    238 % so you can easily shuffle things around later if desired.
     171% Being a large document, it is a good idea to divide your thesis into several files, each one containing one chapter or other significant chunk of content, so you can easily shuffle things around later if desired.
    239172%======================================================================
    240173\begin{document}
     
    243176% FRONT MATERIAL
    244177% title page,declaration, borrowers' page, abstract, acknowledgements,
    245 % dedication, table of contents, list of tables, list of figures,
    246 % nomenclature, etc.
    247 %----------------------------------------------------------------------
    248 \input{uw-ethesis-frontpgs}
     178% dedication, table of contents, list of tables, list of figures, nomenclature, etc.
     179%----------------------------------------------------------------------
     180\input{uw-ethesis-frontpgs}
    249181
    250182%----------------------------------------------------------------------
    251183% MAIN BODY
    252184% We suggest using a separate file for each chapter of your thesis.
    253 % Start each chapter file with the \chapter command. Only use \documentclass,
    254 % \begin{document} and \end{document} commands in this master document.
     185% Start each chapter file with the \chapter command.
     186% Only use \documentclass or \begin{document} and \end{document} commands in this master document.
    255187% Tip: Putting each sentence on a new line is a way to simplify later editing.
    256188%----------------------------------------------------------------------
     
    268200% Bibliography
    269201
    270 % The following statement selects the style to use for references.
    271 % It controls the sort order of the entries in the bibliography and also the
    272 % formatting for the in-text labels.
     202% The following statement selects the style to use for references. 
     203% It controls the sort order of the entries in the bibliography and also the formatting for the in-text labels.
    273204\bibliographystyle{plain}
    274 % This specifies the location of the file containing the bibliographic
    275 % information. It assumes you're using BibTeX to manage your references (if
    276 % not, why not?).
    277 \cleardoublepage % This is needed if the "book" document class is used, to
    278 % place the anchor in the correct page, because the bibliography will start
    279 % on its own page.
    280 % Use \clearpage instead if the document class uses the "oneside" argument.
    281 \phantomsection  % With hyperref package, enables hyperlinking from the table
    282 % of contents to bibliography.
    283 % The following statement causes the title "References" to be used for the
    284 % bibliography section:
     205% This specifies the location of the file containing the bibliographic information. 
     206% It assumes you're using BibTeX to manage your references (if not, why not?).
     207\cleardoublepage % This is needed if the "book" document class is used, to place the anchor in the correct page, because the bibliography will start on its own page.
     208% Use \clearpage instead if the document class uses the "oneside" argument
     209\phantomsection  % With hyperref package, enables hyperlinking from the table of contents to bibliography             
     210% The following statement causes the title "References" to be used for the bibliography section:
    285211\renewcommand*{\bibname}{References}
    286212
     
    289215
    290216\bibliography{uw-ethesis,pl}
    291 % Tip: You can create multiple .bib files to organize your references. Just
    292 % list them all in the \bibliogaphy command, separated by commas (no spaces).
    293 
    294 % The following statement causes the specified references to be added to the
    295 % bibliography even if they were not cited in the text. The asterisk is a
    296 % wildcard that causes all entries in the bibliographic database to be
    297 % included (optional).
     217% Tip: You can create multiple .bib files to organize your references.
     218% Just list them all in the \bibliogaphy command, separated by commas (no spaces).
     219
     220% The following statement causes the specified references to be added to the bibliography even if they were not cited in the text.
     221% The asterisk is a wildcard that causes all entries in the bibliographic database to be included (optional).
    298222% \nocite{*}
    299223%----------------------------------------------------------------------
     
    303227% The \appendix statement indicates the beginning of the appendices.
    304228\appendix
    305 % Add an un-numbered title page before the appendices and a line in the Table
    306 % of Contents
     229% Add an un-numbered title page before the appendices and a line in the Table of Contents
    307230% \chapter*{APPENDICES}
    308231% \addcontentsline{toc}{chapter}{APPENDICES}
    309 % Appendices are just more chapters, with different labeling (letters instead
    310 % of numbers).
     232% Appendices are just more chapters, with different labeling (letters instead of numbers).
    311233% \input{appendix-matlab_plots.tex}
    312234
    313 % GLOSSARIES (Lists of definitions, abbreviations, symbols, etc.
    314 % provided by the glossaries-extra package)
     235% GLOSSARIES (Lists of definitions, abbreviations, symbols, etc. provided by the glossaries-extra package)
    315236% -----------------------------
    316237\printglossaries
  • doc/theses/fangren_yu_COOP_F20/Report.tex

    r95b3a9c r5e99a9a  
    102102\CFA language, developed by the Programming Language Group at the University of Waterloo, has a long history, with the initial language design in 1992 by Glen Ditchfield~\cite{Ditchfield92} and the first proof-of-concept compiler built in 2003 by Richard Bilson~\cite{Bilson03}. Many new features have been added to the language over time, but the core of \CFA's type-system --- parametric functions introduced by the @forall@ clause (hence the name of the language) providing parametric overloading --- remains mostly unchanged.
    103103
    104 The current \CFA reference compiler, @cfa-cc@, is designed using the visitor pattern~\cite{vistorpattern} over an abstract syntax tree (AST), where multiple passes over the AST modify it for subsequent passes. @cfa-cc@ still includes many parts taken directly from the original Bilson implementation, which served as the starting point for this enhancement work to the type system. Unfortunately, the prior implementation did not provide the efficiency required for the language to be practical: a \CFA source file of approximately 1000 lines of code can take multiple minutes to compile. The cause of the problem is that the old compiler used inefficient data structures and algorithms for expression resolution, which involved significant copying and redundant work.
     104The current \CFA reference compiler, @cfa-cc@, is designed using the visitor pattern~\cite{vistorpattern} over an abstract syntax tree (AST), where multiple passes over the AST modify it for subsequent passes. @cfa-cc@ still includes many parts taken directly from the original Bilson implementation, which served as the starting point for this enhancement work to the type system. Unfortunately, the prior implementation did not provide the efficiency required for the language to be practical: a \CFA source file of approximately 1000 lines of code can take a multiple minutes to compile. The cause of the problem is that the old compiler used inefficient data structures and algorithms for expression resolution, which involved significant copying and redundant work.
    105105
    106106This report presents a series of optimizations to the performance-critical parts of the resolver, with a major rework of the compiler data-structures using a functional-programming approach to reduce memory complexity. The improvements were suggested by running the compiler builds with a performance profiler against the \CFA standard-library source-code and a test suite to find the most underperforming components in the compiler algorithm.
     
    122122\end{itemize}
    123123
    124 The resolver algorithm, designed for overload resolution, allows a significant amount of code reused, and hence copying, for the intermediate representations, especially in the following two places:
     124The resolver algorithm, designed for overload resolution, uses a significant amount of reused, and hence copying, for the intermediate representations, especially in the following two places:
    125125\begin{itemize}
    126126\item
     
    301301forall( dtype T | sized( T ) )
    302302T * malloc( void ) { return (T *)malloc( sizeof(T) ); } // call C malloc
    303 int * i = malloc();  // type deduced from left-hand size $\(\Rightarrow\)$ no size argument or return cast
     303int * i = malloc();  // type deduced from left-hand size $\Rightarrow$ no size argument or return cast
    304304\end{cfa}
    305305An unbound return-type is problematic in resolver complexity because a single match of a function call with an unbound return type may create multiple candidates. In the worst case, consider a function declared that returns any @otype@ (defined \VPageref{otype}):
     
    432432\begin{cfa}
    433433void f( int );
    434 double g$\(_1\)$( int );
    435 int g$\(_2\)$( long );
     434double g$_1$( int );
     435int g$_2$( long );
    436436f( g( 42 ) );
    437437\end{cfa}
  • doc/theses/thierry_delisle_PhD/thesis/Makefile

    r95b3a9c r5e99a9a  
    88BibTeX = BIBINPUTS=${TeXLIB} && export BIBINPUTS && bibtex
    99
    10 MAKEFLAGS = --no-print-directory # --silent
     10MAKEFLAGS = --no-print-directory --silent
    1111VPATH = ${Build} ${Figures}
    1212
     
    3232        emptytree \
    3333        fairness \
    34         io_uring \
    35         pivot_ring \
    3634        system \
    3735}
     
    4543## Define the documents that need to be made.
    4644all: thesis.pdf
    47 thesis.pdf: ${TEXTS} ${FIGURES} ${PICTURES} thesis.tex glossary.tex local.bib
     45thesis.pdf: ${TEXTS} ${FIGURES} ${PICTURES} glossary.tex local.bib
    4846
    4947DOCUMENT = thesis.pdf
     
    5149
    5250# Directives #
    53 
    54 .NOTPARALLEL:                                           # cannot make in parallel
    5551
    5652.PHONY : all clean                                      # not file names
     
    8581        ${LaTeX} $<
    8682
     83build/fairness.svg : fig/fairness.py | ${Build}
     84        python3 $< $@
     85
    8786## Define the default recipes.
    8887
     
    106105        sed -i 's/$@/${Build}\/$@/g' ${Build}/$@_t
    107106
    108 build/fairness.svg : fig/fairness.py | ${Build}
    109         python3 $< $@
    110 
    111107## pstex with inverted colors
    112108%.dark.pstex : fig/%.fig Makefile | ${Build}
  • doc/theses/thierry_delisle_PhD/thesis/local.bib

    r95b3a9c r5e99a9a  
    512512}
    513513
    514 @manual{MAN:bsd/kqueue,
    515   title = {KQUEUE(2) - FreeBSD System Calls Manual},
    516   url   = {https://www.freebsd.org/cgi/man.cgi?query=kqueue},
    517   year  = {2020},
    518   month = {may}
    519 }
    520 
    521514% Apple's MAC OS X
    522515@manual{MAN:apple/scheduler,
     
    584577
    585578% --------------------------------------------------
    586 % Man Pages
    587 @manual{MAN:open,
    588   key        = "open",
    589   title      = "open(2) Linux User's Manual",
    590   year       = "2020",
    591   month      = "February",
    592 }
    593 
    594 @manual{MAN:accept,
    595   key        = "accept",
    596   title      = "accept(2) Linux User's Manual",
    597   year       = "2019",
    598   month      = "March",
    599 }
    600 
    601 @manual{MAN:select,
    602   key        = "select",
    603   title      = "select(2) Linux User's Manual",
    604   year       = "2019",
    605   month      = "March",
    606 }
    607 
    608 @manual{MAN:poll,
    609   key        = "poll",
    610   title      = "poll(2) Linux User's Manual",
    611   year       = "2019",
    612   month      = "July",
    613 }
    614 
    615 @manual{MAN:epoll,
    616   key        = "epoll",
    617   title      = "epoll(7) Linux User's Manual",
    618   year       = "2019",
    619   month      = "March",
    620 }
    621 
    622 @manual{MAN:aio,
    623   key        = "aio",
    624   title      = "aio(7) Linux User's Manual",
    625   year       = "2019",
    626   month      = "March",
    627 }
    628 
    629 @misc{MAN:io_uring,
    630   title   = {Efficient IO with io\_uring},
    631   author  = {Axboe, Jens},
    632   year    = "2019",
    633   month   = "March",
    634   version = {0,4},
    635   howpublished = {\url{https://kernel.dk/io_uring.pdf}}
    636 }
    637 
    638 % --------------------------------------------------
    639579% Wikipedia Entries
    640580@misc{wiki:taskparallel,
     
    677617  note = "[Online; accessed 2-January-2021]"
    678618}
    679 
    680 @misc{wiki:future,
    681   author = "{Wikipedia contributors}",
    682   title = "Futures and promises --- {W}ikipedia{,} The Free Encyclopedia",
    683   year = "2020",
    684   url = "https://en.wikipedia.org/wiki/Futures_and_promises",
    685   note = "[Online; accessed 9-February-2021]"
    686 }
  • doc/theses/thierry_delisle_PhD/thesis/text/core.tex

    r95b3a9c r5e99a9a  
    4949
    5050\section{Design}
    51 In general, a na\"{i}ve \glsxtrshort{fifo} ready-queue does not scale with increased parallelism from \glspl{hthrd}, resulting in decreased performance. The problem is adding/removing \glspl{thrd} is a single point of contention. As shown in the evaluation sections, most production schedulers do scale when adding \glspl{hthrd}. The common solution to the single point of contention is to shard the ready-queue so each \gls{hthrd} can access the ready-queue without contention, increasing performance.
     51In general, a na\"{i}ve \glsxtrshort{fifo} ready-queue does not scale with increased parallelism from \glspl{hthrd}, resulting in decreased performance. The problem is adding/removing \glspl{thrd} is a single point of contention. As shown in the evaluation sections, most production schedulers do scale when adding \glspl{hthrd}. The common solution to the single point of contention is to shard the ready-queue so each \gls{hthrd} can access the ready-queue without contention, increasing performance though lack of contention.
    5252
    5353\subsection{Sharding} \label{sec:sharding}
    54 An interesting approach to sharding a queue is presented in \cit{Trevors paper}. This algorithm presents a queue with a relaxed \glsxtrshort{fifo} guarantee using an array of strictly \glsxtrshort{fifo} sublists as shown in Figure~\ref{fig:base}. Each \emph{cell} of the array has a timestamp for the last operation and a pointer to a linked-list with a lock. Each node in the list is marked with a timestamp indicating when it is added to the list. A push operation is done by picking a random cell, acquiring the list lock, and pushing to the list. If the cell is locked, the operation is simply retried on another random cell until a lock is acquired. A pop operation is done in a similar fashion except two random cells are picked. If both cells are unlocked with non-empty lists, the operation pops the node with the oldest timestamp. If one of the cells is unlocked and non-empty, the operation pops from that cell. If both cells are either locked or empty, the operation picks two new random cells and tries again.
     54An interesting approach to sharding a queue is presented in \cit{Trevors paper}. This algorithm presents a queue with a relaxed \glsxtrshort{fifo} guarantee using an array of strictly \glsxtrshort{fifo} sublists as shown in Figure~\ref{fig:base}. Each \emph{cell} of the array has a timestamp for the last operation and a pointer to a linked-list with a lock and each node in the list is marked with a timestamp indicating when it is added to the list. A push operation is done by picking a random cell, acquiring the list lock, and pushing to the list. If the cell is locked, the operation is simply retried on another random cell until a lock is acquired. A pop operation is done in a similar fashion except two random cells are picked. If both cells are unlocked with non-empty lists, the operation pops the node with the oldest cell timestamp. If one of the cells is unlocked and non-empty, the operation pops from that cell. If both cells are either locked or empty, the operation picks two new random cells and tries again.
    5555
    5656\begin{figure}
     
    100100\paragraph{Local Information} Figure~\ref{fig:emptytls} shows an approach using dense information, similar to the bitmap, but each \gls{hthrd} keeps its own independent copy. While this approach can offer good scalability \emph{and} low latency, the liveliness and discovery of the information can become a problem. This case is made worst in systems with few processors where even blind random picks can find \glspl{thrd} in a few tries.
    101101
    102 I built a prototype of these approaches and none of these techniques offer satisfying performance when few threads are present. All of these approach hit the same 2 problems. First, randomly picking sub-queues is very fast. That speed means any improvement to the hit rate can easily be countered by a slow-down in look-up speed, whether or not there are empty lists. Second, the array is already sharded to avoid contention bottlenecks, so any denser data structure tends to become a bottleneck. In all cases, these factors meant the best cases scenario, \ie many threads, would get worst throughput, and the worst-case scenario, few threads, would get a better hit rate, but an equivalent poor throughput. As a result I tried an entirely different approach.
     102I built a prototype of these approaches and none of these techniques offer satisfying performance when few threads are present. All of these approach hit the same 2 problems. First, randomly picking sub-queues is very fast but means any improvement to the hit rate can easily be countered by a slow-down in look-up speed when there are empty lists. Second, the array is already as sharded to avoid contention bottlenecks, so any denser data structure tends to become a bottleneck. In all cases, these factors meant the best cases scenario, \ie many threads, would get worst throughput, and the worst-case scenario, few threads, would get a better hit rate, but an equivalent poor throughput. As a result I tried an entirely different approach.
    103103
    104104\subsection{Dynamic Entropy}\cit{https://xkcd.com/2318/}
    105 In the worst-case scenario there are only few \glspl{thrd} ready to run, or more precisely given $P$ \glspl{proc}\footnote{For simplicity, this assumes there is a one-to-one match between \glspl{proc} and \glspl{hthrd}.}, $T$ \glspl{thrd} and $\epsilon$ a very small number, than the worst case scenario can be represented by $T = P + \epsilon$, with $\epsilon \ll P$. It is important to note in this case that fairness is effectively irrelevant. Indeed, this case is close to \emph{actually matching} the model of the ``Ideal multi-tasking CPU'' on page \pageref{q:LinuxCFS}. In this context, it is possible to use a purely internal-locality based approach and still meet the fairness requirements. This approach simply has each \gls{proc} running a single \gls{thrd} repeatedly. Or from the shared ready-queue viewpoint, each \gls{proc} pushes to a given sub-queue and then pops from the \emph{same} subqueue. The challenge is for the the scheduler to achieve good performance in both the $T = P + \epsilon$ case and the $T \gg P$ case, without affecting the fairness guarantees in the later.
     105In the worst-case scenario there are only few \glspl{thrd} ready to run, or more precisely given $P$ \glspl{proc}\footnote{For simplicity, this assumes there is a one-to-one match between \glspl{proc} and \glspl{hthrd}.}, $T$ \glspl{thrd} and $\epsilon$ a very small number, than the worst case scenario can be represented by $\epsilon \ll P$, than $T = P + \epsilon$. It is important to note in this case that fairness is effectively irrelevant. Indeed, this case is close to \emph{actually matching} the model of the ``Ideal multi-tasking CPU'' on page \pageref{q:LinuxCFS}. In this context, it is possible to use a purely internal-locality based approach and still meet the fairness requirements. This approach simply has each \gls{proc} running a single \gls{thrd} repeatedly. Or from the shared ready-queue viewpoint, each \gls{proc} pushes to a given sub-queue and then popes from the \emph{same} subqueue. In cases where $T \gg P$, the scheduler should also achieves similar performance without affecting the fairness guarantees.
    106106
    107 To handle this case, I use a \glsxtrshort{prng}\todo{Fix missing long form} in a novel way. There exist \glsxtrshort{prng}s that are fast, compact and can be run forward \emph{and} backwards.  Linear congruential generators~\cite{wiki:lcg} are an example of \glsxtrshort{prng}s of such \glsxtrshort{prng}s. The novel approach is to use the ability to run backwards to ``replay'' the \glsxtrshort{prng}. The scheduler uses an exclusive \glsxtrshort{prng} instance per \gls{proc}, the random-number seed effectively starts an encoding that produces a list of all accessed subqueues, from latest to oldest. Replaying the \glsxtrshort{prng} to identify cells accessed recently and which probably have data still cached.
     107To handle this case, I use a pseudo random-number generator, \glsxtrshort{prng} in a novel way. When the scheduler uses a \glsxtrshort{prng} instance per \gls{proc} exclusively, the random-number seed effectively starts an encoding that produces a list of all accessed subqueues, from latest to oldest. The novel approach is to be able to ``replay'' the \glsxtrshort{prng} backwards and there exist \glsxtrshort{prng}s that are fast, compact \emph{and} can be run forward and backwards. Linear congruential generators~\cite{wiki:lcg} are an example of \glsxtrshort{prng}s that match these requirements.
    108108
    109109The algorithm works as follows:
  • doc/theses/thierry_delisle_PhD/thesis/text/intro.tex

    r95b3a9c r5e99a9a  
    77While previous work on the concurrent package of \CFA focused on features and interfaces, this thesis focuses on performance, introducing \glsxtrshort{api} changes only when required by performance considerations. More specifically, this thesis concentrates on scheduling and \glsxtrshort{io}. Prior to this work, the \CFA runtime used a strictly \glsxtrshort{fifo} \gls{rQ}.
    88
    9 This work exclusively concentrates on Linux as it's operating system since the existing \CFA runtime and compiler does not already support other operating systems. Furthermore, as \CFA is yet to be released, supporting version of Linux older than the latest version is not a goal of this work.
     9This work exclusively concentrates on Linux as it's operating system since the existing \CFA runtime and compiler does not already support other operating systems. Furthermore, as \CFA is yet to be released, supporting version of Linux older that the latest version is not a goal of this work.
  • doc/theses/thierry_delisle_PhD/thesis/text/io.tex

    r95b3a9c r5e99a9a  
    1 \chapter{User Level \io}
    2 As mentioned in Section~\ref{prev:io}, User-Level \io requires multiplexing the \io operations of many \glspl{thrd} onto fewer \glspl{proc} using asynchronous \io operations. Different operating systems offer various forms of asynchronous operations and as mentioned in Chapter~\ref{intro}, this work is exclusively focused on the Linux operating-system.
     1\chapter{User Level \glsxtrshort{io}}
     2As mentionned in Section~\ref{prev:io}, User-Level \glsxtrshort{io} requires multiplexing the \glsxtrshort{io} operations of many \glspl{thrd} onto fewer \glspl{proc} using asynchronous \glsxtrshort{io} operations. Various operating systems offer various forms of asynchronous operations and as mentioned in Chapter~\ref{intro}, this work is exclusively focuesd on Linux.
    33
    4 \section{Kernel Interface}
    5 Since this work fundamentally depends on operating-system support, the first step of any design is to discuss the available interfaces and pick one (or more) as the foundations of the non-blocking \io subsystem.
     4\section{Existing options}
     5Since \glsxtrshort{io} operations are generally handled by the
    66
    7 \subsection{\lstinline{O_NONBLOCK}}
    8 In Linux, files can be opened with the flag @O_NONBLOCK@~\cite{MAN:open} (or @SO_NONBLOCK@~\cite{MAN:accept}, the equivalent for sockets) to use the file descriptors in ``nonblocking mode''. In this mode, ``Neither the @open()@ nor any subsequent \io operations on the [opened file descriptor] will cause the calling
    9 process to wait''~\cite{MAN:open}. This feature can be used as the foundation for the non-blocking \io subsystem. However, for the subsystem to know when an \io operation completes, @O_NONBLOCK@ must be use in conjunction with a system call that monitors when a file descriptor becomes ready, \ie, the next \io operation on it does not cause the process to wait\footnote{In this context, ready means \emph{some} operation can be performed without blocking. It does not mean an operation returning \lstinline{EAGAIN} succeeds on the next try. For example, a ready read may only return a subset of bytes and the read must be issues again for the remaining bytes, at which point it may return \lstinline{EAGAIN}.}.
    10 This mechanism is also crucial in determining when all \glspl{thrd} are blocked and the application \glspl{kthrd} can now block.
     7\subsection{\lstinline|epoll|, \lstinline|poll| and \lstinline|select|}
    118
    12 There are three options to monitor file descriptors in Linux\footnote{For simplicity, this section omits \lstinline{pselect} and \lstinline{ppoll}. The difference between these system calls and \lstinline{select} and \lstinline{poll}, respectively, is not relevant for this discussion.}, @select@~\cite{MAN:select}, @poll@~\cite{MAN:poll} and @epoll@~\cite{MAN:epoll}. All three of these options offer a system call that blocks a \gls{kthrd} until at least one of many file descriptors becomes ready. The group of file descriptors being waited is called the \newterm{interest set}.
     9\subsection{Linux's AIO}
    1310
    14 \paragraph{\lstinline{select}} is the oldest of these options, it takes as an input a contiguous array of bits, where each bits represent a file descriptor of interest. On return, it modifies the set in place to identify which of the file descriptors changed status. This destructive change means that calling select in a loop requires re-initializing the array each time and the number of file descriptors supported has a hard limit. Another limit of @select@ is that once the call is started, the interest set can no longer be modified. Monitoring a new file descriptor generally requires aborting any in progress call to @select@\footnote{Starting a new call to \lstinline{select} is possible but requires a distinct kernel thread, and as a result is not an acceptable multiplexing solution when the interest set is large and highly dynamic unless the number of parallel calls to \lstinline{select} can be strictly bounded.}.
    1511
    16 \paragraph{\lstinline{poll}} is an improvement over select, which removes the hard limit on the number of file descriptors and the need to re-initialize the input on every call. It works using an array of structures as an input rather than an array of bits, thus allowing a more compact input for small interest sets. Like @select@, @poll@ suffers from the limitation that the interest set cannot be changed while the call is blocked.
    17 
    18 \paragraph{\lstinline{epoll}} further improves these two functions by allowing the interest set to be dynamically added to and removed from while a \gls{kthrd} is blocked on an @epoll@ call. This dynamic capability is accomplished by creating an \emph{epoll instance} with a persistent interest set, which is used across multiple calls. This capability significantly reduces synchronization overhead on the part of the caller (in this case the \io subsystem), since the interest set can be modified when adding or removing file descriptors without having to synchronize with other \glspl{kthrd} potentially calling @epoll@.
    19 
    20 However, all three of these system calls have limitations. The @man@ page for @O_NONBLOCK@ mentions that ``[@O_NONBLOCK@] has no effect for regular files and block devices'', which means none of these three system calls are viable multiplexing strategies for these types of \io operations. Furthermore, @epoll@ has been shown to have problems with pipes and ttys~\cit{Peter's examples in some fashion}. Finally, none of these are useful solutions for multiplexing \io operations that do not have a corresponding file descriptor and can be awkward for operations using multiple file descriptors.
    21 
    22 \subsection{POSIX asynchronous I/O (AIO)}
    23 An alternative to @O_NONBLOCK@ is the AIO interface. Its interface lets programmers enqueue operations to be performed asynchronously by the kernel. Completions of these operations can be communicated in various ways: either by spawning a new \gls{kthrd}, sending a Linux signal, or by polling for completion of one or more operation. For this work, spawning a new \gls{kthrd} is counter-productive but a related solution is discussed in Section~\ref{io:morethreads}. Using interrupts handlers can also lead to fairly complicated interactions between subsystems. Leaving polling for completion, which is similar to the previous system calls. While AIO only supports read and write operations to file descriptors, it does not have the same limitation as @O_NONBLOCK@, \ie, the file descriptors can be regular files and blocked devices. It also supports batching multiple operations in a single system call.
    24 
    25 AIO offers two different approach to polling: @aio_error@ can be used as a spinning form of polling, returning @EINPROGRESS@ until the operation is completed, and @aio_suspend@ can be used similarly to @select@, @poll@ or @epoll@, to wait until one or more requests have completed. For the purpose of \io multiplexing, @aio_suspend@ is the best interface. However, even if AIO requests can be submitted concurrently, @aio_suspend@ suffers from the same limitation as @select@ and @poll@, \ie, the interest set cannot be dynamically changed while a call to @aio_suspend@ is in progress. AIO also suffers from the limitation of specifying which requests have completed, \ie programmers have to poll each request in the interest set using @aio_error@ to identify the completed requests. This limitation means that, like @select@ and @poll@ but not @epoll@, the time needed to examine polling results increases based on the total number of requests monitored, not the number of completed requests.
    26 Finally, AIO does not seem to be a popular interface, which I believe is due in part to this poor polling interface. Linus Torvalds talks about this interface as follows:
    2712
    2813\begin{displayquote}
    29         AIO is a horrible ad-hoc design, with the main excuse being ``other,
     14        AIO is a horrible ad-hoc design, with the main excuse being "other,
    3015        less gifted people, made that design, and we are implementing it for
    3116        compatibility because database people - who seldom have any shred of
    32         taste - actually use it''.
     17        taste - actually use it".
    3318
    3419        But AIO was always really really ugly.
     
    3924\end{displayquote}
    4025
    41 Interestingly, in this e-mail, Linus goes on to describe
     26Interestingly, in this e-mail answer, Linus goes on to describe
    4227``a true \textit{asynchronous system call} interface''
    4328that does
     
    4530in
    4631``some kind of arbitrary \textit{queue up asynchronous system call} model''.
    47 This description is actually quite close to the interface described in the next section.
     32This description is actually quite close to the interface of the interface described in the next section.
    4833
    49 \subsection{\lstinline{io_uring}}
    50 A very recent addition to Linux, @io_uring@~\cite{MAN:io_uring}, is a framework that aims to solve many of the problems listed in the above interfaces. Like AIO, it represents \io operations as entries added to a queue. But like @epoll@, new requests can be submitted while a blocking call waiting for requests to complete is already in progress. The @io_uring@ interface uses two ring buffers (referred to simply as rings) at its core: a submit ring to which programmers push \io requests and a completion ring from which programmers poll for completion.
    51 
    52 One of the big advantages over the prior interfaces is that @io_uring@ also supports a much wider range of operations. In addition to supporting reads and writes to any file descriptor like AIO, it supports other operations like @open@, @close@, @fsync@, @accept@, @connect@, @send@, @recv@, @splice@, \etc.
    53 
    54 On top of these, @io_uring@ adds many extras like avoiding copies between the kernel and user-space using shared memory, allowing different mechanisms to communicate with device drivers, and supporting chains of requests, \ie, requests that automatically trigger followup requests on completion.
     34\subsection{\texttt{io\_uring}}
     35A very recent addition to Linux, @io_uring@\cit{io\_uring} is a framework that aims to solve many of the problems listed with the above mentioned solutions.
    5536
    5637\subsection{Extra Kernel Threads}\label{io:morethreads}
    57 Finally, if the operating system does not offer a satisfactory form of asynchronous \io operations, an ad-hoc solution is to create a pool of \glspl{kthrd} and delegate operations to it to avoid blocking \glspl{proc}, which is a compromise for multiplexing. In the worst case, where all \glspl{thrd} are consistently blocking on \io, it devolves into 1-to-1 threading. However, regardless of the frequency of \io operations, it achieves the fundamental goal of not blocking \glspl{proc} when \glspl{thrd} are ready to run. This approach is used by languages like Go\cit{Go} and frameworks like libuv\cit{libuv}, since it has the advantage that it can easily be used across multiple operating systems. This advantage is especially relevant for languages like Go, which offer a homogeneous \glsxtrshort{api} across all platforms. As opposed to C, which has a very limited standard api for \io, \eg, the C standard library has no networking.
     38Finally, if the operating system does not offer any satisfying forms of asynchronous \glsxtrshort{io} operations, a solution is to fake it by creating a pool of \glspl{kthrd} and delegating operations to them in order to avoid blocking \glspl{proc}.
    5839
    5940\subsection{Discussion}
    60 These options effectively fall into two broad camps: waiting for \io to be ready versus waiting for \io to complete. All operating systems that support asynchronous \io must offer an interface along one of these lines, but the details vary drastically. For example, Free BSD offers @kqueue@~\cite{MAN:bsd/kqueue}, which behaves similarly to @epoll@, but with some small quality of use improvements, while Windows (Win32)~\cit{https://docs.microsoft.com/en-us/windows/win32/fileio/synchronous-and-asynchronous-i-o} offers ``overlapped I/O'', which handles submissions similarly to @O_NONBLOCK@ with extra flags on the synchronous system call, but waits for completion events, similarly to @io_uring@.
    6141
    62 For this project, I selected @io_uring@, in large parts because to its generality. While @epoll@ has been shown to be a good solution for socket \io (\cite{DBLP:journals/pomacs/KarstenB20}), @io_uring@'s transparent support for files, pipes, and more complex operations, like @splice@ and @tee@, make it a better choice as the foundation for a general \io subsystem.
    6342
    6443\section{Event-Engine}
    65 An event engine's responsibility is to use the kernel interface to multiplex many \io operations onto few \glspl{kthrd}. In concrete terms, this means \glspl{thrd} enter the engine through an interface, the event engines then starts the operation and parks the calling \glspl{thrd}, returning control to the \gls{proc}. The parked \glspl{thrd} are then rescheduled by the event engine once the desired operation has completed.
    66 
    67 \subsection{\lstinline{io_uring} in depth}
    68 Before going into details on the design of my event engine, more details on @io_uring@ usage are presented, each important in the design of the engine.
    69 Figure~\ref{fig:iouring} shows an overview of an @io_uring@ instance.
    70 Two ring buffers are used to communicate with the kernel: one for submissions~(left) and one for completions~(right).
    71 The submission ring contains entries, \newterm{Submit Queue Entries} (SQE), produced (appended) by the application when an operation starts and then consumed by the kernel.
    72 The completion ring contains entries, \newterm{Completion Queue Entries} (CQE), produced (appended) by the kernel when an operation completes and then consumed by the application.
    73 The submission ring contains indexes into the SQE array (denoted \emph{S}) containing entries describing the I/O operation to start;
    74 the completion ring contains entries for the completed I/O operation.
    75 Multiple @io_uring@ instances can be created, in which case they each have a copy of the data structures in the figure.
    76 
    77 \begin{figure}
    78         \centering
    79         \input{io_uring.pstex_t}
    80         \caption{Overview of \lstinline{io_uring}}
    81 %       \caption[Overview of \lstinline{io_uring}]{Overview of \lstinline{io_uring} \smallskip\newline Two ring buffer are used to communicate with the kernel, one for completions~(right) and one for submissions~(left). The completion ring contains entries, \newterm{CQE}s: Completion Queue Entries, that are produced by the kernel when an operation completes and then consumed by the application. On the other hand, the application produces \newterm{SQE}s: Submit Queue Entries, which it appends to the submission ring for the kernel to consume. Unlike the completion ring, the submission ring does not contain the entries directly, it indexes into the SQE array (denoted \emph{S}) instead.}
    82         \label{fig:iouring}
    83 \end{figure}
    84 
    85 New \io operations are submitted to the kernel following 4 steps, which use the components shown in the figure.
    86 \begin{enumerate}
    87 \item
    88 An SQE is allocated from the pre-allocated array (denoted \emph{S} in Figure~\ref{fig:iouring}). This array is created at the same time as the @io_uring@ instance, is in kernel-locked memory visible by both the kernel and the application, and has a fixed size determined at creation. How these entries are allocated is not important for the functioning of @io_uring@, the only requirement is that no entry is reused before the kernel has consumed it.
    89 \item
    90 The SQE is filled according to the desired operation. This step is straight forward, the only detail worth mentioning is that SQEs have a @user_data@ field that must be filled in order to match submission and completion entries.
    91 \item
    92 The SQE is submitted to the submission ring by appending the index of the SQE to the ring following regular ring buffer steps: \lstinline{buffer[head] = item; head++}. Since the head is visible to the kernel, some memory barriers may be required to prevent the compiler from reordering these operations. Since the submission ring is a regular ring buffer, more than one SQE can be added at once and the head is updated only after all entries are updated.
    93 \item
    94 The kernel is notified of the change to the ring using the system call @io_uring_enter@. The number of elements appended to the submission ring is passed as a parameter and the number of elements consumed is returned. The @io_uring@ instance can be constructed so this step is not required, but this requires elevated privilege.% and an early version of @io_uring@ had additional restrictions.
    95 \end{enumerate}
    96 
    97 \begin{sloppypar}
    98 The completion side is simpler: applications call @io_uring_enter@ with the flag @IORING_ENTER_GETEVENTS@ to wait on a desired number of operations to complete. The same call can be used to both submit SQEs and wait for operations to complete. When operations do complete, the kernel appends a CQE to the completion ring and advances the head of the ring. Each CQE contains the result of the operation as well as a copy of the @user_data@ field of the SQE that triggered the operation. It is not necessary to call @io_uring_enter@ to get new events because the kernel can directly modify the completion ring. The system call is only needed if the application wants to block waiting for operations to complete.
    99 \end{sloppypar}
    100 
    101 The @io_uring_enter@ system call is protected by a lock inside the kernel. This protection means that concurrent call to @io_uring_enter@ using the same instance are possible, but there is no performance gained from parallel calls to @io_uring_enter@. It is possible to do the first three submission steps in parallel, however, doing so requires careful synchronization.
    102 
    103 @io_uring@ also introduces constraints on the number of simultaneous operations that can be ``in flight''. Obviously, SQEs are allocated from a fixed-size array, meaning that there is a hard limit to how many SQEs can be submitted at once. In addition, the @io_uring_enter@ system call can fail because ``The  kernel [...] ran out of resources to handle [a request]'' or ``The application is attempting to overcommit the number of requests it can  have  pending.''. This restriction means \io request bursts may have to be subdivided and submitted in chunks at a later time.
    104 
    105 \subsection{Multiplexing \io: Submission}
    106 The submission side is the most complicated aspect of @io_uring@ and its design largely dictates the completion side.
    107 
    108 While it is possible to do the first steps of submission in parallel, the duration of the system call scales with number of entries submitted. The consequence is that the amount of parallelism used to prepare submissions for the next system call is limited. Beyond this limit, the length of the system call is the throughput limiting factor. I concluded from early experiments that preparing submissions seems to take about as long as the system call itself, which means that with a single @io_uring@ instance, there is no benefit in terms of \io throughput to having more than two \glspl{hthrd}. Therefore the design of the submission engine must manage multiple instances of @io_uring@ running in parallel, effectively sharding @io_uring@ instances. Similarly to scheduling, this sharding can be done privately, \ie, one instance per \glspl{proc}, or in decoupled pools, \ie, a pool of \glspl{proc} use a pool of @io_uring@ instances without one-to-one coupling between any given instance and any given \gls{proc}.
    109 
    110 \subsubsection{Pool of Instances}
    111 One approach is to have multiple shared instances. \Glspl{thrd} attempting \io operations pick one of the available instances and submits operations to that instance. Since the completion will be sent to the same instance, all instances with pending operations must be polled continuously\footnote{As will be described in Chapter~\ref{practice}, this does not translate into constant CPU usage.}. Since there is no coupling between \glspl{proc} and @io_uring@ instances in this approach, \glspl{thrd} running on more than one \gls{proc} can attempt to submit to the same instance concurrently. Since @io_uring@ effectively sets the amount of sharding needed to avoid contention on its internal locks, performance in this approach is based on two aspects: the synchronization needed to submit does not induce more contention than @io_uring@ already does and the scheme to route \io requests to specific @io_uring@ instances does not introduce contention. This second aspect has an oversized importance because it comes into play before the sharding of instances, and as such, all \glspl{hthrd} can contend on the routing algorithm.
    112 
    113 Allocation in this scheme can be handled fairly easily. Free SQEs, \ie, SQEs that aren't currently being used to represent a request, can be written to safely and have a field called @user_data@ which the kernel only reads to copy to CQEs. Allocation also requires no ordering guarantee as all free SQEs are interchangeable. This requires a simple concurrent bag. The only added complexity is that the number of SQEs is fixed, which means allocation can fail. This failure needs to be pushed up to the routing algorithm, \glspl{thrd} attempting \io operations must not be directed to @io_uring@ instances without any available SQEs. Ideally, the routing algorithm would block operations up-front if none of the instances have available SQEs.
    114 
    115 Once an SQE is allocated, \glspl{thrd} can fill them normally, they simply need to keep track of the SQE index and which instance it belongs to.
    116 
    117 Once an SQE is filled in, what needs to happen is that the SQE must be added to the submission ring buffer, an operation that is not thread-safe on itself, and the kernel must be notified using the @io_uring_enter@ system call. The submission ring buffer is the same size as the pre-allocated SQE buffer, therefore pushing to the ring buffer cannot fail\footnote{This is because it is invalid to have the same \lstinline{sqe} multiple times in the ring buffer.}. However, as mentioned, the system call itself can fail with the expectation that it will be retried once some of the already submitted operations complete. Since multiple SQEs can be submitted to the kernel at once, it is important to strike a balance between batching and latency. Operations that are ready to be submitted should be batched together in few system calls, but at the same time, operations should not be left pending for long period of times before being submitted. This can be handled by either designating one of the submitting \glspl{thrd} as the being responsible for the system call for the current batch of SQEs or by having some other party regularly submitting all ready SQEs, \eg, the poller \gls{thrd} mentioned later in this section.
    118 
    119 In the case of designating a \gls{thrd}, ideally, when multiple \glspl{thrd} attempt to submit operations to the same @io_uring@ instance, all requests would be batched together and one of the \glspl{thrd} would do the system call on behalf of the others, referred to as the \newterm{submitter}. In practice however, it is important that the \io requests are not left pending indefinitely and as such, it may be required to have a current submitter and a next submitter. Indeed, as long as there is a ``next'' submitter, \glspl{thrd} submitting new \io requests can move on, knowing that some future system call will include their request. Once the system call is done, the submitter must also free SQEs so that the allocator can reused them.
    120 
    121 Finally, the completion side is much simpler since the @io_uring@ system call enforces a natural synchronization point. Polling simply needs to regularly do the system call, go through the produced CQEs and communicate the result back to the originating \glspl{thrd}. Since CQEs only own a signed 32 bit result, in addition to the copy of the @user_data@ field, all that is needed to communicate the result is a simple future~\cite{wiki:future}. If the submission side does not designate submitters, polling can also submit all SQEs as it is polling events.  A simple approach to polling is to allocate a \gls{thrd} per @io_uring@ instance and simply let the poller \glspl{thrd} poll their respective instances when scheduled. This design is especially convenient for reasons explained in Chapter~\ref{practice}.
    122 
    123 With this pool of instances approach, the big advantage is that it is fairly flexible. It does not impose restrictions on what \glspl{thrd} submitting \io operations can and cannot do between allocations and submissions. It also can gracefully handle running out of resources, SQEs or the kernel returning @EBUSY@. The down side to this is that many of the steps used for submitting need complex synchronization to work properly. The routing and allocation algorithm needs to keep track of which ring instances have available SQEs, block incoming requests if no instance is available, prevent barging if \glspl{thrd} are already queued up waiting for SQEs and handle SQEs being freed. The submission side needs to safely append SQEs to the ring buffer, make sure no SQE is dropped or left pending forever, notify the allocation side when SQEs can be reused and handle the kernel returning @EBUSY@. Sharding the @io_uring@ instances should alleviate much of the contention caused by this, but all this synchronization may still have non-zero cost.
    124 
    125 \subsubsection{Private Instances}
    126 Another approach is to simply create one ring instance per \gls{proc}. This alleviate the need for synchronization on the submissions, requiring only that \glspl{thrd} are not interrupted in between two submission steps. This is effectively the same requirement as using @thread_local@ variables. Since SQEs that are allocated must be submitted to the same ring, on the same \gls{proc}, this effectively forces the application to submit SQEs in allocation order\footnote{The actual requirement is that \glspl{thrd} cannot context switch between allocation and submission. This requirement means that from the subsystem's point of view, the allocation and submission are sequential. To remove this requirement, a \gls{thrd} would need the ability to ``yield to a specific \gls{proc}'', \ie, park with the promise that it will be run next on a specific \gls{proc}, the \gls{proc} attached to the correct ring. This is not a current or planned feature of \CFA.}, greatly simplifying both allocation and submission. In this design, allocation and submission form a ring partitioned ring buffer as shown in Figure~\ref{fig:pring}. Once added to the ring buffer, the attached \gls{proc} has a significant amount of flexibility with regards to when to do the system call. Possible options are: when the \gls{proc} runs out of \glspl{thrd} to run, after running a given number of threads \glspl{thrd}, etc.
    127 
    128 \begin{figure}
    129         \centering
    130         \input{pivot_ring.pstex_t}
    131         \caption[Partitioned ring buffer]{Partitioned ring buffer \smallskip\newline Allocated sqes are appending to the first partition. When submitting, the partition is simply advanced to include all the sqes that should be submitted. The kernel considers the partition as the head of the ring.}
    132         \label{fig:pring}
    133 \end{figure}
    134 
    135 This approach has the advantage that it does not require much of the synchronization needed in the shared approach. This comes at the cost that \glspl{thrd} submitting \io operations have less flexibility, they cannot park or yield, and several exceptional cases are handled poorly. Instances running out of SQEs cannot run \glspl{thrd} wanting to do \io operations, in such a case the \gls{thrd} needs to be moved to a different \gls{proc}, the only current way of achieving this would be to @yield()@ hoping to be scheduled on a different \gls{proc}, which is not guaranteed. Another problematic case is that \glspl{thrd} that do not park for long periods of time will delay the submission of any SQE not already submitted. This issue is similar to fairness issues which schedulers that use work-stealing mentioned in the previous chapter.
    136 
    13744
    13845
    13946\section{Interface}
    140 Finally, the last important part of the \io subsystem is it's interface. There are multiple approaches that can be offered to programmers, each with advantages and disadvantages. The new \io subsystem can replace the C runtime's API or extend it. And in the later case the interface can go from very similar to vastly different. The following sections discuss some useful options using @read@ as an example. The standard Linux interface for C is :
    141 
    142 @ssize_t read(int fd, void *buf, size_t count);@.
    143 
    144 \subsection{Replacement}
    145 Replacing the C \glsxtrshort{api}
    146 
    147 \subsection{Synchronous Extension}
    148 
    149 \subsection{Asynchronous Extension}
    150 
    151 \subsection{Interface directly to \lstinline{io_uring}}
  • doc/theses/thierry_delisle_PhD/thesis/text/runtime.tex

    r95b3a9c r5e99a9a  
    1111
    1212\section{Clusters}
    13 \CFA allows the option to group user-level threading, in the form of clusters. Both \glspl{thrd} and \glspl{proc} belong to a specific cluster. \Glspl{thrd} are only scheduled onto \glspl{proc} in the same cluster and scheduling is done independently of other clusters. Figure~\ref{fig:system} shows an overview of the \CFA runtime, which allows programmers to tightly control parallelism. It also opens the door to handling effects like NUMA, by pining clusters to a specific NUMA node\footnote{This is not currently implemented in \CFA, but the only hurdle left is creating a generic interface for cpu masks.}.
     13\CFA allows the option to group user-level threading, in the form of clusters. Both \glspl{thrd} and \glspl{proc} belong to a specific cluster. \Glspl{thrd} are only be scheduled onto \glspl{proc} in the same cluster and scheduling is done independently of other clusters. Figure~\ref{fig:system} shows an overview of the \CFA runtime, which allows programmers to tightly control parallelism. It also opens the door to handling effects like NUMA, by pining clusters to a specific NUMA node\footnote{This is not currently implemented in \CFA, but the only hurdle left is creating a generic interface for cpu masks.}.
    1414
    1515\begin{figure}
     
    2525
    2626\section{\glsxtrshort{io}}\label{prev:io}
    27 Prior to this work, the \CFA runtime did not add any particular support for \glsxtrshort{io} operations. While all \glsxtrshort{io} operations available in C are available in \CFA, \glsxtrshort{io} operations are designed for the POSIX threading model~\cite{pthreads}. Using these 1:1 threading operations in an M:N threading model means \glsxtrshort{io} operations block \glspl{proc} instead of \glspl{thrd}. While this can work in certain cases, it limits the number of concurrent operations to the number of \glspl{proc} rather than \glspl{thrd}. It also means deadlock can occur because all \glspl{proc} are blocked even if at least one \gls{thrd} is ready to run. A simple example of this type of deadlock would be as follows:
    28 
     27Prior to this work, the \CFA runtime did not add any particular support for \glsxtrshort{io} operations. %\CFA being built on C, this means that,
     28While all I/O operations available in C are available in \CFA, \glsxtrshort{io} operations are designed for the POSIX threading model~\cite{pthreads}. Using these 1:1 threading operations in an M:N threading model means I/O operations block \glspl{proc} instead of \glspl{thrd}. While this can work in certain cases, it limits the number of concurrent operations to the number of \glspl{proc} rather than \glspl{thrd}. It also means deadlock can occur because all \glspl{proc} are blocked even if at least one \gls{thrd} is ready to run. A simple example of this type of deadlock would be as follows:
    2929\begin{quote}
    3030Given a simple network program with 2 \glspl{thrd} and a single \gls{proc}, one \gls{thrd} sends network requests to a server and the other \gls{thrd} waits for a response from the server. If the second \gls{thrd} races ahead, it may wait for responses to requests that have not been sent yet. In theory, this should not be a problem, even if the second \gls{thrd} waits, because the first \gls{thrd} is still ready to run and should be able to get CPU time to send the request. With M:N threading, while the first \gls{thrd} is ready, the lone \gls{proc} \emph{cannot} run the first \gls{thrd} if it is blocked in the \glsxtrshort{io} operation of the second \gls{thrd}. If this happen, the system is in a synchronization deadlock\footnote{In this example, the deadlocked could be resolved if the server sends unprompted messages to the client. However, this solution is not general and may not be appropriate even in this simple case.}.
    3131\end{quote}
     32Therefore, one of the objective of this work is to introduce \emph{User-Level \glsxtrshort{io}}, like \glslink{uthrding}{User-Level \emph{Threading}} blocks \glspl{thrd} rather than \glspl{proc} when doing \glsxtrshort{io} operations, which entails multiplexing the \glsxtrshort{io} operations of many \glspl{thrd} onto fewer \glspl{proc}. This multiplexing requires that a single \gls{proc} be able to execute multiple I/O operations in parallel. This requirement cannot be done with operations that block \glspl{proc}, \ie \glspl{kthrd}, since the first operation would prevent starting new operations for its blocking duration. Executing I/O operations in parallel requires \emph{asynchronous} \glsxtrshort{io}, sometimes referred to as \emph{non-blocking}, since the \gls{kthrd} does not block.
    3233
    33 Therefore, one of the objective of this work is to introduce \emph{User-Level \glsxtrshort{io}}, like \glslink{uthrding}{User-Level \emph{Threading}} blocks \glspl{thrd} rather than \glspl{proc} when doing \glsxtrshort{io} operations, which entails multiplexing the \glsxtrshort{io} operations of many \glspl{thrd} onto fewer \glspl{proc}. This multiplexing requires that a single \gls{proc} be able to execute multiple \glsxtrshort{io} operations in parallel. This requirement cannot be done with operations that block \glspl{proc}, \ie \glspl{kthrd}, since the first operation would prevent starting new operations for its blocking duration. Executing \glsxtrshort{io} operations in parallel requires \emph{asynchronous} \glsxtrshort{io}, sometimes referred to as \emph{non-blocking}, since the \gls{kthrd} does not block.
    34 
    35 \section{Interoperating with \texttt{C}}
     34\section{Interoperating with C}
    3635While \glsxtrshort{io} operations are the classical example of operations that block \glspl{kthrd}, the non-blocking challenge extends to all blocking system-calls. The POSIX standard states~\cite[\S~2.9.1]{POSIX17}:
    3736\begin{quote}
     
    4544\begin{enumerate}
    4645        \item Precisely identifying blocking C calls is difficult.
    47         \item Introducing control points code can have a significant impact on general performance.
     46        \item Introducing new code can have a significant impact on general performance.
    4847\end{enumerate}
    49 Because of these consequences, this work does not attempt to ``sandbox'' calls to C. Therefore, it is possible calls from an unidentified library will block a \gls{kthrd} leading to deadlocks in \CFA's M:N threading model, which would not occur in a traditional 1:1 threading model. Currently, all M:N thread systems interacting with UNIX without sandboxing suffer from this problem but manage to work very well in the majority of applications. Therefore, a complete solution to this problem is outside the scope of this thesis.
     48Because of these consequences, this work does not attempt to ``sandbox'' calls to C. Therefore, it is possible for an unidentified library calls to block a \gls{kthrd} leading to deadlocks in \CFA's M:N threading model, which would not occur in a traditional 1:1 threading model. Currently, all M:N thread systems interacting with UNIX without sandboxing suffer from this problem but manage to work very well in the majority of applications. Therefore, a complete solution to this problem is outside the scope of this thesis.
  • doc/theses/thierry_delisle_PhD/thesis/thesis.tex

    r95b3a9c r5e99a9a  
    1 %======================================================================
    2 % University of Waterloo Thesis Template for LaTeX
    3 % Last Updated November, 2020
    4 % by Stephen Carr, IST Client Services,
    5 % University of Waterloo, 200 University Ave. W., Waterloo, Ontario, Canada
    6 % FOR ASSISTANCE, please send mail to request@uwaterloo.ca
     1% uWaterloo Thesis Template for LaTeX
     2% Last Updated June 14, 2017 by Stephen Carr, IST Client Services
     3% FOR ASSISTANCE, please send mail to rt-IST-CSmathsci@ist.uwaterloo.ca
     4
     5% Effective October 2006, the University of Waterloo
     6% requires electronic thesis submission. See the uWaterloo thesis regulations at
     7% https://uwaterloo.ca/graduate-studies/thesis.
     8
     9% DON'T FORGET TO ADD YOUR OWN NAME AND TITLE in the "hyperref" package
     10% configuration below. THIS INFORMATION GETS EMBEDDED IN THE PDF FINAL PDF DOCUMENT.
     11% You can view the information if you view Properties of the PDF document.
     12
     13% Many faculties/departments also require one or more printed
     14% copies. This template attempts to satisfy both types of output.
     15% It is based on the standard "book" document class which provides all necessary
     16% sectioning structures and allows multi-part theses.
    717
    818% DISCLAIMER
    9 % To the best of our knowledge, this template satisfies the current uWaterloo thesis requirements.
    10 % However, it is your responsibility to assure that you have met all requirements of the University and your particular department.
    11 
    12 % Many thanks for the feedback from many graduates who assisted the development of this template.
    13 % Also note that there are explanatory comments and tips throughout this template.
    14 %======================================================================
    15 % Some important notes on using this template and making it your own...
    16 
    17 % The University of Waterloo has required electronic thesis submission since October 2006.
    18 % See the uWaterloo thesis regulations at
    19 % https://uwaterloo.ca/graduate-studies/thesis.
    20 % This thesis template is geared towards generating a PDF version optimized for viewing on an electronic display, including hyperlinks within the PDF.
    21 
    22 % DON'T FORGET TO ADD YOUR OWN NAME AND TITLE in the "hyperref" package configuration below.
    23 % THIS INFORMATION GETS EMBEDDED IN THE PDF FINAL PDF DOCUMENT.
    24 % You can view the information if you view properties of the PDF document.
    25 
    26 % Many faculties/departments also require one or more printed copies.
    27 % This template attempts to satisfy both types of output.
    28 % See additional notes below.
    29 % It is based on the standard "book" document class which provides all necessary sectioning structures and allows multi-part theses.
    30 
    31 % If you are using this template in Overleaf (cloud-based collaboration service), then it is automatically processed and previewed for you as you edit.
    32 
    33 % For people who prefer to install their own LaTeX distributions on their own computers, and process the source files manually, the following notes provide the sequence of tasks:
    34  
     19% To the best of our knowledge, this template satisfies the current uWaterloo requirements.
     20% However, it is your responsibility to assure that you have met all
     21% requirements of the University and your particular department.
     22% Many thanks for the feedback from many graduates that assisted the development of this template.
     23
     24% -----------------------------------------------------------------------
     25
     26% By default, output is produced that is geared toward generating a PDF
     27% version optimized for viewing on an electronic display, including
     28% hyperlinks within the PDF.
     29
    3530% E.g. to process a thesis called "mythesis.tex" based on this template, run:
    3631
    3732% pdflatex mythesis     -- first pass of the pdflatex processor
    3833% bibtex mythesis       -- generates bibliography from .bib data file(s)
    39 % makeindex         -- should be run only if an index is used 
     34% makeindex         -- should be run only if an index is used
    4035% pdflatex mythesis     -- fixes numbering in cross-references, bibliographic references, glossaries, index, etc.
    41 % pdflatex mythesis     -- it takes a couple of passes to completely process all cross-references
    42 
    43 % If you use the recommended LaTeX editor, Texmaker, you would open the mythesis.tex file, then click the PDFLaTeX button. Then run BibTeX (under the Tools menu).
    44 % Then click the PDFLaTeX button two more times.
    45 % If you have an index as well,you'll need to run MakeIndex from the Tools menu as well, before running pdflatex
     36% pdflatex mythesis     -- fixes numbering in cross-references, bibliographic references, glossaries, index, etc.
     37
     38% If you use the recommended LaTeX editor, Texmaker, you would open the mythesis.tex
     39% file, then click the PDFLaTeX button. Then run BibTeX (under the Tools menu).
     40% Then click the PDFLaTeX button two more times. If you have an index as well,
     41% you'll need to run MakeIndex from the Tools menu as well, before running pdflatex
    4642% the last two times.
    4743
    48 % N.B. The "pdftex" program allows graphics in the following formats to be included with the "\includegraphics" command: PNG, PDF, JPEG, TIFF
    49 % Tip: Generate your figures and photos in the size you want them to appear in your thesis, rather than scaling them with \includegraphics options.
    50 % Tip: Any drawings you do should be in scalable vector graphic formats: SVG, PNG, WMF, EPS and then converted to PNG or PDF, so they are scalable in the final PDF as well.
    51 % Tip: Photographs should be cropped and compressed so as not to be too large.
    52 
    53 % To create a PDF output that is optimized for double-sided printing:
    54 % 1) comment-out the \documentclass statement in the preamble below, and un-comment the second \documentclass line.
    55 % 2) change the value assigned below to the boolean variable "PrintVersion" from " false" to "true".
    56 
    57 %======================================================================
    58 %   D O C U M E N T   P R E A M B L E
    59 % Specify the document class, default style attributes, and page dimensions, etc.
     44% N.B. The "pdftex" program allows graphics in the following formats to be
     45% included with the "\includegraphics" command: PNG, PDF, JPEG, TIFF
     46% Tip 1: Generate your figures and photos in the size you want them to appear
     47% in your thesis, rather than scaling them with \includegraphics options.
     48% Tip 2: Any drawings you do should be in scalable vector graphic formats:
     49% SVG, PNG, WMF, EPS and then converted to PNG or PDF, so they are scalable in
     50% the final PDF as well.
     51% Tip 3: Photographs should be cropped and compressed so as not to be too large.
     52
     53% To create a PDF output that is optimized for double-sided printing:
     54%
     55% 1) comment-out the \documentclass statement in the preamble below, and
     56% un-comment the second \documentclass line.
     57%
     58% 2) change the value assigned below to the boolean variable
     59% "PrintVersion" from "false" to "true".
     60
     61% --------------------- Start of Document Preamble -----------------------
     62
     63% Specify the document class, default style attributes, and page dimensions
    6064% For hyperlinked PDF, suitable for viewing on a computer, use this:
    6165\documentclass[letterpaper,12pt,titlepage,oneside,final]{book}
    6266
    63 % For PDF, suitable for double-sided printing, change the PrintVersion variable below to "true" and use this \documentclass line instead of the one above:
     67% For PDF, suitable for double-sided printing, change the PrintVersion variable below
     68% to "true" and use this \documentclass line instead of the one above:
    6469%\documentclass[letterpaper,12pt,titlepage,openright,twoside,final]{book}
    6570
    66 % Some LaTeX commands I define for my own nomenclature.
    67 % If you have to, it's easier to make changes to nomenclature once here than in a million places throughout your thesis!
    68 \newcommand{\package}[1]{\textbf{#1}} % package names in bold text
    69 \newcommand{\cmmd}[1]{\textbackslash\texttt{#1}} % command name in tt font
    70 \newcommand{\href}[1]{#1} % does nothing, but defines the command so the print-optimized version will ignore \href tags (redefined by hyperref pkg).
    71 %\newcommand{\texorpdfstring}[2]{#1} % does nothing, but defines the command
    72 % Anything defined here may be redefined by packages added below...
     71\newcommand{\href}[1]{#1} % does nothing, but defines the command so the
     72    % print-optimized version will ignore \href tags (redefined by hyperref pkg).
    7373
    7474% This package allows if-then-else control structures.
     
    7676\newboolean{PrintVersion}
    7777\setboolean{PrintVersion}{false}
    78 % CHANGE THIS VALUE TO "true" as necessary, to improve printed results for hard copies by overriding some options of the hyperref package, called below.
     78% CHANGE THIS VALUE TO "true" as necessary, to improve printed results for hard copies
     79% by overriding some options of the hyperref package below.
    7980
    8081%\usepackage{nomencl} % For a nomenclature (optional; available from ctan.org)
    8182\usepackage{amsmath,amssymb,amstext} % Lots of math symbols and environments
    82 \usepackage{xcolor}
    8383\usepackage{graphicx} % For including graphics
    8484
    8585% Hyperlinks make it very easy to navigate an electronic document.
    86 % In addition, this is where you should specify the thesis title and author as they appear in the properties of the PDF document.
     86% In addition, this is where you should specify the thesis title
     87% and author as they appear in the properties of the PDF document.
    8788% Use the "hyperref" package
    8889% N.B. HYPERREF MUST BE THE LAST PACKAGE LOADED; ADD ADDITIONAL PKGS ABOVE
    8990\usepackage[pagebackref=false]{hyperref} % with basic options
    90 %\usepackage[pdftex,pagebackref=true]{hyperref}
    91 % N.B. pagebackref=true provides links back from the References to the body text. This can cause trouble for printing.
     91                % N.B. pagebackref=true provides links back from the References to the body text. This can cause trouble for printing.
    9292\hypersetup{
    9393        plainpages=false,       % needed if Roman numbers in frontpages
    94         unicode=false,          % non-Latin characters in Acrobat's bookmarks
    95         pdftoolbar=true,        % show Acrobat's toolbar?
    96         pdfmenubar=true,        % show Acrobat's menu?
     94        unicode=false,          % non-Latin characters in Acrobats bookmarks
     95        pdftoolbar=true,        % show Acrobats toolbar?
     96        pdfmenubar=true,        % show Acrobats menu?
    9797        pdffitwindow=false,     % window fit to page when opened
    9898        pdfstartview={FitH},    % fits the width of the page to the window
     
    110110\ifthenelse{\boolean{PrintVersion}}{   % for improved print quality, change some hyperref options
    111111\hypersetup{    % override some previously defined hyperref options
    112         citecolor=black,%
    113         filecolor=black,%
    114         linkcolor=black,%
     112        citecolor=black,
     113        filecolor=black,
     114        linkcolor=black,
    115115        urlcolor=black
    116116}}{} % end of ifthenelse (no else)
     
    120120% although it's supposed to be in both the TeX Live and MikTeX distributions. There are also documentation and
    121121% installation instructions there.
    122 \makeatletter
    123 \newcommand*{\glsplainhyperlink}[2]{%
    124   \colorlet{currenttext}{.}% store current text color
    125   \colorlet{currentlink}{\@linkcolor}% store current link color
    126   \hypersetup{linkcolor=currenttext}% set link color
    127   \hyperlink{#1}{#2}%
    128   \hypersetup{linkcolor=currentlink}% reset to default
    129 }
    130 \let\@glslink\glsplainhyperlink
    131 \makeatother
     122\renewcommand*{\glstextformat}[1]{\textsf{#1}}
    132123
    133124\usepackage{csquotes}
     
    135126
    136127% Setting up the page margins...
    137 \setlength{\textheight}{9in}
    138 \setlength{\topmargin}{-0.45in}
    139 \setlength{\headsep}{0.25in}
     128\setlength{\textheight}{9in}\setlength{\topmargin}{-0.45in}\setlength{\headsep}{0.25in}
    140129% uWaterloo thesis requirements specify a minimum of 1 inch (72pt) margin at the
    141 % top, bottom, and outside page edges and a 1.125 in. (81pt) gutter margin (on binding side).
    142 % While this is not an issue for electronic viewing, a PDF may be printed, and so we have the same page layout for both printed and electronic versions, we leave the gutter margin in.
     130% top, bottom, and outside page edges and a 1.125 in. (81pt) gutter
     131% margin (on binding side). While this is not an issue for electronic
     132% viewing, a PDF may be printed, and so we have the same page layout for
     133% both printed and electronic versions, we leave the gutter margin in.
    143134% Set margins to minimum permitted by uWaterloo thesis regulations:
    144135\setlength{\marginparwidth}{0pt} % width of margin notes
     
    149140\setlength{\evensidemargin}{0.125in} % Adds 1/8 in. to binding side of all
    150141% even-numbered pages when the "twoside" printing option is selected
    151 \setlength{\oddsidemargin}{0.125in} % Adds 1/8 in. to the left of all pages when "oneside" printing is selected, and to the left of all odd-numbered pages when "twoside" printing is selected
    152 \setlength{\textwidth}{6.375in} % assuming US letter paper (8.5 in. x 11 in.) and side margins as above
     142\setlength{\oddsidemargin}{0.125in} % Adds 1/8 in. to the left of all pages
     143% when "oneside" printing is selected, and to the left of all odd-numbered
     144% pages when "twoside" printing is selected
     145\setlength{\textwidth}{6.375in} % assuming US letter paper (8.5 in. x 11 in.) and
     146% side margins as above
    153147\raggedbottom
    154148
    155 % The following statement specifies the amount of space between paragraphs. Other reasonable specifications are \bigskipamount and \smallskipamount.
     149% The following statement specifies the amount of space between
     150% paragraphs. Other reasonable specifications are \bigskipamount and \smallskipamount.
    156151\setlength{\parskip}{\medskipamount}
    157152
    158 % The following statement controls the line spacing.
    159 % The default spacing corresponds to good typographic conventions and only slight changes (e.g., perhaps "1.2"), if any, should be made.
     153% The following statement controls the line spacing.  The default
     154% spacing corresponds to good typographic conventions and only slight
     155% changes (e.g., perhaps "1.2"), if any, should be made.
    160156\renewcommand{\baselinestretch}{1} % this is the default line space setting
    161157
    162 % By default, each chapter will start on a recto (right-hand side) page.
    163 % We also force each section of the front pages to start on a recto page by inserting \cleardoublepage commands.
    164 % In many cases, this will require that the verso (left-hand) page be blank, and while it should be counted, a page number should not be printed.
    165 % The following statements ensure a page number is not printed on an otherwise blank verso page.
     158% By default, each chapter will start on a recto (right-hand side)
     159% page.  We also force each section of the front pages to start on
     160% a recto page by inserting \cleardoublepage commands.
     161% In many cases, this will require that the verso page be
     162% blank and, while it should be counted, a page number should not be
     163% printed.  The following statements ensure a page number is not
     164% printed on an otherwise blank verso page.
    166165\let\origdoublepage\cleardoublepage
    167166\newcommand{\clearemptydoublepage}{%
     
    195194\input{common}
    196195\CFAStyle                                               % CFA code-style for all languages
    197 \lstset{language=CFA,basicstyle=\linespread{0.9}\tt}    % CFA default language
     196\lstset{basicstyle=\linespread{0.9}\tt}
    198197
    199198% glossary of terms to use
     
    201200\makeindex
    202201
    203 \newcommand\io{\glsxtrshort{io}\xspace}%
    204 
    205202%======================================================================
    206 %   L O G I C A L    D O C U M E N T
    207 % The logical document contains the main content of your thesis.
    208 % Being a large document, it is a good idea to divide your thesis into several files, each one containing one chapter or other significant chunk of content, so you can easily shuffle things around later if desired.
     203%   L O G I C A L    D O C U M E N T -- the content of your thesis
    209204%======================================================================
    210205\begin{document}
    211206
     207% For a large document, it is a good idea to divide your thesis
     208% into several files, each one containing one chapter.
     209% To illustrate this idea, the "front pages" (i.e., title page,
     210% declaration, borrowers' page, abstract, acknowledgements,
     211% dedication, table of contents, list of tables, list of figures,
     212% nomenclature) are contained within the file "uw-ethesis-frontpgs.tex" which is
     213% included into the document by the following statement.
    212214%----------------------------------------------------------------------
    213215% FRONT MATERIAL
    214 % title page,declaration, borrowers' page, abstract, acknowledgements,
    215 % dedication, table of contents, list of tables, list of figures, nomenclature, etc.
    216216%----------------------------------------------------------------------
    217217\input{text/front.tex}
    218218
     219
    219220%----------------------------------------------------------------------
    220221% MAIN BODY
    221 % We suggest using a separate file for each chapter of your thesis.
    222 % Start each chapter file with the \chapter command.
    223 % Only use \documentclass or \begin{document} and \end{document} commands in this master document.
    224 % Tip: Putting each sentence on a new line is a way to simplify later editing.
    225 %----------------------------------------------------------------------
    226 
     222%----------------------------------------------------------------------
     223% Because this is a short document, and to reduce the number of files
     224% needed for this template, the chapters are not separate
     225% documents as suggested above, but you get the idea. If they were
     226% separate documents, they would each start with the \chapter command, i.e,
     227% do not contain \documentclass or \begin{document} and \end{document} commands.
    227228\part{Introduction}
    228229\input{text/intro.tex}
     
    231232\part{Design}
    232233\input{text/core.tex}
     234\input{text/practice.tex}
    233235\input{text/io.tex}
    234 \input{text/practice.tex}
    235236\part{Evaluation}
    236237\label{Evaluation}
     
    242243%----------------------------------------------------------------------
    243244% END MATERIAL
    244 % Bibliography, Appendices, Index, etc.
    245 %----------------------------------------------------------------------
    246 
    247 % Bibliography
    248 
    249 % The following statement selects the style to use for references.
    250 % It controls the sort order of the entries in the bibliography and also the formatting for the in-text labels.
     245%----------------------------------------------------------------------
     246
     247% B I B L I O G R A P H Y
     248% -----------------------
     249
     250% The following statement selects the style to use for references.  It controls the sort order of the entries in the bibliography and also the formatting for the in-text labels.
    251251\bibliographystyle{plain}
    252252% This specifies the location of the file containing the bibliographic information.
    253 % It assumes you're using BibTeX to manage your references (if not, why not?).
    254 \cleardoublepage % This is needed if the "book" document class is used, to place the anchor in the correct page, because the bibliography will start on its own page.
    255 % Use \clearpage instead if the document class uses the "oneside" argument
     253% It assumes you're using BibTeX (if not, why not?).
     254\cleardoublepage % This is needed if the book class is used, to place the anchor in the correct page,
     255                 % because the bibliography will start on its own page.
     256                 % Use \clearpage instead if the document class uses the "oneside" argument
    256257\phantomsection  % With hyperref package, enables hyperlinking from the table of contents to bibliography
    257258% The following statement causes the title "References" to be used for the bibliography section:
     
    262263
    263264\bibliography{local,pl}
    264 % Tip: You can create multiple .bib files to organize your references.
     265% Tip 5: You can create multiple .bib files to organize your references.
    265266% Just list them all in the \bibliogaphy command, separated by commas (no spaces).
    266267
    267 % The following statement causes the specified references to be added to the bibliography even if they were not cited in the text.
    268 % The asterisk is a wildcard that causes all entries in the bibliographic database to be included (optional).
     268% % The following statement causes the specified references to be added to the bibliography% even if they were not
     269% % cited in the text. The asterisk is a wildcard that causes all entries in the bibliographic database to be included (optional).
    269270% \nocite{*}
    270 %----------------------------------------------------------------------
    271 
    272 % Appendices
    273271
    274272% The \appendix statement indicates the beginning of the appendices.
    275273\appendix
    276 % Add an un-numbered title page before the appendices and a line in the Table of Contents
     274% Add a title page before the appendices and a line in the Table of Contents
    277275\chapter*{APPENDICES}
    278276\addcontentsline{toc}{chapter}{APPENDICES}
    279 % Appendices are just more chapters, with different labeling (letters instead of numbers).
    280277%======================================================================
    281278\chapter[PDF Plots From Matlab]{Matlab Code for Making a PDF Plot}
     
    315312%\input{thesis.ind}                             % index
    316313
    317 \phantomsection         % allows hyperref to link to the correct page
    318 
    319 %----------------------------------------------------------------------
    320 \end{document} % end of logical document
     314\phantomsection
     315
     316\end{document}
  • doc/user/figures/Cdecl.fig

    r95b3a9c r5e99a9a  
    19192 2 0 1 0 7 50 -1 -1 0.000 0 0 -1 0 0 5
    2020         2850 1200 3600 1200 3600 1350 2850 1350 2850 1200
    21 4 1 0 50 -1 4 11 0.0000 2 120 90 2925 1325 0\001
    22 4 1 0 50 -1 4 11 0.0000 2 120 90 3075 1325 1\001
    23 4 1 0 50 -1 4 11 0.0000 2 120 90 3225 1325 2\001
    24 4 1 0 50 -1 4 11 0.0000 2 120 90 3375 1325 3\001
    25 4 1 0 50 -1 4 11 0.0000 2 120 90 3525 1325 4\001
     214 1 0 50 -1 4 10 0.0000 2 120 90 2925 1325 0\001
     224 1 0 50 -1 4 10 0.0000 2 120 90 3075 1325 1\001
     234 1 0 50 -1 4 10 0.0000 2 120 90 3225 1325 2\001
     244 1 0 50 -1 4 10 0.0000 2 120 90 3375 1325 3\001
     254 1 0 50 -1 4 10 0.0000 2 120 90 3525 1325 4\001
    2626-6
    27272 2 0 1 0 7 50 -1 -1 0.000 0 0 -1 0 0 5
     
    5555        1 1 1.00 45.00 60.00
    5656         2550 1275 2850 1275
    57 4 1 0 50 -1 4 11 0.0000 2 120 90 1350 1650 0\001
    58 4 1 0 50 -1 4 11 0.0000 2 120 90 1500 1650 1\001
    59 4 1 0 50 -1 4 11 0.0000 2 120 90 1650 1650 2\001
    60 4 1 0 50 -1 4 11 0.0000 2 120 90 1800 1650 3\001
    61 4 1 0 50 -1 4 11 0.0000 2 120 90 1950 1650 4\001
    62 4 1 0 50 -1 4 11 0.0000 2 90 90 1200 1325 x\001
    63 4 1 0 50 -1 4 11 0.0000 2 90 90 2400 1325 x\001
     574 1 0 50 -1 4 10 0.0000 2 120 90 1350 1650 0\001
     584 1 0 50 -1 4 10 0.0000 2 120 90 1500 1650 1\001
     594 1 0 50 -1 4 10 0.0000 2 120 90 1650 1650 2\001
     604 1 0 50 -1 4 10 0.0000 2 120 90 1800 1650 3\001
     614 1 0 50 -1 4 10 0.0000 2 120 90 1950 1650 4\001
     624 1 0 50 -1 4 10 0.0000 2 90 90 1200 1325 x\001
     634 1 0 50 -1 4 10 0.0000 2 90 90 2400 1325 x\001
  • doc/user/user.tex

    r95b3a9c r5e99a9a  
    1111%% Created On       : Wed Apr  6 14:53:29 2016
    1212%% Last Modified By : Peter A. Buhr
    13 %% Last Modified On : Mon Feb 15 13:48:53 2021
    14 %% Update Count     : 4452
     13%% Last Modified On : Mon Oct  5 08:57:29 2020
     14%% Update Count     : 3998
    1515%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
    1616
     
    3737\usepackage{mathptmx}                                   % better math font with "times"
    3838\usepackage[usenames]{color}
    39 \usepackage[dvips,plainpages=false,pdfpagelabels,pdfpagemode=UseNone,colorlinks=true,pagebackref=true,linkcolor=blue,citecolor=blue,urlcolor=blue,pagebackref=true,breaklinks=true]{hyperref}
    40 \usepackage{breakurl}
    41 
    42 \renewcommand\footnoterule{\kern -3pt\rule{0.3\linewidth}{0.15pt}\kern 2pt}
    43 
    44 \usepackage[pagewise]{lineno}
    45 \renewcommand{\linenumberfont}{\scriptsize\sffamily}
    46 \usepackage[firstpage]{draftwatermark}
    47 \SetWatermarkLightness{0.9}
    48 
    49 % Default underscore is too low and wide. Cannot use lstlisting "literate" as replacing underscore
    50 % removes it as a variable-name character so keywords in variables are highlighted. MUST APPEAR
    51 % AFTER HYPERREF.
    52 \renewcommand{\textunderscore}{\leavevmode\makebox[1.2ex][c]{\rule{1ex}{0.075ex}}}
    53 
    54 \setlength{\topmargin}{-0.45in}                                                 % move running title into header
    55 \setlength{\headsep}{0.25in}
    56 
    57 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
    58 
    5939\newcommand{\CFALatin}{}
    6040% inline code ©...© (copyright symbol) emacs: C-q M-)
     
    6646% math escape $...$ (dollar symbol)
    6747\input{common}                                          % common CFA document macros
     48\usepackage[dvips,plainpages=false,pdfpagelabels,pdfpagemode=UseNone,colorlinks=true,pagebackref=true,linkcolor=blue,citecolor=blue,urlcolor=blue,pagebackref=true,breaklinks=true]{hyperref}
     49\usepackage{breakurl}
     50
     51\renewcommand\footnoterule{\kern -3pt\rule{0.3\linewidth}{0.15pt}\kern 2pt}
     52
     53\usepackage[pagewise]{lineno}
     54\renewcommand{\linenumberfont}{\scriptsize\sffamily}
     55\usepackage[firstpage]{draftwatermark}
     56\SetWatermarkLightness{0.9}
     57
     58% Default underscore is too low and wide. Cannot use lstlisting "literate" as replacing underscore
     59% removes it as a variable-name character so keywords in variables are highlighted. MUST APPEAR
     60% AFTER HYPERREF.
     61\renewcommand{\textunderscore}{\leavevmode\makebox[1.2ex][c]{\rule{1ex}{0.075ex}}}
     62
     63\setlength{\topmargin}{-0.45in}                                                 % move running title into header
     64\setlength{\headsep}{0.25in}
     65
     66%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
     67
    6868\CFAStyle                                                                                               % use default CFA format-style
    69 \lstset{language=CFA}                                                                   % CFA default lnaguage
    7069\lstnewenvironment{C++}[1][]                            % use C++ style
    71 {\lstset{language=C++,moredelim=**[is][\protect\color{red}]{@}{@},#1}}
     70{\lstset{language=C++,moredelim=**[is][\protect\color{red}]{®}{®},#1}}
    7271{}
    7372
     
    8281\newcommand{\Emph}[2][red]{{\color{#1}\textbf{\emph{#2}}}}
    8382\newcommand{\R}[1]{\Textbf{#1}}
    84 \newcommand{\RC}[1]{\Textbf{\LstBasicStyle{#1}}}
    8583\newcommand{\B}[1]{{\Textbf[blue]{#1}}}
    8684\newcommand{\G}[1]{{\Textbf[OliveGreen]{#1}}}
     
    105103
    106104\author{
    107 \huge \CFA Team (past and present) \medskip \\
    108 \Large Andrew Beach, Richard Bilson, Michael Brooks, Peter A. Buhr, Thierry Delisle, \smallskip \\
    109 \Large Glen Ditchfield, Rodolfo G. Esteves, Aaron Moss, Colby Parsons, Rob Schluntz, \smallskip \\
    110 \Large Fangren Yu, Mubeen Zulfiqar
     105\huge \CFA Team \medskip \\
     106\Large Andrew Beach, Richard Bilson, Peter A. Buhr, Thierry Delisle, \smallskip \\
     107\Large Glen Ditchfield, Rodolfo G. Esteves, Aaron Moss, Rob Schluntz
    111108}% author
    112109
     
    129126\vspace*{\fill}
    130127\noindent
    131 \copyright\,2016, 2018, 2021 \CFA Project \\ \\
     128\copyright\,2016 \CFA Project \\ \\
    132129\noindent
    133130This work is licensed under the Creative Commons Attribution 4.0 International License.
     
    147144\section{Introduction}
    148145
    149 \CFA{}\index{cforall@\CFA}\footnote{Pronounced ``\Index*{C-for-all}'', and written \CFA, CFA, or \CFL.} is a modern general-purpose concurrent programming-language, designed as an evolutionary step forward for the C programming language.
     146\CFA{}\index{cforall@\CFA}\footnote{Pronounced ``\Index*{C-for-all}'', and written \CFA, CFA, or \CFL.} is a modern general-purpose programming-language, designed as an evolutionary step forward for the C programming language.
    150147The syntax of \CFA builds from C and should look immediately familiar to C/\Index*[C++]{\CC{}} programmers.
    151148% Any language feature that is not described here can be assumed to be using the standard \Celeven syntax.
    152 \CFA adds many modern features that directly lead to increased \emph{\Index{safety}} and \emph{\Index{productivity}}, while maintaining interoperability with existing C programs and achieving similar performance.
     149\CFA adds many modern programming-language features that directly lead to increased \emph{\Index{safety}} and \emph{\Index{productivity}}, while maintaining interoperability with existing C programs and achieving similar performance.
    153150Like C, \CFA is a statically typed, procedural (non-\Index{object-oriented}) language with a low-overhead runtime, meaning there is no global \Index{garbage-collection}, but \Index{regional garbage-collection}\index{garbage-collection!regional} is possible.
    154151The primary new features include polymorphic routines and types, exceptions, concurrency, and modules.
     
    160157instead, a programmer evolves a legacy program into \CFA by incrementally incorporating \CFA features.
    161158As well, new programs can be written in \CFA using a combination of C and \CFA features.
    162 In many ways, \CFA is to C as \Index{Scala}~\cite{Scala} is to Java, providing a vehicle for new typing and control-flow capabilities on top of a highly popular programming language allowing immediate dissemination.
    163159
    164160\Index*[C++]{\CC{}}~\cite{c++:v1} had a similar goal 30 years ago, allowing object-oriented programming to be incrementally added to C.
     
    169165For example, the following programs compare the C, \CFA, and \CC I/O mechanisms, where the programs output the same result.
    170166\begin{center}
    171 \begin{tabular}{@{}l@{\hspace{1em}}l@{\hspace{1em}}l@{}}
    172 \multicolumn{1}{c@{\hspace{1em}}}{\textbf{C}}   & \multicolumn{1}{c}{\textbf{\CFA}}     & \multicolumn{1}{c}{\textbf{\CC}}      \\
    173 \begin{cfa}
    174 #include <stdio.h>$\indexc{stdio.h}$
     167\begin{tabular}{@{}l@{\hspace{1.5em}}l@{\hspace{1.5em}}l@{}}
     168\multicolumn{1}{c@{\hspace{1.5em}}}{\textbf{C}} & \multicolumn{1}{c}{\textbf{\CFA}}     & \multicolumn{1}{c}{\textbf{\CC}}      \\
     169\begin{cfa}
     170#include <stdio.h>§\indexc{stdio.h}§
    175171
    176172int main( void ) {
    177173        int x = 0, y = 1, z = 2;
    178         @printf( "%d %d %d\n", x, y, z );@
     174        ®printf( "%d %d %d\n", x, y, z );®
    179175}
    180176\end{cfa}
    181177&
    182178\begin{cfa}
    183 #include <fstream>$\indexc{fstream}$
     179#include <fstream>§\indexc{fstream}§
    184180
    185181int main( void ) {
    186182        int x = 0, y = 1, z = 2;
    187         @sout | x | y | z;@$\indexc{sout}$
     183        ®sout | x | y | z;®§\indexc{sout}§
    188184}
    189185\end{cfa}
    190186&
    191187\begin{cfa}
    192 #include <iostream>$\indexc{iostream}$
     188#include <iostream>§\indexc{iostream}§
    193189using namespace std;
    194190int main() {
    195191        int x = 0, y = 1, z = 2;
    196         @cout<<x<<" "<<y<<" "<<z<<endl;@
     192        ®cout<<x<<" "<<y<<" "<<z<<endl;®
    197193}
    198194\end{cfa}
    199195\end{tabular}
    200196\end{center}
    201 While \CFA I/O \see{\VRef{s:StreamIOLibrary}} looks similar to \Index*[C++]{\CC{}}, there are important differences, such as automatic spacing between variables and an implicit newline at the end of the expression list, similar to \Index*{Python}~\cite{Python}.
     197While the \CFA I/O looks similar to the \Index*[C++]{\CC{}} output style, there are important differences, such as automatic spacing between variables as in \Index*{Python} (see~\VRef{s:IOLibrary}).
    202198
    203199
     
    214210\section{Why fix C?}
    215211
    216 The C programming language is a foundational technology for modern computing with billions of lines of code implementing everything from hobby projects to commercial operating-systems.
     212The C programming language is a foundational technology for modern computing with millions of lines of code implementing everything from hobby projects to commercial operating-systems.
    217213This installation base and the programmers producing it represent a massive software-engineering investment spanning decades and likely to continue for decades more.
    218214Even with all its problems, C continues to be popular because it allows writing software at virtually any level in a computer system without restriction.
    219 For system programming, where direct access to hardware, storage management, and real-time issues are a requirement, C is the only language of choice.
    220 The TIOBE index~\cite{TIOBE} for February 2021 ranks the top six most \emph{popular} programming languages as C 17.4\%, \Index*{Java} 12\%, Python 12\%, \Index*[C++]{\CC{}} 7.6\%, \Csharp 4\%, Visual Basic 3.8\% = 56.8\%, where the next 50 languages are less than 2\% each, with a long tail.
     215For system programming, where direct access to hardware, storage management, and real-time issues are a requirement, C is usually the only language of choice.
     216The TIOBE index~\cite{TIOBE} for February 2020 ranks the top six most \emph{popular} programming languages as \Index*{Java} 17.4\%, C 16.8\%, Python 9.3\%, \Index*[C++]{\CC{}} 6.2\%, \Csharp 5.9\%, Visual Basic 5.9\% = 61.5\%, where the next 50 languages are less than 2\% each, with a long tail.
    221217The top 4 rankings over the past 35 years are:
    222218\begin{center}
    223219\setlength{\tabcolsep}{10pt}
    224220\begin{tabular}{@{}rcccccccc@{}}
    225                 & 2021  & 2016  & 2011  & 2006  & 2001  & 1996  & 1991  & 1986  \\ \hline
    226 \R{C}   & \R{1} & \R{2} & \R{2} & \R{1} & \R{1} & \R{1} & \R{1} & \R{1} \\
    227 Java    & 2             & 1             & 1             & 2             & 3             & 28    & -             & -             \\
    228 Python  & 3             & 5             & 6             & 7             & 23    & 13    & -             & -             \\
    229 \CC             & 4             & 3             & 3             & 3             & 2             & 2             & 2             & 8             \\
     221                & 2020  & 2015  & 2010  & 2005  & 2000  & 1995  & 1990  & 1985  \\ \hline
     222Java    & 1             & 2             & 1             & 2             & 3             & -             & -             & -             \\
     223\R{C}   & \R{2} & \R{1} & \R{2} & \R{1} & \R{1} & \R{2} & \R{1} & \R{1} \\
     224Python  & 3             & 7             & 6             & 6             & 22    & 21    & -             & -             \\
     225\CC             & 4             & 4             & 4             & 3             & 2             & 1             & 2             & 12    \\
    230226\end{tabular}
    231227\end{center}
     
    236232As stated, the goal of the \CFA project is to engineer modern language-features into C in an evolutionary rather than revolutionary way.
    237233\CC~\cite{C++14,C++} is an example of a similar project;
    238 however, it largely extended the C language, and did not address many of C's existing problems.\footnote{%
     234however, it largely extended the C language, and did not address most of C's existing problems.\footnote{%
    239235Two important existing problems addressed were changing the type of character literals from ©int© to ©char© and enumerator from ©int© to the type of its enumerators.}
    240236\Index*{Fortran}~\cite{Fortran08}, \Index*{Ada}~\cite{Ada12}, and \Index*{Cobol}~\cite{Cobol14} are examples of programming languages that took an evolutionary approach, where modern language-features (\eg objects, concurrency) are added and problems fixed within the framework of the existing language.
     
    245241
    246242The result of this project is a language that is largely backwards compatible with \Index*[C11]{\Celeven{}}~\cite{C11}, but fixes many of the well known C problems while adding modern language-features.
    247 To achieve these goals required a significant engineering exercise, \ie ``thinking \emph{inside} the C box''.
    248 Considering the large body of existing C code and programmers, there is significant impetus to ensure C is transformed into a modern language.
     243To achieve these goals required a significant engineering exercise, where we had to ``think inside the existing C box''.
     244Without these significant extension to C, it is unable to cope with the needs of modern programming problems and programmers;
     245as a result, it will fade into disuse.
     246Considering the large body of existing C code and programmers, there is significant impetus to ensure C is transformed into a modern programming language.
    249247While \Index*[C11]{\Celeven{}} made a few simple extensions to the language, nothing was added to address existing problems in the language or to augment the language with modern language-features.
    250248While some may argue that modern language-features may make C complex and inefficient, it is clear a language without modern capabilities is insufficient for the advanced programming problems existing today.
     
    253251\section{History}
    254252
    255 The \CFA project started with \Index*{Dave Till}\index{Till, Dave}'s \Index*{K-W C}~\cite{Buhr94a,Till89}, which extended C with new declaration syntax, multiple return values from routines, and advanced assignment capabilities using the notion of tuples \see{\cite{Werther96} for similar work in \Index*[C++]{\CC{}}}.
     253The \CFA project started with \Index*{Dave Till}\index{Till, Dave}'s \Index*{K-W C}~\cite{Buhr94a,Till89}, which extended C with new declaration syntax, multiple return values from routines, and advanced assignment capabilities using the notion of tuples.
     254(See~\cite{Werther96} for similar work in \Index*[C++]{\CC{}}.)
    256255The first \CFA implementation of these extensions was by \Index*{Rodolfo Esteves}\index{Esteves, Rodolfo}~\cite{Esteves04}.
    257256
    258257The signature feature of \CFA is \emph{\Index{overload}able} \Index{parametric-polymorphic} functions~\cite{forceone:impl,Cormack90,Duggan96} with functions generalized using a ©forall© clause (giving the language its name):
    259258\begin{cfa}
    260 @forall( otype T )@ T identity( T val ) { return val; }
    261 int forty_two = identity( 42 ); $\C{// T is bound to int, forty\_two == 42}$
     259®forall( otype T )® T identity( T val ) { return val; }
     260int forty_two = identity( 42 ); §\C{// T is bound to int, forty\_two == 42}§
    262261\end{cfa}
    263262% extending the C type system with parametric polymorphism and overloading, as opposed to the \Index*[C++]{\CC{}} approach of object-oriented extensions.
    264263\CFA{}\hspace{1pt}'s polymorphism was originally formalized by \Index*{Glen Ditchfield}\index{Ditchfield, Glen}~\cite{Ditchfield92}, and first implemented by \Index*{Richard Bilson}\index{Bilson, Richard}~\cite{Bilson03}.
    265264However, at that time, there was little interesting in extending C, so work did not continue.
    266 As the saying goes, ``\Index*{What goes around, comes around.}'', and there is now renewed interest in the C programming language because of the legacy code-base, so the \CFA project was restarted in 2015.
     265As the saying goes, ``\Index*{What goes around, comes around.}'', and there is now renewed interest in the C programming language because of legacy code-bases, so the \CFA project has been restarted.
    267266
    268267
     
    274273This feature allows \CFA programmers to take advantage of the existing panoply of C libraries to access thousands of external software features.
    275274Language developers often state that adequate \Index{library support} takes more work than designing and implementing the language itself.
    276 Fortunately, \CFA, like \Index*[C++]{\CC{}}, starts with immediate access to all exiting C libraries, and in many cases, can easily wrap library routines with simpler and safer interfaces, at zero or very low cost.
     275Fortunately, \CFA, like \Index*[C++]{\CC{}}, starts with immediate access to all exiting C libraries, and in many cases, can easily wrap library routines with simpler and safer interfaces, at very low cost.
    277276Hence, \CFA begins by leveraging the large repository of C libraries, and than allows programmers to incrementally augment their C programs with modern \Index{backward-compatible} features.
    278277
     
    287286
    288287double key = 5.0, vals[10] = { /* 10 sorted floating values */ };
    289 double * val = (double *)bsearch( &key, vals, 10, sizeof(vals[0]), comp ); $\C{// search sorted array}$
     288double * val = (double *)bsearch( &key, vals, 10, sizeof(vals[0]), comp ); §\C{// search sorted array}§
    290289\end{cfa}
    291290which can be augmented simply with a polymorphic, type-safe, \CFA-overloaded wrappers:
     
    296295
    297296forall( otype T | { int ?<?( T, T ); } ) unsigned int bsearch( T key, const T * arr, size_t size ) {
    298         T * result = bsearch( key, arr, size ); $\C{// call first version}$
    299         return result ? result - arr : size; } $\C{// pointer subtraction includes sizeof(T)}$
    300 
    301 double * val = bsearch( 5.0, vals, 10 ); $\C{// selection based on return type}$
     297        T * result = bsearch( key, arr, size ); §\C{// call first version}§
     298        return result ? result - arr : size; } §\C{// pointer subtraction includes sizeof(T)}§
     299
     300double * val = bsearch( 5.0, vals, 10 ); §\C{// selection based on return type}§
    302301int posn = bsearch( 5.0, vals, 10 );
    303302\end{cfa}
     
    311310\begin{cfa}
    312311forall( dtype T | sized(T) ) T * malloc( void ) { return (T *)malloc( sizeof(T) ); }
    313 int * ip = malloc(); $\C{// select type and size from left-hand side}$
     312int * ip = malloc(); §\C{// select type and size from left-hand side}§
    314313double * dp = malloc();
    315314struct S {...} * sp = malloc();
     
    320319However, it is necessary to differentiate between C and \CFA code because of name \Index{overload}ing, as for \CC.
    321320For example, the C math-library provides the following routines for computing the absolute value of the basic types: ©abs©, ©labs©, ©llabs©, ©fabs©, ©fabsf©, ©fabsl©, ©cabsf©, ©cabs©, and ©cabsl©.
    322 Whereas, \CFA wraps each of these routines into one overloaded name ©abs©:
    323 \begin{cfa}
    324 char @abs@( char );
    325 extern "C" { int @abs@( int ); } $\C{// use default C routine for int}$
    326 long int @abs@( long int );
    327 long long int @abs@( long long int );
    328 float @abs@( float );
    329 double @abs@( double );
    330 long double @abs@( long double );
    331 float _Complex @abs@( float _Complex );
    332 double _Complex @abs@( double _Complex );
    333 long double _Complex @abs@( long double _Complex );
    334 \end{cfa}
    335 The problem is \Index{name clash} between the C name ©abs© and the \CFA names ©abs©, resulting in two name linkages\index{C linkage}: ©extern "C"© and ©extern "Cforall"© (default).
    336 Overloaded names must use \newterm{name mangling}\index{mangling!name} to create unique names that are different from unmangled C names.
    337 Hence, there is the same need as in \CC to know if a name is a C or \CFA name, so it can be correctly formed.
    338 The only way around this problem is C's approach of creating unique names for each pairing of operation and type.
    339 
    340 This example illustrates a core idea in \CFA: \emph{the \Index{power of a name}}.
     321Whereas, \CFA wraps each of these routines into ones with the overloaded name ©abs©:
     322\begin{cfa}
     323char ®abs®( char );
     324extern "C" { int ®abs®( int ); } §\C{// use default C routine for int}§
     325long int ®abs®( long int );
     326long long int ®abs®( long long int );
     327float ®abs®( float );
     328double ®abs®( double );
     329long double ®abs®( long double );
     330float _Complex ®abs®( float _Complex );
     331double _Complex ®abs®( double _Complex );
     332long double _Complex ®abs®( long double _Complex );
     333\end{cfa}
     334The problem is the name clash between the library routine ©abs© and the \CFA names ©abs©.
     335Hence, names appearing in an ©extern "C"© block have \newterm*{C linkage}.
     336Then overloading polymorphism uses a mechanism called \newterm{name mangling}\index{mangling!name} to create unique names that are different from C names, which are not mangled.
     337Hence, there is the same need, as in \CC, to know if a name is a C or \CFA name, so it can be correctly formed.
     338There is no way around this problem, other than C's approach of creating unique names for each pairing of operation and types.
     339
     340This example strongly illustrates a core idea in \CFA: \emph{the \Index{power of a name}}.
    341341The name ``©abs©'' evokes the notion of absolute value, and many mathematical types provide the notion of absolute value.
    342342Hence, knowing the name ©abs© is sufficient to apply it to any type where it is applicable.
     
    344344
    345345
    346 \section{\CFA Compilation}
     346\section[Compiling a CFA Program]{Compiling a \CFA Program}
    347347
    348348The command ©cfa© is used to compile a \CFA program and is based on the \Index{GNU} \Indexc{gcc} command, \eg:
    349349\begin{cfa}
    350 cfa$\indexc{cfa}\index{compilation!cfa@©cfa©}$ [ gcc/$\CFA{}$-options ] [ C/$\CFA{}$ source-files ] [ assembler/loader files ]
    351 \end{cfa}
    352 There is no ordering among options (flags) and files, unless an option has an argument, which must appear immediately after the option possibly with or without a space separating option and argument.
    353 
    354 \CFA has the following ©gcc© flags turned on:
    355 \begin{description}[topsep=0pt]
     350cfa§\indexc{cfa}\index{compilation!cfa@©cfa©}§ [ gcc-options ] [ C/§\CFA{}§ source-files ] [ assembler/loader files ]
     351\end{cfa}
     352\CFA programs having the following ©gcc© flags turned on:
     353\begin{description}
    356354\item
    357355\Indexc{-std=gnu11}\index{compilation option!-std=gnu11@{©-std=gnu11©}}
     
    361359Use the traditional GNU semantics for inline routines in C11 mode, which allows inline routines in header files.
    362360\end{description}
    363 
    364 \CFA has the following new options:
    365 \begin{description}[topsep=0pt]
     361The following new \CFA options are available:
     362\begin{description}
    366363\item
    367364\Indexc{-CFA}\index{compilation option!-CFA@©-CFA©}
    368 Only the C preprocessor (flag ©-E©) and the \CFA translator steps are performed and the transformed program is written to standard output, which makes it possible to examine the code generated by the \CFA translator.
     365Only the C preprocessor and the \CFA translator steps are performed and the transformed program is written to standard output, which makes it possible to examine the code generated by the \CFA translator.
    369366The generated code starts with the standard \CFA \Index{prelude}.
    370 
    371 \item
    372 \Indexc{-XCFA}\index{compilation option!-XCFA@©-XCFA©}
    373 Pass next flag as-is to the ©cfa-cpp© translator (see details below).
    374367
    375368\item
    376369\Indexc{-debug}\index{compilation option!-debug@©-debug©}
    377370The program is linked with the debugging version of the runtime system.
    378 The debug version performs runtime checks to aid the debugging phase of a \CFA program, but can substantially slow program execution.
     371The debug version performs runtime checks to help during the debugging phase of a \CFA program, but can substantially slow program execution.
    379372The runtime checks should only be removed after the program is completely debugged.
    380373\textbf{This option is the default.}
     
    406399\item
    407400\Indexc{-no-include-stdhdr}\index{compilation option!-no-include-stdhdr@©-no-include-stdhdr©}
    408 Do not supply ©extern "C"© wrappers for \Celeven standard include files \see{\VRef{s:StandardHeaders}}.
     401Do not supply ©extern "C"© wrappers for \Celeven standard include files (see~\VRef{s:StandardHeaders}).
    409402\textbf{This option is \emph{not} the default.}
    410403\end{comment}
     
    437430\begin{cfa}
    438431#ifndef __CFORALL__
    439 #include <stdio.h>$\indexc{stdio.h}$ $\C{// C header file}$
     432#include <stdio.h>§\indexc{stdio.h}§ §\C{// C header file}§
    440433#else
    441 #include <fstream>$\indexc{fstream}$ $\C{// \CFA header file}$
     434#include <fstream>§\indexc{fstream}§ §\C{// \CFA header file}§
    442435#endif
    443436\end{cfa}
     
    445438
    446439The \CFA translator has multiple steps.
    447 The following flags control how the translator works, the stages run, and printing within a stage.
     440The following flags control how the tranlator works, the stages run, and printing within a stage.
    448441The majority of these flags are used by \CFA developers, but some are occasionally useful to programmers.
    449 Each option must be escaped with \Indexc{-XCFA}\index{translator option!-XCFA@{©-XCFA©}} to direct it to the compiler step, similar to the ©-Xlinker© flag for the linker, \eg:
    450 \begin{lstlisting}[language=sh]
    451 cfa $test$.cfa -CFA -XCFA -p # print translated code without printing the standard prelude
    452 cfa $test$.cfa -XCFA -P -XCFA parse -XCFA -n # show program parse without prelude
    453 \end{lstlisting}
    454442\begin{description}[topsep=5pt,itemsep=0pt,parsep=0pt]
    455443\item
    456 \Indexc{-c}\index{translator option!-c@{©-c©}}, \Indexc{--colors}\index{translator option!--colors@{©--colors©}} \, diagnostic color: ©never©, ©always©, \lstinline[deletekeywords=auto]{auto}
    457 \item
    458 \Indexc{-g}\index{translator option!-g@{©-g©}}, \Indexc{--gdb}\index{translator option!--gdb@{©--gdb©}} \, wait for gdb to attach
    459 \item
    460 \Indexc{-h}\index{translator option!-h@{©-h©}}, \Indexc{--help}\index{translator option!--help@{©--help©}} \, print translator help message
    461 \item
    462 \Indexc{-l}\index{translator option!-l@{©-l©}}, \Indexc{--libcfa}\index{translator option!--libcfa@{©--libcfa©}} \, generate ©libcfa.c©
     444\Indexc{-h}\index{translator option!-h@{©-h©}}, \Indexc{--help}\index{translator option!--help@{©--help©}} \, print help message
     445\item
     446\Indexc{-l}\index{translator option!-l@{©-l©}}, \Indexc{--libcfa}\index{translator option!--libcfa@{©--libcfa©}} \, generate libcfa.c
    463447\item
    464448\Indexc{-L}\index{translator option!-L@{©-L©}}, \Indexc{--linemarks}\index{translator option!--linemarks@{©--linemarks©}} \, generate line marks
     
    470454\Indexc{-n}\index{translator option!-n@{©-n©}}, \Indexc{--no-prelude}\index{translator option!--no-prelude@{©--no-prelude©}} \, do not read prelude
    471455\item
    472 \Indexc{-p}\index{translator option!-p@{©-p©}}, \Indexc{--prototypes}\index{translator option!--prototypes@{©--prototypes©}} \, do not generate prelude prototypes $\Rightarrow$ prelude not printed
    473 \item
    474 \Indexc{-d}\index{translator option!-d@{©-d©}}, \Indexc{--deterministic-out}\index{translator option!--deterministic-out@{©--deterministic-out©}} \, only print deterministic output
     456\Indexc{-p}\index{translator option!-p@{©-p©}}, \Indexc{--prototypes}\index{translator option!--prototypes@{©--prototypes©}} \, generate prototypes for prelude functions
    475457\item
    476458\Indexc{-P}\index{translator option!-P@{©-P©}}, \Indexc{--print}\index{translator option!--print@{©--print©}} \, one of:
    477459\begin{description}[topsep=0pt,itemsep=0pt,parsep=0pt]
    478460\item
     461\Indexc{altexpr}\index{translator option!-P@{©-P©}!©altexpr©}\index{translator option!--print@{©-print©}!©altexpr©} \, alternatives for expressions
     462\item
    479463\Indexc{ascodegen}\index{translator option!-P@{©-P©}!©ascodegen©}\index{translator option!--print@{©-print©}!©ascodegen©} \, as codegen rather than AST
    480464\item
     465\Indexc{ast}\index{translator option!-P@{©-P©}!©ast©}\index{translator option!--print@{©-print©}!©ast©} \, AST after parsing
     466\item
     467\Indexc{astdecl}\index{translator option!-P@{©-P©}!©astdecl©}\index{translator option!--print@{©-print©}!©astdecl©} \, AST after declaration validation pass
     468\item
    481469\Indexc{asterr}\index{translator option!-P@{©-P©}!©asterr©}\index{translator option!--print@{©-print©}!©asterr©} \, AST on error
    482470\item
     471\Indexc{astexpr}\index{translator option!-P@{©-P©}!©astexpr©}\index{translator option!--print@{©-print©}!©altexpr©} \, AST after expression analysis
     472\item
     473\Indexc{astgen}\index{translator option!-P@{©-P©}!©astgen©}\index{translator option!--print@{©-print©}!©astgen©} \, AST after instantiate generics
     474\item
     475\Indexc{box}\index{translator option!-P@{©-P©}!©box©}\index{translator option!--print@{©-print©}!©box©} \, before box step
     476\item
     477\Indexc{ctordtor}\index{translator option!-P@{©-P©}!©ctordtor©}\index{translator option!--print@{©-print©}!©ctordtor©} \, after ctor/dtor are replaced
     478\item
     479\Indexc{codegen}\index{translator option!-P@{©-P©}!©codegen©}\index{translator option!--print@{©-print©}!©codegen©} \, before code generation
     480\item
    483481\Indexc{declstats}\index{translator option!-P@{©-P©}!©declstats©}\index{translator option!--print@{©-print©}!©declstats©} \, code property statistics
    484482\item
    485483\Indexc{parse}\index{translator option!-P@{©-P©}!©parse©}\index{translator option!--print@{©-print©}!©parse©} \, yacc (parsing) debug information
    486484\item
    487 \Indexc{pretty}\index{translator option!-P@{©-P©}!©pretty©}\index{translator option!--print@{©-print©}!©pretty©} \, prettyprint for ©ascodegen© flag
     485\Indexc{pretty}\index{translator option!-P@{©-P©}!©pretty©}\index{translator option!--print@{©-print©}!©pretty©} \, prettyprint for ascodegen flag
     486\item
     487\Indexc{resolver}\index{translator option!-P@{©-P©}!©resolver©}\index{translator option!--print@{©-print©}!©resolver©} \, before resolver step
    488488\item
    489489\Indexc{rproto}\index{translator option!-P@{©-P©}!©rproto©}\index{translator option!--print@{©-print©}!©rproto©} \, resolver-proto instance
     
    491491\Indexc{rsteps}\index{translator option!-P@{©-P©}!©rsteps©}\index{translator option!--print@{©-print©}!©rsteps©} \, resolver steps
    492492\item
     493\Indexc{symevt}\index{translator option!-P@{©-P©}!©symevt©}\index{translator option!--print@{©-print©}!©symevt©} \, symbol table events
     494\item
    493495\Indexc{tree}\index{translator option!-P@{©-P©}!©tree©}\index{translator option!--print@{©-print©}!©tree©} \, parse tree
    494496\item
    495 \Indexc{ast}\index{translator option!-P@{©-P©}!©ast©}\index{translator option!--print@{©-print©}!©ast©} \, AST after parsing
    496 \item
    497 \Indexc{symevt}\index{translator option!-P@{©-P©}!©symevt©}\index{translator option!--print@{©-print©}!©symevt©} \, symbol table events
    498 \item
    499 \Indexc{altexpr}\index{translator option!-P@{©-P©}!©altexpr©}\index{translator option!--print@{©-print©}!©altexpr©} \, alternatives for expressions
    500 \item
    501 \Indexc{astdecl}\index{translator option!-P@{©-P©}!©astdecl©}\index{translator option!--print@{©-print©}!©astdecl©} \, AST after declaration validation pass
    502 \item
    503 \Indexc{resolver}\index{translator option!-P@{©-P©}!©resolver©}\index{translator option!--print@{©-print©}!©resolver©} \, before resolver step
    504 \item
    505 \Indexc{astexpr}\index{translator option!-P@{©-P©}!©astexpr©}\index{translator option!--print@{©-print©}!©altexpr©} \, AST after expression analysis
    506 \item
    507 \Indexc{ctordtor}\index{translator option!-P@{©-P©}!©ctordtor©}\index{translator option!--print@{©-print©}!©ctordtor©} \, after ctor/dtor are replaced
    508 \item
    509497\Indexc{tuple}\index{translator option!-P@{©-P©}!©tuple©}\index{translator option!--print@{©-print©}!©tuple©} \, after tuple expansion
    510 \item
    511 \Indexc{astgen}\index{translator option!-P@{©-P©}!©astgen©}\index{translator option!--print@{©-print©}!©astgen©} \, AST after instantiate generics
    512 \item
    513 \Indexc{box}\index{translator option!-P@{©-P©}!©box©}\index{translator option!--print@{©-print©}!©box©} \, before box step
    514 \item
    515 \Indexc{codegen}\index{translator option!-P@{©-P©}!©codegen©}\index{translator option!--print@{©-print©}!©codegen©} \, before code generation
    516498\end{description}
    517499\item
    518500\Indexc{--prelude-dir} <directory> \, prelude directory for debug/nodebug
    519501\item
    520 \Indexc{-S}\index{translator option!-S@{©-S©}!©counters,heap,time,all,none©}, \Indexc{--statistics}\index{translator option!--statistics@{©--statistics©}!©counters,heap,time,all,none©} <option-list> \, enable profiling information: ©counters©, ©heap©, ©time©, ©all©, ©none©
     502\Indexc{-S}\index{translator option!-S@{©-S©}!©counters,heap,time,all,none©}, \Indexc{--statistics}\index{translator option!--statistics@{©--statistics©}!©counters,heap,time,all,none©} <option-list> \, enable profiling information:
     503\begin{description}[topsep=0pt,itemsep=0pt,parsep=0pt]
     504\item
     505\Indexc{counters,heap,time,all,none}
     506\end{description}
    521507\item
    522508\Indexc{-t}\index{translator option!-t@{©-t©}}, \Indexc{--tree}\index{translator option!--tree@{©--tree©}} build in tree
     
    527513\label{s:BackquoteIdentifiers}
    528514
    529 \CFA introduces several new keywords \see{\VRef{s:CFAKeywords}} that can clash with existing C variable-names in legacy code.
     515\CFA introduces several new keywords (see \VRef{s:CFAKeywords}) that can clash with existing C variable-names in legacy code.
    530516Keyword clashes are accommodated by syntactic transformations using the \CFA backquote escape-mechanism:
    531517\begin{cfa}
    532 int @``@otype = 3; $\C{// make keyword an identifier}$
    533 double @``@forall = 3.5;
     518int ®``®otype = 3; §\C{// make keyword an identifier}§
     519double ®``®forall = 3.5;
    534520\end{cfa}
    535521
    536522Existing 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.
    537 \VRef[Figure]{f:HeaderFileInterposition} shows how clashes in existing C header-files \see{\VRef{s:StandardHeaders}} can be handled using preprocessor \newterm{interposition}: ©#include_next© and ©-I filename©.
     523\VRef[Figure]{f:HeaderFileInterposition} shows how clashes in existing C header-files (see~\VRef{s:StandardHeaders}) can be handled using preprocessor \newterm{interposition}: ©#include_next© and ©-I filename©.
    538524Several common C header-files with keyword clashes are fixed in the standard \CFA header-library, so there is a seamless programming-experience.
    539525
     
    541527\begin{cfa}
    542528// include file uses the CFA keyword "with".
    543 #if ! defined( with )                                                   $\C{// nesting ?}$
    544 #define with @``@with                                                   $\C{// make keyword an identifier}$
     529#if ! defined( with ) §\C{// nesting ?}§
     530#define with ®``®with §\C{// make keyword an identifier}§
    545531#define __CFA_BFD_H__
    546532#endif
    547 $\R{\#include\_next} <bfdlink.h>$                               $\C{// must have internal check for multiple expansion}$
    548 #if defined( with ) && defined( __CFA_BFD_H__ ) $\C{// reset only if set}$
     533§{\color{red}\#\textbf{include\_next} <bfdlink.h>}§ §\C{// must have internal check for multiple expansion}§
     534#if defined( with ) && defined( __CFA_BFD_H__ ) §\C{// reset only if set}§
    549535#undef with
    550536#undef __CFA_BFD_H__
     
    558544\section{Constant Underscores}
    559545
    560 Numeric constants are extended to allow \Index{underscore}s\index{constant!underscore} as a separator, \eg:
    561 \begin{cfa}
    562 2@_@147@_@483@_@648; $\C{// decimal constant}$
    563 56@_@ul; $\C{// decimal unsigned long constant}$
    564 0@_@377; $\C{// octal constant}$
    565 0x@_@ff@_@ff; $\C{// hexadecimal constant}$
    566 0x@_@ef3d@_@aa5c; $\C{// hexadecimal constant}$
    567 3.141@_@592@_@654; $\C{// floating constant}$
    568 10@_@e@_@+1@_@00; $\C{// floating constant}$
    569 0x@_@ff@_@ff@_@p@_@3; $\C{// hexadecimal floating}$
    570 0x@_@1.ffff@_@ffff@_@p@_@128@_@l; $\C{// hexadecimal floating long constant}$
    571 L@_@$"\texttt{\textbackslash{x}}$@_@$\texttt{ff}$@_@$\texttt{ee}"$; $\C{// wide character constant}$
     546Numeric constants are extended to allow \Index{underscore}s\index{constant!underscore}, \eg:
     547\begin{cfa}
     5482®_®147®_®483®_®648; §\C{// decimal constant}§
     54956®_®ul; §\C{// decimal unsigned long constant}§
     5500®_®377; §\C{// octal constant}§
     5510x®_®ff®_®ff; §\C{// hexadecimal constant}§
     5520x®_®ef3d®_®aa5c; §\C{// hexadecimal constant}§
     5533.141®_®592®_®654; §\C{// floating constant}§
     55410®_®e®_®+1®_®00; §\C{// floating constant}§
     5550x®_®ff®_®ff®_®p®_®3; §\C{// hexadecimal floating}§
     5560x®_®1.ffff®_®ffff®_®p®_®128®_®l; §\C{// hexadecimal floating long constant}§
     557L®_®§"\texttt{\textbackslash{x}}§®_®§\texttt{ff}§®_®§\texttt{ee}"§; §\C{// wide character constant}§
    572558\end{cfa}
    573559The rules for placement of underscores are:
     
    588574It is significantly easier to read and enter long constants when they are broken up into smaller groupings (many cultures use comma and/or period among digits for the same purpose).
    589575This extension is backwards compatible, matches with the use of underscore in variable names, and appears in \Index*{Ada} and \Index*{Java} 8.
    590 \CC uses the single quote (©'©) as a separator, restricted within a sequence of digits, \eg ©0xaa©©'©©ff©, ©3.141©©'©©592E1©©'©©1©.
    591576
    592577
    593578\section{Exponentiation Operator}
    594579
    595 C, \CC, and Java (and other programming languages) have no exponentiation operator\index{exponentiation!operator}\index{operator!exponentiation}, \ie $x^y$, and instead use a routine, like \Indexc{pow(x,y)}, to perform the exponentiation operation.
    596 \CFA extends the basic operators with the exponentiation operator ©?©\R{©\\©}©?©\index{?\\?@©?@\@?©} and ©?©\R{©\\©}©=?©\index{?\\=?@©@\@=?©}, as in, ©x ©\R{©\\©}© y© and ©x ©\R{©\\©}©= y©, which means $x^y$ and $x \leftarrow x^y$.
    597 The 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©.
     580C, \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(x,y)}, to perform the exponentiation operation.
     581\CFA extends the basic operators with the exponentiation operator ©?®\®?©\index{?\\?@©?®\®?©} and ©?\=?©\index{?\\=?@©®\®=?©}, as in, ©x ®\® y© and ©x ®\®= y©, which means $x^y$ and $x \leftarrow x^y$.
     582The 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)©.
    598583
    599584There are exponentiation operators for integral and floating types, including the builtin \Index{complex} types.
     
    602587Floating exponentiation\index{exponentiation!floating} is performed using \Index{logarithm}s\index{exponentiation!logarithm}, so the exponent cannot be negative.
    603588\begin{cfa}
    604 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
    605            | (1.0f+2.0fi) @\@ (3.0f+2.0fi);
    606 1 1 256 -64 125 @0@ 3273344365508751233 @0@ @0@ -0.015625 18.3791736799526 0.264715-1.1922i
     589sout | 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
     590           | (1.0f+2.0fi) ®\® (3.0f+2.0fi);
     5911 1 256 -64 125 ®0® 3273344365508751233 ®0® ®0® -0.015625 18.3791736799526 0.264715-1.1922i
    607592\end{cfa}
    608593Note, ©5 \ 32© and ©5L \ 64© overflow, and ©-4 \ -3© is a fraction but stored in an integer so all three computations generate an integral zero.
    609 Because exponentiation has higher priority than ©+©, parenthesis are necessary for exponentiation of \Index{complex constant}s or the expression is parsed as ©1.0f+©\R{©(©}©2.0fi \ 3.0f©\R{©)©}©+2.0fi©, requiring \R{©(©}©1.0f+2.0fi©\R{©)©}© \ ©\R{©(©}©3.0f+2.0fi©\R{©)©}.
    610 
     594Parenthesis are necessary for complex constants or the expression is parsed as ©1.0f+®(®2.0fi \ 3.0f®)®+2.0fi©.
    611595The exponentiation operator is available for all the basic types, but for user-defined types, only the integral-computation version is available.
    612596\begin{cfa}
    613 forall( otype T | { void ?{}( T & this, one_t ); T ?*?( T, T ); } )
    614 T ?@\@?( T ep, unsigned int y );
    615 forall( otype T | { void ?{}( T & this, one_t ); T ?*?( T, T ); } )
    616 T ?@\@?( T ep, unsigned long int y );
     597forall( otype OT | { void ?{}( OT & this, one_t ); OT ?*?( OT, OT ); } )
     598OT ?®\®?( OT ep, unsigned int y );
     599forall( otype OT | { void ?{}( OT & this, one_t ); OT ?*?( OT, OT ); } )
     600OT ?®\®?( OT ep, unsigned long int y );
    617601\end{cfa}
    618602The user type ©T© must define multiplication, one (©1©), and ©*©.
     
    625609
    626610%\subsection{\texorpdfstring{\protect\lstinline@if@/\protect\lstinline@while@ Statement}{if Statement}}
    627 \subsection{\texorpdfstring{\LstKeywordStyle{if} / \LstKeywordStyle{while} Statement}{if / while Statement}}
    628 
    629 The ©if©/©while© expression allows declarations, similar to ©for© declaration expression.\footnote{
    630 Declarations in the ©do©-©while© condition are not useful because they appear after the loop body.}
    631 \begin{cfa}
    632 if ( @int x = f()@ ) ... $\C{// x != 0}$
    633 if ( @int x = f(), y = g()@ ) ... $\C{// x != 0 \&\& y != 0}$
    634 if ( @int x = f(), y = g(); x < y@ ) ... $\C{// relational expression}$
    635 if ( @struct S { int i; } x = { f() }; x.i < 4@ ) $\C{// relational expression}$
    636 
    637 while ( @int x = f()@ ) ... $\C{// x != 0}$
    638 while ( @int x = f(), y = g()@ ) ... $\C{// x != 0 \&\& y != 0}$
    639 while ( @int x = f(), y = g(); x < y@ ) ... $\C{// relational expression}$
    640 while ( @struct S { int i; } x = { f() }; x.i < 4@ ) ... $\C{// relational expression}$
    641 \end{cfa}
    642 Unless a relational expression is specified, each variable is compared not equal to 0, which is the standard semantics for the ©if©/©while© expression, and the results are combined using the logical ©&&© operator.
    643 The scope of the declaration(s) is local to the ©if© statement but exist within both the \emph{then} and \emph{else} clauses.
    644 \CC only provides a single declaration always compared ©!=© to 0.
     611\subsection{\texorpdfstring{\LstKeywordStyle{if}/\LstKeywordStyle{while} Statement}{if/while Statement}}
     612
     613The ©if©/©while© expression allows declarations, similar to ©for© declaration expression.
     614(Does not make sense for ©do©-©while©.)
     615\begin{cfa}
     616if ( ®int x = f()® ) ... §\C{// x != 0}§
     617if ( ®int x = f(), y = g()® ) ... §\C{// x != 0 \&\& y != 0}§
     618if ( ®int x = f(), y = g(); x < y® ) ... §\C{// relational expression}§
     619if ( ®struct S { int i; } x = { f() }; x.i < 4® ) §\C{// relational expression}§
     620
     621while ( ®int x = f()® ) ... §\C{// x != 0}§
     622while ( ®int x = f(), y = g()® ) ... §\C{// x != 0 \&\& y != 0}§
     623while ( ®int x = f(), y = g(); x < y® ) ... §\C{// relational expression}§
     624while ( ®struct S { int i; } x = { f() }; x.i < 4® ) ... §\C{// relational expression}§
     625\end{cfa}
     626Unless a relational expression is specified, each variable is compared not equal to 0, which is the standard semantics for the ©if©/©while© expression, and the results are combined using the logical ©&&© operator.\footnote{\CC only provides a single declaration always compared not equal to 0.}
     627The scope of the declaration(s) is local to the @if@ statement but exist within both the ``then'' and ``else'' clauses.
    645628
    646629
    647630%\section{\texorpdfstring{\protect\lstinline@case@ Clause}{case Clause}}
    648631\subsection{\texorpdfstring{\LstKeywordStyle{case} Clause}{case Clause}}
    649 \label{s:caseClause}
    650632
    651633C restricts the ©case© clause of a ©switch© statement to a single value.
     
    658640\begin{cfa}
    659641switch ( i ) {
    660   case @1, 3, 5@:
     642  case ®1, 3, 5®:
    661643        ...
    662   case @2, 4, 6@:
     644  case ®2, 4, 6®:
    663645        ...
    664646}
     
    688670\begin{cfa}
    689671switch ( i ) {
    690   case @1~5:@ $\C{// 1, 2, 3, 4, 5}$
     672  case ®1~5:® §\C{// 1, 2, 3, 4, 5}§
    691673        ...
    692   case @10~15:@ $\C{// 10, 11, 12, 13, 14, 15}$
     674  case ®10~15:® §\C{// 10, 11, 12, 13, 14, 15}§
    693675        ...
    694676}
     
    696678Lists of subranges are also allowed.
    697679\begin{cfa}
    698 case @1~5, 12~21, 35~42@:
     680case ®1~5, 12~21, 35~42®:
    699681\end{cfa}
    700682
     
    740722if ( argc == 3 ) {
    741723        // open output file
    742         @// open input file
    743 @} else if ( argc == 2 ) {
    744         @// open input file (duplicate)
    745 
    746 @} else {
     724        ®// open input file
     725®} else if ( argc == 2 ) {
     726        ®// open input file (duplicate)
     727
     728®} else {
    747729        // usage message
    748730}
     
    751733\end{cquote}
    752734In this example, case 2 is always done if case 3 is done.
    753 This control flow is difficult to simulate with ©if© statements or a ©switch© statement without fall-through as code must be duplicated or placed in a separate routine.
     735This control flow is difficult to simulate with if statements or a ©switch© statement without fall-through as code must be duplicated or placed in a separate routine.
    754736C also uses fall-through to handle multiple case-values resulting in the same action:
    755737\begin{cfa}
    756738switch ( i ) {
    757   @case 1: case 3: case 5:@     // odd values
     739  ®case 1: case 3: case 5:®     // odd values
    758740        // odd action
    759741        break;
    760   @case 2: case 4: case 6:@     // even values
     742  ®case 2: case 4: case 6:®     // even values
    761743        // even action
    762744        break;
    763745}
    764746\end{cfa}
    765 This situation better handled without fall-through by allowing a list of case values \see{\VRef{s:caseClause}}.
    766 While 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.
     747However, this situation is handled in other languages without fall-through by allowing a list of case values.
     748While 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 virtually all other programming languages with a ©switch© statement.
    767749Hence, 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.
    768750
     
    774756        if ( j < k ) {
    775757                ...
    776           @case 1:@             // transfer into "if" statement
     758          ®case 1:®             // transfer into "if" statement
    777759                ...
    778760        } // if
     
    780762        while ( j < 5 ) {
    781763                ...
    782           @case 3:@             // transfer into "while" statement
     764          ®case 3:®             // transfer into "while" statement
    783765                ...
    784766        } // while
    785767} // switch
    786768\end{cfa}
    787 This usage branches into control structures, which is known to cause both comprehension and technical difficulties.
    788 The comprehension problem results from the inability to determine how control reaches a particular point due to the number of branches leading to it.
     769The problem with this usage is branching into control structures, which is known to cause both comprehension and technical difficulties.
     770The comprehension problem occurs from the inability to determine how control reaches a particular point due to the number of branches leading to it.
    789771The technical problem results from the inability to ensure declaration and initialization of variables when blocks are not entered at the beginning.
    790 There are few arguments for this kind of control flow, and therefore, there is a strong impetus to eliminate it.
     772There are no positive arguments for this kind of control flow, and therefore, there is a strong impetus to eliminate it.
    791773Nevertheless, C does have an idiom where this capability is used, known as ``\Index*{Duff's device}''~\cite{Duff83}:
    792774\begin{cfa}
     
    812794\item
    813795It is possible to place the ©default© clause anywhere in the list of labelled clauses for a ©switch© statement, rather than only at the end.
    814 Most programming languages with a ©switch© statement require the ©default© clause to appear last in the case-clause list.
     796Virtually all programming languages with a ©switch© statement require the ©default© clause to appear last in the case-clause list.
    815797The logic for this semantics is that after checking all the ©case© clauses without success, the ©default© clause is selected;
    816798hence, physically placing the ©default© clause at the end of the ©case© clause list matches with this semantics.
     
    821803\begin{cfa}
    822804switch ( x ) {
    823         @int y = 1;@ $\C{// unreachable initialization}$
    824         @x = 7;@ $\C{// unreachable code without label/branch}$
     805        ®int y = 1;® §\C{// unreachable initialization}§
     806        ®x = 7;® §\C{// unreachable code without label/branch}§
    825807  case 0: ...
    826808        ...
    827         @int z = 0;@ $\C{// unreachable initialization, cannot appear after case}$
     809        ®int z = 0;® §\C{// unreachable initialization, cannot appear after case}§
    828810        z = 2;
    829811  case 1:
    830         @x = z;@ $\C{// without fall through, z is uninitialized}$
     812        ®x = z;® §\C{// without fall through, z is uninitialized}§
    831813}
    832814\end{cfa}
    833815While the declaration of the local variable ©y© is useful with a scope across all ©case© clauses, the initialization for such a variable is defined to never be executed because control always transfers over it.
    834 Furthermore, any statements before the first ©case© clause can only be executed if labelled and transferred to using a ©goto©, either from outside or inside of the ©switch©, where both are problematic.
    835 As well, the declaration of ©z© cannot occur after the ©case© because a label can only be attached to a statement, and without a fall-through to case 3, ©z© is uninitialized.
    836 The key observation is that the ©switch© statement branches into a control structure, \ie there are multiple entry points into its statement body.
     816Furthermore, any statements before the first ©case© clause can only be executed if labelled and transferred to using a ©goto©, either from outside or inside of the ©switch©, both of which are problematic.
     817As well, the declaration of ©z© cannot occur after the ©case© because a label can only be attached to a statement, and without a fall through to case 3, ©z© is uninitialized.
     818The key observation is that the ©switch© statement branches into control structure, \ie there are multiple entry points into its statement body.
    837819\end{enumerate}
    838820
     
    860842Therefore, to preserve backwards compatibility, it is necessary to introduce a new kind of ©switch© statement, called ©choose©, with no implicit fall-through semantics and an explicit fall-through if the last statement of a case-clause ends with the new keyword ©fallthrough©/©fallthru©, \eg:
    861843\begin{cfa}
    862 @choose@ ( i ) {
     844®choose® ( i ) {
    863845  case 1:  case 2:  case 3:
    864846        ...
    865         @// implicit end of switch (break)
    866   @case 5:
     847        ®// implicit end of switch (break)
     848  ®case 5:
    867849        ...
    868         @fallthru@; $\C{// explicit fall through}$
     850        ®fallthru®; §\C{// explicit fall through}§
    869851  case 7:
    870852        ...
    871         @break@ $\C{// explicit end of switch (redundant)}$
     853        ®break® §\C{// explicit end of switch (redundant)}§
    872854  default:
    873855        j = 3;
    874856}
    875857\end{cfa}
    876 Like the ©switch© statement, the ©choose© statement retains the fall-through semantics for a list of ©case© clauses.
     858Like the ©switch© statement, the ©choose© statement retains the fall-through semantics for a list of ©case© clauses;
    877859An implicit ©break© is applied only at the end of the \emph{statements} following a ©case© clause.
    878860An explicit ©fallthru© is retained because it is a C-idiom most C programmers expect, and its absence might discourage programmers from using the ©choose© statement.
     
    890872\begin{cfa}
    891873switch ( x ) {
    892         @int i = 0;@ $\C{// allowed only at start}$
     874        ®int i = 0;® §\C{// allowed only at start}§
    893875  case 0:
    894876        ...
    895         @int j = 0;@ $\C{// disallowed}$
     877        ®int j = 0;® §\C{// disallowed}§
    896878  case 1:
    897879        {
    898                 @int k = 0;@ $\C{// allowed at different nesting levels}$
     880                ®int k = 0;® §\C{// allowed at different nesting levels}§
    899881                ...
    900           @case 2:@ $\C{// disallow case in nested statements}$
     882          ®case 2:® §\C{// disallow case in nested statements}§
    901883        }
    902884  ...
     
    915897  case 3:
    916898        if ( ... ) {
    917                 ... @fallthru;@ // goto case 4
     899                ... ®fallthru;® // goto case 4
    918900        } else {
    919901                ...
     
    930912choose ( ... ) {
    931913  case 3:
    932         ... @fallthrough common;@
     914        ... ®fallthrough common;®
    933915  case 4:
    934         ... @fallthrough common;@
    935 
    936   @common:@ // below fallthrough
     916        ... ®fallthrough common;®
     917
     918  ®common:® // below fallthrough
    937919                          // at case-clause level
    938920        ...     // common code for cases 3/4
     
    950932                for ( ... ) {
    951933                        // multi-level transfer
    952                         ... @fallthru common;@
     934                        ... ®fallthru common;®
    953935                }
    954936                ...
    955937        }
    956938        ...
    957   @common:@ // below fallthrough
     939  ®common:® // below fallthrough
    958940                          // at case-clause level
    959941\end{cfa}
     
    966948
    967949\begin{figure}
    968 \begin{tabular}{@{}l@{\hspace{25pt}}|l@{}}
    969 \multicolumn{1}{@{}c@{\hspace{25pt}}|}{loop control} & \multicolumn{1}{c@{}}{output} \\
     950\begin{tabular}{@{}l|l@{}}
     951\multicolumn{1}{c|}{loop control} & \multicolumn{1}{c}{output} \\
    970952\hline
    971 \begin{cfa}
    972 while @($\,$)@ { sout | "empty"; break; }
    973 do { sout | "empty"; break; } while @($\,$)@;
    974 for @($\,$)@ { sout | "empty"; break; }
    975 for ( @0@ ) { sout | "A"; } sout | "zero";
    976 for ( @1@ ) { sout | "A"; }
    977 for ( @10@ ) { sout | "A"; }
    978 for ( @= 10@ ) { sout | "A"; }
    979 for ( @1 ~= 10 ~ 2@ ) { sout | "B"; }
    980 for ( @10 -~= 1 ~ 2@ ) { sout | "C"; }
    981 for ( @0.5 ~ 5.5@ ) { sout | "D"; }
    982 for ( @5.5 -~ 0.5@ ) { sout | "E"; }
    983 for ( @i; 10@ ) { sout | i; }
    984 for ( @i; = 10@ ) { sout | i; }
    985 for ( @i; 1 ~= 10 ~ 2@ ) { sout | i; }
    986 for ( @i; 10 -~= 1 ~ 2@ ) { sout | i; }
    987 for ( @i; 0.5 ~ 5.5@ ) { sout | i; }
    988 for ( @i; 5.5 -~ 0.5@ ) { sout | i; }
    989 for ( @ui; 2u ~= 10u ~ 2u@ ) { sout | ui; }
    990 for ( @ui; 10u -~= 2u ~ 2u@ ) { sout | ui; }
     953\begin{cfa}[xleftmargin=0pt]
     954while ®()® { sout | "empty"; break; }
     955do { sout | "empty"; break; } while ®()®;
     956for ®()® { sout | "empty"; break; }
     957for ( ®0® ) { sout | "A"; } sout | "zero";
     958for ( ®1® ) { sout | "A"; }
     959for ( ®10® ) { sout | "A"; }
     960for ( ®= 10® ) { sout | "A"; }
     961for ( ®1 ~= 10 ~ 2® ) { sout | "B"; }
     962for ( ®10 -~= 1 ~ 2® ) { sout | "C"; }
     963for ( ®0.5 ~ 5.5® ) { sout | "D"; }
     964for ( ®5.5 -~ 0.5® ) { sout | "E"; }
     965for ( ®i; 10® ) { sout | i; }
     966for ( ®i; = 10® ) { sout | i; }
     967for ( ®i; 1 ~= 10 ~ 2® ) { sout | i; }
     968for ( ®i; 10 -~= 1 ~ 2® ) { sout | i; }
     969for ( ®i; 0.5 ~ 5.5® ) { sout | i; }
     970for ( ®i; 5.5 -~ 0.5® ) { sout | i; }
     971for ( ®ui; 2u ~= 10u ~ 2u® ) { sout | ui; }
     972for ( ®ui; 10u -~= 2u ~ 2u® ) { sout | ui; }
    991973enum { N = 10 };
    992 for ( @N@ ) { sout | "N"; }
    993 for ( @i; N@ ) { sout | i; }
    994 for ( @i; N -~ 0@ ) { sout | i; }
     974for ( ®N® ) { sout | "N"; }
     975for ( ®i; N® ) { sout | i; }
     976for ( ®i; N -~ 0® ) { sout | i; }
    995977const int start = 3, comp = 10, inc = 2;
    996 for ( @i; start ~ comp ~ inc + 1@ ) { sout | i; }
    997 for ( i; 1 ~ $\R{@}$ ) { if ( i > 10 ) break; sout | i; }
    998 for ( i; 10 -~ $\R{@}$ ) { if ( i < 0 ) break; sout | i; }
    999 for ( i; 2 ~ $\R{@}$ ~ 2 ) { if ( i > 10 ) break; sout | i; }
    1000 for ( i; 2.1 ~ $\R{@}$ ~ $\R{@}$ ) { if ( i > 10.5 ) break; sout | i; i += 1.7; }
    1001 for ( i; 10 -~ $\R{@}$ ~ 2 ) { if ( i < 0 ) break; sout | i; }
    1002 for ( i; 12.1 ~ $\R{@}$ ~ $\R{@}$ ) { if ( i < 2.5 ) break; sout | i; i -= 1.7; }
    1003 for ( i; 5 @:@ j; -5 ~ $@$ ) { sout | i | j; }
    1004 for ( i; 5 @:@ j; -5 -~ $@$ ) { sout | i | j; }
    1005 for ( i; 5 @:@ j; -5 ~ $@$ ~ 2 ) { sout | i | j; }
    1006 for ( i; 5 @:@ j; -5 -~ $@$ ~ 2 ) { sout | i | j; }
    1007 for ( i; 5 @:@ j; -5 ~ $@$ ) { sout | i | j; }
    1008 for ( i; 5 @:@ j; -5 -~ $@$ ) { sout | i | j; }
    1009 for ( i; 5 @:@ j; -5 ~ $@$ ~ 2 ) { sout | i | j; }
    1010 for ( i; 5 @:@ j; -5 -~ $@$ ~ 2 ) { sout | i | j; }
    1011 for ( i; 5 @:@ j; -5 -~ $@$ ~ 2 @:@ k; 1.5 ~ $@$ ) { sout | i | j | k; }
    1012 for ( i; 5 @:@ j; -5 -~ $@$ ~ 2 @:@ k; 1.5 ~ $@$ ) { sout | i | j | k; }
    1013 for ( i; 5 @:@ k; 1.5 ~ $@$ @:@ j; -5 -~ $@$ ~ 2 ) { sout | i | j | k; }
     978for ( ®i; start ~ comp ~ inc + 1® ) { sout | i; }
     979for ( i; 1 ~ ®@® ) { if ( i > 10 ) break; sout | i; }
     980for ( i; 10 -~ ®@® ) { if ( i < 0 ) break; sout | i; }
     981for ( i; 2 ~ ®@® ~ 2 ) { if ( i > 10 ) break; sout | i; }
     982for ( i; 2.1 ~ ®@® ~ ®@® ) { if ( i > 10.5 ) break; sout | i; i += 1.7; }
     983for ( i; 10 -~ ®@® ~ 2 ) { if ( i < 0 ) break; sout | i; }
     984for ( i; 12.1 ~ ®@® ~ ®@® ) { if ( i < 2.5 ) break; sout | i; i -= 1.7; }
     985for ( i; 5 ®:® j; -5 ~ @ ) { sout | i | j; }
     986for ( i; 5 ®:® j; -5 -~ @ ) { sout | i | j; }
     987for ( i; 5 ®:® j; -5 ~ @ ~ 2 ) { sout | i | j; }
     988for ( i; 5 ®:® j; -5 -~ @ ~ 2 ) { sout | i | j; }
     989for ( i; 5 ®:® j; -5 ~ @ ) { sout | i | j; }
     990for ( i; 5 ®:® j; -5 -~ @ ) { sout | i | j; }
     991for ( i; 5 ®:® j; -5 ~ @ ~ 2 ) { sout | i | j; }
     992for ( i; 5 ®:® j; -5 -~ @ ~ 2 ) { sout | i | j; }
     993for ( i; 5 ®:® j; -5 -~ @ ~ 2 ®:® k; 1.5 ~ @ ) { sout | i | j | k; }
     994for ( i; 5 ®:® j; -5 -~ @ ~ 2 ®:® k; 1.5 ~ @ ) { sout | i | j | k; }
     995for ( i; 5 ®:® k; 1.5 ~ @ ®:® j; -5 -~ @ ~ 2 ) { sout | i | j | k; }
    1014996\end{cfa}
    1015997&
     
    10741056\subsection{Loop Control}
    10751057
    1076 Looping a fixed number of times, possibly with a loop index, occurs frequently.
    1077 \CFA condenses simply looping to facilitate coding speed and safety.
    1078 The ©for©/©while©/©do-while© loop-control is augmented as follows \see{examples in \VRef[Figure]{f:LoopControlExamples}}:
    1079 \begin{itemize}[itemsep=0pt]
     1058The ©for©/©while©/©do-while© loop-control allows empty or simplified ranges (see Figure~\ref{f:LoopControlExamples}).
     1059\begin{itemize}
     1060\item
     1061The loop index is polymorphic in the type of the comparison value N (when the start value is implicit) or the start value M.
     1062\item
     1063An empty conditional implies comparison value of ©1© (true).
     1064\item
     1065A comparison N is implicit up-to exclusive range [0,N©®)®©.
     1066\item
     1067A comparison ©=© N is implicit up-to inclusive range [0,N©®]®©.
     1068\item
     1069The up-to range M ©~©\index{~@©~©} N means exclusive range [M,N©®)®©.
     1070\item
     1071The up-to range M ©~=©\index{~=@©~=©} N means inclusive range [M,N©®]®©.
     1072\item
     1073The down-to range M ©-~©\index{-~@©-~©} N means exclusive range [N,M©®)®©.
     1074\item
     1075The down-to range M ©-~=©\index{-~=@©-~=©} N means inclusive range [N,M©®]®©.
    10801076\item
    10811077©0© is the implicit start value;
     
    10871083The down-to range uses operator ©-=© for decrement.
    10881084\item
    1089 The loop index is polymorphic in the type of the comparison value N (when the start value is implicit) or the start value M.
    1090 \begin{cfa}
    1091 for ( i; @5@ )                                  $\C[2.5in]{// typeof(5) i; 5 is comparison value}$
    1092 for ( i; @1.5@~5.5~0.5 )                $\C{// typeof(1.5) i; 1.5 is start value}$
    1093 \end{cfa}
    1094 \item
    1095 An empty conditional implies comparison value of ©1© (true).
    1096 \begin{cfa}
    1097 while ( $\R{/*empty*/}$ )               $\C{// while ( true )}$
    1098 for ( $\R{/*empty*/}$ )                 $\C{// for ( ; true; )}$
    1099 do ... while ( $\R{/*empty*/}$ ) $\C{// do ... while ( true )}$
    1100 \end{cfa}
    1101 \item
    1102 A comparison N is implicit up-to exclusive range [0,N\R{)}.
    1103 \begin{cfa}
    1104 for ( @5@ )                                             $\C{// for ( typeof(5) i; i < 5; i += 1 )}$
    1105 \end{cfa}
    1106 \item
    1107 A comparison ©=© N is implicit up-to inclusive range [0,N\R{]}.
    1108 \begin{cfa}
    1109 for ( @=@5 )                                    $\C{// for ( typeof(5) i; i <= 5; i += 1 )}$
    1110 \end{cfa}
    1111 \item
    1112 The up-to range M ©~©\index{~@©~©} N means exclusive range [M,N\R{)}.
    1113 \begin{cfa}
    1114 for ( 1@~@5 )                                   $\C{// for ( typeof(1) i = 1; i < 5; i += 1 )}$
    1115 \end{cfa}
    1116 \item
    1117 The up-to range M ©~=©\index{~=@©~=©} N means inclusive range [M,N\R{]}.
    1118 \begin{cfa}
    1119 for ( 1@~=@5 )                                  $\C{// for ( typeof(1) i = 1; i <= 5; i += 1 )}$
    1120 \end{cfa}
    1121 \item
    1122 The down-to range M ©-~©\index{-~@©-~©} N means exclusive range [N,M\R{)}.
    1123 \begin{cfa}
    1124 for ( 1@-~@5 )                                  $\C{// for ( typeof(1) i = 5; i > 0; i -= 1 )}$
    1125 \end{cfa}
    1126 \item
    1127 The down-to range M ©-~=©\index{-~=@©-~=©} N means inclusive range [N,M\R{]}.
    1128 \begin{cfa}
    1129 for ( 1@-~=@5 )                                 $\C{// for ( typeof(1) i = 5; i >= 0; i -= 1 )}$
    1130 \end{cfa}
    1131 \item
    11321085©@© means put nothing in this field.
    1133 \begin{cfa}
    1134 for ( 1~$\R{@}$~2 )                             $\C{// for ( typeof(1) i = 1; /*empty*/; i += 2 )}$
    1135 \end{cfa}
    11361086\item
    11371087©:© means start another index.
    1138 \begin{cfa}
    1139 for ( i; 5 @:@ j; 2~12~3 )              $\C{// for ( typeof(i) i = 1, j = 2; i < 5 \&\& j < 12; i += 1, j += 3 )}\CRT$
    1140 \end{cfa}
    11411088\end{itemize}
    11421089
     
    11451092\subsection{\texorpdfstring{Labelled \LstKeywordStyle{continue} / \LstKeywordStyle{break} Statement}{Labelled continue / break Statement}}
    11461093
    1147 C ©continue© and ©break© statements, for altering control flow, are restricted to one level of nesting for a particular control structure.
    1148 This restriction forces programmers to use \Indexc{goto} to achieve the equivalent control-flow for more than one level of nesting.
     1094While C provides ©continue© and ©break© statements for altering control flow, both are restricted to one level of nesting for a particular control structure.
     1095Unfortunately, this restriction forces programmers to use \Indexc{goto} to achieve the equivalent control-flow for more than one level of nesting.
    11491096To prevent having to switch to the ©goto©, \CFA extends the \Indexc{continue}\index{continue@©continue©!labelled}\index{labelled!continue@©continue©} and \Indexc{break}\index{break@©break©!labelled}\index{labelled!break@©break©} with a target label to support static multi-level exit\index{multi-level exit}\index{static multi-level exit}~\cite{Buhr85}, as in Java.
    11501097For both ©continue© and ©break©, the target label must be directly associated with a ©for©, ©while© or ©do© statement;
    11511098for ©break©, the target label can also be associated with a ©switch©, ©if© or compound (©{}©) statement.
    1152 \VRef[Figure]{f:MultiLevelExit} shows a comparison between labelled ©continue© and ©break© and the corresponding C equivalent using ©goto© and labels.
     1099\VRef[Figure]{f:MultiLevelExit} shows ©continue© and ©break© indicating the specific control structure, and the corresponding C program using only ©goto© and labels.
    11531100The innermost loop has 8 exit points, which cause continuation or termination of one or more of the 7 \Index{nested control-structure}s.
    11541101
     
    11571104\begin{lrbox}{\myboxA}
    11581105\begin{cfa}[tabsize=3]
    1159 @Compound:@ {
    1160         @Try:@ try {
    1161                 @For:@ for ( ... ) {
    1162                         @While:@ while ( ... ) {
    1163                                 @Do:@ do {
    1164                                         @If:@ if ( ... ) {
    1165                                                 @Switch:@ switch ( ... ) {
     1106®Compound:® {
     1107        ®Try:® try {
     1108                ®For:® for ( ... ) {
     1109                        ®While:® while ( ... ) {
     1110                                ®Do:® do {
     1111                                        ®If:® if ( ... ) {
     1112                                                ®Switch:® switch ( ... ) {
    11661113                                                        case 3:
    1167                                                                 @break Compound@;
    1168                                                                 @break Try@;
    1169                                                                 @break For@;      /* or */  @continue For@;
    1170                                                                 @break While@;  /* or */  @continue While@;
    1171                                                                 @break Do@;      /* or */  @continue Do@;
    1172                                                                 @break If@;
    1173                                                                 @break Switch@;
     1114                                                                ®break Compound®;
     1115                                                                ®break Try®;
     1116                                                                ®break For®;      /* or */  ®continue For®;
     1117                                                                ®break While®;  /* or */  ®continue While®;
     1118                                                                ®break Do®;      /* or */  ®continue Do®;
     1119                                                                ®break If®;
     1120                                                                ®break Switch®;
    11741121                                                        } // switch
    11751122                                                } else {
    1176                                                         ... @break If@; ...     // terminate if
     1123                                                        ... ®break If®; ...     // terminate if
    11771124                                                } // if
    11781125                                } while ( ... ); // do
    11791126                        } // while
    11801127                } // for
    1181         } @finally@ { // always executed
     1128        } ®finally® { // always executed
    11821129        } // try
    11831130} // compound
     
    11891136{
    11901137
    1191                 @ForC:@ for ( ... ) {
    1192                         @WhileC:@ while ( ... ) {
    1193                                 @DoC:@ do {
     1138                ®ForC:® for ( ... ) {
     1139                        ®WhileC:® while ( ... ) {
     1140                                ®DoC:® do {
    11941141                                        if ( ... ) {
    11951142                                                switch ( ... ) {
    11961143                                                        case 3:
    1197                                                                 @goto Compound@;
    1198                                                                 @goto Try@;
    1199                                                                 @goto ForB@;      /* or */  @goto ForC@;
    1200                                                                 @goto WhileB@;  /* or */  @goto WhileC@;
    1201                                                                 @goto DoB@;      /* or */  @goto DoC@;
    1202                                                                 @goto If@;
    1203                                                                 @goto Switch@;
    1204                                                         } @Switch:@ ;
     1144                                                                ®goto Compound®;
     1145                                                                ®goto Try®;
     1146                                                                ®goto ForB®;      /* or */  ®goto ForC®;
     1147                                                                ®goto WhileB®;  /* or */  ®goto WhileC®;
     1148                                                                ®goto DoB®;      /* or */  ®goto DoC®;
     1149                                                                ®goto If®;
     1150                                                                ®goto Switch®;
     1151                                                        } ®Switch:® ;
    12051152                                                } else {
    1206                                                         ... @goto If@; ...      // terminate if
    1207                                                 } @If:@;
    1208                                 } while ( ... ); @DoB:@ ;
    1209                         } @WhileB:@ ;
    1210                 } @ForB:@ ;
    1211 
    1212 
    1213 } @Compound:@ ;
     1153                                                        ... ®goto If®; ...      // terminate if
     1154                                                } ®If:®;
     1155                                } while ( ... ); ®DoB:® ;
     1156                        } ®WhileB:® ;
     1157                } ®ForB:® ;
     1158
     1159
     1160} ®Compound:® ;
    12141161\end{cfa}
    12151162\end{lrbox}
    12161163
    12171164\subfloat[\CFA]{\label{f:CFibonacci}\usebox\myboxA}
    1218 \hspace{3pt}
     1165\hspace{2pt}
    12191166\vrule
    1220 \hspace{3pt}
     1167\hspace{2pt}
    12211168\subfloat[C]{\label{f:CFAFibonacciGen}\usebox\myboxB}
    12221169\caption{Multi-level Exit}
     
    12331180This restriction prevents missing declarations and/or initializations at the start of a control structure resulting in undefined behaviour.
    12341181\end{itemize}
    1235 The advantage of the labelled ©continue©/©break© is allowing static multi-level exits without having to use the ©goto© statement, and tying control flow to the target control structure rather than an arbitrary point in a program via a label.
     1182The advantage of the labelled ©continue©/©break© is allowing static multi-level exits without having to use the ©goto© statement, and tying control flow to the target control structure rather than an arbitrary point in a program.
    12361183Furthermore, the location of the label at the \emph{beginning} of the target control structure informs the reader (\Index{eye candy}) that complex control-flow is occurring in the body of the control structure.
    12371184With ©goto©, the label is at the end of the control structure, which fails to convey this important clue early enough to the reader.
     
    12401187
    12411188
    1242 %\subsection{\texorpdfstring{\protect\lstinline@with@ Statement}{with Statement}}
    1243 \subsection{\texorpdfstring{\LstKeywordStyle{with} Statement}{with Statement}}
     1189%\section{\texorpdfstring{\protect\lstinline@with@ Statement}{with Statement}}
     1190\section{\texorpdfstring{\LstKeywordStyle{with} Statement}{with Statement}}
    12441191\label{s:WithStatement}
    12451192
    1246 Grouping heterogeneous data into an \newterm{aggregate} (structure/union) is a common programming practice, and aggregates may be nested:
    1247 \begin{cfa}
    1248 struct Person {                                                         $\C{// aggregate}$
    1249         struct Name { char first[20], last[20]; } name $\C{// nesting}$
    1250         struct Address { ... } address                  $\C{// nesting}$
    1251         int sex;
     1193Grouping heterogeneous data into \newterm{aggregate}s (structure/union) is a common programming practice, and an aggregate can be further organized into more complex structures, such as arrays and containers:
     1194\begin{cfa}
     1195struct S { §\C{// aggregate}§
     1196        char c; §\C{// fields}§
     1197        int i;
     1198        double d;
    12521199};
    1253 \end{cfa}
    1254 Functions manipulating aggregates must repeat the aggregate name to access its containing fields.
    1255 \begin{cfa}
    1256 Person p
    1257 @p.@name; @p.@address; @p.@sex; $\C{// access containing fields}$
    1258 \end{cfa}
    1259 which extends to multiple levels of qualification for nested aggregates and multiple aggregates.
    1260 \begin{cfa}
    1261 struct Ticket { ... } t;
    1262 @p.name@.first; @p.address@.street;             $\C{// access nested fields}$
    1263 @t.@departure; @t.@cost;                                $\C{// access multiple aggregate}$
    1264 \end{cfa}
    1265 Repeated aggregate qualification is tedious and makes code difficult to read.
    1266 Therefore, reducing aggregate qualification is a useful language design goal.
    1267 
    1268 C allows unnamed nested aggregates that open their scope into the containing aggregate.
    1269 This feature is used to group fields for attributes and/or with ©union© aggregates.
    1270 \begin{cfa}
    1271 struct S {
    1272         struct { int g,  h; } __attribute__(( aligned(64) ));
    1273         int tag;
    1274         union {
    1275                 struct { char c1,  c2; } __attribute__(( aligned(128) ));
    1276                 struct { int i1,  i2; };
    1277                 struct { double d1,  d2; };
    1278         };
    1279 };
    1280 s.g; s.h; s.tag; s.c1; s.c2; s.i1; s.i2; s.d1; s.d2;
    1281 \end{cfa}
    1282 
    1283 Object-oriented languages reduce qualification for class variables within member functions, \eg \CC:
     1200S s, as[10];
     1201\end{cfa}
     1202However, functions manipulating aggregates must repeat the aggregate name to access its containing fields:
     1203\begin{cfa}
     1204void f( S s ) {
     1205        ®s.®c; ®s.®i; ®s.®d; §\C{// access containing fields}§
     1206}
     1207\end{cfa}
     1208which extends to multiple levels of qualification for nested aggregates.
     1209A similar situation occurs in object-oriented programming, \eg \CC:
    12841210\begin{C++}
    12851211struct S {
    1286         char @c@;   int @i@;   double @d@;
    1287         void f( /* S * this */ ) {                              $\C{// implicit ``this'' parameter}$
    1288                 @c@;   @i@;   @d@;                                      $\C{// this->c; this->i; this->d;}$
     1212        char c; §\C{// fields}§
     1213        int i;
     1214        double d;
     1215        void f() { §\C{// implicit ``this'' aggregate}§
     1216                ®this->®c; ®this->®i; ®this->®d; §\C{// access containing fields}§
    12891217        }
    12901218}
    12911219\end{C++}
    1292 In general, qualification is elided for the variables and functions in the lexical scopes visible from a member function.
    1293 However, qualification is necessary for name shadowing and explicit aggregate parameters.
    1294 \begin{cfa}
    1295 struct T {
    1296         char @m@;   int @i@;   double @n@;              $\C{// derived class variables}$
    1297 };
    1298 struct S : public T {
    1299         char @c@;   int @i@;   double @d@;              $\C{// class variables}$
    1300         void g( double @d@, T & t ) {
    1301                 d;   @t@.m;   @t@.i;   @t@.n;           $\C{// function parameter}$
    1302                 c;   i;   @this->@d;   @S::@d;          $\C{// class S variables}$
    1303                 m;   @T::@i;   n;                                       $\C{// class T variables}$
    1304         }
    1305 };
    1306 \end{cfa}
    1307 Note the three different forms of qualification syntax in \CC, ©.©, ©->©, ©::©, which is confusing.
    1308 
    1309 Since \CFA in not object-oriented, it has no implicit parameter with its implicit qualification.
    1310 Instead \CFA introduces a general mechanism using the ©with© statement \see{Pascal~\cite[\S~4.F]{Pascal}} to explicitly elide aggregate qualification by opening a scope containing the field identifiers.
    1311 Hence, 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.
    1312 \begin{cfa}
    1313 void f( S & this ) @with ( this )@ {            $\C{// with statement}$
    1314         @c@;   @i@;   @d@;                                              $\C{// this.c, this.i, this.d}$
     1220Object-oriented nesting of member functions in a \lstinline[language=C++]@class/struct@ allows eliding \lstinline[language=C++]@this->@ because of lexical scoping.
     1221However, for other aggregate parameters, qualification is necessary:
     1222\begin{cfa}
     1223struct T { double m, n; };
     1224int S::f( T & t ) { §\C{// multiple aggregate parameters}§
     1225        c; i; d; §\C{\color{red}// this--{\textgreater}.c, this--{\textgreater}.i, this--{\textgreater}.d}§
     1226        ®t.®m; ®t.®n; §\C{// must qualify}§
     1227}
     1228\end{cfa}
     1229
     1230To simplify the programmer experience, \CFA provides a ©with© statement (see Pascal~\cite[\S~4.F]{Pascal}) to elide aggregate qualification to fields by opening a scope containing the field identifiers.
     1231Hence, the qualified fields become variables with the side-effect that it is easier to optimizing field references in a block.
     1232\begin{cfa}
     1233void f( S & this ) ®with ( this )® { §\C{// with statement}§
     1234        c; i; d; §\C{\color{red}// this.c, this.i, this.d}§
    13151235}
    13161236\end{cfa}
    13171237with the generality of opening multiple aggregate-parameters:
    13181238\begin{cfa}
    1319 void g( S & s, T & t ) @with ( s, t )@ {        $\C{// multiple aggregate parameters}$
    1320         c;   @s.@i;   d;                                                $\C{// s.c, s.i, s.d}$
    1321         m;   @t.@i;   n;                                                $\C{// t.m, t.i, t.n}$
    1322 }
    1323 \end{cfa}
    1324 where qualification is only necessary to disambiguate the shadowed variable ©i©.
    1325 
    1326 In detail, the ©with© statement may appear as the body of a function or nested within a function body.
    1327 The ©with© clause takes a list of expressions, where each expression provides an aggregate type and object.
     1239void f( S & s, T & t ) ®with ( s, t )® { §\C{// multiple aggregate parameters}§
     1240        c; i; d; §\C{\color{red}// s.c, s.i, s.d}§
     1241        m; n; §\C{\color{red}// t.m, t.n}§
     1242}
     1243\end{cfa}
     1244
     1245In detail, the ©with© statement has the form:
     1246\begin{cfa}
     1247§\emph{with-statement}§:
     1248        'with' '(' §\emph{expression-list}§ ')' §\emph{compound-statement}§
     1249\end{cfa}
     1250and may appear as the body of a function or nested within a function body.
     1251Each expression in the expression-list provides a type and object.
     1252The type must be an aggregate type.
    13281253(Enumerations are already opened.)
    1329 To open a pointer type, the pointer must be dereferenced to obtain a reference to the aggregate type.
    1330 \begin{cfa}
    1331 S * sp;
    1332 with ( *sp ) { ... }
    1333 \end{cfa}
    1334 The expression object is the implicit qualifier for the open structure-fields.
    1335 \CFA's ability to overload variables \see{\VRef{s:VariableOverload}} and use the left-side of assignment in type resolution means most fields with the same name but different types are automatically disambiguated, eliminating qualification.
     1254The object is the implicit qualifier for the open structure-fields.
     1255
    13361256All expressions in the expression list are open in parallel within the compound statement.
    13371257This semantic is different from Pascal, which nests the openings from left to right.
    13381258The difference between parallel and nesting occurs for fields with the same name and type:
    13391259\begin{cfa}
    1340 struct Q { int @i@; int k; int @m@; } q, w;
    1341 struct R { int @i@; int j; double @m@; } r, w;
    1342 with ( r, q ) {
    1343         j + k;                                                                  $\C{// unambiguous, r.j + q.k}$
    1344         m = 5.0;                                                                $\C{// unambiguous, q.m = 5.0}$
    1345         m = 1;                                                                  $\C{// unambiguous, r.m = 1}$
    1346         int a = m;                                                              $\C{// unambiguous, a = r.i }$
    1347         double b = m;                                                   $\C{// unambiguous, b = q.m}$
    1348         int c = r.i + q.i;                                              $\C{// disambiguate with qualification}$
    1349         (double)m;                                                              $\C{// disambiguate with cast}$
    1350 }
    1351 \end{cfa}
    1352 For parallel semantics, both ©r.i© and ©q.i© are visible, so ©i© is ambiguous without qualification;
    1353 for nested semantics, ©q.i© hides ©r.i©, so ©i© implies ©q.i©.
    1354 Pascal nested-semantics is possible by nesting ©with© statements.
    1355 \begin{cfa}
    1356 with ( r ) {
    1357         i;                                                                              $\C{// unambiguous, r.i}$
    1358         with ( q ) {
    1359                 i;                                                                      $\C{// unambiguous, q.i}$
    1360         }
    1361 }
    1362 \end{cfa}
    1363 A cast or qualification can be used to disambiguate variables within a ©with© \emph{statement}.
    1364 A cast can be used to disambiguate among overload variables in a ©with© \emph{expression}:
    1365 \begin{cfa}
    1366 with ( w ) { ... }                                                      $\C{// ambiguous, same name and no context}$
    1367 with ( (Q)w ) { ... }                                           $\C{// unambiguous, cast}$
    1368 \end{cfa}
    1369 Because 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©.
    1370 
    1371 Finally, there is an interesting problem between parameters and the function-body ©with©, \eg:
    1372 \begin{cfa}
    1373 void ?{}( S & s, int i ) with ( s ) { $\C{// constructor}$
    1374         @s.i = i;@  j = 3;  m = 5.5; $\C{// initialize fields}$
     1260struct S { int ®i®; int j; double m; } s, w;
     1261struct T { int ®i®; int k; int m; } t, w;
     1262with ( s, t ) {
     1263        j + k; §\C{// unambiguous, s.j + t.k}§
     1264        m = 5.0; §\C{// unambiguous, t.m = 5.0}§
     1265        m = 1; §\C{// unambiguous, s.m = 1}§
     1266        int a = m; §\C{// unambiguous, a = s.i }§
     1267        double b = m; §\C{// unambiguous, b = t.m}§
     1268        int c = s.i + t.i; §\C{// unambiguous, qualification}§
     1269        (double)m; §\C{// unambiguous, cast}§
     1270}
     1271\end{cfa}
     1272For parallel semantics, both ©s.i© and ©t.i© are visible, so ©i© is ambiguous without qualification;
     1273for nested semantics, ©t.i© hides ©s.i©, so ©i© implies ©t.i©.
     1274\CFA's ability to overload variables means fields with the same name but different types are automatically disambiguated, eliminating most qualification when opening multiple aggregates.
     1275Qualification or a cast is used to disambiguate.
     1276
     1277There is an interesting problem between parameters and the function-body ©with©, \eg:
     1278\begin{cfa}
     1279void ?{}( S & s, int i ) with ( s ) { §\C{// constructor}§
     1280        ®s.i = i;®  j = 3;  m = 5.5; §\C{// initialize fields}§
    13751281}
    13761282\end{cfa}
     
    13851291and implicitly opened \emph{after} a function-body open, to give them higher priority:
    13861292\begin{cfa}
    1387 void ?{}( S & s, int @i@ ) with ( s ) @with( $\emph{\R{params}}$ )@ { // syntax not allowed, illustration only
    1388         s.i = @i@; j = 3; m = 5.5;
    1389 }
    1390 \end{cfa}
    1391 This implicit semantic matches with programmer expectation.
    1392 
     1293void ?{}( S & s, int ®i® ) with ( s ) ®with( §\emph{\color{red}params}§ )® {
     1294        s.i = ®i®; j = 3; m = 5.5;
     1295}
     1296\end{cfa}
     1297Finally, a cast may be used to disambiguate among overload variables in a ©with© expression:
     1298\begin{cfa}
     1299with ( w ) { ... } §\C{// ambiguous, same name and no context}§
     1300with ( (S)w ) { ... } §\C{// unambiguous, cast}§
     1301\end{cfa}
     1302and ©with© expressions may be complex expressions with type reference (see Section~\ref{s:References}) to aggregate:
     1303% \begin{cfa}
     1304% struct S { int i, j; } sv;
     1305% with ( sv ) { §\C{// implicit reference}§
     1306%       S & sr = sv;
     1307%       with ( sr ) { §\C{// explicit reference}§
     1308%               S * sp = &sv;
     1309%               with ( *sp ) { §\C{// computed reference}§
     1310%                       i = 3; j = 4; §\C{\color{red}// sp--{\textgreater}i, sp--{\textgreater}j}§
     1311%               }
     1312%               i = 2; j = 3; §\C{\color{red}// sr.i, sr.j}§
     1313%       }
     1314%       i = 1; j = 2; §\C{\color{red}// sv.i, sv.j}§
     1315% }
     1316% \end{cfa}
     1317
     1318In \Index{object-oriented} programming, there is an implicit first parameter, often names \textbf{©self©} or \textbf{©this©}, which is elided.
     1319\begin{C++}
     1320class C {
     1321        int i, j;
     1322        int mem() { §\C{\color{red}// implicit "this" parameter}§
     1323                i = 1; §\C{\color{red}// this->i}§
     1324                j = 2; §\C{\color{red}// this->j}§
     1325        }
     1326}
     1327\end{C++}
     1328Since \CFA is non-object-oriented, the equivalent object-oriented program looks like:
     1329\begin{cfa}
     1330struct S { int i, j; };
     1331int mem( S & ®this® ) { §\C{// explicit "this" parameter}§
     1332        ®this.®i = 1; §\C{// "this" is not elided}§
     1333        ®this.®j = 2;
     1334}
     1335\end{cfa}
     1336but it is cumbersome having to write ``©this.©'' many times in a member.
     1337
     1338\CFA provides a ©with© clause/statement (see Pascal~\cite[\S~4.F]{Pascal}) to elided the "©this.©" by opening a scope containing field identifiers, changing the qualified fields into variables and giving an opportunity for optimizing qualified references.
     1339\begin{cfa}
     1340int mem( S & this ) ®with( this )® { §\C{// with clause}§
     1341        i = 1; §\C{\color{red}// this.i}§
     1342        j = 2; §\C{\color{red}// this.j}§
     1343}
     1344\end{cfa}
     1345which extends to multiple routine parameters:
     1346\begin{cfa}
     1347struct T { double m, n; };
     1348int mem2( S & this1, T & this2 ) ®with( this1, this2 )® {
     1349        i = 1; j = 2;
     1350        m = 1.0; n = 2.0;
     1351}
     1352\end{cfa}
     1353
     1354The statement form is used within a block:
     1355\begin{cfa}
     1356int foo() {
     1357        struct S1 { ... } s1;
     1358        struct S2 { ... } s2;
     1359        ®with( s1 )® { §\C{// with statement}§
     1360                // access fields of s1 without qualification
     1361                ®with s2® { §\C{// nesting}§
     1362                        // access fields of s1 and s2 without qualification
     1363                }
     1364        }
     1365        ®with s1, s2® {
     1366                // access unambiguous fields of s1 and s2 without qualification
     1367        }
     1368}
     1369\end{cfa}
     1370
     1371When opening multiple structures, fields with the same name and type are ambiguous and must be fully qualified.
     1372For fields with the same name but different type, context/cast can be used to disambiguate.
     1373\begin{cfa}
     1374struct S { int i; int j; double m; } a, c;
     1375struct T { int i; int k; int m } b, c;
     1376with( a, b )
     1377{
     1378}
     1379\end{cfa}
     1380
     1381\begin{comment}
     1382The components in the "with" clause
     1383
     1384  with a, b, c { ... }
     1385
     1386serve 2 purposes: each component provides a type and object. The type must be a
     1387structure type. Enumerations are already opened, and I think a union is opened
     1388to some extent, too. (Or is that just unnamed unions?) The object is the target
     1389that the naked structure-fields apply to. The components are open in "parallel"
     1390at the scope of the "with" clause/statement, so opening "a" does not affect
     1391opening "b", etc. This semantic is different from Pascal, which nests the
     1392openings.
     1393
     1394Having said the above, it seems reasonable to allow a "with" component to be an
     1395expression. The type is the static expression-type and the object is the result
     1396of the expression. Again, the type must be an aggregate. Expressions require
     1397parenthesis around the components.
     1398
     1399  with( a, b, c ) { ... }
     1400
     1401Does this now make sense?
     1402
     1403Having written more CFA code, it is becoming clear to me that I *really* want
     1404the "with" to be implemented because I hate having to type all those object
     1405names for fields. It's a great way to drive people away from the language.
     1406\end{comment}
    13931407
    13941408
     
    14001414Non-local transfer can cause stack unwinding, \ie non-local routine termination, depending on the kind of raise.
    14011415\begin{cfa}
    1402 exception_t E {}; $\C{// exception type}$
     1416exception_t E {}; §\C{// exception type}§
    14031417void f(...) {
    1404         ... throw E{}; ... $\C{// termination}$
    1405         ... throwResume E{}; ... $\C{// resumption}$
     1418        ... throw E{}; ... §\C{// termination}§
     1419        ... throwResume E{}; ... §\C{// resumption}§
    14061420}
    14071421try {
    14081422        f(...);
    1409 } catch( E e ; $boolean-predicate$ ) {          $\C{// termination handler}$
     1423} catch( E e ; §boolean-predicate§ ) {          §\C{// termination handler}§
    14101424        // recover and continue
    1411 } catchResume( E e ; $boolean-predicate$ ) { $\C{// resumption handler}$
     1425} catchResume( E e ; §boolean-predicate§ ) { §\C{// resumption handler}§
    14121426        // repair and return
    14131427} finally {
     
    14161430\end{cfa}
    14171431The kind of raise and handler match: ©throw© with ©catch© and ©throwResume© with ©catchResume©.
    1418 Then the exception type must match along with any additional predicate must be true.
     1432Then the exception type must match along with any additonal predicate must be true.
    14191433The ©catch© and ©catchResume© handlers may appear in any oder.
    14201434However, the ©finally© clause must appear at the end of the ©try© statement.
     
    14691483For example, a routine returning a \Index{pointer} to an array of integers is defined and used in the following way:
    14701484\begin{cfa}
    1471 int @(*@f@())[@5@]@ {...}; $\C{// definition}$
    1472  ... @(*@f@())[@3@]@ += 1; $\C{// usage}$
     1485int ®(*®f®())[®5®]® {...}; §\C{// definition}§
     1486 ... ®(*®f®())[®3®]® += 1; §\C{// usage}§
    14731487\end{cfa}
    14741488Essentially, the return type is wrapped around the routine name in successive layers (like an \Index{onion}).
     
    14851499\begin{tabular}{@{}l@{\hspace{3em}}l@{}}
    14861500\multicolumn{1}{c@{\hspace{3em}}}{\textbf{\CFA}}        & \multicolumn{1}{c}{\textbf{C}}        \\
    1487 \begin{cfa}[moredelim={**[is][\color{blue}]{\#}{\#}}]
    1488 #[5] *# @int@ x1;
    1489 #* [5]# @int@ x2;
    1490 #[* [5] int]# f@( int p )@;
     1501\begin{cfa}
     1502ß[5] *ß ®int® x1;
     1503ß* [5]ß ®int® x2;
     1504ß[* [5] int]ß f®( int p )®;
    14911505\end{cfa}
    14921506&
    1493 \begin{cfa}[moredelim={**[is][\color{blue}]{\#}{\#}}]
    1494 @int@ #*# x1 #[5]#;
    1495 @int@ #(*#x2#)[5]#;
    1496 #int (*#f@( int p )@#)[5]#;
     1507\begin{cfa}
     1508®int® ß*ß x1 ß[5]ß;
     1509®int® ß(*ßx2ß)[5]ß;
     1510ßint (*ßf®( int p )®ß)[5]ß;
    14971511\end{cfa}
    14981512\end{tabular}
     
    15061520\multicolumn{1}{c@{\hspace{3em}}}{\textbf{\CFA}}        & \multicolumn{1}{c}{\textbf{C}}        \\
    15071521\begin{cfa}
    1508 @*@ int x, y;
     1522®*® int x, y;
    15091523\end{cfa}
    15101524&
    15111525\begin{cfa}
    1512 int @*@x, @*@y;
     1526int ®*®x, ®*®y;
    15131527\end{cfa}
    15141528\end{tabular}
     
    15191533\multicolumn{1}{c@{\hspace{3em}}}{\textbf{\CFA}}        & \multicolumn{1}{c}{\textbf{C}}        \\
    15201534\begin{cfa}
    1521 @*@ int x;
     1535®*® int x;
    15221536int y;
    15231537\end{cfa}
    15241538&
    15251539\begin{cfa}
    1526 int @*@x, y;
     1540int ®*®x, y;
    15271541
    15281542\end{cfa}
     
    16331647
    16341648\section{Pointer / Reference}
    1635 \label{s:PointerReference}
    16361649
    16371650C provides a \newterm{pointer type};
     
    16601673&
    16611674\begin{cfa}
    1662 int * @const@ x = (int *)100
     1675int * ®const® x = (int *)100
    16631676*x = 3;                 // implicit dereference
    1664 int * @const@ y = (int *)104;
     1677int * ®const® y = (int *)104;
    16651678*y = *x;                        // implicit dereference
    16661679\end{cfa}
     
    17001713\begin{tabular}{@{}l@{\hspace{2em}}l@{}}
    17011714\begin{cfa}
    1702 int x, y, @*@ p1, @*@ p2, @**@ p3;
    1703 p1 = @&@x;     // p1 points to x
     1715int x, y, ®*® p1, ®*® p2, ®**® p3;
     1716p1 = ®&®x;     // p1 points to x
    17041717p2 = p1;     // p2 points to x
    1705 p1 = @&@y;     // p1 points to y
     1718p1 = ®&®y;     // p1 points to y
    17061719p3 = &p2;  // p3 points to p2
    17071720\end{cfa}
     
    17151728For example, \Index*{Algol68}~\cite{Algol68} infers pointer dereferencing to select the best meaning for each pointer usage
    17161729\begin{cfa}
    1717 p2 = p1 + x; $\C{// compiler infers *p2 = *p1 + x;}$
     1730p2 = p1 + x; §\C{// compiler infers *p2 = *p1 + x;}§
    17181731\end{cfa}
    17191732Algol68 infers the following dereferencing ©*p2 = *p1 + x©, because adding the arbitrary integer value in ©x© to the address of ©p1© and storing the resulting address into ©p2© is an unlikely operation.
     
    17231736In C, objects of pointer type always manipulate the pointer object's address:
    17241737\begin{cfa}
    1725 p1 = p2; $\C{// p1 = p2\ \ rather than\ \ *p1 = *p2}$
    1726 p2 = p1 + x; $\C{// p2 = p1 + x\ \ rather than\ \ *p2 = *p1 + x}$
     1738p1 = p2; §\C{// p1 = p2\ \ rather than\ \ *p1 = *p2}§
     1739p2 = p1 + x; §\C{// p2 = p1 + x\ \ rather than\ \ *p2 = *p1 + x}§
    17271740\end{cfa}
    17281741even though the assignment to ©p2© is likely incorrect, and the programmer probably meant:
    17291742\begin{cfa}
    1730 p1 = p2; $\C{// pointer address assignment}$
    1731 @*@p2 = @*@p1 + x; $\C{// pointed-to value assignment / operation}$
     1743p1 = p2; §\C{// pointer address assignment}§
     1744®*®p2 = ®*®p1 + x; §\C{// pointed-to value assignment / operation}§
    17321745\end{cfa}
    17331746The C semantics work well for situations where manipulation of addresses is the primary meaning and data is rarely accessed, such as storage management (©malloc©/©free©).
     
    17451758To support this common case, a reference type is introduced in \CFA, denoted by ©&©, which is the opposite dereference semantics to a pointer type, making the value at the pointed-to location the implicit semantics for dereferencing (similar but not the same as \CC \Index{reference type}s).
    17461759\begin{cfa}
    1747 int x, y, @&@ r1, @&@ r2, @&&@ r3;
    1748 @&@r1 = &x; $\C{// r1 points to x}$
    1749 @&@r2 = &r1; $\C{// r2 points to x}$
    1750 @&@r1 = &y; $\C{// r1 points to y}$
    1751 @&&@r3 = @&@&r2; $\C{// r3 points to r2}$
    1752 r2 = ((r1 + r2) * (r3 - r1)) / (r3 - 15); $\C{// implicit dereferencing}$
     1760int x, y, ®&® r1, ®&® r2, ®&&® r3;
     1761®&®r1 = &x; §\C{// r1 points to x}§
     1762®&®r2 = &r1; §\C{// r2 points to x}§
     1763®&®r1 = &y; §\C{// r1 points to y}§
     1764®&&®r3 = ®&®&r2; §\C{// r3 points to r2}§
     1765r2 = ((r1 + r2) * (r3 - r1)) / (r3 - 15); §\C{// implicit dereferencing}§
    17531766\end{cfa}
    17541767Except for auto-dereferencing by the compiler, this reference example is the same as the previous pointer example.
     
    17561769One way to conceptualize a reference is via a rewrite rule, where the compiler inserts a dereference operator before the reference variable for each reference qualifier in a declaration, so the previous example becomes:
    17571770\begin{cfa}
    1758 @*@r2 = ((@*@r1 + @*@r2) @*@ (@**@r3 - @*@r1)) / (@**@r3 - 15);
     1771®*®r2 = ((®*®r1 + ®*®r2) ®*® (®**®r3 - ®*®r1)) / (®**®r3 - 15);
    17591772\end{cfa}
    17601773When a reference operation appears beside a dereference operation, \eg ©&*©, they cancel out.
     
    17651778For a \CFA reference type, the cancellation on the left-hand side of assignment leaves the reference as an address (\Index{lvalue}):
    17661779\begin{cfa}
    1767 (&@*@)r1 = &x; $\C{// (\&*) cancel giving address in r1 not variable pointed-to by r1}$
     1780(&®*®)r1 = &x; §\C{// (\&*) cancel giving address in r1 not variable pointed-to by r1}§
    17681781\end{cfa}
    17691782Similarly, the address of a reference can be obtained for assignment or computation (\Index{rvalue}):
    17701783\begin{cfa}
    1771 (&(&@*@)@*@)r3 = &(&@*@)r2; $\C{// (\&*) cancel giving address in r2, (\&(\&*)*) cancel giving address in r3}$
     1784(&(&®*®)®*®)r3 = &(&®*®)r2; §\C{// (\&*) cancel giving address in r2, (\&(\&*)*) cancel giving address in r3}§
    17721785\end{cfa}
    17731786Cancellation\index{cancellation!pointer/reference}\index{pointer!cancellation} works to arbitrary depth.
     
    17771790int x, *p1 = &x, **p2 = &p1, ***p3 = &p2,
    17781791                 &r1 = x,    &&r2 = r1,   &&&r3 = r2;
    1779 ***p3 = 3; $\C{// change x}$
    1780 r3 = 3; $\C{// change x, ***r3}$
    1781 **p3 = ...; $\C{// change p1}$
    1782 &r3 = ...; $\C{// change r1, (\&*)**r3, 1 cancellation}$
    1783 *p3 = ...; $\C{// change p2}$
    1784 &&r3 = ...; $\C{// change r2, (\&(\&*)*)*r3, 2 cancellations}$
    1785 &&&r3 = p3; $\C{// change r3 to p3, (\&(\&(\&*)*)*)r3, 3 cancellations}$
     1792***p3 = 3; §\C{// change x}§
     1793r3 = 3; §\C{// change x, ***r3}§
     1794**p3 = ...; §\C{// change p1}§
     1795&r3 = ...; §\C{// change r1, (\&*)**r3, 1 cancellation}§
     1796*p3 = ...; §\C{// change p2}§
     1797&&r3 = ...; §\C{// change r2, (\&(\&*)*)*r3, 2 cancellations}§
     1798&&&r3 = p3; §\C{// change r3 to p3, (\&(\&(\&*)*)*)r3, 3 cancellations}§
    17861799\end{cfa}
    17871800Furthermore, both types are equally performant, as the same amount of dereferencing occurs for both types.
     
    17901803As for a pointer type, a reference type may have qualifiers:
    17911804\begin{cfa}
    1792 const int cx = 5; $\C{// cannot change cx;}$
    1793 const int & cr = cx; $\C{// cannot change what cr points to}$
    1794 @&@cr = &cx; $\C{// can change cr}$
    1795 cr = 7; $\C{// error, cannot change cx}$
    1796 int & const rc = x; $\C{// must be initialized}$
    1797 @&@rc = &x; $\C{// error, cannot change rc}$
    1798 const int & const crc = cx; $\C{// must be initialized}$
    1799 crc = 7; $\C{// error, cannot change cx}$
    1800 @&@crc = &cx; $\C{// error, cannot change crc}$
     1805const int cx = 5; §\C{// cannot change cx;}§
     1806const int & cr = cx; §\C{// cannot change what cr points to}§
     1807®&®cr = &cx; §\C{// can change cr}§
     1808cr = 7; §\C{// error, cannot change cx}§
     1809int & const rc = x; §\C{// must be initialized}§
     1810®&®rc = &x; §\C{// error, cannot change rc}§
     1811const int & const crc = cx; §\C{// must be initialized}§
     1812crc = 7; §\C{// error, cannot change cx}§
     1813®&®crc = &cx; §\C{// error, cannot change crc}§
    18011814\end{cfa}
    18021815Hence, for type ©& const©, there is no pointer assignment, so ©&rc = &x© is disallowed, and \emph{the address value cannot be the null pointer unless an arbitrary pointer is coerced\index{coercion} into the reference}:
    18031816\begin{cfa}
    1804 int & const cr = *0; $\C{// where 0 is the int * zero}$
     1817int & const cr = *0; §\C{// where 0 is the int * zero}§
    18051818\end{cfa}
    18061819Note, constant reference-types do not prevent \Index{addressing errors} because of explicit storage-management:
     
    18091822cr = 5;
    18101823free( &cr );
    1811 cr = 7; $\C{// unsound pointer dereference}$
     1824cr = 7; §\C{// unsound pointer dereference}§
    18121825\end{cfa}
    18131826
    18141827The position of the ©const© qualifier \emph{after} the pointer/reference qualifier causes confuse for C programmers.
    18151828The ©const© qualifier cannot be moved before the pointer/reference qualifier for C style-declarations;
    1816 \CFA-style declarations \see{\VRef{s:AlternativeDeclarations}} attempt to address this issue:
     1829\CFA-style declarations (see \VRef{s:AlternativeDeclarations}) attempt to address this issue:
    18171830\begin{cquote}
    18181831\begin{tabular}{@{}l@{\hspace{3em}}l@{}}
    18191832\multicolumn{1}{c@{\hspace{3em}}}{\textbf{\CFA}}        & \multicolumn{1}{c}{\textbf{C}}        \\
    18201833\begin{cfa}
    1821 @const@ * @const@ * const int ccp;
    1822 @const@ & @const@ & const int ccr;
     1834®const® * ®const® * const int ccp;
     1835®const® & ®const® & const int ccr;
    18231836\end{cfa}
    18241837&
    18251838\begin{cfa}
    1826 const int * @const@ * @const@ ccp;
     1839const int * ®const® * ®const® ccp;
    18271840
    18281841\end{cfa}
     
    18331846Finally, like pointers, references are usable and composable with other type operators and generators.
    18341847\begin{cfa}
    1835 int w, x, y, z, & ar[3] = { x, y, z }; $\C{// initialize array of references}$
    1836 &ar[1] = &w; $\C{// change reference array element}$
    1837 typeof( ar[1] ) p; $\C{// (gcc) is int, \ie the type of referenced object}$
    1838 typeof( &ar[1] ) q; $\C{// (gcc) is int \&, \ie the type of reference}$
    1839 sizeof( ar[1] ) == sizeof( int ); $\C{// is true, \ie the size of referenced object}$
    1840 sizeof( &ar[1] ) == sizeof( int *) $\C{// is true, \ie the size of a reference}$
     1848int w, x, y, z, & ar[3] = { x, y, z }; §\C{// initialize array of references}§
     1849&ar[1] = &w; §\C{// change reference array element}§
     1850typeof( ar[1] ) p; §\C{// (gcc) is int, \ie the type of referenced object}§
     1851typeof( &ar[1] ) q; §\C{// (gcc) is int \&, \ie the type of reference}§
     1852sizeof( ar[1] ) == sizeof( int ); §\C{// is true, \ie the size of referenced object}§
     1853sizeof( &ar[1] ) == sizeof( int *) §\C{// is true, \ie the size of a reference}§
    18411854\end{cfa}
    18421855
    18431856In contrast to \CFA reference types, \Index*[C++]{\CC{}}'s reference types are all ©const© references, preventing changes to the reference address, so only value assignment is possible, which eliminates half of the \Index{address duality}.
    18441857Also, \CC does not allow \Index{array}s\index{array!reference} of reference\footnote{
    1845 The reason for disallowing arrays of reference is unknown, but possibly comes from references being ethereal (like a textual macro), and hence, replaceable by the referent object.}
     1858The reason for disallowing arrays of reference is unknown, but possibly comes from references being ethereal (like a textual macro), and hence, replaceable by the referant object.}
    18461859\Index*{Java}'s reference types to objects (all Java objects are on the heap) are like C pointers, which always manipulate the address, and there is no (bit-wise) object assignment, so objects are explicitly cloned by shallow or deep copying, which eliminates half of the address duality.
    18471860
     
    18551868Therefore, for pointer/reference initialization, the initializing value must be an address not a value.
    18561869\begin{cfa}
    1857 int * p = &x; $\C{// assign address of x}$
    1858 @int * p = x;@ $\C{// assign value of x}$
    1859 int & r = x; $\C{// must have address of x}$
     1870int * p = &x; §\C{// assign address of x}§
     1871®int * p = x;® §\C{// assign value of x}§
     1872int & r = x; §\C{// must have address of x}§
    18601873\end{cfa}
    18611874Like the previous example with C pointer-arithmetic, it is unlikely assigning the value of ©x© into a pointer is meaningful (again, a warning is usually given).
     
    18661879Similarly, when a reference type is used for a parameter/return type, the call-site argument does not require a reference operator for the same reason.
    18671880\begin{cfa}
    1868 int & f( int & r ); $\C{// reference parameter and return}$
    1869 z = f( x ) + f( y ); $\C{// reference operator added, temporaries needed for call results}$
     1881int & f( int & r ); §\C{// reference parameter and return}§
     1882z = f( x ) + f( y ); §\C{// reference operator added, temporaries needed for call results}§
    18701883\end{cfa}
    18711884Within routine ©f©, it is possible to change the argument by changing the corresponding parameter, and parameter ©r© can be locally reassigned within ©f©.
     
    18801893When a pointer/reference parameter has a ©const© value (immutable), it is possible to pass literals and expressions.
    18811894\begin{cfa}
    1882 void f( @const@ int & cr );
    1883 void g( @const@ int * cp );
    1884 f( 3 );                   g( @&@3 );
    1885 f( x + y );             g( @&@(x + y) );
     1895void f( ®const® int & cr );
     1896void g( ®const® int * cp );
     1897f( 3 );                   g( ®&®3 );
     1898f( x + y );             g( ®&®(x + y) );
    18861899\end{cfa}
    18871900Here, the compiler passes the address to the literal 3 or the temporary for the expression ©x + y©, knowing the argument cannot be changed through the parameter.
     
    18941907void f( int & r );
    18951908void g( int * p );
    1896 f( 3 );                   g( @&@3 ); $\C{// compiler implicit generates temporaries}$
    1897 f( x + y );             g( @&@(x + y) ); $\C{// compiler implicit generates temporaries}$
     1909f( 3 );                   g( ®&®3 ); §\C{// compiler implicit generates temporaries}§
     1910f( x + y );             g( ®&®(x + y) ); §\C{// compiler implicit generates temporaries}§
    18981911\end{cfa}
    18991912Essentially, there is an implicit \Index{rvalue} to \Index{lvalue} conversion in this case.\footnote{
     
    19061919\begin{cfa}
    19071920void f( int i );
    1908 void (* fp)( int ); $\C{// routine pointer}$
    1909 fp = f; $\C{// reference initialization}$
    1910 fp = &f; $\C{// pointer initialization}$
    1911 fp = *f; $\C{// reference initialization}$
    1912 fp(3); $\C{// reference invocation}$
    1913 (*fp)(3); $\C{// pointer invocation}$
     1921void (* fp)( int ); §\C{// routine pointer}§
     1922fp = f; §\C{// reference initialization}§
     1923fp = &f; §\C{// pointer initialization}§
     1924fp = *f; §\C{// reference initialization}§
     1925fp(3); §\C{// reference invocation}§
     1926(*fp)(3); §\C{// pointer invocation}§
    19141927\end{cfa}
    19151928While C's treatment of routine objects has similarity to inferring a reference type in initialization contexts, the examples are assignment not initialization, and all possible forms of assignment are possible (©f©, ©&f©, ©*f©) without regard for type.
    19161929Instead, a routine object should be referenced by a ©const© reference:
    19171930\begin{cfa}
    1918 @const@ void (@&@ fr)( int ) = f; $\C{// routine reference}$
    1919 fr = ... $\C{// error, cannot change code}$
    1920 &fr = ...; $\C{// changing routine reference}$
    1921 fr( 3 ); $\C{// reference call to f}$
    1922 (*fr)(3); $\C{// error, incorrect type}$
     1931®const® void (®&® fr)( int ) = f; §\C{// routine reference}§
     1932fr = ... §\C{// error, cannot change code}§
     1933&fr = ...; §\C{// changing routine reference}§
     1934fr( 3 ); §\C{// reference call to f}§
     1935(*fr)(3); §\C{// error, incorrect type}§
    19231936\end{cfa}
    19241937because the value of the routine object is a routine literal, \ie the routine code is normally immutable during execution.\footnote{
     
    19331946\begin{itemize}
    19341947\item
    1935 if ©R© is an \Index{rvalue} of type ©T &©$_1\cdots$ ©&©$_r$, where $r \ge 1$ references (©&© symbols), than ©&R© has type ©T ©\R{©*©}©&©\R{$_2$}$\cdots$ ©&©\R{$_r$}, \ie ©T© pointer with $r-1$ references (©&© symbols).
    1936 
    1937 \item
    1938 if ©L© is an \Index{lvalue} of type ©T &©$_1\cdots$ ©&©$_l$, where $l \ge 0$ references (©&© symbols), than ©&L© has type ©T ©\R{©*©}©&©\R{$_1$}$\cdots$ ©&©\R{$_l$}, \ie ©T© pointer with $l$ references (©&© symbols).
     1948if ©R© is an \Index{rvalue} of type ©T &©$_1\cdots$ ©&©$_r$, where $r \ge 1$ references (©&© symbols), than ©&R© has type ©T ®*®&©$_{\color{red}2}\cdots$ ©&©$_{\color{red}r}$, \ie ©T© pointer with $r-1$ references (©&© symbols).
     1949
     1950\item
     1951if ©L© is an \Index{lvalue} of type ©T &©$_1\cdots$ ©&©$_l$, where $l \ge 0$ references (©&© symbols), than ©&L© has type ©T ®*®&©$_{\color{red}1}\cdots$ ©&©$_{\color{red}l}$, \ie ©T© pointer with $l$ references (©&© symbols).
    19391952\end{itemize}
    19401953The following example shows the first rule applied to different \Index{rvalue} contexts:
     
    19421955int x, * px, ** ppx, *** pppx, **** ppppx;
    19431956int & rx = x, && rrx = rx, &&& rrrx = rrx ;
    1944 x = rrrx; $\C[2.0in]{// rrrx is an lvalue with type int \&\&\& (equivalent to x)}$
    1945 px = &rrrx; $\C{// starting from rrrx, \&rrrx is an rvalue with type int *\&\&\& (\&x)}$
    1946 ppx = &&rrrx; $\C{// starting from \&rrrx, \&\&rrrx is an rvalue with type int **\&\& (\&rx)}$
    1947 pppx = &&&rrrx; $\C{// starting from \&\&rrrx, \&\&\&rrrx is an rvalue with type int ***\& (\&rrx)}$
    1948 ppppx = &&&&rrrx; $\C{// starting from \&\&\&rrrx, \&\&\&\&rrrx is an rvalue with type int **** (\&rrrx)}$
     1957x = rrrx; §\C[2.0in]{// rrrx is an lvalue with type int \&\&\& (equivalent to x)}§
     1958px = &rrrx; §\C{// starting from rrrx, \&rrrx is an rvalue with type int *\&\&\& (\&x)}§
     1959ppx = &&rrrx; §\C{// starting from \&rrrx, \&\&rrrx is an rvalue with type int **\&\& (\&rx)}§
     1960pppx = &&&rrrx; §\C{// starting from \&\&rrrx, \&\&\&rrrx is an rvalue with type int ***\& (\&rrx)}§
     1961ppppx = &&&&rrrx; §\C{// starting from \&\&\&rrrx, \&\&\&\&rrrx is an rvalue with type int **** (\&rrrx)}§
    19491962\end{cfa}
    19501963The following example shows the second rule applied to different \Index{lvalue} contexts:
     
    19521965int x, * px, ** ppx, *** pppx;
    19531966int & rx = x, && rrx = rx, &&& rrrx = rrx ;
    1954 rrrx = 2; $\C{// rrrx is an lvalue with type int \&\&\& (equivalent to x)}$
    1955 &rrrx = px; $\C{// starting from rrrx, \&rrrx is an rvalue with type int *\&\&\& (rx)}$
    1956 &&rrrx = ppx; $\C{// starting from \&rrrx, \&\&rrrx is an rvalue with type int **\&\& (rrx)}$
    1957 &&&rrrx = pppx; $\C{// starting from \&\&rrrx, \&\&\&rrrx is an rvalue with type int ***\& (rrrx)}\CRT$
     1967rrrx = 2; §\C{// rrrx is an lvalue with type int \&\&\& (equivalent to x)}§
     1968&rrrx = px; §\C{// starting from rrrx, \&rrrx is an rvalue with type int *\&\&\& (rx)}§
     1969&&rrrx = ppx; §\C{// starting from \&rrrx, \&\&rrrx is an rvalue with type int **\&\& (rrx)}§
     1970&&&rrrx = pppx; §\C{// starting from \&\&rrrx, \&\&\&rrrx is an rvalue with type int ***\& (rrrx)}\CRT§
    19581971\end{cfa}
    19591972
     
    19681981\begin{cfa}
    19691982int x;
    1970 x + 1; $\C[2.0in]{// lvalue variable (int) converts to rvalue for expression}$
     1983x + 1; §\C[2.0in]{// lvalue variable (int) converts to rvalue for expression}§
    19711984\end{cfa}
    19721985An rvalue has no type qualifiers (©cv©), so the lvalue qualifiers are dropped.
     
    19781991\begin{cfa}
    19791992int x, &r = x, f( int p );
    1980 x = @r@ + f( @r@ ); $\C{// lvalue reference converts to rvalue}$
     1993x = ®r® + f( ®r® ); §\C{// lvalue reference converts to rvalue}§
    19811994\end{cfa}
    19821995An rvalue has no type qualifiers (©cv©), so the reference qualifiers are dropped.
     
    19851998lvalue to reference conversion: \lstinline[deletekeywords=lvalue]@lvalue-type cv1 T@ converts to ©cv2 T &©, which allows implicitly converting variables to references.
    19861999\begin{cfa}
    1987 int x, &r = @x@, f( int & p ); $\C{// lvalue variable (int) convert to reference (int \&)}$
    1988 f( @x@ ); $\C{// lvalue variable (int) convert to reference (int \&)}$
     2000int x, &r = ®x®, f( int & p ); §\C{// lvalue variable (int) convert to reference (int \&)}§
     2001f( ®x® ); §\C{// lvalue variable (int) convert to reference (int \&)}§
    19892002\end{cfa}
    19902003Conversion can restrict a type, where ©cv1© $\le$ ©cv2©, \eg passing an ©int© to a ©const volatile int &©, which has low cost.
     
    19962009\begin{cfa}
    19972010int x, & f( int & p );
    1998 f( @x + 3@ );   $\C[1.5in]{// rvalue parameter (int) implicitly converts to lvalue temporary reference (int \&)}$
    1999 @&f@(...) = &x; $\C{// rvalue result (int \&) implicitly converts to lvalue temporary reference (int \&)}\CRT$
     2011f( ®x + 3® );   §\C[1.5in]{// rvalue parameter (int) implicitly converts to lvalue temporary reference (int \&)}§
     2012®&f®(...) = &x; §\C{// rvalue result (int \&) implicitly converts to lvalue temporary reference (int \&)}\CRT§
    20002013\end{cfa}
    20012014In both case, modifications to the temporary are inaccessible (\Index{warning}).
     
    21692182The point of the new syntax is to allow returning multiple values from a routine~\cite{Galletly96,CLU}, \eg:
    21702183\begin{cfa}
    2171 @[ int o1, int o2, char o3 ]@ f( int i1, char i2, char i3 ) {
    2172         $\emph{routine body}$
     2184®[ int o1, int o2, char o3 ]® f( int i1, char i2, char i3 ) {
     2185        §\emph{routine body}§
    21732186}
    21742187\end{cfa}
     
    21812194Declaration qualifiers can only appear at the start of a routine definition, \eg:
    21822195\begin{cfa}
    2183 @extern@ [ int x ] g( int y ) {$\,$}
     2196®extern® [ int x ] g( int y ) {§\,§}
    21842197\end{cfa}
    21852198Lastly, if there are no output parameters or input parameters, the brackets and/or parentheses must still be specified;
    21862199in both cases the type is assumed to be void as opposed to old style C defaults of int return type and unknown parameter types, respectively, as in:
    21872200\begin{cfa}
    2188 [$\,$] g(); $\C{// no input or output parameters}$
    2189 [ void ] g( void ); $\C{// no input or output parameters}$
     2201[§\,§] g(); §\C{// no input or output parameters}§
     2202[ void ] g( void ); §\C{// no input or output parameters}§
    21902203\end{cfa}
    21912204
     
    22052218\begin{cfa}
    22062219typedef int foo;
    2207 int f( int (* foo) ); $\C{// foo is redefined as a parameter name}$
     2220int f( int (* foo) ); §\C{// foo is redefined as a parameter name}§
    22082221\end{cfa}
    22092222The string ``©int (* foo)©'' declares a C-style named-parameter of type pointer to an integer (the parenthesis are superfluous), while the same string declares a \CFA style unnamed parameter of type routine returning integer with unnamed parameter of type pointer to foo.
     
    22132226C-style declarations can be used to declare parameters for \CFA style routine definitions, \eg:
    22142227\begin{cfa}
    2215 [ int ] f( * int, int * ); $\C{// returns an integer, accepts 2 pointers to integers}$
    2216 [ * int, int * ] f( int ); $\C{// returns 2 pointers to integers, accepts an integer}$
     2228[ int ] f( * int, int * ); §\C{// returns an integer, accepts 2 pointers to integers}§
     2229[ * int, int * ] f( int ); §\C{// returns 2 pointers to integers, accepts an integer}§
    22172230\end{cfa}
    22182231The reason for allowing both declaration styles in the new context is for backwards compatibility with existing preprocessor macros that generate C-style declaration-syntax, as in:
    22192232\begin{cfa}
    22202233#define ptoa( n, d ) int (*n)[ d ]
    2221 int f( ptoa( p, 5 ) ) ... $\C{// expands to int f( int (*p)[ 5 ] )}$
    2222 [ int ] f( ptoa( p, 5 ) ) ... $\C{// expands to [ int ] f( int (*p)[ 5 ] )}$
     2234int f( ptoa( p, 5 ) ) ... §\C{// expands to int f( int (*p)[ 5 ] )}§
     2235[ int ] f( ptoa( p, 5 ) ) ... §\C{// expands to [ int ] f( int (*p)[ 5 ] )}§
    22232236\end{cfa}
    22242237Again, programmers are highly encouraged to use one declaration form or the other, rather than mixing the forms.
     
    22392252\begin{minipage}{\linewidth}
    22402253\begin{cfa}
    2241 @[ int x, int y ]@ f() {
     2254®[ int x, int y ]® f() {
    22422255        int z;
    22432256        ... x = 0; ... y = z; ...
    2244         @return;@ $\C{// implicitly return x, y}$
     2257        ®return;® §\C{// implicitly return x, y}§
    22452258}
    22462259\end{cfa}
     
    22522265[ int x, int y ] f() {
    22532266        ...
    2254 } $\C{// implicitly return x, y}$
     2267} §\C{// implicitly return x, y}§
    22552268\end{cfa}
    22562269In this case, the current values of ©x© and ©y© are returned to the calling routine just as if a ©return© had been encountered.
     
    22612274[ int x, int y ] f( int, x, int y ) {
    22622275        ...
    2263 } $\C{// implicitly return x, y}$
     2276} §\C{// implicitly return x, y}§
    22642277\end{cfa}
    22652278This notation allows the compiler to eliminate temporary variables in nested routine calls.
    22662279\begin{cfa}
    2267 [ int x, int y ] f( int, x, int y ); $\C{// prototype declaration}$
     2280[ int x, int y ] f( int, x, int y ); §\C{// prototype declaration}§
    22682281int a, b;
    22692282[a, b] = f( f( f( a, b ) ) );
     
    22792292as well, parameter names are optional, \eg:
    22802293\begin{cfa}
    2281 [ int x ] f (); $\C{// returning int with no parameters}$
    2282 [ * int ] g (int y); $\C{// returning pointer to int with int parameter}$
    2283 [ ] h ( int, char ); $\C{// returning no result with int and char parameters}$
    2284 [ * int, int ] j ( int ); $\C{// returning pointer to int and int, with int parameter}$
     2294[ int x ] f (); §\C{// returning int with no parameters}§
     2295[ * int ] g (int y); §\C{// returning pointer to int with int parameter}§
     2296[ ] h ( int, char ); §\C{// returning no result with int and char parameters}§
     2297[ * int, int ] j ( int ); §\C{// returning pointer to int and int, with int parameter}§
    22852298\end{cfa}
    22862299This syntax allows a prototype declaration to be created by cutting and pasting source text from the routine definition header (or vice versa).
    2287 Like C, it is possible to declare multiple routine-prototypes in a single declaration, where the return type is distributed across \emph{all} routine names in the declaration list \see{\VRef{s:AlternativeDeclarations}}, \eg:
     2300Like C, it is possible to declare multiple routine-prototypes in a single declaration, where the return type is distributed across \emph{all} routine names in the declaration list (see~\VRef{s:AlternativeDeclarations}), \eg:
    22882301\begin{cfa}
    22892302C :             const double bar1(), bar2( int ), bar3( double );
    2290 $\CFA$: [const double] foo(), foo( int ), foo( double ) { return 3.0; }
     2303§\CFA§: [const double] foo(), foo( int ), foo( double ) { return 3.0; }
    22912304\end{cfa}
    22922305\CFA allows the last routine in the list to define its body.
     
    23032316The syntax for pointers to \CFA routines specifies the pointer name on the right, \eg:
    23042317\begin{cfa}
    2305 * [ int x ] () fp; $\C[2.25in]{// pointer to routine returning int with no parameters}$
    2306 * [ * int ] (int y) gp; $\C{// pointer to routine returning pointer to int with int parameter}$
    2307 * [ ] (int,char) hp; $\C{// pointer to routine returning no result with int and char parameters}$
    2308 * [ * int,int ] ( int ) jp; $\C{// pointer to routine returning pointer to int and int, with int parameter}\CRT$
     2318* [ int x ] () fp; §\C{// pointer to routine returning int with no parameters}§
     2319* [ * int ] (int y) gp; §\C{// pointer to routine returning pointer to int with int parameter}§
     2320* [ ] (int,char) hp; §\C{// pointer to routine returning no result with int and char parameters}§
     2321* [ * int,int ] ( int ) jp; §\C{// pointer to routine returning pointer to int and int, with int parameter}§
    23092322\end{cfa}
    23102323While parameter names are optional, \emph{a routine name cannot be specified};
    23112324for example, the following is incorrect:
    23122325\begin{cfa}
    2313 * [ int x ] f () fp; $\C{// routine name "f" is not allowed}$
     2326* [ int x ] f () fp; §\C{// routine name "f" is not allowed}§
    23142327\end{cfa}
    23152328
     
    23342347whereas a named (keyword) call may be:
    23352348\begin{cfa}
    2336 p( z : 3, x : 4, y : 7 );  $\C{// rewrite \(\Rightarrow\) p( 4, 7, 3 )}$
     2349p( z : 3, x : 4, y : 7 );  §\C{// rewrite $\Rightarrow$ p( 4, 7, 3 )}§
    23372350\end{cfa}
    23382351Here the order of the arguments is unimportant, and the names of the parameters are used to associate argument values with the corresponding parameters.
     
    23512364For example, the following routine prototypes and definition are all valid.
    23522365\begin{cfa}
    2353 void p( int, int, int ); $\C{// equivalent prototypes}$
     2366void p( int, int, int ); §\C{// equivalent prototypes}§
    23542367void p( int x, int y, int z );
    23552368void p( int y, int x, int z );
    23562369void p( int z, int y, int x );
    2357 void p( int q, int r, int s ) {} $\C{// match with this definition}$
     2370void p( int q, int r, int s ) {} §\C{// match with this definition}§
    23582371\end{cfa}
    23592372Forcing matching parameter names in routine prototypes with corresponding routine definitions is possible, but goes against a strong tradition in C programming.
     
    23672380int f( int x, double y );
    23682381
    2369 f( j : 3, i : 4 ); $\C{// 1st f}$
    2370 f( x : 7, y : 8.1 ); $\C{// 2nd f}$
    2371 f( 4, 5 );  $\C{// ambiguous call}$
     2382f( j : 3, i : 4 ); §\C{// 1st f}§
     2383f( x : 7, y : 8.1 ); §\C{// 2nd f}§
     2384f( 4, 5 );  §\C{// ambiguous call}§
    23722385\end{cfa}
    23732386However, named arguments compound routine resolution in conjunction with conversions:
    23742387\begin{cfa}
    2375 f( i : 3, 5.7 ); $\C{// ambiguous call ?}$
     2388f( i : 3, 5.7 ); §\C{// ambiguous call ?}§
    23762389\end{cfa}
    23772390Depending on the cost associated with named arguments, this call could be resolvable or ambiguous.
     
    23872400the allowable positional calls are:
    23882401\begin{cfa}
    2389 p(); $\C{// rewrite \(\Rightarrow\) p( 1, 2, 3 )}$
    2390 p( 4 ); $\C{// rewrite \(\Rightarrow\) p( 4, 2, 3 )}$
    2391 p( 4, 4 ); $\C{// rewrite \(\Rightarrow\) p( 4, 4, 3 )}$
    2392 p( 4, 4, 4 ); $\C{// rewrite \(\Rightarrow\) p( 4, 4, 4 )}$
     2402p(); §\C{// rewrite $\Rightarrow$ p( 1, 2, 3 )}§
     2403p( 4 ); §\C{// rewrite $\Rightarrow$ p( 4, 2, 3 )}§
     2404p( 4, 4 ); §\C{// rewrite $\Rightarrow$ p( 4, 4, 3 )}§
     2405p( 4, 4, 4 ); §\C{// rewrite $\Rightarrow$ p( 4, 4, 4 )}§
    23932406// empty arguments
    2394 p(  , 4, 4 ); $\C{// rewrite \(\Rightarrow\) p( 1, 4, 4 )}$
    2395 p( 4,  , 4 ); $\C{// rewrite \(\Rightarrow\) p( 4, 2, 4 )}$
    2396 p( 4, 4,   ); $\C{// rewrite \(\Rightarrow\) p( 4, 4, 3 )}$
    2397 p( 4,  ,   ); $\C{// rewrite \(\Rightarrow\) p( 4, 2, 3 )}$
    2398 p(  , 4,   ); $\C{// rewrite \(\Rightarrow\) p( 1, 4, 3 )}$
    2399 p(  ,  , 4 ); $\C{// rewrite \(\Rightarrow\) p( 1, 2, 4 )}$
    2400 p(  ,  ,   ); $\C{// rewrite \(\Rightarrow\) p( 1, 2, 3 )}$
     2407p(  , 4, 4 ); §\C{// rewrite $\Rightarrow$ p( 1, 4, 4 )}§
     2408p( 4,  , 4 ); §\C{// rewrite $\Rightarrow$ p( 4, 2, 4 )}§
     2409p( 4, 4,   ); §\C{// rewrite $\Rightarrow$ p( 4, 4, 3 )}§
     2410p( 4,  ,   ); §\C{// rewrite $\Rightarrow$ p( 4, 2, 3 )}§
     2411p(  , 4,   ); §\C{// rewrite $\Rightarrow$ p( 1, 4, 3 )}§
     2412p(  ,  , 4 ); §\C{// rewrite $\Rightarrow$ p( 1, 2, 4 )}§
     2413p(  ,  ,   ); §\C{// rewrite $\Rightarrow$ p( 1, 2, 3 )}§
    24012414\end{cfa}
    24022415Here the missing arguments are inserted from the default values in the parameter list.
     
    24222435Default values may only appear in a prototype versus definition context:
    24232436\begin{cfa}
    2424 void p( int x, int y = 2, int z = 3 ); $\C{// prototype: allowed}$
    2425 void p( int, int = 2, int = 3 ); $\C{// prototype: allowed}$
    2426 void p( int x, int y = 2, int z = 3 ) {} $\C{// definition: not allowed}$
     2437void p( int x, int y = 2, int z = 3 ); §\C{// prototype: allowed}§
     2438void p( int, int = 2, int = 3 ); §\C{// prototype: allowed}§
     2439void p( int x, int y = 2, int z = 3 ) {} §\C{// definition: not allowed}§
    24272440\end{cfa}
    24282441The reason for this restriction is to allow separate compilation.
     
    24392452\begin{cfa}
    24402453p( int x, int y, int z, ... );
    2441 p( 1, 4, 5, 6, z : 3, y : 2 ); $\C{// assume p( /* positional */, ... , /* named */ );}$
    2442 p( 1, z : 3, y : 2, 4, 5, 6 ); $\C{// assume p( /* positional */, /* named */, ... );}$
     2454p( 1, 4, 5, 6, z : 3, y : 2 ); §\C{// assume p( /* positional */, ... , /* named */ );}§
     2455p( 1, z : 3, y : 2, 4, 5, 6 ); §\C{// assume p( /* positional */, /* named */, ... );}§
    24432456\end{cfa}
    24442457In the first call, it is necessary for the programmer to conceptually rewrite the call, changing named arguments into positional, before knowing where the ellipse arguments begin.
     
    24492462\begin{cfa}
    24502463void p( int x, int y = 2, int z = 3... );
    2451 p( 1, 4, 5, 6, z : 3 ); $\C{// assume p( /* positional */, ... , /* named */ );}$
    2452 p( 1, z : 3, 4, 5, 6 ); $\C{// assume p( /* positional */, /* named */, ... );}$
     2464p( 1, 4, 5, 6, z : 3 ); §\C{// assume p( /* positional */, ... , /* named */ );}§
     2465p( 1, z : 3, 4, 5, 6 ); §\C{// assume p( /* positional */, /* named */, ... );}§
    24532466\end{cfa}
    24542467The first call is an error because arguments 4 and 5 are actually positional not ellipse arguments;
     
    24562469In the second call, the default value for y is implicitly inserted after argument 1 and the named arguments separate the positional and ellipse arguments, making it trivial to read the call.
    24572470For these reasons, \CFA requires named arguments before ellipse arguments.
    2458 Finally, while ellipse arguments are needed for a small set of existing C routines, like ©printf©, the extended \CFA type system largely eliminates the need for ellipse arguments \see{\VRef{s:Overloading}}, making much of this discussion moot.
    2459 
    2460 Default arguments and overloading \see{\VRef{s:Overloading}} are complementary.
     2471Finally, while ellipse arguments are needed for a small set of existing C routines, like printf, the extended \CFA type system largely eliminates the need for ellipse arguments (see Section 24), making much of this discussion moot.
     2472
     2473Default arguments and overloading (see Section 24) are complementary.
    24612474While in theory default arguments can be simulated with overloading, as in:
    24622475\begin{cquote}
     
    24802493Furthermore, overloading cannot handle accessing default arguments in the middle of a positional list, via a missing argument, such as:
    24812494\begin{cfa}
    2482 p( 1, /* default */, 5 ); $\C{// rewrite \(\Rightarrow\) p( 1, 2, 5 )}$
     2495p( 1, /* default */, 5 ); §\C{// rewrite $\Rightarrow$ p( 1, 2, 5 )}§
    24832496\end{cfa}
    24842497
     
    24932506\begin{cfa}
    24942507struct {
    2495         int f1; $\C{// named field}$
    2496         int f2 : 4; $\C{// named field with bit field size}$
    2497         int : 3; $\C{// unnamed field for basic type with bit field size}$
    2498         int ; $\C{// disallowed, unnamed field}$
    2499         int *; $\C{// disallowed, unnamed field}$
    2500         int (*)( int ); $\C{// disallowed, unnamed field}$
     2508        int f1; §\C{// named field}§
     2509        int f2 : 4; §\C{// named field with bit field size}§
     2510        int : 3; §\C{// unnamed field for basic type with bit field size}§
     2511        int ; §\C{// disallowed, unnamed field}§
     2512        int *; §\C{// disallowed, unnamed field}§
     2513        int (*)( int ); §\C{// disallowed, unnamed field}§
    25012514};
    25022515\end{cfa}
     
    25062519\begin{cfa}
    25072520struct {
    2508         int , , ; $\C{// 3 unnamed fields}$
     2521        int , , ; §\C{// 3 unnamed fields}§
    25092522}
    25102523\end{cfa}
     
    25182531\subsection{Type Nesting}
    25192532
    2520 \CFA allows \Index{type nesting}, and type qualification of the nested types \see{\VRef[Figure]{f:TypeNestingQualification}}, where as C hoists\index{type hoisting} (refactors) nested types into the enclosing scope and has no type qualification.
     2533\CFA allows \Index{type nesting}, and type qualification of the nested types (see \VRef[Figure]{f:TypeNestingQualification}), where as C hoists\index{type hoisting} (refactors) nested types into the enclosing scope and has no type qualification.
    25212534\begin{figure}
    25222535\centering
     
    25742587
    25752588int fred() {
    2576         s.t.c = @S.@R;  // type qualification
    2577         struct @S.@T t = { @S.@R, 1, 2 };
    2578         enum @S.@C c;
    2579         union @S.T.@U u;
     2589        s.t.c = ®S.®R;  // type qualification
     2590        struct ®S.®T t = { ®S.®R, 1, 2 };
     2591        enum ®S.®C c;
     2592        union ®S.T.®U u;
    25802593}
    25812594\end{cfa}
     
    26002613const unsigned int size = 5;
    26012614int ia[size];
    2602 ... $\C{// assign values to array ia}$
    2603 qsort( ia, size ); $\C{// sort ascending order using builtin ?<?}$
     2615... §\C{// assign values to array ia}§
     2616qsort( ia, size ); §\C{// sort ascending order using builtin ?<?}§
    26042617{
    2605         @int ?<?( int x, int y ) { return x > y; }@ $\C{// nested routine}$
    2606         qsort( ia, size ); $\C{// sort descending order by local redefinition}$
     2618        ®int ?<?( int x, int y ) { return x > y; }® §\C{// nested routine}§
     2619        qsort( ia, size ); §\C{// sort descending order by local redefinition}§
    26072620}
    26082621\end{cfa}
     
    26122625The following program in undefined in \CFA (and Indexc{gcc})
    26132626\begin{cfa}
    2614 [* [int]( int )] foo() { $\C{// int (* foo())( int )}$
    2615         int @i@ = 7;
     2627[* [int]( int )] foo() { §\C{// int (* foo())( int )}§
     2628        int ®i® = 7;
    26162629        int bar( int p ) {
    2617                 @i@ += 1; $\C{// dependent on local variable}$
    2618                 sout | @i@;
     2630                ®i® += 1; §\C{// dependent on local variable}§
     2631                sout | ®i®;
    26192632        }
    2620         return bar; $\C{// undefined because of local dependence}$
     2633        return bar; §\C{// undefined because of local dependence}§
    26212634}
    26222635int main() {
    2623         * [int]( int ) fp = foo(); $\C{// int (* fp)( int )}$
     2636        * [int]( int ) fp = foo(); §\C{// int (* fp)( int )}§
    26242637        sout | fp( 3 );
    26252638}
     
    26342647In C and \CFA, lists of elements appear in several contexts, such as the parameter list of a routine call.
    26352648\begin{cfa}
    2636 f( @2, x, 3 + i@ ); $\C{// element list}$
     2649f( ®2, x, 3 + i® ); §\C{// element list}§
    26372650\end{cfa}
    26382651A list of elements is called a \newterm{tuple}, and is different from a \Index{comma expression}.
     
    26432656
    26442657In C and most programming languages, functions return at most one value;
    2645 however, many operations have multiple outcomes, some exceptional \see{\VRef{s:ExceptionHandling}}.
     2658however, many operations have multiple outcomes, some exceptional (see~\VRef{s:ExceptionHandling}).
    26462659To emulate functions with multiple return values, \emph{\Index{aggregation}} and/or \emph{\Index{aliasing}} is used.
    26472660
     
    26492662For example, consider C's \Indexc{div} function, which returns the quotient and remainder for a division of an integer value.
    26502663\begin{cfa}
    2651 typedef struct { int quot, rem; } div_t;        $\C[7cm]{// from include stdlib.h}$
     2664typedef struct { int quot, rem; } div_t;        §\C[7cm]{// from include stdlib.h}§
    26522665div_t div( int num, int den );
    2653 div_t qr = div( 13, 5 ); $\C{// return quotient/remainder aggregate}$
    2654 printf( "%d %d\n", qr.quot, qr.rem ); $\C{// print quotient/remainder}$
     2666div_t qr = div( 13, 5 ); §\C{// return quotient/remainder aggregate}§
     2667printf( "%d %d\n", qr.quot, qr.rem ); §\C{// print quotient/remainder}§
    26552668\end{cfa}
    26562669This approach requires a name for the return type and fields, where \Index{naming} is a common programming-language issue.
     
    26622675For example, consider C's \Indexc{modf} function, which returns the integral and fractional part of a floating value.
    26632676\begin{cfa}
    2664 double modf( double x, double * i ); $\C{// from include math.h}$
    2665 double intp, frac = modf( 13.5, &intp ); $\C{// return integral and fractional components}$
    2666 printf( "%g %g\n", intp, frac ); $\C{// print integral/fractional components}$
     2677double modf( double x, double * i ); §\C{// from include math.h}§
     2678double intp, frac = modf( 13.5, &intp ); §\C{// return integral and fractional components}§
     2679printf( "%g %g\n", intp, frac ); §\C{// print integral/fractional components}§
    26672680\end{cfa}
    26682681This approach requires allocating storage for the return values, which complicates the call site with a sequence of variable declarations leading to the call.
     
    26912704When a function call is passed as an argument to another call, the best match of actual arguments to formal parameters is evaluated given all possible expression interpretations in the current scope.
    26922705\begin{cfa}
    2693 void g( int, int ); $\C{// 1}$
    2694 void g( double, double ); $\C{// 2}$
    2695 g( div( 13, 5 ) ); $\C{// select 1}$
    2696 g( modf( 13.5 ) ); $\C{// select 2}$
     2706void g( int, int ); §\C{// 1}§
     2707void g( double, double ); §\C{// 2}§
     2708g( div( 13, 5 ) ); §\C{// select 1}§
     2709g( modf( 13.5 ) ); §\C{// select 2}§
    26972710\end{cfa}
    26982711In this case, there are two overloaded ©g© routines.
     
    27032716The previous examples can be rewritten passing the multiple returned-values directly to the ©printf© function call.
    27042717\begin{cfa}
    2705 [ int, int ] div( int x, int y ); $\C{// from include stdlib}$
    2706 printf( "%d %d\n", div( 13, 5 ) ); $\C{// print quotient/remainder}$
    2707 
    2708 [ double, double ] modf( double x ); $\C{// from include math}$
    2709 printf( "%g %g\n", modf( 13.5 ) ); $\C{// print integral/fractional components}$
     2718[ int, int ] div( int x, int y ); §\C{// from include stdlib}§
     2719printf( "%d %d\n", div( 13, 5 ) ); §\C{// print quotient/remainder}§
     2720
     2721[ double, double ] modf( double x ); §\C{// from include math}§
     2722printf( "%g %g\n", modf( 13.5 ) ); §\C{// print integral/fractional components}§
    27102723\end{cfa}
    27112724This approach provides the benefits of compile-time checking for appropriate return statements as in aggregation, but without the required verbosity of declaring a new named type.
     
    27172730\begin{cfa}
    27182731int quot, rem;
    2719 [ quot, rem ] = div( 13, 5 ); $\C{// assign multiple variables}$
    2720 printf( "%d %d\n", quot, rem ); $\C{// print quotient/remainder}\CRT$
     2732[ quot, rem ] = div( 13, 5 ); §\C{// assign multiple variables}§
     2733printf( "%d %d\n", quot, rem ); §\C{// print quotient/remainder}\CRT§
    27212734\end{cfa}
    27222735Here, the multiple return-values are matched in much the same way as passing multiple return-values to multiple parameters in a call.
     
    27472760In \CFA, it is possible to overcome this restriction by declaring a \newterm{tuple variable}.
    27482761\begin{cfa}
    2749 [int, int] @qr@ = div( 13, 5 ); $\C{// initialize tuple variable}$
    2750 printf( "%d %d\n", @qr@ ); $\C{// print quotient/remainder}$
     2762[int, int] ®qr® = div( 13, 5 ); §\C{// initialize tuple variable}§
     2763printf( "%d %d\n", ®qr® ); §\C{// print quotient/remainder}§
    27512764\end{cfa}
    27522765It is now possible to match the multiple return-values to a single variable, in much the same way as \Index{aggregation}.
     
    27542767One way to access the individual components of a tuple variable is with assignment.
    27552768\begin{cfa}
    2756 [ quot, rem ] = qr; $\C{// assign multiple variables}$
     2769[ quot, rem ] = qr; §\C{// assign multiple variables}§
    27572770\end{cfa}
    27582771
     
    27772790[int, double] * p;
    27782791
    2779 int y = x.0; $\C{// access int component of x}$
    2780 y = f().1; $\C{// access int component of f}$
    2781 p->0 = 5; $\C{// access int component of tuple pointed-to by p}$
    2782 g( x.1, x.0 ); $\C{// rearrange x to pass to g}$
    2783 double z = [ x, f() ].0.1; $\C{// access second component of first component of tuple expression}$
     2792int y = x.0; §\C{// access int component of x}§
     2793y = f().1; §\C{// access int component of f}§
     2794p->0 = 5; §\C{// access int component of tuple pointed-to by p}§
     2795g( x.1, x.0 ); §\C{// rearrange x to pass to g}§
     2796double z = [ x, f() ].0.1; §\C{// access second component of first component of tuple expression}§
    27842797\end{cfa}
    27852798Tuple-index expressions can occur on any tuple-typed expression, including tuple-returning functions, square-bracketed tuple expressions, and other tuple-index expressions, provided the retrieved component is also a tuple.
     
    27882801
    27892802\subsection{Flattening and Structuring}
    2790 \label{s:FlatteningStructuring}
    27912803
    27922804As evident in previous examples, tuples in \CFA do not have a rigid structure.
     
    28492861double y;
    28502862[int, double] z;
    2851 [y, x] = 3.14; $\C{// mass assignment}$
    2852 [x, y] = z;                                                         $\C{// multiple assignment}$
    2853 z = 10;                                                         $\C{// mass assignment}$
    2854 z = [x, y]; $\C{// multiple assignment}$
     2863[y, x] = 3.14; §\C{// mass assignment}§
     2864[x, y] = z;                                                         §\C{// multiple assignment}§
     2865z = 10;                                                         §\C{// mass assignment}§
     2866z = [x, y]; §\C{// multiple assignment}§
    28552867\end{cfa}
    28562868Let $L_i$ for $i$ in $[0, n)$ represent each component of the flattened left side, $R_i$ represent each component of the flattened right side of a multiple assignment, and $R$ represent the right side of a mass assignment.
     
    28602872\begin{cfa}
    28612873[ int, int ] x, y, z;
    2862 [ x, y ] = z;                                              $\C{// multiple assignment, invalid 4 != 2}$
     2874[ x, y ] = z;                                              §\C{// multiple assignment, invalid 4 != 2}§
    28632875\end{cfa}
    28642876Multiple assignment assigns $R_i$ to $L_i$ for each $i$.
     
    28962908        double c, d;
    28972909        [ void ] f( [ int, int ] );
    2898         f( [ c, a ] = [ b, d ] = 1.5 ); $\C{// assignments in parameter list}$
     2910        f( [ c, a ] = [ b, d ] = 1.5 ); §\C{// assignments in parameter list}§
    28992911\end{cfa}
    29002912The tuple expression begins with a mass assignment of ©1.5© into ©[b, d]©, which assigns ©1.5© into ©b©, which is truncated to ©1©, and ©1.5© into ©d©, producing the tuple ©[1, 1.5]© as a result.
     
    29092921\begin{cfa}
    29102922struct S;
    2911 void ?{}(S *); $\C{// (1)}$
    2912 void ?{}(S *, int); $\C{// (2)}$
    2913 void ?{}(S * double); $\C{// (3)}$
    2914 void ?{}(S *, S); $\C{// (4)}$
    2915 
    2916 [S, S] x = [3, 6.28]; $\C{// uses (2), (3), specialized constructors}$
    2917 [S, S] y; $\C{// uses (1), (1), default constructor}$
    2918 [S, S] z = x.0; $\C{// uses (4), (4), copy constructor}$
     2923void ?{}(S *); §\C{// (1)}§
     2924void ?{}(S *, int); §\C{// (2)}§
     2925void ?{}(S * double); §\C{// (3)}§
     2926void ?{}(S *, S); §\C{// (4)}§
     2927
     2928[S, S] x = [3, 6.28]; §\C{// uses (2), (3), specialized constructors}§
     2929[S, S] y; §\C{// uses (1), (1), default constructor}§
     2930[S, S] z = x.0; §\C{// uses (4), (4), copy constructor}§
    29192931\end{cfa}
    29202932In this example, ©x© is initialized by the multiple constructor calls ©?{}(&x.0, 3)© and ©?{}(&x.1, 6.28)©, while ©y© is initialized by two default constructor calls ©?{}(&y.0)© and ©?{}(&y.1)©.
     
    29572969A member-access tuple may be used anywhere a tuple can be used, \eg:
    29582970\begin{cfa}
    2959 s.[ y, z, x ] = [ 3, 3.2, 'x' ]; $\C{// equivalent to s.x = 'x', s.y = 3, s.z = 3.2}$
    2960 f( s.[ y, z ] ); $\C{// equivalent to f( s.y, s.z )}$
     2971s.[ y, z, x ] = [ 3, 3.2, 'x' ]; §\C{// equivalent to s.x = 'x', s.y = 3, s.z = 3.2}§
     2972f( s.[ y, z ] ); §\C{// equivalent to f( s.y, s.z )}§
    29612973\end{cfa}
    29622974Note, the fields appearing in a record-field tuple may be specified in any order;
     
    29682980void f( double, long );
    29692981
    2970 f( x.[ 0, 3 ] ); $\C{// f( x.0, x.3 )}$
    2971 x.[ 0, 1 ] = x.[ 1, 0 ]; $\C{// [ x.0, x.1 ] = [ x.1, x.0 ]}$
     2982f( x.[ 0, 3 ] ); §\C{// f( x.0, x.3 )}§
     2983x.[ 0, 1 ] = x.[ 1, 0 ]; §\C{// [ x.0, x.1 ] = [ x.1, x.0 ]}§
    29722984[ long, int, long ] y = x.[ 2, 0, 2 ];
    29732985\end{cfa}
     
    29862998\begin{cfa}
    29872999[ int, float, double ] f();
    2988 [ double, float ] x = f().[ 2, 1 ]; $\C{// f() called once}$
     3000[ double, float ] x = f().[ 2, 1 ]; §\C{// f() called once}§
    29893001\end{cfa}
    29903002
     
    29993011That is, a cast can be used to select the type of an expression when it is ambiguous, as in the call to an overloaded function.
    30003012\begin{cfa}
    3001 int f(); $\C{// (1)}$
    3002 double f(); $\C{// (2)}$
    3003 
    3004 f(); $\C{// ambiguous - (1),(2) both equally viable}$
    3005 (int)f(); $\C{// choose (2)}$
     3013int f(); §\C{// (1)}§
     3014double f(); §\C{// (2)}§
     3015
     3016f(); §\C{// ambiguous - (1),(2) both equally viable}§
     3017(int)f(); §\C{// choose (2)}§
    30063018\end{cfa}
    30073019Since casting is a fundamental operation in \CFA, casts need to be given a meaningful interpretation in the context of tuples.
     
    30113023void g();
    30123024
    3013 (void)f(); $\C{// valid, ignore results}$
    3014 (int)g(); $\C{// invalid, void cannot be converted to int}$
     3025(void)f(); §\C{// valid, ignore results}§
     3026(int)g(); §\C{// invalid, void cannot be converted to int}§
    30153027
    30163028struct A { int x; };
    3017 (struct A)f(); $\C{// invalid, int cannot be converted to A}$
     3029(struct A)f(); §\C{// invalid, int cannot be converted to A}§
    30183030\end{cfa}
    30193031In C, line 4 is a valid cast, which calls ©f© and discards its result.
     
    30313043        [int, [int, int], int] g();
    30323044
    3033         ([int, double])f(); $\C{// (1) valid}$
    3034         ([int, int, int])g(); $\C{// (2) valid}$
    3035         ([void, [int, int]])g(); $\C{// (3) valid}$
    3036         ([int, int, int, int])g(); $\C{// (4) invalid}$
    3037         ([int, [int, int, int]])g(); $\C{// (5) invalid}$
     3045        ([int, double])f(); §\C{// (1) valid}§
     3046        ([int, int, int])g(); §\C{// (2) valid}§
     3047        ([void, [int, int]])g(); §\C{// (3) valid}§
     3048        ([int, int, int, int])g(); §\C{// (4) invalid}§
     3049        ([int, [int, int, int]])g(); §\C{// (5) invalid}§
    30383050\end{cfa}
    30393051
     
    30953107void f([int, int], int, int);
    30963108
    3097 f([0, 0], 0, 0); $\C{// no cost}$
    3098 f(0, 0, 0, 0); $\C{// cost for structuring}$
    3099 f([0, 0,], [0, 0]); $\C{// cost for flattening}$
    3100 f([0, 0, 0], 0); $\C{// cost for flattening and structuring}$
     3109f([0, 0], 0, 0); §\C{// no cost}§
     3110f(0, 0, 0, 0); §\C{// cost for structuring}§
     3111f([0, 0,], [0, 0]); §\C{// cost for flattening}§
     3112f([0, 0, 0], 0); §\C{// cost for flattening and structuring}§
    31013113\end{cfa}
    31023114
     
    31343146The general syntax of a lexical list is:
    31353147\begin{cfa}
    3136 [ $\emph{exprlist}$ ]
     3148[ §\emph{exprlist}§ ]
    31373149\end{cfa}
    31383150where ©$\emph{exprlist}$© is a list of one or more expressions separated by commas.
     
    31463158Tuples are permitted to contain sub-tuples (\ie nesting), such as ©[ [ 14, 21 ], 9 ]©, which is a 2-element tuple whose first element is itself a tuple.
    31473159Note, a tuple is not a record (structure);
    3148 a record denotes a single value with substructure, whereas a tuple is multiple values with no substructure \see{flattening coercion in \VRef{s:FlatteningStructuring}}.
     3160a record denotes a single value with substructure, whereas a tuple is multiple values with no substructure (see flattening coercion in Section 12.1).
    31493161In essence, tuples are largely a compile time phenomenon, having little or no runtime presence.
    31503162
     
    31543166The general syntax of a tuple type is:
    31553167\begin{cfa}
    3156 [ $\emph{typelist}$ ]
     3168[ §\emph{typelist}§ ]
    31573169\end{cfa}
    31583170where ©$\emph{typelist}$© is a list of one or more legal \CFA or C type specifications separated by commas, which may include other tuple type specifications.
     
    31613173[ unsigned int, char ]
    31623174[ double, double, double ]
    3163 [ * int, int * ] $\C{// mix of CFA and ANSI}$
     3175[ * int, int * ] §\C{// mix of CFA and ANSI}§
    31643176[ * [ 5 ] int, * * char, * [ [ int, int ] ] (int, int) ]
    31653177\end{cfa}
     
    31683180Examples of declarations using tuple types are:
    31693181\begin{cfa}
    3170 [ int, int ] x; $\C{// 2 element tuple, each element of type int}$
    3171 * [ char, char ] y; $\C{// pointer to a 2 element tuple}$
     3182[ int, int ] x; §\C{// 2 element tuple, each element of type int}§
     3183* [ char, char ] y; §\C{// pointer to a 2 element tuple}§
    31723184[ [ int, int ] ] z ([ int, int ]);
    31733185\end{cfa}
     
    31863198[ int, int ] w1;
    31873199[ int, int, int ] w2;
    3188 [ void ] f (int, int, int); $\C{// three input parameters of type int}$
    3189 [ void ] g ([ int, int, int ]); $\C{3 element tuple as input}$
     3200[ void ] f (int, int, int); §\C{// three input parameters of type int}§
     3201[ void ] g ([ int, int, int ]); §\C{3 element tuple as input}§
    31903202f( [ 1, 2, 3 ] );
    31913203f( w1, 3 );
     
    32673279[ int, int, int, int ] w = [ 1, 2, 3, 4 ];
    32683280int x = 5;
    3269 [ x, w ] = [ w, x ]; $\C{// all four tuple coercions}$
     3281[ x, w ] = [ w, x ]; §\C{// all four tuple coercions}§
    32703282\end{cfa}
    32713283Starting on the right-hand tuple in the last assignment statement, w is opened, producing a tuple of four values;
     
    32733285This tuple is then flattened, yielding ©[ 1, 2, 3, 4, 5 ]©, which is structured into ©[ 1, [ 2, 3, 4, 5 ] ]© to match the tuple type of the left-hand side.
    32743286The tuple ©[ 2, 3, 4, 5 ]© is then closed to create a tuple value.
    3275 Finally, ©x© is assigned ©1© and ©w© is assigned the tuple value using \Index{multiple assignment} \see{\VRef{s:TupleAssignment}}.
     3287Finally, ©x© is assigned ©1© and ©w© is assigned the tuple value using multiple assignment (see Section 14).
    32763288\begin{rationale}
    32773289A possible additional language extension is to use the structuring coercion for tuples to initialize a complex record with a tuple.
     
    32843296Mass assignment has the following form:
    32853297\begin{cfa}
    3286 [ $\emph{lvalue}$, ... , $\emph{lvalue}$ ] = $\emph{expr}$;
     3298[ §\emph{lvalue}§, ... , §\emph{lvalue}§ ] = §\emph{expr}§;
    32873299\end{cfa}
    32883300\index{lvalue}
     
    33243336Multiple assignment has the following form:
    33253337\begin{cfa}
    3326 [ $\emph{lvalue}$, ... , $\emph{lvalue}$ ] = [ $\emph{expr}$, ... , $\emph{expr}$ ];
     3338[ §\emph{lvalue}§, ... , §\emph{lvalue}§ ] = [ §\emph{expr}§, ... , §\emph{expr}§ ];
    33273339\end{cfa}
    33283340\index{lvalue}
     
    33553367both these examples produce indeterminate results:
    33563368\begin{cfa}
    3357 f( x++, x++ ); $\C{// C routine call with side effects in arguments}$
    3358 [ v1, v2 ] = [ x++, x++ ]; $\C{// side effects in right-hand side of multiple assignment}$
     3369f( x++, x++ ); §\C{// C routine call with side effects in arguments}§
     3370[ v1, v2 ] = [ x++, x++ ]; §\C{// side effects in righthand side of multiple assignment}§
    33593371\end{cfa}
    33603372
     
    33653377Cascade assignment has the following form:
    33663378\begin{cfa}
    3367 $\emph{tuple}$ = $\emph{tuple}$ = ... = $\emph{tuple}$;
     3379§\emph{tuple}§ = §\emph{tuple}§ = ... = §\emph{tuple}§;
    33683380\end{cfa}
    33693381and it has the same parallel semantics as for mass and multiple assignment.
     
    34123424\begin{cfa}
    34133425int x = 1, y = 2, z = 3;
    3414 sout | x @|@ y @|@ z;
     3426sout | x ®|® y ®|® z;
    34153427\end{cfa}
    34163428&
    34173429\begin{cfa}
    34183430
    3419 cout << x @<< " "@ << y @<< " "@ << z << endl;
     3431cout << x ®<< " "® << y ®<< " "® << z << endl;
    34203432\end{cfa}
    34213433&
     
    34263438\\
    34273439\begin{cfa}[showspaces=true,aboveskip=0pt,belowskip=0pt]
    3428 1@ @2@ @3
     34401® ®2® ®3
    34293441\end{cfa}
    34303442&
    34313443\begin{cfa}[showspaces=true,aboveskip=0pt,belowskip=0pt]
    3432 1@ @2@ @3
     34441® ®2® ®3
    34333445\end{cfa}
    34343446&
    34353447\begin{cfa}[showspaces=true,aboveskip=0pt,belowskip=0pt]
    3436 1@ @2@ @3
     34481® ®2® ®3
    34373449\end{cfa}
    34383450\end{tabular}
     
    34423454\begin{cfa}
    34433455[int, [ int, int ] ] t1 = [ 1, [ 2, 3 ] ], t2 = [ 4, [ 5, 6 ] ];
    3444 sout | t1 | t2; $\C{// print tuples}$
     3456sout | t1 | t2; §\C{// print tuples}§
    34453457\end{cfa}
    34463458\begin{cfa}[showspaces=true,aboveskip=0pt]
    3447 1@, @2@, @3 4@, @5@, @6
     34591®, ®2®, ®3 4®, ®5®, ®6
    34483460\end{cfa}
    34493461Finally, \CFA uses the logical-or operator for I/O as it is the lowest-priority \emph{overloadable} operator, other than assignment.
     
    34543466&
    34553467\begin{cfa}
    3456 sout | x * 3 | y + 1 | z << 2 | x == y | @(@x | y@)@ | @(@x || y@)@ | @(@x > z ? 1 : 2@)@;
     3468sout | x * 3 | y + 1 | z << 2 | x == y | ®(®x | y®)® | ®(®x || y®)® | ®(®x > z ? 1 : 2®)®;
    34573469\end{cfa}
    34583470\\
     
    34603472&
    34613473\begin{cfa}
    3462 cout << x * 3 << y + 1 << @(@z << 2@)@ << @(@x == y@)@ << @(@x | y@)@ << @(@x || y@)@ << @(@x > z ? 1 : 2@)@ << endl;
     3474cout << x * 3 << y + 1 << ®(®z << 2®)® << ®(®x == y®)® << ®(®x | y®)® << ®(®x || y®)® << ®(®x > z ? 1 : 2®)® << endl;
    34633475\end{cfa}
    34643476\\
     
    34953507\\
    34963508\begin{cfa}[showspaces=true,aboveskip=0pt,belowskip=0pt]
    3497 @1@ @2.5@ @A@
     3509®1® ®2.5® ®A®
    34983510
    34993511
     
    35013513&
    35023514\begin{cfa}[showspaces=true,aboveskip=0pt,belowskip=0pt]
    3503 @1@ @2.5@ @A@
     3515®1® ®2.5® ®A®
    35043516
    35053517
     
    35073519&
    35083520\begin{cfa}[showspaces=true,aboveskip=0pt,belowskip=0pt]
    3509 @1@
    3510 @2.5@
    3511 @A@
     3521®1®
     3522®2.5®
     3523®A®
    35123524\end{cfa}
    35133525\end{tabular}
     
    35453557
    35463558\item
    3547 A separator does not appear before a C string starting with the (extended) \Index*{ASCII}\index{ASCII!extended} characters: \LstStringStyle{,.;!?)]\}\%\textcent\guillemotright}, where \LstStringStyle{\guillemotright} a closing citation mark.
    3548 \begin{cfa}
     3559{\lstset{language=CFA,deletedelim=**[is][]{¢}{¢}}
     3560A separator does not appear before a C string starting with the (extended) \Index*{ASCII}\index{ASCII!extended} characters: \lstinline[basicstyle=\tt]@,.;!?)]}%¢»@, where \lstinline[basicstyle=\tt]@»@ is a closing citation mark.
     3561\begin{cfa}[belowskip=0pt]
    35493562sout | 1 | ", x" | 2 | ". x" | 3 | "; x" | 4 | "! x" | 5 | "? x" | 6 | "% x"
    3550            | 7 | "$\LstStringStyle{\textcent}$ x" | 8 | "$\LstStringStyle{\guillemotright}$ x" | 9 | ") x" | 10 | "] x" | 11 | "} x";
    3551 \end{cfa}
    3552 \begin{cfa}[showspaces=true]
    3553 1@,@ x 2@.@ x 3@;@ x 4@!@ x 5@?@ x 6@%@ x 7$\R{\LstStringStyle{\textcent}}$ x 8$\R{\LstStringStyle{\guillemotright}}$ x 9@)@ x 10@]@ x 11@}@ x
    3554 \end{cfa}
    3555 
    3556 \item
    3557 A separator does not appear after a C string ending with the (extended) \Index*{ASCII}\index{ASCII!extended} characters: \LstStringStyle{([\{=\$\textsterling\textyen\textexclamdown\textquestiondown\guillemotleft}, where \LstStringStyle{\textexclamdown\textquestiondown} are inverted opening exclamation and question marks, and \LstStringStyle{\guillemotleft} is an opening citation mark.
     3563                | 7 | "¢ x" | 8 | "» x" | 9 | ") x" | 10 | "] x" | 11 | "} x";
     3564\end{cfa}
     3565\begin{cfa}[basicstyle=\tt,showspaces=true,aboveskip=0pt,belowskip=0pt]
     35661®,® x 2®.® x 3®;® x 4®!® x 5®?® x 6®%® x 7§\color{red}\textcent§ x 8®»® x 9®)® x 10®]® x 11®}® x
     3567\end{cfa}}%
     3568
     3569\item
     3570A separator does not appear after a C string ending with the (extended) \Index*{ASCII}\index{ASCII!extended} characters: \lstinline[mathescape=off,basicstyle=\tt]@([{=$£¥¡¿«@, where \lstinline[basicstyle=\tt]@¡¿@ are inverted opening exclamation and question marks, and \lstinline[basicstyle=\tt]@«@ is an opening citation mark.
    35583571%$
    3559 \begin{cfa}
    3560 sout | "x (" | 1 | "x [" | 2 | "x {" | 3 | "x =" | 4 | "x $" | 5 | "x $\LstStringStyle{\textsterling}$" | 6 | "x $\LstStringStyle{\textyen}$"
    3561            | 7 | "x $\LstStringStyle{\textexclamdown}$" | 8 | "x $\LstStringStyle{\textquestiondown}$" | 9 | "x $\LstStringStyle{\guillemotleft}$" | 10;
     3572\begin{cfa}[mathescape=off]
     3573sout | "x (" | 1 | "x [" | 2 | "x {" | 3 | "x =" | 4 | "x $" | 5 | "x £" | 6 | "x ¥"
     3574                | 7 | "x ¡" | 8 | "x ¿" | 9 | "x «" | 10;
    35623575\end{cfa}
    35633576%$
    3564 \begin{cfa}[showspaces=true]
    3565 x @(@1 x @[@2 x @{@3 x @=@4 x $\LstStringStyle{\textdollar}$5 x $\R{\LstStringStyle{\textsterling}}$6 x $\R{\LstStringStyle{\textyen}}$7 x $\R{\LstStringStyle{\textexclamdown}}$8 x $\R{\LstStringStyle{\textquestiondown}}$9 x $\R{\LstStringStyle{\guillemotleft}}$10
     3577\begin{cfa}[mathescape=off,basicstyle=\tt,showspaces=true,aboveskip=0pt,belowskip=0pt]
     3578x ®(®1 x ®[®2 x ®{®3 x ®=®4 x ®$®5 x ®£®6 x ®¥®7 x ®¡®8 x ®¿®9 x ®«®10
    35663579\end{cfa}
    35673580%$
    35683581
    35693582\item
    3570 A seperator does not appear before/after a C string starting/ending with the \Index*{ASCII} quote or whitespace characters: \lstinline[basicstyle=\tt,showspaces=true]{`'": \t\v\f\r\n}
    3571 \begin{cfa}
     3583A seperator does not appear before/after a C string starting/ending with the \Index*{ASCII} quote or whitespace characters: \lstinline[basicstyle=\tt,showspaces=true]@`'": \t\v\f\r\n@
     3584\begin{cfa}[belowskip=0pt]
    35723585sout | "x`" | 1 | "`x'" | 2 | "'x\"" | 3 | "\"x:" | 4 | ":x " | 5 | " x\t" | 6 | "\tx";
    35733586\end{cfa}
    3574 \begin{cfa}[showspaces=true,showtabs=true]
    3575 x@`@1@`@x$\R{\texttt{'}}$2$\R{\texttt{'}}$x$\R{\texttt{"}}$3$\R{\texttt{"}}$x@:@4@:@x@ @5@ @x@  @6@     @x
     3587\begin{cfa}[basicstyle=\tt,showspaces=true,showtabs=true,aboveskip=0pt,belowskip=0pt]
     3588x®`®1®`®x§\color{red}\texttt{'}§2§\color{red}\texttt{'}§x§\color{red}\texttt{"}§3§\color{red}\texttt{"}§x®:®4®:®x® ®5® ®x®      ®6®     ®x
    35763589\end{cfa}
    35773590
    35783591\item
    35793592If a space is desired before or after one of the special string start/end characters, simply insert a space.
    3580 \begin{cfa}
    3581 sout | "x ($\R{\texttt{\textvisiblespace}}$" | 1 | "$\R{\texttt{\textvisiblespace}}$) x" | 2 | "$\R{\texttt{\textvisiblespace}}$, x" | 3 | "$\R{\texttt{\textvisiblespace}}$:x:$\R{\texttt{\textvisiblespace}}$" | 4;
    3582 \end{cfa}
    3583 \begin{cfa}[showspaces=true,showtabs=true]
    3584 x (@ @1@ @) x 2@ @, x 3@ @:x:@ @4
     3593\begin{cfa}[belowskip=0pt]
     3594sout | "x (§\color{red}\texttt{\textvisiblespace}§" | 1 | "§\color{red}\texttt{\textvisiblespace}§) x" | 2 | "§\color{red}\texttt{\textvisiblespace}§, x" | 3 | "§\color{red}\texttt{\textvisiblespace}§:x:§\color{red}\texttt{\textvisiblespace}§" | 4;
     3595\end{cfa}
     3596\begin{cfa}[basicstyle=\tt,showspaces=true,showtabs=true,aboveskip=0pt,belowskip=0pt]
     3597x (® ®1® ®) x 2® ®, x 3® ®:x:® ®4
    35853598\end{cfa}
    35863599\end{enumerate}
     
    35953608\Indexc{sepSet}\index{manipulator!sepSet@©sepSet©} and \Indexc{sep}\index{manipulator!sep@©sep©}/\Indexc{sepGet}\index{manipulator!sepGet@©sepGet©} set and get the separator string.
    35963609The separator string can be at most 16 characters including the ©'\0'© string terminator (15 printable characters).
    3597 \begin{cfa}[escapechar=off,belowskip=0pt]
    3598 sepSet( sout, ", $" ); $\C{// set separator from " " to ", \$"}$
    3599 sout | 1 | 2 | 3 | " \"" | @sep@ | "\"";
     3610\begin{cfa}[mathescape=off,belowskip=0pt]
     3611sepSet( sout, ", $" ); §\C{// set separator from " " to ", \$"}§
     3612sout | 1 | 2 | 3 | " \"" | ®sep® | "\"";
    36003613\end{cfa}
    36013614%$
    36023615\begin{cfa}[mathescape=off,showspaces=true,aboveskip=0pt]
    3603 1@, $@2@, $@3 @", $"@
     36161®, $®2®, $®3 ®", $"®
    36043617\end{cfa}
    36053618%$
    36063619\begin{cfa}[belowskip=0pt]
    3607 sepSet( sout, " " ); $\C{// reset separator to " "}$
    3608 sout | 1 | 2 | 3 | " \"" | @sepGet( sout )@ | "\"";
     3620sepSet( sout, " " ); §\C{// reset separator to " "}§
     3621sout | 1 | 2 | 3 | " \"" | ®sepGet( sout )® | "\"";
    36093622\end{cfa}
    36103623\begin{cfa}[showspaces=true,aboveskip=0pt]
    3611 1@ @2@ @3 @" "@
     36241® ®2® ®3 ®" "®
    36123625\end{cfa}
    36133626©sepGet© can be used to store a separator and then restore it:
    36143627\begin{cfa}[belowskip=0pt]
    3615 char store[@sepSize@]; $\C{// sepSize is the maximum separator size}$
    3616 strcpy( store, sepGet( sout ) ); $\C{// copy current separator}$
    3617 sepSet( sout, "_" ); $\C{// change separator to underscore}$
     3628char store[®sepSize®]; §\C{// sepSize is the maximum separator size}§
     3629strcpy( store, sepGet( sout ) ); §\C{// copy current separator}§
     3630sepSet( sout, "_" ); §\C{// change separator to underscore}§
    36183631sout | 1 | 2 | 3;
    36193632\end{cfa}
    36203633\begin{cfa}[showspaces=true,aboveskip=0pt,belowskip=0pt]
    3621 1@_@2@_@3
     36341®_®2®_®3
    36223635\end{cfa}
    36233636\begin{cfa}[belowskip=0pt]
    3624 sepSet( sout, store ); $\C{// change separator back to original}$
     3637sepSet( sout, store ); §\C{// change separator back to original}§
    36253638sout | 1 | 2 | 3;
    36263639\end{cfa}
    36273640\begin{cfa}[showspaces=true,aboveskip=0pt]
    3628 1@ @2@ @3
     36411® ®2® ®3
    36293642\end{cfa}
    36303643
     
    36333646The tuple separator-string can be at most 16 characters including the ©'\0'© string terminator (15 printable characters).
    36343647\begin{cfa}[belowskip=0pt]
    3635 sepSetTuple( sout, " " ); $\C{// set tuple separator from ", " to " "}$
    3636 sout | t1 | t2 | " \"" | @sepTuple@ | "\"";
     3648sepSetTuple( sout, " " ); §\C{// set tuple separator from ", " to " "}§
     3649sout | t1 | t2 | " \"" | ®sepTuple® | "\"";
    36373650\end{cfa}
    36383651\begin{cfa}[showspaces=true,aboveskip=0pt]
    3639 1 2 3 4 5 6 @" "@
     36521 2 3 4 5 6 ®" "®
    36403653\end{cfa}
    36413654\begin{cfa}[belowskip=0pt]
    3642 sepSetTuple( sout, ", " ); $\C{// reset tuple separator to ", "}$
    3643 sout | t1 | t2 | " \"" | @sepGetTuple( sout )@ | "\"";
     3655sepSetTuple( sout, ", " ); §\C{// reset tuple separator to ", "}§
     3656sout | t1 | t2 | " \"" | ®sepGetTuple( sout )® | "\"";
    36443657\end{cfa}
    36453658\begin{cfa}[showspaces=true,aboveskip=0pt]
    3646 1, 2, 3 4, 5, 6 @", "@
     36591, 2, 3 4, 5, 6 ®", "®
    36473660\end{cfa}
    36483661As for ©sepGet©, ©sepGetTuple© can be use to store a tuple separator and then restore it.
     
    36513664\Indexc{sepDisable}\index{manipulator!sepDisable@©sepDisable©} and \Indexc{sepEnable}\index{manipulator!sepEnable@©sepEnable©} toggle printing the separator.
    36523665\begin{cfa}[belowskip=0pt]
    3653 sout | sepDisable | 1 | 2 | 3; $\C{// turn off implicit separator}$
     3666sout | sepDisable | 1 | 2 | 3; §\C{// turn off implicit separator}§
    36543667\end{cfa}
    36553668\begin{cfa}[showspaces=true,aboveskip=0pt,belowskip=0pt]
     
    36573670\end{cfa}
    36583671\begin{cfa}[belowskip=0pt]
    3659 sout | sepEnable | 1 | 2 | 3; $\C{// turn on implicit separator}$
     3672sout | sepEnable | 1 | 2 | 3; §\C{// turn on implicit separator}§
    36603673\end{cfa}
    36613674\begin{cfa}[mathescape=off,showspaces=true,aboveskip=0pt,belowskip=0pt]
     
    36663679\Indexc{sepOn}\index{manipulator!sepOn@©sepOn©} and \Indexc{sepOff}\index{manipulator!sepOff@©sepOff©} toggle printing the separator with respect to the next printed item, and then return to the global seperator setting.
    36673680\begin{cfa}[belowskip=0pt]
    3668 sout | 1 | sepOff | 2 | 3; $\C{// turn off implicit separator for the next item}$
     3681sout | 1 | sepOff | 2 | 3; §\C{// turn off implicit separator for the next item}§
    36693682\end{cfa}
    36703683\begin{cfa}[showspaces=true,aboveskip=0pt,belowskip=0pt]
     
    36723685\end{cfa}
    36733686\begin{cfa}[belowskip=0pt]
    3674 sout | sepDisable | 1 | sepOn | 2 | 3; $\C{// turn on implicit separator for the next item}$
     3687sout | sepDisable | 1 | sepOn | 2 | 3; §\C{// turn on implicit separator for the next item}§
    36753688\end{cfa}
    36763689\begin{cfa}[showspaces=true,aboveskip=0pt,belowskip=0pt]
     
    36793692The tuple separator also responses to being turned on and off.
    36803693\begin{cfa}[belowskip=0pt]
    3681 sout | t1 | sepOff | t2; $\C{// turn off implicit separator for the next item}$
     3694sout | t1 | sepOff | t2; §\C{// turn off implicit separator for the next item}§
    36823695\end{cfa}
    36833696\begin{cfa}[showspaces=true,aboveskip=0pt,belowskip=0pt]
     
    36873700use ©sep© to accomplish this functionality.
    36883701\begin{cfa}[belowskip=0pt]
    3689 sout | sepOn | 1 | 2 | 3 | sepOn; $\C{// sepOn does nothing at start/end of line}$
     3702sout | sepOn | 1 | 2 | 3 | sepOn; §\C{// sepOn does nothing at start/end of line}§
    36903703\end{cfa}
    36913704\begin{cfa}[showspaces=true,aboveskip=0pt,belowskip=0pt]
     
    36933706\end{cfa}
    36943707\begin{cfa}[belowskip=0pt]
    3695 sout | sep | 1 | 2 | 3 | sep ; $\C{// use sep to print separator at start/end of line}$
     3708sout | sep | 1 | 2 | 3 | sep ; §\C{// use sep to print separator at start/end of line}§
    36963709\end{cfa}
    36973710\begin{cfa}[showspaces=true,aboveskip=0pt,belowskip=0pt]
    3698 @ @1 2 3@ @
     3711® ®1 2 3® ®
    36993712\end{cfa}
    37003713\end{enumerate}
     
    37083721\begin{enumerate}[parsep=0pt]
    37093722\item
    3710 \Indexc{nl}\index{manipulator!nl@©nl©} scans characters until the next newline character, \ie ignore the remaining characters in the line.
     3723\Indexc{nl}\index{manipulator!nl@©nl©} scans characters until the next newline character, i.e., ignore the remaining characters in the line.
    37113724\item
    37123725\Indexc{nlOn}\index{manipulator!nlOn@©nlOn©} reads the newline character, when reading single characters.
     
    37163729For example, in:
    37173730\begin{cfa}
    3718 sin | i | @nl@ | j;
    3719 1 @2@
     3731sin | i | ®nl® | j;
     37321 ®2®
    372037333
    37213734\end{cfa}
     
    37273740\Indexc{nl}\index{manipulator!nl@©nl©} inserts a newline.
    37283741\begin{cfa}
    3729 sout | nl; $\C{// only print newline}$
    3730 sout | 2; $\C{// implicit newline}$
    3731 sout | 3 | nl | 4 | nl; $\C{// terminating nl merged with implicit newline}$
    3732 sout | 5 | nl | nl; $\C{// again terminating nl merged with implicit newline}$
    3733 sout | 6; $\C{// implicit newline}$
     3742sout | nl; §\C{// only print newline}§
     3743sout | 2; §\C{// implicit newline}§
     3744sout | 3 | nl | 4 | nl; §\C{// terminating nl merged with implicit newline}§
     3745sout | 5 | nl | nl; §\C{// again terminating nl merged with implicit newline}§
     3746sout | 6; §\C{// implicit newline}§
    37343747
    373537482
     
    375837710b0 0b11011 0b11011 0b11011 0b11011
    37593772sout | bin( -27HH ) | bin( -27H ) | bin( -27 ) | bin( -27L );
    3760 0b11100101 0b1111111111100101 0b11111111111111111111111111100101 0b@(58 1s)@100101
     37730b11100101 0b1111111111100101 0b11111111111111111111111111100101 0b®(58 1s)®100101
    37613774\end{cfa}
    37623775
     
    37973810\begin{cfa}[belowskip=0pt]
    37983811sout | upcase( bin( 27 ) ) | upcase( hex( 27 ) ) | upcase( 27.5e-10 ) | upcase( hex( 27.5 ) );
    3799 0@B@11011 0@X@1@B@ 2.75@E@-09 0@X@1.@B@8@P@+4
     38120®B®11011 0®X®1®B® 2.75®E®-09 0®X®1.®B®8®P®+4
    38003813\end{cfa}
    38013814
     
    38133826\begin{cfa}[belowskip=0pt]
    38143827sout | 0. | nodp( 0. ) | 27.0 | nodp( 27.0 ) | nodp( 27.5 );
    3815 0.0 @0@ 27.0 @27@ 27.5
     38280.0 ®0® 27.0 ®27® 27.5
    38163829\end{cfa}
    38173830
     
    38203833\begin{cfa}[belowskip=0pt]
    38213834sout | sign( 27 ) | sign( -27 ) | sign( 27. ) | sign( -27. ) | sign( 27.5 ) | sign( -27.5 );
    3822 @+@27 -27 @+@27.0 -27.0 @+@27.5 -27.5
     3835®+®27 -27 ®+®27.0 -27.0 ®+®27.5 -27.5
    38233836\end{cfa}
    38243837
     
    38333846\end{cfa}
    38343847\begin{cfa}[showspaces=true,aboveskip=0pt,belowskip=0pt]
    3835 @  @34 @ @34 34
    3836 @  @4.000000 @ @4.000000 4.000000
    3837 @  @ab @ @ab ab
     3848®  ®34 ® ®34 34
     3849®  ®4.000000 ® ®4.000000 4.000000
     3850®  ®ab ® ®ab ab
    38383851\end{cfa}
    38393852If the value is larger, it is printed without truncation, ignoring the ©minimum©.
     
    38443857\end{cfa}
    38453858\begin{cfa}[showspaces=true,aboveskip=0pt,belowskip=0pt]
    3846 3456@7@ 345@67@ 34@567@
    3847 3456@.@ 345@6.@ 34@56.@
    3848 abcd@e@ abc@de@ ab@cde@
     38593456®7® 345®67® 34®567®
     38603456®.® 345®6.® 34®56.®
     3861abcd®e® abc®de® ab®cde®
    38493862\end{cfa}
    38503863
     
    38553868\end{cfa}
    38563869\begin{cfa}[showspaces=true,aboveskip=0pt,belowskip=0pt]
    3857  @0@34     @00@34 @00000000@34
     3870 ®0®34     ®00®34 ®00000000®34
    38583871\end{cfa}
    38593872If the value is larger, it is printed without truncation, ignoring the ©precision©.
     
    38703883\end{cfa}
    38713884\begin{cfa}[showspaces=true,aboveskip=0pt,belowskip=0pt]
    3872 @    @ @00000000@34
     3885®    ® ®00000000®34
    38733886\end{cfa}
    38743887For floating-point types, ©precision© is the minimum number of digits after the decimal point.
     
    38773890\end{cfa}
    38783891\begin{cfa}[showspaces=true,aboveskip=0pt,belowskip=0pt]
    3879 27.@500@     27.@5@      28. 27.@50000000@
    3880 \end{cfa}
    3881 For the C-string type, ©precision© is the maximum number of printed characters, so the string is truncated if it exceeds the maximum.
     389227.®500®     27.®5®      28. 27.®50000000®
     3893\end{cfa}
     3894For the C-string type, ©precision© is the maximum number of printed characters, so the string is truncared if it exceeds the maximum.
    38823895\begin{cfa}[belowskip=0pt]
    38833896sout | wd( 6,8, "abcd" ) | wd( 6,8, "abcdefghijk" ) | wd( 6,3, "abcd" );
     
    38953908\end{cfa}
    38963909\begin{cfa}[showspaces=true,aboveskip=0pt,belowskip=0pt]
    3897 234.567 234.5@7@  234.@6@    23@5@
     3910234.567 234.5®7®  234.®6®    23®5®
    38983911\end{cfa}
    38993912If a value's magnitude is greater than ©significant©, the value is printed in scientific notation with the specified number of significant digits.
     
    39023915\end{cfa}
    39033916\begin{cfa}[showspaces=true,aboveskip=0pt,belowskip=0pt]
    3904 234567. 2.3457@e+05@ 2.346@e+05@ 2.35@e+05@
     3917234567. 2.3457®e+05® 2.346®e+05® 2.35®e+05®
    39053918\end{cfa}
    39063919If ©significant© is greater than ©minimum©, it defines the number of printed characters.
     
    39183931\end{cfa}
    39193932\begin{cfa}[showspaces=true,aboveskip=0pt,belowskip=0pt]
    3920 27@  @ 27.000000  27.500000  027  27.500@    @
     393327®  ® 27.000000  27.500000  027  27.500®    ®
    39213934\end{cfa}
    39223935
     
    39253938\begin{cfa}[belowskip=0pt]
    39263939sout | pad0( wd( 4, 27 ) ) | pad0( wd( 4,3, 27 ) ) | pad0( wd( 8,3, 27.5 ) );
    3927 @00@27  @0@27 @00@27.500
     3940®00®27  ®0®27 ®00®27.500
    39283941\end{cfa}
    39293942\end{enumerate}
     
    40214034\end{cfa}
    40224035\begin{cfa}[showspaces=true,aboveskip=0pt,belowskip=0pt]
    4023 @abc   @
    4024 @abc  @
    4025 @xx@
     4036®abc   ®
     4037®abc  ®
     4038®xx®
    40264039\end{cfa}
    40274040
     
    40344047\end{cfa}
    40354048\begin{cfa}[showspaces=true,aboveskip=0pt,belowskip=0pt]
    4036 @abcd1233.456E+2@
     4049®abcd1233.456E+2®
    40374050\end{cfa}
    40384051Note, input ©wdi© cannot be overloaded with output ©wd© because both have the same parameters but return different types.
     
    40474060\end{cfa}
    40484061\begin{cfa}[showspaces=true,aboveskip=0pt,belowskip=0pt]
    4049 @  -75.35e-4@ 25
     4062®  -75.35e-4® 25
    40504063\end{cfa}
    40514064
     
    40594072\end{cfa}
    40604073\begin{cfa}[showspaces=true,aboveskip=0pt,belowskip=0pt]
    4061 @bca@xyz
     4074®bca®xyz
    40624075\end{cfa}
    40634076
     
    40714084\end{cfa}
    40724085\begin{cfa}[showspaces=true,aboveskip=0pt,belowskip=0pt]
    4073 @xyz@bca
     4086®xyz®bca
    40744087\end{cfa}
    40754088\end{enumerate}
     
    40884101
    40894102A type definition is different from a typedef in C because a typedef just creates an alias for a type,  while Do.s type definition creates a distinct type.
    4090 This means that users can define distinct function overloads for the new type \see{\VRef{s:Overloading} for more information}.
     4103This means that users can define distinct function overloads for the new type (see Overloading for more information).
    40914104For example:
    40924105
     
    41944207\CFA supports C initialization of structures, but it also adds constructors for more advanced initialization.
    41954208Additionally, \CFA adds destructors that are called when a variable is deallocated (variable goes out of scope or object is deleted).
    4196 These functions take a reference to the structure as a parameter \see{\VRef{s:PointerReference} for more information}.
     4209These functions take a reference to the structure as a parameter (see References for more information).
    41974210
    41984211\begin{figure}
     
    42454258
    42464259\section{Overloading}
    4247 \label{s:Overloading}
    42484260
    42494261Overloading refers to the capability of a programmer to define and use multiple objects in a program with the same name.
     
    42784290
    42794291
    4280 \subsection{Constant}
     4292\subsection{Overloaded Constant}
    42814293
    42824294The constants 0 and 1 have special meaning.
     
    43174329
    43184330
    4319 \subsection{Variable}
    4320 \label{s:VariableOverload}
     4331\subsection{Variable Overloading}
    43214332
    43224333The overload rules of \CFA allow a programmer to define multiple variables with the same name, but different types.
     
    43614372
    43624373
    4363 \subsection{Operator}
     4374\subsection{Operator Overloading}
    43644375
    43654376\CFA also allows operators to be overloaded, to simplify the use of user-defined types.
     
    44574468For example, given
    44584469\begin{cfa}
    4459 auto j = @...@
     4470auto j = ®...®
    44604471\end{cfa}
    44614472and the need to write a routine to compute using ©j©
    44624473\begin{cfa}
    4463 void rtn( @...@ parm );
     4474void rtn( ®...® parm );
    44644475rtn( j );
    44654476\end{cfa}
     
    47024713
    47034714coroutine Fibonacci {
    4704         int fn; $\C{// used for communication}$
     4715        int fn; §\C{// used for communication}§
    47054716};
    47064717void ?{}( Fibonacci * this ) {
     
    47084719}
    47094720void main( Fibonacci * this ) {
    4710         int fn1, fn2; $\C{// retained between resumes}$
    4711         this->fn = 0; $\C{// case 0}$
     4721        int fn1, fn2; §\C{// retained between resumes}§
     4722        this->fn = 0; §\C{// case 0}§
    47124723        fn1 = this->fn;
    4713         suspend(); $\C{// return to last resume}$
    4714 
    4715         this->fn = 1; $\C{// case 1}$
     4724        suspend(); §\C{// return to last resume}§
     4725
     4726        this->fn = 1; §\C{// case 1}§
    47164727        fn2 = fn1;
    47174728        fn1 = this->fn;
    4718         suspend(); $\C{// return to last resume}$
    4719 
    4720         for ( ;; ) { $\C{// general case}$
     4729        suspend(); §\C{// return to last resume}§
     4730
     4731        for ( ;; ) { §\C{// general case}§
    47214732                this->fn = fn1 + fn2;
    47224733                fn2 = fn1;
    47234734                fn1 = this->fn;
    4724                 suspend(); $\C{// return to last resume}$
     4735                suspend(); §\C{// return to last resume}§
    47254736        } // for
    47264737}
    47274738int next( Fibonacci * this ) {
    4728         resume( this ); $\C{// transfer to last suspend}$
     4739        resume( this ); §\C{// transfer to last suspend}§
    47294740        return this->fn;
    47304741}
     
    49534964When building a \CFA module which needs to be callable from C code, users can use the tools to generate a header file suitable for including in these C files with all of the needed declarations.
    49544965
    4955 In order to interoperate with existing C code, \CFA files can still include header files, the contents of which will be enclosed in a C linkage section to indicate C calling conventions \see{\VRef{s:Interoperability} for more information}.
     4966In order to interoperate with existing C code, \CFA files can still include header files, the contents of which will be enclosed in a C linkage section to indicate C calling conventions (see Interoperability for more information).
    49564967
    49574968
     
    56195630\end{cfa}
    56205631&
    5621 \begin{C++}
     5632\begin{lstlisting}[language=C++]
    56225633class Line {
    56235634        float lnth;
     
    56465657Line line1;
    56475658Line line2( 3.4 );
    5648 \end{C++}
     5659\end{lstlisting}
    56495660&
    56505661\begin{lstlisting}[language=Golang]
     
    62716282In \CFA, there are ambiguous cases with dereference and operator identifiers, \eg ©int *?*?()©, where the string ©*?*?© can be interpreted as:
    62726283\begin{cfa}
    6273 *?$\R{\textvisiblespace}$*? $\C{// dereference operator, dereference operator}$
    6274 *$\R{\textvisiblespace}$?*? $\C{// dereference, multiplication operator}$
     6284*?§\color{red}\textvisiblespace§*? §\C{// dereference operator, dereference operator}§
     6285*§\color{red}\textvisiblespace§?*? §\C{// dereference, multiplication operator}§
    62756286\end{cfa}
    62766287By default, the first interpretation is selected, which does not yield a meaningful parse.
     
    62816292The ambiguity occurs when the deference operator has no parameters:
    62826293\begin{cfa}
    6283 *?()$\R{\textvisiblespace...}$ ;
    6284 *?()$\R{\textvisiblespace...}$(...) ;
     6294*?()§\color{red}\textvisiblespace...§ ;
     6295*?()§\color{red}\textvisiblespace...§(...) ;
    62856296\end{cfa}
    62866297requiring arbitrary whitespace look-ahead for the routine-call parameter-list to disambiguate.
     
    62906301The remaining cases are with the increment/decrement operators and conditional expression, \eg:
    62916302\begin{cfa}
    6292 i++?$\R{\textvisiblespace...}$(...);
    6293 i?++$\R{\textvisiblespace...}$(...);
     6303i++?§\color{red}\textvisiblespace...§(...);
     6304i?++§\color{red}\textvisiblespace...§(...);
    62946305\end{cfa}
    62956306requiring arbitrary whitespace look-ahead for the operator parameter-list, even though that interpretation is an incorrect expression (juxtaposed identifiers).
    62966307Therefore, it is necessary to disambiguate these cases with a space:
    62976308\begin{cfa}
    6298 i++$\R{\textvisiblespace}$? i : 0;
    6299 i?$\R{\textvisiblespace}$++i : 0;
     6309i++§\color{red}\textvisiblespace§? i : 0;
     6310i?§\color{red}\textvisiblespace§++i : 0;
    63006311\end{cfa}
    63016312
     
    63106321\begin{description}
    63116322\item[Change:] add new keywords \\
    6312 New keywords are added to \CFA \see{\VRef{s:CFAKeywords}}.
     6323New keywords are added to \CFA (see~\VRef{s:CFAKeywords}).
    63136324\item[Rationale:] keywords added to implement new semantics of \CFA.
    63146325\item[Effect on original feature:] change to semantics of well-defined feature. \\
    63156326Any \Celeven programs using these keywords as identifiers are invalid \CFA programs.
    6316 \item[Difficulty of converting:] keyword clashes are accommodated by syntactic transformations using the \CFA backquote escape-mechanism \see{\VRef{s:BackquoteIdentifiers}}.
     6327\item[Difficulty of converting:] keyword clashes are accommodated by syntactic transformations using the \CFA backquote escape-mechanism (see~\VRef{s:BackquoteIdentifiers}).
    63176328\item[How widely used:] clashes among new \CFA keywords and existing identifiers are rare.
    63186329\end{description}
     
    63246335\eg:
    63256336\begin{cfa}
    6326 x; $\C{// int x}$
    6327 *y; $\C{// int *y}$
    6328 f( p1, p2 ); $\C{// int f( int p1, int p2 );}$
    6329 g( p1, p2 ) int p1, p2; $\C{// int g( int p1, int p2 );}$
     6337x; §\C{// int x}§
     6338*y; §\C{// int *y}§
     6339f( p1, p2 ); §\C{// int f( int p1, int p2 );}§
     6340g( p1, p2 ) int p1, p2; §\C{// int g( int p1, int p2 );}§
    63306341\end{cfa}
    63316342\CFA continues to support K\&R routine definitions:
    63326343\begin{cfa}
    6333 f( a, b, c ) $\C{// default int return}$
    6334         int a, b; char c $\C{// K\&R parameter declarations}$
     6344f( a, b, c ) §\C{// default int return}§
     6345        int a, b; char c §\C{// K\&R parameter declarations}§
    63356346{
    63366347        ...
     
    63516362int rtn( int i );
    63526363int rtn( char c );
    6353 rtn( 'x' ); $\C{// programmer expects 2nd rtn to be called}$
     6364rtn( 'x' ); §\C{// programmer expects 2nd rtn to be called}§
    63546365\end{cfa}
    63556366\item[Rationale:] it is more intuitive for the call to ©rtn© to match the second version of definition of ©rtn© rather than the first.
     
    63736384\item[Change:] make string literals ©const©:
    63746385\begin{cfa}
    6375 char * p = "abc"; $\C{// valid in C, deprecated in \CFA}$
    6376 char * q = expr ? "abc" : "de"; $\C{// valid in C, invalid in \CFA}$
     6386char * p = "abc"; §\C{// valid in C, deprecated in \CFA}§
     6387char * q = expr ? "abc" : "de"; §\C{// valid in C, invalid in \CFA}§
    63776388\end{cfa}
    63786389The type of a string literal is changed from ©[] char© to ©const [] char©.
     
    63816392\begin{cfa}
    63826393char * p = "abc";
    6383 p[0] = 'w'; $\C{// segment fault or change constant literal}$
     6394p[0] = 'w'; §\C{// segment fault or change constant literal}§
    63846395\end{cfa}
    63856396The same problem occurs when passing a string literal to a routine that changes its argument.
     
    63936404\item[Change:] remove \newterm{tentative definitions}, which only occurs at file scope:
    63946405\begin{cfa}
    6395 int i; $\C{// forward definition}$
    6396 int *j = @&i@; $\C{// forward reference, valid in C, invalid in \CFA}$
    6397 int i = 0; $\C{// definition}$
     6406int i; §\C{// forward definition}§
     6407int *j = ®&i®; §\C{// forward reference, valid in C, invalid in \CFA}§
     6408int i = 0; §\C{// definition}§
    63986409\end{cfa}
    63996410is valid in C, and invalid in \CFA because duplicate overloaded object definitions at the same scope level are disallowed.
     
    64016412\begin{cfa}
    64026413struct X { int i; struct X *next; };
    6403 static struct X a; $\C{// forward definition}$
    6404 static struct X b = { 0, @&a@ };$\C{// forward reference, valid in C, invalid in \CFA}$
    6405 static struct X a = { 1, &b }; $\C{// definition}$
     6414static struct X a; §\C{// forward definition}§
     6415static struct X b = { 0, ®&a® };§\C{// forward reference, valid in C, invalid in \CFA}§
     6416static struct X a = { 1, &b }; §\C{// definition}§
    64066417\end{cfa}
    64076418\item[Rationale:] avoids having different initialization rules for builtin types and user-defined types.
     
    64156426\item[Change:] have ©struct© introduce a scope for nested types:
    64166427\begin{cfa}
    6417 enum @Colour@ { R, G, B, Y, C, M };
     6428enum ®Colour® { R, G, B, Y, C, M };
    64186429struct Person {
    6419         enum @Colour@ { R, G, B };      $\C[7cm]{// nested type}$
    6420         struct Face { $\C{// nested type}$
    6421                 @Colour@ Eyes, Hair; $\C{// type defined outside (1 level)}$
     6430        enum ®Colour® { R, G, B };      §\C[7cm]{// nested type}§
     6431        struct Face { §\C{// nested type}§
     6432                ®Colour® Eyes, Hair; §\C{// type defined outside (1 level)}§
    64226433        };
    6423         @.Colour@ shirt; $\C{// type defined outside (top level)}$
    6424         @Colour@ pants; $\C{// type defined same level}$
    6425         Face looks[10]; $\C{// type defined same level}$
     6434        ®.Colour® shirt; §\C{// type defined outside (top level)}§
     6435        ®Colour® pants; §\C{// type defined same level}§
     6436        Face looks[10]; §\C{// type defined same level}§
    64266437};
    6427 @Colour@ c = R; $\C{// type/enum defined same level}$
    6428 Person@.Colour@ pc = Person@.@R;$\C{// type/enum defined inside}$
    6429 Person@.@Face pretty; $\C{// type defined inside}\CRT$
     6438®Colour® c = R; §\C{// type/enum defined same level}§
     6439Person®.Colour® pc = Person®.®R;§\C{// type/enum defined inside}§
     6440Person®.®Face pretty; §\C{// type defined inside}\CRT§
    64306441\end{cfa}
    64316442In C, the name of the nested types belongs to the same scope as the name of the outermost enclosing structure, \ie the nested types are hoisted to the scope of the outer-most type, which is not useful and confusing.
     
    64446455\item[Difficulty of converting:] Semantic transformation. To make the struct type name visible in the scope of the enclosing struct, the struct tag could be declared in the scope of the enclosing struct, before the enclosing struct is defined. Example:
    64456456\begin{cfa}
    6446 struct Y; $\C{// struct Y and struct X are at the same scope}$
     6457struct Y; §\C{// struct Y and struct X are at the same scope}§
    64476458struct X {
    64486459        struct Y { /* ... */ } y;
     
    64596470\begin{cfa}
    64606471void foo() {
    6461         int * b = malloc( sizeof(int) ); $\C{// implicitly convert void * to int *}$
    6462         char * c = b; $\C{// implicitly convert int * to void *, and then void * to char *}$
     6472        int * b = malloc( sizeof(int) ); §\C{// implicitly convert void * to int *}§
     6473        char * c = b; §\C{// implicitly convert int * to void *, and then void * to char *}§
    64636474}
    64646475\end{cfa}
    64656476\item[Rationale:] increase type safety
    64666477\item[Effect on original feature:] deletion of semantically well-defined feature.
    6467 \item[Difficulty of converting:] requires adding a cast \see{\VRef{s:StorageManagement} for better alternatives}:
     6478\item[Difficulty of converting:] requires adding a cast (see \VRef{s:StorageManagement} for better alternatives):
    64686479\begin{cfa}
    64696480        int * b = (int *)malloc( sizeof(int) );
     
    65756586\end{cquote}
    65766587For the prescribed head-files, \CFA uses header interposition to wraps these includes in an ©extern "C"©;
    6577 hence, names in these include files are not mangled\index{mangling!name} \see{\VRef{s:Interoperability}}.
     6588hence, names in these include files are not mangled\index{mangling!name} (see~\VRef{s:Interoperability}).
    65786589All other C header files must be explicitly wrapped in ©extern "C"© to prevent name mangling.
    65796590This approach is different from \Index*[C++]{\CC{}} where the name-mangling issue is handled internally in C header-files through checks for preprocessor variable ©__cplusplus©, which adds appropriate ©extern "C"© qualifiers.
     
    66386649Type-safe allocation is provided for all C allocation routines and new \CFA allocation routines, \eg in
    66396650\begin{cfa}
    6640 int * ip = (int *)malloc( sizeof(int) );                $\C{// C}$
    6641 int * ip = malloc();                                                    $\C{// \CFA type-safe version of C malloc}$
    6642 int * ip = alloc();                                                             $\C{// \CFA type-safe uniform alloc}$
     6651int * ip = (int *)malloc( sizeof(int) );                §\C{// C}§
     6652int * ip = malloc();                                                    §\C{// \CFA type-safe version of C malloc}§
     6653int * ip = alloc();                                                             §\C{// \CFA type-safe uniform alloc}§
    66436654\end{cfa}
    66446655the latter two allocations determine the allocation size from the type of ©p© (©int©) and cast the pointer to the allocated storage to ©int *©.
     
    66476658\begin{cfa}
    66486659struct S { int i; } __attribute__(( aligned( 128 ) )); // cache-line alignment
    6649 S * sp = malloc();                                                              $\C{// honour type alignment}$
     6660S * sp = malloc();                                                              §\C{// honour type alignment}§
    66506661\end{cfa}
    66516662the storage allocation is implicitly aligned to 128 rather than the default 16.
     
    66626673\CFA memory management extends allocation to support constructors for initialization of allocated storage, \eg in
    66636674\begin{cfa}
    6664 struct S { int i; };                                                    $\C{// cache-line alignment}$
     6675struct S { int i; };                                                    §\C{// cache-line aglinment}§
    66656676void ?{}( S & s, int i ) { s.i = i; }
    66666677// assume ?|? operator for printing an S
    66676678
    6668 S & sp = *@new@( 3 );                                                   $\C{// call constructor after allocation}$
     6679S & sp = *®new®( 3 );                                                   §\C{// call constructor after allocation}§
    66696680sout | sp.i;
    6670 @delete@( &sp );
    6671 
    6672 S * spa = @anew@( 10, 5 );                                              $\C{// allocate array and initialize each array element}$
     6681®delete®( &sp );
     6682
     6683S * spa = ®anew®( 10, 5 );                                              §\C{// allocate array and initialize each array element}§
    66736684for ( i; 10 ) sout | spa[i] | nonl;
    66746685sout | nl;
    6675 @adelete@( 10, spa );
     6686®adelete®( 10, spa );
    66766687\end{cfa}
    66776688Allocation routines ©new©/©anew© allocate a variable/array and initialize storage using the allocated type's constructor.
     
    66826693extern "C" {
    66836694        // C unsafe allocation
    6684         void * malloc( size_t size );$\indexc{malloc}$
    6685         void * calloc( size_t dim, size_t size );$\indexc{calloc}$
    6686         void * realloc( void * ptr, size_t size );$\indexc{realloc}$
    6687         void * memalign( size_t align, size_t size );$\indexc{memalign}$
    6688         void * aligned_alloc( size_t align, size_t size );$\indexc{aligned_alloc}$
    6689         int posix_memalign( void ** ptr, size_t align, size_t size );$\indexc{posix_memalign}$
    6690         void * cmemalign( size_t alignment, size_t noOfElems, size_t elemSize );$\indexc{cmemalign}$ // CFA
     6695        void * malloc( size_t size );§\indexc{malloc}§
     6696        void * calloc( size_t dim, size_t size );§\indexc{calloc}§
     6697        void * realloc( void * ptr, size_t size );§\indexc{realloc}§
     6698        void * memalign( size_t align, size_t size );§\indexc{memalign}§
     6699        void * aligned_alloc( size_t align, size_t size );§\indexc{aligned_alloc}§
     6700        int posix_memalign( void ** ptr, size_t align, size_t size );§\indexc{posix_memalign}§
     6701        void * cmemalign( size_t alignment, size_t noOfElems, size_t elemSize );§\indexc{cmemalign}§ // CFA
    66916702
    66926703        // C unsafe initialization/copy
    6693         void * memset( void * dest, int c, size_t size );$\indexc{memset}$
    6694         void * memcpy( void * dest, const void * src, size_t size );$\indexc{memcpy}$
     6704        void * memset( void * dest, int c, size_t size );§\indexc{memset}§
     6705        void * memcpy( void * dest, const void * src, size_t size );§\indexc{memcpy}§
    66956706}
    66966707
     
    66986709
    66996710forall( dtype T | sized(T) ) {
    6700         // $\CFA$ safe equivalents, i.e., implicit size specification
     6711        // §\CFA§ safe equivalents, i.e., implicit size specification
    67016712        T * malloc( void );
    67026713        T * calloc( size_t dim );
     
    67076718        int posix_memalign( T ** ptr, size_t align );
    67086719
    6709         // $\CFA$ safe general allocation, fill, resize, alignment, array
    6710         T * alloc( void );$\indexc{alloc}$                                      $\C[3.5in]{// variable, T size}$
    6711         T * alloc( size_t dim );                                                        $\C{// array[dim], T size elements}$
    6712         T * alloc( T ptr[], size_t dim );                                       $\C{// realloc array[dim], T size elements}$
    6713 
    6714         T * alloc_set( char fill );$\indexc{alloc_set}$         $\C{// variable, T size, fill bytes with value}$
    6715         T * alloc_set( T fill );                                                        $\C{// variable, T size, fill with value}$
    6716         T * alloc_set( size_t dim, char fill );                         $\C{// array[dim], T size elements, fill bytes with value}$
    6717         T * alloc_set( size_t dim, T fill );                            $\C{// array[dim], T size elements, fill elements with value}$
    6718         T * alloc_set( size_t dim, const T fill[] );            $\C{// array[dim], T size elements, fill elements with array}$
    6719         T * alloc_set( T ptr[], size_t dim, char fill );        $\C{// realloc array[dim], T size elements, fill bytes with value}$
    6720 
    6721         T * alloc_align( size_t align );                                        $\C{// aligned variable, T size}$
    6722         T * alloc_align( size_t align, size_t dim );            $\C{// aligned array[dim], T size elements}$
    6723         T * alloc_align( T ptr[], size_t align );                       $\C{// realloc new aligned array}$
    6724         T * alloc_align( T ptr[], size_t align, size_t dim ); $\C{// realloc new aligned array[dim]}$
    6725 
    6726         T * alloc_align_set( size_t align, char fill );         $\C{// aligned variable, T size, fill bytes with value}$
    6727         T * alloc_align_set( size_t align, T fill );            $\C{// aligned variable, T size, fill with value}$
    6728         T * alloc_align_set( size_t align, size_t dim, char fill ); $\C{// aligned array[dim], T size elements, fill bytes with value}$
    6729         T * alloc_align_set( size_t align, size_t dim, T fill ); $\C{// aligned array[dim], T size elements, fill elements with value}$
    6730         T * alloc_align_set( size_t align, size_t dim, const T fill[] ); $\C{// aligned array[dim], T size elements, fill elements with array}$
    6731         T * alloc_align_set( T ptr[], size_t align, size_t dim, char fill ); $\C{// realloc new aligned array[dim], fill new bytes with value}$
    6732 
    6733         // $\CFA$ safe initialization/copy, i.e., implicit size specification
    6734         T * memset( T * dest, char fill );$\indexc{memset}$
    6735         T * memcpy( T * dest, const T * src );$\indexc{memcpy}$
    6736 
    6737         // $\CFA$ safe initialization/copy, i.e., implicit size specification, array types
     6720        // §\CFA§ safe general allocation, fill, resize, alignment, array
     6721        T * alloc( void );§\indexc{alloc}§                                      §\C[3.5in]{// variable, T size}§
     6722        T * alloc( size_t dim );                                                        §\C{// array[dim], T size elements}§
     6723        T * alloc( T ptr[], size_t dim );                                       §\C{// realloc array[dim], T size elements}§
     6724
     6725        T * alloc_set( char fill );§\indexc{alloc_set}§         §\C{// variable, T size, fill bytes with value}§
     6726        T * alloc_set( T fill );                                                        §\C{// variable, T size, fill with value}§
     6727        T * alloc_set( size_t dim, char fill );                         §\C{// array[dim], T size elements, fill bytes with value}§
     6728        T * alloc_set( size_t dim, T fill );                            §\C{// array[dim], T size elements, fill elements with value}§
     6729        T * alloc_set( size_t dim, const T fill[] );            §\C{// array[dim], T size elements, fill elements with array}§
     6730        T * alloc_set( T ptr[], size_t dim, char fill );        §\C{// realloc array[dim], T size elements, fill bytes with value}§
     6731
     6732        T * alloc_align( size_t align );                                        §\C{// aligned variable, T size}§
     6733        T * alloc_align( size_t align, size_t dim );            §\C{// aligned array[dim], T size elements}§
     6734        T * alloc_align( T ptr[], size_t align );                       §\C{// realloc new aligned array}§
     6735        T * alloc_align( T ptr[], size_t align, size_t dim ); §\C{// realloc new aligned array[dim]}§
     6736
     6737        T * alloc_align_set( size_t align, char fill );         §\C{// aligned variable, T size, fill bytes with value}§
     6738        T * alloc_align_set( size_t align, T fill );            §\C{// aligned variable, T size, fill with value}§
     6739        T * alloc_align_set( size_t align, size_t dim, char fill ); §\C{// aligned array[dim], T size elements, fill bytes with value}§
     6740        T * alloc_align_set( size_t align, size_t dim, T fill ); §\C{// aligned array[dim], T size elements, fill elements with value}§
     6741        T * alloc_align_set( size_t align, size_t dim, const T fill[] ); §\C{// aligned array[dim], T size elements, fill elements with array}§
     6742        T * alloc_align_set( T ptr[], size_t align, size_t dim, char fill ); §\C{// realloc new aligned array[dim], fill new bytes with value}§
     6743
     6744        // §\CFA§ safe initialization/copy, i.e., implicit size specification
     6745        T * memset( T * dest, char fill );§\indexc{memset}§
     6746        T * memcpy( T * dest, const T * src );§\indexc{memcpy}§
     6747
     6748        // §\CFA§ safe initialization/copy, i.e., implicit size specification, array types
    67386749        T * amemset( T dest[], char fill, size_t dim );
    67396750        T * amemcpy( T dest[], const T src[], size_t dim );
    67406751}
    67416752
    6742 // $\CFA$ allocation/deallocation and constructor/destructor, non-array types
    6743 forall( dtype T | sized(T), ttype Params | { void ?{}( T &, Params ); } ) T * new( Params p );$\indexc{new}$
    6744 forall( dtype T | sized(T) | { void ^?{}( T & ); } ) void delete( T * ptr );$\indexc{delete}$
     6753// §\CFA§ allocation/deallocation and constructor/destructor, non-array types
     6754forall( dtype T | sized(T), ttype Params | { void ?{}( T &, Params ); } ) T * new( Params p );§\indexc{new}§
     6755forall( dtype T | sized(T) | { void ^?{}( T & ); } ) void delete( T * ptr );§\indexc{delete}§
    67456756forall( dtype T, ttype Params | sized(T) | { void ^?{}( T & ); void delete( Params ); } )
    67466757  void delete( T * ptr, Params rest );
    67476758
    6748 // $\CFA$ allocation/deallocation and constructor/destructor, array types
    6749 forall( dtype T | sized(T), ttype Params | { void ?{}( T &, Params ); } ) T * anew( size_t dim, Params p );$\indexc{anew}$
    6750 forall( dtype T | sized(T) | { void ^?{}( T & ); } ) void adelete( size_t dim, T arr[] );$\indexc{adelete}$
     6759// §\CFA§ allocation/deallocation and constructor/destructor, array types
     6760forall( dtype T | sized(T), ttype Params | { void ?{}( T &, Params ); } ) T * anew( size_t dim, Params p );§\indexc{anew}§
     6761forall( dtype T | sized(T) | { void ^?{}( T & ); } ) void adelete( size_t dim, T arr[] );§\indexc{adelete}§
    67516762forall( dtype T | sized(T) | { void ^?{}( T & ); }, ttype Params | { void adelete( Params ); } )
    67526763  void adelete( size_t dim, T arr[], Params rest );
     
    67586769\leavevmode
    67596770\begin{cfa}[aboveskip=0pt,belowskip=0pt]
    6760 int ato( const char * ptr );$\indexc{ato}$
     6771int ato( const char * ptr );§\indexc{ato}§
    67616772unsigned int ato( const char * ptr );
    67626773long int ato( const char * ptr );
     
    67906801\leavevmode
    67916802\begin{cfa}[aboveskip=0pt,belowskip=0pt]
    6792 forall( otype T | { int ?<?( T, T ); } ) $\C{// location}$
    6793 T * bsearch( T key, const T * arr, size_t dim );$\indexc{bsearch}$
    6794 
    6795 forall( otype T | { int ?<?( T, T ); } ) $\C{// position}$
     6803forall( otype T | { int ?<?( T, T ); } ) §\C{// location}§
     6804T * bsearch( T key, const T * arr, size_t dim );§\indexc{bsearch}§
     6805
     6806forall( otype T | { int ?<?( T, T ); } ) §\C{// position}§
    67966807unsigned int bsearch( T key, const T * arr, size_t dim );
    67976808
    67986809forall( otype T | { int ?<?( T, T ); } )
    6799 void qsort( const T * arr, size_t dim );$\indexc{qsort}$
     6810void qsort( const T * arr, size_t dim );§\indexc{qsort}§
    68006811
    68016812forall( otype E | { int ?<?( E, E ); } ) {
    6802         E * bsearch( E key, const E * vals, size_t dim );$\indexc{bsearch}$ $\C{// location}$
    6803         size_t bsearch( E key, const E * vals, size_t dim );$\C{// position}$
    6804         E * bsearchl( E key, const E * vals, size_t dim );$\indexc{bsearchl}$
     6813        E * bsearch( E key, const E * vals, size_t dim );§\indexc{bsearch}§ §\C{// location}§
     6814        size_t bsearch( E key, const E * vals, size_t dim );§\C{// position}§
     6815        E * bsearchl( E key, const E * vals, size_t dim );§\indexc{bsearchl}§
    68056816        size_t bsearchl( E key, const E * vals, size_t dim );
    6806         E * bsearchu( E key, const E * vals, size_t dim );$\indexc{bsearchu}$
     6817        E * bsearchu( E key, const E * vals, size_t dim );§\indexc{bsearchu}§
    68076818        size_t bsearchu( E key, const E * vals, size_t dim );
    68086819}
     
    68186829
    68196830forall( otype E | { int ?<?( E, E ); } ) {
    6820         void qsort( E * vals, size_t dim );$\indexc{qsort}$
     6831        void qsort( E * vals, size_t dim );§\indexc{qsort}§
    68216832}
    68226833\end{cfa}
     
    68276838\leavevmode
    68286839\begin{cfa}[aboveskip=0pt,belowskip=0pt]
    6829 unsigned char abs( signed char );$\indexc{abs}$
     6840unsigned char abs( signed char );§\indexc{abs}§
    68306841int abs( int );
    68316842unsigned long int abs( long int );
     
    68466857\leavevmode
    68476858\begin{cfa}[aboveskip=0pt,belowskip=0pt]
    6848 void srandom( unsigned int seed );$\indexc{srandom}$
    6849 char random( void );$\indexc{random}$
    6850 char random( char u ); $\C{// [0,u)}$
    6851 char random( char l, char u ); $\C{// [l,u)}$
     6859void srandom( unsigned int seed );§\indexc{srandom}§
     6860char random( void );§\indexc{random}§
     6861char random( char u ); §\C{// [0,u)}§
     6862char random( char l, char u ); §\C{// [l,u)}§
    68526863int random( void );
    6853 int random( int u ); $\C{// [0,u)}$
    6854 int random( int l, int u ); $\C{// [l,u)}$
     6864int random( int u ); §\C{// [0,u)}§
     6865int random( int l, int u ); §\C{// [l,u)}§
    68556866unsigned int random( void );
    6856 unsigned int random( unsigned int u ); $\C{// [0,u)}$
    6857 unsigned int random( unsigned int l, unsigned int u ); $\C{// [l,u)}$
     6867unsigned int random( unsigned int u ); §\C{// [0,u)}§
     6868unsigned int random( unsigned int l, unsigned int u ); §\C{// [l,u)}§
    68586869long int random( void );
    6859 long int random( long int u ); $\C{// [0,u)}$
    6860 long int random( long int l, long int u ); $\C{// [l,u)}$
     6870long int random( long int u ); §\C{// [0,u)}§
     6871long int random( long int l, long int u ); §\C{// [l,u)}§
    68616872unsigned long int random( void );
    6862 unsigned long int random( unsigned long int u ); $\C{// [0,u)}$
    6863 unsigned long int random( unsigned long int l, unsigned long int u ); $\C{// [l,u)}$
    6864 float random( void );                                            $\C{// [0.0, 1.0)}$
    6865 double random( void );                                           $\C{// [0.0, 1.0)}$
    6866 float _Complex random( void );                           $\C{// [0.0, 1.0)+[0.0, 1.0)i}$
    6867 double _Complex random( void );                          $\C{// [0.0, 1.0)+[0.0, 1.0)i}$
    6868 long double _Complex random( void );             $\C{// [0.0, 1.0)+[0.0, 1.0)i}$
     6873unsigned long int random( unsigned long int u ); §\C{// [0,u)}§
     6874unsigned long int random( unsigned long int l, unsigned long int u ); §\C{// [l,u)}§
     6875float random( void );                                            §\C{// [0.0, 1.0)}§
     6876double random( void );                                           §\C{// [0.0, 1.0)}§
     6877float _Complex random( void );                           §\C{// [0.0, 1.0)+[0.0, 1.0)i}§
     6878double _Complex random( void );                          §\C{// [0.0, 1.0)+[0.0, 1.0)i}§
     6879long double _Complex random( void );             §\C{// [0.0, 1.0)+[0.0, 1.0)i}§
    68696880\end{cfa}
    68706881
     
    68746885\leavevmode
    68756886\begin{cfa}[aboveskip=0pt,belowskip=0pt]
    6876 forall( otype T | { int ?<?( T, T ); } ) T min( T t1, T t2 );$\indexc{min}$
    6877 forall( otype T | { int ?>?( T, T ); } ) T max( T t1, T t2 );$\indexc{max}$
    6878 forall( otype T | { T min( T, T ); T max( T, T ); } ) T clamp( T value, T min_val, T max_val );$\indexc{clamp}$
    6879 forall( otype T ) void swap( T * t1, T * t2 );$\indexc{swap}$
     6887forall( otype T | { int ?<?( T, T ); } ) T min( T t1, T t2 );§\indexc{min}§
     6888forall( otype T | { int ?>?( T, T ); } ) T max( T t1, T t2 );§\indexc{max}§
     6889forall( otype T | { T min( T, T ); T max( T, T ); } ) T clamp( T value, T min_val, T max_val );§\indexc{clamp}§
     6890forall( otype T ) void swap( T * t1, T * t2 );§\indexc{swap}§
    68806891\end{cfa}
    68816892
     
    68916902\leavevmode
    68926903\begin{cfa}[aboveskip=0pt,belowskip=0pt]
    6893 float ?%?( float, float );$\indexc{fmod}$
     6904float ?%?( float, float );§\indexc{fmod}§
    68946905float fmod( float, float );
    68956906double ?%?( double, double );
     
    68986909long double fmod( long double, long double );
    68996910
    6900 float remainder( float, float );$\indexc{remainder}$
     6911float remainder( float, float );§\indexc{remainder}§
    69016912double remainder( double, double );
    69026913long double remainder( long double, long double );
    69036914
    6904 float remquo( float, float, int * );$\indexc{remquo}$
     6915float remquo( float, float, int * );§\indexc{remquo}§
    69056916double remquo( double, double, int * );
    69066917long double remquo( long double, long double, int * );
     
    69096920[ int, long double ] remquo( long double, long double );
    69106921
    6911 float div( float, float, int * );$\indexc{div}$ $\C{// alternative name for remquo}$
     6922float div( float, float, int * );§\indexc{div}§ §\C{// alternative name for remquo}§
    69126923double div( double, double, int * );
    69136924long double div( long double, long double, int * );
     
    69166927[ int, long double ] div( long double, long double );
    69176928
    6918 float fma( float, float, float );$\indexc{fma}$
     6929float fma( float, float, float );§\indexc{fma}§
    69196930double fma( double, double, double );
    69206931long double fma( long double, long double, long double );
    69216932
    6922 float fdim( float, float );$\indexc{fdim}$
     6933float fdim( float, float );§\indexc{fdim}§
    69236934double fdim( double, double );
    69246935long double fdim( long double, long double );
    69256936
    6926 float nan( const char * );$\indexc{nan}$
     6937float nan( const char * );§\indexc{nan}§
    69276938double nan( const char * );
    69286939long double nan( const char * );
     
    69346945\leavevmode
    69356946\begin{cfa}[aboveskip=0pt,belowskip=0pt]
    6936 float exp( float );$\indexc{exp}$
     6947float exp( float );§\indexc{exp}§
    69376948double exp( double );
    69386949long double exp( long double );
     
    69416952long double _Complex exp( long double _Complex );
    69426953
    6943 float exp2( float );$\indexc{exp2}$
     6954float exp2( float );§\indexc{exp2}§
    69446955double exp2( double );
    69456956long double exp2( long double );
     
    69486959// long double _Complex exp2( long double _Complex );
    69496960
    6950 float expm1( float );$\indexc{expm1}$
     6961float expm1( float );§\indexc{expm1}§
    69516962double expm1( double );
    69526963long double expm1( long double );
    69536964
    6954 float pow( float, float );$\indexc{pow}$
     6965float pow( float, float );§\indexc{pow}§
    69556966double pow( double, double );
    69566967long double pow( long double, long double );
     
    69656976\leavevmode
    69666977\begin{cfa}[aboveskip=0pt,belowskip=0pt]
    6967 float log( float );$\indexc{log}$
     6978float log( float );§\indexc{log}§
    69686979double log( double );
    69696980long double log( long double );
     
    69726983long double _Complex log( long double _Complex );
    69736984
    6974 float log2( float );$\indexc{log2}$
     6985float log2( float );§\indexc{log2}§
    69756986double log2( double );
    69766987long double log2( long double );
     
    69796990// long double _Complex log2( long double _Complex );
    69806991
    6981 float log10( float );$\indexc{log10}$
     6992float log10( float );§\indexc{log10}§
    69826993double log10( double );
    69836994long double log10( long double );
     
    69866997// long double _Complex log10( long double _Complex );
    69876998
    6988 float log1p( float );$\indexc{log1p}$
     6999float log1p( float );§\indexc{log1p}§
    69897000double log1p( double );
    69907001long double log1p( long double );
    69917002
    6992 int ilogb( float );$\indexc{ilogb}$
     7003int ilogb( float );§\indexc{ilogb}§
    69937004int ilogb( double );
    69947005int ilogb( long double );
    69957006
    6996 float logb( float );$\indexc{logb}$
     7007float logb( float );§\indexc{logb}§
    69977008double logb( double );
    69987009long double logb( long double );
    69997010
    7000 float sqrt( float );$\indexc{sqrt}$
     7011float sqrt( float );§\indexc{sqrt}§
    70017012double sqrt( double );
    70027013long double sqrt( long double );
     
    70057016long double _Complex sqrt( long double _Complex );
    70067017
    7007 float cbrt( float );$\indexc{cbrt}$
     7018float cbrt( float );§\indexc{cbrt}§
    70087019double cbrt( double );
    70097020long double cbrt( long double );
    70107021
    7011 float hypot( float, float );$\indexc{hypot}$
     7022float hypot( float, float );§\indexc{hypot}§
    70127023double hypot( double, double );
    70137024long double hypot( long double, long double );
     
    70197030\leavevmode
    70207031\begin{cfa}[aboveskip=0pt,belowskip=0pt]
    7021 float sin( float );$\indexc{sin}$
     7032float sin( float );§\indexc{sin}§
    70227033double sin( double );
    70237034long double sin( long double );
     
    70267037long double _Complex sin( long double _Complex );
    70277038
    7028 float cos( float );$\indexc{cos}$
     7039float cos( float );§\indexc{cos}§
    70297040double cos( double );
    70307041long double cos( long double );
     
    70337044long double _Complex cos( long double _Complex );
    70347045
    7035 float tan( float );$\indexc{tan}$
     7046float tan( float );§\indexc{tan}§
    70367047double tan( double );
    70377048long double tan( long double );
     
    70407051long double _Complex tan( long double _Complex );
    70417052
    7042 float asin( float );$\indexc{asin}$
     7053float asin( float );§\indexc{asin}§
    70437054double asin( double );
    70447055long double asin( long double );
     
    70477058long double _Complex asin( long double _Complex );
    70487059
    7049 float acos( float );$\indexc{acos}$
     7060float acos( float );§\indexc{acos}§
    70507061double acos( double );
    70517062long double acos( long double );
     
    70547065long double _Complex acos( long double _Complex );
    70557066
    7056 float atan( float );$\indexc{atan}$
     7067float atan( float );§\indexc{atan}§
    70577068double atan( double );
    70587069long double atan( long double );
     
    70617072long double _Complex atan( long double _Complex );
    70627073
    7063 float atan2( float, float );$\indexc{atan2}$
     7074float atan2( float, float );§\indexc{atan2}§
    70647075double atan2( double, double );
    70657076long double atan2( long double, long double );
    70667077
    7067 float atan( float, float ); $\C{// alternative name for atan2}$
    7068 double atan( double, double );$\indexc{atan}$
     7078float atan( float, float ); §\C{// alternative name for atan2}§
     7079double atan( double, double );§\indexc{atan}§
    70697080long double atan( long double, long double );
    70707081\end{cfa}
     
    70757086\leavevmode
    70767087\begin{cfa}[aboveskip=0pt,belowskip=0pt]
    7077 float sinh( float );$\indexc{sinh}$
     7088float sinh( float );§\indexc{sinh}§
    70787089double sinh( double );
    70797090long double sinh( long double );
     
    70827093long double _Complex sinh( long double _Complex );
    70837094
    7084 float cosh( float );$\indexc{cosh}$
     7095float cosh( float );§\indexc{cosh}§
    70857096double cosh( double );
    70867097long double cosh( long double );
     
    70897100long double _Complex cosh( long double _Complex );
    70907101
    7091 float tanh( float );$\indexc{tanh}$
     7102float tanh( float );§\indexc{tanh}§
    70927103double tanh( double );
    70937104long double tanh( long double );
     
    70967107long double _Complex tanh( long double _Complex );
    70977108
    7098 float asinh( float );$\indexc{asinh}$
     7109float asinh( float );§\indexc{asinh}§
    70997110double asinh( double );
    71007111long double asinh( long double );
     
    71037114long double _Complex asinh( long double _Complex );
    71047115
    7105 float acosh( float );$\indexc{acosh}$
     7116float acosh( float );§\indexc{acosh}§
    71067117double acosh( double );
    71077118long double acosh( long double );
     
    71107121long double _Complex acosh( long double _Complex );
    71117122
    7112 float atanh( float );$\indexc{atanh}$
     7123float atanh( float );§\indexc{atanh}§
    71137124double atanh( double );
    71147125long double atanh( long double );
     
    71237134\leavevmode
    71247135\begin{cfa}[aboveskip=0pt,belowskip=0pt]
    7125 float erf( float );$\indexc{erf}$
     7136float erf( float );§\indexc{erf}§
    71267137double erf( double );
    71277138long double erf( long double );
     
    71307141long double _Complex erf( long double _Complex );
    71317142
    7132 float erfc( float );$\indexc{erfc}$
     7143float erfc( float );§\indexc{erfc}§
    71337144double erfc( double );
    71347145long double erfc( long double );
     
    71377148long double _Complex erfc( long double _Complex );
    71387149
    7139 float lgamma( float );$\indexc{lgamma}$
     7150float lgamma( float );§\indexc{lgamma}§
    71407151double lgamma( double );
    71417152long double lgamma( long double );
     
    71447155long double lgamma( long double, int * );
    71457156
    7146 float tgamma( float );$\indexc{tgamma}$
     7157float tgamma( float );§\indexc{tgamma}§
    71477158double tgamma( double );
    71487159long double tgamma( long double );
     
    71547165\leavevmode
    71557166\begin{cfa}[aboveskip=0pt,belowskip=0pt]
    7156 float floor( float );$\indexc{floor}$
     7167float floor( float );§\indexc{floor}§
    71577168double floor( double );
    71587169long double floor( long double );
    71597170
    7160 float ceil( float );$\indexc{ceil}$
     7171float ceil( float );§\indexc{ceil}§
    71617172double ceil( double );
    71627173long double ceil( long double );
    71637174
    7164 float trunc( float );$\indexc{trunc}$
     7175float trunc( float );§\indexc{trunc}§
    71657176double trunc( double );
    71667177long double trunc( long double );
    71677178
    7168 float rint( float );$\indexc{rint}$
     7179float rint( float );§\indexc{rint}§
    71697180long double rint( long double );
    71707181long int rint( float );
     
    71757186long long int rint( long double );
    71767187
    7177 long int lrint( float );$\indexc{lrint}$
     7188long int lrint( float );§\indexc{lrint}§
    71787189long int lrint( double );
    71797190long int lrint( long double );
     
    71827193long long int llrint( long double );
    71837194
    7184 float nearbyint( float );$\indexc{nearbyint}$
     7195float nearbyint( float );§\indexc{nearbyint}§
    71857196double nearbyint( double );
    71867197long double nearbyint( long double );
    71877198
    7188 float round( float );$\indexc{round}$
     7199float round( float );§\indexc{round}§
    71897200long double round( long double );
    71907201long int round( float );
     
    71957206long long int round( long double );
    71967207
    7197 long int lround( float );$\indexc{lround}$
     7208long int lround( float );§\indexc{lround}§
    71987209long int lround( double );
    71997210long int lround( long double );
     
    72087219\leavevmode
    72097220\begin{cfa}[aboveskip=0pt,belowskip=0pt]
    7210 float copysign( float, float );$\indexc{copysign}$
     7221float copysign( float, float );§\indexc{copysign}§
    72117222double copysign( double, double );
    72127223long double copysign( long double, long double );
    72137224
    7214 float frexp( float, int * );$\indexc{frexp}$
     7225float frexp( float, int * );§\indexc{frexp}§
    72157226double frexp( double, int * );
    72167227long double frexp( long double, int * );
    72177228
    7218 float ldexp( float, int );$\indexc{ldexp}$
     7229float ldexp( float, int );§\indexc{ldexp}§
    72197230double ldexp( double, int );
    72207231long double ldexp( long double, int );
    72217232
    7222 [ float, float ] modf( float );$\indexc{modf}$
     7233[ float, float ] modf( float );§\indexc{modf}§
    72237234float modf( float, float * );
    72247235[ double, double ] modf( double );
     
    72277238long double modf( long double, long double * );
    72287239
    7229 float nextafter( float, float );$\indexc{nextafter}$
     7240float nextafter( float, float );§\indexc{nextafter}§
    72307241double nextafter( double, double );
    72317242long double nextafter( long double, long double );
    72327243
    7233 float nexttoward( float, long double );$\indexc{nexttoward}$
     7244float nexttoward( float, long double );§\indexc{nexttoward}§
    72347245double nexttoward( double, long double );
    72357246long double nexttoward( long double, long double );
    72367247
    7237 float scalbn( float, int );$\indexc{scalbn}$
     7248float scalbn( float, int );§\indexc{scalbn}§
    72387249double scalbn( double, int );
    72397250long double scalbn( long double, int );
    72407251
    7241 float scalbln( float, long int );$\indexc{scalbln}$
     7252float scalbln( float, long int );§\indexc{scalbln}§
    72427253double scalbln( double, long int );
    72437254long double scalbln( long double, long int );
     
    72567267\begin{cfa}[aboveskip=0pt,belowskip=0pt]
    72577268struct Duration {
    7258         int64_t tv; $\C{// nanoseconds}$
     7269        int64_t tv; §\C{// nanoseconds}§
    72597270};
    72607271
     
    73867397\begin{cfa}[aboveskip=0pt,belowskip=0pt]
    73877398struct Time {
    7388         uint64_t tv; $\C{// nanoseconds since UNIX epoch}$
     7399        uint64_t tv; §\C{// nanoseconds since UNIX epoch}§
    73897400};
    73907401
     
    74577468\begin{cfa}[aboveskip=0pt,belowskip=0pt]
    74587469struct Clock {
    7459         Duration offset; $\C{// for virtual clock: contains offset from real-time}$
    7460         int clocktype; $\C{// implementation only -1 (virtual), CLOCK\_REALTIME}$
     7470        Duration offset; §\C{// for virtual clock: contains offset from real-time}§
     7471        int clocktype; §\C{// implementation only -1 (virtual), CLOCK\_REALTIME}§
    74617472};
    74627473
     
    74667477void ?{}( Clock & clk, Duration adj );
    74677478
    7468 Duration getResNsec(); $\C{// with nanoseconds}$
    7469 Duration getRes(); $\C{// without nanoseconds}$
    7470 
    7471 Time getTimeNsec(); $\C{// with nanoseconds}$
    7472 Time getTime(); $\C{// without nanoseconds}$
     7479Duration getResNsec(); §\C{// with nanoseconds}§
     7480Duration getRes(); §\C{// without nanoseconds}§
     7481
     7482Time getTimeNsec(); §\C{// with nanoseconds}§
     7483Time getTime(); §\C{// without nanoseconds}§
    74737484Time getTime( Clock & clk );
    74747485Time ?()( Clock & clk );
     
    74867497
    74877498\begin{cfa}
    7488 void ?{}( Int * this ); $\C{// constructor/destructor}$
     7499void ?{}( Int * this ); §\C{// constructor/destructor}§
    74897500void ?{}( Int * this, Int init );
    74907501void ?{}( Int * this, zero_t );
     
    74957506void ^?{}( Int * this );
    74967507
    7497 Int ?=?( Int * lhs, Int rhs ); $\C{// assignment}$
     7508Int ?=?( Int * lhs, Int rhs ); §\C{// assignment}§
    74987509Int ?=?( Int * lhs, long int rhs );
    74997510Int ?=?( Int * lhs, unsigned long int rhs );
     
    75127523unsigned long int narrow( Int val );
    75137524
    7514 int ?==?( Int oper1, Int oper2 ); $\C{// comparison}$
     7525int ?==?( Int oper1, Int oper2 ); §\C{// comparison}§
    75157526int ?==?( Int oper1, long int oper2 );
    75167527int ?==?( long int oper2, Int oper1 );
     
    75487559int ?>=?( unsigned long int oper1, Int oper2 );
    75497560
    7550 Int +?( Int oper ); $\C{// arithmetic}$
     7561Int +?( Int oper ); §\C{// arithmetic}§
    75517562Int -?( Int oper );
    75527563Int ~?( Int oper );
     
    76307641Int ?>>=?( Int * lhs, mp_bitcnt_t shift );
    76317642
    7632 Int abs( Int oper ); $\C{// number functions}$
     7643Int abs( Int oper ); §\C{// number functions}§
    76337644Int fact( unsigned long int N );
    76347645Int gcd( Int oper1, Int oper2 );
     
    76427653Int sqrt( Int oper );
    76437654
    7644 forall( dtype istype | istream( istype ) ) istype * ?|?( istype * is, Int * mp );  $\C{// I/O}$
     7655forall( dtype istype | istream( istype ) ) istype * ?|?( istype * is, Int * mp );  §\C{// I/O}§
    76457656forall( dtype ostype | ostream( ostype ) ) ostype * ?|?( ostype * os, Int mp );
    76467657\end{cfa}
     
    76537664\hline
    76547665\begin{cfa}
    7655 #include <gmp>$\indexc{gmp}$
     7666#include <gmp>§\indexc{gmp}§
    76567667int main( void ) {
    76577668        sout | "Factorial Numbers";
     
    76677678&
    76687679\begin{cfa}
    7669 #include <gmp.h>$\indexc{gmp.h}$
     7680#include <gmp.h>§\indexc{gmp.h}§
    76707681int main( void ) {
    7671         @gmp_printf@( "Factorial Numbers\n" );
    7672         @mpz_t@ fact;
    7673         @mpz_init_set_ui@( fact, 1 );
    7674         @gmp_printf@( "%d %Zd\n", 0, fact );
     7682        ®gmp_printf®( "Factorial Numbers\n" );
     7683        ®mpz_t® fact;
     7684        ®mpz_init_set_ui®( fact, 1 );
     7685        ®gmp_printf®( "%d %Zd\n", 0, fact );
    76757686        for ( unsigned int i = 1; i <= 40; i += 1 ) {
    7676                 @mpz_mul_ui@( fact, fact, i );
    7677                 @gmp_printf@( "%d %Zd\n", i, fact );
     7687                ®mpz_mul_ui®( fact, fact, i );
     7688                ®gmp_printf®( "%d %Zd\n", i, fact );
    76787689        }
    76797690}
     
    77407751\begin{cfa}[belowskip=0pt]
    77417752// implementation
    7742 struct Rational {$\indexc{Rational}$
    7743         long int numerator, denominator; $\C{// invariant: denominator > 0}$
     7753struct Rational {§\indexc{Rational}§
     7754        long int numerator, denominator; §\C{// invariant: denominator > 0}§
    77447755}; // Rational
    77457756
    7746 Rational rational(); $\C{// constructors}$
     7757Rational rational(); §\C{// constructors}§
    77477758Rational rational( long int n );
    77487759Rational rational( long int n, long int d );
     
    77507761void ?{}( Rational * r, one_t );
    77517762
    7752 long int numerator( Rational r ); $\C{// numerator/denominator getter/setter}$
     7763long int numerator( Rational r ); §\C{// numerator/denominator getter/setter}§
    77537764long int numerator( Rational r, long int n );
    77547765long int denominator( Rational r );
    77557766long int denominator( Rational r, long int d );
    77567767
    7757 int ?==?( Rational l, Rational r ); $\C{// comparison}$
     7768int ?==?( Rational l, Rational r ); §\C{// comparison}§
    77587769int ?!=?( Rational l, Rational r );
    77597770int ?<?( Rational l, Rational r );
     
    77627773int ?>=?( Rational l, Rational r );
    77637774
    7764 Rational -?( Rational r ); $\C{// arithmetic}$
     7775Rational -?( Rational r ); §\C{// arithmetic}§
    77657776Rational ?+?( Rational l, Rational r );
    77667777Rational ?-?( Rational l, Rational r );
     
    77687779Rational ?/?( Rational l, Rational r );
    77697780
    7770 double widen( Rational r ); $\C{// conversion}$
     7781double widen( Rational r ); §\C{// conversion}§
    77717782Rational narrow( double f, long int md );
    77727783
  • libcfa/src/bits/containers.hfa

    r95b3a9c r5e99a9a  
    151151                }
    152152
    153                 void append( __queue(T) & this, T * val ) with(this) {
     153                void append( __queue(T) & this, T * val ) with( this ) {
    154154                        verify(this.tail != 0p);
    155155                        verify(*this.tail == 1p);
     
    161161                T * peek( __queue(T) & this ) {
    162162                        verify(*this.tail == 1p);
    163                         T * frontnode = this.head;
    164                         if( frontnode != 1p ) {
     163                        T * front = this.head;
     164                        if( front != 1p ) {
    165165                                verify(*this.tail == 1p);
    166                                 return frontnode;
     166                                return front;
    167167                        }
    168168                        verify(*this.tail == 1p);
  • libcfa/src/bits/sequence.hfa

    r95b3a9c r5e99a9a  
    3030        // PUBLIC
    3131
    32         void ?{}( Seqable & sq ) {
     32        void ?{}( Seqable & sq ) with( sq ) {
    3333                ((Colable &)sq){};
    34                 sq.back = 0p;
     34                back = 0p;
    3535        } // post: ! listed()
    3636
  • libcfa/src/fstream.hfa

    r95b3a9c r5e99a9a  
    1616#pragma once
    1717
    18 #include "bits/weakso_locks.hfa"
    1918#include "iostream.hfa"
    2019#include <exception.hfa>
     
    3534        char $separator[sepSize];
    3635        char $tupleSeparator[sepSize];
    37 //      multiple_acquisition_lock lock;
    3836}; // ofstream
    3937
  • libcfa/src/memory.cfa

    r95b3a9c r5e99a9a  
    1010// Created On       : Tue Jun  2 16:48:00 2020
    1111// Last Modified By : Andrew Beach
    12 // Last Modified On : Mon Feb  1 16:10:00 2021
    13 // Update Count     : 1
     12// Last Modified On : Tue Jun  3 12:30:00 2020
     13// Update Count     : 0
    1414//
    1515
     
    5656}
    5757
    58 forall(T & | sized(T))
     58forall(T & | sized(T) | { void ^?{}(T &); })
    5959void ?{}(counter_ptr(T) & this, counter_ptr(T) that) {
    6060        // `that` is a copy but it should have neither a constructor
    6161        // nor destructor run on it so it shouldn't need adjustment.
     62        internal_decrement(this);
    6263        internal_copy(this, that);
    6364}
     
    6566forall(T & | sized(T), Args... | { void ?{}(T&, Args); })
    6667void ?{}(counter_ptr(T) & this, Args args) {
    67         this.data = malloc();
    68         this.data->counter = 1;
    69         (this.data->object){args};
     68        this.data = (counter_data(T)*)new(args);
    7069}
    7170
     
    127126forall(T & | sized(T), Args... | { void ?{}(T &, Args); })
    128127void ?{}(unique_ptr(T) & this, Args args) {
    129         this.data = malloc();
    130         (*this.data){args};
     128        this.data = (T *)new(args);
    131129}
    132130
  • libcfa/src/memory.hfa

    r95b3a9c r5e99a9a  
    1010// Created On       : Tue Jun  2 16:48:00 2020
    1111// Last Modified By : Andrew Beach
    12 // Last Modified On : Fri Jan 29 15:52:00 2021
    13 // Update Count     : 1
     12// Last Modified On : Tue Jun  3 12:29:00 2020
     13// Update Count     : 0
    1414//
    1515
     
    1717
    1818// Internal data object.
    19 forall(T & | sized(T))
    20 struct counter_data {
    21         unsigned int counter;
    22         T object;
    23 };
     19forall(T & | sized(T)) {
     20        struct counter_data {
     21                unsigned int counter;
     22                T object;
     23        };
    2424
    25 forall(T & | sized(T), Args... | { void ?{}(T &, Args); })
    26 void ?{}(counter_data(T) & this, Args args);
     25        forall(Args... | { void ?{}(T &, Args); })
     26        void ?{}(counter_data(T) & this, Args args);
    2727
    28 forall(T & | sized(T) | { void ^?{}(T &); })
    29 void ^?{}(counter_data(T) & this);
     28        forall( | { void ^?{}(T &); })
     29        void ^?{}(counter_data(T) & this);
     30}
    3031
    3132// This is one of many pointers keeping this alive.
    32 forall(T & | sized(T))
    33 struct counter_ptr {
    34         counter_data(T) * data;
    35 };
     33forall(T & | sized(T)) {
     34        struct counter_ptr {
     35                counter_data(T) * data;
     36        };
    3637
    37 forall(T & | sized(T))
    38 void ?{}(counter_ptr(T) & this);
    39 forall(T & | sized(T))
    40 void ?{}(counter_ptr(T) & this, zero_t);
    41 forall(T & | sized(T))
    42 void ?{}(counter_ptr(T) & this, counter_ptr(T) that);
    43 forall(T & | sized(T), Args... | { void ?{}(T&, Args); })
    44 void ?{}(counter_ptr(T) & this, Args args);
     38        void ?{}(counter_ptr(T) & this);
     39        void ?{}(counter_ptr(T) & this, zero_t);
     40        forall( | { void ^?{}(T &); })
     41        void ?{}(counter_ptr(T) & this, counter_ptr(T) that);
     42        forall(Args... | { void ?{}(T&, Args); })
     43        void ?{}(counter_ptr(T) & this, Args args);
    4544
    46 forall(T & | sized(T) | { void ^?{}(T &); })
    47 void ^?{}(counter_ptr(T) & this);
     45        forall( | { void ^?{}(T &); })
     46        void ^?{}(counter_ptr(T) & this);
    4847
    49 forall(T & | sized(T))
    50 T & *?(counter_ptr(T) & this);
     48        T & *?(counter_ptr(T) & this);
    5149
    52 forall(T & | sized(T) | { void ^?{}(T &); })
    53 void ?=?(counter_ptr(T) & this, counter_ptr(T) that);
    54 forall(T & | sized(T) | { void ^?{}(T &); })
    55 void ?=?(counter_ptr(T) & this, zero_t);
     50        forall( | { void ^?{}(T &); })
     51        void ?=?(counter_ptr(T) & this, counter_ptr(T) that);
     52        forall( | { void ^?{}(T &); })
     53        void ?=?(counter_ptr(T) & this, zero_t);
    5654
    57 forall(T & | sized(T))
    58 int ?==?(counter_ptr(T) const & this, counter_ptr(T) const & that);
    59 forall(T & | sized(T))
    60 int ?!=?(counter_ptr(T) const & this, counter_ptr(T) const & that);
    61 forall(T & | sized(T))
    62 int ?==?(counter_ptr(T) const & this, zero_t);
    63 forall(T & | sized(T))
    64 int ?!=?(counter_ptr(T) const & this, zero_t);
     55        int ?==?(counter_ptr(T) const & this, counter_ptr(T) const & that);
     56        int ?!=?(counter_ptr(T) const & this, counter_ptr(T) const & that);
     57        int ?==?(counter_ptr(T) const & this, zero_t);
     58        int ?!=?(counter_ptr(T) const & this, zero_t);
     59}
    6560
    6661// This is the only pointer that keeps this alive.
    67 forall(T &)
    68 struct unique_ptr {
    69         T * data;
    70 };
     62forall(T &) {
     63        struct unique_ptr {
     64                T * data;
     65        };
    7166
    72 forall(T &)
    73 void ?{}(unique_ptr(T) & this);
    74 forall(T &)
    75 void ?{}(unique_ptr(T) & this, zero_t);
    76 forall(T &)
    77 void ?{}(unique_ptr(T) & this, unique_ptr(T) that) = void;
    78 forall(T & | sized(T), Args... | { void ?{}(T &, Args); })
    79 void ?{}(unique_ptr(T) & this, Args args);
     67        void ?{}(unique_ptr(T) & this);
     68        void ?{}(unique_ptr(T) & this, zero_t);
     69        void ?{}(unique_ptr(T) & this, unique_ptr(T) that) = void;
     70        forall( | sized(T), Args... | { void ?{}(T &, Args); })
     71        void ?{}(unique_ptr(T) & this, Args args);
    8072
    81 forall(T & | { void ^?{}(T &); })
    82 void ^?{}(unique_ptr(T) & this);
     73        forall( | { void ^?{}(T &); })
     74        void ^?{}(unique_ptr(T) & this);
    8375
    84 forall(T & )
    85 T & *?(unique_ptr(T) & this);
     76        T & *?(unique_ptr(T) & this);
    8677
    87 forall(T &)
    88 void ?=?(unique_ptr(T) & this, unique_ptr(T) that) = void;
    89 forall(T & | { void ^?{}(T &); })
    90 void ?=?(unique_ptr(T) & this, zero_t);
     78        void ?=?(unique_ptr(T) & this, unique_ptr(T) that) = void;
     79        forall( | { void ^?{}(T &); })
     80        void ?=?(unique_ptr(T) & this, zero_t);
    9181
    92 forall(T & | { void ^?{}(T &); })
    93 void move(unique_ptr(T) & this, unique_ptr(T) & that);
     82        forall( | { void ^?{}(T &); })
     83        void move(unique_ptr(T) & this, unique_ptr(T) & that);
    9484
    95 forall(T &)
    96 int ?==?(unique_ptr(T) const & this, unique_ptr(T) const & that);
    97 forall(T &)
    98 int ?!=?(unique_ptr(T) const & this, unique_ptr(T) const & that);
    99 forall(T &)
    100 int ?==?(unique_ptr(T) const & this, zero_t);
    101 forall(T &)
    102 int ?!=?(unique_ptr(T) const & this, zero_t);
     85        int ?==?(unique_ptr(T) const & this, unique_ptr(T) const & that);
     86        int ?!=?(unique_ptr(T) const & this, unique_ptr(T) const & that);
     87        int ?==?(unique_ptr(T) const & this, zero_t);
     88        int ?!=?(unique_ptr(T) const & this, zero_t);
     89}
  • src/Parser/lex.ll

    r95b3a9c r5e99a9a  
    1010 * Created On       : Sat Sep 22 08:58:10 2001
    1111 * Last Modified By : Peter A. Buhr
    12  * Last Modified On : Wed Feb 17 08:38:13 2021
    13  * Update Count     : 752
     12 * Last Modified On : Tue Oct  6 18:15:41 2020
     13 * Update Count     : 743
    1414 */
    1515
     
    221221break                   { KEYWORD_RETURN(BREAK); }
    222222case                    { KEYWORD_RETURN(CASE); }
    223 catch                   { QKEYWORD_RETURN(CATCH); }                             // CFA
    224 catchResume             { QKEYWORD_RETURN(CATCHRESUME); }               // CFA
     223catch                   { KEYWORD_RETURN(CATCH); }                              // CFA
     224catchResume             { KEYWORD_RETURN(CATCHRESUME); }                // CFA
    225225char                    { KEYWORD_RETURN(CHAR); }
    226226choose                  { KEYWORD_RETURN(CHOOSE); }                             // CFA
     
    247247fallthrough             { KEYWORD_RETURN(FALLTHROUGH); }                // CFA
    248248fallthru                { KEYWORD_RETURN(FALLTHRU); }                   // CFA
    249 finally                 { QKEYWORD_RETURN(FINALLY); }                   // CFA
    250 fixup                   { QKEYWORD_RETURN(FIXUP); }                             // CFA
     249finally                 { KEYWORD_RETURN(FINALLY); }                    // CFA
    251250float                   { KEYWORD_RETURN(FLOAT); }
    252251__float80               { KEYWORD_RETURN(uuFLOAT80); }                  // GCC
     
    288287or                              { QKEYWORD_RETURN(WOR); }                               // CFA
    289288otype                   { KEYWORD_RETURN(OTYPE); }                              // CFA
    290 recover                 { QKEYWORD_RETURN(RECOVER); }                   // CFA
    291289register                { KEYWORD_RETURN(REGISTER); }
    292 report                  { KEYWORD_RETURN(THROWRESUME); }                // CFA
    293290restrict                { KEYWORD_RETURN(RESTRICT); }                   // C99
    294291__restrict              { KEYWORD_RETURN(RESTRICT); }                   // GCC
     
    327324__volatile              { KEYWORD_RETURN(VOLATILE); }                   // GCC
    328325__volatile__    { KEYWORD_RETURN(VOLATILE); }                   // GCC
    329 waitfor                 { KEYWORD_RETURN(WAITFOR); }                    // CFA
    330 when                    { KEYWORD_RETURN(WHEN); }                               // CFA
     326waitfor                 { KEYWORD_RETURN(WAITFOR); }
     327when                    { KEYWORD_RETURN(WHEN); }
    331328while                   { KEYWORD_RETURN(WHILE); }
    332329with                    { KEYWORD_RETURN(WITH); }                               // CFA
  • src/Parser/parser.yy

    r95b3a9c r5e99a9a  
    1010// Created On       : Sat Sep  1 20:22:55 2001
    1111// Last Modified By : Peter A. Buhr
    12 // Last Modified On : Wed Feb 17 09:03:07 2021
    13 // Update Count     : 4722
     12// Last Modified On : Wed Jan 27 08:58:56 2021
     13// Update Count     : 4680
    1414//
    1515
     
    282282%token ATTRIBUTE EXTENSION                                                              // GCC
    283283%token IF ELSE SWITCH CASE DEFAULT DO WHILE FOR BREAK CONTINUE GOTO RETURN
    284 %token CHOOSE DISABLE ENABLE FALLTHRU FALLTHROUGH TRY THROW THROWRESUME AT WITH WHEN WAITFOR // CFA
     284%token CHOOSE DISABLE ENABLE FALLTHRU FALLTHROUGH TRY CATCH CATCHRESUME FINALLY THROW THROWRESUME AT WITH WHEN WAITFOR // CFA
    285285%token ASM                                                                                              // C99, extension ISO/IEC 9899:1999 Section J.5.10(1)
    286286%token ALIGNAS ALIGNOF GENERIC STATICASSERT                             // C11
    287287
    288288// names and constants: lexer differentiates between identifier and typedef names
    289 %token<tok> IDENTIFIER          QUOTED_IDENTIFIER       TYPEDEFname             TYPEGENname
    290 %token<tok> TIMEOUT                     WOR                                     CATCH                   RECOVER                 CATCHRESUME             FIXUP           FINALLY         // CFA
    291 %token<tok> INTEGERconstant     CHARACTERconstant       STRINGliteral
     289%token<tok> IDENTIFIER                  QUOTED_IDENTIFIER               TYPEDEFname                             TYPEGENname
     290%token<tok> TIMEOUT                             WOR
     291%token<tok> INTEGERconstant             CHARACTERconstant               STRINGliteral
    292292%token<tok> DIRECTIVE
    293293// Floating point constant is broken into three kinds of tokens because of the ambiguity with tuple indexing and
     
    462462// Order of these lines matters (low-to-high precedence). THEN is left associative over WOR/TIMEOUT/ELSE, WOR is left
    463463// associative over TIMEOUT/ELSE, and TIMEOUT is left associative over ELSE.
    464 %precedence THEN                // rule precedence for IF/WAITFOR statement
    465 %precedence WOR                 // token precedence for start of WOR in WAITFOR statement
    466 %precedence TIMEOUT             // token precedence for start of TIMEOUT in WAITFOR statement
    467 %precedence CATCH               // token precedence for start of TIMEOUT in WAITFOR statement
    468 %precedence RECOVER             // token precedence for start of TIMEOUT in WAITFOR statement
    469 %precedence CATCHRESUME // token precedence for start of TIMEOUT in WAITFOR statement
    470 %precedence FIXUP               // token precedence for start of TIMEOUT in WAITFOR statement
    471 %precedence FINALLY             // token precedence for start of TIMEOUT in WAITFOR statement
    472 %precedence ELSE                // token precedence for start of else clause in IF/WAITFOR statement
    473 
     464%precedence THEN        // rule precedence for IF/WAITFOR statement
     465%precedence WOR         // token precedence for start of WOR in WAITFOR statement
     466%precedence TIMEOUT     // token precedence for start of TIMEOUT in WAITFOR statement
     467%precedence ELSE        // token precedence for start of else clause in IF/WAITFOR statement
    474468
    475469// Handle shift/reduce conflict for generic type by shifting the '(' token. For example, this string is ambiguous:
     
    550544        TIMEOUT
    551545        | WOR
    552         | CATCH
    553         | RECOVER
    554         | CATCHRESUME
    555         | FIXUP
    556         | FINALLY
    557546        ;
    558547
     
    629618postfix_expression:
    630619        primary_expression
    631         | postfix_expression '[' assignment_expression ',' comma_expression ']'
    632                 // { $$ = new ExpressionNode( build_binary_val( OperKinds::Index, $1, new ExpressionNode( build_binary_val( OperKinds::Index, $3, $5 ) ) ) ); }
    633                 { SemanticError( yylloc, "New array subscript is currently unimplemented." ); $$ = nullptr; }
    634620        | postfix_expression '[' assignment_expression ']'
    635621                // CFA, comma_expression disallowed in this context because it results in a common user error: subscripting a
     
    13771363
    13781364exception_statement:
    1379         TRY compound_statement handler_clause                                   %prec THEN
     1365        TRY compound_statement handler_clause
    13801366                { $$ = new StatementNode( build_try( $2, $3, 0 ) ); }
    13811367        | TRY compound_statement finally_clause
     
    14001386handler_key:
    14011387        CATCH                                                                           { $$ = CatchStmt::Terminate; }
    1402         | RECOVER                                                                       { $$ = CatchStmt::Terminate; }
    14031388        | CATCHRESUME                                                           { $$ = CatchStmt::Resume; }
    1404         | FIXUP                                                                         { $$ = CatchStmt::Resume; }
    14051389        ;
    14061390
     
    32033187        | '[' ']' multi_array_dimension
    32043188                { $$ = DeclarationNode::newArray( 0, 0, false )->addArray( $3 ); }
    3205         | '[' push assignment_expression pop ',' comma_expression ']'
    3206                 { $$ = DeclarationNode::newArray( $3, 0, false )->addArray( DeclarationNode::newArray( $6, 0, false ) ); }
    3207                 // { SemanticError( yylloc, "New array dimension is currently unimplemented." ); $$ = nullptr; }
    32083189        | multi_array_dimension
    32093190        ;
  • src/main.cc

    r95b3a9c r5e99a9a  
    99// Author           : Peter Buhr and Rob Schluntz
    1010// Created On       : Fri May 15 23:12:02 2015
    11 // Last Modified By : Peter A. Buhr
    12 // Last Modified On : Mon Feb  8 21:10:16 2021
    13 // Update Count     : 642
     11// Last Modified By : Andrew Beach
     12// Last Modified On : Mon Dec  7 15:29:00 2020
     13// Update Count     : 639
    1414//
    1515
     
    492492
    493493static const char * description[] = {
    494         "diagnostic color: never, always, auto",                        // -c
     494        "diagnostic color: never, always, or auto.",            // -c
    495495        "wait for gdb to attach",                                                       // -g
    496         "print translator help message",                                        // -h
     496        "print help message",                                                           // -h
    497497        "generate libcfa.c",                                                            // -l
    498498        "generate line marks",                                                          // -L
     
    500500        "do not generate line marks",                                           // -N
    501501        "do not read prelude",                                                          // -n
    502         "do not generate prelude prototypes => prelude not printed", // -p
     502        "generate prototypes for prelude functions",            // -p
    503503        "only print deterministic output",                  // -d
    504504        "Use the old-ast",                                                                      // -O
     
    506506        "print",                                                                                        // -P
    507507        "<directory> prelude directory for debug/nodebug",      // no flag
    508         "<option-list> enable profiling information: counters, heap, time, all, none", // -S
     508        "<option-list> enable profiling information:\n          counters,heap,time,all,none", // -S
    509509        "building cfa standard lib",                                            // -t
    510510        "",                                                                                                     // -w
  • tests/smart-pointers.cfa

    r95b3a9c r5e99a9a  
    22
    33#include <memory.hfa>
    4 #include <assert.h>
     4#include <stdlib.hfa>
    55
    66void counter_test(void) {
     
    5353}
    5454
    55 void declare_test(void) {
    56         counter_ptr(int) ptr_i0 = 3;
    57         counter_ptr(char) ptr_c0 = 'a';
    58         counter_ptr(float) ptr_f0 = 3.5f;
    59         counter_ptr(double) ptr_d0 = 3.5;
    60 
    61         unique_ptr(int) ptr_i1 = 3;
    62         unique_ptr(char) ptr_c1 = 'a';
    63         unique_ptr(float) ptr_f1 = 3.5f;
    64         unique_ptr(double) ptr_d1 = 3.5;
    65 }
    66 
    6755int main(int argc, char * argv[]) {
    6856        counter_test();
    6957        unique_test();
    7058        pointer_equality();
    71 
    72         printf("done\n");
    7359}
Note: See TracChangeset for help on using the changeset viewer.