Changeset f3543b0


Ignore:
Timestamp:
Feb 15, 2018, 10:51:50 AM (7 years ago)
Author:
Peter A. Buhr <pabuhr@…>
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, resolv-new, with_gc
Children:
d27e340
Parents:
ed2bf54
Message:

update library discussion

File:
1 edited

Legend:

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

    red2bf54 rf3543b0  
    17631763In addition to the expressive power, \lstinline|@=| provides a simple path for migrating legacy C code to \CFA, by providing a mechanism to incrementally convert initializers; the \CFA design team decided to introduce a new syntax for this escape hatch because we believe that our RAII implementation will handle the vast majority of code in a desirable way, and we wished to maintain familiar syntax for this common case.
    17641764
     1765
     1766\subsection{Type Nesting}
     1767
     1768\CFA allows \newterm{type nesting}, and type qualification of the nested types (see Figure~\ref{f:TypeNestingQualification}), where as C hoists (refactors) nested types into the enclosing scope and has no type qualification.
     1769\begin{figure}
     1770\centering
     1771\lstDeleteShortInline@%
     1772\begin{tabular}{@{}l@{\hspace{3em}}l|l@{}}
     1773\multicolumn{1}{c@{\hspace{3em}}}{\textbf{C Type Nesting}}      & \multicolumn{1}{c}{\textbf{C Implicit Hoisting}}      & \multicolumn{1}{|c}{\textbf{\CFA}}    \\
     1774\hline
     1775\begin{cfa}
     1776struct S {
     1777        enum C { R, G, B };
     1778        struct T {
     1779                union U { int i, j; };
     1780                enum C c;
     1781                short int i, j;
     1782        };
     1783        struct T t;
     1784} s;
     1785
     1786int rtn() {
     1787        s.t.c = R;
     1788        struct T t = { R, 1, 2 };
     1789        enum C c;
     1790        union U u;
     1791}
     1792\end{cfa}
     1793&
     1794\begin{cfa}
     1795enum C { R, G, B };
     1796union U { int i, j; };
     1797struct T {
     1798        enum C c;
     1799        short int i, j;
     1800};
     1801struct S {
     1802        struct T t;
     1803} s;
     1804       
     1805
     1806
     1807
     1808
     1809
     1810
     1811\end{cfa}
     1812&
     1813\begin{cfa}
     1814struct S {
     1815        enum C { R, G, B };
     1816        struct T {
     1817                union U { int i, j; };
     1818                enum C c;
     1819                short int i, j;
     1820        };
     1821        struct T t;
     1822} s;
     1823
     1824int rtn() {
     1825        s.t.c = `S.`R;  // type qualification
     1826        struct `S.`T t = { `S.`R, 1, 2 };
     1827        enum `S.`C c;
     1828        union `S.T.`U u;
     1829}
     1830\end{cfa}
     1831\end{tabular}
     1832\lstMakeShortInline@%
     1833\caption{Type Nesting / Qualification}
     1834\label{f:TypeNestingQualification}
     1835\end{figure}
     1836In the left example in C, types @C@, @U@ and @T@ are implicitly hoisted outside of type @S@ into the containing block scope.
     1837In the right example in \CFA, the types are not hoisted and accessed using the field-selection operator ``@.@'' for type qualification, as does Java, rather than the \CC type-selection operator ``@::@''.
     1838
     1839
    17651840\subsection{Default Parameters}
    17661841
     
    18151890\section{Libraries}
    18161891
    1817 As stated in Section~\ref{sec:poly-fns}, \CFA inherits a massive corpus of library code, where other programming languages must rewrite or provide fragile inter-language communication with C.
    1818 \CFA has replacement libraries condensing hundreds of existing C routines into tens of \CFA overloaded routines, all without rewriting the actual computations.
     1892As stated in Section~\ref{sec:poly-fns}, \CFA inherits a large corpus of library code, where other programming languages must rewrite or provide fragile inter-language communication with C.
     1893\CFA has replacement libraries condensing hundreds of existing C names into tens of \CFA overloaded names, all without rewriting the actual computations.
    18191894In many cases, the interface is an inline wrapper providing overloading during compilation but zero cost at runtime.
    18201895The following sections give a glimpse of the interface reduction to many C libraries.
     
    19081983\lstMakeShortInline@%
    19091984\end{cquote}
    1910 While \Celeven provides type-generic math~\cite[\S~7.25]{C11} in @tgmath.h@ to provide a similar mechanism, these macros are limited, matching a routine name with a single set of floating type(s).
     1985While \Celeven has type-generic math~\cite[\S~7.25]{C11} in @tgmath.h@ to provide a similar mechanism, these macros are limited, matching a routine name with a single set of floating type(s).
    19111986For example, it is not possible to overload @atan@ for both one and two arguments;
    19121987instead the names @atan@ and @atan2@ are required.
     
    19552030\lstMakeShortInline@%
    19562031\end{cquote}
     2032In additon, there are polymorphic routines, like @min@ and @max@, which work on any type with operators @?<?@ or @?>?@.
    19572033
    19582034The following shows one example where \CFA \emph{extends} an existing standard C interface to reduce complexity and provide safety.
     
    19722048\end{description}
    19732049Table~\ref{t:StorageManagementOperations} shows the capabilities provided by C/\Celeven allocation-routines and how all the capabilities can be combined into two \CFA routines.
     2050
     2051\CFA storage-management routines extend the C equivalents by overloading, providing shallow type-safety, and removing the need to specify the base allocation-size.
    19742052The following example contrasts \CFA and C storage-allocation operation performing the same operations with the same type safety:
    19752053\begin{cquote}
    19762054\begin{cfa}[aboveskip=0pt]
    1977 size_t  dim = 10;
    1978 char fill = '\xff';
     2055size_t  dim = 10;                                                       $\C{// array dimension}$
     2056char fill = '\xff';                                                     $\C{// initialization fill value}$
    19792057int * ip;
    19802058\end{cfa}
     
    20132091\end{cquote}
    20142092Variadic @new@ (see Section~\ref{sec:variadic-tuples}) cannot support the same overloading because extra parameters are for initialization.
    2015 
    2016 Finally, the \CFA memory-allocator has \newterm{sticky properties} for dynamically-allocated storage: fill and alignment are remembered with an object's storage.
     2093Hence, there are @new@ and @anew@ routines for single and array variables, and the fill value is the arguments to the constructor, \eg:
     2094\begin{cfa}
     2095struct S { int i, j; };
     2096void ?{}( S & s, int i, int j ) { s.i = i; s.j = j; }
     2097S * s = new( 2, 3 );                                            $\C{// allocate storage and run constructor}$
     2098S * as = anew( dim, 2, 3 );                                     $\C{// each array element initialized to 2, 3}$
     2099\end{cfa}
     2100Note, \CC can only initialization array elements via the default constructor.
     2101
     2102Finally, the \CFA memory-allocator has \newterm{sticky properties} for dynamic storage: fill and alignment are remembered with an object's storage in the heap.
    20172103When a @realloc@ is performed, the sticky properties are respected, so that new storage is correctly aligned and initialized with the fill character.
    20182104
     
    21302216There are routines to set and get the separator string, and manipulators to toggle separation on and off in the middle of output.
    21312217\end{itemize}
    2132 The storage-management routines extend their C equivalents by overloading, alternate names, providing shallow type-safety, and removing the need to specify the allocation size for non-array types.
    21332218
    21342219
     
    21392224The \CFA interface wraps GMP routines into operator routines to make programming with multi-precision integers identical to using fixed-sized integers.
    21402225The \CFA type name for multi-precision signed-integers is @Int@ and the header file is @gmp@.
    2141 The following factorial programs contrast using GMP with the \CFA and C interfaces.
     2226The following multi-precision factorial programs contrast using GMP with the \CFA and C interfaces.
    21422227\begin{cquote}
    21432228\lstDeleteShortInline@%
Note: See TracChangeset for help on using the changeset viewer.