# Changeset 271326e

Ignore:
Timestamp:
Feb 15, 2018, 4:00:40 PM (4 years ago)
Branches:
aaron-thesis, arm-eh, cleanup-dtors, deferred_resn, demangler, jacob/cs343-translation, jenkins-sandbox, master, new-ast, new-ast-unique-expr, new-env, no_list, persistent-indexer, resolv-new, with_gc
Children:
359f29f
Parents:
d27e340
Message:

 rd27e340 \section{Introduction and Background} \section{Introduction} 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. The new constructs are empirically compared with both standard C and \CC; the results show the new design is comparable in performance. \subsection{Polymorphic Functions} \section{Polymorphic Functions} \CFA introduces both ad-hoc and parametric polymorphism to C, with a design originally formalized by Ditchfield~\cite{Ditchfield92}, and first implemented by Bilson~\cite{Bilson03}. \subsection{Name Overloading} C already has a limited form of ad-hoc polymorphism in the form of its basic arithmetic operators, which apply to a variety of different types using identical syntax. \CFA extends the built-in operator overloading by allowing users to define overloads for any function, not just operators, and even any variable; Section~\ref{sec:libraries} includes a number of examples of how this overloading simplifies \CFA programming relative to C. Code generation for these overloaded functions and variables is implemented by the usual approach of mangling the identifier names to include a representation of their type, while \CFA decides which overload to apply based on the same usual arithmetic conversions'' used in C to disambiguate operator overloads. As an example: \begin{cfa} int max(int a, int b) { return a < b ? b : a; }  // (1) double max(double a, double b) { return a < b ? b : a; }  // (2) int max = INT_MAX;     // (3) double max = DBL_MAX;  // (4) max(7, -max);   $\C{// uses (1) and (3), by matching int from constant 7}$ max(max, 3.14); $\C{// uses (2) and (4), by matching double from constant 3.14}$ //max(max, -max);  $\C{// ERROR: ambiguous}$ int m = max(max, -max); $\C{// uses (1) once and (3) twice, by matching return type}$ \end{cfa} \Celeven did add @_Generic@ expressions, which can be used in preprocessor macros to provide a form of ad-hoc polymorphism; however, this polymorphism is both functionally and ergonomically inferior to \CFA name overloading. The macro wrapping the generic expression imposes some limitations; as an example, it could not implement the example above, because the variables @max@ would collide with the functions @max@. Ergonomic limitations of @_Generic@ include the necessity to put a fixed list of supported types in a single place and manually dispatch to appropriate overloads, as well as possible namespace pollution from the functions dispatched to, which must all have distinct names. \subsection{\texorpdfstring{\LstKeywordStyle{forall} Functions}{forall Functions}} \label{sec:poly-fns} \CFA{}\hspace{1pt}'s polymorphism was originally formalized by Ditchfield~\cite{Ditchfield92}, and first implemented by Bilson~\cite{Bilson03}. The signature feature of \CFA is parametric-polymorphic functions~\cite{forceone:impl,Cormack90,Duggan96} with functions generalized using a @forall@ clause (giving the language its name): \begin{lstlisting} Hence, programmers can easily form local environments, adding and modifying appropriate functions, to maximize reuse of other existing functions and types. Finally, \CFA allows variable overloading: \begin{lstlisting} short int MAX = ...;   int MAX = ...;  double MAX = ...; short int s = MAX;    int i = MAX;    double d = MAX;   $\C{// select correct MAX}$ \end{lstlisting} Here, the single name @MAX@ replaces all the C type-specific names: @SHRT_MAX@, @INT_MAX@, @DBL_MAX@. %% Redundant with Section~\ref{sec:libraries} %% % Finally, \CFA allows variable overloading: % \begin{lstlisting} % short int MAX = ...;   int MAX = ...;  double MAX = ...; % short int s = MAX;    int i = MAX;    double d = MAX;   $\C{// select correct MAX}$ % \end{lstlisting} % Here, the single name @MAX@ replaces all the C type-specific names: @SHRT_MAX@, @INT_MAX@, @DBL_MAX@. \subsection{Traits} \end{cfa} \subsection{Exception Handling ???} % \subsection{Exception Handling ???} \section{Declarations} \section{Libraries} \label{sec:libraries} As stated in Section~\ref{sec:poly-fns}, \CFA inherits a large corpus of library code, where other programming languages must rewrite or provide fragile inter-language communication with C.