Ignore:
Timestamp:
May 11, 2018, 10:42:18 AM (4 years ago)
Author:
Thierry Delisle <tdelisle@…>
Branches:
aaron-thesis, arm-eh, cleanup-dtors, deferred_resn, demangler, jacob/cs343-translation, jenkins-sandbox, master, new-ast, new-ast-unique-expr, new-env, no_list, persistent-indexer, with_gc
Children:
705e612
Parents:
de94a60 (diff), a8de0f4 (diff)
Note: this is a merge changeset, the changes displayed below correspond to the merge itself.
Use the (diff) links above to see all the changes relative to each parent.
Message:

Merge branch 'master' of plg.uwaterloo.ca:software/cfa/cfa-cc

File:
1 edited

Legend:

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

    rde94a60 r78af962  
    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 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).
     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).
    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{-10pt}
     325\vspace{-9pt}
    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 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}).
     440To 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}).
    441441\begin{cfa}
    442442forall( otype `T` ) {                                                   $\C{// distribution block, add forall qualifier to declarations}$
     
    480480\end{cquote}
    481481
    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:
     482Note, the @sumable@ trait does not include a copy constructor needed for the right side of @?+=?@ and return;
     483it is provided by @otype@, which is syntactic sugar for the following trait:
    483484\begin{cfa}
    484485trait otype( dtype T | sized(T) ) {  // sized is a pseudo-trait for types with known size and alignment
     
    498499Instead, 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.
    499500Hence, 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.)
    501502
    502503% Nominal inheritance can be simulated with traits using marker variables or functions:
     
    525526
    526527
    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, \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.
     573Polymorphic pointers are an example of dtype-static types;
     574given 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.
    574575
    575576\CFA generic types also allow checked argument-constraints.
     
    955956}
    956957\end{cfa}
    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 ) {
     958One more step permits the summation of any sumable type with all arguments of the same type:
     959\begin{cfa}
     960trait sumable( otype T ) {
    960961        T ?+?( T, T );
    961962};
    962 forall( otype R | summable( R ) ) R sum( R x, R y ) {
     963forall( otype R | sumable( R ) ) R sum( R x, R y ) {
    963964        return x + y;
    964965}
    965 forall( otype R, ttype Params | summable(R) | { R sum(R, Params); } ) R sum(R x, R y, Params rest) {
     966forall( otype R, ttype Params | sumable(R) | { R sum(R, Params); } ) R sum(R x, R y, Params rest) {
    966967        return sum( x + y, rest );
    967968}
     
    11081109\begin{cquote}
    11091110\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}}     \\
    11121113\begin{cfa}
    11131114case 2, 10, 34, 42:
     
    11241125\lstDeleteShortInline@%
    11251126\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}}     \\
    11271128\begin{cfa}
    11281129case 2~42:
     
    11781179\lstDeleteShortInline@%
    11791180\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}}     \\
    11811182\begin{cfa}
    11821183`choose` ( day ) {
     
    12241225\lstDeleteShortInline@%
    12251226\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}}  \\
    12271228\begin{cfa}
    12281229choose ( ... ) {
     
    12681269\lstDeleteShortInline@%
    12691270\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}}   \\
    12711272\begin{cfa}
    12721273`LC:` {
     
    13641365\lstDeleteShortInline@%
    13651366\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}}   \\
    13671368\begin{cfa}
    13681369`exception R { int fix; };`
     
    16321633\lstDeleteShortInline@%
    16331634\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}}     \\
    16351636\begin{cfa}
    16361637`[5] *` int x1;
     
    16601661\lstDeleteShortInline@%
    16611662\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}}     \\
    16631664\begin{cfa}
    16641665`*` int x, y;
     
    16811682\lstDeleteShortInline@%
    16821683\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}}     \\
    16841685\begin{cfa}
    16851686[ 5 ] int z;
     
    17231724\lstDeleteShortInline@%
    17241725\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}}     \\
    17261727\begin{cfa}
    17271728extern const * const int x;
     
    17481749\lstDeleteShortInline@%
    17491750\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}}     \\
    17511752\begin{cfa}
    17521753y = (* int)x;
     
    17761777\lstDeleteShortInline@%
    17771778\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}}     \\
    17791780\begin{cfa}
    17801781[double] foo(), foo( int ), foo( double ) {...}
     
    17941795* [ * int ] ( int y ) gp;               $\C{// pointer to function returning pointer to int with int parameter}$
    17951796* [ ] ( 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$
    17971798\end{cfa}
    17981799Note, the name of the function pointer is specified last, as for other variable declarations.
     
    19931994The symbol \lstinline+^+ is used for the destructor name because it was the last binary operator that could be used in a unary context.}.
    19941995The 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, ...)@.
     1996Like other \CFA operators, these names represent the syntax used to explicitly call the constructor or destructor, \eg @s{...}@ or @^s{...}@.
    19961997The constructor and destructor have return type @void@, and the first parameter is a reference to the object type to be constructed or destructed.
    19971998While 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 parametes after the @this@ parameter for specifying values for initialization/de-initialization\footnote{
     1999Both constructors and destructors allow additional parameters after the @this@ parameter for specifying values for initialization/de-initialization\footnote{
    19992000Destruction parameters are useful for specifying storage-management actions, such as de-initialize but not deallocate.}.
    20002001\begin{cfa}
     
    20032004void ^?{}( VLA & vla ) with ( vla ) { free( data ); } $\C{// destructor}$
    20042005{
    2005         VLA x;                                                                  $\C{// implicit:  ?\{\}( x );}$
    2006 }                                                                                       $\C{// implicit:  ?\^{}\{\}( x );}$
     2006        VLA x;                                                                  $\C{// implicit:\ \ x\{\};}$
     2007}                                                                                       $\C{// implicit:\ \textasciicircum{}x\{\};}$
    20072008\end{cfa}
    20082009@VLA@ is a \newterm{managed type}\footnote{
     
    20292030appropriate care is taken to not recursively call the copy constructor when initializing the second parameter.
    20302031
    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.
    20322033Explicit 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:
     2034Like the other operators in \CFA, there is a concise syntax for constructor/destructor function calls:
    20342035\begin{cfa}
    20352036{
    20362037        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 };
    20382039        ^x{};                                                                   $\C{// deallocate x}$
    20392040        x{};                                                                    $\C{// reallocate x}$
     
    20422043        y{ x };                                                                 $\C{// reallocate y, points to x}$
    20432044        x{};                                                                    $\C{// reallocate x, not pointing to y}$
    2044         // ^?{}(z);  ^?{}(y);  ^?{}(x);
     2045        //  ^z{};  ^y{};  ^x{};
    20452046}
    20462047\end{cfa}
     
    20632064In these cases, \CFA provides the initialization syntax \lstinline|S x `@=` {}|, and the object becomes unmanaged, so implicit constructor and destructor calls are not generated.
    20642065Any 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.
     2066The same syntax can be used in a compound literal, \eg \lstinline|a = (VLA)`@`{ 0, 0x0 }|, to create a C-style literal.
    20662067The 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.
    20672068
     
    21192120
    21202121In C, @0@ has the special property that it is the only ``false'' value;
    2121 from the standard, any value that compares equal to @0@ is false, while any value that compares unequal to @0@ is true.
     2122by the standard, any value that compares equal to @0@ is false, while any value that compares unequal to @0@ is true.
    21222123As 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.
    21232124Operator 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.
     
    21542155\lstDeleteShortInline@%
    21552156\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}}       \\
    21572158\begin{cfa}
    21582159int |?`h|( int s );
     
    21992200\lstset{language=CFA,moredelim=**[is][\color{red}]{|}{|},deletedelim=**[is][]{`}{`}}
    22002201\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}}   \\
    22032204\begin{cfa}
    22042205struct W {
     
    22742275\lstDeleteShortInline@%
    22752276\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}} \\
    22772278\begin{cfa}
    22782279const short int `MIN` = -32768;
     
    22932294\lstDeleteShortInline@%
    22942295\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}}     \\
    22962297\begin{cfa}
    22972298MIN
     
    23192320\lstDeleteShortInline@%
    23202321\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}} \\
    23222323\begin{cfa}
    23232324float `log`( float x );
     
    23382339\lstDeleteShortInline@%
    23392340\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}}     \\
    23412342\begin{cfa}
    23422343log
     
    23662367\lstDeleteShortInline@%
    23672368\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}} \\
    23692370\begin{cfa}
    23702371unsigned int `abs`( int );
     
    23852386\lstDeleteShortInline@%
    23862387\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}}     \\
    23882389\begin{cfa}
    23892390abs
     
    24082409an allocation with a specified character.
    24092410\item[resize]
    2410 an existing allocation to decreased or increased its size.
     2411an existing allocation to decrease or increase its size.
    24112412In 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.
    24122413For an increase in storage size, new storage after the copied data may be filled.
     
    24472448\begin{figure}
    24482449\centering
    2449 \begin{cquote}
    2450 \begin{cfa}[aboveskip=0pt]
     2450\begin{cfa}[aboveskip=0pt,xleftmargin=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{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]
    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 ) );
    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}
     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) ); memset( ip, fill, 4 * dim * sizeof(int));
     2479
     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@%
    24882487\caption{\CFA versus C Storage-Allocation}
    24892488\label{f:StorageAllocation}
     
    24982497S * as = anew( dim, 2, 3 );                                     $\C{// each array element initialized to 2, 3}$
    24992498\end{cfa}
    2500 Note, \CC can only initialization array elements via the default constructor.
     2499Note, \CC can only initialize array elements via the default constructor.
    25012500
    25022501Finally, the \CFA memory-allocator has \newterm{sticky properties} for dynamic storage: fill and alignment are remembered with an object's storage in the heap.
     
    25152514\lstDeleteShortInline@%
    25162515\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}}   \\
    25182517\begin{cfa}
    25192518int x = 1, y = 2, z = 3;
     
    26042603\centering
    26052604\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}}     \\
    26082607\begin{cfa}
    26092608#include <gmp>
     
    26382637
    26392638
    2640 \section{Polymorphic Evaluation}
     2639\section{Polymorphism Evaluation}
    26412640\label{sec:eval}
    26422641
     
    27272726Line-count is a fairly rough measure of code complexity;
    27282727another 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 untype-checked downcasts, \eg @object@ to @integer@ when popping a stack.
     2728Such 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.
    27302729To 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.
    27312730The \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.
    27322731The \CFA benchmark is able to eliminate all redundant type annotations through use of the polymorphic @alloc@ function discussed in Section~\ref{sec:libraries}.
    27332732
    2734 We conjecture these results scale across most generic data-types as the underlying polymorphic implement is constant.
     2733We conjecture these results scale across most generic data-types as the underlying polymorphism implement is constant.
    27352734
    27362735
Note: See TracChangeset for help on using the changeset viewer.