Ignore:
Timestamp:
Aug 2, 2021, 6:26:24 PM (3 years ago)
Author:
Peter A. Buhr <pabuhr@…>
Branches:
ADT, ast-experimental, enum, forall-pointer-decay, jacob/cs343-translation, master, new-ast-unique-expr, pthread-emulation, qualifiedEnum
Children:
1e567ab, 42a02ce
Parents:
417e8ea
Message:

proofread exisitng chapter of Andrew's thesis

Location:
doc/theses/andrew_beach_MMath
Files:
2 edited

Legend:

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

    r417e8ea rfa7dbf1  
    1010
    1111Only those \CFA features pertaining to this thesis are discussed.
    12 Also, only new features of \CFA will be discussed, a familiarity with
     12% Also, only new features of \CFA will be discussed,
     13A familiarity with
    1314C or C-like languages is assumed.
    1415
     
    1617\CFA has extensive overloading, allowing multiple definitions of the same name
    1718to be defined~\cite{Moss18}.
    18 \begin{cfa}
    19 char i; int i; double i;
    20 int f(); double f();
    21 void g( int ); void g( double );
    22 \end{cfa}
     19\begin{lstlisting}[language=CFA,{moredelim=**[is][\color{red}]{@}{@}}]
     20char @i@; int @i@; double @i@;
     21int @f@(); double @f@();
     22void @g@( int ); void @g@( double );
     23\end{lstlisting}
    2324This feature requires name mangling so the assembly symbols are unique for
    2425different overloads. For compatibility with names in C, there is also a syntax
     
    6263int && rri = ri;
    6364rri = 3;
    64 &ri = &j;
     65&ri = &j; // rebindable
    6566ri = 5;
    6667\end{cfa}
     
    7879\end{minipage}
    7980
    80 References are intended to be used when you would use pointers but would
    81 be dereferencing them (almost) every usage.
     81References are intended for pointer situations where dereferencing is the common usage,
     82\ie the value is more important than the pointer.
    8283Mutable references may be assigned to by converting them to a pointer
    8384with a @&@ and then assigning a pointer to them, as in @&ri = &j;@ above
     
    8586\section{Operators}
    8687
    87 \CFA implements operator overloading by providing special names.
    88 Operator uses are translated into function calls using these names.
    89 These names are created by taking the operator symbols and joining them with
    90 @?@s to show where the arguments go.
     88\CFA implements operator overloading by providing special names, where
     89operator usages are translated into function calls using these names.
     90An operator name is created by taking the operator symbols and joining them with
     91@?@s to show where the parameters go.
    9192For example,
    92 infixed multiplication is @?*?@ while prefix dereference is @*?@.
     93infixed multiplication is @?*?@, while prefix dereference is @*?@.
    9394This syntax make it easy to tell the difference between prefix operations
    9495(such as @++?@) and post-fix operations (@?++@).
    95 
     96For example, plus and equality operators are defined for a point type.
    9697\begin{cfa}
    9798point ?+?(point a, point b) { return point{a.x + b.x, a.y + b.y}; }
    98 bool ?==?(point a, point b) { return a.x == b.x && a.y == b.y; }
     99int ?==?(point a, point b) { return a.x == b.x && a.y == b.y; }
    99100{
    100101        assert(point{1, 2} + point{3, 4} == point{4, 6});
    101102}
    102103\end{cfa}
    103 Note that these special names are not limited to just being used for these
    104 operator functions, and may be used name other declarations.
    105 Some ``near misses", that will not match an operator form but looks like
    106 it may have been supposed to, will generate wantings but otherwise they are
    107 left alone.
     104Note these special names are not limited to builtin
     105operators, and hence, may be used with arbitrary types.
     106\begin{cfa}
     107double ?+?( 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.
     112Because operators are never part of the type definition they may be added
     113at any time, including on built-in types.
    108114
    109115%\subsection{Constructors and Destructors}
    110116
    111 Both constructors and destructors are operators, which means they are
    112 functions with special operator names rather than type names in \Cpp. The
    113 special operator names may be used to call the functions explicitly.
    114 % Placement new means that this is actually equivant to C++.
     117\CFA also provides constructors and destructors as operators, which means they
     118are functions with special operator names rather than type names in \Cpp.
     119While constructors and destructions are normally called implicitly by the compiler,
     120the special operator names, allow explicit calls.
     121
     122% Placement new means that this is actually equivalent to C++.
    115123
    116124The special name for a constructor is @?{}@, which comes from the
    117125initialization syntax in C, \eg @Example e = { ... }@.
    118 \CFA will generate a constructor call each time a variable is declared,
    119 passing the initialization arguments to the constructort.
     126\CFA generates a constructor call each time a variable is declared,
     127passing the initialization arguments to the constructor.
    120128\begin{cfa}
    121129struct Example { ... };
    122130void ?{}(Example & this) { ... }
    123 {
    124         Example a;
    125         Example b = {};
    126 }
    127131void ?{}(Example & this, char first, int num) { ... }
    128 {
    129         Example c = {'a', 2};
    130 }
    131 \end{cfa}
    132 Both @a@ and @b@ will be initalized with the first constructor,
    133 while @c@ will be initalized with the second.
    134 Currently, there is no general way to skip initialation.
    135 
     132Example a;              // implicit constructor calls
     133Example b = {};
     134Example c = {'a', 2};
     135\end{cfa}
     136Both @a@ and @b@ are initialized with the first constructor,
     137while @c@ is initialized with the second.
     138Constructor calls can be replaced with C initialization using special operator \lstinline{@=}.
     139\begin{cfa}
     140Example d @= {42};
     141\end{cfa}
    136142% I don't like the \^{} symbol but $^\wedge$ isn't better.
    137 Similarly destructors use the special name @^?{}@ (the @^@ has no special
     143Similarly, destructors use the special name @^?{}@ (the @^@ has no special
    138144meaning).
    139 These are a normally called implicitly called on a variable when it goes out
    140 of scope. They can be called explicitly as well.
     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.
    141147\begin{cfa}
    142148void ^?{}(Example & this) { ... }
    143149{
    144         Example d;
    145 } // <- implicit destructor call
    146 \end{cfa}
    147 
    148 Whenever a type is defined, \CFA will create a default zero-argument
     150        Example e;      // implicit constructor call
     151        ^?{}(e);                // explicit destructor call
     152        ?{}(e);         // explicit constructor call
     153} // implicit destructor call
     154\end{cfa}
     155
     156Whenever a type is defined, \CFA creates a default zero-argument
    149157constructor, a copy constructor, a series of argument-per-field constructors
    150158and a destructor. All user constructors are defined after this.
    151 Because operators are never part of the type definition they may be added
    152 at any time, including on built-in types.
    153159
    154160\section{Polymorphism}
     
    202208Note, a function named @do_once@ is not required in the scope of @do_twice@ to
    203209compile it, unlike \Cpp template expansion. Furthermore, call-site inferencing
    204 allows local replacement of the most specific parametric functions needs for a
     210allows local replacement of the specific parametric functions needs for a
    205211call.
    206212\begin{cfa}
     
    218224to @do_twice@ and called within it.
    219225The global definition of @do_once@ is ignored, however if quadruple took a
    220 @double@ argument then the global definition would be used instead as it
    221 would be a better match.
     226@double@ argument, then the global definition would be used instead as it
     227is a better match.
    222228% Aaron's thesis might be a good reference here.
    223229
    224230To avoid typing long lists of assertions, constraints can be collect into
    225 convenient packages called a @trait@, which can then be used in an assertion
     231convenient package called a @trait@, which can then be used in an assertion
    226232instead of the individual constraints.
    227233\begin{cfa}
     
    239245functionality, like @sumable@, @listable@, \etc.
    240246
    241 Polymorphic structures and unions are defined by qualifying the aggregate type
     247Polymorphic structures and unions are defined by qualifying an aggregate type
    242248with @forall@. The type variables work the same except they are used in field
    243249declarations instead of parameters, returns, and local variable declarations.
     
    285291coroutine CountUp {
    286292        unsigned int next;
    287 }
     293};
    288294CountUp countup;
     295for (10) sout | resume(countup).next; // print 10 values
    289296\end{cfa}
    290297Each coroutine has a @main@ function, which takes a reference to a coroutine
    291298object and returns @void@.
    292299%[numbers=left] Why numbers on this one?
    293 \begin{cfa}
     300\begin{cfa}[numbers=left,numberstyle=\scriptsize\sf]
    294301void main(CountUp & this) {
    295         for (unsigned int next = 0 ; true ; ++next) {
    296                 next = up;
     302        for (unsigned int up = 0;; ++up) {
     303                this.next = up;
    297304                suspend;$\label{suspend}$
    298305        }
     
    300307\end{cfa}
    301308In this function, or functions called by this function (helper functions), the
    302 @suspend@ statement is used to return execution to the coroutine's caller
    303 without terminating the coroutine's function.
     309@suspend@ statement is used to return execution to the coroutine's resumer
     310without terminating the coroutine's function(s).
    304311
    305312A coroutine is resumed by calling the @resume@ function, \eg @resume(countup)@.
     
    323330exclusion on a monitor object by qualifying an object reference parameter with
    324331@mutex@.
    325 \begin{cfa}
    326 void example(MonitorA & mutex argA, MonitorB & mutex argB);
    327 \end{cfa}
     332\begin{lstlisting}[language=CFA,{moredelim=**[is][\color{red}]{@}{@}}]
     333void example(MonitorA & @mutex@ argA, MonitorB & @mutex@ argB);
     334\end{lstlisting}
    328335When the function is called, it implicitly acquires the monitor lock for all of
    329336the mutex parameters without deadlock.  This semantics means all functions with
     
    355362{
    356363        StringWorker stringworker; // fork thread running in "main"
    357 } // <- implicitly join with thread / wait for completion
     364} // implicitly join with thread / wait for completion
    358365\end{cfa}
    359366The thread main is where a new thread starts execution after a fork operation
  • doc/theses/andrew_beach_MMath/uw-ethesis.tex

    r417e8ea rfa7dbf1  
    210210\lstMakeShortInline@
    211211\lstset{language=CFA,style=cfacommon,basicstyle=\linespread{0.9}\tt}
    212 \lstset{moredelim=**[is][\protect\color{red}]{@}{@}}
     212% PAB causes problems with inline @=
     213%\lstset{moredelim=**[is][\protect\color{red}]{@}{@}}
    213214% Annotations from Peter:
    214215\newcommand{\PAB}[1]{{\color{blue}PAB: #1}}
Note: See TracChangeset for help on using the changeset viewer.