- Timestamp:
- Feb 14, 2018, 9:19:51 PM (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:
- 2dcb750
- Parents:
- cd310f7
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
doc/papers/general/Paper.tex
rcd310f7 r493d73a 6 6 \usepackage{upquote} % switch curled `'" to straight 7 7 \usepackage{listings} % format program code 8 \usepackage{enumitem} 8 9 \usepackage[flushmargin]{footmisc} % support label/reference in footnote 9 10 \usepackage{rotating} … … 1056 1057 \begin{cquote} 1057 1058 \lstDeleteShortInline@% 1058 \begin{tabular}{@{}l@{\hspace{ 3em}}l@{}}1059 \multicolumn{1}{c@{\hspace{ 3em}}}{\textbf{\CFA}} & \multicolumn{1}{c}{\textbf{C}} \\1059 \begin{tabular}{@{}l@{\hspace{\parindentlnth}}l@{}} 1060 \multicolumn{1}{c@{\hspace{\parindentlnth}}}{\textbf{\CFA}} & \multicolumn{1}{c}{\textbf{C}} \\ 1060 1061 \begin{cfa} 1061 1062 case 2, 10, 34, 42: … … 1071 1072 \begin{cquote} 1072 1073 \lstDeleteShortInline@% 1073 \begin{tabular}{@{}l@{\hspace{ 3em}}l@{}}1074 \multicolumn{1}{c@{\hspace{ 3em}}}{\textbf{\CFA}} & \multicolumn{1}{c}{\textbf{C}} \\1074 \begin{tabular}{@{}l@{\hspace{\parindentlnth}}l@{}} 1075 \multicolumn{1}{c@{\hspace{\parindentlnth}}}{\textbf{\CFA}} & \multicolumn{1}{c}{\textbf{C}} \\ 1075 1076 \begin{cfa} 1076 1077 case 2~42: … … 1123 1124 \begin{cquote} 1124 1125 \lstDeleteShortInline@% 1125 \begin{tabular}{@{}l@{\hspace{ 3em}}l@{}}1126 \multicolumn{1}{c@{\hspace{ 3em}}}{\textbf{\CFA}} & \multicolumn{1}{c}{\textbf{C}} \\1126 \begin{tabular}{@{}l@{\hspace{\parindentlnth}}l@{}} 1127 \multicolumn{1}{c@{\hspace{\parindentlnth}}}{\textbf{\CFA}} & \multicolumn{1}{c}{\textbf{C}} \\ 1127 1128 \begin{cfa} 1128 1129 `choose` ( day ) { … … 1379 1380 \lstDeleteShortInline@% 1380 1381 \lstset{moredelim=**[is][\color{blue}]{+}{+}} 1381 \begin{tabular}{@{}l@{\hspace{ 3em}}l@{}}1382 \multicolumn{1}{c@{\hspace{ 3em}}}{\textbf{\CFA}} & \multicolumn{1}{c}{\textbf{C}} \\1382 \begin{tabular}{@{}l@{\hspace{\parindentlnth}}l@{}} 1383 \multicolumn{1}{c@{\hspace{\parindentlnth}}}{\textbf{\CFA}} & \multicolumn{1}{c}{\textbf{C}} \\ 1383 1384 \begin{cfa} 1384 1385 +[5] *+ `int` x1; 1385 1386 +* [5]+ `int` x2; 1386 +[* [5] int]+ f`( int p )`;1387 `[* [5] int]` f+( int p )+; 1387 1388 \end{cfa} 1388 1389 & … … 1390 1391 `int` +*+ x1 +[5]+; 1391 1392 `int` +(*+x2+)[5]+; 1392 +int (*+f`( int p )`+)[5]+;1393 `int (*`f+( int p )+`)[5]`; 1393 1394 \end{cfa} 1394 1395 \end{tabular} … … 1401 1402 \begin{cquote} 1402 1403 \lstDeleteShortInline@% 1403 \begin{tabular}{@{}l@{\hspace{ 3em}}l@{}}1404 \multicolumn{1}{c@{\hspace{ 3em}}}{\textbf{\CFA}} & \multicolumn{1}{c}{\textbf{C}} \\1404 \begin{tabular}{@{}l@{\hspace{\parindentlnth}}l@{}} 1405 \multicolumn{1}{c@{\hspace{\parindentlnth}}}{\textbf{\CFA}} & \multicolumn{1}{c}{\textbf{C}} \\ 1405 1406 \begin{cfa} 1406 1407 `*` int x, y; … … 1416 1417 \begin{cquote} 1417 1418 \lstDeleteShortInline@% 1418 \begin{tabular}{@{}l@{\hspace{ 3em}}l@{}}1419 \multicolumn{1}{c@{\hspace{ 3em}}}{\textbf{\CFA}} & \multicolumn{1}{c}{\textbf{C}} \\1419 \begin{tabular}{@{}l@{\hspace{\parindentlnth}}l@{}} 1420 \multicolumn{1}{c@{\hspace{\parindentlnth}}}{\textbf{\CFA}} & \multicolumn{1}{c}{\textbf{C}} \\ 1420 1421 \begin{cfa} 1421 1422 `*` int x; … … 1434 1435 \begin{cquote} 1435 1436 \lstDeleteShortInline@% 1436 \begin{tabular}{@{}l@{\hspace{ 3em}}l@{\hspace{2em}}l@{}}1437 \multicolumn{1}{c@{\hspace{ 3em}}}{\textbf{\CFA}} & \multicolumn{1}{c@{\hspace{2em}}}{\textbf{C}} \\1437 \begin{tabular}{@{}l@{\hspace{\parindentlnth}}l@{\hspace{\parindentlnth}}l@{}} 1438 \multicolumn{1}{c@{\hspace{\parindentlnth}}}{\textbf{\CFA}} & \multicolumn{1}{c@{\hspace{\parindentlnth}}}{\textbf{C}} \\ 1438 1439 \begin{cfa} 1439 1440 [ 5 ] int z; … … 1475 1476 \begin{cquote} 1476 1477 \lstDeleteShortInline@% 1477 \begin{tabular}{@{}l@{\hspace{ 1em}}l@{\hspace{1em}}l@{}}1478 \multicolumn{1}{c@{\hspace{ 1em}}}{\textbf{\CFA}} & \multicolumn{1}{c@{\hspace{1em}}}{\textbf{C}} \\1478 \begin{tabular}{@{}l@{\hspace{\parindentlnth}}l@{\hspace{\parindentlnth}}l@{}} 1479 \multicolumn{1}{c@{\hspace{\parindentlnth}}}{\textbf{\CFA}} & \multicolumn{1}{c@{\hspace{\parindentlnth}}}{\textbf{C}} \\ 1479 1480 \begin{cfa} 1480 1481 const * const int x; … … 1498 1499 \begin{cquote} 1499 1500 \lstDeleteShortInline@% 1500 \begin{tabular}{@{}l@{\hspace{ 3em}}l@{\hspace{2em}}l@{}}1501 \multicolumn{1}{c@{\hspace{ 3em}}}{\textbf{\CFA}} & \multicolumn{1}{c@{\hspace{2em}}}{\textbf{C}} \\1501 \begin{tabular}{@{}l@{\hspace{\parindentlnth}}l@{\hspace{\parindentlnth}}l@{}} 1502 \multicolumn{1}{c@{\hspace{\parindentlnth}}}{\textbf{\CFA}} & \multicolumn{1}{c@{\hspace{\parindentlnth}}}{\textbf{C}} \\ 1502 1503 \begin{cfa} 1503 1504 extern [ 5 ] int x; … … 1521 1522 \begin{cquote} 1522 1523 \lstDeleteShortInline@% 1523 \begin{tabular}{@{}l@{\hspace{ 3em}}l@{}}1524 \multicolumn{1}{c@{\hspace{ 3em}}}{\textbf{\CFA}} & \multicolumn{1}{c}{\textbf{C}} \\1524 \begin{tabular}{@{}l@{\hspace{\parindentlnth}}l@{}} 1525 \multicolumn{1}{c@{\hspace{\parindentlnth}}}{\textbf{\CFA}} & \multicolumn{1}{c}{\textbf{C}} \\ 1525 1526 \begin{cfa} 1526 1527 y = (* int)x; … … 1552 1553 \begin{cquote} 1553 1554 \lstDeleteShortInline@% 1554 \begin{tabular}{@{}l@{\hspace{ 3em}}l@{}}1555 \multicolumn{1}{c@{\hspace{ 3em}}}{\textbf{\CFA}} & \multicolumn{1}{c}{\textbf{C}} \\1555 \begin{tabular}{@{}l@{\hspace{\parindentlnth}}l@{}} 1556 \multicolumn{1}{c@{\hspace{\parindentlnth}}}{\textbf{\CFA}} & \multicolumn{1}{c}{\textbf{C}} \\ 1556 1557 \begin{cfa} 1557 1558 [double] foo(), foo( int ), foo( double ) {...} … … 1815 1816 1816 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. 1817 \CFA has replacement libraries condensing hundreds of existing C functions into tens of \CFA overloaded functions, all without rewriting the actual computations.1818 \CFA has replacement libraries condensing hundreds of existing C routines into tens of \CFA overloaded routines, all without rewriting the actual computations. 1818 1819 In many cases, the interface is an inline wrapper providing overloading during compilation but zero cost at runtime. 1819 1820 The following sections give a gleams of the interface reduction to many C libraries. … … 1824 1825 1825 1826 C library @limits.h@ provides lower and upper bound constants for the basic types. 1826 \CFA name overloading is used to overload theseconstants, \eg:1827 \CFA name overloading is used to condense these typed constants, \eg: 1827 1828 \begin{cquote} 1828 1829 \lstDeleteShortInline@% 1829 \begin{tabular}{@{}l@{\hspace{ 3em}}l@{}}1830 \multicolumn{1}{c@{\hspace{ 3em}}}{\textbf{Definition}} & \multicolumn{1}{c}{\textbf{Usage}} \\1830 \begin{tabular}{@{}l@{\hspace{\parindentlnth}}l@{}} 1831 \multicolumn{1}{c@{\hspace{\parindentlnth}}}{\textbf{Definition}} & \multicolumn{1}{c}{\textbf{Usage}} \\ 1831 1832 \begin{cfa} 1832 1833 const short int `MIN` = -32768; … … 1846 1847 \begin{cquote} 1847 1848 \lstDeleteShortInline@% 1848 \begin{tabular}{@{}l@{\hspace{ 3em}}l@{}}1849 \multicolumn{1}{c@{\hspace{ 3em}}}{\textbf{\CFA}} & \multicolumn{1}{c}{\textbf{C}} \\1850 \begin{cfa} 1851 MIN ,1852 MAX ,1853 M_PI ,1849 \begin{tabular}{@{}l@{\hspace{\parindentlnth}}l@{}} 1850 \multicolumn{1}{c@{\hspace{\parindentlnth}}}{\textbf{\CFA}} & \multicolumn{1}{c}{\textbf{C}} \\ 1851 \begin{cfa} 1852 MIN 1853 MAX 1854 M_PI 1854 1855 M_E 1855 1856 \end{cfa} … … 1868 1869 \subsection{Math} 1869 1870 1870 C library @math.h@ provides lower and upper bound constants for the basic types.1871 \CFA name overloading is used to overload these constants, \eg:1871 C library @math.h@ provides many mathematical routines. 1872 \CFA routine overloading is used to condense these mathematical routines, \eg: 1872 1873 \begin{cquote} 1873 1874 \lstDeleteShortInline@% 1874 \begin{tabular}{@{}l@{\hspace{ 3em}}l@{}}1875 \multicolumn{1}{c@{\hspace{ 3em}}}{\textbf{Definition}} & \multicolumn{1}{c}{\textbf{Usage}} \\1875 \begin{tabular}{@{}l@{\hspace{\parindentlnth}}l@{}} 1876 \multicolumn{1}{c@{\hspace{\parindentlnth}}}{\textbf{Definition}} & \multicolumn{1}{c}{\textbf{Usage}} \\ 1876 1877 \begin{cfa} 1877 1878 float `log`( float x ); … … 1891 1892 \begin{cquote} 1892 1893 \lstDeleteShortInline@% 1893 \begin{tabular}{@{}l@{\hspace{ 3em}}l@{}}1894 \multicolumn{1}{c@{\hspace{ 3em}}}{\textbf{\CFA}} & \multicolumn{1}{c}{\textbf{C}} \\1895 \begin{cfa} 1896 log ,1897 sqrt ,1894 \begin{tabular}{@{}l@{\hspace{\parindentlnth}}l@{}} 1895 \multicolumn{1}{c@{\hspace{\parindentlnth}}}{\textbf{\CFA}} & \multicolumn{1}{c}{\textbf{C}} \\ 1896 \begin{cfa} 1897 log 1898 sqrt 1898 1899 sin 1899 1900 \end{cfa} … … 1907 1908 \lstMakeShortInline@% 1908 1909 \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). 1911 For example, it is not possible to overload @atan@ for both one and two arguments; 1912 instead the names @atan@ and @atan2@ are required. 1913 The key observation is that only a restricted set of type-generic macros are provided for a limited set of routine names, which do not generalize across the type system, as in \CFA. 1909 1914 1910 1915 1911 1916 \subsection{Standard} 1912 1917 1913 Library routines (@stdlib.h@) with multiple types. 1918 C library @stdlib.h@ provides many general routines. 1919 \CFA routine overloading is used to condense these utility routines, \eg: 1914 1920 \begin{cquote} 1915 1921 \lstDeleteShortInline@% 1916 \begin{tabular}{@{}l@{\hspace{ 3em}}l@{}}1917 \multicolumn{1}{c@{\hspace{ 3em}}}{\textbf{Definition}} & \multicolumn{1}{c}{\textbf{Usage}} \\1922 \begin{tabular}{@{}l@{\hspace{\parindentlnth}}l@{}} 1923 \multicolumn{1}{c@{\hspace{\parindentlnth}}}{\textbf{Definition}} & \multicolumn{1}{c}{\textbf{Usage}} \\ 1918 1924 \begin{cfa} 1919 1925 unsigned int `abs`( int ); … … 1930 1936 \lstMakeShortInline@% 1931 1937 \end{cquote} 1932 The result is a significant reduction in names to access mathroutines, \eg:1938 The result is a significant reduction in names to access utility routines, \eg: 1933 1939 \begin{cquote} 1934 1940 \lstDeleteShortInline@% 1935 \begin{tabular}{@{}l@{\hspace{ 3em}}l@{}}1936 \multicolumn{1}{c@{\hspace{ 3em}}}{\textbf{\CFA}} & \multicolumn{1}{c}{\textbf{C}} \\1937 \begin{cfa} 1938 abs ,1939 strto ,1941 \begin{tabular}{@{}l@{\hspace{\parindentlnth}}l@{}} 1942 \multicolumn{1}{c@{\hspace{\parindentlnth}}}{\textbf{\CFA}} & \multicolumn{1}{c}{\textbf{C}} \\ 1943 \begin{cfa} 1944 abs 1945 strto 1940 1946 random 1941 1947 \end{cfa} … … 1952 1958 The following shows one example where \CFA \emph{extends} an existing standard C interface to reduce complexity and provide safety. 1953 1959 C/\Celeven provide a number of complex and overlapping storage-management operation to support the following capabilities: 1954 \begin{description} 1960 \begin{description}[itemsep=2pt,parsep=0pt] 1955 1961 \item[fill] 1956 1962 after allocation the storage is filled with a specified character. … … 1966 1972 \end{description} 1967 1973 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. 1968 \begin{table}[h] 1974 The following example contrasts \CFA and C storage-allocation operation performing the same operations with the same type safety: 1975 \begin{cquote} 1976 \begin{cfa}[aboveskip=0pt] 1977 size_t dim = 10; 1978 char fill = '\xff'; 1979 int * ip; 1980 \end{cfa} 1981 \lstDeleteShortInline@% 1982 \begin{tabular}{@{}l@{\hspace{\parindentlnth}}l@{}} 1983 \multicolumn{1}{c@{\hspace{\parindentlnth}}}{\textbf{\CFA}} & \multicolumn{1}{c}{\textbf{C}} \\ 1984 \begin{cfa} 1985 ip = alloc(); 1986 ip = alloc( fill ); 1987 ip = alloc( dim ); 1988 ip = alloc( dim, fill ); 1989 ip = alloc( ip, 2 * dim ); 1990 ip = alloc( ip, 4 * dim, fill ); 1991 1992 ip = align_alloc( 16 ); 1993 ip = align_alloc( 16, fill ); 1994 ip = align_alloc( 16, dim ); 1995 ip = align_alloc( 16, dim, fill ); 1996 \end{cfa} 1997 & 1998 \begin{cfa} 1999 ip = (int *)malloc( sizeof( int ) ); 2000 ip = (int *)malloc( sizeof( int ) ); memset( ip, fill, sizeof( int ) ); 2001 ip = (int *)malloc( dim * sizeof( int ) ); 2002 ip = (int *)malloc( sizeof( int ) ); memset( ip, fill, dim * sizeof( int ) ); 2003 ip = (int *)realloc( ip, 2 * dim * sizeof( int ) ); 2004 ip = (int *)realloc( ip, 4 * dim * sizeof( int ) ); memset( ip, fill, 4 * dim * sizeof( int ) ); 2005 2006 ip = memalign( 16, sizeof( int ) ); 2007 ip = memalign( 16, sizeof( int ) ); memset( ip, fill, sizeof( int ) ); 2008 ip = memalign( 16, dim * sizeof( int ) ); 2009 ip = memalign( 16, dim * sizeof( int ) ); memset( ip, fill, dim * sizeof( int ) ); 2010 \end{cfa} 2011 \end{tabular} 2012 \lstMakeShortInline@% 2013 \end{cquote} 2014 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. 2017 When a @realloc@ is performed, the sticky properties are respected, so that new storage is correctly aligned and initialized with the fill character. 2018 2019 \begin{table} 1969 2020 \centering 1970 2021 \lstDeleteShortInline@% … … 1981 2032 C11 & ~aligned_alloc~ & no & no & yes & no \\ 1982 2033 \hline 1983 \CFA & ~alloc~ & no/copy/yes& no/yes & no & yes \\1984 & ~align_alloc~ & no/yes& no & yes & yes \\2034 \CFA & ~alloc~ & yes/copy & no/yes & no & yes \\ 2035 & ~align_alloc~ & yes & no & yes & yes \\ 1985 2036 \end{tabular} 1986 2037 \lstDeleteShortInline~% … … 1989 2040 \label{t:StorageManagementOperations} 1990 2041 \end{table} 1991 It is impossible to resize with alignment because the underlying @realloc@ allocates storage if more space is needed, and it does not honour alignment from the original allocation.1992 2042 1993 2043 … … 2002 2052 \begin{cquote} 2003 2053 \lstDeleteShortInline@% 2004 \begin{tabular}{@{}l@{\hspace{ 3em}}l@{}}2005 \multicolumn{1}{c@{\hspace{ 3em}}}{\textbf{\CFA}} & \multicolumn{1}{c}{\textbf{\CC}} \\2054 \begin{tabular}{@{}l@{\hspace{\parindentlnth}}l@{}} 2055 \multicolumn{1}{c@{\hspace{\parindentlnth}}}{\textbf{\CFA}} & \multicolumn{1}{c}{\textbf{\CC}} \\ 2006 2056 \begin{cfa} 2007 2057 int x = 1, y = 2, z = 3; … … 2062 2112 The implicit separator character (space/blank) is a separator not a terminator. 2063 2113 The rules for implicitly adding the separator are: 2064 \begin{ list}{\footnotesize$\bullet$}{\itemsep=2pt\parsep=0pt}2114 \begin{itemize}[itemsep=2pt,parsep=0pt] 2065 2115 \item 2066 2116 A separator does not appear at the start or end of a line. … … 2079 2129 \item 2080 2130 There are routines to set and get the separator string, and manipulators to toggle separation on and off in the middle of output. 2081 \end{ list}2131 \end{itemize} 2082 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. 2083 2133
Note: See TracChangeset
for help on using the changeset viewer.