Changeset 3d60c08 for doc/papers/general/Paper.tex
- Timestamp:
- May 8, 2018, 9:20:23 PM (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:
- b4a835d
- Parents:
- 83034ec
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
doc/papers/general/Paper.tex
r83034ec r3d60c08 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 nsource-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 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). 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{- 10pt}325 \vspace{-9pt} 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 ingduplication, 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 reduce 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 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: 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: 483 484 \begin{cfa} 484 485 trait otype( dtype T | sized(T) ) { // sized is a pseudo-trait for types with known size and alignment … … 498 499 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. 499 500 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. 500 (Nominal inheritance can be approximated with traits using marker variables or functions, as is done in Go.)501 % (Nominal inheritance can be approximated with traits using marker variables or functions, as is done in Go.) 501 502 502 503 % Nominal inheritance can be simulated with traits using marker variables or functions: … … 525 526 526 527 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, \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. 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. 574 575 575 576 \CFA generic types also allow checked argument-constraints. … … 955 956 } 956 957 \end{cfa} 957 One more step permits the summation of any sum mable type with all arguments of the same type:958 \begin{cfa} 959 trait sum mable( otype T ) {958 One more step permits the summation of any sumable type with all arguments of the same type: 959 \begin{cfa} 960 trait sumable( otype T ) { 960 961 T ?+?( T, T ); 961 962 }; 962 forall( otype R | sum mable( R ) ) R sum( R x, R y ) {963 forall( otype R | sumable( R ) ) R sum( R x, R y ) { 963 964 return x + y; 964 965 } 965 forall( otype R, ttype Params | sum mable(R) | { R sum(R, Params); } ) R sum(R x, R y, Params rest) {966 forall( otype R, ttype Params | sumable(R) | { R sum(R, Params); } ) R sum(R x, R y, Params rest) { 966 967 return sum( x + y, rest ); 967 968 } … … 1108 1109 \begin{cquote} 1109 1110 \lstDeleteShortInline@% 1110 \begin{tabular}{@{}l |@{\hspace{2\parindentlnth}}l@{}}1111 \multicolumn{1}{ c@{\hspace{2\parindentlnth}}}{\textbf{\CFA}} & \multicolumn{1}{c}{\textbf{C}} \\1111 \begin{tabular}{@{}l@{\hspace{2\parindentlnth}}l@{}} 1112 \multicolumn{1}{@{}c@{\hspace{2\parindentlnth}}}{\textbf{\CFA}} & \multicolumn{1}{c@{}}{\textbf{C}} \\ 1112 1113 \begin{cfa} 1113 1114 case 2, 10, 34, 42: … … 1124 1125 \lstDeleteShortInline@% 1125 1126 \begin{tabular}{@{}l@{\hspace{2\parindentlnth}}l@{}} 1126 \multicolumn{1}{ c@{\hspace{2\parindentlnth}}}{\textbf{\CFA}} & \multicolumn{1}{c}{\textbf{C}} \\1127 \multicolumn{1}{@{}c@{\hspace{2\parindentlnth}}}{\textbf{\CFA}} & \multicolumn{1}{c@{}}{\textbf{C}} \\ 1127 1128 \begin{cfa} 1128 1129 case 2~42: … … 1178 1179 \lstDeleteShortInline@% 1179 1180 \begin{tabular}{@{}l|@{\hspace{\parindentlnth}}l@{}} 1180 \multicolumn{1}{ c|@{\hspace{\parindentlnth}}}{\textbf{\CFA}} & \multicolumn{1}{c}{\textbf{C}} \\1181 \multicolumn{1}{@{}c|@{\hspace{\parindentlnth}}}{\textbf{\CFA}} & \multicolumn{1}{c@{}}{\textbf{C}} \\ 1181 1182 \begin{cfa} 1182 1183 `choose` ( day ) { … … 1224 1225 \lstDeleteShortInline@% 1225 1226 \begin{tabular}{@{}l|@{\hspace{\parindentlnth}}l@{}} 1226 \multicolumn{1}{ c|@{\hspace{\parindentlnth}}}{\textbf{non-terminator}} & \multicolumn{1}{c}{\textbf{target label}} \\1227 \multicolumn{1}{@{}c|@{\hspace{\parindentlnth}}}{\textbf{non-terminator}} & \multicolumn{1}{c@{}}{\textbf{target label}} \\ 1227 1228 \begin{cfa} 1228 1229 choose ( ... ) { … … 1268 1269 \lstDeleteShortInline@% 1269 1270 \begin{tabular}{@{\hspace{\parindentlnth}}l|@{\hspace{\parindentlnth}}l@{\hspace{\parindentlnth}}l@{}} 1270 \multicolumn{1}{@{\hspace{\parindentlnth}}c|@{\hspace{\parindentlnth}}}{\textbf{\CFA}} & \multicolumn{1}{@{\hspace{\parindentlnth}}c }{\textbf{C}} \\1271 \multicolumn{1}{@{\hspace{\parindentlnth}}c|@{\hspace{\parindentlnth}}}{\textbf{\CFA}} & \multicolumn{1}{@{\hspace{\parindentlnth}}c@{}}{\textbf{C}} \\ 1271 1272 \begin{cfa} 1272 1273 `LC:` { … … 1364 1365 \lstDeleteShortInline@% 1365 1366 \begin{tabular}{@{}l|@{\hspace{\parindentlnth}}l@{}} 1366 \multicolumn{1}{ c|@{\hspace{\parindentlnth}}}{\textbf{Resumption}} & \multicolumn{1}{c}{\textbf{Termination}} \\1367 \multicolumn{1}{@{}c|@{\hspace{\parindentlnth}}}{\textbf{Resumption}} & \multicolumn{1}{c@{}}{\textbf{Termination}} \\ 1367 1368 \begin{cfa} 1368 1369 `exception R { int fix; };` … … 1632 1633 \lstDeleteShortInline@% 1633 1634 \begin{tabular}{@{}l@{\hspace{2\parindentlnth}}l@{\hspace{2\parindentlnth}}l@{}} 1634 \multicolumn{1}{ c@{\hspace{2\parindentlnth}}}{\textbf{\CFA}} & \multicolumn{1}{c}{\textbf{C}} \\1635 \multicolumn{1}{@{}c@{\hspace{2\parindentlnth}}}{\textbf{\CFA}} & \multicolumn{1}{c@{}}{\textbf{C}} \\ 1635 1636 \begin{cfa} 1636 1637 `[5] *` int x1; … … 1660 1661 \lstDeleteShortInline@% 1661 1662 \begin{tabular}{@{}l@{\hspace{2\parindentlnth}}l@{}} 1662 \multicolumn{1}{ c@{\hspace{2\parindentlnth}}}{\textbf{\CFA}} & \multicolumn{1}{c}{\textbf{C}} \\1663 \multicolumn{1}{@{}c@{\hspace{2\parindentlnth}}}{\textbf{\CFA}} & \multicolumn{1}{c@{}}{\textbf{C}} \\ 1663 1664 \begin{cfa} 1664 1665 `*` int x, y; … … 1681 1682 \lstDeleteShortInline@% 1682 1683 \begin{tabular}{@{}l@{\hspace{2\parindentlnth}}l@{\hspace{2\parindentlnth}}l@{}} 1683 \multicolumn{1}{ c@{\hspace{2\parindentlnth}}}{\textbf{\CFA}} & \multicolumn{1}{c@{\hspace{2\parindentlnth}}}{\textbf{C}} \\1684 \multicolumn{1}{@{}c@{\hspace{2\parindentlnth}}}{\textbf{\CFA}} & \multicolumn{1}{c@{\hspace{2\parindentlnth}}}{\textbf{C}} \\ 1684 1685 \begin{cfa} 1685 1686 [ 5 ] int z; … … 1723 1724 \lstDeleteShortInline@% 1724 1725 \begin{tabular}{@{}l@{\hspace{2\parindentlnth}}l@{\hspace{2\parindentlnth}}l@{}} 1725 \multicolumn{1}{ c@{\hspace{2\parindentlnth}}}{\textbf{\CFA}} & \multicolumn{1}{c@{\hspace{2\parindentlnth}}}{\textbf{C}} \\1726 \multicolumn{1}{@{}c@{\hspace{2\parindentlnth}}}{\textbf{\CFA}} & \multicolumn{1}{c@{\hspace{2\parindentlnth}}}{\textbf{C}} \\ 1726 1727 \begin{cfa} 1727 1728 extern const * const int x; … … 1748 1749 \lstDeleteShortInline@% 1749 1750 \begin{tabular}{@{}l@{\hspace{2\parindentlnth}}l@{}} 1750 \multicolumn{1}{ c@{\hspace{2\parindentlnth}}}{\textbf{\CFA}} & \multicolumn{1}{c}{\textbf{C}} \\1751 \multicolumn{1}{@{}c@{\hspace{2\parindentlnth}}}{\textbf{\CFA}} & \multicolumn{1}{c@{}}{\textbf{C}} \\ 1751 1752 \begin{cfa} 1752 1753 y = (* int)x; … … 1776 1777 \lstDeleteShortInline@% 1777 1778 \begin{tabular}{@{}l@{\hspace{2\parindentlnth}}l@{}} 1778 \multicolumn{1}{ c@{\hspace{2\parindentlnth}}}{\textbf{\CFA}} & \multicolumn{1}{c}{\textbf{C}} \\1779 \multicolumn{1}{@{}c@{\hspace{2\parindentlnth}}}{\textbf{\CFA}} & \multicolumn{1}{c@{}}{\textbf{C}} \\ 1779 1780 \begin{cfa} 1780 1781 [double] foo(), foo( int ), foo( double ) {...} … … 1794 1795 * [ * int ] ( int y ) gp; $\C{// pointer to function returning pointer to int with int parameter}$ 1795 1796 * [ ] ( int, char ) hp; $\C{// pointer to function returning no result with int and char parameters}$ 1796 * [ * int, int ] ( int ) jp; $\C{// pointer to function returning pointer to int and int with int parameter} $1797 * [ * int, int ] ( int ) jp; $\C{// pointer to function returning pointer to int and int with int parameter}\CRT$ 1797 1798 \end{cfa} 1798 1799 Note, the name of the function pointer is specified last, as for other variable declarations. … … 1993 1994 The symbol \lstinline+^+ is used for the destructor name because it was the last binary operator that could be used in a unary context.}. 1994 1995 The name @{}@ comes from the syntax for the initializer: @struct S { int i, j; } s = `{` 2, 3 `}`@. 1995 Like other \CFA operators, these names represent the syntax used to call the constructor or destructor, \eg @?{}(x, ...)@ or @^{}(x, ...)@.1996 Like other \CFA operators, these names represent the syntax used to explicitly call the constructor or destructor, \eg @s{...}@ or @^s{...}@. 1996 1997 The constructor and destructor have return type @void@, and the first parameter is a reference to the object type to be constructed or destructed. 1997 1998 While the first parameter is informally called the @this@ parameter, as in object-oriented languages, any variable name may be used. 1998 Both constructors and destructors allow additional paramete s after the @this@ parameter for specifying values for initialization/de-initialization\footnote{1999 Both constructors and destructors allow additional parameters after the @this@ parameter for specifying values for initialization/de-initialization\footnote{ 1999 2000 Destruction parameters are useful for specifying storage-management actions, such as de-initialize but not deallocate.}. 2000 2001 \begin{cfa} … … 2003 2004 void ^?{}( VLA & vla ) with ( vla ) { free( data ); } $\C{// destructor}$ 2004 2005 { 2005 VLA x; $\C{// implicit: ?\{\}( x );}$2006 } $\C{// implicit: ?\^{}\{\}( x );}$2006 VLA x; $\C{// implicit:\ \ x\{\};}$ 2007 } $\C{// implicit:\ \textasciicircum{}x\{\};}$ 2007 2008 \end{cfa} 2008 2009 @VLA@ is a \newterm{managed type}\footnote{ … … 2029 2030 appropriate care is taken to not recursively call the copy constructor when initializing the second parameter. 2030 2031 2031 \CFA constructors may be explicitly call , like Java, and destructors may be explicitly called, like \CC.2032 \CFA constructors may be explicitly called, like Java, and destructors may be explicitly called, like \CC. 2032 2033 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. 2033 While existing call syntax works for explicit calls to constructors and destructors, \CFA also provides a more concise \newterm{operator syntax} for both:2034 Like the other operators in \CFA, there is a concise syntax for constructor/destructor function calls: 2034 2035 \begin{cfa} 2035 2036 { 2036 2037 VLA x, y = { 20, 0x01 }, z = y; $\C{// z points to y}$ 2037 // ?{}( x ); ?{}( y, 20, 0x01 ); ?{}( z, y );2038 // x{}; y{ 20, 0x01 }; z{ z, y }; 2038 2039 ^x{}; $\C{// deallocate x}$ 2039 2040 x{}; $\C{// reallocate x}$ … … 2042 2043 y{ x }; $\C{// reallocate y, points to x}$ 2043 2044 x{}; $\C{// reallocate x, not pointing to y}$ 2044 // ^?{}(z); ^?{}(y); ^?{}(x);2045 // ^z{}; ^y{}; ^x{}; 2045 2046 } 2046 2047 \end{cfa} … … 2063 2064 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. 2064 2065 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. 2065 The same syntax can be used in a compound literal, \eg \lstinline|a = VLA`@`{ 0, 0x0 }|, to create a C-style literal.2066 The same syntax can be used in a compound literal, \eg \lstinline|a = (VLA)`@`{ 0, 0x0 }|, to create a C-style literal. 2066 2067 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. 2067 2068 … … 2119 2120 2120 2121 In C, @0@ has the special property that it is the only ``false'' value; 2121 fromthe standard, any value that compares equal to @0@ is false, while any value that compares unequal to @0@ is true.2122 by the standard, any value that compares equal to @0@ is false, while any value that compares unequal to @0@ is true. 2122 2123 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. 2123 2124 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. … … 2154 2155 \lstDeleteShortInline@% 2155 2156 \begin{tabular}{@{}l@{\hspace{2\parindentlnth}}l@{\hspace{2\parindentlnth}}l@{\hspace{2\parindentlnth}}l@{}} 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}} \\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}} \\ 2157 2158 \begin{cfa} 2158 2159 int |?`h|( int s ); … … 2199 2200 \lstset{language=CFA,moredelim=**[is][\color{red}]{|}{|},deletedelim=**[is][]{`}{`}} 2200 2201 \lstDeleteShortInline@% 2201 \begin{tabular}{@{}l@{\hspace{ 2\parindentlnth}}l@{}}2202 \multicolumn{1}{ c@{\hspace{2\parindentlnth}}}{\textbf{\CFA}} & \multicolumn{1}{c}{\textbf{\CC}} \\2202 \begin{tabular}{@{}l@{\hspace{1.25\parindentlnth}}l@{}} 2203 \multicolumn{1}{@{}c@{\hspace{1.25\parindentlnth}}}{\textbf{\CFA}} & \multicolumn{1}{c@{}}{\textbf{\CC}} \\ 2203 2204 \begin{cfa} 2204 2205 struct W { … … 2274 2275 \lstDeleteShortInline@% 2275 2276 \begin{tabular}{@{}l@{\hspace{2\parindentlnth}}l@{}} 2276 \multicolumn{1}{ c@{\hspace{2\parindentlnth}}}{\textbf{Definition}} & \multicolumn{1}{c}{\textbf{Usage}} \\2277 \multicolumn{1}{@{}c@{\hspace{2\parindentlnth}}}{\textbf{Definition}} & \multicolumn{1}{c@{}}{\textbf{Usage}} \\ 2277 2278 \begin{cfa} 2278 2279 const short int `MIN` = -32768; … … 2293 2294 \lstDeleteShortInline@% 2294 2295 \begin{tabular}{@{}l@{\hspace{\parindentlnth}}l@{}} 2295 \multicolumn{1}{ c@{\hspace{\parindentlnth}}}{\textbf{\CFA}} & \multicolumn{1}{c}{\textbf{C}} \\2296 \multicolumn{1}{@{}c@{\hspace{\parindentlnth}}}{\textbf{\CFA}} & \multicolumn{1}{c@{}}{\textbf{C}} \\ 2296 2297 \begin{cfa} 2297 2298 MIN … … 2319 2320 \lstDeleteShortInline@% 2320 2321 \begin{tabular}{@{}l@{\hspace{2\parindentlnth}}l@{}} 2321 \multicolumn{1}{ c@{\hspace{2\parindentlnth}}}{\textbf{Definition}} & \multicolumn{1}{c}{\textbf{Usage}} \\2322 \multicolumn{1}{@{}c@{\hspace{2\parindentlnth}}}{\textbf{Definition}} & \multicolumn{1}{c@{}}{\textbf{Usage}} \\ 2322 2323 \begin{cfa} 2323 2324 float `log`( float x ); … … 2338 2339 \lstDeleteShortInline@% 2339 2340 \begin{tabular}{@{}l@{\hspace{2\parindentlnth}}l@{}} 2340 \multicolumn{1}{ c@{\hspace{2\parindentlnth}}}{\textbf{\CFA}} & \multicolumn{1}{c}{\textbf{C}} \\2341 \multicolumn{1}{@{}c@{\hspace{2\parindentlnth}}}{\textbf{\CFA}} & \multicolumn{1}{c@{}}{\textbf{C}} \\ 2341 2342 \begin{cfa} 2342 2343 log … … 2366 2367 \lstDeleteShortInline@% 2367 2368 \begin{tabular}{@{}l@{\hspace{2\parindentlnth}}l@{}} 2368 \multicolumn{1}{ c@{\hspace{2\parindentlnth}}}{\textbf{Definition}} & \multicolumn{1}{c}{\textbf{Usage}} \\2369 \multicolumn{1}{@{}c@{\hspace{2\parindentlnth}}}{\textbf{Definition}} & \multicolumn{1}{c@{}}{\textbf{Usage}} \\ 2369 2370 \begin{cfa} 2370 2371 unsigned int `abs`( int ); … … 2385 2386 \lstDeleteShortInline@% 2386 2387 \begin{tabular}{@{}l@{\hspace{2\parindentlnth}}l@{}} 2387 \multicolumn{1}{ c@{\hspace{2\parindentlnth}}}{\textbf{\CFA}} & \multicolumn{1}{c}{\textbf{C}} \\2388 \multicolumn{1}{@{}c@{\hspace{2\parindentlnth}}}{\textbf{\CFA}} & \multicolumn{1}{c@{}}{\textbf{C}} \\ 2388 2389 \begin{cfa} 2389 2390 abs … … 2408 2409 an allocation with a specified character. 2409 2410 \item[resize] 2410 an existing allocation to decrease d or increasedits size.2411 an existing allocation to decrease or increase its size. 2411 2412 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. 2412 2413 For an increase in storage size, new storage after the copied data may be filled. … … 2447 2448 \begin{figure} 2448 2449 \centering 2449 \begin{cquote} 2450 \begin{cfa}[aboveskip=0pt] 2450 \begin{cfa}[aboveskip=0pt,xleftmargin=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{ 2\parindentlnth}}l@{}}2457 \multicolumn{1}{ c@{\hspace{2\parindentlnth}}}{\textbf{\CFA}} & \multicolumn{1}{c}{\textbf{C}} \\2458 \begin{cfa} 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] 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 ) ); 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} 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@% 2488 2487 \caption{\CFA versus C Storage-Allocation} 2489 2488 \label{f:StorageAllocation} … … 2498 2497 S * as = anew( dim, 2, 3 ); $\C{// each array element initialized to 2, 3}$ 2499 2498 \end{cfa} 2500 Note, \CC can only initializ ationarray elements via the default constructor.2499 Note, \CC can only initialize array elements via the default constructor. 2501 2500 2502 2501 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. … … 2515 2514 \lstDeleteShortInline@% 2516 2515 \begin{tabular}{@{}l@{\hspace{2\parindentlnth}}l@{}} 2517 \multicolumn{1}{ c@{\hspace{2\parindentlnth}}}{\textbf{\CFA}} & \multicolumn{1}{c}{\textbf{\CC}} \\2516 \multicolumn{1}{@{}c@{\hspace{2\parindentlnth}}}{\textbf{\CFA}} & \multicolumn{1}{c@{}}{\textbf{\CC}} \\ 2518 2517 \begin{cfa} 2519 2518 int x = 1, y = 2, z = 3; … … 2604 2603 \centering 2605 2604 \lstDeleteShortInline@% 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}} \\2605 \begin{tabular}{@{}l@{\hspace{3\parindentlnth}}l@{}} 2606 \multicolumn{1}{@{}c@{\hspace{3\parindentlnth}}}{\textbf{\CFA}} & \multicolumn{1}{c@{}}{\textbf{C}} \\ 2608 2607 \begin{cfa} 2609 2608 #include <gmp> … … 2638 2637 2639 2638 2640 \section{Polymorphi cEvaluation}2639 \section{Polymorphism Evaluation} 2641 2640 \label{sec:eval} 2642 2641 … … 2727 2726 Line-count is a fairly rough measure of code complexity; 2728 2727 another important factor is how much type information the programmer must specify manually, especially where that information is not compiler-checked. 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 un type-checked downcasts, \eg @object@ to @integer@ when popping a stack.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. 2730 2729 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. 2731 2730 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. 2732 2731 The \CFA benchmark is able to eliminate all redundant type annotations through use of the polymorphic @alloc@ function discussed in Section~\ref{sec:libraries}. 2733 2732 2734 We conjecture these results scale across most generic data-types as the underlying polymorphi cimplement is constant.2733 We conjecture these results scale across most generic data-types as the underlying polymorphism implement is constant. 2735 2734 2736 2735
Note: See TracChangeset
for help on using the changeset viewer.