Changes in doc/papers/general/Paper.tex [3d60c08:387c9a1]
- File:
-
- 1 edited
-
doc/papers/general/Paper.tex (modified) (45 diffs)
Legend:
- Unmodified
- Added
- Removed
-
doc/papers/general/Paper.tex
r3d60c08 r387c9a1 60 60 \renewcommand{\textunderscore}{\leavevmode\makebox[1.2ex][c]{\rule{1ex}{0.075ex}}} 61 61 62 \renewcommand*{\thefootnote}{\ Alph{footnote}} % hack because fnsymbol does not work62 \renewcommand*{\thefootnote}{\alph{footnote}} % hack because fnsymbol does not work 63 63 %\renewcommand*{\thefootnote}{\fnsymbol{footnote}} 64 64 … … 249 249 All languages features discussed in this paper are working, except some advanced exception-handling features. 250 250 Not discussed in this paper are the integrated concurrency-constructs and user-level threading-library~\cite{Delisle18}. 251 \CFA is an \emph{open-source} project 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).251 \CFA is an \emph{open-source} project implemented as an 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). 252 252 Ultimately, a compiler is necessary for advanced features and optimal performance. 253 253 % @plg2[9]% cd cfa-cc/src; cloc ArgTweak CodeGen CodeTools Common Concurrency ControlStruct Designators GenPoly InitTweak MakeLibCfa.cc MakeLibCfa.h Parser ResolvExpr SymTab SynTree Tuples driver prelude main.cc … … 323 323 There are only two hard things in Computer Science: cache invalidation and \emph{naming things} -- Phil Karlton 324 324 \end{quote} 325 \vspace{- 9pt}325 \vspace{-10pt} 326 326 C already has a limited form of ad-hoc polymorphism in the form of its basic arithmetic operators, which apply to a variety of different types using identical syntax. 327 327 \CFA extends the built-in operator overloading by allowing users to define overloads for any function, not just operators, and even any variable; … … 438 438 Hence, programmers can easily form local environments, adding and modifying appropriate functions, to maximize reuse of other existing functions and types. 439 439 440 To reduc eduplication, it is possible to distribute a group of @forall@ (and storage-class qualifiers) over functions/types, so each block declaration is prefixed by the group (see example in Appendix~\ref{s:CforallStack}).440 To reducing duplication, it is possible to distribute a group of @forall@ (and storage-class qualifiers) over functions/types, so each block declaration is prefixed by the group (see example in Appendix~\ref{s:CforallStack}). 441 441 \begin{cfa} 442 442 forall( otype `T` ) { $\C{// distribution block, add forall qualifier to declarations}$ … … 480 480 \end{cquote} 481 481 482 Note, the @sumable@ trait does not include a copy constructor needed for the right side of @?+=?@ and return; 483 it is provided by @otype@, which is syntactic sugar for the following trait: 482 In fact, the set of @summable@ trait operators is incomplete, as it is missing assignment for type @T@, but @otype@ is syntactic sugar for the following implicit trait: 484 483 \begin{cfa} 485 484 trait otype( dtype T | sized(T) ) { // sized is a pseudo-trait for types with known size and alignment … … 499 498 Instead, each polymorphic function (or generic type) defines the structural type needed for its execution (polymorphic type-key), and this key is fulfilled at each call site from the lexical environment, which is similar to Go~\cite{Go} interfaces. 500 499 Hence, new lexical scopes and nested functions are used extensively to create local subtypes, as in the @qsort@ example, without having to manage a nominal-inheritance hierarchy. 501 %(Nominal inheritance can be approximated with traits using marker variables or functions, as is done in Go.)500 (Nominal inheritance can be approximated with traits using marker variables or functions, as is done in Go.) 502 501 503 502 % Nominal inheritance can be simulated with traits using marker variables or functions: … … 526 525 527 526 527 \vspace*{-2pt} 528 528 \section{Generic Types} 529 529 … … 571 571 Concrete types have a fixed memory layout regardless of type parameters, while dynamic types vary in memory layout depending on their type parameters. 572 572 A \newterm{dtype-static} type has polymorphic parameters but is still concrete. 573 Polymorphic pointers are an example of dtype-static types; 574 given some type variable @T@, @T@ is a polymorphic type, as is @T *@, but @T *@ has a fixed size and can therefore be represented by @void *@ in code generation. 573 Polymorphic pointers are an example of dtype-static types, \eg @forall(dtype T) T *@ is a polymorphic type, but for any @T@, @T *@ is a fixed-sized pointer, and therefore, can be represented by a @void *@ in code generation. 575 574 576 575 \CFA generic types also allow checked argument-constraints. … … 956 955 } 957 956 \end{cfa} 958 One more step permits the summation of any sum able type with all arguments of the same type:959 \begin{cfa} 960 trait sum able( otype T ) {957 One more step permits the summation of any summable type with all arguments of the same type: 958 \begin{cfa} 959 trait summable( otype T ) { 961 960 T ?+?( T, T ); 962 961 }; 963 forall( otype R | sum able( R ) ) R sum( R x, R y ) {962 forall( otype R | summable( R ) ) R sum( R x, R y ) { 964 963 return x + y; 965 964 } 966 forall( otype R, ttype Params | sum able(R) | { R sum(R, Params); } ) R sum(R x, R y, Params rest) {965 forall( otype R, ttype Params | summable(R) | { R sum(R, Params); } ) R sum(R x, R y, Params rest) { 967 966 return sum( x + y, rest ); 968 967 } … … 1109 1108 \begin{cquote} 1110 1109 \lstDeleteShortInline@% 1111 \begin{tabular}{@{}l @{\hspace{2\parindentlnth}}l@{}}1112 \multicolumn{1}{ @{}c@{\hspace{2\parindentlnth}}}{\textbf{\CFA}} & \multicolumn{1}{c@{}}{\textbf{C}} \\1110 \begin{tabular}{@{}l|@{\hspace{2\parindentlnth}}l@{}} 1111 \multicolumn{1}{c@{\hspace{2\parindentlnth}}}{\textbf{\CFA}} & \multicolumn{1}{c}{\textbf{C}} \\ 1113 1112 \begin{cfa} 1114 1113 case 2, 10, 34, 42: … … 1125 1124 \lstDeleteShortInline@% 1126 1125 \begin{tabular}{@{}l@{\hspace{2\parindentlnth}}l@{}} 1127 \multicolumn{1}{ @{}c@{\hspace{2\parindentlnth}}}{\textbf{\CFA}} & \multicolumn{1}{c@{}}{\textbf{C}} \\1126 \multicolumn{1}{c@{\hspace{2\parindentlnth}}}{\textbf{\CFA}} & \multicolumn{1}{c}{\textbf{C}} \\ 1128 1127 \begin{cfa} 1129 1128 case 2~42: … … 1179 1178 \lstDeleteShortInline@% 1180 1179 \begin{tabular}{@{}l|@{\hspace{\parindentlnth}}l@{}} 1181 \multicolumn{1}{ @{}c|@{\hspace{\parindentlnth}}}{\textbf{\CFA}} & \multicolumn{1}{c@{}}{\textbf{C}} \\1180 \multicolumn{1}{c|@{\hspace{\parindentlnth}}}{\textbf{\CFA}} & \multicolumn{1}{c}{\textbf{C}} \\ 1182 1181 \begin{cfa} 1183 1182 `choose` ( day ) { … … 1225 1224 \lstDeleteShortInline@% 1226 1225 \begin{tabular}{@{}l|@{\hspace{\parindentlnth}}l@{}} 1227 \multicolumn{1}{ @{}c|@{\hspace{\parindentlnth}}}{\textbf{non-terminator}} & \multicolumn{1}{c@{}}{\textbf{target label}} \\1226 \multicolumn{1}{c|@{\hspace{\parindentlnth}}}{\textbf{non-terminator}} & \multicolumn{1}{c}{\textbf{target label}} \\ 1228 1227 \begin{cfa} 1229 1228 choose ( ... ) { … … 1269 1268 \lstDeleteShortInline@% 1270 1269 \begin{tabular}{@{\hspace{\parindentlnth}}l|@{\hspace{\parindentlnth}}l@{\hspace{\parindentlnth}}l@{}} 1271 \multicolumn{1}{@{\hspace{\parindentlnth}}c|@{\hspace{\parindentlnth}}}{\textbf{\CFA}} & \multicolumn{1}{@{\hspace{\parindentlnth}}c @{}}{\textbf{C}} \\1270 \multicolumn{1}{@{\hspace{\parindentlnth}}c|@{\hspace{\parindentlnth}}}{\textbf{\CFA}} & \multicolumn{1}{@{\hspace{\parindentlnth}}c}{\textbf{C}} \\ 1272 1271 \begin{cfa} 1273 1272 `LC:` { … … 1365 1364 \lstDeleteShortInline@% 1366 1365 \begin{tabular}{@{}l|@{\hspace{\parindentlnth}}l@{}} 1367 \multicolumn{1}{ @{}c|@{\hspace{\parindentlnth}}}{\textbf{Resumption}} & \multicolumn{1}{c@{}}{\textbf{Termination}} \\1366 \multicolumn{1}{c|@{\hspace{\parindentlnth}}}{\textbf{Resumption}} & \multicolumn{1}{c}{\textbf{Termination}} \\ 1368 1367 \begin{cfa} 1369 1368 `exception R { int fix; };` … … 1633 1632 \lstDeleteShortInline@% 1634 1633 \begin{tabular}{@{}l@{\hspace{2\parindentlnth}}l@{\hspace{2\parindentlnth}}l@{}} 1635 \multicolumn{1}{ @{}c@{\hspace{2\parindentlnth}}}{\textbf{\CFA}} & \multicolumn{1}{c@{}}{\textbf{C}} \\1634 \multicolumn{1}{c@{\hspace{2\parindentlnth}}}{\textbf{\CFA}} & \multicolumn{1}{c}{\textbf{C}} \\ 1636 1635 \begin{cfa} 1637 1636 `[5] *` int x1; … … 1661 1660 \lstDeleteShortInline@% 1662 1661 \begin{tabular}{@{}l@{\hspace{2\parindentlnth}}l@{}} 1663 \multicolumn{1}{ @{}c@{\hspace{2\parindentlnth}}}{\textbf{\CFA}} & \multicolumn{1}{c@{}}{\textbf{C}} \\1662 \multicolumn{1}{c@{\hspace{2\parindentlnth}}}{\textbf{\CFA}} & \multicolumn{1}{c}{\textbf{C}} \\ 1664 1663 \begin{cfa} 1665 1664 `*` int x, y; … … 1682 1681 \lstDeleteShortInline@% 1683 1682 \begin{tabular}{@{}l@{\hspace{2\parindentlnth}}l@{\hspace{2\parindentlnth}}l@{}} 1684 \multicolumn{1}{ @{}c@{\hspace{2\parindentlnth}}}{\textbf{\CFA}} & \multicolumn{1}{c@{\hspace{2\parindentlnth}}}{\textbf{C}} \\1683 \multicolumn{1}{c@{\hspace{2\parindentlnth}}}{\textbf{\CFA}} & \multicolumn{1}{c@{\hspace{2\parindentlnth}}}{\textbf{C}} \\ 1685 1684 \begin{cfa} 1686 1685 [ 5 ] int z; … … 1724 1723 \lstDeleteShortInline@% 1725 1724 \begin{tabular}{@{}l@{\hspace{2\parindentlnth}}l@{\hspace{2\parindentlnth}}l@{}} 1726 \multicolumn{1}{ @{}c@{\hspace{2\parindentlnth}}}{\textbf{\CFA}} & \multicolumn{1}{c@{\hspace{2\parindentlnth}}}{\textbf{C}} \\1725 \multicolumn{1}{c@{\hspace{2\parindentlnth}}}{\textbf{\CFA}} & \multicolumn{1}{c@{\hspace{2\parindentlnth}}}{\textbf{C}} \\ 1727 1726 \begin{cfa} 1728 1727 extern const * const int x; … … 1749 1748 \lstDeleteShortInline@% 1750 1749 \begin{tabular}{@{}l@{\hspace{2\parindentlnth}}l@{}} 1751 \multicolumn{1}{ @{}c@{\hspace{2\parindentlnth}}}{\textbf{\CFA}} & \multicolumn{1}{c@{}}{\textbf{C}} \\1750 \multicolumn{1}{c@{\hspace{2\parindentlnth}}}{\textbf{\CFA}} & \multicolumn{1}{c}{\textbf{C}} \\ 1752 1751 \begin{cfa} 1753 1752 y = (* int)x; … … 1777 1776 \lstDeleteShortInline@% 1778 1777 \begin{tabular}{@{}l@{\hspace{2\parindentlnth}}l@{}} 1779 \multicolumn{1}{ @{}c@{\hspace{2\parindentlnth}}}{\textbf{\CFA}} & \multicolumn{1}{c@{}}{\textbf{C}} \\1778 \multicolumn{1}{c@{\hspace{2\parindentlnth}}}{\textbf{\CFA}} & \multicolumn{1}{c}{\textbf{C}} \\ 1780 1779 \begin{cfa} 1781 1780 [double] foo(), foo( int ), foo( double ) {...} … … 1795 1794 * [ * int ] ( int y ) gp; $\C{// pointer to function returning pointer to int with int parameter}$ 1796 1795 * [ ] ( int, char ) hp; $\C{// pointer to function returning no result with int and char parameters}$ 1797 * [ * int, int ] ( int ) jp; $\C{// pointer to function returning pointer to int and int with int parameter} \CRT$1796 * [ * int, int ] ( int ) jp; $\C{// pointer to function returning pointer to int and int with int parameter}$ 1798 1797 \end{cfa} 1799 1798 Note, the name of the function pointer is specified last, as for other variable declarations. … … 1994 1993 The symbol \lstinline+^+ is used for the destructor name because it was the last binary operator that could be used in a unary context.}. 1995 1994 The name @{}@ comes from the syntax for the initializer: @struct S { int i, j; } s = `{` 2, 3 `}`@. 1996 Like other \CFA operators, these names represent the syntax used to explicitly call the constructor or destructor, \eg @s{...}@ or @^s{...}@.1995 Like other \CFA operators, these names represent the syntax used to call the constructor or destructor, \eg @?{}(x, ...)@ or @^{}(x, ...)@. 1997 1996 The constructor and destructor have return type @void@, and the first parameter is a reference to the object type to be constructed or destructed. 1998 1997 While the first parameter is informally called the @this@ parameter, as in object-oriented languages, any variable name may be used. 1999 Both constructors and destructors allow additional paramete rs after the @this@ parameter for specifying values for initialization/de-initialization\footnote{1998 Both constructors and destructors allow additional parametes after the @this@ parameter for specifying values for initialization/de-initialization\footnote{ 2000 1999 Destruction parameters are useful for specifying storage-management actions, such as de-initialize but not deallocate.}. 2001 2000 \begin{cfa} … … 2004 2003 void ^?{}( VLA & vla ) with ( vla ) { free( data ); } $\C{// destructor}$ 2005 2004 { 2006 VLA x; $\C{// implicit: \ \ x\{\};}$2007 } $\C{// implicit: \ \textasciicircum{}x\{\};}$2005 VLA x; $\C{// implicit: ?\{\}( x );}$ 2006 } $\C{// implicit: ?\^{}\{\}( x );}$ 2008 2007 \end{cfa} 2009 2008 @VLA@ is a \newterm{managed type}\footnote{ … … 2030 2029 appropriate care is taken to not recursively call the copy constructor when initializing the second parameter. 2031 2030 2032 \CFA constructors may be explicitly call ed, like Java, and destructors may be explicitly called, like \CC.2031 \CFA constructors may be explicitly call, like Java, and destructors may be explicitly called, like \CC. 2033 2032 Explicit calls to constructors double as a \CC-style \emph{placement syntax}, useful for construction of member fields in user-defined constructors and reuse of existing storage allocations. 2034 Like the other operators in \CFA, there is a concise syntax for constructor/destructor function calls:2033 While existing call syntax works for explicit calls to constructors and destructors, \CFA also provides a more concise \newterm{operator syntax} for both: 2035 2034 \begin{cfa} 2036 2035 { 2037 2036 VLA x, y = { 20, 0x01 }, z = y; $\C{// z points to y}$ 2038 // x{}; y{ 20, 0x01 }; z{ z, y };2037 // ?{}( x ); ?{}( y, 20, 0x01 ); ?{}( z, y ); 2039 2038 ^x{}; $\C{// deallocate x}$ 2040 2039 x{}; $\C{// reallocate x}$ … … 2043 2042 y{ x }; $\C{// reallocate y, points to x}$ 2044 2043 x{}; $\C{// reallocate x, not pointing to y}$ 2045 // ^z{}; ^y{}; ^x{};2044 // ^?{}(z); ^?{}(y); ^?{}(x); 2046 2045 } 2047 2046 \end{cfa} … … 2064 2063 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. 2065 2064 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. 2066 The same syntax can be used in a compound literal, \eg \lstinline|a = (VLA)`@`{ 0, 0x0 }|, to create a C-style literal.2065 The same syntax can be used in a compound literal, \eg \lstinline|a = VLA`@`{ 0, 0x0 }|, to create a C-style literal. 2067 2066 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. 2068 2067 … … 2120 2119 2121 2120 In C, @0@ has the special property that it is the only ``false'' value; 2122 bythe standard, any value that compares equal to @0@ is false, while any value that compares unequal to @0@ is true.2121 from the standard, any value that compares equal to @0@ is false, while any value that compares unequal to @0@ is true. 2123 2122 As such, an expression @x@ in any boolean context (such as the condition of an @if@ or @while@ statement, or the arguments to @&&@, @||@, or @?:@\,) can be rewritten as @x != 0@ without changing its semantics. 2124 2123 Operator overloading in \CFA provides a natural means to implement this truth-value comparison for arbitrary types, but the C type system is not precise enough to distinguish an equality comparison with @0@ from an equality comparison with an arbitrary integer or pointer. … … 2155 2154 \lstDeleteShortInline@% 2156 2155 \begin{tabular}{@{}l@{\hspace{2\parindentlnth}}l@{\hspace{2\parindentlnth}}l@{\hspace{2\parindentlnth}}l@{}} 2157 \multicolumn{1}{ @{}c@{\hspace{2\parindentlnth}}}{\textbf{postfix function}} & \multicolumn{1}{c@{\hspace{2\parindentlnth}}}{\textbf{constant}} & \multicolumn{1}{c@{\hspace{2\parindentlnth}}}{\textbf{variable/expression}} & \multicolumn{1}{c@{}}{\textbf{postfix pointer}} \\2156 \multicolumn{1}{c@{\hspace{2\parindentlnth}}}{\textbf{postfix function}} & \multicolumn{1}{c@{\hspace{2\parindentlnth}}}{\textbf{constant}} & \multicolumn{1}{c@{\hspace{2\parindentlnth}}}{\textbf{variable/expression}} & \multicolumn{1}{c}{\textbf{postfix pointer}} \\ 2158 2157 \begin{cfa} 2159 2158 int |?`h|( int s ); … … 2200 2199 \lstset{language=CFA,moredelim=**[is][\color{red}]{|}{|},deletedelim=**[is][]{`}{`}} 2201 2200 \lstDeleteShortInline@% 2202 \begin{tabular}{@{}l@{\hspace{ 1.25\parindentlnth}}l@{}}2203 \multicolumn{1}{ @{}c@{\hspace{1.25\parindentlnth}}}{\textbf{\CFA}} & \multicolumn{1}{c@{}}{\textbf{\CC}} \\2201 \begin{tabular}{@{}l@{\hspace{2\parindentlnth}}l@{}} 2202 \multicolumn{1}{c@{\hspace{2\parindentlnth}}}{\textbf{\CFA}} & \multicolumn{1}{c}{\textbf{\CC}} \\ 2204 2203 \begin{cfa} 2205 2204 struct W { … … 2275 2274 \lstDeleteShortInline@% 2276 2275 \begin{tabular}{@{}l@{\hspace{2\parindentlnth}}l@{}} 2277 \multicolumn{1}{ @{}c@{\hspace{2\parindentlnth}}}{\textbf{Definition}} & \multicolumn{1}{c@{}}{\textbf{Usage}} \\2276 \multicolumn{1}{c@{\hspace{2\parindentlnth}}}{\textbf{Definition}} & \multicolumn{1}{c}{\textbf{Usage}} \\ 2278 2277 \begin{cfa} 2279 2278 const short int `MIN` = -32768; … … 2294 2293 \lstDeleteShortInline@% 2295 2294 \begin{tabular}{@{}l@{\hspace{\parindentlnth}}l@{}} 2296 \multicolumn{1}{ @{}c@{\hspace{\parindentlnth}}}{\textbf{\CFA}} & \multicolumn{1}{c@{}}{\textbf{C}} \\2295 \multicolumn{1}{c@{\hspace{\parindentlnth}}}{\textbf{\CFA}} & \multicolumn{1}{c}{\textbf{C}} \\ 2297 2296 \begin{cfa} 2298 2297 MIN … … 2320 2319 \lstDeleteShortInline@% 2321 2320 \begin{tabular}{@{}l@{\hspace{2\parindentlnth}}l@{}} 2322 \multicolumn{1}{ @{}c@{\hspace{2\parindentlnth}}}{\textbf{Definition}} & \multicolumn{1}{c@{}}{\textbf{Usage}} \\2321 \multicolumn{1}{c@{\hspace{2\parindentlnth}}}{\textbf{Definition}} & \multicolumn{1}{c}{\textbf{Usage}} \\ 2323 2322 \begin{cfa} 2324 2323 float `log`( float x ); … … 2339 2338 \lstDeleteShortInline@% 2340 2339 \begin{tabular}{@{}l@{\hspace{2\parindentlnth}}l@{}} 2341 \multicolumn{1}{ @{}c@{\hspace{2\parindentlnth}}}{\textbf{\CFA}} & \multicolumn{1}{c@{}}{\textbf{C}} \\2340 \multicolumn{1}{c@{\hspace{2\parindentlnth}}}{\textbf{\CFA}} & \multicolumn{1}{c}{\textbf{C}} \\ 2342 2341 \begin{cfa} 2343 2342 log … … 2367 2366 \lstDeleteShortInline@% 2368 2367 \begin{tabular}{@{}l@{\hspace{2\parindentlnth}}l@{}} 2369 \multicolumn{1}{ @{}c@{\hspace{2\parindentlnth}}}{\textbf{Definition}} & \multicolumn{1}{c@{}}{\textbf{Usage}} \\2368 \multicolumn{1}{c@{\hspace{2\parindentlnth}}}{\textbf{Definition}} & \multicolumn{1}{c}{\textbf{Usage}} \\ 2370 2369 \begin{cfa} 2371 2370 unsigned int `abs`( int ); … … 2386 2385 \lstDeleteShortInline@% 2387 2386 \begin{tabular}{@{}l@{\hspace{2\parindentlnth}}l@{}} 2388 \multicolumn{1}{ @{}c@{\hspace{2\parindentlnth}}}{\textbf{\CFA}} & \multicolumn{1}{c@{}}{\textbf{C}} \\2387 \multicolumn{1}{c@{\hspace{2\parindentlnth}}}{\textbf{\CFA}} & \multicolumn{1}{c}{\textbf{C}} \\ 2389 2388 \begin{cfa} 2390 2389 abs … … 2409 2408 an allocation with a specified character. 2410 2409 \item[resize] 2411 an existing allocation to decrease or increaseits size.2410 an existing allocation to decreased or increased its size. 2412 2411 In either case, new storage may or may not be allocated and, if there is a new allocation, as much data from the existing allocation is copied. 2413 2412 For an increase in storage size, new storage after the copied data may be filled. … … 2448 2447 \begin{figure} 2449 2448 \centering 2450 \begin{cfa}[aboveskip=0pt,xleftmargin=0pt] 2449 \begin{cquote} 2450 \begin{cfa}[aboveskip=0pt] 2451 2451 size_t dim = 10; $\C{// array dimension}$ 2452 2452 char fill = '\xff'; $\C{// initialization fill value}$ … … 2454 2454 \end{cfa} 2455 2455 \lstDeleteShortInline@% 2456 \begin{tabular}{@{}l@{\hspace{ \parindentlnth}}l@{}}2457 \multicolumn{1}{ @{}c@{\hspace{\parindentlnth}}}{\textbf{\CFA}} & \multicolumn{1}{c@{}}{\textbf{C}} \\2458 \begin{cfa} [xleftmargin=-10pt]2456 \begin{tabular}{@{}l@{\hspace{2\parindentlnth}}l@{}} 2457 \multicolumn{1}{c@{\hspace{2\parindentlnth}}}{\textbf{\CFA}} & \multicolumn{1}{c}{\textbf{C}} \\ 2458 \begin{cfa} 2459 2459 ip = alloc(); 2460 2460 ip = alloc( fill ); … … 2471 2471 & 2472 2472 \begin{cfa} 2473 ip = (int *)malloc( sizeof(int) ); 2474 ip = (int *)malloc( sizeof(int) ); memset( ip, fill, sizeof(int) ); 2475 ip = (int *)malloc( dim * sizeof(int) ); 2476 ip = (int *)malloc( sizeof(int) ); memset( ip, fill, dim * sizeof(int) ); 2477 ip = (int *)realloc( ip, 2 * dim * sizeof(int) ); 2478 ip = (int *)realloc( ip, 4 * dim * sizeof(int) ); memset( ip, fill, 4 * dim * sizeof(int)); 2479 2480 ip = memalign( 16, sizeof(int) ); 2481 ip = memalign( 16, sizeof(int) ); memset( ip, fill, sizeof(int) ); 2482 ip = memalign( 16, dim * sizeof(int) ); 2483 ip = memalign( 16, dim * sizeof(int) ); memset( ip, fill, dim * sizeof(int) ); 2484 \end{cfa} 2485 \end{tabular} 2486 \lstMakeShortInline@% 2473 ip = (int *)malloc( sizeof( int ) ); 2474 ip = (int *)malloc( sizeof( int ) ); memset( ip, fill, sizeof( int ) ); 2475 ip = (int *)malloc( dim * sizeof( int ) ); 2476 ip = (int *)malloc( sizeof( int ) ); memset( ip, fill, dim * sizeof( int ) ); 2477 ip = (int *)realloc( ip, 2 * dim * sizeof( int ) ); 2478 ip = (int *)realloc( ip, 4 * dim * sizeof( int ) ); 2479 memset( ip, fill, 4 * dim * sizeof( int ) ); 2480 ip = memalign( 16, sizeof( int ) ); 2481 ip = memalign( 16, sizeof( int ) ); memset( ip, fill, sizeof( int ) ); 2482 ip = memalign( 16, dim * sizeof( int ) ); 2483 ip = memalign( 16, dim * sizeof( int ) ); memset( ip, fill, dim * sizeof( int ) ); 2484 \end{cfa} 2485 \end{tabular} 2486 \lstMakeShortInline@% 2487 \end{cquote} 2487 2488 \caption{\CFA versus C Storage-Allocation} 2488 2489 \label{f:StorageAllocation} … … 2497 2498 S * as = anew( dim, 2, 3 ); $\C{// each array element initialized to 2, 3}$ 2498 2499 \end{cfa} 2499 Note, \CC can only initializ earray elements via the default constructor.2500 Note, \CC can only initialization array elements via the default constructor. 2500 2501 2501 2502 Finally, the \CFA memory-allocator has \newterm{sticky properties} for dynamic storage: fill and alignment are remembered with an object's storage in the heap. … … 2514 2515 \lstDeleteShortInline@% 2515 2516 \begin{tabular}{@{}l@{\hspace{2\parindentlnth}}l@{}} 2516 \multicolumn{1}{ @{}c@{\hspace{2\parindentlnth}}}{\textbf{\CFA}} & \multicolumn{1}{c@{}}{\textbf{\CC}} \\2517 \multicolumn{1}{c@{\hspace{2\parindentlnth}}}{\textbf{\CFA}} & \multicolumn{1}{c}{\textbf{\CC}} \\ 2517 2518 \begin{cfa} 2518 2519 int x = 1, y = 2, z = 3; … … 2603 2604 \centering 2604 2605 \lstDeleteShortInline@% 2605 \begin{tabular}{@{}l@{\hspace{ 3\parindentlnth}}l@{}}2606 \multicolumn{1}{ @{}c@{\hspace{3\parindentlnth}}}{\textbf{\CFA}} & \multicolumn{1}{c@{}}{\textbf{C}} \\2606 \begin{tabular}{@{}l@{\hspace{2\parindentlnth}}@{\hspace{2\parindentlnth}}l@{}} 2607 \multicolumn{1}{c@{\hspace{2\parindentlnth}}}{\textbf{\CFA}} & \multicolumn{1}{@{\hspace{2\parindentlnth}}c}{\textbf{C}} \\ 2607 2608 \begin{cfa} 2608 2609 #include <gmp> … … 2637 2638 2638 2639 2639 \section{Polymorphi smEvaluation}2640 \section{Polymorphic Evaluation} 2640 2641 \label{sec:eval} 2641 2642 … … 2726 2727 Line-count is a fairly rough measure of code complexity; 2727 2728 another important factor is how much type information the programmer must specify manually, especially where that information is not compiler-checked. 2728 Such unchecked type information produces a heavier documentation burden and increased potential for runtime bugs, and is much less common in \CFA than C, with its manually specified function pointer arguments and format codes, or \CCV, with its extensive use of un -type-checked downcasts, \eg @object@ to @integer@ when popping a stack.2729 Such unchecked type information produces a heavier documentation burden and increased potential for runtime bugs, and is much less common in \CFA than C, with its manually specified function pointer arguments and format codes, or \CCV, with its extensive use of untype-checked downcasts, \eg @object@ to @integer@ when popping a stack. 2729 2730 To quantify this manual typing, the ``redundant type annotations'' line in Table~\ref{tab:eval} counts the number of lines on which the type of a known variable is respecified, either as a format specifier, explicit downcast, type-specific function, or by name in a @sizeof@, struct literal, or @new@ expression. 2730 2731 The \CC benchmark uses two redundant type annotations to create a new stack nodes, while the C and \CCV benchmarks have several such annotations spread throughout their code. 2731 2732 The \CFA benchmark is able to eliminate all redundant type annotations through use of the polymorphic @alloc@ function discussed in Section~\ref{sec:libraries}. 2732 2733 2733 We conjecture these results scale across most generic data-types as the underlying polymorphi smimplement is constant.2734 We conjecture these results scale across most generic data-types as the underlying polymorphic implement is constant. 2734 2735 2735 2736
Note:
See TracChangeset
for help on using the changeset viewer.