- Timestamp:
- May 29, 2017, 3:08:47 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:
- 2ab67b9, a029714
- Parents:
- ff98952 (diff), 4c5b972 (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. - Location:
- doc
- Files:
-
- 2 added
- 4 edited
Legend:
- Unmodified
- Added
- Removed
-
doc/LaTeXmacros/lstlang.sty
rff98952 r4a368547 8 8 %% Created On : Sat May 13 16:34:42 2017 9 9 %% Last Modified By : Peter A. Buhr 10 %% Last Modified On : Sat May 13 16:49:09 201711 %% Update Count : 410 %% Last Modified On : Fri May 26 12:47:09 2017 11 %% Update Count : 8 12 12 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% 13 13 … … 118 118 } 119 119 120 % uC++ programming language, based on ANSI C++ 121 \lstdefinelanguage{uC++}[ANSI]{C++}{ 122 morekeywords={ 123 _Accept, _AcceptReturn, _AcceptWait, _Actor, _At, _CatchResume, _Cormonitor, _Coroutine, _Disable, 124 _Else, _Enable, _Event, _Finally, _Monitor, _Mutex, _Nomutex, _PeriodicTask, _RealTimeTask, 125 _Resume, _Select, _SporadicTask, _Task, _Timeout, _When, _With, _Throw}, 126 } 127 120 128 % Local Variables: % 121 129 % tab-width: 4 % -
doc/bibliography/cfa.bib
rff98952 r4a368547 3035 3035 year = 1992, 3036 3036 pages = {T1-53}, 3037 } 3038 3039 @manual{GMP, 3040 keywords = {GMP arbitrary-precision library}, 3041 contributer = {pabuhr@plg}, 3042 title = {{GNU} Multiple Precision Arithmetic Library}, 3043 author = {GMP}, 3044 organization= {GNU}, 3045 year = 2016, 3046 note = {\href{https://gmplib.org}{https://\-gmplib.org}}, 3037 3047 } 3038 3048 -
doc/user/user.tex
rff98952 r4a368547 11 11 %% Created On : Wed Apr 6 14:53:29 2016 12 12 %% Last Modified By : Peter A. Buhr 13 %% Last Modified On : Sun May 21 23:36:42 201714 %% Update Count : 1 82213 %% Last Modified On : Wed May 24 22:21:42 2017 14 %% Update Count : 1994 15 15 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% 16 16 … … 151 151 152 152 Like \Index*[C++]{\CC}, there may be both an old and new ways to achieve the same effect. 153 For example, the following programs compare the \CFA and C I/O mechanisms.153 For example, the following programs compare the \CFA, C, nad \CC I/O mechanisms, where the programs output the same result. 154 154 \begin{quote2} 155 155 \begin{tabular}{@{}l@{\hspace{1.5em}}l@{\hspace{1.5em}}l@{}} … … 183 183 \end{tabular} 184 184 \end{quote2} 185 The programs output the same result.186 185 While the \CFA I/O looks similar to the \Index*[C++]{\CC} output style, there are important differences, such as automatic spacing between variables as in \Index*{Python} (see~\VRef{s:IOLibrary}). 187 186 … … 1426 1425 1427 1426 1428 \section{Type/Routine Nesting} 1427 \section{Unnamed Structure Fields} 1428 1429 C requires each field of a structure to have a name, except for a bit field associated with a basic type, \eg: 1430 \begin{cfa} 1431 struct { 1432 int f1; §\C{// named field}§ 1433 int f2 : 4; §\C{// named field with bit field size}§ 1434 int : 3; §\C{// unnamed field for basic type with bit field size}§ 1435 int ; §\C{// disallowed, unnamed field}§ 1436 int *; §\C{// disallowed, unnamed field}§ 1437 int (*)(int); §\C{// disallowed, unnamed field}§ 1438 }; 1439 \end{cfa} 1440 This requirement is relaxed by making the field name optional for all field declarations; therefore, all the field declarations in the example are allowed. 1441 As for unnamed bit fields, an unnamed field is used for padding a structure to a particular size. 1442 A list of unnamed fields is also supported, \eg: 1443 \begin{cfa} 1444 struct { 1445 int , , ; §\C{// 3 unnamed fields}§ 1446 } 1447 \end{cfa} 1448 1449 1450 \section{Nesting} 1429 1451 1430 1452 Nesting of types and routines is useful for controlling name visibility (\newterm{name hiding}). … … 1796 1818 1797 1819 1798 \section{Unnamed Structure Fields}1799 1800 C requires each field of a structure to have a name, except for a bit field associated with a basic type, \eg:1801 \begin{cfa}1802 struct {1803 int f1; §\C{// named field}§1804 int f2 : 4; §\C{// named field with bit field size}§1805 int : 3; §\C{// unnamed field for basic type with bit field size}§1806 int ; §\C{// disallowed, unnamed field}§1807 int *; §\C{// disallowed, unnamed field}§1808 int (*)(int); §\C{// disallowed, unnamed field}§1809 };1810 \end{cfa}1811 This requirement is relaxed by making the field name optional for all field declarations; therefore, all the field declarations in the example are allowed.1812 As for unnamed bit fields, an unnamed field is used for padding a structure to a particular size.1813 A list of unnamed fields is also supported, \eg:1814 \begin{cfa}1815 struct {1816 int , , ; §\C{// 3 unnamed fields}§1817 }1818 \end{cfa}1819 1820 1821 1820 \section{Field Tuples} 1822 1821 … … 1861 1860 1862 1861 While C provides ©continue© and ©break© statements for altering control flow, both are restricted to one level of nesting for a particular control structure. 1863 Unfortunately, this restriction forces programmers to use ©goto©to achieve the equivalent control-flow for more than one level of nesting.1864 To prevent having to switch to the ©goto©, \CFA extends the ©continue©\index{continue@©continue©}\index{continue@©continue©!labelled}\index{labelled!continue@©continue©} and ©break©\index{break@©break©}\index{break@©break©!labelled}\index{labelled!break@©break©} with a target label to support static multi-level exit\index{multi-level exit}\index{static multi-level exit}~\cite{Buhr85,Java}.1862 Unfortunately, this restriction forces programmers to use \Indexc{goto} to achieve the equivalent control-flow for more than one level of nesting. 1863 To prevent having to switch to the ©goto©, \CFA extends the \Indexc{continue}\index{continue@©continue©!labelled}\index{labelled!continue@©continue©} and \Indexc{break}\index{break@©break©!labelled}\index{labelled!break@©break©} with a target label to support static multi-level exit\index{multi-level exit}\index{static multi-level exit}~\cite{Buhr85,Java}. 1865 1864 For both ©continue© and ©break©, the target label must be directly associated with a ©for©, ©while© or ©do© statement; 1866 1865 for ©break©, the target label can also be associated with a ©switch©, ©if© or compound (©{}©) statement. 1867 1868 The following example shows the labelled ©continue© specifying which control structure is the target for the next loop iteration: 1869 \begin{quote2} 1870 \begin{tabular}{@{}l@{\hspace{3em}}l@{}} 1871 \multicolumn{1}{c@{\hspace{3em}}}{\textbf{\CFA}} & \multicolumn{1}{c}{\textbf{C}} \\ 1872 \begin{cfa} 1873 ®L1:® do { 1874 ®L2:® while ( ... ) { 1875 ®L3:® for ( ... ) { 1876 ... continue ®L1®; ... // continue do 1877 ... continue ®L2®; ... // continue while 1878 ... continue ®L3®; ... // continue for 1879 } // for 1880 } // while 1881 } while ( ... ); 1882 \end{cfa} 1883 & 1884 \begin{cfa} 1885 do { 1886 while ( ... ) { 1887 for ( ... ) { 1888 ... goto L1; ... 1889 ... goto L2; ... 1890 ... goto L3; ... 1891 L3: ; } 1892 L2: ; } 1893 L1: ; } while ( ... ); 1894 \end{cfa} 1895 \end{tabular} 1896 \end{quote2} 1897 The innermost loop has three restart points, which cause the next loop iteration to begin. 1898 1899 The following example shows the labelled ©break© specifying which control structure is the target for exit: 1900 \begin{quote2} 1901 \begin{tabular}{@{}l@{\hspace{3em}}l@{}} 1902 \multicolumn{1}{c@{\hspace{3em}}}{\textbf{\CFA}} & \multicolumn{1}{c}{\textbf{C}} \\ 1903 \begin{cfa} 1904 ®L1:® { 1866 \VRef[Figure]{f:MultiLevelResumeTermination} shows the labelled ©continue© and ©break©, specifying which control structure is the target for exit, and the corresponding C program using only ©goto©. 1867 The innermost loop has 7 exit points, which cause resumption or termination of one or more of the 7 \Index{nested control-structure}s. 1868 1869 \begin{figure} 1870 \begin{tabular}{@{\hspace{\parindentlnth}}l@{\hspace{1.5em}}l@{}} 1871 \multicolumn{1}{c@{\hspace{1.5em}}}{\textbf{\CFA}} & \multicolumn{1}{c}{\textbf{C}} \\ 1872 \begin{cfa} 1873 ®LC:® { 1905 1874 ... §declarations§ ... 1906 ®L 2:® switch ( ... ) {1875 ®LS:® switch ( ... ) { 1907 1876 case 3: 1908 ®L3:® if ( ... ) { 1909 ®L4:® for ( ... ) { 1910 ... break ®L1®; ... // exit compound statement 1911 ... break ®L2®; ... // exit switch 1912 ... break ®L3®; ... // exit if 1913 ... break ®L4®; ... // exit loop 1877 ®LIF:® if ( ... ) { 1878 ®LF:® for ( ... ) { 1879 ®LW:® while ( ... ) { 1880 ... break ®LC®; ... // terminate compound 1881 ... break ®LS®; ... // terminate switch 1882 ... break ®LIF®; ... // terminate if 1883 ... continue ®LF;® ... // resume loop 1884 ... break ®LF®; ... // terminate loop 1885 ... continue ®LW®; ... // resume loop 1886 ... break ®LW®; ... // terminate loop 1887 } // while 1914 1888 } // for 1915 1889 } else { 1916 ... break ®L 3®; ... // exitif1890 ... break ®LIF®; ... // terminate if 1917 1891 } // if 1918 1892 } // switch … … 1925 1899 switch ( ... ) { 1926 1900 case 3: 1927 1901 if ( ... ) { 1928 1902 for ( ... ) { 1929 ... goto L1; ... 1930 ... goto L2; ... 1931 ... goto L3; ... 1932 ... goto L4; ... 1933 } L4: ; 1903 for ( ... ) { 1904 ... goto ®LC®; ... 1905 ... goto ®LS®; ... 1906 ... goto ®LIF®; ... 1907 ... goto ®LFC®; ... 1908 ... goto ®LFB®; ... 1909 ... goto ®LWC®; ... 1910 ... goto ®LWB®; ... 1911 ®LWC®: ; } ®LWB:® ; 1912 ®LFC:® ; } ®LFB:® ; 1934 1913 } else { 1935 ... goto L3; ...1936 } L3:;1937 } L2:;1938 } L1:;1914 ... goto ®LIF®; ... 1915 } ®L3:® ; 1916 } ®LS:® ; 1917 } ®LC:® ; 1939 1918 \end{cfa} 1940 1919 \end{tabular} 1941 \end{quote2} 1942 The innermost loop has four exit points, which cause termination of one or more of the four \Index{nested control structure}s. 1943 1944 Both ©continue© and ©break© with target labels are simply a ©goto©\index{goto@©goto©!restricted} restricted in the following ways: 1920 \caption{Multi-level Resume/Termination} 1921 \label{f:MultiLevelResumeTermination} 1922 \end{figure} 1923 1924 Both labelled ©continue© and ©break© are a ©goto©\index{goto@©goto©!restricted} restricted in the following ways: 1945 1925 \begin{itemize} 1946 1926 \item 1947 They cannot be used to create a loop.1948 This means that only the looping construct can be used to create a loop.1949 This restriction is important since all situations that can result in repeated execution of statements in a program are clearly delineated. 1950 \item 1951 Since they always transfer out of containing control structures, they cannot be used to branch into a control structure.1927 They cannot create a loop, which means only the looping constructs cause looping. 1928 This restriction means all situations resulting in repeated execution are clearly delineated. 1929 \item 1930 They cannot branch into a control structure. 1931 This restriction prevents missing initialization at the start of a control structure resulting in undefined behaviour. 1952 1932 \end{itemize} 1953 The advantage of the labelled ©continue©/©break© is allowing static multi-level exits without having to use the ©goto© statement and tying control flow to the target control structure rather than an arbitrary point in a program.1933 The advantage of the labelled ©continue©/©break© is allowing static multi-level exits without having to use the ©goto© statement, and tying control flow to the target control structure rather than an arbitrary point in a program. 1954 1934 Furthermore, the location of the label at the \emph{beginning} of the target control structure informs the reader that complex control-flow is occurring in the body of the control structure. 1955 1935 With ©goto©, the label is at the end of the control structure, which fails to convey this important clue early enough to the reader. … … 2268 2248 \index{input/output library} 2269 2249 2270 The goal for the \CFA I/O is to make I/O as simple as possible in the common cases, while fully supporting polymorphism and user defined types in a consistent way.2250 The goal of \CFA I/O is to simplify the common cases\index{I/O!common case}, while fully supporting polymorphism and user defined types in a consistent way. 2271 2251 The common case is printing out a sequence of variables separated by whitespace. 2272 2252 \begin{quote2} … … 2274 2254 \multicolumn{1}{c@{\hspace{3em}}}{\textbf{\CFA}} & \multicolumn{1}{c}{\textbf{\CC}} \\ 2275 2255 \begin{cfa} 2276 int x = 0, y = 1, z = 2;2256 int x = 1, y = 2, z = 3; 2277 2257 sout | x ®|® y ®|® z | endl; 2278 2258 \end{cfa} … … 2281 2261 2282 2262 cout << x ®<< " "® << y ®<< " "® << z << endl; 2263 \end{cfa} 2264 \\ 2265 \begin{cfa}[mathescape=off,showspaces=true,aboveskip=0pt,belowskip=0pt] 2266 1 2 3 2267 \end{cfa} 2268 & 2269 \begin{cfa}[mathescape=off,showspaces=true,aboveskip=0pt,belowskip=0pt] 2270 1 2 3 2283 2271 \end{cfa} 2284 2272 \end{tabular} 2285 2273 \end{quote2} 2286 2274 The \CFA form has half as many characters as the \CC form, and is similar to \Index*{Python} I/O with respect to implicit separators. 2287 2288 The logical-or operator is used because it is the lowest-priority overloadable operator, other than assignment. 2275 A tuple prints all the tuple's values, each separated by ©", "©. 2276 \begin{cfa}[mathescape=off,aboveskip=0pt,belowskip=0pt] 2277 [int, int] t1 = [1, 2], t2 = [3, 4]; 2278 sout | t1 | t2 | endl; §\C{// print tuples}§ 2279 \end{cfa} 2280 \begin{cfa}[mathescape=off,showspaces=true,belowskip=0pt] 2281 1, 2, 3, 4 2282 \end{cfa} 2283 \CFA uses the logical-or operator for I/O because it is the lowest-priority overloadable operator, other than assignment. 2289 2284 Therefore, fewer output expressions require parenthesis. 2290 2285 \begin{quote2} … … 2299 2294 & 2300 2295 \begin{cfa} 2301 cout << x * 3 << y + 1 << (z << 2) << (x == y) << (x | y) << (x || y) << (x > z ? 1 : 2) << endl; 2296 cout << x * 3 << y + 1 << ®(®z << 2®)® << ®(®x == y®)® << (x | y) << (x || y) << (x > z ? 1 : 2) << endl; 2297 \end{cfa} 2298 \\ 2299 & 2300 \begin{cfa}[mathescape=off,showspaces=true,aboveskip=0pt,belowskip=0pt] 2301 3 3 12 0 3 1 2 2302 2302 \end{cfa} 2303 2303 \end{tabular} … … 2305 2305 Finally, the logical-or operator has a link with the Shell pipe-operator for moving data, where data flows in the correct direction for input but the opposite direction for output. 2306 2306 2307 2307 2308 The implicit separator\index{I/O separator} character (space/blank) is a separator not a terminator. 2308 2309 The rules for implicitly adding the separator are: … … 2316 2317 1 2 3 2317 2318 \end{cfa} 2319 2318 2320 \item 2319 2321 A separator does not appear before or after a character literal or variable. … … 2322 2324 123 2323 2325 \end{cfa} 2324 \item 2325 A separator does not appear before or after a null (empty) C string 2326 2327 \item 2328 A separator does not appear before or after a null (empty) C string. 2326 2329 \begin{cfa} 2327 2330 sout | 1 | "" | 2 | "" | 3 | endl; … … 2329 2332 \end{cfa} 2330 2333 which is a local mechanism to disable insertion of the separator character. 2331 \item 2332 A separator does not appear before a C string starting with the (extended) \Index{ASCII}\index{ASCII!extended} characters: \lstinline[mathescape=off]@([{=$£¥¡¿«@ 2334 2335 \item 2336 A separator does not appear before a C string starting with the (extended) \Index{ASCII}\index{ASCII!extended} characters: \lstinline[mathescape=off,basicstyle=\tt]@([{=$£¥¡¿«@ 2333 2337 %$ 2334 2338 \begin{cfa}[mathescape=off] … … 2337 2341 \end{cfa} 2338 2342 %$ 2339 \begin{cfa}[mathescape=off, showspaces=true,aboveskip=0pt,belowskip=0pt]2340 x (1 x [2 x {3 x =4 x $5 x £6 x ¥7 x ¡8 x ¿9 x «102343 \begin{cfa}[mathescape=off,basicstyle=\tt,showspaces=true,aboveskip=0pt,belowskip=0pt] 2344 x ®(®1 x ®[®2 x ®{®3 x ®=®4 x ®$®5 x ®£®6 x ®¥®7 x ®¡®8 x ®¿®9 x ®«®10 2341 2345 \end{cfa} 2342 2346 %$ 2347 where \lstinline[basicstyle=\tt]@¡¿@ are inverted opening exclamation and question marks, and \lstinline[basicstyle=\tt]@«@ is an opening citation mark. 2348 2343 2349 \item 2344 2350 {\lstset{language=CFA,deletedelim=**[is][]{¢}{¢}} 2345 A seperator does not appear after a C string ending with the (extended) \Index{ASCII}\index{ASCII!extended} characters: ©,.;!?)]}%¢»©2351 A seperator does not appear after a C string ending with the (extended) \Index{ASCII}\index{ASCII!extended} characters: \lstinline[basicstyle=\tt]@,.;!?)]}%¢»@ 2346 2352 \begin{cfa}[belowskip=0pt] 2347 2353 sout | 1 | ", x" | 2 | ". x" | 3 | "; x" | 4 | "! x" | 5 | "? x" | 6 | "% x" 2348 2354 | 7 | "¢ x" | 8 | "» x" | 9 | ") x" | 10 | "] x" | 11 | "} x" | endl; 2349 2355 \end{cfa} 2350 \begin{cfa}[ mathescape=off,showspaces=true,aboveskip=0pt,belowskip=0pt]2351 1 , x 2. x 3; x 4! x 5? x 6% x 7§\textcent§ x 8» x 9) x 10] x 11}x2356 \begin{cfa}[basicstyle=\tt,showspaces=true,aboveskip=0pt,belowskip=0pt] 2357 1®,® x 2®.® x 3®;® x 4®!® x 5®?® x 6®%® x 7§\color{red}\textcent§ x 8®»® x 9®)® x 10®]® x 11®}® x 2352 2358 \end{cfa}}% 2353 \item 2354 A seperator does not appear before or after a C string begining/ending with the \Index{ASCII} quote or whitespace characters: \lstinline[showspaces=true]@`'": \t\v\f\r\n@ 2359 where \lstinline[basicstyle=\tt]@»@ is a closing citation mark. 2360 2361 \item 2362 A seperator does not appear before or after a C string begining/ending with the \Index{ASCII} quote or whitespace characters: \lstinline[basicstyle=\tt,showspaces=true]@`'": \t\v\f\r\n@ 2355 2363 \begin{cfa}[belowskip=0pt] 2356 2364 sout | "x`" | 1 | "`x'" | 2 | "'x\"" | 3 | "\"x:" | 4 | ":x " | 5 | " x\t" | 6 | "\tx" | endl; 2357 2365 \end{cfa} 2358 \begin{cfa}[mathescape=off,showspaces=true,showtabs=true,aboveskip=0pt,belowskip=0pt] 2359 x`1`x'2'x"3"x:4:x 5 x 6 x 2366 \begin{cfa}[basicstyle=\tt,showspaces=true,showtabs=true,aboveskip=0pt,belowskip=0pt] 2367 x®`®1®`®x§\color{red}\texttt{'}§2§\color{red}\texttt{'}§x§\color{red}\texttt{"}§3§\color{red}\texttt{"}§x®:®4®:®x® ®5® ®x® ®6® ®x 2368 \end{cfa} 2369 2370 \item 2371 If a space is desired before or after one of the special string start/end characters, simply insert a space. 2372 \begin{cfa}[belowskip=0pt] 2373 sout | "x (§\color{red}\texttt{\textvisiblespace}§" | 1 | "§\color{red}\texttt{\textvisiblespace}§) x" | 2 | "§\color{red}\texttt{\textvisiblespace}§, x" | 3 | "§\color{red}\texttt{\textvisiblespace}§:x:§\color{red}\texttt{\textvisiblespace}§" | 4 | endl; 2374 \end{cfa} 2375 \begin{cfa}[basicstyle=\tt,showspaces=true,showtabs=true,aboveskip=0pt,belowskip=0pt] 2376 x (® ®1® ®) x 2® ®, x 3® ®:x:® ®4 2360 2377 \end{cfa} 2361 2378 \end{enumerate} 2362 2379 2363 The following \CC-style \Index{manipulator}s allow control over implicit seperation. 2380 The following routines and \CC-style \Index{manipulator}s control implicit seperation. 2381 \begin{enumerate} 2382 \item 2383 Routines \Indexc{sepSet}\index{manipulator!sepSet@©sepSet©} and \Indexc{sepGet}\index{manipulator!sepGet@©sepGet©} set and get the separator string. 2384 The separator string can be at most 16 characters including the ©'\0'© string terminator (15 printable characters). 2385 \begin{cfa}[mathescape=off,aboveskip=0pt,belowskip=0pt] 2386 sepSet( sout, ", $" ); §\C{// set separator from " " to ", \$"}§ 2387 sout | 1 | 2 | 3 | " \"" | ®sepGet( sout )® | "\"" | endl; 2388 \end{cfa} 2389 %$ 2390 \begin{cfa}[mathescape=off,showspaces=true,aboveskip=0pt] 2391 1, $2, $3 ®", $"® 2392 \end{cfa} 2393 %$ 2394 \begin{cfa}[mathescape=off,aboveskip=0pt,belowskip=0pt] 2395 sepSet( sout, " " ); §\C{// reset separator to " "}§ 2396 sout | 1 | 2 | 3 | " \"" | ®sepGet( sout )® | "\"" | endl; 2397 \end{cfa} 2398 \begin{cfa}[mathescape=off,showspaces=true,aboveskip=0pt] 2399 1 2 3 ®" "® 2400 \end{cfa} 2401 2402 \item 2364 2403 Manipulators \Indexc{sepOn}\index{manipulator!sepOn@©sepOn©} and \Indexc{sepOff}\index{manipulator!sepOff@©sepOff©} \emph{locally} toggle printing the separator, \ie the seperator is adjusted only with respect to the next printed item. 2365 2404 \begin{cfa}[mathescape=off,belowskip=0pt] … … 2375 2414 12 3 2376 2415 \end{cfa} 2416 2417 \item 2377 2418 Manipulators \Indexc{sepDisable}\index{manipulator!sepDisable@©sepDisable©} and \Indexc{sepEnable}\index{manipulator!sepEnable@©sepEnable©} \emph{globally} toggle printing the separator, \ie the seperator is adjusted with respect to all subsequent printed items, unless locally adjusted. 2378 2419 \begin{cfa}[mathescape=off,aboveskip=0pt,belowskip=0pt] … … 2394 2435 1 2 3 2395 2436 \end{cfa} 2396 Printing a tuple outputs all the tuple's values separated by ©", "©: 2437 2438 \item 2439 Routine \Indexc{sepSetTuple}\index{manipulator!sepSetTuple@©sepSetTuple©} and \Indexc{sepGetTuple}\index{manipulator!sepGetTuple@©sepGetTuple©} get and set the tuple separator-string. 2440 The tuple separator-string can be at most 16 characters including the ©'\0'© string terminator (15 printable characters). 2397 2441 \begin{cfa}[mathescape=off,aboveskip=0pt,belowskip=0pt] 2398 sout | [2, 3] | [4, 5] | endl; §\C{// print tuple}§ 2442 sepSetTuple( sout, " " ); §\C{// set tuple separator from ", " to " "}§ 2443 sout | t1 | t2 | " \"" | ®sepGetTuple( sout )® | "\"" | endl; 2444 \end{cfa} 2445 \begin{cfa}[mathescape=off,showspaces=true,aboveskip=0pt] 2446 1 2 3 4 ®" "® 2447 \end{cfa} 2448 \begin{cfa}[mathescape=off,aboveskip=0pt,belowskip=0pt] 2449 sepSetTuple( sout, ", " ); §\C{// reset tuple separator to ", "}§ 2450 sout | t1 | t2 | " \"" | ®sepGetTuple( sout )® | "\"" | endl; 2451 \end{cfa} 2452 \begin{cfa}[mathescape=off,showspaces=true,aboveskip=0pt] 2453 1, 2, 3, 4 ®", "® 2454 \end{cfa} 2455 2456 \item 2457 The tuple separator can also be turned on and off. 2458 \begin{cfa}[mathescape=off,aboveskip=0pt,belowskip=0pt] 2459 sout | sepOn | t1 | sepOff | t2 | endl; §\C{// locally turn on/off implicit separation}§ 2399 2460 \end{cfa} 2400 2461 \begin{cfa}[mathescape=off,showspaces=true,aboveskip=0pt,belowskip=0pt] 2401 2, 3, 4, 5 2402 \end{cfa} 2403 The tuple separator can also be turned on and off: 2404 \begin{cfa}[mathescape=off,aboveskip=0pt,belowskip=0pt] 2405 sout | sepOn | [2, 3] | sepOff | [4, 5] | endl; §\C{// locally turn on/off implicit separation}§ 2406 \end{cfa} 2407 \begin{cfa}[mathescape=off,showspaces=true,aboveskip=0pt,belowskip=0pt] 2408 , 2, 34, 5 2462 , 1, 23, 4 2409 2463 \end{cfa} 2410 2464 Notice a tuple seperator starts the line because the next item is a tuple. 2411 Finally, the stream routines \Indexc{sepGet}\index{manipulator!sepGet@©sepGet©} and \Indexc{sepSet}\index{manipulator!sepSet@©sepSet©} get and set the basic separator-string. 2412 \begin{cfa}[mathescape=off,aboveskip=0pt,aboveskip=0pt,belowskip=0pt] 2413 sepSet( sout, ", $" ); §\C{// set separator from " " to ", \$"}§ 2414 sout | 1 | 2 | 3 | " \"" | sepGet( sout ) | "\"" | endl; 2415 \end{cfa} 2416 %$ 2417 \begin{cfa}[mathescape=off,showspaces=true,aboveskip=0pt] 2418 1, $2, $3 ", $" 2419 \end{cfa} 2420 %$ 2421 \begin{cfa}[mathescape=off,aboveskip=0pt,aboveskip=0pt,belowskip=0pt] 2422 sepSet( sout, " " ); §\C{// reset separator to " "}§ 2423 sout | 1 | 2 | 3 | " \"" | sepGet( sout ) | "\"" | endl; 2424 \end{cfa} 2425 \begin{cfa}[mathescape=off,showspaces=true,aboveskip=0pt] 2426 1 2 3 " " 2427 \end{cfa} 2428 and the stream routines \Indexc{sepGetTuple}\index{manipulator!sepGetTuple@©sepGetTuple©} and \Indexc{sepSetTuple}\index{manipulator!sepSetTuple@©sepSetTuple©} get and set the tuple separator-string. 2429 \begin{cfa}[mathescape=off,aboveskip=0pt,aboveskip=0pt,belowskip=0pt] 2430 sepSetTuple( sout, " " ); §\C{// set tuple separator from ", " to " "}§ 2431 sout | [2, 3] | [4, 5] | " \"" | sepGetTuple( sout ) | "\"" | endl; 2432 \end{cfa} 2433 \begin{cfa}[mathescape=off,showspaces=true,aboveskip=0pt] 2434 2 3 4 5 " " 2435 \end{cfa} 2436 \begin{cfa}[mathescape=off,aboveskip=0pt,aboveskip=0pt,belowskip=0pt] 2437 sepSetTuple( sout, ", " ); §\C{// reset tuple separator to ", "}§ 2438 sout | [2, 3] | [4, 5] | " \"" | sepGetTuple( sout ) | "\"" | endl; 2439 \end{cfa} 2440 \begin{cfa}[mathescape=off,showspaces=true,aboveskip=0pt] 2441 2, 3, 4, 5 ", " 2442 \end{cfa} 2465 \end{enumerate} 2443 2466 2444 2467 \begin{comment} … … 2446 2469 2447 2470 int main( void ) { 2448 int x = 0, y = 1, z = 2; 2449 sout | x * 3 | y + 1 | z << 2 | x == y | (x | y) | (x || y) | (x > z ? 1 : 2) | endl | endl; 2471 int x = 1, y = 2, z = 3; 2472 sout | x | y | z | endl; 2473 [int, int] t1 = [1, 2], t2 = [3, 4]; 2474 sout | t1 | t2 | endl; // print tuple 2475 sout | x * 3 | y + 1 | z << 2 | x == y | (x | y) | (x || y) | (x > z ? 1 : 2) | endl; 2450 2476 sout | 1 | 2 | 3 | endl; 2451 2477 sout | '1' | '2' | '3' | endl; … … 2456 2482 | 7 | "¢ x" | 8 | "» x" | 9 | ") x" | 10 | "] x" | 11 | "} x" | endl; 2457 2483 sout | "x`" | 1 | "`x'" | 2 | "'x\"" | 3 | "\"x:" | 4 | ":x " | 5 | " x\t" | 6 | "\tx" | endl; 2458 2459 sout | sepOn | 1 | 2 | 3 | sepOn | endl; // separator at start of line 2460 sout | 1 | sepOff | 2 | 3 | endl; // locally turn off implicit separator 2461 sout | sepDisable | 1 | 2 | 3 | endl; // globally turn off implicit separation 2462 sout | 1 | sepOn | 2 | 3 | endl; // locally turn on implicit separator 2463 sout | sepEnable | 1 | 2 | 3 | endl; // globally turn on implicit separation 2464 2465 sout | [2, 3] | [4, 5] | endl; // print tuple 2466 sout | sepOn | [2, 3] | sepOff | [4, 5] | endl; // locally turn on/off implicit separation 2484 sout | "x ( " | 1 | " ) x" | 2 | " , x" | 3 | " :x: " | 4 | endl; 2467 2485 2468 2486 sepSet( sout, ", $" ); // set separator from " " to ", $" … … 2471 2489 sout | 1 | 2 | 3 | " \"" | sepGet( sout ) | "\"" | endl; 2472 2490 2491 sout | sepOn | 1 | 2 | 3 | sepOn | endl; // separator at start of line 2492 sout | 1 | sepOff | 2 | 3 | endl; // locally turn off implicit separator 2493 2494 sout | sepDisable | 1 | 2 | 3 | endl; // globally turn off implicit separation 2495 sout | 1 | sepOn | 2 | 3 | endl; // locally turn on implicit separator 2496 sout | sepEnable | 1 | 2 | 3 | endl; // globally turn on implicit separation 2497 2473 2498 sepSetTuple( sout, " " ); // set tuple separator from ", " to " " 2474 sout | [2, 3] | [4, 5]| " \"" | sepGetTuple( sout ) | "\"" | endl;2499 sout | t1 | t2 | " \"" | sepGetTuple( sout ) | "\"" | endl; 2475 2500 sepSetTuple( sout, ", " ); // reset tuple separator to ", " 2476 sout | [2, 3] | [4, 5] | " \"" | sepGetTuple( sout ) | "\"" | endl; 2501 sout | t1 | t2 | " \"" | sepGetTuple( sout ) | "\"" | endl; 2502 2503 sout | t1 | t2 | endl; // print tuple 2504 sout | sepOn | t1 | sepOff | t2 | endl; // locally turn on/off implicit separation 2477 2505 } 2478 2506 2479 2507 // Local Variables: // 2480 2508 // tab-width: 4 // 2509 // fill-column: 100 // 2481 2510 // End: // 2482 2511 \end{comment} … … 2972 3001 generic (type T | bool ?<?(T, T) ) 2973 3002 2974 T min( T a, T b) {3003 T min( T a, T b ) { 2975 3004 return a < b ? a : b; 2976 3005 } … … 3011 3040 3012 3041 generic (type T | Orderable(T)) 3013 T min( T a, T b) {3042 T min( T a, T b ) { 3014 3043 return a < b ? a : b; 3015 3044 } … … 5081 5110 C11 prescribes the following standard header-files~\cite[\S~7.1.2]{C11} and \CFA adds to this list: 5082 5111 \begin{quote2} 5083 \begin{tabular}{lll |l}5084 \multicolumn{ 3}{c|}{C11} & \multicolumn{1}{c}{\CFA} \\5112 \begin{tabular}{llll|l} 5113 \multicolumn{4}{c|}{C11} & \multicolumn{1}{c}{\CFA} \\ 5085 5114 \hline 5086 assert.h & math.h & stdlib.h & unistd.h \\ 5087 complex.h & setjmp.h & stdnoreturn.h & gmp.h \\ 5088 ctype.h & signal.h & string.h \\ 5089 errno.h & stdalign.h & tgmath.h \\ 5090 fenv.h & stdarg.h & threads.h \\ 5091 float.h & stdatomic.h & time.h \\ 5092 inttypes.h & stdbool.h & uchar.h \\ 5093 iso646.h & stddef.h & wchar.h \\ 5094 limits.h & stdint.h & wctype.h \\ 5095 locale.h & stdio.h & \\ 5115 \begin{tabular}{@{}l@{}} 5116 assert.h \\ 5117 complex.h \\ 5118 ctype.h \\ 5119 errno.h \\ 5120 fenv.h \\ 5121 float.h \\ 5122 inttypes.h \\ 5123 iso646.h \\ 5124 \end{tabular} 5125 & 5126 \begin{tabular}{@{}l@{}} 5127 limits.h \\ 5128 locale.h \\ 5129 math.h \\ 5130 setjmp.h \\ 5131 signal.h \\ 5132 stdalign.h \\ 5133 stdarg.h \\ 5134 stdatomic.h \\ 5135 \end{tabular} 5136 & 5137 \begin{tabular}{@{}l@{}} 5138 stdbool.h \\ 5139 stddef.h \\ 5140 stdint.h \\ 5141 stdio.h \\ 5142 stdlib.h \\ 5143 stdnoreturn.h \\ 5144 string.h \\ 5145 tgmath.h \\ 5146 \end{tabular} 5147 & 5148 \begin{tabular}{@{}l@{}} 5149 threads.h \\ 5150 time.h \\ 5151 uchar.h \\ 5152 wchar.h \\ 5153 wctype.h \\ 5154 \\ 5155 \\ 5156 \\ 5157 \end{tabular} 5158 & 5159 \begin{tabular}{@{}l@{}} 5160 unistd.h \\ 5161 gmp.h \\ 5162 \\ 5163 \\ 5164 \\ 5165 \\ 5166 \\ 5167 \\ 5168 \end{tabular} 5096 5169 \end{tabular} 5097 5170 \end{quote2} … … 5104 5177 \label{s:StandardLibrary} 5105 5178 5106 The \CFA standard-library wraps many existingexplicitly-polymorphic C general-routines into implicitly-polymorphic versions.5179 The \CFA standard-library wraps explicitly-polymorphic C general-routines into implicitly-polymorphic versions. 5107 5180 5108 5181 … … 5122 5195 forall( dtype T | sized(T) ) T * memalign( size_t alignment ); // deprecated 5123 5196 forall( dtype T | sized(T) ) int posix_memalign( T ** ptr, size_t alignment ); 5124 5125 forall( otype T ) T * memset( T * ptr, unsigned char fill ); // use default value '\0' for fill5126 forall( otype T ) T * memset( T * ptr ); // remove when default value available5127 5197 5128 5198 forall( dtype T, ttype Params | sized(T) | { void ?{}(T *, Params); } ) T * new( Params p ); … … 5168 5238 \leavevmode 5169 5239 \begin{cfa}[aboveskip=0pt,belowskip=0pt] 5170 forall( otype T | { int ?<?( T, T ); } ) 5171 T * bsearch( const T key, const T * arr, size_t dimension );§\indexc{bsearch}§ 5240 forall( otype T | { int ?<?( T, T ); } ) // location 5241 T * bsearch( T key, const T * arr, size_t dimension );§\indexc{bsearch}§ 5242 5243 forall( otype T | { int ?<?( T, T ); } ) // position 5244 unsigned int bsearch( T key, const T * arr, size_t dimension ); 5172 5245 5173 5246 forall( otype T | { int ?<?( T, T ); } ) … … 5180 5253 \leavevmode 5181 5254 \begin{cfa}[aboveskip=0pt,belowskip=0pt] 5182 char abs(char );§\indexc{abs}§5255 unsigned char abs( signed char );§\indexc{abs}§ 5183 5256 int abs( int ); 5184 long int abs( long int );5185 long long int abs( long long int );5257 unsigned long int abs( long int ); 5258 unsigned long long int abs( long long int ); 5186 5259 float abs( float ); 5187 5260 double abs( double ); … … 5190 5263 double abs( double _Complex ); 5191 5264 long double abs( long double _Complex ); 5265 forall( otype T | { void ?{}( T *, zero_t ); int ?<?( T, T ); T -?( T ); } ) 5266 T abs( T ); 5192 5267 \end{cfa} 5193 5268 … … 5216 5291 \begin{cfa}[aboveskip=0pt,belowskip=0pt] 5217 5292 forall( otype T | { int ?<?( T, T ); } ) 5218 T min( const T t1, constT t2 );§\indexc{min}§5293 T min( T t1, T t2 );§\indexc{min}§ 5219 5294 5220 5295 forall( otype T | { int ?>?( T, T ); } ) 5221 T max( const T t1, constT t2 );§\indexc{max}§5296 T max( T t1, T t2 );§\indexc{max}§ 5222 5297 5223 5298 forall( otype T | { T min( T, T ); T max( T, T ); } ) … … 5232 5307 \label{s:Math Library} 5233 5308 5234 The \CFA math-library wraps many existingexplicitly-polymorphic C math-routines into implicitly-polymorphic versions.5309 The \CFA math-library wraps explicitly-polymorphic C math-routines into implicitly-polymorphic versions. 5235 5310 5236 5311 … … 5239 5314 \leavevmode 5240 5315 \begin{cfa}[aboveskip=0pt,belowskip=0pt] 5241 float fabs( float );§\indexc{fabs}§5242 double fabs( double );5243 long double fabs( long double );5244 float cabs( float _Complex );5245 double cabs( double _Complex );5246 long double cabs( long double _Complex );5247 5248 5316 float ?%?( float, float );§\indexc{fmod}§ 5249 5317 float fmod( float, float ); … … 5600 5668 5601 5669 5670 \section{Multi-precision Integers} 5671 \label{s:MultiPrecisionIntegers} 5672 5673 \CFA has an interface to the \Index{GMP} \Index{multi-precision} signed-integers~\cite{GMP}, similar to the \CC interface provided by GMP. 5674 The \CFA interface wraps GMP routines into operator routines to make programming with multi-precision integers identical to using fixed-sized integers. 5675 The \CFA type name for multi-precision signed-integers is \Indexc{Int}. 5676 5677 \begin{cfa} 5678 void ?{}( Int * this ); §\C{// constructor}§ 5679 void ?{}( Int * this, Int init ); 5680 void ?{}( Int * this, zero_t ); 5681 void ?{}( Int * this, one_t ); 5682 void ?{}( Int * this, signed long int init ); 5683 void ?{}( Int * this, unsigned long int init ); 5684 void ?{}( Int * this, const char * val ); 5685 void ^?{}( Int * this ); 5686 5687 Int ?=?( Int * lhs, Int rhs ); §\C{// assignment}§ 5688 Int ?=?( Int * lhs, long int rhs ); 5689 Int ?=?( Int * lhs, unsigned long int rhs ); 5690 Int ?=?( Int * lhs, const char * rhs ); 5691 5692 char ?=?( char * lhs, Int rhs ); 5693 short int ?=?( short int * lhs, Int rhs ); 5694 int ?=?( int * lhs, Int rhs ); 5695 long int ?=?( long int * lhs, Int rhs ); 5696 unsigned char ?=?( unsigned char * lhs, Int rhs ); 5697 unsigned short int ?=?( unsigned short int * lhs, Int rhs ); 5698 unsigned int ?=?( unsigned int * lhs, Int rhs ); 5699 unsigned long int ?=?( unsigned long int * lhs, Int rhs ); 5700 5701 long int narrow( Int val ); 5702 unsigned long int narrow( Int val ); 5703 5704 int ?==?( Int oper1, Int oper2 ); §\C{// comparison}§ 5705 int ?==?( Int oper1, long int oper2 ); 5706 int ?==?( long int oper2, Int oper1 ); 5707 int ?==?( Int oper1, unsigned long int oper2 ); 5708 int ?==?( unsigned long int oper2, Int oper1 ); 5709 5710 int ?!=?( Int oper1, Int oper2 ); 5711 int ?!=?( Int oper1, long int oper2 ); 5712 int ?!=?( long int oper1, Int oper2 ); 5713 int ?!=?( Int oper1, unsigned long int oper2 ); 5714 int ?!=?( unsigned long int oper1, Int oper2 ); 5715 5716 int ?<?( Int oper1, Int oper2 ); 5717 int ?<?( Int oper1, long int oper2 ); 5718 int ?<?( long int oper2, Int oper1 ); 5719 int ?<?( Int oper1, unsigned long int oper2 ); 5720 int ?<?( unsigned long int oper2, Int oper1 ); 5721 5722 int ?<=?( Int oper1, Int oper2 ); 5723 int ?<=?( Int oper1, long int oper2 ); 5724 int ?<=?( long int oper2, Int oper1 ); 5725 int ?<=?( Int oper1, unsigned long int oper2 ); 5726 int ?<=?( unsigned long int oper2, Int oper1 ); 5727 5728 int ?>?( Int oper1, Int oper2 ); 5729 int ?>?( Int oper1, long int oper2 ); 5730 int ?>?( long int oper1, Int oper2 ); 5731 int ?>?( Int oper1, unsigned long int oper2 ); 5732 int ?>?( unsigned long int oper1, Int oper2 ); 5733 5734 int ?>=?( Int oper1, Int oper2 ); 5735 int ?>=?( Int oper1, long int oper2 ); 5736 int ?>=?( long int oper1, Int oper2 ); 5737 int ?>=?( Int oper1, unsigned long int oper2 ); 5738 int ?>=?( unsigned long int oper1, Int oper2 ); 5739 5740 Int +?( Int oper ); §\C{// arithmetic}§ 5741 Int -?( Int oper ); 5742 Int ~?( Int oper ); 5743 5744 Int ?&?( Int oper1, Int oper2 ); 5745 Int ?&?( Int oper1, long int oper2 ); 5746 Int ?&?( long int oper1, Int oper2 ); 5747 Int ?&?( Int oper1, unsigned long int oper2 ); 5748 Int ?&?( unsigned long int oper1, Int oper2 ); 5749 Int ?&=?( Int * lhs, Int rhs ); 5750 5751 Int ?|?( Int oper1, Int oper2 ); 5752 Int ?|?( Int oper1, long int oper2 ); 5753 Int ?|?( long int oper1, Int oper2 ); 5754 Int ?|?( Int oper1, unsigned long int oper2 ); 5755 Int ?|?( unsigned long int oper1, Int oper2 ); 5756 Int ?|=?( Int * lhs, Int rhs ); 5757 5758 Int ?^?( Int oper1, Int oper2 ); 5759 Int ?^?( Int oper1, long int oper2 ); 5760 Int ?^?( long int oper1, Int oper2 ); 5761 Int ?^?( Int oper1, unsigned long int oper2 ); 5762 Int ?^?( unsigned long int oper1, Int oper2 ); 5763 Int ?^=?( Int * lhs, Int rhs ); 5764 5765 Int ?+?( Int addend1, Int addend2 ); 5766 Int ?+?( Int addend1, long int addend2 ); 5767 Int ?+?( long int addend2, Int addend1 ); 5768 Int ?+?( Int addend1, unsigned long int addend2 ); 5769 Int ?+?( unsigned long int addend2, Int addend1 ); 5770 Int ?+=?( Int * lhs, Int rhs ); 5771 Int ?+=?( Int * lhs, long int rhs ); 5772 Int ?+=?( Int * lhs, unsigned long int rhs ); 5773 Int ++?( Int * lhs ); 5774 Int ?++( Int * lhs ); 5775 5776 Int ?-?( Int minuend, Int subtrahend ); 5777 Int ?-?( Int minuend, long int subtrahend ); 5778 Int ?-?( long int minuend, Int subtrahend ); 5779 Int ?-?( Int minuend, unsigned long int subtrahend ); 5780 Int ?-?( unsigned long int minuend, Int subtrahend ); 5781 Int ?-=?( Int * lhs, Int rhs ); 5782 Int ?-=?( Int * lhs, long int rhs ); 5783 Int ?-=?( Int * lhs, unsigned long int rhs ); 5784 Int --?( Int * lhs ); 5785 Int ?--( Int * lhs ); 5786 5787 Int ?*?( Int multiplicator, Int multiplicand ); 5788 Int ?*?( Int multiplicator, long int multiplicand ); 5789 Int ?*?( long int multiplicand, Int multiplicator ); 5790 Int ?*?( Int multiplicator, unsigned long int multiplicand ); 5791 Int ?*?( unsigned long int multiplicand, Int multiplicator ); 5792 Int ?*=?( Int * lhs, Int rhs ); 5793 Int ?*=?( Int * lhs, long int rhs ); 5794 Int ?*=?( Int * lhs, unsigned long int rhs ); 5795 5796 Int ?/?( Int dividend, Int divisor ); 5797 Int ?/?( Int dividend, unsigned long int divisor ); 5798 Int ?/?( unsigned long int dividend, Int divisor ); 5799 Int ?/?( Int dividend, long int divisor ); 5800 Int ?/?( long int dividend, Int divisor ); 5801 Int ?/=?( Int * lhs, Int rhs ); 5802 Int ?/=?( Int * lhs, long int rhs ); 5803 Int ?/=?( Int * lhs, unsigned long int rhs ); 5804 5805 [ Int, Int ] div( Int dividend, Int divisor ); 5806 [ Int, Int ] div( Int dividend, unsigned long int divisor ); 5807 5808 Int ?%?( Int dividend, Int divisor ); 5809 Int ?%?( Int dividend, unsigned long int divisor ); 5810 Int ?%?( unsigned long int dividend, Int divisor ); 5811 Int ?%?( Int dividend, long int divisor ); 5812 Int ?%?( long int dividend, Int divisor ); 5813 Int ?%=?( Int * lhs, Int rhs ); 5814 Int ?%=?( Int * lhs, long int rhs ); 5815 Int ?%=?( Int * lhs, unsigned long int rhs ); 5816 5817 Int ?<<?( Int shiften, mp_bitcnt_t shift ); 5818 Int ?<<=?( Int * lhs, mp_bitcnt_t shift ); 5819 Int ?>>?( Int shiften, mp_bitcnt_t shift ); 5820 Int ?>>=?( Int * lhs, mp_bitcnt_t shift ); 5821 5822 Int abs( Int oper ); §\C{// number functions}§ 5823 Int fact( unsigned long int N ); 5824 Int gcd( Int oper1, Int oper2 ); 5825 Int pow( Int base, unsigned long int exponent ); 5826 Int pow( unsigned long int base, unsigned long int exponent ); 5827 void srandom( gmp_randstate_t state ); 5828 Int random( gmp_randstate_t state, mp_bitcnt_t n ); 5829 Int random( gmp_randstate_t state, Int n ); 5830 Int random( gmp_randstate_t state, mp_size_t max_size ); 5831 int sgn( Int oper ); 5832 Int sqrt( Int oper ); 5833 5834 forall( dtype istype | istream( istype ) ) istype * ?|?( istype * is, Int * mp ); §\C{// I/O}§ 5835 forall( dtype ostype | ostream( ostype ) ) ostype * ?|?( ostype * os, Int mp ); 5836 \end{cfa} 5837 5838 The following factorial programs contrast using GMP with the \CFA and C interfaces, where the output from these programs appears in \VRef[Figure]{f:MultiPrecisionFactorials}. 5839 (Compile with flag \Indexc{-lgmp} to link with the GMP library.) 5840 \begin{quote2} 5841 \begin{tabular}{@{}l@{\hspace{\parindentlnth}}|@{\hspace{\parindentlnth}}l@{}} 5842 \multicolumn{1}{c|@{\hspace{\parindentlnth}}}{\textbf{\CFA}} & \multicolumn{1}{@{\hspace{\parindentlnth}}c}{\textbf{C}} \\ 5843 \hline 5844 \begin{cfa} 5845 #include <gmp> 5846 int main( void ) { 5847 sout | "Factorial Numbers" | endl; 5848 Int fact; 5849 fact = 1; 5850 sout | 0 | fact | endl; 5851 for ( unsigned int i = 1; i <= 40; i += 1 ) { 5852 fact *= i; 5853 sout | i | fact | endl; 5854 } 5855 } 5856 \end{cfa} 5857 & 5858 \begin{cfa} 5859 #include <gmp.h> 5860 int main( void ) { 5861 ®gmp_printf®( "Factorial Numbers\n" ); 5862 ®mpz_t® fact; 5863 ®mpz_init_set_ui®( fact, 1 ); 5864 ®gmp_printf®( "%d %Zd\n", 0, fact ); 5865 for ( unsigned int i = 1; i <= 40; i += 1 ) { 5866 ®mpz_mul_ui®( fact, fact, i ); 5867 ®gmp_printf®( "%d %Zd\n", i, fact ); 5868 } 5869 } 5870 \end{cfa} 5871 \end{tabular} 5872 \end{quote2} 5873 5874 \begin{figure} 5875 \begin{cfa} 5876 Factorial Numbers 5877 0 1 5878 1 1 5879 2 2 5880 3 6 5881 4 24 5882 5 120 5883 6 720 5884 7 5040 5885 8 40320 5886 9 362880 5887 10 3628800 5888 11 39916800 5889 12 479001600 5890 13 6227020800 5891 14 87178291200 5892 15 1307674368000 5893 16 20922789888000 5894 17 355687428096000 5895 18 6402373705728000 5896 19 121645100408832000 5897 20 2432902008176640000 5898 21 51090942171709440000 5899 22 1124000727777607680000 5900 23 25852016738884976640000 5901 24 620448401733239439360000 5902 25 15511210043330985984000000 5903 26 403291461126605635584000000 5904 27 10888869450418352160768000000 5905 28 304888344611713860501504000000 5906 29 8841761993739701954543616000000 5907 30 265252859812191058636308480000000 5908 31 8222838654177922817725562880000000 5909 32 263130836933693530167218012160000000 5910 33 8683317618811886495518194401280000000 5911 34 295232799039604140847618609643520000000 5912 35 10333147966386144929666651337523200000000 5913 36 371993326789901217467999448150835200000000 5914 37 13763753091226345046315979581580902400000000 5915 38 523022617466601111760007224100074291200000000 5916 39 20397882081197443358640281739902897356800000000 5917 40 815915283247897734345611269596115894272000000000 5918 \end{cfa} 5919 \caption{Multi-precision Factorials} 5920 \label{f:MultiPrecisionFactorials} 5921 \end{figure} 5922 5923 5602 5924 \section{Rational Numbers} 5603 5925 \label{s:RationalNumbers} … … 5612 5934 }; // Rational 5613 5935 5614 // constants 5615 extern struct Rational 0; 5616 extern struct Rational 1; 5617 5618 // constructors 5619 Rational rational(); 5936 Rational rational(); §\C{// constructors}§ 5620 5937 Rational rational( long int n ); 5621 5938 Rational rational( long int n, long int d ); 5622 5623 // getter/setter for numerator/denominator 5624 long int numerator( Rational r ); 5939 void ?{}( Rational * r, zero_t ); 5940 void ?{}( Rational * r, one_t ); 5941 5942 long int numerator( Rational r ); §\C{// numerator/denominator getter/setter}§ 5625 5943 long int numerator( Rational r, long int n ); 5626 5944 long int denominator( Rational r ); 5627 5945 long int denominator( Rational r, long int d ); 5628 5946 5629 // comparison 5630 int ?==?( Rational l, Rational r ); 5947 int ?==?( Rational l, Rational r ); §\C{// comparison}§ 5631 5948 int ?!=?( Rational l, Rational r ); 5632 5949 int ?<?( Rational l, Rational r ); … … 5635 5952 int ?>=?( Rational l, Rational r ); 5636 5953 5637 // arithmetic 5638 Rational -?( Rational r ); 5954 Rational -?( Rational r ); §\C{// arithmetic}§ 5639 5955 Rational ?+?( Rational l, Rational r ); 5640 5956 Rational ?-?( Rational l, Rational r ); … … 5642 5958 Rational ?/?( Rational l, Rational r ); 5643 5959 5644 // conversion 5645 double widen( Rational r ); 5960 double widen( Rational r ); §\C{// conversion}§ 5646 5961 Rational narrow( double f, long int md ); 5647 5962 5648 // I/O 5649 forall( dtype istype | istream( istype ) ) istype * ?|?( istype *, Rational * ); 5963 forall( dtype istype | istream( istype ) ) istype * ?|?( istype *, Rational * ); // I/O 5650 5964 forall( dtype ostype | ostream( ostype ) ) ostype * ?|?( ostype *, Rational ); 5651 5965 \end{cfa} -
doc/working/resolver_design.md
rff98952 r4a368547 41 41 ensure that they are two-arg functions (this restriction may be valuable 42 42 regardless). 43 44 Regardless of syntax, there should be a type assertion that expresses `From` 45 is convertable to `To`. 46 If user-defined conversions are not added to the language, 47 `void ?{} ( To*, From )` may be a suitable representation, relying on 48 conversions on the argument types to account for transitivity. 49 On the other hand, `To*` should perhaps match its target type exactly, so 50 another assertion syntax specific to conversions may be required, e.g. 51 `From -> To`. 43 52 44 53 ### Constructor Idiom ###
Note: See TracChangeset
for help on using the changeset viewer.