Ignore:
Timestamp:
Nov 23, 2017, 1:31:43 PM (7 years ago)
Author:
Thierry Delisle <tdelisle@…>
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:
88ef2af
Parents:
07c1e595
Message:

Revised up to chapter three

File:
1 edited

Legend:

Unmodified
Added
Removed
  • doc/proposals/concurrency/text/cforall.tex

    r07c1e595 r9f10d1f2  
    77The following is a quick introduction to the \CFA language, specifically tailored to the features needed to support concurrency.
    88
    9 \CFA is a extension of ISO-C and therefore supports all of the same paradigms as C. It is a non-object oriented system language, meaning most of the major abstractions have either no runtime overhead or can be opt-out easily. Like C, the basics of \CFA revolve around structures and routines, which are thin abstractions over machine code. The vast majority of the code produced by the \CFA translator respects memory-layouts and calling-conventions laid out by C. Interestingly, while \CFA is not an object-oriented language, lacking the concept of a receiver (e.g., this), it does have some notion of objects\footnote{C defines the term objects as : ``region of data storage in the execution environment, the contents of which can represent
    10 values''\cite[3.15]{C11}}, most importantly construction and destruction of objects. Most of the following code examples can be found on the \CFA website \cite{www-cfa}
     9\CFA is an extension of ISO-C and therefore supports all of the same paradigms as C. It is a non-object-oriented system-language, meaning most of the major abstractions have either no runtime overhead or can be opt-out easily. Like C, the basics of \CFA revolve around structures and routines, which are thin abstractions over machine code. The vast majority of the code produced by the \CFA translator respects memory-layouts and calling-conventions laid out by C. Interestingly, while \CFA is not an object-oriented language, lacking the concept of a receiver (e.g., {\tt this}), it does have some notion of objects\footnote{C defines the term objects as : ``region of data storage in the execution environment, the contents of which can represent
     10values''~\cite[3.15]{C11}}, most importantly construction and destruction of objects. Most of the following code examples can be found on the \CFA website~\cite{www-cfa}
    1111
    1212\section{References}
     
    2121*p3   = ...;                                            //change p2
    2222int y, z, & ar[3] = {x, y, z};          //initialize array of references
    23 typeof( ar[1]) p;                                       //is int, i.e., the type of referenced object
    24 typeof(&ar[1]) q;                                       //is int &, i.e., the type of reference
    25 sizeof( ar[1]) == sizeof(int);          //is true, i.e., the size of referenced object
    26 sizeof(&ar[1]) == sizeof(int *);        //is true, i.e., the size of a reference
     23typeof( ar[1]) p;                                       //is int, referenced object type
     24typeof(&ar[1]) q;                                       //is int &, reference type
     25sizeof( ar[1]) == sizeof(int);          //is true, referenced object size
     26sizeof(&ar[1]) == sizeof(int *);        //is true, reference size
    2727\end{cfacode}
    28 The important take away from this code example is that references offer a handle to an object, much like pointers, but which is automatically dereferenced for convenience.
     28The important take away from this code example is that a reference offers a handle to an object, much like a pointer, but which is automatically dereferenced for convenience.
    2929
    3030\section{Overloading}
    3131
    32 Another important feature of \CFA is function overloading as in Java and \CC, where routines with the same name are selected based on the number and type of the arguments. As well, \CFA uses the return type as part of the selection criteria, as in Ada\cite{Ada}. For routines with multiple parameters and returns, the selection is complex.
     32Another important feature of \CFA is function overloading as in Java and \CC, where routines with the same name are selected based on the number and type of the arguments. As well, \CFA uses the return type as part of the selection criteria, as in Ada~\cite{Ada}. For routines with multiple parameters and returns, the selection is complex.
    3333\begin{cfacode}
    3434//selection based on type and number of parameters
     
    9999delete(s);                              //deallocation, call destructor
    100100\end{cfacode}
    101 Note that like \CC, \CFA introduces \code{new} and \code{delete}, which behave like \code{malloc} and \code{free} in addition to constructing and destructing objects, after calling \code{malloc} and before calling \code{free} respectively.
     101Note that like \CC, \CFA introduces \code{new} and \code{delete}, which behave like \code{malloc} and \code{free} in addition to constructing and destructing objects, after calling \code{malloc} and before calling \code{free}, respectively.
    102102
    103103\section{Parametric Polymorphism}
    104 Routines in \CFA can also be reused for multiple types. This capability is done using the \code{forall} clause which gives \CFA its name. \code{forall} clauses allow separately compiled routines to support generic usage over multiple types. For example, the following sum function works for any type that supports construction from 0 and addition :
     104Routines in \CFA can also be reused for multiple types. This capability is done using the \code{forall} clause, which gives \CFA its name. \code{forall} clauses allow separately compiled routines to support generic usage over multiple types. For example, the following sum function works for any type that supports construction from 0 and addition :
    105105\begin{cfacode}
    106106//constraint type, 0 and +
     
    135135struct S { int i, j; };
    136136int mem(S & this) with (this)           //with clause
    137         i = 1;                                          //this->i
    138         j = 2;                                          //this->j
     137        i = 1;                                                  //this->i
     138        j = 2;                                                  //this->j
    139139}
    140140int foo() {
    141141        struct S1 { ... } s1;
    142142        struct S2 { ... } s2;
    143         with (s1)                                       //with statement
     143        with (s1)                                               //with statement
    144144        {
    145                 //access fields of s1
    146                 //without qualification
     145                //access fields of s1 without qualification
    147146                with (s2)                                       //nesting
    148147                {
    149                         //access fields of s1 and s2
    150                         //without qualification
     148                        //access fields of s1 and s2 without qualification
    151149                }
    152150        }
    153         with (s1, s2)                           //scopes open in parallel
     151        with (s1, s2)                                   //scopes open in parallel
    154152        {
    155                 //access fields of s1 and s2
    156                 //without qualification
     153                //access fields of s1 and s2 without qualification
    157154        }
    158155}
    159156\end{cfacode}
    160157
     158\section{otype/dtype}
     159
    161160For more information on \CFA see \cite{cforall-ug,rob-thesis,www-cfa}.
Note: See TracChangeset for help on using the changeset viewer.