Changeset f3543b0
- Timestamp:
- Feb 15, 2018, 10:51:50 AM (7 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, resolv-new, with_gc
- Children:
- d27e340
- Parents:
- ed2bf54
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
doc/papers/general/Paper.tex
red2bf54 rf3543b0 1763 1763 In 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. 1764 1764 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} 1776 struct 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 1786 int 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} 1795 enum C { R, G, B }; 1796 union U { int i, j; }; 1797 struct T { 1798 enum C c; 1799 short int i, j; 1800 }; 1801 struct S { 1802 struct T t; 1803 } s; 1804 1805 1806 1807 1808 1809 1810 1811 \end{cfa} 1812 & 1813 \begin{cfa} 1814 struct 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 1824 int 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} 1836 In the left example in C, types @C@, @U@ and @T@ are implicitly hoisted outside of type @S@ into the containing block scope. 1837 In 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 1765 1840 \subsection{Default Parameters} 1766 1841 … … 1815 1890 \section{Libraries} 1816 1891 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.1892 As 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. 1819 1894 In many cases, the interface is an inline wrapper providing overloading during compilation but zero cost at runtime. 1820 1895 The following sections give a glimpse of the interface reduction to many C libraries. … … 1908 1983 \lstMakeShortInline@% 1909 1984 \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).1985 While \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). 1911 1986 For example, it is not possible to overload @atan@ for both one and two arguments; 1912 1987 instead the names @atan@ and @atan2@ are required. … … 1955 2030 \lstMakeShortInline@% 1956 2031 \end{cquote} 2032 In additon, there are polymorphic routines, like @min@ and @max@, which work on any type with operators @?<?@ or @?>?@. 1957 2033 1958 2034 The following shows one example where \CFA \emph{extends} an existing standard C interface to reduce complexity and provide safety. … … 1972 2048 \end{description} 1973 2049 Table~\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. 1974 2052 The following example contrasts \CFA and C storage-allocation operation performing the same operations with the same type safety: 1975 2053 \begin{cquote} 1976 2054 \begin{cfa}[aboveskip=0pt] 1977 size_t dim = 10; 1978 char fill = '\xff'; 2055 size_t dim = 10; $\C{// array dimension}$ 2056 char fill = '\xff'; $\C{// initialization fill value}$ 1979 2057 int * ip; 1980 2058 \end{cfa} … … 2013 2091 \end{cquote} 2014 2092 Variadic @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. 2093 Hence, 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} 2095 struct S { int i, j; }; 2096 void ?{}( S & s, int i, int j ) { s.i = i; s.j = j; } 2097 S * s = new( 2, 3 ); $\C{// allocate storage and run constructor}$ 2098 S * as = anew( dim, 2, 3 ); $\C{// each array element initialized to 2, 3}$ 2099 \end{cfa} 2100 Note, \CC can only initialization array elements via the default constructor. 2101 2102 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. 2017 2103 When a @realloc@ is performed, the sticky properties are respected, so that new storage is correctly aligned and initialized with the fill character. 2018 2104 … … 2130 2216 There are routines to set and get the separator string, and manipulators to toggle separation on and off in the middle of output. 2131 2217 \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.2133 2218 2134 2219 … … 2139 2224 The \CFA interface wraps GMP routines into operator routines to make programming with multi-precision integers identical to using fixed-sized integers. 2140 2225 The \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.2226 The following multi-precision factorial programs contrast using GMP with the \CFA and C interfaces. 2142 2227 \begin{cquote} 2143 2228 \lstDeleteShortInline@%
Note: See TracChangeset
for help on using the changeset viewer.