Ignore:
File:
1 edited

Legend:

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

    r3d60c08 r387c9a1  
    6060\renewcommand{\textunderscore}{\leavevmode\makebox[1.2ex][c]{\rule{1ex}{0.075ex}}}
    6161
    62 \renewcommand*{\thefootnote}{\Alph{footnote}} % hack because fnsymbol does not work
     62\renewcommand*{\thefootnote}{\alph{footnote}} % hack because fnsymbol does not work
    6363%\renewcommand*{\thefootnote}{\fnsymbol{footnote}}
    6464
     
    249249All languages features discussed in this paper are working, except some advanced exception-handling features.
    250250Not 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).
    252252Ultimately, a compiler is necessary for advanced features and optimal performance.
    253253% @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
     
    323323There are only two hard things in Computer Science: cache invalidation and \emph{naming things} -- Phil Karlton
    324324\end{quote}
    325 \vspace{-9pt}
     325\vspace{-10pt}
    326326C 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.
    327327\CFA extends the built-in operator overloading by allowing users to define overloads for any function, not just operators, and even any variable;
     
    438438Hence, programmers can easily form local environments, adding and modifying appropriate functions, to maximize reuse of other existing functions and types.
    439439
    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}).
     440To 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}).
    441441\begin{cfa}
    442442forall( otype `T` ) {                                                   $\C{// distribution block, add forall qualifier to declarations}$
     
    480480\end{cquote}
    481481
    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:
     482In 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:
    484483\begin{cfa}
    485484trait otype( dtype T | sized(T) ) {  // sized is a pseudo-trait for types with known size and alignment
     
    499498Instead, 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.
    500499Hence, 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.)
    502501
    503502% Nominal inheritance can be simulated with traits using marker variables or functions:
     
    526525
    527526
     527\vspace*{-2pt}
    528528\section{Generic Types}
    529529
     
    571571Concrete types have a fixed memory layout regardless of type parameters, while dynamic types vary in memory layout depending on their type parameters.
    572572A \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.
     573Polymorphic 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.
    575574
    576575\CFA generic types also allow checked argument-constraints.
     
    956955}
    957956\end{cfa}
    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 ) {
     957One more step permits the summation of any summable type with all arguments of the same type:
     958\begin{cfa}
     959trait summable( otype T ) {
    961960        T ?+?( T, T );
    962961};
    963 forall( otype R | sumable( R ) ) R sum( R x, R y ) {
     962forall( otype R | summable( R ) ) R sum( R x, R y ) {
    964963        return x + y;
    965964}
    966 forall( otype R, ttype Params | sumable(R) | { R sum(R, Params); } ) R sum(R x, R y, Params rest) {
     965forall( otype R, ttype Params | summable(R) | { R sum(R, Params); } ) R sum(R x, R y, Params rest) {
    967966        return sum( x + y, rest );
    968967}
     
    11091108\begin{cquote}
    11101109\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}}        \\
    11131112\begin{cfa}
    11141113case 2, 10, 34, 42:
     
    11251124\lstDeleteShortInline@%
    11261125\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}}        \\
    11281127\begin{cfa}
    11291128case 2~42:
     
    11791178\lstDeleteShortInline@%
    11801179\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}}        \\
    11821181\begin{cfa}
    11831182`choose` ( day ) {
     
    12251224\lstDeleteShortInline@%
    12261225\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}}     \\
    12281227\begin{cfa}
    12291228choose ( ... ) {
     
    12691268\lstDeleteShortInline@%
    12701269\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}}      \\
    12721271\begin{cfa}
    12731272`LC:` {
     
    13651364\lstDeleteShortInline@%
    13661365\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}}      \\
    13681367\begin{cfa}
    13691368`exception R { int fix; };`
     
    16331632\lstDeleteShortInline@%
    16341633\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}}        \\
    16361635\begin{cfa}
    16371636`[5] *` int x1;
     
    16611660\lstDeleteShortInline@%
    16621661\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}}        \\
    16641663\begin{cfa}
    16651664`*` int x, y;
     
    16821681\lstDeleteShortInline@%
    16831682\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}}     \\
    16851684\begin{cfa}
    16861685[ 5 ] int z;
     
    17241723\lstDeleteShortInline@%
    17251724\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}}     \\
    17271726\begin{cfa}
    17281727extern const * const int x;
     
    17491748\lstDeleteShortInline@%
    17501749\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}}        \\
    17521751\begin{cfa}
    17531752y = (* int)x;
     
    17771776\lstDeleteShortInline@%
    17781777\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}}        \\
    17801779\begin{cfa}
    17811780[double] foo(), foo( int ), foo( double ) {...}
     
    17951794* [ * int ] ( int y ) gp;               $\C{// pointer to function returning pointer to int with int parameter}$
    17961795* [ ] ( 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}$
    17981797\end{cfa}
    17991798Note, the name of the function pointer is specified last, as for other variable declarations.
     
    19941993The symbol \lstinline+^+ is used for the destructor name because it was the last binary operator that could be used in a unary context.}.
    19951994The 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{...}@.
     1995Like other \CFA operators, these names represent the syntax used to call the constructor or destructor, \eg @?{}(x, ...)@ or @^{}(x, ...)@.
    19971996The constructor and destructor have return type @void@, and the first parameter is a reference to the object type to be constructed or destructed.
    19981997While 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 parameters after the @this@ parameter for specifying values for initialization/de-initialization\footnote{
     1998Both constructors and destructors allow additional parametes after the @this@ parameter for specifying values for initialization/de-initialization\footnote{
    20001999Destruction parameters are useful for specifying storage-management actions, such as de-initialize but not deallocate.}.
    20012000\begin{cfa}
     
    20042003void ^?{}( VLA & vla ) with ( vla ) { free( data ); } $\C{// destructor}$
    20052004{
    2006         VLA x;                                                                  $\C{// implicit:\ \ x\{\};}$
    2007 }                                                                                       $\C{// implicit:\ \textasciicircum{}x\{\};}$
     2005        VLA x;                                                                  $\C{// implicit:  ?\{\}( x );}$
     2006}                                                                                       $\C{// implicit:  ?\^{}\{\}( x );}$
    20082007\end{cfa}
    20092008@VLA@ is a \newterm{managed type}\footnote{
     
    20302029appropriate care is taken to not recursively call the copy constructor when initializing the second parameter.
    20312030
    2032 \CFA constructors may be explicitly called, 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.
    20332032Explicit 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:
     2033While existing call syntax works for explicit calls to constructors and destructors, \CFA also provides a more concise \newterm{operator syntax} for both:
    20352034\begin{cfa}
    20362035{
    20372036        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 );
    20392038        ^x{};                                                                   $\C{// deallocate x}$
    20402039        x{};                                                                    $\C{// reallocate x}$
     
    20432042        y{ x };                                                                 $\C{// reallocate y, points to x}$
    20442043        x{};                                                                    $\C{// reallocate x, not pointing to y}$
    2045         //  ^z{};  ^y{};  ^x{};
     2044        // ^?{}(z);  ^?{}(y);  ^?{}(x);
    20462045}
    20472046\end{cfa}
     
    20642063In these cases, \CFA provides the initialization syntax \lstinline|S x `@=` {}|, and the object becomes unmanaged, so implicit constructor and destructor calls are not generated.
    20652064Any 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.
     2065The same syntax can be used in a compound literal, \eg \lstinline|a = VLA`@`{ 0, 0x0 }|, to create a C-style literal.
    20672066The 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.
    20682067
     
    21202119
    21212120In C, @0@ has the special property that it is the only ``false'' value;
    2122 by the standard, any value that compares equal to @0@ is false, while any value that compares unequal to @0@ is true.
     2121from the standard, any value that compares equal to @0@ is false, while any value that compares unequal to @0@ is true.
    21232122As 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.
    21242123Operator 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.
     
    21552154\lstDeleteShortInline@%
    21562155\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}}  \\
    21582157\begin{cfa}
    21592158int |?`h|( int s );
     
    22002199\lstset{language=CFA,moredelim=**[is][\color{red}]{|}{|},deletedelim=**[is][]{`}{`}}
    22012200\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}}      \\
    22042203\begin{cfa}
    22052204struct W {
     
    22752274\lstDeleteShortInline@%
    22762275\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}}    \\
    22782277\begin{cfa}
    22792278const short int `MIN` = -32768;
     
    22942293\lstDeleteShortInline@%
    22952294\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}}        \\
    22972296\begin{cfa}
    22982297MIN
     
    23202319\lstDeleteShortInline@%
    23212320\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}}    \\
    23232322\begin{cfa}
    23242323float `log`( float x );
     
    23392338\lstDeleteShortInline@%
    23402339\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}}        \\
    23422341\begin{cfa}
    23432342log
     
    23672366\lstDeleteShortInline@%
    23682367\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}}    \\
    23702369\begin{cfa}
    23712370unsigned int `abs`( int );
     
    23862385\lstDeleteShortInline@%
    23872386\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}}        \\
    23892388\begin{cfa}
    23902389abs
     
    24092408an allocation with a specified character.
    24102409\item[resize]
    2411 an existing allocation to decrease or increase its size.
     2410an existing allocation to decreased or increased its size.
    24122411In 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.
    24132412For an increase in storage size, new storage after the copied data may be filled.
     
    24482447\begin{figure}
    24492448\centering
    2450 \begin{cfa}[aboveskip=0pt,xleftmargin=0pt]
     2449\begin{cquote}
     2450\begin{cfa}[aboveskip=0pt]
    24512451size_t  dim = 10;                                                       $\C{// array dimension}$
    24522452char fill = '\xff';                                                     $\C{// initialization fill value}$
     
    24542454\end{cfa}
    24552455\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}
    24592459ip = alloc();
    24602460ip = alloc( fill );
     
    24712471&
    24722472\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@%
     2473ip = (int *)malloc( sizeof( int ) );
     2474ip = (int *)malloc( sizeof( int ) ); memset( ip, fill, sizeof( int ) );
     2475ip = (int *)malloc( dim * sizeof( int ) );
     2476ip = (int *)malloc( sizeof( int ) ); memset( ip, fill, dim * sizeof( int ) );
     2477ip = (int *)realloc( ip, 2 * dim * sizeof( int ) );
     2478ip = (int *)realloc( ip, 4 * dim * sizeof( int ) );
     2479                        memset( ip, fill, 4 * dim * sizeof( int ) );
     2480ip = memalign( 16, sizeof( int ) );
     2481ip = memalign( 16, sizeof( int ) ); memset( ip, fill, sizeof( int ) );
     2482ip = memalign( 16, dim * sizeof( int ) );
     2483ip = memalign( 16, dim * sizeof( int ) ); memset( ip, fill, dim * sizeof( int ) );
     2484\end{cfa}
     2485\end{tabular}
     2486\lstMakeShortInline@%
     2487\end{cquote}
    24872488\caption{\CFA versus C Storage-Allocation}
    24882489\label{f:StorageAllocation}
     
    24972498S * as = anew( dim, 2, 3 );                                     $\C{// each array element initialized to 2, 3}$
    24982499\end{cfa}
    2499 Note, \CC can only initialize array elements via the default constructor.
     2500Note, \CC can only initialization array elements via the default constructor.
    25002501
    25012502Finally, the \CFA memory-allocator has \newterm{sticky properties} for dynamic storage: fill and alignment are remembered with an object's storage in the heap.
     
    25142515\lstDeleteShortInline@%
    25152516\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}}      \\
    25172518\begin{cfa}
    25182519int x = 1, y = 2, z = 3;
     
    26032604\centering
    26042605\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}}     \\
    26072608\begin{cfa}
    26082609#include <gmp>
     
    26372638
    26382639
    2639 \section{Polymorphism Evaluation}
     2640\section{Polymorphic Evaluation}
    26402641\label{sec:eval}
    26412642
     
    27262727Line-count is a fairly rough measure of code complexity;
    27272728another 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.
     2729Such 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.
    27292730To 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.
    27302731The \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.
    27312732The \CFA benchmark is able to eliminate all redundant type annotations through use of the polymorphic @alloc@ function discussed in Section~\ref{sec:libraries}.
    27322733
    2733 We conjecture these results scale across most generic data-types as the underlying polymorphism implement is constant.
     2734We conjecture these results scale across most generic data-types as the underlying polymorphic implement is constant.
    27342735
    27352736
Note: See TracChangeset for help on using the changeset viewer.