Ignore:
File:
1 edited

Legend:

Unmodified
Added
Removed
  • doc/papers/general/Paper.tex

    r3fd3bda r860f19f  
    1 \documentclass[AMA,STIX1COL]{WileyNJD-v2}
    2 
    3 \articletype{RESEARCH ARTICLE}%
    4 
    5 \received{26 April 2016}
    6 \revised{6 June 2016}
    7 \accepted{6 June 2016}
    8 
    9 \raggedbottom
    10 
    11 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
    12 
    13 % Latex packages used in the document.
    14 
     1\documentclass{article}
     2
     3\usepackage{fullpage}
    154\usepackage{epic,eepic}
    16 \usepackage{xspace}
    17 \usepackage{comment}
     5\usepackage{xspace,calc,comment}
    186\usepackage{upquote}                                            % switch curled `'" to straight
    197\usepackage{listings}                                           % format program code
    20 %\usepackage{enumitem}
    21 %\setlist[itemize]{topsep=3pt,itemsep=2pt,parsep=0pt}% global
    22 %\usepackage{rotating}
    23 
    24 \hypersetup{breaklinks=true}
    25 \definecolor{ForestGreen}{cmyk}{1, 0, 0.99995, 0}
    26 
    27 \usepackage[pagewise]{lineno}
    28 \renewcommand{\linenumberfont}{\scriptsize\sffamily}
     8\usepackage{enumitem}
     9\setlist[itemize]{topsep=3pt,itemsep=2pt,parsep=0pt}% global
     10\usepackage[flushmargin]{footmisc}                      % support label/reference in footnote
     11\usepackage{rotating}
     12\usepackage[usenames]{color}
     13\usepackage{pslatex}                                            % reduce size of san serif font
     14\usepackage[plainpages=false,pdfpagelabels,pdfpagemode=UseNone,pagebackref=true,breaklinks=true,colorlinks=true,linkcolor=blue,citecolor=blue,urlcolor=blue]{hyperref}
     15\urlstyle{sf}
     16\usepackage{breakurl}
     17
     18\setlength{\textheight}{9in}
     19%\oddsidemargin 0.0in
     20\renewcommand{\topfraction}{0.8}                        % float must be greater than X of the page before it is forced onto its own page
     21\renewcommand{\bottomfraction}{0.8}                     % float must be greater than X of the page before it is forced onto its own page
     22\renewcommand{\floatpagefraction}{0.8}          % float must be greater than X of the page before it is forced onto its own page
     23\renewcommand{\textfraction}{0.0}                       % the entire page maybe devoted to floats with no text on the page at all
    2924
    3025\lefthyphenmin=4                                                        % hyphen only after 4 characters
    3126\righthyphenmin=4
    32 
    33 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
    3427
    3528% Names used in the document.
     
    7164\newlength{\gcolumnposn}                                        % temporary hack because lstlisting does not handle tabs correctly
    7265\newlength{\columnposn}
    73 \setlength{\gcolumnposn}{3.5in}
     66\setlength{\gcolumnposn}{2.75in}
    7467\setlength{\columnposn}{\gcolumnposn}
    7568\newcommand{\C}[2][\@empty]{\ifx#1\@empty\else\global\setlength{\columnposn}{#1}\global\columnposn=\columnposn\fi\hfill\makebox[\textwidth-\columnposn][l]{\lst@basicstyle{\LstCommentStyle{#2}}}}
     
    10497}%
    10598\newcommand{\ETAL}{\abbrevFont{et}~\abbrevFont{al}}
    106 \renewcommand*{\etal}{%
     99\newcommand*{\etal}{%
    107100        \@ifnextchar{.}{\protect\ETAL}%
    108101                {\protect\ETAL.\xspace}%
     
    152145belowskip=3pt,
    153146% replace/adjust listing characters that look bad in sanserif
    154 literate={-}{\makebox[1ex][c]{\raisebox{0.4ex}{\rule{0.8ex}{0.1ex}}}}1 {^}{\raisebox{0.6ex}{$\scriptstyle\land\,$}}1
    155         {~}{\raisebox{0.3ex}{$\scriptstyle\sim\,$}}1 % {`}{\ttfamily\upshape\hspace*{-0.1ex}`}1
    156         {<-}{$\leftarrow$}2 {=>}{$\Rightarrow$}2 {->}{\makebox[1ex][c]{\raisebox{0.5ex}{\rule{0.8ex}{0.075ex}}}\kern-0.2ex{\textgreater}}2,
     147literate={-}{\makebox[1ex][c]{\raisebox{0.4ex}{\rule{0.8ex}{0.1ex}}}}1 {^}{\raisebox{0.6ex}{$\scriptscriptstyle\land\,$}}1
     148        {~}{\raisebox{0.3ex}{$\scriptstyle\sim\,$}}1 {@}{\small{@}}1 {<}{\small{\textless}}1 {>}{\small{\textgreater}}1  % {`}{\ttfamily\upshape\hspace*{-0.1ex}`}1
     149        {<-}{$\leftarrow$}2 {=>}{$\Rightarrow$}2 {->}{\makebox[1ex][c]{\raisebox{0.4ex}{\rule{0.8ex}{0.075ex}}}\kern-0.2ex{\small\textgreater}}2,
    157150moredelim=**[is][\color{red}]{`}{`},
    158151}% lstset
     152
     153% inline code @...@
     154\lstMakeShortInline@%
    159155
    160156\lstnewenvironment{cfa}[1][]
     
    165161{}
    166162
    167 % inline code @...@
    168 \lstMakeShortInline@%
    169 
    170 
    171 \title{\texorpdfstring{\protect\CFA : Adding Modern Programming Language Features to C}{Cforall : Adding Modern Programming Language Features to C}}
    172 
    173 \author[1]{Aaron Moss}
    174 \author[1]{Robert Schluntz}
    175 \author[1]{Peter A. Buhr*}
    176 
    177 \address[1]{\orgdiv{David R. Cheriton School of Computer Science}, \orgname{University of Waterloo}, \orgaddress{\state{Ontario}, \country{Canada}}}
    178 
    179 \corres{*Peter A. Buhr, \email{pabuhr{\char`\@}uwaterloo.ca}}
    180 \presentaddress{David R. Cheriton School of Computer Science, University of Waterloo, Waterloo, ON, N2L 3G1, Canada}
    181 
    182 
    183 \abstract[Summary]{
     163
     164\title{\protect\CFA : Adding Modern Programming Language Features to C}
     165
     166\author{Aaron Moss, Robert Schluntz, Peter Buhr}
     167% \email{a3moss@uwaterloo.ca}
     168% \email{rschlunt@uwaterloo.ca}
     169% \email{pabuhr@uwaterloo.ca}
     170% \affiliation{%
     171%       \institution{University of Waterloo}
     172%       \department{David R. Cheriton School of Computer Science}
     173%       \streetaddress{Davis Centre, University of Waterloo}
     174%       \city{Waterloo}
     175%       \state{ON}
     176%       \postcode{N2L 3G1}
     177%       \country{Canada}
     178% }
     179
     180%\terms{generic, tuple, variadic, types}
     181%\keywords{generic types, tuple types, variadic types, polymorphic functions, C, Cforall}
     182
     183\begin{document}
     184\maketitle
     185
     186
     187\begin{abstract}
    184188The C programming language is a foundational technology for modern computing with millions of lines of code implementing everything from commercial operating-systems to hobby projects.
    185189This installation base and the programmers producing it represent a massive software-engineering investment spanning decades and likely to continue for decades more.
     
    191195This paper presents a quick tour of \CFA features showing how their design avoids shortcomings of similar features in C and other C-like languages.
    192196Finally, experimental results are presented to validate several of the new features.
    193 }%
    194 
    195 \keywords{generic types, tuple types, variadic types, polymorphic functions, C, Cforall}
    196 
    197 
    198 \begin{document}
    199 \linenumbers                                            % comment out to turn off line numbering
    200 
    201 \maketitle
     197\end{abstract}
    202198
    203199
     
    234230\CFA is currently implemented as a source-to-source translator from \CFA to the gcc-dialect of C~\cite{GCCExtensions}, allowing it to leverage the portability and code optimizations provided by gcc, meeting goals (1)--(3).
    235231Ultimately, a compiler is necessary for advanced features and optimal performance.
    236 All features discussed in this paper are working, unless otherwise stated as under construction.
     232All of the features discussed in this paper are working, unless a feature states it is a future feature for completion.
    237233
    238234Finally, it is impossible to describe a programming language without usages before definitions.
     
    262258
    263259\begin{cfa}
    264 int max = 2147483647;                                   $\C[4in]{// (1)}$
     260int max = 2147483647;                                           $\C[3.75in]{// (1)}$
    265261double max = 1.7976931348623157E+308;   $\C{// (2)}$
    266262int max( int a, int b ) { return a < b ? b : a; }  $\C{// (3)}$
    267263double max( double a, double b ) { return a < b ? b : a; }  $\C{// (4)}\CRT$
    268 max( 7, -max );                                         $\C[2.75in]{// uses (3) and (1), by matching int from constant 7}$
    269 max( max, 3.14 );                                       $\C{// uses (4) and (2), by matching double from constant 3.14}$
    270 max( max, -max );                                       $\C{// ERROR: ambiguous}$
    271 int m = max( max, -max );                       $\C{// uses (3) and (1) twice, by matching return type}\CRT$
     264max( 7, -max );                                                         $\C{// uses (3) and (1), by matching int from constant 7}$
     265max( max, 3.14 );                                                       $\C{// uses (4) and (2), by matching double from constant 3.14}$
     266max( max, -max );                                                       $\C{// ERROR: ambiguous}$
     267int m = max( max, -max );                                       $\C{// uses (3) and (1) twice, by matching return type}$
    272268\end{cfa}
    273269
     
    296292\begin{cfa}
    297293`forall( otype T )` T identity( T val ) { return val; }
    298 int forty_two = identity( 42 );         $\C{// T is bound to int, forty\_two == 42}$
     294int forty_two = identity( 42 );                         $\C{// T is bound to int, forty\_two == 42}$
    299295\end{cfa}
    300296This @identity@ function can be applied to any complete \newterm{object type} (or @otype@).
     
    310306For example, the function @twice@ can be defined using the \CFA syntax for operator overloading:
    311307\begin{cfa}
    312 forall( otype T `| { T ?+?(T, T); }` ) T twice( T x ) { return x `+` x; }  $\C{// ? denotes operands}$
     308forall( otype T `| { T ?+?(T, T); }` ) T twice( T x ) { return x `+` x; }       $\C{// ? denotes operands}$
    313309int val = twice( twice( 3.7 ) );
    314310\end{cfa}
     
    329325}
    330326double key = 5.0, vals[10] = { /* 10 sorted float values */ };
    331 double * val = (double *)bsearch( &key, vals, 10, sizeof(vals[0]), comp ); $\C{// search sorted array}$
     327double * val = (double *)bsearch( &key, vals, 10, sizeof(vals[0]), comp );      $\C{// search sorted array}$
    332328\end{cfa}
    333329which can be augmented simply with a generalized, type-safe, \CFA-overloaded wrappers:
     
    339335forall( otype T | { int ?<?( T, T ); } ) unsigned int bsearch( T key, const T * arr, size_t size ) {
    340336        T * result = bsearch( key, arr, size ); $\C{// call first version}$
    341         return result ? result - arr : size; $\C{// pointer subtraction includes sizeof(T)}$
    342 }
    343 double * val = bsearch( 5.0, vals, 10 ); $\C{// selection based on return type}$
     337        return result ? result - arr : size;    $\C{// pointer subtraction includes sizeof(T)}$
     338}
     339double * val = bsearch( 5.0, vals, 10 );        $\C{// selection based on return type}$
    344340int posn = bsearch( 5.0, vals, 10 );
    345341\end{cfa}
     
    365361forall( otype T | { int ?<?( T, T ); } ) void qsort( const T * arr, size_t size ) { /* use C qsort */ }
    366362{
    367         int ?<?( double x, double y ) { return x `>` y; } $\C{// locally override behaviour}$
     363        int ?<?( double x, double y ) { return x `>` y; }       $\C{// locally override behaviour}$
    368364        qsort( vals, size );                                    $\C{// descending sort}$
    369365}
     
    372368Hence, programmers can easily form local environments, adding and modifying appropriate functions, to maximize reuse of other existing functions and types.
    373369
    374 Under construction is a mechanism to distribute @forall@ over routines/types, where each block declaration is prefixed with the initial @forall@ clause significantly reducing duplication (see @stack@ examples in Section~\ref{sec:eval}):
    375 \begin{cfa}
    376 forall( otype `T` ) {                                                   $\C{// forall block}$
    377         struct stack { stack_node(`T`) * head; };       $\C{// generic type}$
    378         void push( stack(`T`) & s, `T` value ) ...      $\C{// generic operations}$
    379         T pop( stack(`T`) & s ) ...
    380 }
    381 \end{cfa}
     370Unconstruction is a mechanism to distribute @forall@ over related routines/types (see @stack@ examples in Section~\ref{sec:eval}):
     371\begin{cfa}
     372forall( otype T ) {                                                     $\C{// forall block}$
     373        struct stack { stack_node(T) * head; }; $\C{// generic type}$
     374        void push( stack(T) & s, T value ) ...  $\C{// generic operations}$
     375        T pop( stack(T) & s ) ...
     376}
     377\end{cfa}
     378Each block declaration is prefixed with the initial @forall@ clause significantly reducing duplication.
    382379
    383380
     
    391388        T ?+=?( T *, T );
    392389        T ++?( T * );
    393         T ?++( T * );
    394 };
     390        T ?++( T * ); };
     391
    395392forall( otype T `| summable( T )` ) T sum( T a[$\,$], size_t size ) {  // use trait
    396393        `T` total = { `0` };                                    $\C{// instantiate T from 0 by calling its constructor}$
    397394        for ( unsigned int i = 0; i < size; i += 1 ) total `+=` a[i]; $\C{// select appropriate +}$
    398         return total;
    399 }
     395        return total; }
    400396\end{cfa}
    401397
     
    406402        void ?{}( T &, T );                                             $\C{// copy constructor}$
    407403        void ?=?( T &, T );                                             $\C{// assignment operator}$
    408         void ^?{}( T & );                                               $\C{// destructor}$
    409 };
     404        void ^?{}( T & ); };                                    $\C{// destructor}$
    410405\end{cfa}
    411406Given the information provided for an @otype@, variables of polymorphic type can be treated as if they were a complete type: stack-allocatable, default or copy-initialized, assigned, and deleted.
     
    659654p`->0` = 5;                                                                     $\C{// change quotient}$
    660655bar( qr`.1`, qr );                                                      $\C{// pass remainder and quotient/remainder}$
    661 rem = [div( 13, 5 ), 42]`.0.1`;                         $\C{// access 2nd component of 1st component}$
     656rem = [div( 13, 5 ), 42]`.0.1`;                         $\C{// access 2nd component of 1st component of tuple expression}$
    662657\end{cfa}
    663658
     
    668663Tuple flattening recursively expands a tuple into the list of its basic components.
    669664Tuple structuring packages a list of expressions into a value of tuple type, \eg:
     665%\lstDeleteShortInline@%
     666%\par\smallskip
     667%\begin{tabular}{@{}l@{\hspace{1.5\parindent}}||@{\hspace{1.5\parindent}}l@{}}
    670668\begin{cfa}
    671669int f( int, int );
     
    674672[int, int] x;
    675673int y;
    676 f( x );                                                                         $\C{// flatten}$
    677 g( y, 10 );                                                                     $\C{// structure}$
    678 h( x, y );                                                                      $\C{// flatten and structure}$
    679 \end{cfa}
     674f( x );                 $\C{// flatten}$
     675g( y, 10 );             $\C{// structure}$
     676h( x, y );              $\C{// flatten and structure}$
     677\end{cfa}
     678%\end{cfa}
     679%&
     680%\begin{cfa}
     681%\end{tabular}
     682%\smallskip\par\noindent
     683%\lstMakeShortInline@%
    680684In the call to @f@, @x@ is implicitly flattened so the components of @x@ are passed as the two arguments.
    681685In the call to @g@, the values @y@ and @10@ are structured into a single argument of type @[int, int]@ to match the parameter type of @g@.
     
    688692An assignment where the left side is a tuple type is called \newterm{tuple assignment}.
    689693There are two kinds of tuple assignment depending on whether the right side of the assignment operator has a tuple type or a non-tuple type, called \newterm{multiple} and \newterm{mass assignment}, respectively.
     694%\lstDeleteShortInline@%
     695%\par\smallskip
     696%\begin{tabular}{@{}l@{\hspace{1.5\parindent}}||@{\hspace{1.5\parindent}}l@{}}
    690697\begin{cfa}
    691698int x = 10;
     
    697704[y, x] = 3.14;                                                          $\C{// mass assignment}$
    698705\end{cfa}
     706%\end{cfa}
     707%&
     708%\begin{cfa}
     709%\end{tabular}
     710%\smallskip\par\noindent
     711%\lstMakeShortInline@%
    699712Both kinds of tuple assignment have parallel semantics, so that each value on the left and right side is evaluated before any assignments occur.
    700713As a result, it is possible to swap the values in two variables without explicitly creating any temporary variables or calling a function, \eg, @[x, y] = [y, x]@.
     
    720733Here, the mass assignment sets all members of @s@ to zero.
    721734Since tuple-index expressions are a form of member-access expression, it is possible to use tuple-index expressions in conjunction with member tuple expressions to manually restructure a tuple (\eg rearrange, drop, and duplicate components).
     735%\lstDeleteShortInline@%
     736%\par\smallskip
     737%\begin{tabular}{@{}l@{\hspace{1.5\parindent}}||@{\hspace{1.5\parindent}}l@{}}
    722738\begin{cfa}
    723739[int, int, long, double] x;
     
    727743[int, int, int] y = x.[2, 0, 2];                        $\C{// duplicate: [y.0, y.1, y.2] = [x.2, x.0.x.2]}$
    728744\end{cfa}
     745%\end{cfa}
     746%&
     747%\begin{cfa}
     748%\end{tabular}
     749%\smallskip\par\noindent
     750%\lstMakeShortInline@%
    729751It is also possible for a member access to contain other member accesses, \eg:
    730752\begin{cfa}
     
    10161038\begin{cquote}
    10171039\lstDeleteShortInline@%
    1018 \begin{tabular}{@{}l@{\hspace{2\parindentlnth}}l@{}}
    1019 \multicolumn{1}{c@{\hspace{2\parindentlnth}}}{\textbf{\CFA}}    & \multicolumn{1}{c}{\textbf{C}}        \\
     1040\begin{tabular}{@{}l@{\hspace{\parindentlnth}}l@{}}
     1041\multicolumn{1}{c@{\hspace{\parindentlnth}}}{\textbf{\CFA}}     & \multicolumn{1}{c}{\textbf{C}}        \\
    10201042\begin{cfa}
    10211043case 2, 10, 34, 42:
     
    10311053\begin{cquote}
    10321054\lstDeleteShortInline@%
    1033 \begin{tabular}{@{}l@{\hspace{2\parindentlnth}}l@{}}
    1034 \multicolumn{1}{c@{\hspace{2\parindentlnth}}}{\textbf{\CFA}}    & \multicolumn{1}{c}{\textbf{C}}        \\
     1055\begin{tabular}{@{}l@{\hspace{\parindentlnth}}l@{}}
     1056\multicolumn{1}{c@{\hspace{\parindentlnth}}}{\textbf{\CFA}}     & \multicolumn{1}{c}{\textbf{C}}        \\
    10351057\begin{cfa}
    10361058case 2~42:
     
    10481070\end{cfa}
    10491071
    1050 C allows placement of @case@ clauses \emph{within} statements nested in the @switch@ body (called Duff's device~\cite{Duff83});
     1072C allows placement of @case@ clauses \emph{within} statements nested in the @switch@ body (see Duff's device~\cite{Duff83});
    10511073\begin{cfa}
    10521074switch ( i ) {
     
    10591081}
    10601082\end{cfa}
    1061 \CFA precludes this form of transfer \emph{into} a control structure because it causes undefined behaviour, especially with respect to missed initialization, and provides very limited functionality.
     1083\CFA precludes this form of transfer into a control structure because it causes undefined behaviour, especially with respect to missed initialization, and provides very limited functionality.
    10621084
    10631085C allows placement of declaration within the @switch@ body and unreachable code at the start, resulting in undefined behaviour:
     
    11241146\end{figure}
    11251147
    1126 Finally, Figure~\ref{f:FallthroughStatement} shows @fallthrough@ may appear in contexts other than terminating a @case@ clause, and have an explicit transfer label allowing separate cases but common final-code for a set of cases.
    1127 The target label must be below the @fallthrough@, \ie @fallthrough@ cannot form a loop, and the label may not be nested in a control structure, \ie it must be at the same level as the @case@ clauses;
    1128 the target label may be case @default@.
    1129 
    1130 \begin{figure}
    1131 \centering
     1148Finally, @fallthrough@ may appear in contexts other than terminating a @case@ clause, and have an explicit transfer label allowing separate cases but common final-code for a set of cases:
     1149\begin{cquote}
    11321150\lstDeleteShortInline@%
    11331151\begin{tabular}{@{}l@{\hspace{2\parindentlnth}}l@{}}
     
    11511169  case 4:
    11521170        ... `fallthrough common;`
    1153   common: // below fallthrough at same level as case clauses
     1171  common: // below fallthrough and at same level as case clauses
    11541172        ...      // common code for cases 3 and 4
    11551173        // implicit break
     
    11581176\end{tabular}
    11591177\lstMakeShortInline@%
    1160 \caption{\lstinline|fallthrough| Statement}
    1161 \label{f:FallthroughStatement}
    1162 \end{figure}
     1178\end{cquote}
     1179The target label must be below the @fallthrough@, \ie @fallthrough@ cannot form a loop, and the label may not be nested in a control structure, \ie it must be at the same level as the @case@ clauses;
     1180the target label may be case @default@.
    11631181
    11641182Collectively, these control-structure enhancements reduce programmer burden and increase readability and safety.
     
    12921310        R r;
    12931311        ... `resume( r );` ...
    1294         ... r.fix // control returns here after handler
     1312        ... r.fix // control does return here after handler
    12951313}
    12961314`try` {
     
    14051423
    14061424
    1407 \subsection{\texorpdfstring{\protect\lstinline{with} Statement}{with Statement}}
    1408 \label{s:WithStatement}
     1425\subsection{\texorpdfstring{\protect\lstinline{with} Clause / Statement}{with Clause / Statement}}
     1426\label{s:WithClauseStatement}
    14091427
    14101428Grouping 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:
     
    14261444A similar situation occurs in object-oriented programming, \eg \CC:
    14271445\begin{C++}
    1428 struct S {
     1446class C {
    14291447        char c;                                                                 $\C{// fields}$
    14301448        int i;
    14311449        double d;
    1432         void f() {                                                              $\C{// implicit ``this'' aggregate}$
     1450        int f() {                                                               $\C{// implicit ``this'' aggregate}$
    14331451                `this->`c; `this->`i; `this->`d;        $\C{// access containing fields}$
    14341452        }
    14351453}
    14361454\end{C++}
    1437 Object-oriented nesting of member functions in a \lstinline[language=C++]@class/struct@ allows eliding \lstinline[language=C++]@this->@ because of lexical scoping.
     1455Object-oriented nesting of member functions in a \lstinline[language=C++]@class@ allows eliding \lstinline[language=C++]@this->@ because of lexical scoping.
    14381456However, for other aggregate parameters, qualification is necessary:
    14391457\begin{cfa}
    14401458struct T { double m, n; };
    1441 int S::f( T & t ) {                                                     $\C{// multiple aggregate parameters}$
    1442         c; i; d;                                                                $\C{\color{red}// this--{\textgreater}.c, this--{\textgreater}.i, this--{\textgreater}.d}$
     1459int C::f( T & t ) {                                                     $\C{// multiple aggregate parameters}$
     1460        c; i; d;                                                                $\C{\color{red}// this--{\small\textgreater}.c, this--{\small\textgreater}.i, this--{\small\textgreater}.d}$
    14431461        `t.`m; `t.`n;                                                   $\C{// must qualify}$
    14441462}
     
    14541472with the generality of opening multiple aggregate-parameters:
    14551473\begin{cfa}
    1456 void f( S & s, T & t ) `with ( s, t )` {                $\C{// multiple aggregate parameters}$
     1474int f( S & s, T & t ) `with ( s, t )` {         $\C{// multiple aggregate parameters}$
    14571475        c; i; d;                                                                $\C{\color{red}// s.c, s.i, s.d}$
    14581476        m; n;                                                                   $\C{\color{red}// t.m, t.n}$
     
    15201538\begin{cfa}
    15211539struct S { int i, j; } sv;
    1522 with ( sv ) {                                                           $\C{// implicit reference}$
     1540with ( sv ) {                                                           $\C{implicit reference}$
    15231541        S & sr = sv;
    1524         with ( sr ) {                                                   $\C{// explicit reference}$
     1542        with ( sr ) {                                                   $\C{explicit reference}$
    15251543                S * sp = &sv;
    1526                 with ( *sp ) {                                          $\C{// computed reference}$
    1527                         i = 3; j = 4;                                   $\C{\color{red}// sp--{\textgreater}i, sp--{\textgreater}j}$
     1544                with ( *sp ) {                                          $\C{computed reference}$
     1545                        i = 3; j = 4;                                   $\C{\color{red}// sp--{\small\textgreater}i, sp--{\small\textgreater}j}$
    15281546                }
    15291547                i = 2; j = 3;                                           $\C{\color{red}// sr.i, sr.j}$
     
    15751593\begin{cquote}
    15761594\lstDeleteShortInline@%
    1577 \begin{tabular}{@{}l@{\hspace{2\parindentlnth}}l@{\hspace{2\parindentlnth}}l@{}}
    1578 \multicolumn{1}{c@{\hspace{2\parindentlnth}}}{\textbf{\CFA}}    & \multicolumn{1}{c}{\textbf{C}}        \\
     1595\begin{tabular}{@{}l@{\hspace{\parindentlnth}}l@{\hspace{\parindentlnth}}l@{}}
     1596\multicolumn{1}{c@{\hspace{\parindentlnth}}}{\textbf{\CFA}}     & \multicolumn{1}{c}{\textbf{C}}        \\
    15791597\begin{cfa}
    15801598`[5] *` int x1;
     
    15911609\begin{cfa}
    15921610// array of 5 pointers to int
    1593 // pointer to array of 5 int
    1594 // function returning pointer to array of 5 int and taking int
     1611// pointer to an array of 5 int
     1612// function returning pointer to an array of 5 int and taking an int
    15951613\end{cfa}
    15961614\end{tabular}
     
    16031621\begin{cquote}
    16041622\lstDeleteShortInline@%
    1605 \begin{tabular}{@{}l@{\hspace{2\parindentlnth}}l@{}}
    1606 \multicolumn{1}{c@{\hspace{2\parindentlnth}}}{\textbf{\CFA}}    & \multicolumn{1}{c}{\textbf{C}}        \\
     1623\begin{tabular}{@{}l@{\hspace{\parindentlnth}}l@{}}
     1624\multicolumn{1}{c@{\hspace{\parindentlnth}}}{\textbf{\CFA}}     & \multicolumn{1}{c}{\textbf{C}}        \\
    16071625\begin{cfa}
    16081626`*` int x, y;
     
    16231641\begin{cquote}
    16241642\lstDeleteShortInline@%
    1625 \begin{tabular}{@{}l@{\hspace{2\parindentlnth}}l@{\hspace{2\parindentlnth}}l@{}}
    1626 \multicolumn{1}{c@{\hspace{2\parindentlnth}}}{\textbf{\CFA}}    & \multicolumn{1}{c@{\hspace{2\parindentlnth}}}{\textbf{C}}     \\
     1643\begin{tabular}{@{}l@{\hspace{\parindentlnth}}l@{\hspace{\parindentlnth}}l@{}}
     1644\multicolumn{1}{c@{\hspace{\parindentlnth}}}{\textbf{\CFA}}     & \multicolumn{1}{c@{\hspace{\parindentlnth}}}{\textbf{C}}      \\
    16271645\begin{cfa}
    16281646[ 5 ] int z;
     
    16651683\begin{cquote}
    16661684\lstDeleteShortInline@%
    1667 \begin{tabular}{@{}l@{\hspace{2\parindentlnth}}l@{\hspace{2\parindentlnth}}l@{}}
    1668 \multicolumn{1}{c@{\hspace{2\parindentlnth}}}{\textbf{\CFA}}    & \multicolumn{1}{c@{\hspace{2\parindentlnth}}}{\textbf{C}}     \\
     1685\begin{tabular}{@{}l@{\hspace{1em}}l@{\hspace{1em}}l@{}}
     1686\multicolumn{1}{c@{\hspace{1em}}}{\textbf{\CFA}}        & \multicolumn{1}{c@{\hspace{1em}}}{\textbf{C}} \\
    16691687\begin{cfa}
    16701688extern const * const int x;
    1671 static const * [5] const int y;
     1689static const * [ 5 ] const int y;
    16721690\end{cfa}
    16731691&
    16741692\begin{cfa}
    16751693int extern const * const x;
    1676 static const int (* const y)[5]
     1694static const int (* const y)[ 5 ]
    16771695\end{cfa}
    16781696&
     
    16901708\begin{cquote}
    16911709\lstDeleteShortInline@%
    1692 \begin{tabular}{@{}l@{\hspace{2\parindentlnth}}l@{}}
    1693 \multicolumn{1}{c@{\hspace{2\parindentlnth}}}{\textbf{\CFA}}    & \multicolumn{1}{c}{\textbf{C}}        \\
     1710\begin{tabular}{@{}l@{\hspace{\parindentlnth}}l@{}}
     1711\multicolumn{1}{c@{\hspace{\parindentlnth}}}{\textbf{\CFA}}     & \multicolumn{1}{c}{\textbf{C}}        \\
    16941712\begin{cfa}
    16951713y = (* int)x;
     
    17081726as well, parameter names are optional, \eg:
    17091727\begin{cfa}
    1710 [ int x ] f ( /* void */ );             $\C[2.5in]{// returning int with no parameters}$
    1711 [ int x ] f (...);                              $\C{// returning int with unknown parameters}$
    1712 [ * int ] g ( int y );                  $\C{// returning pointer to int with int parameter}$
    1713 [ void ] h ( int, char );               $\C{// returning no result with int and char parameters}$
    1714 [ * int, int ] j ( int );               $\C{// returning pointer to int and int with int parameter}$
     1728[ int x ] f ( /* void */ );                                     $\C{// returning int with no parameters}$
     1729[ int x ] f (...);                                                      $\C{// returning int with unknown parameters}$
     1730[ * int ] g ( int y );                                          $\C{// returning pointer to int with int parameter}$
     1731[ void ] h ( int, char );                                       $\C{// returning no result with int and char parameters}$
     1732[ * int, int ] j ( int );                                       $\C{// returning pointer to int and int, with int parameter}$
    17151733\end{cfa}
    17161734This syntax allows a prototype declaration to be created by cutting and pasting source text from the function-definition header (or vice versa).
     
    17181736\begin{cquote}
    17191737\lstDeleteShortInline@%
    1720 \begin{tabular}{@{}l@{\hspace{2\parindentlnth}}l@{}}
    1721 \multicolumn{1}{c@{\hspace{2\parindentlnth}}}{\textbf{\CFA}}    & \multicolumn{1}{c}{\textbf{C}}        \\
     1738\begin{tabular}{@{}l@{\hspace{\parindentlnth}}l@{}}
     1739\multicolumn{1}{c@{\hspace{\parindentlnth}}}{\textbf{\CFA}}     & \multicolumn{1}{c}{\textbf{C}}        \\
    17221740\begin{cfa}
    17231741[double] foo(), foo( int ), foo( double ) {...}
     
    17341752The syntax for pointers to \CFA functions specifies the pointer name on the right, \eg:
    17351753\begin{cfa}
    1736 * [ int x ] () fp;                              $\C{// pointer to function returning int with no parameters}$
    1737 * [ * int ] ( int y ) gp;               $\C{// pointer to function returning pointer to int with int parameter}$
    1738 * [ ] ( int, char ) hp;                 $\C{// pointer to function returning no result with int and char parameters}$
    1739 * [ * int, int ] ( int ) jp;    $\C{// pointer to function returning pointer to int and int with int parameter}$
     1754* [ int x ] () fp;                                                      $\C{// pointer to function returning int with no parameters}$
     1755* [ * int ] ( int y ) gp;                                       $\C{// pointer to function returning pointer to int with int parameter}$
     1756* [ ] ( int, char ) hp;                                         $\C{// pointer to function returning no result with int and char parameters}$
     1757* [ * int, int ] ( int ) jp;                            $\C{// pointer to function returning pointer to int and int, with int parameter}$
    17401758\end{cfa}
    17411759Note, a function name cannot be specified:
    17421760\begin{cfa}
    1743 * [ int x ] f () fp;                    $\C{// function name "f" is disallowed}\CRT$
     1761* [ int x ] f () fp;                                            $\C{// function name "f" is disallowed}$
    17441762\end{cfa}
    17451763
     
    20452063\begin{cquote}
    20462064\lstDeleteShortInline@%
    2047 \begin{tabular}{@{}l@{\hspace{2\parindentlnth}}l@{\hspace{2\parindentlnth}}l@{}}
     2065\begin{tabular}{@{}l@{\hspace{\parindentlnth}}l@{\hspace{\parindentlnth}}l@{}}
    20482066\begin{cfa}
    2049206720_`hh`     // signed char
     
    21292147        return (W){ l.stones + r.stones };
    21302148}
    2131 W |?`st|(double w) { return (W){ w }; }
    2132 W |?`lb|(double w) { return (W){ w/14.0 }; }
    2133 W |?`kg|(double w) { return (W){ w*0.16 }; }
     2149W |?`st|( double w ) { return (W){ w }; }
     2150W |?`lb|( double w ) { return (W){ w / 14.0 }; }
     2151W |?`kg|( double w ) { return (W) { w * 0.16 }; }
    21342152
    21352153
     
    21542172        return W( l.stones + r.stones );
    21552173}
    2156 W |operator""_st|(unsigned long long int w) {return W(w); }
    2157 W |operator""_lb|(unsigned long long int w) {return W(w/14.0); }
    2158 W |operator""_kg|(unsigned long long int w) {return W(w*0.16); }
    2159 W |operator""_st|(long double w ) { return W( w ); }
    2160 W |operator""_lb|(long double w ) { return W( w / 14.0 ); }
    2161 W |operator""_kg|(long double w ) { return W( w * 0.16 ); }
     2174W |operator"" _st|( unsigned long long int w ) { return W( w ); }
     2175W |operator"" _lb|( unsigned long long int w ) { return W( w / 14.0 ); }
     2176W |operator"" _kg|( unsigned long long int w ) { return W( w * 0.16 ); }
     2177W |operator"" _st|( long double w ) { return W( w ); }
     2178W |operator"" _lb|( long double w ) { return W( w / 14.0 ); }
     2179W |operator"" _kg|( long double w ) { return W( w * 0.16 ); }
    21622180int main() {
    21632181        W w, heavy = { 20 };
     
    21922210\begin{cquote}
    21932211\lstDeleteShortInline@%
    2194 \begin{tabular}{@{}l@{\hspace{2\parindentlnth}}l@{}}
    2195 \multicolumn{1}{c@{\hspace{2\parindentlnth}}}{\textbf{Definition}}      & \multicolumn{1}{c}{\textbf{Usage}}    \\
     2212\begin{tabular}{@{}l@{\hspace{\parindentlnth}}l@{}}
     2213\multicolumn{1}{c@{\hspace{\parindentlnth}}}{\textbf{Definition}}       & \multicolumn{1}{c}{\textbf{Usage}}    \\
    21962214\begin{cfa}
    21972215const short int `MIN` = -32768;
     
    22112229\begin{cquote}
    22122230\lstDeleteShortInline@%
    2213 \begin{tabular}{@{}l@{\hspace{2\parindentlnth}}l@{}}
    2214 \multicolumn{1}{c@{\hspace{2\parindentlnth}}}{\textbf{\CFA}}    & \multicolumn{1}{c}{\textbf{C}}        \\
     2231\lstset{basicstyle=\linespread{0.9}\sf\small}
     2232\begin{tabular}{@{}l@{\hspace{0.5\parindentlnth}}l@{}}
     2233\multicolumn{1}{c@{\hspace{0.5\parindentlnth}}}{\textbf{\CFA}}  & \multicolumn{1}{c}{\textbf{C}}        \\
    22152234\begin{cfa}
    22162235MIN
    2217 
    22182236MAX
    2219 
    22202237PI
    22212238E
     
    22232240&
    22242241\begin{cfa}
    2225 SCHAR_MIN, CHAR_MIN, SHRT_MIN, INT_MIN, LONG_MIN, LLONG_MIN,
    2226                 FLT_MIN, DBL_MIN, LDBL_MIN
    2227 SCHAR_MAX, UCHAR_MAX, SHRT_MAX, INT_MAX, LONG_MAX, LLONG_MAX,
    2228                 FLT_MAX, DBL_MAX, LDBL_MAX
     2242SCHAR_MIN, CHAR_MIN, SHRT_MIN, INT_MIN, LONG_MIN, LLONG_MIN, FLT_MIN, DBL_MIN, LDBL_MIN
     2243SCHAR_MAX, UCHAR_MAX, SHRT_MAX, INT_MAX, LONG_MAX, LLONG_MAX, FLT_MAX, DBL_MAX, LDBL_MAX
    22292244M_PI, M_PIl
    22302245M_E, M_El
     
    22412256\begin{cquote}
    22422257\lstDeleteShortInline@%
    2243 \begin{tabular}{@{}l@{\hspace{2\parindentlnth}}l@{}}
    2244 \multicolumn{1}{c@{\hspace{2\parindentlnth}}}{\textbf{Definition}}      & \multicolumn{1}{c}{\textbf{Usage}}    \\
     2258\begin{tabular}{@{}l@{\hspace{\parindentlnth}}l@{}}
     2259\multicolumn{1}{c@{\hspace{\parindentlnth}}}{\textbf{Definition}}       & \multicolumn{1}{c}{\textbf{Usage}}    \\
    22452260\begin{cfa}
    22462261float `log`( float x );
     
    22602275\begin{cquote}
    22612276\lstDeleteShortInline@%
    2262 \begin{tabular}{@{}l@{\hspace{2\parindentlnth}}l@{}}
    2263 \multicolumn{1}{c@{\hspace{2\parindentlnth}}}{\textbf{\CFA}}    & \multicolumn{1}{c}{\textbf{C}}        \\
     2277\begin{tabular}{@{}l@{\hspace{\parindentlnth}}l@{}}
     2278\multicolumn{1}{c@{\hspace{\parindentlnth}}}{\textbf{\CFA}}     & \multicolumn{1}{c}{\textbf{C}}        \\
    22642279\begin{cfa}
    22652280log
     
    22882303\begin{cquote}
    22892304\lstDeleteShortInline@%
    2290 \begin{tabular}{@{}l@{\hspace{2\parindentlnth}}l@{}}
    2291 \multicolumn{1}{c@{\hspace{2\parindentlnth}}}{\textbf{Definition}}      & \multicolumn{1}{c}{\textbf{Usage}}    \\
     2305\begin{tabular}{@{}l@{\hspace{\parindentlnth}}l@{}}
     2306\multicolumn{1}{c@{\hspace{\parindentlnth}}}{\textbf{Definition}}       & \multicolumn{1}{c}{\textbf{Usage}}    \\
    22922307\begin{cfa}
    22932308unsigned int `abs`( int );
     
    23072322\begin{cquote}
    23082323\lstDeleteShortInline@%
    2309 \begin{tabular}{@{}l@{\hspace{2\parindentlnth}}l@{}}
    2310 \multicolumn{1}{c@{\hspace{2\parindentlnth}}}{\textbf{\CFA}}    & \multicolumn{1}{c}{\textbf{C}}        \\
     2324\begin{tabular}{@{}l@{\hspace{\parindentlnth}}l@{}}
     2325\multicolumn{1}{c@{\hspace{\parindentlnth}}}{\textbf{\CFA}}     & \multicolumn{1}{c}{\textbf{C}}        \\
    23112326\begin{cfa}
    23122327abs
     
    23272342The following shows one example where \CFA \emph{extends} an existing standard C interface to reduce complexity and provide safety.
    23282343C/\Celeven provide a number of complex and overlapping storage-management operation to support the following capabilities:
    2329 \begin{description}%[topsep=3pt,itemsep=2pt,parsep=0pt]
     2344\begin{description}[topsep=3pt,itemsep=2pt,parsep=0pt]
    23302345\item[fill]
    23312346an allocation with a specified character.
     
    23772392\end{cfa}
    23782393\lstDeleteShortInline@%
    2379 \begin{tabular}{@{}l@{\hspace{2\parindentlnth}}l@{}}
    2380 \multicolumn{1}{c@{\hspace{2\parindentlnth}}}{\textbf{\CFA}}    & \multicolumn{1}{c}{\textbf{C}}        \\
     2394\begin{tabular}{@{}l@{\hspace{\parindentlnth}}l@{}}
     2395\multicolumn{1}{c@{\hspace{\parindentlnth}}}{\textbf{\CFA}}     & \multicolumn{1}{c}{\textbf{C}}        \\
    23812396\begin{cfa}
    23822397ip = alloc();
     
    23992414ip = (int *)malloc( sizeof( int ) ); memset( ip, fill, dim * sizeof( int ) );
    24002415ip = (int *)realloc( ip, 2 * dim * sizeof( int ) );
    2401 ip = (int *)realloc( ip, 4 * dim * sizeof( int ) );
    2402                         memset( ip, fill, 4 * dim * sizeof( int ) );
     2416ip = (int *)realloc( ip, 4 * dim * sizeof( int ) ); memset( ip, fill, 4 * dim * sizeof( int ) );
     2417
    24032418ip = memalign( 16, sizeof( int ) );
    24042419ip = memalign( 16, sizeof( int ) ); memset( ip, fill, sizeof( int ) );
     
    24372452\begin{cquote}
    24382453\lstDeleteShortInline@%
    2439 \begin{tabular}{@{}l@{\hspace{2\parindentlnth}}l@{}}
    2440 \multicolumn{1}{c@{\hspace{2\parindentlnth}}}{\textbf{\CFA}}    & \multicolumn{1}{c}{\textbf{\CC}}      \\
     2454\begin{tabular}{@{}l@{\hspace{\parindentlnth}}l@{}}
     2455\multicolumn{1}{c@{\hspace{\parindentlnth}}}{\textbf{\CFA}}     & \multicolumn{1}{c}{\textbf{\CC}}      \\
    24412456\begin{cfa}
    24422457int x = 1, y = 2, z = 3;
     
    25262541\centering
    25272542\lstDeleteShortInline@%
    2528 \begin{tabular}{@{}l@{\hspace{2\parindentlnth}}@{\hspace{2\parindentlnth}}l@{}}
    2529 \multicolumn{1}{c@{\hspace{2\parindentlnth}}}{\textbf{\CFA}}    & \multicolumn{1}{@{\hspace{2\parindentlnth}}c}{\textbf{C}}     \\
     2543\begin{tabular}{@{}l@{\hspace{\parindentlnth}}@{\hspace{\parindentlnth}}l@{}}
     2544\multicolumn{1}{c@{\hspace{\parindentlnth}}}{\textbf{\CFA}}     & \multicolumn{1}{@{\hspace{\parindentlnth}}c}{\textbf{C}}      \\
    25302545\begin{cfa}
    25312546#include <gmp>
     
    27222737Objective-C and Cyclone are two other extensions to C with different design goals than \CFA, as discussed above.
    27232738Other languages extend C with more focused features.
    2724 $\mu$\CC~\cite{uC++book}, CUDA~\cite{Nickolls08}, ispc~\cite{Pharr12}, and Sierra~\cite{Leissa14} add concurrent or data-parallel primitives to C or \CC;
    2725 data-parallel features have not yet been added to \CFA, but are easily incorporated within its design, while concurrency primitives similar to those in $\mu$\CC have already been added~\cite{Delisle18}.
    2726 Finally, CCured~\cite{Necula02} and Ironclad \CC~\cite{DeLozier13} attempt to provide a more memory-safe C by annotating pointer types with garbage collection information; type-checked polymorphism in \CFA covers several of C's memory-safety issues, but more aggressive approaches such as annotating all pointer types with their nullability or requiring runtime garbage collection are contradictory to \CFA's backwards compatibility goals.
     2739CUDA~\cite{Nickolls08}, ispc~\cite{Pharr12}, and Sierra~\cite{Leissa14} add data-parallel primitives to C or \CC;
     2740such features have not yet been added to \CFA, but are easily incorporated within its design.
     2741Finally, some C extensions (or suggested extensions) attempt to provide a more memory-safe C~\cite{Boehm88,Rafkind09};
     2742type-checked polymorphism in \CFA covers several of C's memory-safety issues, but more aggressive approaches such as annotating all pointer types with their nullability are contradictory to \CFA's backwards compatibility goals.
    27272743
    27282744
     
    27732789\section{Acknowledgments}
    27742790
    2775 The authors would like to recognize the design assistance of Glen Ditchfield, Richard Bilson, Thierry Delisle, Andrew Beach and Brice Dobry on the features described in this paper, and thank Magnus Madsen for feedback on the writing.
    2776 This work is supported by a corporate partnership with Huawei Ltd.\ (\url{http://www.huawei.com}), and Aaron Moss and Peter Buhr are partially funded by the Natural Sciences and Engineering Research Council of Canada.
    2777 
    2778 
     2791The authors would like to recognize the design assistance of Glen Ditchfield, Richard Bilson, Thierry Delisle, and Andrew Beach on the features described in this paper, and thank Magnus Madsen for feedback in the writing.
     2792This work is supported through a corporate partnership with Huawei Ltd.\ (\url{http://www.huawei.com}), and Aaron Moss and Peter Buhr are partially funded by the Natural Sciences and Engineering Research Council of Canada.
     2793
     2794% the first author's \grantsponsor{NSERC-PGS}{NSERC PGS D}{http://www.nserc-crsng.gc.ca/Students-Etudiants/PG-CS/BellandPostgrad-BelletSuperieures_eng.asp} scholarship.
     2795
     2796
     2797\bibliographystyle{plain}
    27792798\bibliography{pl}
    27802799
     
    27842803\section{Benchmark Stack Implementation}
    27852804\label{sec:BenchmarkStackImplementation}
     2805
     2806\lstset{basicstyle=\linespread{0.9}\sf\small}
    27862807
    27872808Throughout, @/***/@ designates a counted redundant type annotation; code reformatted for brevity.
Note: See TracChangeset for help on using the changeset viewer.