Changeset 0a84919


Ignore:
Timestamp:
Apr 18, 2017, 8:58:40 AM (7 years ago)
Author:
Peter A. Buhr <pabuhr@…>
Branches:
ADT, aaron-thesis, arm-eh, ast-experimental, cleanup-dtors, deferred_resn, demangler, enum, forall-pointer-decay, jacob/cs343-translation, jenkins-sandbox, master, new-ast, new-ast-unique-expr, new-env, no_list, persistent-indexer, pthread-emulation, qualifiedEnum, resolv-new, with_gc
Children:
3bdd6f5
Parents:
036895e
Message:

cleanup source file

File:
1 edited

Legend:

Unmodified
Added
Removed
  • doc/generic_types/generic_types.tex

    r036895e r0a84919  
    99
    1010\makeatletter
     11% Default underscore is too low and wide. Cannot use lstlisting "literate" as replacing underscore
     12% removes it as a variable-name character so keyworks in variables are highlighted
     13\DeclareTextCommandDefault{\textunderscore}{\leavevmode\makebox[1.2ex][c]{\rule{1ex}{0.1ex}}}
     14
    1115% parindent is relative, i.e., toggled on/off in environments like itemize, so store the value for
    1216% use rather than use \parident directly.
     
    1418\setlength{\parindentlnth}{\parindent}
    1519
    16 \newlength{\gcolumnposn}                                % temporary hack because lstlisting does handle tabs correctly
     20\newlength{\gcolumnposn}                                % temporary hack because lstlisting does not handle tabs correctly
    1721\newlength{\columnposn}
    1822\setlength{\gcolumnposn}{2.75in}
     
    2125\newcommand{\CRT}{\global\columnposn=\gcolumnposn}
    2226
    23 \newcommand{\TODO}[1]{\textbf{TODO}: {\itshape #1}} % TODO included
    24 %\newcommand{\TODO}[1]{} % TODO elided
    2527% Latin abbreviation
    2628\newcommand{\abbrevFont}{\textit}       % set empty for no italics
     
    4345                {\abbrevFont{et al}.\xspace}%
    4446}%
    45 % \newcommand{\eg}{\textit{e}.\textit{g}.,\xspace}
    46 % \newcommand{\ie}{\textit{i}.\textit{e}.,\xspace}
    47 % \newcommand{\etc}{\textit{etc}.,\xspace}
    4847\makeatother
    4948
     
    5857\newcommand{\CS}{C\raisebox{-0.7ex}{\Large$^\sharp$}\xspace}
    5958\newcommand{\Textbf}[1]{{\color{red}\textbf{#1}}}
     59\newcommand{\TODO}[1]{\textbf{TODO}: {\itshape #1}} % TODO included
     60%\newcommand{\TODO}[1]{} % TODO elided
    6061
    6162% CFA programming language, based on ANSI C (with some gcc additions)
     
    8283belowskip=3pt,
    8384% replace/adjust listing characters that look bad in sanserif
    84 literate={-}{\raisebox{-0.15ex}{\texttt{-}}}1 {^}{\raisebox{0.6ex}{$\scriptscriptstyle\land\,$}}1
    85         {~}{\raisebox{0.3ex}{$\scriptstyle\sim\,$}}1%{_}{\makebox[1.2ex][c]{\rule{1ex}{0.1ex}}}1 % {`}{\ttfamily\upshape\hspace*{-0.1ex}`}1
    86         {<-}{$\leftarrow$}2 {=>}{$\Rightarrow$}2,
     85literate={-}{\makebox[1.4ex][c]{\raisebox{0.5ex}{\rule{1.2ex}{0.1ex}}}}1 {^}{\raisebox{0.6ex}{$\scriptscriptstyle\land\,$}}1
     86        {~}{\raisebox{0.3ex}{$\scriptstyle\sim\,$}}1 % {`}{\ttfamily\upshape\hspace*{-0.1ex}`}1
     87        {<-}{$\leftarrow$}2 {=>}{$\Rightarrow$}2 {->}{\makebox[1.4ex][c]{\raisebox{0.5ex}{\rule{1.2ex}{0.1ex}}}\kern-0.3ex\textgreater}2,
    8788moredelim=**[is][\color{red}]{`}{`},
    8889}% lstset
     
    185186\CC is used similarly, but has the disadvantages of multiple legacy design-choices that cannot be updated and active divergence of the language model from C, requiring significant effort and training to incrementally add \CC to a C-based project.
    186187
    187 \CFA is currently implemented as a source-to-source translator from \CFA to the GCC-dialect of C~\citep{GCCExtensions}, allowing it to leverage the portability and code optimizations provided by GCC, meeting goals (1)-(3).
     188\CFA is currently implemented as a source-to-source translator from \CFA to the GCC-dialect of C~\citep{GCCExtensions}, allowing it to leverage the portability and code optimizations provided by GCC, meeting goals (1)--(3).
    188189Ultimately, a compiler is necessary for advanced features and optimal performance.
    189190
     
    273274
    274275Finally, \CFA allows variable overloading:
    275 %\lstDeleteShortInline@%
    276 %\par\smallskip
    277 %\begin{tabular}{@{}l@{\hspace{1.5\parindent}}||@{\hspace{1.5\parindent}}l@{}}
    278276\begin{lstlisting}
    279277short int MAX = ...;   int MAX = ...;  double MAX = ...;
    280278short int s = MAX;    int i = MAX;    double d = MAX;   $\C{// select correct MAX}$
    281279\end{lstlisting}
    282 %\end{lstlisting}
    283 %&
    284 %\begin{lstlisting}
    285 %\end{tabular}
    286 %\smallskip\par\noindent
    287 %\lstMakeShortInline@%
    288280Here, the single name @MAX@ replaces all the C type-specific names: @SHRT_MAX@, @INT_MAX@, @DBL_MAX@.
    289281As well, restricted constant overloading is allowed for the values @0@ and @1@, which have special status in C, \eg the value @0@ is both an integer and a pointer literal, so its meaning depends on context.
     
    464456}
    465457\end{lstlisting}
    466 %       int c = cmp( a->first, b->first );
    467 %       if ( c == 0 ) c = cmp( a->second, b->second );
    468 %       return c;
    469458Since @pair(T *, T * )@ is a concrete type, there are no implicit parameters passed to @lexcmp@, so the generated code is identical to a function written in standard C using @void *@, yet the \CFA version is type-checked to ensure the fields of both pairs and the arguments to the comparison function match in type.
    470459
     
    612601double y = 3.5;
    613602[int, double] z;
    614 z = [x, y];             $\C{// multiple assignment}$
    615 [x, y] = z;             $\C{// multiple assignment}$
    616 z = 10;                 $\C{// mass assignment}$
    617 [y, x] = 3.14;  $\C{// mass assignment}$
     603z = [x, y];                                                                     $\C{// multiple assignment}$
     604[x, y] = z;                                                                     $\C{// multiple assignment}$
     605z = 10;                                                                         $\C{// mass assignment}$
     606[y, x] = 3.14;                                                          $\C{// mass assignment}$
    618607\end{lstlisting}
    619608%\end{lstlisting}
     
    652641[int, int, long, double] x;
    653642void f( double, long );
    654 x.[0, 1] = x.[1, 0];    $\C{// rearrange: [x.0, x.1] = [x.1, x.0]}$
    655 f( x.[0, 3] );            $\C{// drop: f(x.0, x.3)}$
    656 [int, int, int] y = x.[2, 0, 2]; $\C{// duplicate: [y.0, y.1, y.2] = [x.2, x.0.x.2]}$
     643x.[0, 1] = x.[1, 0];                                            $\C{// rearrange: [x.0, x.1] = [x.1, x.0]}$
     644f( x.[0, 3] );                                                          $\C{// drop: f(x.0, x.3)}$
     645[int, int, int] y = x.[2, 0, 2];                        $\C{// duplicate: [y.0, y.1, y.2] = [x.2, x.0.x.2]}$
    657646\end{lstlisting}
    658647%\end{lstlisting}
     
    851840\begin{lstlisting}
    852841forall(dtype T0, dtype T1 | sized(T0) | sized(T1)) struct _tuple2 {
    853         T0 field_0;                     $\C{// generated before the first 2-tuple}$
     842        T0 field_0;                                                             $\C{// generated before the first 2-tuple}$
    854843        T1 field_1;
    855844};
     
    857846        _tuple2(double, double) x;
    858847        forall(dtype T0, dtype T1, dtype T2 | sized(T0) | sized(T1) | sized(T2)) struct _tuple3 {
    859                 T0 field_0;             $\C{// generated before the first 3-tuple}$
     848                T0 field_0;                                                     $\C{// generated before the first 3-tuple}$
    860849                T1 field_1;
    861850                T2 field_2;
     
    11091098
    11101099\begin{acks}
    1111 The authors would like to recognize the design assistance of Glen Ditchfield, Richard Bilson, and Thierry Delisle on the features described in this paper. They also thank Magnus Madsen and three anonymous reviewers for valuable editorial feedback.
    1112 
    1113 This work is supported in part by a corporate partnership with \grantsponsor{Huawei}{Huawei Ltd.}{http://www.huawei.com}\ and the first author's \grantsponsor{NSERC-PGS}{NSERC PGS D}{http://www.nserc-crsng.gc.ca/Students-Etudiants/PG-CS/BellandPostgrad-BelletSuperieures_eng.asp} scholarship.
     1100The authors would like to recognize the design assistance of Glen Ditchfield, Richard Bilson, and Thierry Delisle on the features described in this paper, and thank Magnus Madsen and the three anonymous reviewers for valuable feedback.
     1101This work is supported in part by a corporate partnership with \grantsponsor{Huawei}{Huawei Ltd.}{http://www.huawei.com}, and Aaron Moss and Peter Buhr are funded by the \grantsponsor{Natural Sciences and Engineering Research Council} of Canada.
     1102% the first author's \grantsponsor{NSERC-PGS}{NSERC PGS D}{http://www.nserc-crsng.gc.ca/Students-Etudiants/PG-CS/BellandPostgrad-BelletSuperieures_eng.asp} scholarship.
    11141103\end{acks}
    11151104
     
    11251114
    11261115\lstset{basicstyle=\linespread{0.9}\sf\small}
    1127 
    1128 \begin{comment}
    1129 \CFA
    1130 \begin{lstlisting}[xleftmargin=2\parindentlnth,aboveskip=0pt,belowskip=0pt]
    1131 forall(otype T) struct stack_node;
    1132 forall(otype T) struct stack { stack_node(T) * head; };
    1133 forall(otype T) void ?{}(stack(T) * s);
    1134 forall(otype T) void ?{}(stack(T) * s, stack(T) t);
    1135 forall(otype T) stack(T) ?=?(stack(T) * s, stack(T) t);
    1136 forall(otype T) void ^?{}(stack(T) * s);
    1137 forall(otype T) _Bool empty(const stack(T) * s);
    1138 forall(otype T) void push(stack(T) * s, T value);
    1139 forall(otype T) T pop(stack(T) * s);
    1140 forall(otype T) void clear(stack(T) * s);
    1141 
    1142 void print( FILE * out, const char * x );
    1143 void print( FILE * out, _Bool x );
    1144 void print( FILE * out, char x );
    1145 void print( FILE * out, int x );
    1146 forall(otype T, ttype Params | { void print( FILE *, T ); void print( FILE *, Params ); })
    1147         void print( FILE * out, T arg, Params rest );
    1148 forall(otype R, otype S | { void print( FILE *, R ); void print( FILE *, S ); })
    1149         void print( FILE * out, pair(R, S) x );
    1150 \end{lstlisting}
    1151 
    1152 \medskip\noindent
    1153 \CC
    1154 \begin{lstlisting}[xleftmargin=2\parindentlnth,aboveskip=0pt,belowskip=0pt]
    1155 std::pair
    1156 std::forward_list wrapped in std::stack interface
    1157 
    1158 template<typename T> void print(ostream & out, const T & x) { out << x; }
    1159 template<> void print<bool>(ostream & out, const bool & x) { out << (x ? "true" : "false"); }
    1160 template<> void print<char>(ostream & out, const char & x ) { out << "'" << x << "'"; }
    1161 template<typename R, typename S> ostream & operator<< (ostream & out, const pair<R, S>& x) {
    1162         out << "["; print(out, x.first); out << ", "; print(out, x.second); return out << "]"; }
    1163 template<typename T, typename... Args> void print(ostream & out, const T & arg, const Args &... rest) {
    1164         out << arg;     print(out, rest...); }
    1165 \end{lstlisting}
    1166 
    1167 \medskip\noindent
    1168 C
    1169 \begin{lstlisting}[xleftmargin=2\parindentlnth,aboveskip=0pt,belowskip=0pt]
    1170 struct pair { void * first, second; };
    1171 struct pair * new_pair( void * first, void * second );
    1172 struct pair * copy_pair( const struct pair * src,
    1173         void * (*copy_first)( const void * ), void * (*copy_second)( const void * ) );
    1174 void free_pair( struct pair * p, void (*free_first)( void * ), void (*free_second)( void * ) );
    1175 int cmp_pair( const struct pair * a, const struct pair * b,
    1176         int (*cmp_first)( const void *, const void * ), int (*cmp_second)( const void *, const void * ) );
    1177 
    1178 struct stack_node;
    1179 struct stack { struct stack_node * head; };
    1180 struct stack new_stack();
    1181 void copy_stack( struct stack * dst, const struct stack * src, void * (*copy)( const void * ) );
    1182 void clear_stack( struct stack * s, void (*free_el)( void * ) );
    1183 _Bool stack_empty( const struct stack * s );
    1184 void push_stack( struct stack * s, void * value );
    1185 void * pop_stack( struct stack * s );
    1186 
    1187 void print_string( FILE * out, const char * x );
    1188 void print_bool( FILE * out, _Bool x );
    1189 void print_char( FILE * out, char x );
    1190 void print_int( FILE * out, int x );
    1191 void print( FILE * out, const char * fmt, ... );
    1192 \end{lstlisting}
    1193 \end{comment}
    11941116
    11951117Throughout, @/***/@ designates a counted redundant type annotation.
Note: See TracChangeset for help on using the changeset viewer.