Changeset be497c6 for doc/theses


Ignore:
Timestamp:
Aug 13, 2021, 3:35:55 PM (3 years ago)
Author:
Andrew Beach <ajbeach@…>
Branches:
ADT, ast-experimental, enum, forall-pointer-decay, jacob/cs343-translation, master, pthread-emulation, qualifiedEnum
Children:
3b8acfb
Parents:
cb6b8cb
Message:

Andrew MMath: Used Peter's feedback for the existing chapter.

File:
1 edited

Legend:

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

    rcb6b8cb rbe497c6  
    1010
    1111Only those \CFA features pertaining to this thesis are discussed.
    12 Also, only new features of \CFA will be discussed, a familiarity with
     12A familiarity with
    1313C or C-like languages is assumed.
    1414
     
    7878\end{minipage}
    7979
    80 References are intended to be used when you would use pointers but would
    81 be dereferencing them (almost) every usage.
     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.
    8283Mutable references may be assigned to by converting them to a pointer
    83 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% ???
    8486
    8587\section{Operators}
    8688
    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
     89\CFA implements operator overloading by providing special names, where
     90operator expressions are translated into function calls using these names.
     91An operator name is created by taking the operator symbols and joining them with
    9092@?@s to show where the arguments go.
    9193For example,
    92 infixed multiplication is @?*?@ while prefix dereference is @*?@.
     94infixed multiplication is @?*?@, while prefix dereference is @*?@.
    9395This syntax make it easy to tell the difference between prefix operations
    9496(such as @++?@) and post-fix operations (@?++@).
    9597
     98As an example, here are the addition and equality operators for a point type.
    9699\begin{cfa}
    97100point ?+?(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; }
     101int ?==?(point a, point b) { return a.x == b.x && a.y == b.y; }
    99102{
    100103        assert(point{1, 2} + point{3, 4} == point{4, 6});
    101104}
    102105\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.
     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.
    108112
    109113%\subsection{Constructors and Destructors}
    110 
    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.
     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.
    114118% Placement new means that this is actually equivant to C++.
    115119
    116120The special name for a constructor is @?{}@, which comes from the
    117121initialization 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.
     122\CFA generates a constructor call each time a variable is declared,
     123passing the initialization arguments to the constructor.
    120124\begin{cfa}
    121125struct Example { ... };
     
    131135\end{cfa}
    132136Both @a@ and @b@ will be initalized with the first constructor,
    133 while @c@ will be initalized with the second.
     137@b@ because of the explicit call and @a@ implicitly.
     138@c@ will be initalized with the second constructor.
    134139Currently, there is no general way to skip initialation.
     140% I don't use @= anywhere in the thesis.
    135141
    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.
    141145\begin{cfa}
    142146void ^?{}(Example & this) { ... }
    143147{
    144148        Example d;
    145 } // <- implicit destructor call
    146 \end{cfa}
    147 
    148 Whenever a type is defined, \CFA will create a default zero-argument
     149        ^?{}(d);
     150
     151        Example e;
     152} // Implicit call of ^?{}(e);
     153\end{cfa}
     154
     155Whenever a type is defined, \CFA creates a default zero-argument
    149156constructor, a copy constructor, a series of argument-per-field constructors
    150157and 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.
    153158
    154159\section{Polymorphism}
     
    202207Note, a function named @do_once@ is not required in the scope of @do_twice@ to
    203208compile it, unlike \Cpp template expansion. Furthermore, call-site inferencing
    204 allows local replacement of the most specific parametric functions needs for a
     209allows local replacement of the specific parametric functions needs for a
    205210call.
    206211\begin{cfa}
     
    218223to @do_twice@ and called within it.
    219224The 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.
    222 % Aaron's thesis might be a good reference here.
    223 
    224 To 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
     225@double@ argument, then the global definition would be used instead as it
     226would then be a better match.
     227\todo{cite Aaron's thesis (maybe)}
     228
     229To avoid typing long lists of assertions, constraints can be collected into
     230convenient a package called a @trait@, which can then be used in an assertion
    226231instead of the individual constraints.
    227232\begin{cfa}
     
    239244functionality, like @sumable@, @listable@, \etc.
    240245
    241 Polymorphic structures and unions are defined by qualifying the aggregate type
     246Polymorphic structures and unions are defined by qualifying an aggregate type
    242247with @forall@. The type variables work the same except they are used in field
    243248declarations instead of parameters, returns, and local variable declarations.
     
    247252        node(T) * next;
    248253        T * data;
    249 }
     254};
    250255node(int) inode;
    251256\end{cfa}
     
    285290coroutine CountUp {
    286291        unsigned int next;
    287 }
     292};
    288293CountUp countup;
    289294\end{cfa}
     
    294299void main(CountUp & this) {
    295300        for (unsigned int next = 0 ; true ; ++next) {
    296                 next = up;
     301                this.next = next;
    297302                suspend;$\label{suspend}$
    298303        }
     
    306311The first resume calls the @main@ function at the top. Thereafter, resume calls
    307312continue a coroutine in the last suspended function after the @suspend@
    308 statement, in this case @main@ line~\ref{suspend}.  The @resume@ function takes
    309 a reference to the coroutine structure and returns the same reference. The
    310 return value allows easy access to communication variables defined in the
    311 coroutine object. For example, the @next@ value for coroutine object @countup@
    312 is both generated and collected in the single expression:
    313 @resume(countup).next@.
     313statement. In this case there is only one and, hence, the difference between
     314subsequent calls is the state of variables inside the function and the
     315coroutine object.
     316The return value of @resume@ is a reference to the coroutine, to make it
     317convent to access fields of the coroutine in the same expression.
     318Here is a simple example in a helper function:
     319\begin{cfa}
     320unsigned int get_next(CountUp & this) {
     321        return resume(this).next;
     322}
     323\end{cfa}
     324
     325When the main function returns the coroutine halts and can no longer be
     326resumed.
    314327
    315328\subsection{Monitor and Mutex Parameter}
     
    355368{
    356369        StringWorker stringworker; // fork thread running in "main"
    357 } // <- implicitly join with thread / wait for completion
     370} // Implicit call to join(stringworker), waits for completion.
    358371\end{cfa}
    359372The thread main is where a new thread starts execution after a fork operation
Note: See TracChangeset for help on using the changeset viewer.