Changeset 37218fc for doc/user/user.tex


Ignore:
Timestamp:
Apr 11, 2016, 11:51:07 AM (8 years ago)
Author:
Rob Schluntz <rschlunt@…>
Branches:
ADT, aaron-thesis, arm-eh, ast-experimental, cleanup-dtors, ctor, deferred_resn, demangler, enum, forall-pointer-decay, gc_noraii, jacob/cs343-translation, jenkins-sandbox, master, memory, new-ast, new-ast-unique-expr, new-env, no_list, persistent-indexer, pthread-emulation, qualifiedEnum, resolv-new, string, with_gc
Children:
37f0da8
Parents:
3aba311 (diff), e55ca05 (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:/u/cforall/software/cfa/cfa-cc

Conflicts:

src/Parser/ParseNode.h

File:
1 edited

Legend:

Unmodified
Added
Removed
  • doc/user/user.tex

    r3aba311 r37218fc  
     1%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% -*- Mode: Latex -*- %%%%%%%%%%%%%%%%%%%%%%%%%%%%
     2%%
     3%% Cforall Version 1.0.0 Copyright (C) 2016 University of Waterloo
     4%%
     5%% The contents of this file are covered under the licence agreement in the
     6%% file "LICENCE" distributed with Cforall.
     7%%
     8%% user.tex --
     9%%
     10%% Author           : Peter A. Buhr
     11%% Created On       : Wed Apr  6 14:53:29 2016
     12%% Last Modified By : Peter A. Buhr
     13%% Last Modified On : Fri Apr  8 11:40:53 2016
     14%% Update Count     : 42
     15%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
     16
    117% requires tex packages: texlive-base texlive-latex-base tex-common texlive-humanities texlive-latex-extra texlive-fonts-recommended
    218
     
    521
    622% Latex packages used in the document.
    7 
     23\usepackage[T1]{fontenc}
     24\usepackage{textcomp}
     25\usepackage[latin1]{inputenc}
     26\usepackage{upquote}
    827\usepackage{fullpage,times}
    928\usepackage{xspace}
     
    2443% Names used in the document.
    2544
    26 \newcommand{\CFA}{C$\forall$\xspace}    % set language symbolic name
    27 \newcommand{\CFL}{Cforall\xspace}               % set language text name
    28 \newcommand{\CC}{C\kern-.1em\hbox{+\kern-.25em+}\xspace} % CC symbolic name
    29 \def\c11{ISO/IEC C} % C11 name (cannot have numbers in latex command name)
    3045\newcommand{\CS}{C\raisebox{-0.9ex}{\large$^\sharp$}\xspace}
    3146
     
    3348
    3449% Bespoke macros used in the document.
    35 
    36 \makeatletter
    37 % allow escape sequence in lstinline
    38 %\usepackage{etoolbox}
    39 %\patchcmd{\lsthk@TextStyle}{\let\lst@DefEsc\@empty}{}{}{\errmessage{failed to patch}}
    40 
    41 \renewcommand\small{%
    42    \@setfontsize\small{8.5}{11}%
    43    \abovedisplayskip 8.5pt \@plus 3pt \@minus 4pt
    44    \abovedisplayshortskip \z@ \@plus 2pt
    45    \belowdisplayshortskip 4pt \@plus 2pt \@minus 2pt
    46    \def\@listi{\leftmargin\leftmargini
    47                \topsep 4pt \@plus 2pt \@minus 2pt
    48                \parsep 2pt \@pluspt \@minuspt
    49                \itemsep \parsep}%
    50    \belowdisplayskip \abovedisplayskip
    51 }
    52 \usepackage{relsize}            % must be after change to small
    53 
    54 \renewcommand{\labelitemi}{{\raisebox{0.25ex}{\footnotesize$\bullet$}}}
    55 \renewenvironment{itemize}{\begin{list}{\labelitemi}{\topsep=5pt\itemsep=5pt\parsep=0pt}}{\end{list}}
    56 
    57 %  Reduce size of section titles
    58 \renewcommand\section{\@startsection{section}{1}{\z@}{-3.0ex \@plus -1ex \@minus -.2ex}{1.0ex \@plus .2ex}{\normalfont\large\bfseries}}
    59 \renewcommand\subsection{\@startsection{subsection}{2}{\z@}{-2.5ex \@plus -1ex \@minus -.2ex}{1.0ex \@plus .2ex}{\normalfont\normalsize\bfseries}}
    60 \renewcommand\subsubsection{\@startsection{subsubsection}{3}{\z@}{-2.5ex \@plus -1ex \@minus -.2ex}{1.0ex \@plus .2ex}{\normalfont\normalsize\bfseries}}
    61 \renewcommand\paragraph{\@startsection{paragraph}{4}{\z@}{-2.0ex \@plus -1ex \@minus -.2ex}{-1em}{\normalfont\normalsize\bfseries}}
    62 
    63 % index macros
    64 \newcommand{\italic}[1]{\emph{\hyperpage{#1}}}
    65 \newcommand{\definition}[1]{\textbf{\hyperpage{#1}}}
    66 \newcommand{\see}[1]{\emph{see} #1}
    67 
    68 % Define some commands that produce formatted index entries suitable for cross-references.
    69 % ``\spec'' produces entries for specifications of entities.  ``\impl'' produces entries for their
    70 % implementations, and ``\use'' for their uses.
    71 
    72 %  \newcommand{\bold}[1]{{\bf #1}}
    73 %  \def\spec{\@bsphack\begingroup
    74 %             \def\protect##1{\string##1\space}\@sanitize
    75 %             \@wrxref{|bold}}
    76 \def\impl{\@bsphack\begingroup
    77           \def\protect##1{\string##1\space}\@sanitize
    78           \@wrxref{|definition}}
    79 \newcommand{\indexcode}[1]{{\lstinline$#1$}}
    80 \def\use{\@bsphack\begingroup
    81          \def\protect##1{\string##1\space}\@sanitize
    82          \@wrxref{|hyperpage}}
    83 \def\@wrxref#1#2{\let\thepage\relax
    84     \xdef\@gtempa{\write\@indexfile{\string
    85     \indexentry{#2@{\lstinline$#2$}#1}{\thepage}}}\endgroup\@gtempa
    86     \if@nobreak \ifvmode\nobreak\fi\fi\@esphack}
    87 %\newcommand{\use}[1]{\index{#1@{\lstinline$#1$}}}
    88 %\newcommand{\impl}[1]{\index{\protect#1@{\lstinline$\protect#1$}|definition}}
    89 
    90 % inline text and lowercase index: \Index{inline and lowercase index text}
    91 % inline text and as-in index: \Index[as-is index text]{inline text}
    92 % inline text but index with different as-is text: \Index[index text]{inline text}
    93 \newcommand{\Index}{\@ifstar\@sIndex\@Index}
    94 \newcommand{\@Index}[2][\@empty]{\lowercase{\def\temp{#2}}#2\ifx#1\@empty\index{\temp}\else\index{#1@{\protect#2}}\fi}
    95 \newcommand{\@sIndex}[2][\@empty]{#2\ifx#1\@empty\index{#2}\else\index{#1@{\protect#2}}\fi}
    96 
    97 \newcommand{\newtermFontInline}{\emph}
    98 \newcommand{\newterm}{\@ifstar\@snewterm\@newterm}
    99 \newcommand{\@newterm}[2][\@empty]{\lowercase{\def\temp{#2}}{\newtermFontInline{#2}}\ifx#1\@empty\index{\temp}\else\index{#1@{\protect#2}}\fi}
    100 \newcommand{\@snewterm}[2][\@empty]{{\newtermFontInline{#2}}\ifx#1\@empty\index{#2}\else\index{#1@{\protect#2}}\fi}
    101 \makeatother
    102 
    103 % blocks and titles
    104 \newenvironment{quote2}{%
    105         \list{}{\lstset{resetmargins=true}\leftmargin=\parindent\rightmargin\leftmargin}%
    106         \item\relax
    107 }{%
    108         \endlist
    109 }% quote2
    110 \newenvironment{rationale}{%
    111   \begin{quotation}\noindent$\Box$\enspace
    112 }{%
    113   \hfill\enspace$\Box$\end{quotation}
    114 }%
    115 \newcommand{\define}[1]{\emph{#1\/}\index{#1}}
    116 \newcommand{\rewrite}{\(\Rightarrow\)}
    117 \newcommand{\rewriterules}{\paragraph{Rewrite Rules}~\par\noindent}
    118 \newcommand{\examples}{\paragraph{Examples}~\par\noindent}
    119 \newcommand{\semantics}{\paragraph{Semantics}~\par\noindent}
    120 \newcommand{\constraints}{\paragraph{Constraints}~\par\noindent}
    121 \newcommand{\predefined}{\paragraph{Predefined Identifiers}~\par\noindent}
    122 
    123 % BNF macros
    124 \def\syntax{\paragraph{Syntax}\trivlist\parindent=.5in\item[\hskip.5in]}
    125 \let\endsyntax=\endtrivlist
    126 \newcommand{\lhs}[1]{\par{\emph{#1:}}\index{#1@{\emph{#1}}|italic}}
    127 \newcommand{\rhs}{\hfil\break\hbox{\hskip1in}}
    128 \newcommand{\oldlhs}[1]{\emph{#1: \ldots}\index{#1@{\emph{#1}}|italic}}
    129 \newcommand{\nonterm}[1]{\emph{#1\/}\index{#1@{\emph{#1}}|italic}}
    130 \newcommand{\opt}{$_{opt}$\ }
    131 
    132 % adjust varioref package with default "section" and "page" titles, and optional title with faraway page numbers
    133 % \VRef{label} => Section 2.7, \VPageref{label} => page 17
    134 % \VRef[Figure]{label} => Figure 3.4, \VPageref{label} => page 17
    135 \renewcommand{\reftextfaceafter}{\unskip}
    136 \renewcommand{\reftextfacebefore}{\unskip}
    137 \renewcommand{\reftextafter}{\unskip}
    138 \renewcommand{\reftextbefore}{\unskip}
    139 \renewcommand{\reftextfaraway}[1]{\unskip, p.~\pageref{#1}}
    140 \renewcommand{\reftextpagerange}[2]{\unskip, pp.~\pageref{#1}--\pageref{#2}}
    141 \newcommand{\VRef}[2][Section]{\ifx#1\@empty\else{#1}\nobreakspace\fi\vref{#2}}
    142 \newcommand{\VPageref}[2][page]{\ifx#1\@empty\else{#1}\nobreakspace\fi\pageref{#2}}
    143 
    144 % Go programming language
    145 \lstdefinelanguage{Golang}%
    146   {morekeywords=[1]{package,import,func,type,struct,return,defer,panic, recover,select,var,const,iota,},%
    147    morekeywords=[2]{string,uint,uint8,uint16,uint32,uint64,int,int8,int16, int32,int64,
    148                 bool,float32,float64,complex64,complex128,byte,rune,uintptr, error,interface},%
    149    morekeywords=[3]{map,slice,make,new,nil,len,cap,copy,close,true,false, delete,append,real,imag,complex,chan,},%
    150    morekeywords=[4]{for,break,continue,range,goto,switch,case,fallthrough,if, else,default,},%
    151    morekeywords=[5]{Println,Printf,Error,},%
    152    sensitive=true,%
    153    morecomment=[l]{//},%
    154    morecomment=[s]{/*}{*/},%
    155    morestring=[b]',%
    156    morestring=[b]",%
    157    morestring=[s]{`}{`},%
    158 }
    159 
    160 % CFA based on ANSI C
    161 \lstdefinelanguage{CFA}[ANSI]{C}%
    162 {morekeywords={asm,_Alignas,_Alignof,_At,_Atomic,_Bool,catch,catchResume,choose,_Complex,trait,disable,dtype,enable,
    163         fallthru,finally,forall,ftype,_Generic,_Imaginary,inline,lvalue,_Noreturn,otype,restrict,_Static_assert,
    164         _Thread_local,throw,throwResume,try,},
    165 }%
    166 
    167 \lstset{
    168 language=CFA,
    169 columns=flexible,
    170 basicstyle=\sf\relsize{-1},
    171 tabsize=4,
    172 xleftmargin=\parindent,
    173 escapechar=@,
    174 mathescape=true,
    175 keepspaces=true,
    176 showstringspaces=false,
    177 showlines=true,
    178 }%
    179 
    180 \makeatletter
    181 % replace/adjust listings characters that look bad in sanserif
    182 \lst@CCPutMacro
    183 \lst@ProcessOther{"2D}{\lst@ttfamily{-{}}{{\ttfamily\upshape -}}} % replace minus
    184 \lst@ProcessOther{"3C}{\lst@ttfamily{<}{\texttt{<}}} % replace less than
    185 \lst@ProcessOther{"3E}{\lst@ttfamily{<}{\texttt{>}}} % replace greater than
    186 \lst@ProcessOther{"5E}{\raisebox{0.4ex}{$\scriptstyle\land\,$}} % replace circumflex
    187 \lst@ProcessLetter{"5F}{\lst@ttfamily{\char95}{{\makebox[1.2ex][c]{\rule{1ex}{0.1ex}}}}} % replace underscore
    188 \lst@ProcessOther{"7E}{\raisebox{0.3ex}{$\scriptstyle\sim\,$}} % replace tilde
    189 %\lst@ProcessOther{"7E}{\raisebox{-.4ex}[1ex][0pt]{\textasciitilde}} % lower tilde
    190 \@empty\z@\@empty
    191 \makeatother
     50\input{common}
    19251
    19352\setcounter{secnumdepth}{3}     % number subsubsections
     
    366225
    367226The command \lstinline@cfa@ is used to compile \CFA program(s).
    368 This command works like the GNU \lstinline@gcc@ command, e.g.:
     227This command works like the GNU \lstinline@gcc@\index{gcc} command, e.g.:
    369228\begin{lstlisting}
    370229cfa [ gcc-options ] C/@{\CFA}@-files [ assembler/loader-files ]
    371230\end{lstlisting}
    372 The following additional option is available:
     231By default, \CFA programs having the following \lstinline@gcc@ flags turned on:
     232\begin{description}
     233\item
     234\hspace*{-4pt}\lstinline@-std=gnu99@
     235The 1999 C standard plus GNU extensions.
     236\end{description}
     237The following new \CFA option is available:
    373238\begin{description}
    374239\item
     
    382247Numeric constants are extended to allow \Index{underscore}s within constants\index{constant!underscore}, e.g.:
    383248\begin{lstlisting}
    384 2_147_483_648;                          // decimal constant
     2492`_`147`_`483`_`648;                            // decimal constant
    38525056_ul;                                          // decimal unsigned long constant
    3862510_377;                                          // octal constant
     
    451316\multicolumn{1}{c@{\hspace{30pt}}}{\textbf{\CFA}}       & \multicolumn{1}{c}{\textbf{C}}        \\
    452317\begin{lstlisting}
    453 * int x, y;
     318`* int x, y;`
    454319\end{lstlisting}
    455320&
     
    571436The point of the new syntax is to allow returning multiple values from a routine~\cite{CLU,Galletly96}, e.g.:
    572437\begin{lstlisting}
    573 [ int o1, int o2, char o3 ] f( int i1, char i2, char i3 ) {
     438`[ int o1, int o2, char o3 ]` f( int i1, char i2, char i3 ) {
    574439        @\emph{routine body}@
    575440}
     
    639504Because the value in the return variable is automatically returned when a \CFA routine terminates, the \lstinline@return@ statement \emph{does not} contain an expression, as in:
    640505\begin{lstlisting}
    641 [ int x ] f() {
     506`[ int x ]` f() {
    642507        ... x = 0; ... x = y; ...
    643         return; // implicitly return x
     508        `return;` // implicitly return x
    644509}
    645510\end{lstlisting}
     
    697562for example, the following is incorrect:
    698563\begin{lstlisting}
    699 * [ int x ] f () fp;            // routine name ``f'' is not allowed
     564* [ int x ] f () fp;            // routine name "f" is not allowed
    700565\end{lstlisting}
    701566
     
    864729\subsection{Type Nesting}
    865730
    866 C allows \Index{type nesting}, but the nested types are hoisted\index{type!hoisting} (refactored) into the enclosing scope.
     731\CFA allows \Index{type nesting}, and type qualification of the nested types, where as C hoists\index{type!hoisting} (refactors) nested types into the enclosing scope and has no type qualification.
    867732\begin{quote2}
    868733\begin{tabular}{@{}l@{\hspace{30pt}}l|l@{}}
     
    919784
    920785int fred() {
    921         s.t.c = S.R;
    922         struct S.T t = { S.R, 1, 2 };
    923         enum S.C c;
    924         union S.T.U u;
     786        s.t.c = `S.`R;  // type qualification
     787        struct `S.`T t = { `S.`R, 1, 2 };
     788        enum `S.`C c;
     789        union `S.T.`U u;
    925790}
    926791\end{lstlisting}
    927792\end{tabular}
    928793\end{quote2}
    929 
    930 \CFA is C \emph{incompatible} on this issue, and provides semantics similar to \CC.
    931 Nested types are not hoisted and can be referenced using the field selection operator ``\lstinline@.@'', unlike the \CC scope-resolution operator ``\lstinline@::@''.
    932 Given that nested types in C are equivalent to not using them, i.e., they are essentially useless, it is unlikely there are any realistic usages that break because of this incompatibility.
     794In the left example in C, types \lstinline@C@, \lstinline@U@ and \lstinline@T@ are implicitly hoisted outside of type \lstinline@S@ into the containing block scope.
     795In the right example in \CFA, the types are not hoisted and accessed using the field-selection operator ``\lstinline@.@'' for type qualification, as does Java, rather than the \CC type-selection operator ``\lstinline@::@''.
    933796
    934797
     
    944807\begin{lstlisting}
    945808const unsigned int size = 10;
    946 int a[size];
    947 
    948 qsort( a, size );               // ascending order using built in ?<?
    949 {                                               // descending order by local redefinition
    950         int ?<?( int a, int b ) { return a > b; } // nested routine
    951         qsort( a, size );
    952 }
    953 \end{lstlisting}
     809int ia[size];
     810...                                             // assign values to array ia
     811qsort( ia, size );              // sort ascending order using builtin ?<?
     812{
     813        `int ?<?( int x, int y ) { return x > y; }` // nested routine
     814        qsort( ia, size );      // sort descending order by local redefinition
     815}
     816\end{lstlisting}
     817
     818Nested routines are not first-class, meaning a nested routine cannot be returned if it has references to variables in its enclosing blocks;
     819the only exception is references to the external block of the translation unit, as these variables persist for the duration of the program.
     820The following program in undefined in \CFA (and \lstinline@gcc@\index{gcc})
     821\begin{lstlisting}
     822[* [int]( int )] foo() {                // int (*foo())( int )
     823        int `i` = 7;
     824        int bar( int p ) {
     825                `i` += 1;                                       // dependent on local variable
     826                sout | `i` | endl;
     827        }
     828        return bar;                                     // undefined because of local dependence
     829}
     830int main() {
     831        * [int](int) fp = foo();        // int (*fp)(int)
     832    sout | fp( 3 ) | endl;
     833}
     834\end{lstlisting}
     835because
     836
     837Currently, there are no \Index{lambda} expressions, i.e., unnamed routines because routine names are very important to properly select the correct routine.
    954838
    955839
     
    1013897
    1014898\item
    1015 Change: A struct is a scope in C++, not in C
    1016 Rationale: Class scope is crucial to C++, and a struct is a class.
    1017 Effect on original feature: Change to semantics of well-defined feature.
    1018 Difficulty of converting: Semantic transformation.
    1019 How widely used: C programs use struct extremely frequently, but the change is only noticeable when
    1020 struct, enumeration, or enumerator names are referred to outside the struct. The latter is probably
    1021 rare.
     899Change: A struct is a scope in C++, not in C \\
     900Rationale: Class scope is crucial to C++, and a struct is a class. \\
     901Effect on original feature: Change to semantics of well-defined feature. \\
     902Difficulty of converting: Semantic transformation. \\
     903How widely used: C programs use struct extremely frequently, but the change is only noticeable when struct, enumeration, or enumerator names are referred to outside the struct.
     904The latter is probably rare.
     905
     906\CFA is C \emph{incompatible} on this issue, and provides semantics similar to \CC.
     907Nested types are not hoisted and can be referenced using the field selection operator ``\lstinline@.@'', unlike the \CC scope-resolution operator ``\lstinline@::@''.
     908Given that nested types in C are equivalent to not using them, i.e., they are essentially useless, it is unlikely there are any realistic usages that break because of this incompatibility.
     909
    1022910
    1023911\item
     
    11851073First the right-hand tuple is flattened and then the values are assigned individually.
    11861074Flattening is also performed on tuple types.
    1187 For example, the type \lstinline@[ int, [ int, int ], int ]@ can be coerced, using flattening, into the type lstinline@[ int, int, int, int ]@.
     1075For example, the type \lstinline@[ int, [ int, int ], int ]@ can be coerced, using flattening, into the type \lstinline@[ int, int, int, int ]@.
    11881076
    11891077A \newterm{structuring coercion} is the opposite of flattening;
     
    13521240\multicolumn{1}{c@{\hspace{30pt}}}{\textbf{\CFA}}       & \multicolumn{1}{c}{\textbf{C}}        \\
    13531241\begin{lstlisting}
    1354 L1: for ( ... ) {
    1355         L2: for ( ... ) {
    1356                 L3: for ( ... ) {
    1357                         ... break L1; ...
    1358                         ... break L2; ...
    1359                         ... break L3; // or break
     1242`L1:` for ( ... ) {
     1243        `L2:` for ( ... ) {
     1244                `L3:` for ( ... ) {
     1245                        ... break `L1`; ...
     1246                        ... break `L2`; ...
     1247                        ... break `L3`; // or break
    13601248                }
    13611249        }
     
    13821270\multicolumn{1}{c@{\hspace{30pt}}}{\textbf{\CFA}}       & \multicolumn{1}{c}{\textbf{C}}        \\
    13831271\begin{lstlisting}
    1384 L1: for ( ... ) {
    1385         L2: for ( ... ) {
    1386                 L3: for ( ... ) {
    1387                         ... continue L1; ...
    1388                         ... continue L2; ...
    1389                         ... continue L3; ...
     1272`L1`: for ( ... ) {
     1273        `L2`: for ( ... ) {
     1274                `L3`: for ( ... ) {
     1275                        ... continue `L1`; ...
     1276                        ... continue `L2`; ...
     1277                        ... continue `L3`; ...
    13901278
    13911279                }
     
    16231511\begin{lstlisting}
    16241512switch ( i ) {
    1625   case 1, 3, 5:
     1513  `case 1, 3, 5`:
    16261514        ...
    1627   case 2, 4, 6:
     1515  `case 2, 4, 6`:
    16281516        ...
    16291517}
     
    16341522  case 1: case 3 : case 5:
    16351523        ...
    1636   case 2: case 4 : case 6: /* even values */
     1524  case 2: case 4 : case 6:
    16371525        ...
    16381526}
     
    16551543\begin{lstlisting}
    16561544switch ( i ) {
    1657   case 1~5
     1545  `case 1~5:`
    16581546        ...
    1659   case 10~15
     1547  `case 10~15:`
    16601548        ...
    16611549}
     
    16721560&
    16731561\begin{lstlisting}
     1562
    16741563// 1, 2, 3, 4, 5
    16751564
     
    21682057
    21692058
    2170 \section{Generics }
     2059\section{Auto Type-Inferencing}
     2060
     2061Auto type-inferencing occurs in a declaration where a variable's type is inferred from its initialization expression type.
     2062\begin{quote2}
     2063\begin{tabular}{@{}l@{\hspace{30pt}}ll@{}}
     2064\multicolumn{1}{c@{\hspace{30pt}}}{\textbf{\CC}}        & \multicolumn{1}{c}{\lstinline@gcc@}\index{gcc} \\
     2065\begin{lstlisting}
     2066
     2067auto j = 3.0 * 4;
     2068int i;
     2069auto k = i;
     2070\end{lstlisting}
     2071&
     2072\begin{lstlisting}
     2073#define expr 3.0 * i
     2074typeof(expr) j = expr;
     2075int i;
     2076typeof(i) k = i;
     2077\end{lstlisting}
     2078&
     2079\begin{lstlisting}
     2080
     2081// use type of initialization expression
     2082
     2083// use type of primary variable
     2084\end{lstlisting}
     2085\end{tabular}
     2086\end{quote2}
     2087The two important capabilities are:
     2088\begin{itemize}
     2089\item
     2090preventing having to determine or write out long generic types,
     2091\item
     2092ensure secondary variables, related to a primary variable, always have the same type.
     2093\end{itemize}
     2094
     2095In \CFA, \lstinline@typedef@ provides a mechanism to alias long type names with short ones, both globally and locally, but not eliminate the use of the short name.
     2096\lstinline@gcc@ provides \lstinline@typeof@ to declare a secondary variable from a primary variable.
     2097\CFA also relies heavily on the specification of the left-hand side of assignment for type inferencing, so in many cases it is crucial to specify the type of the left-hand side to select the correct type of the right-hand expression.
     2098Only for overloaded routines with the same return type is variable type-inferencing possible.
     2099Finally, \lstinline@auto@ presents the programming problem of tracking down a type when the type is actually needed.
     2100For example, given
     2101\begin{lstlisting}
     2102auto j = `...`
     2103\end{lstlisting}
     2104and the need to write a routine to compute using \lstinline@j@
     2105\begin{lstlisting}
     2106void rtn( `...` parm );
     2107rtn( j );
     2108\end{lstlisting}
     2109A programmer must work backwards to determine the type of \lstinline@j@'s initialization expression, reconstructing the possibly long generic type-name.
     2110In this situation, having the type name or a short alias is very useful.
     2111
     2112There is also the conundrum in type inferencing of when to \emph{\Index{brand}} a type.
     2113That is, when is the type of the variable more important than the type of its initialization expression.
     2114For example, if a change is made in an initialization expression, it can cause hundreds or thousands of cascading type changes and/or errors.
     2115At some point, a programmer wants the type of the variable to remain constant and the expression to be in error when it changes.
     2116
     2117Given \lstinline@typedef@ and \lstinline@typeof@ in \CFA, and the strong need to use the type of left-hand side in inferencing, auto type-inferencing is not supported at this time.
     2118Should a significant need arise, this feature can be revisited.
     2119
     2120
     2121\section{Generics}
    21712122
    21722123\CFA supports parametric polymorphism to allow users to define generic functions and types.
     
    24572408
    24582409
    2459 \section{I/O Library}
    2460 \label{s:IOLibrary}
    2461 
    2462 The goal for \CFA I/O is to make I/O as simple as possible for the general case, while fully supporting polmorphism and user defined types in a consistent way.
    2463 The general case is printing out a sequence of variables separated by whitespace.
    2464 \begin{lstlisting}
    2465 int x = 0, y = 1, z = 2;
    2466 sout | x | y | z | endl;
    2467 
    2468 cout << x << " " << y << " " << z << endl;
    2469 \end{lstlisting}
    2470 The \CC form takes almost twice as many characters.
    2471 
    2472 The logical-or operator is used because it is the lowest priority overloadable operator, other than assignment.
    2473 Therefore, most output expressions do not require parenthesis.
    2474 \begin{lstlisting}
    2475 int x = 0, y = 1, z = 2;
    2476 sout | x * 3 | y + 1 | z << 2 | x == y | (x | y) | (x || y) | (x > z ? 1 : 2) | endl;
    2477 
    2478 cout << x * 3 << y + 1 << (z << 2) << (x == y) << (x | y) << (x || y) << (x > z ? 1 : 2) << endl;
    2479 \end{lstlisting}
    2480 
    2481 Finally, the logical-or operator has a link with the Shell pipe-operator for moving data, although data flows in the opposite direction.
    2482 
    2483 \begin{figure}
    2484 \begin{lstlisting}[mathescape=off]
    2485 #include <fstream>
    2486 
    2487 int main() {
    2488         char c;
    2489         short int si;
    2490         unsigned short int usi;
    2491         int i;
    2492         unsigned int ui;
    2493         long int li;
    2494         unsigned long int uli;
    2495         long long int lli;
    2496         unsigned long long int ulli;
    2497         float f;
    2498         double d;
    2499         long double ld;
    2500         float _Complex fc;
    2501         double _Complex dc;
    2502         long double _Complex ldc;
    2503         char s1[10], s2[10];
    2504 
    2505         ifstream in;
    2506         open( &in, "read.data", "r" );
    2507 
    2508         &in | &c
    2509                 | &si | &usi | &i | &ui | &li | &uli | &lli | &ulli
    2510                 | &f | &d | &ld
    2511                 | &fc | &dc | &ldc
    2512                 | str( s1 ) | str( s2, 10 );
    2513 
    2514         sout | c | ' ' | endl
    2515                  | si | usi | i | ui | li | uli | lli | ulli | endl
    2516                  | f | d | ld | endl
    2517                  | f | "" | d | "" | ld | endl;
    2518 
    2519         sepSet( sout, ", $" );
    2520         sout | fc | dc | ldc | endl
    2521                  | sepOn | s1 | sepOff | s2 | endl
    2522                  | s1 | "" | s2 | endl;
    2523 }
    2524 
    2525 $ cat read.data
    2526 A 1 2 3 4 5 6 7 8 1.1 1.2 1.3 1.1+2.3 1.1-2.3 1.1-2.3 abc xyz
    2527 $ a.out
    2528 A
    2529 1 2 3 4 5 6 7 8
    2530 1.1 1.2 1.3
    2531 1.11.21.3
    2532 1.1+2.3i, $1.1-2.3i, $1.1-2.3i
    2533 , $abcxyz
    2534 abcxyz
    2535 \end{lstlisting}
    2536 \end{figure}
    2537 
    2538 
    2539 \section{Standard Library}
    2540 \label{s:StandardLibrary}
    2541 
    2542 The goal of the \CFA standard-library is to wrap many of the existing C library-routines that are explicitly polymorphic into implicitly polymorphic versions.
    2543 
    2544 
    2545 \subsection{malloc}
    2546 
    2547 \begin{lstlisting}
    2548 forall( otype T ) T * malloc( void );
    2549 forall( otype T ) T * malloc( char fill );
    2550 forall( otype T ) T * malloc( T * ptr, size_t size );
    2551 forall( otype T ) T * malloc( T * ptr, size_t size, unsigned char fill );
    2552 forall( otype T ) T * calloc( size_t size );
    2553 forall( otype T ) T * realloc( T * ptr, size_t size );
    2554 forall( otype T ) T * realloc( T * ptr, size_t size, unsigned char fill );
    2555 
    2556 forall( otype T ) T * aligned_alloc( size_t alignment );
    2557 forall( otype T ) T * memalign( size_t alignment );             // deprecated
    2558 forall( otype T ) int posix_memalign( T ** ptr, size_t alignment );
    2559 
    2560 forall( otype T ) T * memset( T * ptr, unsigned char fill ); // use default value '\0' for fill
    2561 forall( otype T ) T * memset( T * ptr );                                // remove when default value available
    2562 \end{lstlisting}
    2563 
    2564 
    2565 \subsection{ato/strto}
    2566 
    2567 \begin{lstlisting}
    2568 int ato( const char * ptr );
    2569 unsigned int ato( const char * ptr );
    2570 long int ato( const char * ptr );
    2571 unsigned long int ato( const char * ptr );
    2572 long long int ato( const char * ptr );
    2573 unsigned long long int ato( const char * ptr );
    2574 float ato( const char * ptr );
    2575 double ato( const char * ptr );
    2576 long double ato( const char * ptr );
    2577 float _Complex ato( const char * ptr );
    2578 double _Complex ato( const char * ptr );
    2579 long double _Complex ato( const char * ptr );
    2580 
    2581 int strto( const char * sptr, char ** eptr, int base );
    2582 unsigned int strto( const char * sptr, char ** eptr, int base );
    2583 long int strto( const char * sptr, char ** eptr, int base );
    2584 unsigned long int strto( const char * sptr, char ** eptr, int base );
    2585 long long int strto( const char * sptr, char ** eptr, int base );
    2586 unsigned long long int strto( const char * sptr, char ** eptr, int base );
    2587 float strto( const char * sptr, char ** eptr );
    2588 double strto( const char * sptr, char ** eptr );
    2589 long double strto( const char * sptr, char ** eptr );
    2590 float _Complex strto( const char * sptr, char ** eptr );
    2591 double _Complex strto( const char * sptr, char ** eptr );
    2592 long double _Complex strto( const char * sptr, char ** eptr );
    2593 \end{lstlisting}
    2594 
    2595 
    2596 \subsection{bsearch/qsort}
    2597 
    2598 \begin{lstlisting}
    2599 forall( otype T | { int ?<?( T, T ); } )
    2600 T * bsearch( const T key, const T * arr, size_t dimension );
    2601 
    2602 forall( otype T | { int ?<?( T, T ); } )
    2603 void qsort( const T * arr, size_t dimension );
    2604 \end{lstlisting}
    2605 
    2606 
    2607 \subsection{abs}
    2608 
    2609 \begin{lstlisting}
    2610 char abs( char );
    2611 extern "C" {
    2612 int abs( int );         // use default C routine for int
    2613 } // extern
    2614 long int abs( long int );
    2615 long long int abs( long long int );
    2616 float abs( float );
    2617 double abs( double );
    2618 long double abs( long double );
    2619 float _Complex abs( float _Complex );
    2620 double _Complex abs( double _Complex );
    2621 long double _Complex abs( long double _Complex );
    2622 \end{lstlisting}
    2623 
    2624 
    2625 \subsection{random}
    2626 
    2627 \begin{lstlisting}
    2628 void randseed( long int s );
    2629 char random();
    2630 int random();
    2631 unsigned int random();
    2632 long int random();
    2633 unsigned long int random();
    2634 float random();
    2635 double random();
    2636 float _Complex random();
    2637 double _Complex random();
    2638 long double _Complex random();
    2639 \end{lstlisting}
    2640 
    2641 
    2642 \subsection{min/max/swap}
    2643 
    2644 \begin{lstlisting}
    2645 forall( otype T | { int ?<?( T, T ); } )
    2646 T min( const T t1, const T t2 );
    2647 
    2648 forall( otype T | { int ?>?( T, T ); } )
    2649 T max( const T t1, const T t2 );
    2650 
    2651 forall( otype T )
    2652 void swap( T * t1, T * t2 );
    2653 \end{lstlisting}
     2410\section{Syntactic Anomalies}
     2411
     2412The number 0 and 1 are treated specially in \CFA, and can be redefined as variables.
     2413One syntactic anomaly is when a field in an structure is names 0 or 1:
     2414\begin{lstlisting}
     2415struct S {
     2416        int 0, 1;
     2417} s;
     2418\end{lstlisting}
     2419The problem occurs in accesing these fields using the selection operation ``\lstinline@.@'':
     2420\begin{lstlisting}
     2421s.0 = 0;        // ambiguity with floating constant .0
     2422s.1 = 1;        // ambiguity with floating constant .1
     2423\end{lstlisting}
     2424To make this work, a space is required after the field selection:
     2425\begin{lstlisting}
     2426`s.@\textvisiblespace@0` = 0;
     2427`s.@\textvisiblespace@1` = 1;
     2428\end{lstlisting}
     2429While this sytact is awkward, it is unlikely many programers will name fields of a structure 0 or 1.
     2430Like the \CC lexical problem with closing template-syntax, e.g, \lstinline@Foo<Bar<int`>>`@, this issue can be solved with a more powerful lexer/parser.
     2431
     2432There are several ambiguous cases with operator identifiers, e.g., \lstinline@int *?*?()@, where the string \lstinline@*?*?@ can be lexed as \lstinline@*@/\lstinline@?*?@ or \lstinline@*?@/\lstinline@*?@.
     2433Since it is common practise to put a unary operator juxtaposed to an identifier, e.g., \lstinline@*i@, users will be annoyed if they cannot do this with respect to operator identifiers.
     2434Even with this special hack, there are 5 general cases that cannot be handled.
     2435The first case is for the function-call identifier \lstinline@?()@:
     2436\begin{lstlisting}
     2437int *@\textvisiblespace@?()();  // declaration: space required after '*'
     2438*@\textvisiblespace@?()();              // expression: space required after '*'
     2439\end{lstlisting}
     2440Without the space, the string \lstinline@*?()@ is ambiguous without N character look ahead;
     2441it requires scanning ahead to determine if there is a \lstinline@'('@, which is the start of an argument/parameter list.
     2442
     2443The 4 remaining cases occur in expressions:
     2444\begin{lstlisting}
     2445i++@\textvisiblespace@?i:0;             // space required before '?'
     2446i--@\textvisiblespace@?i:0;             // space required before '?'
     2447i@\textvisiblespace@?++i:0;             // space required after '?'
     2448i@\textvisiblespace@?--i:0;             // space required after '?'
     2449\end{lstlisting}
     2450In the first two cases, the string \lstinline@i++?@ is ambiguous, where this string can be lexed as \lstinline@i@ / \lstinline@++?@ or \lstinline@i++@ / \lstinline@?@;
     2451it requires scanning ahead to determine if there is a \lstinline@'('@, which is the start of an argument list.
     2452In the second two cases, the string \lstinline@?++x@ is ambiguous, where this string can be lexed as \lstinline@?++@ / \lstinline@x@ or \lstinline@?@ / y\lstinline@++x@;
     2453it requires scanning ahead to determine if there is a \lstinline@'('@, which is the start of an argument list.
    26542454
    26552455
     
    26762476
    26772477task creates a type with implicit locking, separate stack, and a thread
     2478
    26782479
    26792480\subsection{Monitors}
     
    37753576\multicolumn{1}{c|}{\textbf{\CFA/\CC}} & \multicolumn{1}{c|}{\textbf{Go}} & \multicolumn{1}{c}{\textbf{Rust}}   \\
    37763577\hline
    3777 \begin{lstlisting}
     3578\begin{lstlisting}[boxpos=t]
    37783579extern "C" {
    37793580#include <sys/types.h>
     
    37823583}
    37833584size_t fileSize( const char *path ) {
    3784         stat s;
     3585        struct stat s;
    37853586        stat(path, &s);
    37863587        return s.st_size;
     
    37883589\end{lstlisting}
    37893590&
    3790 \begin{lstlisting}
     3591\begin{lstlisting}[boxpos=t]
    37913592/*
    37923593#cgo
     
    38073608\end{lstlisting}
    38083609&
    3809 \begin{lstlisting}
     3610\begin{lstlisting}[boxpos=t]
    38103611use libc::{c_int, size_t};
    3811 
    3812 // The following declarations are
    38133612// translated from sys/stat.h
    38143613#[repr(C)]
     
    38183617        ...
    38193618}
    3820 
    38213619#[link(name = "libc")]
    38223620extern {
     
    38243622        buf: *mut stat_t) -> c_int;
    38253623}
    3826 
    38273624fn fileSize(path: *const u8) -> size_t
    38283625{
    38293626        unsafe {
    3830         let mut buf: stat_t = uninit();
    3831         stat(path, &mut buf);
    3832         buf.st_size
     3627                let mut buf: stat_t = uninit();
     3628                stat(path, &mut buf);
     3629                buf.st_size
    38333630        }
    38343631}
     
    39533750
    39543751
     3752\begin{comment}
    39553753\subsubsection{Modules/Packages}
    39563754
     
    40323830}
    40333831\end{lstlisting}
     3832\end{comment}
     3833
    40343834
    40353835\subsubsection{Parallel Tasks}
     
    41873987\end{flushleft}
    41883988
     3989\lstset{basicstyle=\sf\relsize{-1}}
     3990
     3991
    41893992\subsection{Summary of Language Comparison}
    41903993
     
    42554058
    42564059
     4060\appendix
     4061
     4062
     4063\section{I/O Library}
     4064\label{s:IOLibrary}
     4065\index{input/output library}
     4066
     4067The goal for \CFA I/O is to make I/O as simple as possible for the general case, while fully supporting polmorphism and user defined types in a consistent way.
     4068The general case is printing out a sequence of variables separated by whitespace.
     4069\begin{quote2}
     4070\begin{tabular}{@{}l@{\hspace{30pt}}l@{}}
     4071\multicolumn{1}{c@{\hspace{30pt}}}{\textbf{\CFA}}       & \multicolumn{1}{c}{\textbf{\CC}}      \\
     4072\begin{lstlisting}
     4073int x = 0, y = 1, z = 2;
     4074`sout` `|` x `|` y `|` z `| endl`;
     4075\end{lstlisting}
     4076&
     4077\begin{lstlisting}
     4078
     4079cout << x << " " << y << " " << z << endl;
     4080\end{lstlisting}
     4081\end{tabular}
     4082\end{quote2}
     4083The \CFA form is half as many characters, and is similar to Python I/O with respect to implicit separators.
     4084
     4085The logical-or operator is used because it is the lowest-priority overloadable operator, other than assignment.
     4086Therefore, fewer output expressions require parenthesis.
     4087\begin{quote2}
     4088\begin{tabular}{@{}ll@{}}
     4089\textbf{\CFA:}
     4090&
     4091\begin{lstlisting}
     4092sout | x * 3 | y + 1 | z << 2 | x == y | (x | y) | (x || y) | (x > z ? 1 : 2) | endl;
     4093\end{lstlisting}
     4094\\
     4095\textbf{\CC:}
     4096&
     4097\begin{lstlisting}
     4098cout << x * 3 << y + 1 << (z << 2) << (x == y) << (x | y) << (x || y) << (x > z ? 1 : 2) << endl;
     4099\end{lstlisting}
     4100\end{tabular}
     4101\end{quote2}
     4102Finally, the logical-or operator has a link with the Shell pipe-operator for moving data, although data flows in the opposite direction.
     4103
     4104The implicit seperator\index{I/O separator} character (space/blank) is a separator not a terminator.
     4105The rules for implicitly adding the separator are:
     4106\begin{enumerate}
     4107\item
     4108A seperator does not appear at the start or end of a line.
     4109\begin{lstlisting}[belowskip=0pt]
     4110sout 1 | 2 | 3 | endl;
     4111\end{lstlisting}
     4112\begin{lstlisting}[mathescape=off,showspaces=true,aboveskip=0pt,belowskip=0pt]
     41131 2 3
     4114\end{lstlisting}
     4115\item
     4116A seperator does not appear before or after a character literal or variable.
     4117\begin{lstlisting}
     4118sout | '1' | '2' | '3' | endl;
     4119123
     4120\end{lstlisting}
     4121\item
     4122A seperator does not appear before or after a null (empty) C string
     4123\begin{lstlisting}
     4124sout | 1 | "" | 2 | "" | 3 | endl;
     4125123
     4126\end{lstlisting}
     4127which is a local mechanism to disable insertion of the separator character.
     4128\item
     4129A seperator does not appear before a C string starting with the \Index{extended ASCII}\index{ASCII} characters: \lstinline[mathescape=off]@([{$£¥¿«@
     4130%$
     4131\begin{lstlisting}[mathescape=off]
     4132sout | "x (" | 1 | "x [" | 2 | "x {" | 3 | "x $" | 4 | "x £" | 5 | "x ¥" | 6 | "x ¿" | 7 | "x «" | 8 | endl;
     4133\end{lstlisting}
     4134%$
     4135\begin{lstlisting}[mathescape=off,showspaces=true,aboveskip=0pt,belowskip=0pt]
     4136x (1 x [2 x {3 x $4 x £5 x ¥6 x ¿7 x «8
     4137\end{lstlisting}
     4138%$
     4139\item
     4140A seperator does not appear after a C string ending with the extended ASCII characters: \lstinline@,.:;!?)]}%¢»@
     4141\begin{lstlisting}[belowskip=0pt]
     4142sout | 1 | ", x" | 2 | ". x" | 3 | ": x" | 4 | "; x" | 5 | "! x" | 6 | "? x" | 7 | ") x" | 8 | "] x" | 9 | "} x"
     4143         | 10 | "% x" | 11 | L"¢ x" | 12 | L"» x" | endl;
     4144\end{lstlisting}
     4145\begin{lstlisting}[mathescape=off,showspaces=true,aboveskip=0pt,belowskip=0pt]
     41461, x 2. x 3: x 4; x 5! x 6? x 7) x 8] x 9} x 10% x 11¢ 12»
     4147\end{lstlisting}
     4148\item
     4149A seperator does not appear before or after a C string begining/ending with the characters: \lstinline@\f\n\r\t\v\`'"@
     4150\begin{lstlisting}[belowskip=0pt]
     4151sout | "x '" | 1 | "' x \`" | 2 | "\` x \"" | 3 | "\" x" | endl;
     4152\end{lstlisting}
     4153\begin{lstlisting}[mathescape=off,showspaces=true,aboveskip=0pt,belowskip=0pt]
     4154x '1' x \`2\` x "3" x
     4155\end{lstlisting}
     4156\begin{lstlisting}[showtabs=true,aboveskip=0pt]
     4157sout | "x\t" | 1 | "\tx" | endl;
     4158x       1       x
     4159\end{lstlisting}
     4160\end{enumerate}
     4161The following \CC-style \Index{manipulator}s allow further control over implicit seperation.
     4162\begin{lstlisting}[mathescape=off,belowskip=0pt]
     4163sout | sepOn | 1 | 2 | 3 | sepOn | endl;        // separator at start of line
     4164\end{lstlisting}
     4165\begin{lstlisting}[mathescape=off,showspaces=true,aboveskip=0pt,belowskip=0pt]
     4166 1 2 3
     4167\end{lstlisting}
     4168\begin{lstlisting}[mathescape=off,aboveskip=0pt,belowskip=0pt]
     4169sout | 1 | sepOff | 2 | 3 | endl;                       // turn off implicit separator temporarily
     4170\end{lstlisting}
     4171\begin{lstlisting}[mathescape=off,showspaces=true,aboveskip=0pt,belowskip=0pt]
     417212 3
     4173\end{lstlisting}
     4174\begin{lstlisting}[mathescape=off,aboveskip=0pt,belowskip=0pt]
     4175sout | sepDisable | 1 | 2 | 3 | endl;           // turn off implicit separation, affects all subsequent prints
     4176\end{lstlisting}
     4177\begin{lstlisting}[mathescape=off,showspaces=true,aboveskip=0pt,belowskip=0pt]
     4178123
     4179\end{lstlisting}
     4180\begin{lstlisting}[mathescape=off,aboveskip=0pt,belowskip=0pt]
     4181sout | 1 | sepOn | 2 | 3 | endl;                        // turn on implicit separator temporarily
     4182\end{lstlisting}
     4183\begin{lstlisting}[mathescape=off,showspaces=true,aboveskip=0pt,belowskip=0pt]
     41841 23
     4185\end{lstlisting}
     4186\begin{lstlisting}[mathescape=off,aboveskip=0pt,belowskip=0pt]
     4187sout | sepEnable | 1 | 2 | 3 | endl;            // turn on implicit separation, affects all subsequent prints
     4188\end{lstlisting}
     4189\begin{lstlisting}[mathescape=off,showspaces=true,aboveskip=0pt,belowskip=0pt]
     41901 2 3
     4191\end{lstlisting}
     4192\begin{lstlisting}[mathescape=off,aboveskip=0pt,aboveskip=0pt,belowskip=0pt]
     4193sepSet( sout, ", $" );                                          // change separator from " " to ", $"
     4194sout | 1 | 2 | 3 | endl;
     4195\end{lstlisting}
     4196%$
     4197\begin{lstlisting}[mathescape=off,showspaces=true,aboveskip=0pt]
     41981, $2, $3
     4199\end{lstlisting}
     4200%$
     4201\VRef[Figure]{f:ExampleIO} shows an example of input and output I/O in \CFA.
     4202
     4203\begin{figure}
     4204\begin{lstlisting}[mathescape=off]
     4205#include <fstream>
     4206
     4207int main() {
     4208        char c;                                                                                                         // basic types
     4209        short int si;
     4210        unsigned short int usi;
     4211        int i;
     4212        unsigned int ui;
     4213        long int li;
     4214        unsigned long int uli;
     4215        long long int lli;
     4216        unsigned long long int ulli;
     4217        float f;
     4218        double d;
     4219        long double ld;
     4220        float _Complex fc;
     4221        double _Complex dc;
     4222        long double _Complex ldc;
     4223        char s1[10], s2[10];
     4224
     4225        ifstream in;                                                                                            // create / open file
     4226        open( &in, "input.data", "r" );
     4227
     4228        &in | &c                                                                                                        // character
     4229                | &si | &usi | &i | &ui | &li | &uli | &lli | &ulli             // integral
     4230                | &f | &d | &ld                                                                                 // floating point
     4231                | &fc | &dc | &ldc                                                                              // floating-point complex
     4232                | cstr( s1 ) | cstr( s2, 10 );                                                  // C string, length unchecked and checked
     4233
     4234        sout | c | ' ' | endl                                                                           // character
     4235                 | si | usi | i | ui | li | uli | lli | ulli | endl             // integral
     4236                 | f | d | ld | endl                                                                    // floating point
     4237                 | fc | dc | ldc | endl;                                                                // complex
     4238        sout | endl;
     4239        sout | f | "" | d | "" | ld | endl                                                      // floating point without separator
     4240                 | sepDisable | fc | dc | ldc | sepEnable | endl                // complex without separator
     4241                 | sepOn | s1 | sepOff | s2 | endl                                              // local separator removal
     4242                 | s1 | "" | s2 | endl;                                                                 // C string withou separator
     4243        sout | endl;
     4244        sepSet( sout, ", $" );                                                                          // change separator, maximum of 15 characters
     4245        sout | f | d | ld | endl                                                                        // floating point without separator
     4246                 | fc | dc | ldc | endl                                                                 // complex without separator
     4247                 | s1 | s2 | endl;
     4248}
     4249
     4250$ cat input.data
     4251A 1 2 3 4 5 6 7 8 1.1 1.2 1.3 1.1+2.3 1.1-2.3 1.1-2.3 abc xyz
     4252$ a.out
     4253A
     42541 2 3 4 5 6 7 8
     42551.1 1.2 1.3
     42561.1+2.3i 1.1-2.3i 1.1-2.3i
     4257
     42581.11.21.3
     42591.1+2.3i1.1-2.3i1.1-2.3i
     4260 abcxyz
     4261abcxyz
     4262
     42631.1, $1.2, $1.3
     42641.1+2.3i, $1.1-2.3i, $1.1-2.3i
     4265abc, $xyz
     4266\end{lstlisting}
     4267\caption{Example I/O}
     4268\label{f:ExampleIO}
     4269\end{figure}
     4270
     4271
     4272\section{Standard Library}
     4273\label{s:StandardLibrary}
     4274
     4275The goal of the \CFA standard-library is to wrap many of the existing C library-routines that are explicitly polymorphic into implicitly polymorphic versions.
     4276
     4277
     4278\subsection{malloc}
     4279
     4280\begin{lstlisting}
     4281forall( otype T ) T * malloc( void );
     4282forall( otype T ) T * malloc( char fill );
     4283forall( otype T ) T * malloc( T * ptr, size_t size );
     4284forall( otype T ) T * malloc( T * ptr, size_t size, unsigned char fill );
     4285forall( otype T ) T * calloc( size_t size );
     4286forall( otype T ) T * realloc( T * ptr, size_t size );
     4287forall( otype T ) T * realloc( T * ptr, size_t size, unsigned char fill );
     4288
     4289forall( otype T ) T * aligned_alloc( size_t alignment );
     4290forall( otype T ) T * memalign( size_t alignment );             // deprecated
     4291forall( otype T ) int posix_memalign( T ** ptr, size_t alignment );
     4292
     4293forall( otype T ) T * memset( T * ptr, unsigned char fill ); // use default value '\0' for fill
     4294forall( otype T ) T * memset( T * ptr );                                // remove when default value available
     4295\end{lstlisting}
     4296
     4297
     4298\subsection{ato/strto}
     4299
     4300\begin{lstlisting}
     4301int ato( const char * ptr );
     4302unsigned int ato( const char * ptr );
     4303long int ato( const char * ptr );
     4304unsigned long int ato( const char * ptr );
     4305long long int ato( const char * ptr );
     4306unsigned long long int ato( const char * ptr );
     4307float ato( const char * ptr );
     4308double ato( const char * ptr );
     4309long double ato( const char * ptr );
     4310float _Complex ato( const char * ptr );
     4311double _Complex ato( const char * ptr );
     4312long double _Complex ato( const char * ptr );
     4313
     4314int strto( const char * sptr, char ** eptr, int base );
     4315unsigned int strto( const char * sptr, char ** eptr, int base );
     4316long int strto( const char * sptr, char ** eptr, int base );
     4317unsigned long int strto( const char * sptr, char ** eptr, int base );
     4318long long int strto( const char * sptr, char ** eptr, int base );
     4319unsigned long long int strto( const char * sptr, char ** eptr, int base );
     4320float strto( const char * sptr, char ** eptr );
     4321double strto( const char * sptr, char ** eptr );
     4322long double strto( const char * sptr, char ** eptr );
     4323float _Complex strto( const char * sptr, char ** eptr );
     4324double _Complex strto( const char * sptr, char ** eptr );
     4325long double _Complex strto( const char * sptr, char ** eptr );
     4326\end{lstlisting}
     4327
     4328
     4329\subsection{bsearch/qsort}
     4330
     4331\begin{lstlisting}
     4332forall( otype T | { int ?<?( T, T ); } )
     4333T * bsearch( const T key, const T * arr, size_t dimension );
     4334
     4335forall( otype T | { int ?<?( T, T ); } )
     4336void qsort( const T * arr, size_t dimension );
     4337\end{lstlisting}
     4338
     4339
     4340\subsection{abs}
     4341
     4342\begin{lstlisting}
     4343char abs( char );
     4344extern "C" {
     4345int abs( int );                         // use default C routine for int
     4346} // extern "C"
     4347long int abs( long int );
     4348long long int abs( long long int );
     4349float abs( float );
     4350double abs( double );
     4351long double abs( long double );
     4352float _Complex abs( float _Complex );
     4353double _Complex abs( double _Complex );
     4354long double _Complex abs( long double _Complex );
     4355\end{lstlisting}
     4356
     4357
     4358\subsection{floor/ceil}
     4359
     4360\begin{lstlisting}
     4361float floor( float );
     4362extern "C" {
     4363double floor( double );         // use C routine for double
     4364} // extern "C"
     4365long double floor( long double );
     4366
     4367float ceil( float );
     4368extern "C" {
     4369double ceil( double );          // use C routine for double
     4370} // extern "C"
     4371long double ceil( long double );
     4372\end{lstlisting}
     4373
     4374
     4375\subsection{random}
     4376
     4377\begin{lstlisting}
     4378void rand48seed( long int s );
     4379char rand48();
     4380int rand48();
     4381unsigned int rand48();
     4382long int rand48();
     4383unsigned long int rand48();
     4384float rand48();
     4385double rand48();
     4386float _Complex rand48();
     4387double _Complex rand48();
     4388long double _Complex rand48();
     4389\end{lstlisting}
     4390
     4391
     4392\subsection{min/max/swap}
     4393
     4394\begin{lstlisting}
     4395forall( otype T | { int ?<?( T, T ); } )
     4396T min( const T t1, const T t2 );
     4397
     4398forall( otype T | { int ?>?( T, T ); } )
     4399T max( const T t1, const T t2 );
     4400
     4401forall( otype T )
     4402void swap( T * t1, T * t2 );
     4403\end{lstlisting}
     4404
     4405
     4406\section{Rational Numbers}
     4407\label{s:RationalNumbers}
     4408
     4409Rational numbers are numbers written as a ratio, i.e., as a fraction, where the numerator (top number) and the denominator (bottom number) are whole numbers.
     4410When creating and computing with rational numbers, results are constantly reduced to keep the numerator and denominator as small as possible.
     4411
     4412\begin{lstlisting}
     4413// implementation
     4414struct Rational {
     4415        long int numerator, denominator;                                        // invariant: denominator > 0
     4416}; // Rational
     4417
     4418// constants
     4419extern struct Rational 0;
     4420extern struct Rational 1;
     4421
     4422// constructors
     4423Rational rational();
     4424Rational rational( long int n );
     4425Rational rational( long int n, long int d );
     4426
     4427// getter/setter for numerator/denominator
     4428long int numerator( Rational r );
     4429long int numerator( Rational r, long int n );
     4430long int denominator( Rational r );
     4431long int denominator( Rational r, long int d );
     4432
     4433// comparison
     4434int ?==?( Rational l, Rational r );
     4435int ?!=?( Rational l, Rational r );
     4436int ?<?( Rational l, Rational r );
     4437int ?<=?( Rational l, Rational r );
     4438int ?>?( Rational l, Rational r );
     4439int ?>=?( Rational l, Rational r );
     4440
     4441// arithmetic
     4442Rational -?( Rational r );
     4443Rational ?+?( Rational l, Rational r );
     4444Rational ?-?( Rational l, Rational r );
     4445Rational ?*?( Rational l, Rational r );
     4446Rational ?/?( Rational l, Rational r );
     4447
     4448// conversion
     4449double widen( Rational r );
     4450Rational narrow( double f, long int md );
     4451
     4452// I/O
     4453forall( dtype istype | istream( istype ) ) istype * ?|?( istype *, Rational * );
     4454forall( dtype ostype | ostream( ostype ) ) ostype * ?|?( ostype *, Rational );
     4455\end{lstlisting}
     4456
     4457
    42574458\bibliographystyle{plain}
    4258 \bibliography{/usr/local/bibliographies/pl.bib}
     4459\bibliography{cfa}
    42594460
    42604461
Note: See TracChangeset for help on using the changeset viewer.