Changes in / [f522618:4eb31f2b]


Ignore:
Location:
doc
Files:
1 deleted
5 edited

Legend:

Unmodified
Added
Removed
  • doc/user/user.tex

    rf522618 r4eb31f2b  
    1111%% Created On       : Wed Apr  6 14:53:29 2016
    1212%% Last Modified By : Peter A. Buhr
    13 %% Last Modified On : Fri Jun 16 12:00:01 2017
    14 %% Update Count     : 2433
     13%% Last Modified On : Tue Jun 13 11:50:27 2017
     14%% Update Count     : 2403
    1515%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
    1616
     
    4343\usepackage[pagewise]{lineno}
    4444\renewcommand{\linenumberfont}{\scriptsize\sffamily}
    45 \input{common}                                          % common CFA document macros
     45\input{common}                                          % bespoke macros used in the document
    4646\usepackage[dvips,plainpages=false,pdfpagelabels,pdfpagemode=UseNone,colorlinks=true,pagebackref=true,linkcolor=blue,citecolor=blue,urlcolor=blue,pagebackref=true,breaklinks=true]{hyperref}
    4747\usepackage{breakurl}
     
    110110\renewcommand{\subsectionmark}[1]{\markboth{\thesubsection\quad #1}{\thesubsection\quad #1}}
    111111\pagenumbering{roman}
    112 %\linenumbers                                            % comment out to turn off line numbering
     112\linenumbers                                            % comment out to turn off line numbering
    113113
    114114\maketitle
     
    881881
    882882
     883\subsection{Address-of Semantics}
     884
     885In C, ©&E© is an rvalue for any expression ©E©.
     886\CFA extends the ©&© (address-of) operator as follows:
     887\begin{itemize}
     888\item
     889if ©R© is an \Index{rvalue} of type ©T &$_1$...&$_r$© where $r \ge 1$ references (©&© symbols) than ©&R© has type ©T ®*®&$_{\color{red}2}$...&$_{\color{red}r}$©, \ie ©T© pointer with $r-1$ references (©&© symbols).
     890
     891\item
     892if ©L© is an \Index{lvalue} of type ©T &$_1$...&$_l$© where $l \ge 0$ references (©&© symbols) then ©&L© has type ©T ®*®&$_{\color{red}1}$...&$_{\color{red}l}$©, \ie ©T© pointer with $l$ references (©&© symbols).
     893\end{itemize}
     894The following example shows the first rule applied to different \Index{rvalue} contexts:
     895\begin{cfa}
     896int x, * px, ** ppx, *** pppx, **** ppppx;
     897int & rx = x, && rrx = rx, &&& rrrx = rrx ;
     898x = rrrx;               // rrrx is an lvalue with type int &&& (equivalent to x)
     899px = &rrrx;             // starting from rrrx, &rrrx is an rvalue with type int *&&& (&x)
     900ppx = &&rrrx;   // starting from &rrrx, &&rrrx is an rvalue with type int **&& (&rx)
     901pppx = &&&rrrx; // starting from &&rrrx, &&&rrrx is an rvalue with type int ***& (&rrx)
     902ppppx = &&&&rrrx; // starting from &&&rrrx, &&&&rrrx is an rvalue with type int **** (&rrrx)
     903\end{cfa}
     904The following example shows the second rule applied to different \Index{lvalue} contexts:
     905\begin{cfa}
     906int x, * px, ** ppx, *** pppx;
     907int & rx = x, && rrx = rx, &&& rrrx = rrx ;
     908rrrx = 2;               // rrrx is an lvalue with type int &&& (equivalent to x)
     909&rrrx = px;             // starting from rrrx, &rrrx is an rvalue with type int *&&& (rx)
     910&&rrrx = ppx;   // starting from &rrrx, &&rrrx is an rvalue with type int **&& (rrx)
     911&&&rrrx = pppx; // starting from &&rrrx, &&&rrrx is an rvalue with type int ***& (rrrx)
     912\end{cfa}
     913
     914
     915\subsection{Conversions}
     916
     917C provides a basic implicit conversion to simplify variable usage:
     918\begin{enumerate}
     919\setcounter{enumi}{-1}
     920\item
     921lvalue to rvalue conversion: ©cv T© converts to ©T©, which allows implicit variable dereferencing.
     922\begin{cfa}
     923int x;
     924x + 1;                  // lvalue variable (int) converts to rvalue for expression
     925\end{cfa}
     926An rvalue has no type qualifiers (©cv©), so the lvalue qualifiers are dropped.
     927\end{enumerate}
     928\CFA provides three new implicit conversion for reference types to simplify reference usage.
     929\begin{enumerate}
     930\item
     931reference to rvalue conversion: ©cv T &© converts to ©T©, which allows implicit reference dereferencing.
     932\begin{cfa}
     933int x, &r = x, f( int p );
     934x = ®r® + f( ®r® );  // lvalue reference converts to rvalue
     935\end{cfa}
     936An rvalue has no type qualifiers (©cv©), so the reference qualifiers are dropped.
     937
     938\item
     939lvalue to reference conversion: \lstinline[deletekeywords={lvalue}]@lvalue-type cv1 T@ converts to ©cv2 T &©, which allows implicitly converting variables to references.
     940\begin{cfa}
     941int x, &r = ®x®, f( int & p ); // lvalue variable (int) convert to reference (int &)
     942f( ®x® );               // lvalue variable (int) convert to reference (int &)
     943\end{cfa}
     944Conversion can restrict a type, where ©cv1© $\le$ ©cv2©, \eg passing an ©int© to a ©const volatile int &©, which has low cost.
     945Conversion can expand a type, where ©cv1© $>$ ©cv2©, \eg passing a ©const volatile int© to an ©int &©, which has high cost (\Index{warning});
     946furthermore, if ©cv1© has ©const© but not ©cv2©, a temporary variable is created to preserve the immutable lvalue.
     947
     948\item
     949rvalue to reference conversion: ©T© converts to ©cv T &©, which allows binding references to temporaries.
     950\begin{cfa}
     951int x, & f( int & p );
     952f( ®x + 3® );   // rvalue parameter (int) implicitly converts to lvalue temporary reference (int &)
     953®&f®(...) = &x; // rvalue result (int &) implicitly converts to lvalue temporary reference (int &)
     954\end{cfa}
     955In both case, modifications to the temporary are inaccessible (\Index{warning}).
     956Conversion expands the temporary-type with ©cv©, which is low cost since the temporary is inaccessible.
     957\end{enumerate}
     958
     959
    883960\subsection{Initialization}
    884961
     
    9611038
    9621039
    963 \subsection{Address-of Semantics}
    964 
    965 In C, ©&E© is an rvalue for any expression ©E©.
    966 \CFA extends the ©&© (address-of) operator as follows:
    967 \begin{itemize}
    968 \item
    969 if ©R© is an \Index{rvalue} of type ©T &$_1$...&$_r$© where $r \ge 1$ references (©&© symbols) than ©&R© has type ©T ®*®&$_{\color{red}2}$...&$_{\color{red}r}$©, \ie ©T© pointer with $r-1$ references (©&© symbols).
    970 
    971 \item
    972 if ©L© is an \Index{lvalue} of type ©T &$_1$...&$_l$© where $l \ge 0$ references (©&© symbols) then ©&L© has type ©T ®*®&$_{\color{red}1}$...&$_{\color{red}l}$©, \ie ©T© pointer with $l$ references (©&© symbols).
    973 \end{itemize}
    974 The following example shows the first rule applied to different \Index{rvalue} contexts:
    975 \begin{cfa}
    976 int x, * px, ** ppx, *** pppx, **** ppppx;
    977 int & rx = x, && rrx = rx, &&& rrrx = rrx ;
    978 x = rrrx;               // rrrx is an lvalue with type int &&& (equivalent to x)
    979 px = &rrrx;             // starting from rrrx, &rrrx is an rvalue with type int *&&& (&x)
    980 ppx = &&rrrx;   // starting from &rrrx, &&rrrx is an rvalue with type int **&& (&rx)
    981 pppx = &&&rrrx; // starting from &&rrrx, &&&rrrx is an rvalue with type int ***& (&rrx)
    982 ppppx = &&&&rrrx; // starting from &&&rrrx, &&&&rrrx is an rvalue with type int **** (&rrrx)
    983 \end{cfa}
    984 The following example shows the second rule applied to different \Index{lvalue} contexts:
    985 \begin{cfa}
    986 int x, * px, ** ppx, *** pppx;
    987 int & rx = x, && rrx = rx, &&& rrrx = rrx ;
    988 rrrx = 2;               // rrrx is an lvalue with type int &&& (equivalent to x)
    989 &rrrx = px;             // starting from rrrx, &rrrx is an rvalue with type int *&&& (rx)
    990 &&rrrx = ppx;   // starting from &rrrx, &&rrrx is an rvalue with type int **&& (rrx)
    991 &&&rrrx = pppx; // starting from &&rrrx, &&&rrrx is an rvalue with type int ***& (rrrx)
    992 \end{cfa}
    993 
    994 
    995 \subsection{Conversions}
    996 
    997 C provides a basic implicit conversion to simplify variable usage:
    998 \begin{enumerate}
    999 \setcounter{enumi}{-1}
    1000 \item
    1001 lvalue to rvalue conversion: ©cv T© converts to ©T©, which allows implicit variable dereferencing.
    1002 \begin{cfa}
    1003 int x;
    1004 x + 1;                  // lvalue variable (int) converts to rvalue for expression
    1005 \end{cfa}
    1006 An rvalue has no type qualifiers (©cv©), so the lvalue qualifiers are dropped.
    1007 \end{enumerate}
    1008 \CFA provides three new implicit conversion for reference types to simplify reference usage.
    1009 \begin{enumerate}
    1010 \item
    1011 reference to rvalue conversion: ©cv T &© converts to ©T©, which allows implicit reference dereferencing.
    1012 \begin{cfa}
    1013 int x, &r = x, f( int p );
    1014 x = ®r® + f( ®r® );  // lvalue reference converts to rvalue
    1015 \end{cfa}
    1016 An rvalue has no type qualifiers (©cv©), so the reference qualifiers are dropped.
    1017 
    1018 \item
    1019 lvalue to reference conversion: \lstinline[deletekeywords={lvalue}]@lvalue-type cv1 T@ converts to ©cv2 T &©, which allows implicitly converting variables to references.
    1020 \begin{cfa}
    1021 int x, &r = ®x®, f( int & p ); // lvalue variable (int) convert to reference (int &)
    1022 f( ®x® );               // lvalue variable (int) convert to reference (int &)
    1023 \end{cfa}
    1024 Conversion can restrict a type, where ©cv1© $\le$ ©cv2©, \eg passing an ©int© to a ©const volatile int &©, which has low cost.
    1025 Conversion can expand a type, where ©cv1© $>$ ©cv2©, \eg passing a ©const volatile int© to an ©int &©, which has high cost (\Index{warning});
    1026 furthermore, if ©cv1© has ©const© but not ©cv2©, a temporary variable is created to preserve the immutable lvalue.
    1027 
    1028 \item
    1029 rvalue to reference conversion: ©T© converts to ©cv T &©, which allows binding references to temporaries.
    1030 \begin{cfa}
    1031 int x, & f( int & p );
    1032 f( ®x + 3® );   // rvalue parameter (int) implicitly converts to lvalue temporary reference (int &)
    1033 ®&f®(...) = &x; // rvalue result (int &) implicitly converts to lvalue temporary reference (int &)
    1034 \end{cfa}
    1035 In both case, modifications to the temporary are inaccessible (\Index{warning}).
    1036 Conversion expands the temporary-type with ©cv©, which is low cost since the temporary is inaccessible.
    1037 \end{enumerate}
    1038 
    10391040
    10401041\begin{comment}
     1042\section{References}
     1043
     1044By introducing references in parameter types, users are given an easy way to pass a value by reference, without the need for NULL pointer checks.
     1045In structures, a reference can replace a pointer to an object that should always have a valid value.
     1046When a structure contains a reference, all of its constructors must initialize the reference and all instances of this structure must initialize it upon definition.
     1047
     1048The syntax for using references in \CFA is the same as \CC with the exception of reference initialization.
     1049Use ©&© to specify a reference, and access references just like regular objects, not like pointers (use dot notation to access fields).
     1050When initializing a reference, \CFA uses a different syntax which differentiates reference initialization from assignment to a reference.
     1051The ©&© is used on both sides of the expression to clarify that the address of the reference is being set to the address of the variable to which it refers.
     1052
     1053
    10411054From: Richard Bilson <rcbilson@gmail.com>
    10421055Date: Wed, 13 Jul 2016 01:58:58 +0000
     
    12001213\section{Routine Definition}
    12011214
    1202 \CFA also supports a new syntax for routine definition, as well as \Celeven and K\&R routine syntax.
     1215\CFA also supports a new syntax for routine definition, as well as ISO C and K\&R routine syntax.
    12031216The point of the new syntax is to allow returning multiple values from a routine~\cite{Galletly96,CLU}, \eg:
    12041217\begin{cfa}
     
    12201233in both cases the type is assumed to be void as opposed to old style C defaults of int return type and unknown parameter types, respectively, as in:
    12211234\begin{cfa}
    1222 [§\,§] g();                                                     §\C{// no input or output parameters}§
    1223 [ void ] g( void );                                     §\C{// no input or output parameters}§
     1235[§\,§] g();                                             §\C{// no input or output parameters}§
     1236[ void ] g( void );                             §\C{// no input or output parameters}§
    12241237\end{cfa}
    12251238
     
    12391252\begin{cfa}
    12401253typedef int foo;
    1241 int f( int (* foo) );                           §\C{// foo is redefined as a parameter name}§
     1254int f( int (* foo) );                   §\C{// foo is redefined as a parameter name}§
    12421255\end{cfa}
    12431256The string ``©int (* foo)©'' declares a C-style named-parameter of type pointer to an integer (the parenthesis are superfluous), while the same string declares a \CFA style unnamed parameter of type routine returning integer with unnamed parameter of type pointer to foo.
     
    12471260C-style declarations can be used to declare parameters for \CFA style routine definitions, \eg:
    12481261\begin{cfa}
    1249 [ int ] f( * int, int * );                      §\C{// returns an integer, accepts 2 pointers to integers}§
    1250 [ * int, int * ] f( int );                      §\C{// returns 2 pointers to integers, accepts an integer}§
     1262[ int ] f( * int, int * );              §\C{// returns an integer, accepts 2 pointers to integers}§
     1263[ * int, int * ] f( int );              §\C{// returns 2 pointers to integers, accepts an integer}§
    12511264\end{cfa}
    12521265The reason for allowing both declaration styles in the new context is for backwards compatibility with existing preprocessor macros that generate C-style declaration-syntax, as in:
    12531266\begin{cfa}
    12541267#define ptoa( n, d ) int (*n)[ d ]
    1255 int f( ptoa( p, 5 ) ) ...                       §\C{// expands to int f( int (*p)[ 5 ] )}§
    1256 [ int ] f( ptoa( p, 5 ) ) ...           §\C{// expands to [ int ] f( int (*p)[ 5 ] )}§
     1268int f( ptoa( p, 5 ) ) ...               §\C{// expands to int f( int (*p)[ 5 ] )}§
     1269[ int ] f( ptoa( p, 5 ) ) ...   §\C{// expands to [ int ] f( int (*p)[ 5 ] )}§
    12571270\end{cfa}
    12581271Again, programmers are highly encouraged to use one declaration form or the other, rather than mixing the forms.
     
    12761289        int z;
    12771290        ... x = 0; ... y = z; ...
    1278         ®return;®                                                       §\C{// implicitly return x, y}§
     1291        ®return;® §\C{// implicitly return x, y}§
    12791292}
    12801293\end{cfa}
     
    12861299[ int x, int y ] f() {
    12871300        ...
    1288 }                                                                               §\C{// implicitly return x, y}§
     1301} §\C{// implicitly return x, y}§
    12891302\end{cfa}
    12901303In this case, the current values of ©x© and ©y© are returned to the calling routine just as if a ©return© had been encountered.
    1291 
    1292 Named return values may be used in conjunction with named parameter values;
    1293 specifically, a return and parameter can have the same name.
    1294 \begin{cfa}
    1295 [ int x, int y ] f( int, x, int y ) {
    1296         ...
    1297 }                                                                               §\C{// implicitly return x, y}§
    1298 \end{cfa}
    1299 This notation allows the compiler to eliminate temporary variables in nested routine calls.
    1300 \begin{cfa}
    1301 [ int x, int y ] f( int, x, int y );    §\C{// prototype declaration}§
    1302 int a, b;
    1303 [a, b] = f( f( f( a, b ) ) );
    1304 \end{cfa}
    1305 While the compiler normally ignores parameters names in prototype declarations, here they are used to eliminate temporary return-values by inferring that the results of each call are the inputs of the next call, and ultimately, the left-hand side of the assignment.
    1306 Hence, even without the body of routine ©f© (separate compilation), it is possible to perform a global optimization across routine calls.
    1307 The compiler warns about naming inconsistencies between routine prototype and definition in this case, and behaviour is \Index{undefined} if the programmer is inconsistent.
    13081304
    13091305
     
    13131309as well, parameter names are optional, \eg:
    13141310\begin{cfa}
    1315 [ int x ] f ();                                                 §\C{// returning int with no parameters}§
    1316 [ * int ] g (int y);                                    §\C{// returning pointer to int with int parameter}§
    1317 [ ] h ( int, char );                                    §\C{// returning no result with int and char parameters}§
    1318 [ * int, int ] j ( int );                               §\C{// returning pointer to int and int, with int parameter}§
     1311[ int x ] f ();                                 §\C{// returning int with no parameters}§
     1312[ * int ] g (int y);                    §\C{// returning pointer to int with int parameter}§
     1313[ ] h (int,char);                               §\C{// returning no result with int and char parameters}§
     1314[ * int,int ] j (int);                  §\C{// returning pointer to int and int, with int parameter}§
    13191315\end{cfa}
    13201316This syntax allows a prototype declaration to be created by cutting and pasting source text from the routine definition header (or vice versa).
     
    13241320\multicolumn{1}{c@{\hspace{3em}}}{\textbf{\CFA}}        & \multicolumn{1}{c}{\textbf{C}}        \\
    13251321\begin{cfa}
    1326 [ int ] f( int ), g;
     1322[ int ] f(int), g;
    13271323\end{cfa}
    13281324&
    13291325\begin{cfa}
    1330 int f( int ), g( int );
     1326int f(int), g(int);
    13311327\end{cfa}
    13321328\end{tabular}
     
    13341330Declaration qualifiers can only appear at the start of a \CFA routine declaration,\footref{StorageClassSpecifier} \eg:
    13351331\begin{cfa}
    1336 extern [ int ] f ( int );
    1337 static [ int ] g ( int );
     1332extern [ int ] f (int);
     1333static [ int ] g (int);
    13381334\end{cfa}
    13391335
     
    13431339The syntax for pointers to \CFA routines specifies the pointer name on the right, \eg:
    13441340\begin{cfa}
    1345 * [ int x ] () fp;                                              §\C{// pointer to routine returning int with no parameters}§
    1346 * [ * int ] (int y) gp;                                 §\C{// pointer to routine returning pointer to int with int parameter}§
    1347 * [ ] (int,char) hp;                                    §\C{// pointer to routine returning no result with int and char parameters}§
    1348 * [ * int,int ] ( int ) jp;                             §\C{// pointer to routine returning pointer to int and int, with int parameter}§
     1341* [ int x ] () fp;                      §\C{// pointer to routine returning int with no parameters}§
     1342* [ * int ] (int y) gp;         §\C{// pointer to routine returning pointer to int with int parameter}§
     1343* [ ] (int,char) hp;            §\C{// pointer to routine returning no result with int and char parameters}§
     1344* [ * int,int ] (int) jp;       §\C{// pointer to routine returning pointer to int and int, with int parameter}§
    13491345\end{cfa}
    13501346While parameter names are optional, \emph{a routine name cannot be specified};
    13511347for example, the following is incorrect:
    13521348\begin{cfa}
    1353 * [ int x ] f () fp;                                    §\C{// routine name "f" is not allowed}§
     1349* [ int x ] f () fp;            §\C{// routine name "f" is not allowed}§
    13541350\end{cfa}
    13551351
     
    15381534        int ;                                   §\C{// disallowed, unnamed field}§
    15391535        int *;                                  §\C{// disallowed, unnamed field}§
    1540         int (*)( int );                 §\C{// disallowed, unnamed field}§
     1536        int (*)(int);                   §\C{// disallowed, unnamed field}§
    15411537};
    15421538\end{cfa}
     
    16611657}
    16621658int main() {
    1663         * [int]( int ) fp = foo();      §\C{// int (*fp)( int )}§
     1659        * [int](int) fp = foo();        §\C{// int (*fp)(int)}§
    16641660        sout | fp( 3 ) | endl;
    16651661}
     
    27822778
    27832779
    2784 \section{Constructors and Destructors}
     2780\subsection{Constructors and Destructors}
    27852781
    27862782\CFA supports C initialization of structures, but it also adds constructors for more advanced initialization.
     
    31133109
    31143110
    3115 \begin{comment}
    31163111\section{Generics}
    31173112
     
    33203315        }
    33213316\end{cfa}
    3322 \end{comment}
    33233317
    33243318
     
    33803374        Complex *p3 = new(0.5, 1.0); // allocate + 2 param constructor
    33813375}
     3376
    33823377\end{cfa}
    33833378
     
    33913386
    33923387
    3393 \begin{comment}
    33943388\subsection{Unsafe C Constructs}
    33953389
     
    34023396The exact set of unsafe C constructs that will be disallowed in \CFA has not yet been decided, but is sure to include pointer arithmetic, pointer casting, etc.
    34033397Once the full set is decided, the rules will be listed here.
    3404 \end{comment}
    34053398
    34063399
    34073400\section{Concurrency}
     3401
     3402Today's processors for nearly all use cases, ranging from embedded systems to large cloud computing servers, are composed of multiple cores, often heterogeneous.
     3403As machines grow in complexity, it becomes more difficult for a program to make the most use of the hardware available.
     3404\CFA includes built-in concurrency features to enable high performance and improve programmer productivity on these multi-/many-core machines.
    34083405
    34093406Concurrency support in \CFA is implemented on top of a highly efficient runtime system of light-weight, M:N, user level threads.
     
    34123409This enables a very familiar interface to all programmers, even those with no parallel programming experience.
    34133410It also allows the compiler to do static type checking of all communication, a very important safety feature.
    3414 This controlled communication with type safety has some similarities with channels in \Index*{Go}, and can actually implement channels exactly, as well as create additional communication patterns that channels cannot.
     3411This controlled communication with type safety has some similarities with channels in \Index*{Go}, and can actually implement
     3412channels exactly, as well as create additional communication patterns that channels cannot.
    34153413Mutex objects, monitors, are used to contain mutual exclusion within an object and synchronization across concurrent threads.
    34163414
    3417 \begin{figure}
    3418 \begin{cfa}
    3419 #include <fstream>
    3420 #include <coroutine>
    3421 
    3422 coroutine Fibonacci {
    3423         int fn;                                                         §\C{// used for communication}§
    3424 };
    3425 void ?{}( Fibonacci * this ) {
    3426         this->fn = 0;
    3427 }
    3428 void main( Fibonacci * this ) {
    3429         int fn1, fn2;                                           §\C{// retained between resumes}§
    3430         this->fn = 0;                                           §\C{// case 0}§
    3431         fn1 = this->fn;
    3432         suspend();                                                      §\C{// return to last resume}§
    3433 
    3434         this->fn = 1;                                           §\C{// case 1}§
    3435         fn2 = fn1;
    3436         fn1 = this->fn;
    3437         suspend();                                                      §\C{// return to last resume}§
    3438 
    3439         for ( ;; ) {                                            §\C{// general case}§
    3440                 this->fn = fn1 + fn2;
    3441                 fn2 = fn1;
    3442                 fn1 = this->fn;
    3443                 suspend();                                              §\C{// return to last resume}§
    3444         } // for
    3445 }
    3446 int next( Fibonacci * this ) {
    3447         resume( this );                                         §\C{// transfer to last suspend}§
    3448         return this->fn;
    3449 }
    3450 int main() {
    3451         Fibonacci f1, f2;
    3452         for ( int i = 1; i <= 10; i += 1 ) {
    3453                 sout | next( &f1 ) | ' ' | next( &f2 ) | endl;
    3454         } // for
    3455 }
    3456 \end{cfa}
    3457 \caption{Fibonacci Coroutine}
    3458 \label{f:FibonacciCoroutine}
    3459 \end{figure}
    3460 
    3461 
    3462 \subsection{Coroutine}
    3463 
    3464 \Index{Coroutines} are the precursor to tasks.
    3465 \VRef[Figure]{f:FibonacciCoroutine} shows a coroutine that computes the \Index*{Fibonacci} numbers.
     3415Three new keywords are added to support these features:
     3416
     3417monitor creates a structure with implicit locking when accessing fields
     3418
     3419mutex implies use of a monitor requiring the implicit locking
     3420
     3421task creates a type with implicit locking, separate stack, and a thread
    34663422
    34673423
     
    34783434\end{cfa}
    34793435
    3480 \begin{figure}
    3481 \begin{cfa}
    3482 #include <fstream>
    3483 #include <kernel>
    3484 #include <monitor>
    3485 #include <thread>
    3486 
    3487 monitor global_t {
    3488         int value;
    3489 };
    3490 
    3491 void ?{}(global_t * this) {
    3492         this->value = 0;
    3493 }
    3494 
    3495 static global_t global;
    3496 
    3497 void increment3( global_t * mutex this ) {
    3498         this->value += 1;
    3499 }
    3500 void increment2( global_t * mutex this ) {
    3501         increment3( this );
    3502 }
    3503 void increment( global_t * mutex this ) {
    3504         increment2( this );
    3505 }
    3506 
    3507 thread MyThread {};
    3508 
    3509 void main( MyThread* this ) {
    3510         for(int i = 0; i < 1_000_000; i++) {
    3511                 increment( &global );
    3512         }
    3513 }
    3514 int main(int argc, char* argv[]) {
    3515         processor p;
    3516         {
    3517                 MyThread f[4];
    3518         }
    3519         sout | global.value | endl;
    3520 }
    3521 \end{cfa}
    3522 \caption{Atomic-Counter Monitor}
    3523 \caption{f:AtomicCounterMonitor}
    3524 \end{figure}
    3525 
    3526 \begin{comment}
    35273436Since a monitor structure includes an implicit locking mechanism, it does not make sense to copy a monitor;
    35283437it is always passed by reference.
     
    35713480}
    35723481\end{cfa}
    3573 \end{comment}
    35743482
    35753483
     
    35793487A task provides mutual exclusion like a monitor, and also has its own execution state and a thread of control.
    35803488Similar to a monitor, a task is defined like a structure:
    3581 
    3582 \begin{figure}
    3583 \begin{cfa}
    3584 #include <fstream>
    3585 #include <kernel>
    3586 #include <stdlib>
    3587 #include <thread>
    3588 
    3589 thread First  { signal_once * lock; };
    3590 thread Second { signal_once * lock; };
    3591 
    3592 void ?{}( First * this, signal_once* lock ) { this->lock = lock; }
    3593 void ?{}( Second * this, signal_once* lock ) { this->lock = lock; }
    3594 
    3595 void main( First * this ) {
    3596         for ( int i = 0; i < 10; i += 1 ) {
    3597                 sout | "First : Suspend No." | i + 1 | endl;
    3598                 yield();
    3599         }
    3600         signal( this->lock );
    3601 }
    3602 
    3603 void main( Second * this ) {
    3604         wait( this->lock );
    3605         for ( int i = 0; i < 10; i += 1 ) {
    3606                 sout | "Second : Suspend No." | i + 1 | endl;
    3607                 yield();
    3608         }
    3609 }
    3610 
    3611 int main( void ) {
    3612         signal_once lock;
    3613         sout | "User main begin" | endl;
    3614         {
    3615                 processor p;
    3616                 {
    3617                         First  f = { &lock };
    3618                         Second s = { &lock };
    3619                 }
    3620         }
    3621         sout | "User main end" | endl;
    3622 }
    3623 \end{cfa}
    3624 \caption{Simple Tasks}
    3625 \label{f:SimpleTasks}
    3626 \end{figure}
    3627 
    3628 
    3629 \begin{comment}
    36303489\begin{cfa}
    36313490type Adder = task {
     
    36813540\end{cfa}
    36823541
     3542
    36833543\subsection{Cooperative Scheduling}
    36843544
     
    37933653}
    37943654\end{cfa}
    3795 \end{comment}
    3796 
     3655
     3656
     3657\section{Modules and Packages }
    37973658
    37983659\begin{comment}
    3799 \section{Modules and Packages }
    3800 
    38013660High-level encapsulation is useful for organizing code into reusable units, and accelerating compilation speed.
    38023661\CFA provides a convenient mechanism for creating, building and sharing groups of functionality that enhances productivity and improves compile time.
     
    44624321
    44634322
    4464 \begin{comment}
    44654323\subsection[Comparing Key Features of CFA]{Comparing Key Features of \CFA}
    44664324
     
    48404698
    48414699
     4700\begin{comment}
    48424701\subsubsection{Modules / Packages}
    48434702
     
    49194778}
    49204779\end{cfa}
     4780\end{comment}
    49214781
    49224782
     
    50794939
    50804940\subsection{Summary of Language Comparison}
    5081 \end{comment}
    5082 
    5083 
    5084 \subsection[C++]{\CC}
     4941
     4942
     4943\subsubsection[C++]{\CC}
    50854944
    50864945\Index*[C++]{\CC{}} is a general-purpose programming language.
     
    51034962
    51044963
    5105 \subsection{Go}
     4964\subsubsection{Go}
    51064965
    51074966\Index*{Go}, also commonly referred to as golang, is a programming language developed at Google in 2007 [.].
     
    51194978
    51204979
    5121 \subsection{Rust}
     4980\subsubsection{Rust}
    51224981
    51234982\Index*{Rust} is a general-purpose, multi-paradigm, compiled programming language developed by Mozilla Research.
     
    51334992
    51344993
    5135 \subsection{D}
     4994\subsubsection{D}
    51364995
    51374996The \Index*{D} programming language is an object-oriented, imperative, multi-paradigm system programming
     
    52455104\item[Rationale:] keywords added to implement new semantics of \CFA.
    52465105\item[Effect on original feature:] change to semantics of well-defined feature. \\
    5247 Any \Celeven programs using these keywords as identifiers are invalid \CFA programs.
     5106Any ISO C programs using these keywords as identifiers are invalid \CFA programs.
    52485107\item[Difficulty of converting:] keyword clashes are accommodated by syntactic transformations using the \CFA backquote escape-mechanism (see~\VRef{s:BackquoteIdentifiers}).
    52495108\item[How widely used:] clashes among new \CFA keywords and existing identifiers are rare.
  • doc/working/exception/impl/exception.c

    rf522618 r4eb31f2b  
    7373}
    7474
     75// Example throw routine
    7576void __throw_terminate( int val ) {
    7677        // Store the current exception
     
    106107        printf("UNWIND ERROR %d after raise exception\n", ret);
    107108        abort();
    108 }
    109 
    110 // Nesting this the other way would probably be faster.
    111 void __rethrow_terminate(void) {
    112         // DEBUG
    113         printf("Rethrowing termination exception\n");
    114 
    115         __throw_terminate(shared_stack.current_exception);
    116109}
    117110
  • doc/working/exception/impl/exception.h

    rf522618 r4eb31f2b  
    88// These might be given simpler names and made public.
    99void __throw_terminate(exception except) __attribute__((noreturn));
    10 void __rethrow_terminate(void) __attribute__((noreturn));
    1110void __throw_resume(exception except);
    1211
     
    2322
    2423
    25 
    26 /* The following code is temperary. How exceptions interact with coroutines
    27  * and threads means that... well I'm going to get it working ignoring those
    28  * first, then get it working with concurrency.
    29  */
     24// When I have it working in a single threaded environment.
    3025struct shared_stack_t {
    3126        //struct lock lock;
  • doc/working/exception/impl/test-main.c

    rf522618 r4eb31f2b  
    289289// Terminate Rethrow:
    290290// I don't have an implementation for this.
    291 void reterminate() {
    292         {
    293                 void fn_try1() {
    294                         void fn_try2() {
    295                                 terminate(1);
    296                         }
    297                         void fn_catch2(int index, exception except) {
    298                                 switch (index) {
    299                                 case 1:
    300                                         printf("reterminate 2 caught and "
    301                                                "will rethrow exception 1\n");
    302                                         __rethrow_terminate();
    303                                         break;
    304                                 default:
    305                                         printf("INVALID INDEX in reterminate 2: %d (%d)\n",
    306                                                 index, except);
    307                                 }
    308                         }
    309                         int fn_match2(exception except) {
    310                                 if (1 == except) {
    311                                         return 1;
    312                                 } else {
    313                                         return 0;
    314                                 }
    315                         }
    316                         __try_terminate(fn_try2, fn_catch2, fn_match2);
    317                 }
    318                 void fn_catch1(int index, exception except) {
    319                         switch (index) {
    320                         case 1:
    321                                 printf("reterminate 1 caught exception 1\n");
    322                                 break;
    323                         default:
    324                                 printf("INVALID INDEX in reterminate 1: %d (%d)\n",
    325                                         index, except);
    326                         }
    327                 }
    328                 int fn_match1(exception except) {
    329                         if (1 == except) {
    330                                 return 1;
    331                         } else {
    332                                 return 0;
    333                         }
    334                 }
    335                 __try_terminate(fn_try1, fn_catch1, fn_match1);
    336         }
    337 }
    338291
    339292// Resume Rethrow:
     
    475428        terminate_swapped(); printf("\n");
    476429        resume_swapped(); printf("\n");
    477         reterminate(); printf("\n");
    478430        reresume(); printf("\n");
    479431        fee(); printf("\n");
  • doc/working/exception/translate.c

    rf522618 r4eb31f2b  
    5454
    5555__throw_resume(exception_instance);
    56 
    57 
    58 
    59 // Rethrows (inside matching handlers):
    60 "Cforall"
    61 
    62 throw;
    63 
    64 resume;
    65 
    66 "C"
    67 
    68 __rethrow_terminate();
    69 
    70 return false;
    7156
    7257
Note: See TracChangeset for help on using the changeset viewer.