Changes in / [cab8cac:d87ade9]
- Location:
- doc
- Files:
-
- 3 edited
-
bibliography/cfa.bib (modified) (1 diff)
-
generic_types/evaluation/timing.gp (modified) (1 diff)
-
generic_types/generic_types.tex (modified) (19 diffs)
Legend:
- Unmodified
- Added
- Removed
-
doc/bibliography/cfa.bib
rcab8cac rd87ade9 3650 3650 contributer = {pabuhr@plg}, 3651 3651 author = {James Gosling and Bill Joy and Guy Steele and Gilad Bracha and Alex Buckley}, 3652 title = {{Java} Language Spec .},3652 title = {{Java} Language Specification}, 3653 3653 organization= {Oracle}, 3654 3654 publisher = {Oracle}, -
doc/generic_types/evaluation/timing.gp
rcab8cac rd87ade9 1 1 # set terminal pdfcairo linewidth 3 size 6,3 2 2 # set output "timing.pdf" 3 set terminal pslatex size 6.25,2. 125 color solid3 set terminal pslatex size 6.25,2.25 color solid 4 4 set output "timing.tex" 5 5 -
doc/generic_types/generic_types.tex
rcab8cac rd87ade9 9 9 10 10 \makeatletter 11 % Default underscore is too low and wide. Cannot use lstlisting "literate" as replacing underscore12 % removes it as a variable-name character so keyworks in variables are highlighted13 \DeclareTextCommandDefault{\textunderscore}{\leavevmode\makebox[1.2ex][c]{\rule{1ex}{0.1ex}}}14 15 11 % parindent is relative, i.e., toggled on/off in environments like itemize, so store the value for 16 12 % use rather than use \parident directly. … … 18 14 \setlength{\parindentlnth}{\parindent} 19 15 20 \newlength{\gcolumnposn} % temporary hack because lstlisting does nothandle tabs correctly16 \newlength{\gcolumnposn} % temporary hack because lstlisting does handle tabs correctly 21 17 \newlength{\columnposn} 22 18 \setlength{\gcolumnposn}{2.75in} … … 25 21 \newcommand{\CRT}{\global\columnposn=\gcolumnposn} 26 22 23 \newcommand{\TODO}[1]{\textbf{TODO}: {\itshape #1}} % TODO included 24 %\newcommand{\TODO}[1]{} % TODO elided 27 25 % Latin abbreviation 28 26 \newcommand{\abbrevFont}{\textit} % set empty for no italics … … 45 43 {\abbrevFont{et al}.\xspace}% 46 44 }% 45 % \newcommand{\eg}{\textit{e}.\textit{g}.,\xspace} 46 % \newcommand{\ie}{\textit{i}.\textit{e}.,\xspace} 47 % \newcommand{\etc}{\textit{etc}.,\xspace} 47 48 \makeatother 48 49 … … 55 56 \newcommand{\CCtwenty}{\rm C\kern-.1em\hbox{+\kern-.25em+}20\xspace} % C++20 symbolic name 56 57 \newcommand{\CCV}{\rm C\kern-.1em\hbox{+\kern-.25em+}obj\xspace} % C++ virtual symbolic name 57 \newcommand{\C sharp}{C\raisebox{-0.7ex}{\Large$^\sharp$}\xspace} % C# symbolic name58 \newcommand{\CS}{C\raisebox{-0.7ex}{\Large$^\sharp$}\xspace} 58 59 \newcommand{\Textbf}[1]{{\color{red}\textbf{#1}}} 59 \newcommand{\TODO}[1]{\textbf{TODO}: {\itshape #1}} % TODO included60 %\newcommand{\TODO}[1]{} % TODO elided61 60 62 61 % CFA programming language, based on ANSI C (with some gcc additions) … … 83 82 belowskip=3pt, 84 83 % replace/adjust listing characters that look bad in sanserif 85 literate={-}{\ makebox[1.4ex][c]{\raisebox{0.5ex}{\rule{1.2ex}{0.1ex}}}}1 {^}{\raisebox{0.6ex}{$\scriptscriptstyle\land\,$}}186 {~}{\raisebox{0.3ex}{$\scriptstyle\sim\,$}}1 % {`}{\ttfamily\upshape\hspace*{-0.1ex}`}187 {<-}{$\leftarrow$}2 {=>}{$\Rightarrow$}2 {->}{\makebox[1.4ex][c]{\raisebox{0.5ex}{\rule{1.2ex}{0.1ex}}}\kern-0.3ex\textgreater}2,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, 88 87 moredelim=**[is][\color{red}]{`}{`}, 89 88 }% lstset … … 160 159 The C programming language is a foundational technology for modern computing with millions of lines of code implementing everything from commercial operating-systems to hobby projects. 161 160 This installation base and the programmers producing it represent a massive software-engineering investment spanning decades and likely to continue for decades more. 162 The \citet{TIOBE} ranks the top 5 most popular programming languages as: Java 16\%, \Textbf{C 7\%}, \Textbf{\CC 5\%}, \C sharp4\%, Python 4\% = 36\%, where the next 50 languages are less than 3\% each with a long tail.161 The \citet{TIOBE} ranks the top 5 most popular programming languages as: Java 16\%, \Textbf{C 7\%}, \Textbf{\CC 5\%}, \CS 4\%, Python 4\% = 36\%, where the next 50 languages are less than 3\% each with a long tail. 163 162 The top 3 rankings over the past 30 years are: 164 163 \lstDeleteShortInline@% … … 186 185 \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. 187 186 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).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). 189 188 Ultimately, a compiler is necessary for advanced features and optimal performance. 190 189 … … 274 273 275 274 Finally, \CFA allows variable overloading: 275 %\lstDeleteShortInline@% 276 %\par\smallskip 277 %\begin{tabular}{@{}l@{\hspace{1.5\parindent}}||@{\hspace{1.5\parindent}}l@{}} 276 278 \begin{lstlisting} 277 279 short int MAX = ...; int MAX = ...; double MAX = ...; 278 280 short int s = MAX; int i = MAX; double d = MAX; $\C{// select correct MAX}$ 279 281 \end{lstlisting} 282 %\end{lstlisting} 283 %& 284 %\begin{lstlisting} 285 %\end{tabular} 286 %\smallskip\par\noindent 287 %\lstMakeShortInline@% 280 288 Here, the single name @MAX@ replaces all the C type-specific names: @SHRT_MAX@, @INT_MAX@, @DBL_MAX@. 281 289 As 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. … … 456 464 } 457 465 \end{lstlisting} 466 % int c = cmp( a->first, b->first ); 467 % if ( c == 0 ) c = cmp( a->second, b->second ); 468 % return c; 458 469 Since @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. 459 470 … … 601 612 double y = 3.5; 602 613 [int, double] z; 603 z = [x, y]; $\C{// multiple assignment}$604 [x, y] = z; $\C{// multiple assignment}$605 z = 10; $\C{// mass assignment}$606 [y, x] = 3.14; $\C{// mass assignment}$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}$ 607 618 \end{lstlisting} 608 619 %\end{lstlisting} … … 641 652 [int, int, long, double] x; 642 653 void f( double, long ); 643 x.[0, 1] = x.[1, 0]; $\C{// rearrange: [x.0, x.1] = [x.1, x.0]}$644 f( 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]}$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]}$ 646 657 \end{lstlisting} 647 658 %\end{lstlisting} … … 840 851 \begin{lstlisting} 841 852 forall(dtype T0, dtype T1 | sized(T0) | sized(T1)) struct _tuple2 { 842 T0 field_0; $\C{// generated before the first 2-tuple}$853 T0 field_0; $\C{// generated before the first 2-tuple}$ 843 854 T1 field_1; 844 855 }; … … 846 857 _tuple2(double, double) x; 847 858 forall(dtype T0, dtype T1, dtype T2 | sized(T0) | sized(T1) | sized(T2)) struct _tuple3 { 848 T0 field_0; $\C{// generated before the first 3-tuple}$859 T0 field_0; $\C{// generated before the first 3-tuple}$ 849 860 T1 field_1; 850 861 T2 field_2; … … 1012 1023 \section{Related Work} 1013 1024 1014 1015 \subsection{Polymorphism} 1025 % \subsection{Polymorphism} 1016 1026 1017 1027 \CC is the most similar language to \CFA; … … 1031 1041 In \CFA terms, all Cyclone polymorphism must be dtype-static. 1032 1042 While the Cyclone design provides the efficiency benefits discussed in Section~\ref{sec:generic-apps} for dtype-static polymorphism, it is more restrictive than \CFA's general model. 1033 \citet{Smith98} present Polymorphic C, an ML dialect with polymorphic functions and C-like syntax and pointer types; it lacks many of C's features, however, most notably struct uretypes, and so is not a practical C replacement.1043 \citet{Smith98} present Polymorphic C, an ML dialect with polymorphic functions and C-like syntax and pointer types; it lacks many of C's features, however, most notably struct types, and so is not a practical C replacement. 1034 1044 1035 1045 \citet{obj-c-book} is an industrially successful extension to C. 1036 1046 However, Objective-C is a radical departure from C, using an object-oriented model with message-passing. 1037 Objective-C did not support type-checked generics until recently \cite t{xcode7}, historically using less-efficient runtime checking of object types.1047 Objective-C did not support type-checked generics until recently \citep{xcode7}, historically using less-efficient runtime checking of object types. 1038 1048 The~\citet{GObject} framework also adds object-oriented programming with runtime type-checking and reference-counting garbage-collection to C; 1039 1049 these features are more intrusive additions than those provided by \CFA, in addition to the runtime overhead of reference-counting. 1040 1050 \citet{Vala} compiles to GObject-based C, adding the burden of learning a separate language syntax to the aforementioned demerits of GObject as a modernization path for existing C code-bases. 1041 Java~\citep{Java8} included generic types in Java~5 ,which are type-checked at compilation and type-erased at runtime, similar to \CFA's.1051 Java~\citep{Java8} included generic types in Java~5 which are type-checked at compilation and type-erased at runtime, similar to \CFA's. 1042 1052 However, in Java, each object carries its own table of method pointers, while \CFA passes the method pointers separately to maintain a C-compatible layout. 1043 1053 Java is also a garbage-collected, object-oriented language, with the associated resource usage and C-interoperability burdens. … … 1053 1063 \CFA, with its more modest safety features, allows direct ports of C code while maintaining the idiomatic style of the original source. 1054 1064 1055 1056 \subsection{Tuples/Variadics} 1065 % \subsection{Tuples/Variadics} 1057 1066 1058 1067 Many programming languages have some form of tuple construct and/or variadic functions, \eg SETL, C, KW-C, \CC, D, Go, Java, ML, and Scala. … … 1098 1107 1099 1108 \begin{acks} 1100 The 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 valuablefeedback.1101 This 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.1109 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. 1110 1111 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. 1103 1112 \end{acks} 1104 1113 … … 1114 1123 1115 1124 \lstset{basicstyle=\linespread{0.9}\sf\small} 1125 1126 \begin{comment} 1127 \CFA 1128 \begin{lstlisting}[xleftmargin=2\parindentlnth,aboveskip=0pt,belowskip=0pt] 1129 forall(otype T) struct stack_node; 1130 forall(otype T) struct stack { stack_node(T) * head; }; 1131 forall(otype T) void ?{}(stack(T) * s); 1132 forall(otype T) void ?{}(stack(T) * s, stack(T) t); 1133 forall(otype T) stack(T) ?=?(stack(T) * s, stack(T) t); 1134 forall(otype T) void ^?{}(stack(T) * s); 1135 forall(otype T) _Bool empty(const stack(T) * s); 1136 forall(otype T) void push(stack(T) * s, T value); 1137 forall(otype T) T pop(stack(T) * s); 1138 forall(otype T) void clear(stack(T) * s); 1139 1140 void print( FILE * out, const char * x ); 1141 void print( FILE * out, _Bool x ); 1142 void print( FILE * out, char x ); 1143 void print( FILE * out, int x ); 1144 forall(otype T, ttype Params | { void print( FILE *, T ); void print( FILE *, Params ); }) 1145 void print( FILE * out, T arg, Params rest ); 1146 forall(otype R, otype S | { void print( FILE *, R ); void print( FILE *, S ); }) 1147 void print( FILE * out, pair(R, S) x ); 1148 \end{lstlisting} 1149 1150 \medskip\noindent 1151 \CC 1152 \begin{lstlisting}[xleftmargin=2\parindentlnth,aboveskip=0pt,belowskip=0pt] 1153 std::pair 1154 std::forward_list wrapped in std::stack interface 1155 1156 template<typename T> void print(ostream & out, const T & x) { out << x; } 1157 template<> void print<bool>(ostream & out, const bool & x) { out << (x ? "true" : "false"); } 1158 template<> void print<char>(ostream & out, const char & x ) { out << "'" << x << "'"; } 1159 template<typename R, typename S> ostream & operator<< (ostream & out, const pair<R, S>& x) { 1160 out << "["; print(out, x.first); out << ", "; print(out, x.second); return out << "]"; } 1161 template<typename T, typename... Args> void print(ostream & out, const T & arg, const Args &... rest) { 1162 out << arg; print(out, rest...); } 1163 \end{lstlisting} 1164 1165 \medskip\noindent 1166 C 1167 \begin{lstlisting}[xleftmargin=2\parindentlnth,aboveskip=0pt,belowskip=0pt] 1168 struct pair { void * first, second; }; 1169 struct pair * new_pair( void * first, void * second ); 1170 struct pair * copy_pair( const struct pair * src, 1171 void * (*copy_first)( const void * ), void * (*copy_second)( const void * ) ); 1172 void free_pair( struct pair * p, void (*free_first)( void * ), void (*free_second)( void * ) ); 1173 int cmp_pair( const struct pair * a, const struct pair * b, 1174 int (*cmp_first)( const void *, const void * ), int (*cmp_second)( const void *, const void * ) ); 1175 1176 struct stack_node; 1177 struct stack { struct stack_node * head; }; 1178 struct stack new_stack(); 1179 void copy_stack( struct stack * dst, const struct stack * src, void * (*copy)( const void * ) ); 1180 void clear_stack( struct stack * s, void (*free_el)( void * ) ); 1181 _Bool stack_empty( const struct stack * s ); 1182 void push_stack( struct stack * s, void * value ); 1183 void * pop_stack( struct stack * s ); 1184 1185 void print_string( FILE * out, const char * x ); 1186 void print_bool( FILE * out, _Bool x ); 1187 void print_char( FILE * out, char x ); 1188 void print_int( FILE * out, int x ); 1189 void print( FILE * out, const char * fmt, ... ); 1190 \end{lstlisting} 1191 \end{comment} 1116 1192 1117 1193 Throughout, @/***/@ designates a counted redundant type annotation.
Note:
See TracChangeset
for help on using the changeset viewer.