Ignore:
Timestamp:
Aug 9, 2021, 4:35:49 PM (12 months ago)
Author:
Andrew Beach <ajbeach@…>
Branches:
enum, forall-pointer-decay, jacob/cs343-translation, master, pthread-emulation
Children:
cb6b8cb
Parents:
5438e41
Message:

Copied out and reverted changes to thesis.

File:
1 edited

Legend:

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

    r5438e41 rf42a6b8  
    1010
    1111Only those \CFA features pertaining to this thesis are discussed.
    12 % Also, only new features of \CFA will be discussed,
    13 A familiarity with
     12Also, only new features of \CFA will be discussed, a familiarity with
    1413C or C-like languages is assumed.
    1514
     
    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 you would use pointers but would
     81be dereferencing them (almost) every usage.
    8382Mutable references may be assigned to by converting them to a pointer
    8483with a @&@ and then assigning a pointer to them, as in @&ri = &j;@ above
     
    8685\section{Operators}
    8786
    88 \CFA implements operator overloading by providing special names, where
    89 operator usages are translated into function calls using these names.
    90 An operator name is created by taking the operator symbols and joining them with
     87\CFA implements operator overloading by providing special names.
     88Operator uses are translated into function calls using these names.
     89These names are created by taking the operator symbols and joining them with
    9190@?@s to show where the arguments go.
    9291For example,
    93 infixed multiplication is @?*?@, while prefix dereference is @*?@.
     92infixed multiplication is @?*?@ while prefix dereference is @*?@.
    9493This syntax make it easy to tell the difference between prefix operations
    9594(such as @++?@) and post-fix operations (@?++@).
    96 For example, plus and equality operators are defined for a point type.
     95
    9796\begin{cfa}
    9897point ?+?(point a, point b) { return point{a.x + b.x, a.y + b.y}; }
    99 int ?==?(point a, point b) { return a.x == b.x && a.y == b.y; }
     98bool ?==?(point a, point b) { return a.x == b.x && a.y == b.y; }
    10099{
    101100        assert(point{1, 2} + point{3, 4} == point{4, 6});
    102101}
    103102\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.
     103Note that these special names are not limited to just being used for these
     104operator functions, and may be used name other declarations.
     105Some ``near misses", that will not match an operator form but looks like
     106it may have been supposed to, will generate wantings but otherwise they are
     107left alone.
     108
     109%\subsection{Constructors and Destructors}
     110
     111Both constructors and destructors are operators, which means they are
     112functions with special operator names rather than type names in \Cpp. The
     113special operator names may be used to call the functions explicitly.
     114% Placement new means that this is actually equivant to C++.
     115
     116The special name for a constructor is @?{}@, which comes from the
     117initialization syntax in C, \eg @Example e = { ... }@.
     118\CFA will generate a constructor call each time a variable is declared,
     119passing the initialization arguments to the constructort.
     120\begin{cfa}
     121struct Example { ... };
     122void ?{}(Example & this) { ... }
     123{
     124        Example a;
     125        Example b = {};
     126}
     127void ?{}(Example & this, char first, int num) { ... }
     128{
     129        Example c = {'a', 2};
     130}
     131\end{cfa}
     132Both @a@ and @b@ will be initalized with the first constructor,
     133while @c@ will be initalized with the second.
     134Currently, there is no general way to skip initialation.
     135
     136% I don't like the \^{} symbol but $^\wedge$ isn't better.
     137Similarly destructors use the special name @^?{}@ (the @^@ has no special
     138meaning).
     139These are a normally called implicitly called on a variable when it goes out
     140of scope. They can be called explicitly as well.
     141\begin{cfa}
     142void ^?{}(Example & this) { ... }
     143{
     144        Example d;
     145} // <- implicit destructor call
     146\end{cfa}
     147
     148Whenever a type is defined, \CFA will create a default zero-argument
     149constructor, a copy constructor, a series of argument-per-field constructors
     150and a destructor. All user constructors are defined after this.
    112151Because operators are never part of the type definition they may be added
    113152at any time, including on built-in types.
    114 
    115 %\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++.
    123 
    124 The special name for a constructor is @?{}@, which comes from the
    125 initialization syntax in C, \eg @Example e = { ... }@.
    126 \CFA generates a constructor call each time a variable is declared,
    127 passing the initialization arguments to the constructor.
    128 \begin{cfa}
    129 struct Example { ... };
    130 void ?{}(Example & this) { ... }
    131 void ?{}(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}
    142 % I don't like the \^{} symbol but $^\wedge$ isn't better.
    143 Similarly, destructors use the special name @^?{}@ (the @^@ has no special
    144 meaning).
    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.
    147 \begin{cfa}
    148 void ^?{}(Example & this) { ... }
    149 {
    150         Example e;      // implicit constructor call
    151         ^?{}(e);                // explicit destructor call
    152         ?{}(e);         // explicit constructor call
    153 } // implicit destructor call
    154 \end{cfa}
    155 
    156 Whenever a type is defined, \CFA creates a default zero-argument
    157 constructor, a copy constructor, a series of argument-per-field constructors
    158 and a destructor. All user constructors are defined after this.
    159153
    160154\section{Polymorphism}
     
    208202Note, a function named @do_once@ is not required in the scope of @do_twice@ to
    209203compile it, unlike \Cpp template expansion. Furthermore, call-site inferencing
    210 allows local replacement of the specific parametric functions needs for a
     204allows local replacement of the most specific parametric functions needs for a
    211205call.
    212206\begin{cfa}
     
    224218to @do_twice@ and called within it.
    225219The global definition of @do_once@ is ignored, however if quadruple took a
    226 @double@ argument, then the global definition would be used instead as it
    227 is a better match.
     220@double@ argument then the global definition would be used instead as it
     221would be a better match.
    228222% Aaron's thesis might be a good reference here.
    229223
    230224To 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
     225convenient packages called a @trait@, which can then be used in an assertion
    232226instead of the individual constraints.
    233227\begin{cfa}
     
    245239functionality, like @sumable@, @listable@, \etc.
    246240
    247 Polymorphic structures and unions are defined by qualifying an aggregate type
     241Polymorphic structures and unions are defined by qualifying the aggregate type
    248242with @forall@. The type variables work the same except they are used in field
    249243declarations instead of parameters, returns, and local variable declarations.
     
    291285coroutine CountUp {
    292286        unsigned int next;
    293 };
     287}
    294288CountUp countup;
    295 for (10) sout | resume(countup).next; // print 10 values
    296289\end{cfa}
    297290Each coroutine has a @main@ function, which takes a reference to a coroutine
    298291object and returns @void@.
    299292%[numbers=left] Why numbers on this one?
    300 \begin{cfa}[numbers=left,numberstyle=\scriptsize\sf]
     293\begin{cfa}
    301294void main(CountUp & this) {
    302         for (unsigned int up = 0;; ++up) {
    303                 this.next = up;
     295        for (unsigned int next = 0 ; true ; ++next) {
     296                next = up;
    304297                suspend;$\label{suspend}$
    305298        }
     
    307300\end{cfa}
    308301In 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).
     302@suspend@ statement is used to return execution to the coroutine's caller
     303without terminating the coroutine's function.
    311304
    312305A coroutine is resumed by calling the @resume@ function, \eg @resume(countup)@.
     
    330323exclusion on a monitor object by qualifying an object reference parameter with
    331324@mutex@.
    332 \begin{lstlisting}[language=CFA,{moredelim=**[is][\color{red}]{@}{@}}]
    333 void example(MonitorA & @mutex@ argA, MonitorB & @mutex@ argB);
    334 \end{lstlisting}
     325\begin{cfa}
     326void example(MonitorA & mutex argA, MonitorB & mutex argB);
     327\end{cfa}
    335328When the function is called, it implicitly acquires the monitor lock for all of
    336329the mutex parameters without deadlock.  This semantics means all functions with
     
    362355{
    363356        StringWorker stringworker; // fork thread running in "main"
    364 } // implicitly join with thread / wait for completion
     357} // <- implicitly join with thread / wait for completion
    365358\end{cfa}
    366359The thread main is where a new thread starts execution after a fork operation
Note: See TracChangeset for help on using the changeset viewer.