Ignore:
Timestamp:
Sep 9, 2021, 3:56:32 PM (4 years ago)
Author:
Thierry Delisle <tdelisle@…>
Branches:
ADT, ast-experimental, enum, forall-pointer-decay, master, pthread-emulation, qualifiedEnum
Children:
d0b9247
Parents:
dd1cc02 (diff), d8d512e (diff)
Note: this is a merge changeset, the changes displayed below correspond to the merge itself.
Use the (diff) links above to see all the changes relative to each parent.
Message:

Merge branch 'master' of plg.uwaterloo.ca:software/cfa/cfa-cc

File:
1 edited

Legend:

Unmodified
Added
Removed
  • doc/theses/andrew_beach_MMath/existing.tex

    rdd1cc02 r5a40e4e  
    1010
    1111Only those \CFA features pertaining to this thesis are discussed.
    12 % Also, only new features of \CFA will be discussed,
    1312A familiarity with
    1413C or C-like languages is assumed.
     
    1716\CFA has extensive overloading, allowing multiple definitions of the same name
    1817to be defined~\cite{Moss18}.
    19 \begin{lstlisting}[language=CFA,{moredelim=**[is][\color{red}]{@}{@}}]
    20 char @i@; int @i@; double @i@;
    21 int @f@(); double @f@();
    22 void @g@( int ); void @g@( double );
    23 \end{lstlisting}
     18\begin{cfa}
     19char i; int i; double i;
     20int f(); double f();
     21void g( int ); void g( double );
     22\end{cfa}
    2423This feature requires name mangling so the assembly symbols are unique for
    2524different overloads. For compatibility with names in C, there is also a syntax
     
    6362int && rri = ri;
    6463rri = 3;
    65 &ri = &j; // rebindable
     64&ri = &j;
    6665ri = 5;
    6766\end{cfa}
     
    7978\end{minipage}
    8079
    81 References are intended for pointer situations where dereferencing is the common usage,
    82 \ie the value is more important than the pointer.
     80References are intended to be used when the indirection of a pointer is
     81required, but the address is not as important as the value and dereferencing
     82is the common usage.
    8383Mutable references may be assigned to by converting them to a pointer
    84 with a @&@ and then assigning a pointer to them, as in @&ri = &j;@ above
     84with a @&@ and then assigning a pointer to them, as in @&ri = &j;@ above.
     85% ???
    8586
    8687\section{Operators}
    8788
    8889\CFA implements operator overloading by providing special names, where
    89 operator usages are translated into function calls using these names.
     90operator expressions are translated into function calls using these names.
    9091An operator name is created by taking the operator symbols and joining them with
    9192@?@s to show where the arguments go.
     
    9495This syntax make it easy to tell the difference between prefix operations
    9596(such as @++?@) and post-fix operations (@?++@).
    96 For example, plus and equality operators are defined for a point type.
     97
     98As an example, here are the addition and equality operators for a point type.
    9799\begin{cfa}
    98100point ?+?(point a, point b) { return point{a.x + b.x, a.y + b.y}; }
     
    102104}
    103105\end{cfa}
    104 Note these special names are not limited to builtin
    105 operators, and hence, may be used with arbitrary types.
    106 \begin{cfa}
    107 double ?+?( int x, point y ); // arbitrary types
    108 \end{cfa}
    109 % Some ``near misses", that are that do not match an operator form but looks like
    110 % it may have been supposed to, will generate warning but otherwise they are
    111 % left alone.
    112 Because operators are never part of the type definition they may be added
    113 at any time, including on built-in types.
     106Note that this syntax works effectively but a textual transformation,
     107the compiler converts all operators into functions and then resolves them
     108normally. This means any combination of types may be used,
     109although nonsensical ones (like @double ?==?(point, int);@) are discouraged.
     110This feature is also used for all builtin operators as well,
     111although those are implicitly provided by the language.
    114112
    115113%\subsection{Constructors and Destructors}
    116 
    117 \CFA also provides constructors and destructors as operators, which means they
    118 are functions with special operator names rather than type names in \Cpp.
    119 While constructors and destructions are normally called implicitly by the compiler,
    120 the special operator names, allow explicit calls.
    121 
    122 % Placement new means that this is actually equivalent to C++.
     114In \CFA, constructors and destructors are operators, which means they are
     115functions with special operator names rather than type names in \Cpp.
     116Both constructors and destructors can be implicity called by the compiler,
     117however the operator names allow explicit calls.
     118% Placement new means that this is actually equivant to C++.
    123119
    124120The special name for a constructor is @?{}@, which comes from the
     
    129125struct Example { ... };
    130126void ?{}(Example & this) { ... }
     127{
     128        Example a;
     129        Example b = {};
     130}
    131131void ?{}(Example & this, char first, int num) { ... }
    132 Example a;              // implicit constructor calls
    133 Example b = {};
    134 Example c = {'a', 2};
    135 \end{cfa}
    136 Both @a@ and @b@ are initialized with the first constructor,
    137 while @c@ is initialized with the second.
    138 Constructor calls can be replaced with C initialization using special operator \lstinline{@=}.
    139 \begin{cfa}
    140 Example d @= {42};
    141 \end{cfa}
     132{
     133        Example c = {'a', 2};
     134}
     135\end{cfa}
     136Both @a@ and @b@ will be initalized with the first constructor,
     137@b@ because of the explicit call and @a@ implicitly.
     138@c@ will be initalized with the second constructor.
     139Currently, there is no general way to skip initialation.
     140% I don't use @= anywhere in the thesis.
     141
    142142% I don't like the \^{} symbol but $^\wedge$ isn't better.
    143143Similarly, destructors use the special name @^?{}@ (the @^@ has no special
    144144meaning).
    145 % These are a normally called implicitly called on a variable when it goes out
    146 % of scope. They can be called explicitly as well.
    147145\begin{cfa}
    148146void ^?{}(Example & this) { ... }
    149147{
    150         Example e;      // implicit constructor call
    151         ^?{}(e);                // explicit destructor call
    152         ?{}(e);         // explicit constructor call
    153 } // implicit destructor call
     148        Example d;
     149        ^?{}(d);
     150
     151        Example e;
     152} // Implicit call of ^?{}(e);
    154153\end{cfa}
    155154
     
    225224The global definition of @do_once@ is ignored, however if quadruple took a
    226225@double@ argument, then the global definition would be used instead as it
    227 is a better match.
    228 % Aaron's thesis might be a good reference here.
    229 
    230 To avoid typing long lists of assertions, constraints can be collect into
    231 convenient package called a @trait@, which can then be used in an assertion
     226would then be a better match.\cite{Moss19}
     227
     228To avoid typing long lists of assertions, constraints can be collected into
     229convenient a package called a @trait@, which can then be used in an assertion
    232230instead of the individual constraints.
    233231\begin{cfa}
     
    253251        node(T) * next;
    254252        T * data;
    255 }
     253};
    256254node(int) inode;
    257255\end{cfa}
     
    293291};
    294292CountUp countup;
    295 for (10) sout | resume(countup).next; // print 10 values
    296293\end{cfa}
    297294Each coroutine has a @main@ function, which takes a reference to a coroutine
    298295object and returns @void@.
    299296%[numbers=left] Why numbers on this one?
    300 \begin{cfa}[numbers=left,numberstyle=\scriptsize\sf]
     297\begin{cfa}
    301298void main(CountUp & this) {
    302         for (unsigned int up = 0;; ++up) {
    303                 this.next = up;
     299        for (unsigned int next = 0 ; true ; ++next) {
     300                this.next = next;
    304301                suspend;$\label{suspend}$
    305302        }
     
    307304\end{cfa}
    308305In this function, or functions called by this function (helper functions), the
    309 @suspend@ statement is used to return execution to the coroutine's resumer
    310 without terminating the coroutine's function(s).
     306@suspend@ statement is used to return execution to the coroutine's caller
     307without terminating the coroutine's function.
    311308
    312309A coroutine is resumed by calling the @resume@ function, \eg @resume(countup)@.
    313310The first resume calls the @main@ function at the top. Thereafter, resume calls
    314311continue a coroutine in the last suspended function after the @suspend@
    315 statement, in this case @main@ line~\ref{suspend}.  The @resume@ function takes
    316 a reference to the coroutine structure and returns the same reference. The
    317 return value allows easy access to communication variables defined in the
    318 coroutine object. For example, the @next@ value for coroutine object @countup@
    319 is both generated and collected in the single expression:
    320 @resume(countup).next@.
     312statement. In this case there is only one and, hence, the difference between
     313subsequent calls is the state of variables inside the function and the
     314coroutine object.
     315The return value of @resume@ is a reference to the coroutine, to make it
     316convent to access fields of the coroutine in the same expression.
     317Here is a simple example in a helper function:
     318\begin{cfa}
     319unsigned int get_next(CountUp & this) {
     320        return resume(this).next;
     321}
     322\end{cfa}
     323
     324When the main function returns the coroutine halts and can no longer be
     325resumed.
    321326
    322327\subsection{Monitor and Mutex Parameter}
     
    330335exclusion on a monitor object by qualifying an object reference parameter with
    331336@mutex@.
    332 \begin{lstlisting}[language=CFA,{moredelim=**[is][\color{red}]{@}{@}}]
    333 void example(MonitorA & @mutex@ argA, MonitorB & @mutex@ argB);
    334 \end{lstlisting}
     337\begin{cfa}
     338void example(MonitorA & mutex argA, MonitorB & mutex argB);
     339\end{cfa}
    335340When the function is called, it implicitly acquires the monitor lock for all of
    336341the mutex parameters without deadlock.  This semantics means all functions with
     
    362367{
    363368        StringWorker stringworker; // fork thread running in "main"
    364 } // implicitly join with thread / wait for completion
     369} // Implicit call to join(stringworker), waits for completion.
    365370\end{cfa}
    366371The thread main is where a new thread starts execution after a fork operation
Note: See TracChangeset for help on using the changeset viewer.