Changeset 36e05a2


Ignore:
Timestamp:
Apr 3, 2017, 9:10:57 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:
8396044, fc19129
Parents:
ea73caf
Message:

more squeezing of text to fit on first 3 pages

File:
1 edited

Legend:

Unmodified
Added
Removed
  • doc/generic_types/generic_types.tex

    rea73caf r36e05a2  
    133133\item Extensions introduced by \CFA must be translated in the most efficient way possible.
    134134\end{enumerate}
    135 The purpose of these goals is to ensure that existing C code-bases can be converted to \CFA incrementally and with minimal effort, and that programmers who know C 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).
     135These 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.
    136136
    137137\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 describes how generic and tuple types are designed and implemented in \CFA in accordance with both the backward compatibility goals and existing features described above.
     
    167167\begin{lstlisting}
    168168forall( otype T `| { int ?<?( T, T ); }` )      $\C{// type assertion}$
    169   void qsort( const T * arr, size_t dim );
     169  void qsort( const T * arr, size_t size );
    170170forall( otype T `| { int ?<?( T, T ); }` )      $\C{// type assertion}$
    171   T * bsearch( T key, const T * arr, size_t dim );
     171  T * bsearch( T key, const T * arr, size_t size );
    172172double vals[10] = { /* 10 floating-point values */ };
    173173qsort( vals, 10 );                                                      $\C{// sort array}$
     
    190190but providing a type-safe \CFA overloaded wrapper.
    191191\begin{lstlisting}
    192 forall( otype T | { int ?<?( T, T ); } ) T * bsearch( T key, const T * arr, size_t dim ) {
     192forall( otype T | { int ?<?( T, T ); } ) T * bsearch( T key, const T * arr, size_t size ) {
    193193        int comp( const void * t1, const void * t2 ) { /* as above with double changed to T */ }
    194         return (T *)bsearch( &key, arr, dim, sizeof(T), comp );
    195 }
    196 forall( otype T | { int ?<?( T, T ); } ) unsigned int bsearch( T key, const T * arr, size_t dim ) {
    197         T *result = bsearch( key, arr, dim );   $\C{// call first version}$
    198         return result ? result - arr : dim;             $\C{// pointer subtraction includes sizeof(T)}$
     194        return (T *)bsearch( &key, arr, size, sizeof(T), comp );
     195}
     196forall( otype T | { int ?<?( T, T ); } ) unsigned int bsearch( T key, const T * arr, size_t size ) {
     197        T *result = bsearch( key, arr, size );  $\C{// call first version}$
     198        return result ? result - arr : size;            $\C{// pointer subtraction includes sizeof(T)}$
    199199}
    200200double * val = bsearch( 5.0, vals, 10 );        $\C{// selection based on return type}$
     
    262262};
    263263forall( otype T | summable( T ) )
    264   T sum( T a[$\,$], size_t dim ) {
    265         T total = { 0 };                                                        $\C{// instantiate T from 0}$
    266         for ( unsigned int i = 0; i < dim; i += 1 )
     264  T sum( T a[$\,$], size_t size ) {
     265        T total = { 0 };                                                $\C{// instantiate T from 0}$
     266        for ( unsigned int i = 0; i < size; i += 1 )
    267267                total += a[i];                                          $\C{// select appropriate +}$
    268268        return total;
Note: See TracChangeset for help on using the changeset viewer.