Changeset 49eb6a2 for doc/papers/general
- Timestamp:
- Mar 11, 2018, 11:51:09 PM (7 years ago)
- Branches:
- ADT, aaron-thesis, arm-eh, ast-experimental, cleanup-dtors, deferred_resn, demangler, enum, forall-pointer-decay, jacob/cs343-translation, jenkins-sandbox, master, new-ast, new-ast-unique-expr, new-env, no_list, persistent-indexer, pthread-emulation, qualifiedEnum, resolv-new, with_gc
- Children:
- 53dece1
- Parents:
- 200b2b5
- Location:
- doc/papers/general
- Files:
-
- 117 added
- 2 edited
Legend:
- Unmodified
- Added
- Removed
-
doc/papers/general/Makefile
r200b2b5 r49eb6a2 3 3 Build = build 4 4 Figures = figures 5 Macros = ../../LaTeXmacros5 Macros = AMA/AMA-stix/ama 6 6 TeXLIB = .:${Macros}:${Build}:../../bibliography: 7 7 LaTeX = TEXINPUTS=${TeXLIB} && export TEXINPUTS && latex -halt-on-error -output-directory=${Build} 8 8 BibTeX = BIBINPUTS=${TeXLIB} && export BIBINPUTS && bibtex 9 9 10 MAKEFLAGS = --no-print-directory --silent #10 MAKEFLAGS = --no-print-directory # --silent 11 11 VPATH = ${Build} ${Figures} evaluation 12 12 … … 50 50 51 51 ${basename ${DOCUMENT}}.ps : ${basename ${DOCUMENT}}.dvi 52 dvips ${Build}/$< -o $@52 dvips -h ${Build}/Paper.out.ps -o $@ ${Build}/$< 53 53 54 54 ${basename ${DOCUMENT}}.dvi : Makefile ${Build} ${GRAPHS} ${PROGRAMS} ${PICTURES} ${FIGURES} ${SOURCES} \ 55 ${Macros}/common.tex ${Macros}/indexstyle../../bibliography/pl.bib55 ../../bibliography/pl.bib 56 56 # Must have *.aux file containing citations for bibtex 57 57 if [ ! -r ${basename $@}.aux ] ; then ${LaTeX} ${basename $@}.tex ; fi 58 -${BibTeX} ${Build}/${basename $@}58 ${BibTeX} ${Build}/${basename $@} 59 59 # Some citations reference others so run again to resolve these citations 60 60 ${LaTeX} ${basename $@}.tex 61 -${BibTeX} ${Build}/${basename $@}61 ${BibTeX} ${Build}/${basename $@} 62 62 # Run again to finish citations 63 63 ${LaTeX} ${basename $@}.tex -
doc/papers/general/Paper.tex
r200b2b5 r49eb6a2 1 \documentclass{article} 1 \documentclass[AMA,STIX1COL]{WileyNJD-v2} 2 %\documentclass{article} 3 4 \articletype{RESEARCH ARTICLE}% 5 6 \received{26 April 2016} 7 \revised{6 June 2016} 8 \accepted{6 June 2016} 9 10 \raggedbottom 2 11 3 12 \usepackage{fullpage} … … 8 17 \usepackage{enumitem} 9 18 \setlist[itemize]{topsep=3pt,itemsep=2pt,parsep=0pt}% global 10 \usepackage[flushmargin]{footmisc} % support label/reference in footnote11 19 \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 20 \definecolor{ForestGreen}{cmyk}{1, 0, 0.99995, 0} 21 \hypersetup{breaklinks=true} 22 23 \usepackage[pagewise]{lineno} 24 \renewcommand{\linenumberfont}{\scriptsize\sffamily} 25 26 \setlength{\topmargin}{-0.75in}\setlength{\headsep}{0.5in}\setlength{\footskip}{0.25in} 27 \setlength{\textheight}{9.325in} 28 \setlength{\textwidth}{6.75in} 29 \setlength{\evensidemargin}{-0.25in} 30 \setlength{\oddsidemargin}{-0.25in} 24 31 25 32 \lefthyphenmin=4 % hyphen only after 4 characters … … 64 71 \newlength{\gcolumnposn} % temporary hack because lstlisting does not handle tabs correctly 65 72 \newlength{\columnposn} 66 \setlength{\gcolumnposn}{ 2.75in}73 \setlength{\gcolumnposn}{3.5in} 67 74 \setlength{\columnposn}{\gcolumnposn} 68 75 \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}}}} … … 96 103 {\ETC.\xspace}% 97 104 }% 98 \newcommand{\ETAL}{\abbrevFont{et}~\abbrevFont{al}}99 \newcommand*{\etal}{%100 \@ifnextchar{.}{\protect\ETAL}%101 {\protect\ETAL.\xspace}%102 }%105 %\newcommand{\ETAL}{\abbrevFont{et}~\abbrevFont{al}} 106 %\newcommand*{\etal}{% 107 % \@ifnextchar{.}{\protect\ETAL}% 108 % {\protect\ETAL.\xspace}% 109 %}% 103 110 \newcommand{\VIZ}{\abbrevFont{viz}} 104 111 \newcommand*{\viz}{% … … 145 152 belowskip=3pt, 146 153 % replace/adjust listing characters that look bad in sanserif 147 literate={-}{\makebox[1ex][c]{\raisebox{0.4ex}{\rule{0.8ex}{0.1ex}}}}1 {^}{\raisebox{0.6ex}{$\scripts criptstyle\land\,$}}1148 {~}{\raisebox{0.3ex}{$\scriptstyle\sim\,$}}1 {@}{\small{@}}1 {<}{\small{\textless}}1 {>}{\small{\textgreater}}1% {`}{\ttfamily\upshape\hspace*{-0.1ex}`}1149 {<-}{$\leftarrow$}2 {=>}{$\Rightarrow$}2 {->}{\makebox[1ex][c]{\raisebox{0. 4ex}{\rule{0.8ex}{0.075ex}}}\kern-0.2ex{\small\textgreater}}2,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, 150 157 moredelim=**[is][\color{red}]{`}{`}, 151 158 }% lstset 152 153 % inline code @...@154 \lstMakeShortInline@%155 159 156 160 \lstnewenvironment{cfa}[1][] … … 162 166 163 167 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 168 \begin{document} 184 \maketitle 185 186 187 \begin{abstract} 169 \linenumbers % comment out to turn off line numbering 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{*Aaron Moss, \email{a3moss@uwaterloo.ca}} 180 \corres{*Peter A. Buhr, \email{pabuhr@uwaterloo.ca}} 181 \presentaddress{David R. Cheriton School of Computer Science, University of Waterloo, Waterloo, ON, N2L 3G1, Canada} 182 183 % inline code @...@ 184 \lstMakeShortInline@% 185 186 187 \abstract[Summary]{ 188 188 The 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. 189 189 This installation base and the programmers producing it represent a massive software-engineering investment spanning decades and likely to continue for decades more. … … 195 195 This paper presents a quick tour of \CFA features showing how their design avoids shortcomings of similar features in C and other C-like languages. 196 196 Finally, experimental results are presented to validate several of the new features. 197 \end{abstract} 197 }% 198 199 \keywords{generic types, tuple types, variadic types, polymorphic functions, C, Cforall} 200 201 \maketitle 198 202 199 203 … … 230 234 \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). 231 235 Ultimately, a compiler is necessary for advanced features and optimal performance. 232 All of the features discussed in this paper are working, unless a feature states it is a future feature for completion.236 All features discussed in this paper are working, unless otherwise stated as under construction. 233 237 234 238 Finally, it is impossible to describe a programming language without usages before definitions. … … 258 262 259 263 \begin{cfa} 260 int max = 2147483647; $\C[3.75in]{// (1)}$264 int max = 2147483647; $\C[4in]{// (1)}$ 261 265 double max = 1.7976931348623157E+308; $\C{// (2)}$ 262 266 int max( int a, int b ) { return a < b ? b : a; } $\C{// (3)}$ 263 267 double max( double a, double b ) { return a < b ? b : a; } $\C{// (4)}\CRT$ 264 max( 7, -max ); $\C{// uses (3) and (1), by matching int from constant 7}$265 max( max, 3.14 ); 266 max( max, -max ); 267 int m = max( max, -max ); $\C{// uses (3) and (1) twice, by matching return type}$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$ 268 272 \end{cfa} 269 273 … … 292 296 \begin{cfa} 293 297 `forall( otype T )` T identity( T val ) { return val; } 294 int forty_two = identity( 42 ); 298 int forty_two = identity( 42 ); $\C{// T is bound to int, forty\_two == 42}$ 295 299 \end{cfa} 296 300 This @identity@ function can be applied to any complete \newterm{object type} (or @otype@). … … 306 310 For example, the function @twice@ can be defined using the \CFA syntax for operator overloading: 307 311 \begin{cfa} 308 forall( otype T `| { T ?+?(T, T); }` ) T twice( T x ) { return x `+` x; } 312 forall( otype T `| { T ?+?(T, T); }` ) T twice( T x ) { return x `+` x; } $\C{// ? denotes operands}$ 309 313 int val = twice( twice( 3.7 ) ); 310 314 \end{cfa} … … 325 329 } 326 330 double key = 5.0, vals[10] = { /* 10 sorted float values */ }; 327 double * val = (double *)bsearch( &key, vals, 10, sizeof(vals[0]), comp ); 331 double * val = (double *)bsearch( &key, vals, 10, sizeof(vals[0]), comp ); $\C{// search sorted array}$ 328 332 \end{cfa} 329 333 which can be augmented simply with a generalized, type-safe, \CFA-overloaded wrappers: … … 335 339 forall( otype T | { int ?<?( T, T ); } ) unsigned int bsearch( T key, const T * arr, size_t size ) { 336 340 T * result = bsearch( key, arr, size ); $\C{// call first version}$ 337 return result ? result - arr : size; 338 } 339 double * val = bsearch( 5.0, vals, 10 ); 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}$ 340 344 int posn = bsearch( 5.0, vals, 10 ); 341 345 \end{cfa} … … 361 365 forall( otype T | { int ?<?( T, T ); } ) void qsort( const T * arr, size_t size ) { /* use C qsort */ } 362 366 { 363 int ?<?( double x, double y ) { return x `>` y; } 367 int ?<?( double x, double y ) { return x `>` y; } $\C{// locally override behaviour}$ 364 368 qsort( vals, size ); $\C{// descending sort}$ 365 369 } … … 368 372 Hence, programmers can easily form local environments, adding and modifying appropriate functions, to maximize reuse of other existing functions and types. 369 373 370 Unconstruction is a mechanism to distribute @forall@ over related routines/types (see @stack@ examples in Section~\ref{sec:eval}): 371 \begin{cfa} 372 forall( 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} 378 Each block declaration is prefixed with the initial @forall@ clause significantly reducing duplication. 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} 379 382 380 383 … … 388 391 T ?+=?( T *, T ); 389 392 T ++?( T * ); 390 T ?++( T * ); };391 393 T ?++( T * ); 394 }; 392 395 forall( otype T `| summable( T )` ) T sum( T a[$\,$], size_t size ) { // use trait 393 396 `T` total = { `0` }; $\C{// instantiate T from 0 by calling its constructor}$ 394 397 for ( unsigned int i = 0; i < size; i += 1 ) total `+=` a[i]; $\C{// select appropriate +}$ 395 return total; } 398 return total; 399 } 396 400 \end{cfa} 397 401 … … 402 406 void ?{}( T &, T ); $\C{// copy constructor}$ 403 407 void ?=?( T &, T ); $\C{// assignment operator}$ 404 void ^?{}( T & ); }; $\C{// destructor}$ 408 void ^?{}( T & ); $\C{// destructor}$ 409 }; 405 410 \end{cfa} 406 411 Given 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. … … 654 659 p`->0` = 5; $\C{// change quotient}$ 655 660 bar( qr`.1`, qr ); $\C{// pass remainder and quotient/remainder}$ 656 rem = [div( 13, 5 ), 42]`.0.1`; $\C{// access 2nd component of 1st component of tuple expression}$661 rem = [div( 13, 5 ), 42]`.0.1`; $\C{// access 2nd component of 1st component}$ 657 662 \end{cfa} 658 663 … … 663 668 Tuple flattening recursively expands a tuple into the list of its basic components. 664 669 Tuple structuring packages a list of expressions into a value of tuple type, \eg: 665 %\lstDeleteShortInline@%666 %\par\smallskip667 %\begin{tabular}{@{}l@{\hspace{1.5\parindent}}||@{\hspace{1.5\parindent}}l@{}}668 670 \begin{cfa} 669 671 int f( int, int ); … … 672 674 [int, int] x; 673 675 int y; 674 f( x ); $\C{// flatten}$ 675 g( y, 10 ); $\C{// structure}$ 676 h( 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@% 676 f( x ); $\C{// flatten}$ 677 g( y, 10 ); $\C{// structure}$ 678 h( x, y ); $\C{// flatten and structure}$ 679 \end{cfa} 684 680 In the call to @f@, @x@ is implicitly flattened so the components of @x@ are passed as the two arguments. 685 681 In 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@. … … 692 688 An assignment where the left side is a tuple type is called \newterm{tuple assignment}. 693 689 There 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\smallskip696 %\begin{tabular}{@{}l@{\hspace{1.5\parindent}}||@{\hspace{1.5\parindent}}l@{}}697 690 \begin{cfa} 698 691 int x = 10; … … 704 697 [y, x] = 3.14; $\C{// mass assignment}$ 705 698 \end{cfa} 706 %\end{cfa}707 %&708 %\begin{cfa}709 %\end{tabular}710 %\smallskip\par\noindent711 %\lstMakeShortInline@%712 699 Both kinds of tuple assignment have parallel semantics, so that each value on the left and right side is evaluated before any assignments occur. 713 700 As 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]@. … … 733 720 Here, the mass assignment sets all members of @s@ to zero. 734 721 Since 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\smallskip737 %\begin{tabular}{@{}l@{\hspace{1.5\parindent}}||@{\hspace{1.5\parindent}}l@{}}738 722 \begin{cfa} 739 723 [int, int, long, double] x; … … 743 727 [int, int, int] y = x.[2, 0, 2]; $\C{// duplicate: [y.0, y.1, y.2] = [x.2, x.0.x.2]}$ 744 728 \end{cfa} 745 %\end{cfa}746 %&747 %\begin{cfa}748 %\end{tabular}749 %\smallskip\par\noindent750 %\lstMakeShortInline@%751 729 It is also possible for a member access to contain other member accesses, \eg: 752 730 \begin{cfa} … … 1146 1124 \end{figure} 1147 1125 1148 Finally, @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} 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 1150 1132 \lstDeleteShortInline@% 1151 1133 \begin{tabular}{@{}l@{\hspace{2\parindentlnth}}l@{}} … … 1169 1151 case 4: 1170 1152 ... `fallthrough common;` 1171 common: // below fallthrough a nd at same level as case clauses1153 common: // below fallthrough at same level as case clauses 1172 1154 ... // common code for cases 3 and 4 1173 1155 // implicit break … … 1176 1158 \end{tabular} 1177 1159 \lstMakeShortInline@% 1178 \ end{cquote}1179 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; 1180 the target label may be case @default@. 1160 \caption{\lstinline|fallthrough| Statement} 1161 \label{f:FallthroughStatement} 1162 \end{figure} 1181 1163 1182 1164 Collectively, these control-structure enhancements reduce programmer burden and increase readability and safety. … … 1310 1292 R r; 1311 1293 ... `resume( r );` ... 1312 ... r.fix // control does returnhere after handler1294 ... r.fix // control returns here after handler 1313 1295 } 1314 1296 `try` { … … 1423 1405 1424 1406 1425 \subsection{\texorpdfstring{\protect\lstinline{with} Clause / Statement}{with Clause /Statement}}1426 \label{s:With ClauseStatement}1407 \subsection{\texorpdfstring{\protect\lstinline{with} Statement}{with Statement}} 1408 \label{s:WithStatement} 1427 1409 1428 1410 Grouping 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: … … 1444 1426 A similar situation occurs in object-oriented programming, \eg \CC: 1445 1427 \begin{C++} 1446 class C{1428 struct S { 1447 1429 char c; $\C{// fields}$ 1448 1430 int i; 1449 1431 double d; 1450 intf() { $\C{// implicit ``this'' aggregate}$1432 void f() { $\C{// implicit ``this'' aggregate}$ 1451 1433 `this->`c; `this->`i; `this->`d; $\C{// access containing fields}$ 1452 1434 } 1453 1435 } 1454 1436 \end{C++} 1455 Object-oriented nesting of member functions in a \lstinline[language=C++]@class @ allows eliding \lstinline[language=C++]@this->@ because of lexical scoping.1437 Object-oriented nesting of member functions in a \lstinline[language=C++]@class/struct@ allows eliding \lstinline[language=C++]@this->@ because of lexical scoping. 1456 1438 However, for other aggregate parameters, qualification is necessary: 1457 1439 \begin{cfa} 1458 1440 struct T { double m, n; }; 1459 int 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}$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}$ 1461 1443 `t.`m; `t.`n; $\C{// must qualify}$ 1462 1444 } … … 1472 1454 with the generality of opening multiple aggregate-parameters: 1473 1455 \begin{cfa} 1474 intf( S & s, T & t ) `with ( s, t )` { $\C{// multiple aggregate parameters}$1456 void f( S & s, T & t ) `with ( s, t )` { $\C{// multiple aggregate parameters}$ 1475 1457 c; i; d; $\C{\color{red}// s.c, s.i, s.d}$ 1476 1458 m; n; $\C{\color{red}// t.m, t.n}$ … … 1538 1520 \begin{cfa} 1539 1521 struct S { int i, j; } sv; 1540 with ( sv ) { $\C{ implicit reference}$1522 with ( sv ) { $\C{// implicit reference}$ 1541 1523 S & sr = sv; 1542 with ( sr ) { $\C{ explicit reference}$1524 with ( sr ) { $\C{// explicit reference}$ 1543 1525 S * sp = &sv; 1544 with ( *sp ) { $\C{ computed reference}$1545 i = 3; j = 4; $\C{\color{red}// sp--{\ small\textgreater}i, sp--{\small\textgreater}j}$1526 with ( *sp ) { $\C{// computed reference}$ 1527 i = 3; j = 4; $\C{\color{red}// sp--{\textgreater}i, sp--{\textgreater}j}$ 1546 1528 } 1547 1529 i = 2; j = 3; $\C{\color{red}// sr.i, sr.j}$ … … 1609 1591 \begin{cfa} 1610 1592 // array of 5 pointers to int 1611 // pointer to a n array of 5 int1612 // function returning pointer to a n array of 5 int and taking anint1593 // pointer to array of 5 int 1594 // function returning pointer to array of 5 int and taking int 1613 1595 \end{cfa} 1614 1596 \end{tabular} … … 1687 1669 \begin{cfa} 1688 1670 extern const * const int x; 1689 static const * [ 5] const int y;1671 static const * [5] const int y; 1690 1672 \end{cfa} 1691 1673 & 1692 1674 \begin{cfa} 1693 1675 int extern const * const x; 1694 static const int (* const y)[ 5]1676 static const int (* const y)[5] 1695 1677 \end{cfa} 1696 1678 & … … 1726 1708 as well, parameter names are optional, \eg: 1727 1709 \begin{cfa} 1728 [ int x ] f ( /* void */ ); $\C{// returning int with no parameters}$1729 [ int x ] f (...); 1730 [ * int ] g ( int y ); 1731 [ void ] h ( int, char ); 1732 [ * int, int ] j ( int ); $\C{// returning pointer to int and int,with int parameter}$1710 [ int x ] f ( /* void */ ); $\C[2in]{// 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}$ 1733 1715 \end{cfa} 1734 1716 This syntax allows a prototype declaration to be created by cutting and pasting source text from the function-definition header (or vice versa). … … 1752 1734 The syntax for pointers to \CFA functions specifies the pointer name on the right, \eg: 1753 1735 \begin{cfa} 1754 * [ int x ] () fp; 1755 * [ * int ] ( int y ) gp; 1756 * [ ] ( int, char ) hp; 1757 * [ * int, int ] ( int ) jp; $\C{// pointer to function returning pointer to int and int,with int parameter}$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}$ 1758 1740 \end{cfa} 1759 1741 Note, a function name cannot be specified: 1760 1742 \begin{cfa} 1761 * [ int x ] f () fp; $\C{// function name "f" is disallowed}$1743 * [ int x ] f () fp; $\C{// function name "f" is disallowed}\CRT$ 1762 1744 \end{cfa} 1763 1745 … … 2147 2129 return (W){ l.stones + r.stones }; 2148 2130 } 2149 W |?`st|( double w) { return (W){ w }; }2150 W |?`lb|( double w ) { return (W){ w /14.0 }; }2151 W |?`kg|( double w ) { return (W) { w *0.16 }; }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 }; } 2152 2134 2153 2135 … … 2172 2154 return W( l.stones + r.stones ); 2173 2155 } 2174 W |operator"" _st|( unsigned long long int w ) { return W( w); }2175 W |operator"" _lb|( unsigned long long int w ) { return W( w / 14.0); }2176 W |operator"" _kg|( unsigned long long int w ) { return W( w * 0.16); }2177 W |operator"" _st|(long double w ) { return W( w ); }2178 W |operator"" _lb|(long double w ) { return W( w / 14.0 ); }2179 W |operator"" _kg|(long double w ) { return W( w * 0.16 ); }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 ); } 2180 2162 int main() { 2181 2163 W w, heavy = { 20 }; … … 2210 2192 \begin{cquote} 2211 2193 \lstDeleteShortInline@% 2212 \begin{tabular}{@{}l@{\hspace{ \parindentlnth}}l@{}}2213 \multicolumn{1}{c@{\hspace{ \parindentlnth}}}{\textbf{Definition}} & \multicolumn{1}{c}{\textbf{Usage}} \\2194 \begin{tabular}{@{}l@{\hspace{2\parindentlnth}}l@{}} 2195 \multicolumn{1}{c@{\hspace{2\parindentlnth}}}{\textbf{Definition}} & \multicolumn{1}{c}{\textbf{Usage}} \\ 2214 2196 \begin{cfa} 2215 2197 const short int `MIN` = -32768; … … 2229 2211 \begin{cquote} 2230 2212 \lstDeleteShortInline@% 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}} \\ 2213 \begin{tabular}{@{}l@{\hspace{2\parindentlnth}}l@{}} 2214 \multicolumn{1}{c@{\hspace{2\parindentlnth}}}{\textbf{\CFA}} & \multicolumn{1}{c}{\textbf{C}} \\ 2234 2215 \begin{cfa} 2235 2216 MIN 2217 2236 2218 MAX 2219 2237 2220 PI 2238 2221 E … … 2240 2223 & 2241 2224 \begin{cfa} 2242 SCHAR_MIN, CHAR_MIN, SHRT_MIN, INT_MIN, LONG_MIN, LLONG_MIN, FLT_MIN, DBL_MIN, LDBL_MIN 2243 SCHAR_MAX, UCHAR_MAX, SHRT_MAX, INT_MAX, LONG_MAX, LLONG_MAX, FLT_MAX, DBL_MAX, LDBL_MAX 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 2244 2229 M_PI, M_PIl 2245 2230 M_E, M_El … … 2256 2241 \begin{cquote} 2257 2242 \lstDeleteShortInline@% 2258 \begin{tabular}{@{}l@{\hspace{ \parindentlnth}}l@{}}2259 \multicolumn{1}{c@{\hspace{ \parindentlnth}}}{\textbf{Definition}} & \multicolumn{1}{c}{\textbf{Usage}} \\2243 \begin{tabular}{@{}l@{\hspace{2\parindentlnth}}l@{}} 2244 \multicolumn{1}{c@{\hspace{2\parindentlnth}}}{\textbf{Definition}} & \multicolumn{1}{c}{\textbf{Usage}} \\ 2260 2245 \begin{cfa} 2261 2246 float `log`( float x ); … … 2275 2260 \begin{cquote} 2276 2261 \lstDeleteShortInline@% 2277 \begin{tabular}{@{}l@{\hspace{ \parindentlnth}}l@{}}2278 \multicolumn{1}{c@{\hspace{ \parindentlnth}}}{\textbf{\CFA}} & \multicolumn{1}{c}{\textbf{C}} \\2262 \begin{tabular}{@{}l@{\hspace{2\parindentlnth}}l@{}} 2263 \multicolumn{1}{c@{\hspace{2\parindentlnth}}}{\textbf{\CFA}} & \multicolumn{1}{c}{\textbf{C}} \\ 2279 2264 \begin{cfa} 2280 2265 log … … 2303 2288 \begin{cquote} 2304 2289 \lstDeleteShortInline@% 2305 \begin{tabular}{@{}l@{\hspace{ \parindentlnth}}l@{}}2306 \multicolumn{1}{c@{\hspace{ \parindentlnth}}}{\textbf{Definition}} & \multicolumn{1}{c}{\textbf{Usage}} \\2290 \begin{tabular}{@{}l@{\hspace{2\parindentlnth}}l@{}} 2291 \multicolumn{1}{c@{\hspace{2\parindentlnth}}}{\textbf{Definition}} & \multicolumn{1}{c}{\textbf{Usage}} \\ 2307 2292 \begin{cfa} 2308 2293 unsigned int `abs`( int ); … … 2322 2307 \begin{cquote} 2323 2308 \lstDeleteShortInline@% 2324 \begin{tabular}{@{}l@{\hspace{ \parindentlnth}}l@{}}2325 \multicolumn{1}{c@{\hspace{ \parindentlnth}}}{\textbf{\CFA}} & \multicolumn{1}{c}{\textbf{C}} \\2309 \begin{tabular}{@{}l@{\hspace{2\parindentlnth}}l@{}} 2310 \multicolumn{1}{c@{\hspace{2\parindentlnth}}}{\textbf{\CFA}} & \multicolumn{1}{c}{\textbf{C}} \\ 2326 2311 \begin{cfa} 2327 2312 abs … … 2414 2399 ip = (int *)malloc( sizeof( int ) ); memset( ip, fill, dim * sizeof( int ) ); 2415 2400 ip = (int *)realloc( ip, 2 * dim * sizeof( int ) ); 2416 ip = (int *)realloc( ip, 4 * dim * sizeof( int ) ); memset( ip, fill, 4 * dim * sizeof( int ) );2417 2401 ip = (int *)realloc( ip, 4 * dim * sizeof( int ) ); 2402 memset( ip, fill, 4 * dim * sizeof( int ) ); 2418 2403 ip = memalign( 16, sizeof( int ) ); 2419 2404 ip = memalign( 16, sizeof( int ) ); memset( ip, fill, sizeof( int ) ); … … 2788 2773 \section{Acknowledgments} 2789 2774 2790 The 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. 2791 This 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. 2792 2793 % 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. 2794 2795 2796 \bibliographystyle{plain} 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 2797 2779 \bibliography{pl} 2798 2780 … … 2802 2784 \section{Benchmark Stack Implementation} 2803 2785 \label{sec:BenchmarkStackImplementation} 2804 2805 \lstset{basicstyle=\linespread{0.9}\sf\small}2806 2786 2807 2787 Throughout, @/***/@ designates a counted redundant type annotation; code reformatted for brevity.
Note: See TracChangeset
for help on using the changeset viewer.