Changeset c8ad5d9 for doc/papers/general/Paper.tex
- Timestamp:
- Apr 22, 2018, 9:49:50 AM (6 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, with_gc
- Children:
- 22bdc34, da7fe39
- Parents:
- 58caf150
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
doc/papers/general/Paper.tex
r58caf150 rc8ad5d9 1 \documentclass[AMA,STIX1COL,STIXSMALL]{WileyNJD-v2} 1 \documentclass[AMA,STIX1COL]{WileyNJD-v2} 2 2 3 \articletype{RESEARCH ARTICLE}% 3 4 … … 17 18 \usepackage{upquote} % switch curled `'" to straight 18 19 \usepackage{listings} % format program code 20 \captionsetup{justification=raggedright,singlelinecheck=false} 19 21 %\usepackage{enumitem} 20 22 %\setlist[itemize]{topsep=3pt,itemsep=2pt,parsep=0pt}% global … … 27 29 \renewcommand{\linenumberfont}{\scriptsize\sffamily} 28 30 29 \lefthyphenmin= 4% hyphen only after 4 characters30 \righthyphenmin= 431 \lefthyphenmin=3 % hyphen only after 4 characters 32 \righthyphenmin=3 31 33 32 34 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% … … 86 88 \newcommand{\abbrevFont}{\textit} % set empty for no italics 87 89 \@ifundefined{eg}{ 88 \newcommand{\EG}{\abbrevFont{e} .\abbrevFont{g}.}90 \newcommand{\EG}{\abbrevFont{e}\abbrevFont{g}} 89 91 \newcommand*{\eg}{% 90 92 \@ifnextchar{,}{\EG}% … … 93 95 }}{}% 94 96 \@ifundefined{ie}{ 95 \newcommand{\IE}{\abbrevFont{i} .\abbrevFont{e}.}97 \newcommand{\IE}{\abbrevFont{i}\abbrevFont{e}} 96 98 \newcommand*{\ie}{% 97 99 \@ifnextchar{,}{\IE}% … … 129 131 \lstdefinelanguage{CFA}[ANSI]{C}{ 130 132 morekeywords={ 131 _Alignas, _Alignof, __alignof, __alignof__, asm, __asm, __asm__, _At, __attribute, 132 __attribute__, auto, _Bool, catch, catchResume, choose, _Complex, __complex, __complex__, 133 __const, __const__, disable, dtype, enable, exception, __extension__, fallthrough, fallthru, 134 finally, forall, ftype, _Generic, _Imaginary, inline, __label__, lvalue, _Noreturn, one_t, 135 otype, restrict, _Static_assert, throw, throwResume, trait, try, ttype, typeof, __typeof, 136 __typeof__, virtual, with, zero_t}, 137 morekeywords=[2]{ 138 _Atomic, coroutine, is_coroutine, is_monitor, is_thread, monitor, mutex, nomutex, or, 139 resume, suspend, thread, _Thread_local, waitfor, when, yield}, 133 _Alignas, _Alignof, __alignof, __alignof__, asm, __asm, __asm__, __attribute, __attribute__, 134 auto, _Bool, catch, catchResume, choose, _Complex, __complex, __complex__, __const, __const__, 135 coroutine, disable, dtype, enable, exception, __extension__, fallthrough, fallthru, finally, 136 __float80, float80, __float128, float128, forall, ftype, _Generic, _Imaginary, __imag, __imag__, 137 inline, __inline, __inline__, __int128, int128, __label__, monitor, mutex, _Noreturn, one_t, or, 138 otype, restrict, __restrict, __restrict__, __signed, __signed__, _Static_assert, thread, 139 _Thread_local, throw, throwResume, timeout, trait, try, ttype, typeof, __typeof, __typeof__, 140 virtual, __volatile, __volatile__, waitfor, when, with, zero_t}, 140 141 moredirectives={defined,include_next}% 141 142 } … … 158 159 literate={-}{\makebox[1ex][c]{\raisebox{0.4ex}{\rule{0.8ex}{0.1ex}}}}1 {^}{\raisebox{0.6ex}{$\scriptstyle\land\,$}}1 159 160 {~}{\raisebox{0.3ex}{$\scriptstyle\sim\,$}}1 % {`}{\ttfamily\upshape\hspace*{-0.1ex}`}1 160 {<-}{$\leftarrow$}2 {=>}{$\Rightarrow$}2 {->}{\makebox[1ex][c]{\raisebox{0. 5ex}{\rule{0.8ex}{0.075ex}}}\kern-0.2ex{\textgreater}}2,161 {<-}{$\leftarrow$}2 {=>}{$\Rightarrow$}2 {->}{\makebox[1ex][c]{\raisebox{0.4ex}{\rule{0.8ex}{0.075ex}}}\kern-0.2ex{\textgreater}}2, 161 162 moredelim=**[is][\color{red}]{`}{`}, 162 163 }% lstset … … 180 181 \authormark{MOSS \textsc{et al}} 181 182 182 \address[1]{\orgdiv{ David R. Cheriton School of Computer Science}, \orgname{University of Waterloo}, \orgaddress{\state{Ontario}, \country{Canada}}}183 184 \corres{*Peter A. Buhr, \email{pabuhr{\char`\@}uwaterloo.ca}}185 \presentaddress{David R. Cheriton School of Computer Science, University of Waterloo, Waterloo, ON, N2L 3G1, Canada} 186 183 \address[1]{\orgdiv{Cheriton School of Computer Science}, \orgname{University of Waterloo}, \orgaddress{\state{Waterloo, ON}, \country{Canada}}} 184 185 \corres{*Peter A. Buhr, Cheriton School of Computer Science, University of Waterloo, 200 University Avenue West, Waterloo, ON, N2L 3G1, Canada. \email{pabuhr{\char`\@}uwaterloo.ca}} 186 187 \fundingInfo{Natural Sciences and Engineering Research Council of Canada} 187 188 188 189 \abstract[Summary]{ … … 228 229 Nevertheless, C, first standardized over thirty years ago, lacks many features that make programming in more modern languages safer and more productive. 229 230 230 \CFA (pronounced ``C-for-all'', and written \CFA or Cforall) is an evolutionary extension of the C programming language that aims to add modern language features to C while maintaining both source compatibility with C and a familiar programming model for programmers.231 \CFA (pronounced ``C-for-all'', and written \CFA or Cforall) is an evolutionary extension of the C programming language that aims to add modern language features to C, while maintaining both source and runtime compatibility with C and a familiar programming model for programmers. 231 232 The four key design goals for \CFA~\cite{Bilson03} are: 232 233 (1) The behaviour of standard C code must remain the same when translated by a \CFA compiler as when translated by a C compiler; … … 328 329 A simple example is leveraging the existing type-unsafe (@void *@) C @bsearch@ to binary search a sorted float array: 329 330 \begin{cfa} 330 void * bsearch( const void * key, const void * base, size_t nmemb, size_t size, 331 int (* compar)( const void *, const void * )); 331 void * bsearch( const void * key, const void * base, size_t nmemb, size_t size, int (* compar)( const void *, const void * )); 332 332 int comp( const void * t1, const void * t2 ) { 333 333 return *(double *)t1 < *(double *)t2 ? -1 : *(double *)t2 < *(double *)t1 ? 1 : 0; … … 336 336 double * val = (double *)bsearch( &key, vals, 10, sizeof(vals[0]), comp ); $\C{// search sorted array}$ 337 337 \end{cfa} 338 which can be augmented simply with ageneralized, type-safe, \CFA-overloaded wrappers:338 which can be augmented simply with generalized, type-safe, \CFA-overloaded wrappers: 339 339 \begin{cfa} 340 340 forall( otype T | { int ?<?( T, T ); } ) T * bsearch( T key, const T * arr, size_t size ) { … … 398 398 T ?++( T * ); 399 399 }; 400 forall( otype T `| summable( T )` ) T sum( T a[$\,$], size_t size ) { // use trait400 forall( otype T `| summable( T )` ) T sum( T a[$\,$], size_t size ) {$\C{// use trait}$ 401 401 `T` total = { `0` }; $\C{// instantiate T from 0 by calling its constructor}$ 402 402 for ( unsigned int i = 0; i < size; i += 1 ) total `+=` a[i]; $\C{// select appropriate +}$ … … 576 576 return (scalar(U)){ a.value + b.value }; 577 577 } 578 scalar(metres) half_marathon = { 21 093 };579 scalar(litres) swimming_pool = { 2 500000 };578 scalar(metres) half_marathon = { 21_093 }; 579 scalar(litres) swimming_pool = { 2_500_000 }; 580 580 scalar(metres) marathon = half_marathon + half_marathon; 581 581 scalar(litres) two_pools = swimming_pool + swimming_pool; … … 724 724 \end{cfa} 725 725 Here, the mass assignment sets all members of @s@ to zero. 726 Since tuple-index expressions are a form of member-access expression, it is possible to use tuple-index expressions in conjunction with member 726 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). 727 727 \begin{cfa} 728 728 [int, int, long, double] x; … … 1879 1879 \lstDeleteShortInline@% 1880 1880 \begin{tabular}{@{}l@{\hspace{3em}}l|l@{}} 1881 \multicolumn{1}{c@{\hspace{3em}}}{\textbf{C Type Nesting}} & \multicolumn{1}{c }{\textbf{C Implicit Hoisting}} & \multicolumn{1}{|c}{\textbf{\CFA}} \\1881 \multicolumn{1}{c@{\hspace{3em}}}{\textbf{C Type Nesting}} & \multicolumn{1}{c|}{\textbf{C Implicit Hoisting}} & \multicolumn{1}{c}{\textbf{\CFA}} \\ 1882 1882 \hline 1883 1883 \begin{cfa} … … 2002 2002 { 2003 2003 VLA x, y = { 20, 0x01 }, z = y; $\C{// z points to y}$ 2004 // ?{}( x ); ?{}( y, 20, 0x01 );?{}( z, y );2004 // ?{}( x ); ?{}( y, 20, 0x01 ); ?{}( z, y ); 2005 2005 ^x{}; $\C{// deallocate x}$ 2006 2006 x{}; $\C{// reallocate x}$ … … 2027 2027 These semantics closely mirror the rule for implicit declaration of constructors in \CC\cite[p.~186]{ANSI98:C++}. 2028 2028 2029 In some circumstance programmers may not wish to have constructor and destructor calls. 2030 In these cases, \CFA provides the initialization syntax \lstinline|S x @= {}|, and the object becomes unmanaged, so implicit constructor and destructor calls are not generated. 2031 Any C initializer can be the right-hand side of an \lstinline|@=| initializer, \eg \lstinline|VLA a @= { 0, 0x0 }|, with the usual C initialization semantics. 2029 In some circumstance programmers may not wish to have implicit constructor and destructor generation and calls. 2030 In these cases, \CFA provides the initialization syntax \lstinline|S x `@=` {}|, and the object becomes unmanaged, so implicit constructor and destructor calls are not generated. 2031 Any C initializer can be the right-hand side of an \lstinline|@=| initializer, \eg \lstinline|VLA a @= { 0, 0x0 }|, with the usual C initialization semantics. 2032 The same syntax can be used in a compound literal, \eg \lstinline|a = VLA`@`{ 0, 0x0 }|, to create a C-style literal. 2032 2033 The point of \lstinline|@=| is to provide a migration path from legacy C code to \CFA, by providing a mechanism to incrementally convert to implicit initialization. 2033 2034 … … 2054 2055 \begin{cfa} 2055 2056 20_`hh` // signed char 2056 21_`hh`u 2057 21_`hh`u // unsigned char 2057 2058 22_`h` // signed short int 2058 2059 23_u`h` // unsigned short int 2059 24`z` // size_t2060 24`z` // size_t 2060 2061 \end{cfa} 2061 2062 & … … 2088 2089 To provide this precision, \CFA introduces a new type @zero_t@ as the type of literal @0@ (somewhat analagous to @nullptr_t@ and @nullptr@ in \CCeleven); 2089 2090 @zero_t@ can only take the value @0@, but has implicit conversions to the integer and pointer types so that C code involving @0@ continues to work. 2090 With this addition, \CFA rewrites @if (x)@ and similar expressions to @if ( (x) != 0)@ or the appropriate analogue, and any type @T@ is ``truthy'' by defining an operator overload @int ?!=?(T, zero_t)@.2091 With this addition, \CFA rewrites @if (x)@ and similar expressions to @if ( (x) != 0 )@ or the appropriate analogue, and any type @T@ is ``truthy'' by defining an operator overload @int ?!=?( T, zero_t )@. 2091 2092 \CC makes types truthy by adding a conversion to @bool@; 2092 2093 prior to the addition of explicit cast operators in \CCeleven, this approach had the pitfall of making truthy types transitively convertable to any numeric type; … … 2163 2164 \lstset{language=CFA,moredelim=**[is][\color{red}]{|}{|},deletedelim=**[is][]{`}{`}} 2164 2165 \lstDeleteShortInline@% 2165 \begin{tabular}{@{}l@{\hspace{ \parindentlnth}}l@{}}2166 \multicolumn{1}{c@{\hspace{ \parindentlnth}}}{\textbf{\CFA}} & \multicolumn{1}{c}{\textbf{\CC}} \\2166 \begin{tabular}{@{}l@{\hspace{2\parindentlnth}}l@{}} 2167 \multicolumn{1}{c@{\hspace{2\parindentlnth}}}{\textbf{\CFA}} & \multicolumn{1}{c}{\textbf{\CC}} \\ 2167 2168 \begin{cfa} 2168 2169 struct W { … … 2260 2261 \begin{cfa} 2261 2262 MIN 2262 2263 2263 MAX 2264 2265 2264 PI 2266 2265 E … … 2268 2267 & 2269 2268 \begin{cfa} 2270 SCHAR_MIN, CHAR_MIN, SHRT_MIN, INT_MIN, LONG_MIN, LLONG_MIN, 2271 FLT_MIN, DBL_MIN, LDBL_MIN 2272 SCHAR_MAX, UCHAR_MAX, SHRT_MAX, INT_MAX, LONG_MAX, LLONG_MAX, 2273 FLT_MAX, DBL_MAX, LDBL_MAX 2269 SCHAR_MIN, CHAR_MIN, SHRT_MIN, INT_MIN, LONG_MIN, LLONG_MIN, FLT_MIN, DBL_MIN, LDBL_MIN 2270 SCHAR_MAX, UCHAR_MAX, SHRT_MAX, INT_MAX, LONG_MAX, LLONG_MAX, FLT_MAX, DBL_MAX, LDBL_MAX 2274 2271 M_PI, M_PIl 2275 2272 M_E, M_El … … 2444 2441 ip = (int *)malloc( sizeof( int ) ); memset( ip, fill, dim * sizeof( int ) ); 2445 2442 ip = (int *)realloc( ip, 2 * dim * sizeof( int ) ); 2446 ip = (int *)realloc( ip, 4 * dim * sizeof( int ) ); 2447 memset( ip, fill, 4 * dim * sizeof( int ) ); 2443 ip = (int *)realloc( ip, 4 * dim * sizeof( int ) ); memset( ip, fill, 4 * dim * sizeof( int ) ); 2444 2448 2445 ip = memalign( 16, sizeof( int ) ); 2449 2446 ip = memalign( 16, sizeof( int ) ); memset( ip, fill, sizeof( int ) );
Note: See TracChangeset
for help on using the changeset viewer.