# Changeset f42a6b8 for doc/theses/andrew_beach_MMath/existing.tex

Ignore:
Timestamp:
Aug 9, 2021, 4:35:49 PM (12 months ago)
Branches:
Children:
cb6b8cb
Parents:
5438e41
Message:

Copied out and reverted changes to thesis.

File:
1 edited

### Legend:

Unmodified
 r5438e41 Only those \CFA features pertaining to this thesis are discussed. % Also, only new features of \CFA will be discussed, A familiarity with Also, only new features of \CFA will be discussed, a familiarity with C or C-like languages is assumed. \CFA has extensive overloading, allowing multiple definitions of the same name to be defined~\cite{Moss18}. \begin{lstlisting}[language=CFA,{moredelim=**[is][\color{red}]{@}{@}}] char @i@; int @i@; double @i@; int @f@(); double @f@(); void @g@( int ); void @g@( double ); \end{lstlisting} \begin{cfa} char i; int i; double i; int f(); double f(); void g( int ); void g( double ); \end{cfa} This feature requires name mangling so the assembly symbols are unique for different overloads. For compatibility with names in C, there is also a syntax int && rri = ri; rri = 3; &ri = &j; // rebindable &ri = &j; ri = 5; \end{cfa} \end{minipage} References are intended for pointer situations where dereferencing is the common usage, \ie the value is more important than the pointer. References are intended to be used when you would use pointers but would be dereferencing them (almost) every usage. Mutable references may be assigned to by converting them to a pointer with a @&@ and then assigning a pointer to them, as in @&ri = &j;@ above \section{Operators} \CFA implements operator overloading by providing special names, where operator usages are translated into function calls using these names. An operator name is created by taking the operator symbols and joining them with \CFA implements operator overloading by providing special names. Operator uses are translated into function calls using these names. These names are created by taking the operator symbols and joining them with @?@s to show where the arguments go. For example, infixed multiplication is @?*?@, while prefix dereference is @*?@. infixed multiplication is @?*?@ while prefix dereference is @*?@. This syntax make it easy to tell the difference between prefix operations (such as @++?@) and post-fix operations (@?++@). For example, plus and equality operators are defined for a point type. \begin{cfa} point ?+?(point a, point b) { return point{a.x + b.x, a.y + b.y}; } int ?==?(point a, point b) { return a.x == b.x && a.y == b.y; } bool ?==?(point a, point b) { return a.x == b.x && a.y == b.y; } { assert(point{1, 2} + point{3, 4} == point{4, 6}); } \end{cfa} Note these special names are not limited to builtin operators, and hence, may be used with arbitrary types. \begin{cfa} double ?+?( int x, point y ); // arbitrary types \end{cfa} % Some near misses", that are that do not match an operator form but looks like % it may have been supposed to, will generate warning but otherwise they are % left alone. Note that these special names are not limited to just being used for these operator functions, and may be used name other declarations. Some near misses", that will not match an operator form but looks like it may have been supposed to, will generate wantings but otherwise they are left alone. %\subsection{Constructors and Destructors} Both constructors and destructors are operators, which means they are functions with special operator names rather than type names in \Cpp. The special operator names may be used to call the functions explicitly. % Placement new means that this is actually equivant to C++. The special name for a constructor is @?{}@, which comes from the initialization syntax in C, \eg @Example e = { ... }@. \CFA will generate a constructor call each time a variable is declared, passing the initialization arguments to the constructort. \begin{cfa} struct Example { ... }; void ?{}(Example & this) { ... } { Example a; Example b = {}; } void ?{}(Example & this, char first, int num) { ... } { Example c = {'a', 2}; } \end{cfa} Both @a@ and @b@ will be initalized with the first constructor, while @c@ will be initalized with the second. Currently, there is no general way to skip initialation. % I don't like the \^{} symbol but $^\wedge$ isn't better. Similarly destructors use the special name @^?{}@ (the @^@ has no special meaning). These are a normally called implicitly called on a variable when it goes out of scope. They can be called explicitly as well. \begin{cfa} void ^?{}(Example & this) { ... } { Example d; } // <- implicit destructor call \end{cfa} Whenever a type is defined, \CFA will create a default zero-argument constructor, a copy constructor, a series of argument-per-field constructors and a destructor. All user constructors are defined after this. Because operators are never part of the type definition they may be added at any time, including on built-in types. %\subsection{Constructors and Destructors} \CFA also provides constructors and destructors as operators, which means they are functions with special operator names rather than type names in \Cpp. While constructors and destructions are normally called implicitly by the compiler, the special operator names, allow explicit calls. % Placement new means that this is actually equivalent to C++. The special name for a constructor is @?{}@, which comes from the initialization syntax in C, \eg @Example e = { ... }@. \CFA generates a constructor call each time a variable is declared, passing the initialization arguments to the constructor. \begin{cfa} struct Example { ... }; void ?{}(Example & this) { ... } void ?{}(Example & this, char first, int num) { ... } Example a;              // implicit constructor calls Example b = {}; Example c = {'a', 2}; \end{cfa} Both @a@ and @b@ are initialized with the first constructor, while @c@ is initialized with the second. Constructor calls can be replaced with C initialization using special operator \lstinline{@=}. \begin{cfa} Example d @= {42}; \end{cfa} % I don't like the \^{} symbol but $^\wedge$ isn't better. Similarly, destructors use the special name @^?{}@ (the @^@ has no special meaning). % These are a normally called implicitly called on a variable when it goes out % of scope. They can be called explicitly as well. \begin{cfa} void ^?{}(Example & this) { ... } { Example e;      // implicit constructor call ^?{}(e);                // explicit destructor call ?{}(e);         // explicit constructor call } // implicit destructor call \end{cfa} Whenever a type is defined, \CFA creates a default zero-argument constructor, a copy constructor, a series of argument-per-field constructors and a destructor. All user constructors are defined after this. \section{Polymorphism} Note, a function named @do_once@ is not required in the scope of @do_twice@ to compile it, unlike \Cpp template expansion. Furthermore, call-site inferencing allows local replacement of the specific parametric functions needs for a allows local replacement of the most specific parametric functions needs for a call. \begin{cfa} to @do_twice@ and called within it. The global definition of @do_once@ is ignored, however if quadruple took a @double@ argument, then the global definition would be used instead as it is a better match. @double@ argument then the global definition would be used instead as it would be a better match. % Aaron's thesis might be a good reference here. To avoid typing long lists of assertions, constraints can be collect into convenient package called a @trait@, which can then be used in an assertion convenient packages called a @trait@, which can then be used in an assertion instead of the individual constraints. \begin{cfa} functionality, like @sumable@, @listable@, \etc. Polymorphic structures and unions are defined by qualifying an aggregate type Polymorphic structures and unions are defined by qualifying the aggregate type with @forall@. The type variables work the same except they are used in field declarations instead of parameters, returns, and local variable declarations. coroutine CountUp { unsigned int next; }; } CountUp countup; for (10) sout | resume(countup).next; // print 10 values \end{cfa} Each coroutine has a @main@ function, which takes a reference to a coroutine object and returns @void@. %[numbers=left] Why numbers on this one? \begin{cfa}[numbers=left,numberstyle=\scriptsize\sf] \begin{cfa} void main(CountUp & this) { for (unsigned int up = 0;; ++up) { this.next = up; for (unsigned int next = 0 ; true ; ++next) { next = up; suspend;$\label{suspend}$ } \end{cfa} In this function, or functions called by this function (helper functions), the @suspend@ statement is used to return execution to the coroutine's resumer without terminating the coroutine's function(s). @suspend@ statement is used to return execution to the coroutine's caller without terminating the coroutine's function. A coroutine is resumed by calling the @resume@ function, \eg @resume(countup)@. exclusion on a monitor object by qualifying an object reference parameter with @mutex@. \begin{lstlisting}[language=CFA,{moredelim=**[is][\color{red}]{@}{@}}] void example(MonitorA & @mutex@ argA, MonitorB & @mutex@ argB); \end{lstlisting} \begin{cfa} void example(MonitorA & mutex argA, MonitorB & mutex argB); \end{cfa} When the function is called, it implicitly acquires the monitor lock for all of the mutex parameters without deadlock.  This semantics means all functions with { StringWorker stringworker; // fork thread running in "main" } // implicitly join with thread / wait for completion } // <- implicitly join with thread / wait for completion \end{cfa} The thread main is where a new thread starts execution after a fork operation