Changes in / [7a026ff:22444f4]


Ignore:
File:
1 edited

Legend:

Unmodified
Added
Removed
  • doc/generic_types/generic_types.tex

    r7a026ff r22444f4  
    149149Nonetheless, C, first standardized over thirty years ago, lacks many features that make programming in more modern languages safer and more productive.
    150150
    151 \CFA (pronounced ``C-for-all'', and written \CFA or Cforall) is an evolutionary extension of the C programming language that aims to add modern language features to C while maintaining both source compatibility with C and a familiar programming model for programmers. The four key design goals for \CFA~\citep{Bilson03} are:
     151\CFA (pronounced ``C-for-all'', and written \CFA or Cforall) is an evolutionary extension of the C programming language that aims to add modern language features to C while maintaining both source compatibility with C and a familiar programming model for programmers. Four key design goals were set out in the original design of \CFA~\citep{Bilson03}:
    152152(1) The behaviour of standard C code must remain the same when translated by a \CFA compiler as when translated by a C compiler;
    153153(2) Standard C code must be as fast and as small when translated by a \CFA compiler as when translated by a C compiler;
    154154(3) \CFA code must be at least as portable as standard C code;
    155155(4) Extensions introduced by \CFA must be translated in the most efficient way possible.
    156 These goals ensure existing C code-bases can be converted to \CFA incrementally with minimal effort, and C programmers can productively generate \CFA code without training beyond the features being used. In its current implementation, \CFA is compiled by translating it to the GCC-dialect of C~\citep{GCCExtensions}, allowing it to leverage the portability and code optimizations provided by GCC, meeting goals (1)-(3). Ultimately, a compiler is necessary for advanced features and optimal performance.
    157 
    158 This paper identifies shortcomings in existing approaches to generic and variadic data types in C-like languages and presents a design for generic and variadic types avoiding those shortcomings. Specifically, the solution is both reusable and type-checked, as well as conforming to the design goals of \CFA with ergonomic use of existing C abstractions. The new constructs are empirically compared with both standard C and \CC; the results show the new design is comparable in performance.
     156These goals ensure existing C code-bases can be converted to \CFA incrementally and with minimal effort, and C programmers can productively generate \CFA code without training beyond the features they wish to employ. In its current implementation, \CFA is compiled by translating it to the GCC-dialect of C~\citep{GCCExtensions}, allowing it to leverage the portability and code optimizations provided by GCC, meeting goals (1)-(3). Ultimately, a compiler is necessary for advanced features and optimal performance.
     157
     158\CFA has been previously extended with polymorphic functions and name overloading (including operator overloading) by \citet{Bilson03}, and deterministically-executed constructors and destructors by \citet{Schluntz17}. This paper builds on those contributions, identifying shortcomings in existing approaches to generic and variadic data types in C-like languages and presenting a design for generic and variadic types avoiding those shortcomings. Specifically, the solution is both reusable and type-checked, as well as conforming to the design goals of \CFA with ergonomic use of existing C abstractions. The new constructs are empirically compared with both standard C and \CC; the results show the new design is comparable in performance.
    159159
    160160
     
    224224Call-site inferencing and nested functions provide a localized form of inheritance. For example, @qsort@ only sorts in ascending order using @<@. However, it is trivial to locally change this behaviour:
    225225\begin{lstlisting}
    226 {
    227         int ?<?( double x, double y ) { return x `>` y; }       $\C{// override behaviour}$
     226{   int ?<?( double x, double y ) { return x `>` y; }   $\C{// override behaviour}$
    228227        qsort( vals, size );                                    $\C{// descending sort}$
    229228}
     
    258257\begin{lstlisting}
    259258trait summable( otype T ) {
    260         void ?{}( T *, zero_t );                                $\C{// constructor from 0 literal}$
     259        void ?{}(T*, zero_t);                                   $\C{// constructor from 0 literal}$
    261260        T ?+?( T, T );                                                  $\C{// assortment of additions}$
    262261        T ?+=?( T *, T );
     
    264263        T ?++( T * );
    265264};
    266 forall( otype T `| summable( T )` ) T sum( T a[$\,$], size_t size ) {  // use trait
    267         `T` total = { `0` };                                    $\C{// instantiate T from 0 by calling its constructor}$
     265forall( otype T | summable( T ) )
     266  T sum( T a[$\,$], size_t size ) {
     267        `T` total = { `0` };                                    $\C{// instantiate T from 0 but calling its constructor}$
    268268        for ( unsigned int i = 0; i < size; i += 1 )
    269269                total `+=` a[i];                                        $\C{// select appropriate +}$
Note: See TracChangeset for help on using the changeset viewer.