Changeset 0a061c0


Ignore:
Timestamp:
Aug 4, 2021, 4:54:14 PM (3 years ago)
Author:
Thierry Delisle <tdelisle@…>
Branches:
ADT, ast-experimental, enum, forall-pointer-decay, jacob/cs343-translation, master, new-ast-unique-expr, pthread-emulation, qualifiedEnum
Children:
d2cdd4f
Parents:
d83b266 (diff), 199894e (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

Files:
5 added
1 deleted
12 edited

Legend:

Unmodified
Added
Removed
  • doc/theses/andrew_beach_MMath/code/ThrowFinally.java

    rd83b266 r0a061c0  
    77                        throws EmptyException {
    88                if (0 < frames) {
    9                         unwind_finally(frames - 1);
     9                        try {
     10                                unwind_finally(frames - 1);
     11                        } finally {
     12                                // ...
     13                        }
    1014                } else {
    1115                        throw new EmptyException();
  • doc/theses/andrew_beach_MMath/code/ThrowOther.java

    rd83b266 r0a061c0  
    1616                                // ...
    1717                        }
     18                } else if (should_throw) {
     19                        throw new NotRaisedException();
    1820                } else {
    19                         if (should_throw) {
    20                                 throw new NotRaisedException();
    21                         }
    2221                        throw new EmptyException();
    2322                }
  • doc/theses/andrew_beach_MMath/existing.tex

    rd83b266 r0a061c0  
    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
     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
    9091@?@s to show where the arguments 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/intro.tex

    rd83b266 r0a061c0  
    22
    33% The highest level overview of Cforall and EHMs. Get this done right away.
    4 This thesis goes over the design and implementation of the exception handling
     4This thesis covers the design and implementation of the exception handling
    55mechanism (EHM) of
    66\CFA (pronounced sea-for-all and may be written Cforall or CFA).
    7 \CFA is a new programming language that extends C, that maintains
     7\CFA is a new programming language that extends C, which maintains
    88backwards-compatibility while introducing modern programming features.
    99Adding exception handling to \CFA gives it new ways to handle errors and
    10 make other large control-flow jumps.
     10make large control-flow jumps.
    1111
    1212% Now take a step back and explain what exceptions are generally.
     13A language's EHM is a combination of language syntax and run-time
     14components that are used to construct, raise, and handle exceptions,
     15including all control flow.
     16Exceptions are an active mechanism for replacing passive error/return codes and return unions (Go and Rust).
    1317Exception handling provides dynamic inter-function control flow.
    1418There are two forms of exception handling covered in this thesis:
    1519termination, which acts as a multi-level return,
    1620and resumption, which is a dynamic function call.
     21% PAB: Maybe this sentence was suppose to be deleted?
    1722Termination handling is much more common,
    18 to the extent that it is often seen
    19 This seperation is uncommon because termination exception handling is so
    20 much more common that it is often assumed.
     23to the extent that it is often seen as the only form of handling.
     24% PAB: I like this sentence better than the next sentence.
     25% This separation is uncommon because termination exception handling is so
     26% much more common that it is often assumed.
    2127% WHY: Mention other forms of continuation and \cite{CommonLisp} here?
    22 A language's EHM is the combination of language syntax and run-time
    23 components that are used to construct, raise and handle exceptions,
    24 including all control flow.
    25 
    26 Termination exception handling allows control to return to any previous
    27 function on the stack directly, skipping any functions between it and the
    28 current function.
     28
     29Exception handling relies on the concept of nested functions to create handlers that deal with exceptions.
    2930\begin{center}
    30 \input{callreturn}
     31\begin{tabular}[t]{ll}
     32\begin{lstlisting}[aboveskip=0pt,belowskip=0pt,language=CFA,{moredelim=**[is][\color{red}]{@}{@}}]
     33void f( void (*hp)() ) {
     34        hp();
     35}
     36void g( void (*hp)() ) {
     37        f( hp );
     38}
     39void h( int @i@, void (*hp)() ) {
     40        void @handler@() { // nested
     41                printf( "%d\n", @i@ );
     42        }
     43        if ( i == 1 ) hp = handler;
     44        if ( i > 0 ) h( i - 1, hp );
     45        else g( hp );
     46}
     47h( 2, 0 );
     48\end{lstlisting}
     49&
     50\raisebox{-0.5\totalheight}{\input{handler}}
     51\end{tabular}
    3152\end{center}
    32 
    33 Resumption exception handling seaches the stack for a handler and then calls
    34 it without adding or removing any other stack frames.
    35 \todo{Add a diagram showing control flow for resumption.}
     53The nested function @handler@ in the second stack frame is explicitly passed to function @f@.
     54When this handler is called in @f@, it uses the parameter @i@ in the second stack frame, which is accessible by an implicit lexical-link pointer.
     55Setting @hp@ in @h@ at different points in the recursion, results in invoking a different handler.
     56Exception handling extends this idea by eliminating explicit handler passing, and instead, performing a stack search for a handler that matches some criteria (conditional dynamic call), and calls the handler at the top of the stack.
     57It is the runtime search $O(N)$ that differentiates an EHM call (raise) from normal dynamic call $O(1)$ via a function or virtual-member pointer.
     58
     59Termination exception handling searches the stack for a handler, unwinds the stack to the frame containing the matching handler, and calling the handler at the top of the stack.
     60\begin{center}
     61\input{termination}
     62\end{center}
     63Note, since the handler can reference variables in @h@, @h@ must remain on the stack for the handler call.
     64After the handler returns, control continues after the lexical location of the handler in @h@ (static return)~\cite[p.~108]{Tennent77}.
     65Unwinding allows recover to any previous
     66function on the stack, skipping any functions between it and the
     67function containing the matching handler.
     68
     69Resumption exception handling searches the stack for a handler, does \emph{not} unwind the stack to the frame containing the matching handler, and calls the handler at the top of the stack.
     70\begin{center}
     71\input{resumption}
     72\end{center}
     73After the handler returns, control continues after the resume in @f@ (dynamic return).
     74Not unwinding allows fix up of the problem in @f@ by any previous function on the stack, without disrupting the current set of stack frames.
    3675
    3776Although a powerful feature, exception handling tends to be complex to set up
    3877and expensive to use
    39 so they are often limited to unusual or ``exceptional" cases.
    40 The classic example of this is error handling, exceptions can be used to
    41 remove error handling logic from the main execution path and while paying
     78so it is often limited to unusual or ``exceptional" cases.
     79The classic example is error handling, where exceptions are used to
     80remove error handling logic from the main execution path, while paying
    4281most of the cost only when the error actually occurs.
    4382
     
    4988some of the underlying tools used to implement and express exception handling
    5089in other languages are absent in \CFA.
    51 Still the resulting syntax resembles that of other languages:
    52 \begin{cfa}
    53 try {
     90Still the resulting basic syntax resembles that of other languages:
     91\begin{lstlisting}[language=CFA,{moredelim=**[is][\color{red}]{@}{@}}]
     92@try@ {
    5493        ...
    5594        T * object = malloc(request_size);
    5695        if (!object) {
    57                 throw OutOfMemory{fixed_allocation, request_size};
     96                @throw@ OutOfMemory{fixed_allocation, request_size};
    5897        }
    5998        ...
    60 } catch (OutOfMemory * error) {
     99} @catch@ (OutOfMemory * error) {
    61100        ...
    62101}
    63 \end{cfa}
    64 
     102\end{lstlisting}
    65103% A note that yes, that was a very fast overview.
    66104The design and implementation of all of \CFA's EHM's features are
     
    69107
    70108% The current state of the project and what it contributes.
    71 All of these features have been implemented in \CFA, along with
    72 a suite of test cases as part of this project.
    73 The implementation techniques are generally applicable in other programming
     109The majority of the \CFA EHM is implemented in \CFA, except for a small amount of assembler code.
     110In addition,
     111a suite of tests and performance benchmarks were created as part of this project.
     112The \CFA implementation techniques are generally applicable in other programming
    74113languages and much of the design is as well.
    75 Some parts of the EHM use other features unique to \CFA and these would be
    76 harder to replicate in other programming languages.
    77 
     114Some parts of the EHM use features unique to \CFA, and hence,
     115are harder to replicate in other programming languages.
    78116% Talk about other programming languages.
    79 Some existing programming languages that include EHMs/exception handling
    80 include C++, Java and Python. All three examples focus on termination
    81 exceptions which unwind the stack as part of the
    82 Exceptions also can replace return codes and return unions.
     117Three well known programming languages with EHMs, %/exception handling
     118C++, Java and Python are examined in the performance work. However, these languages focus on termination
     119exceptions, so there is no comparison with resumption.
    83120
    84121The contributions of this work are:
    85122\begin{enumerate}
    86123\item Designing \CFA's exception handling mechanism, adapting designs from
    87 other programming languages and the creation of new features.
    88 \item Implementing stack unwinding and the EHM in \CFA, including updating
    89 the compiler and the run-time environment.
    90 \item Designed and implemented a prototype virtual system.
     124other programming languages, and creating new features.
     125\item Implementing stack unwinding for the \CFA EHM, including updating
     126the \CFA compiler and run-time environment to generate and execute the EHM code.
     127\item Designing and implementing a prototype virtual system.
    91128% I think the virtual system and per-call site default handlers are the only
    92129% "new" features, everything else is a matter of implementation.
     130\item Creating tests and performance benchmarks to compare with EHM's in other languages.
    93131\end{enumerate}
    94132
    95 \todo{I can't figure out a good lead-in to the roadmap.}
    96 The next section covers the existing state of exceptions.
    97 The existing state of \CFA is also covered in \autoref{c:existing}.
    98 The new features are introduced in \autoref{c:features},
    99 which explains their usage and design.
    100 That is followed by the implementation of those features in
     133%\todo{I can't figure out a good lead-in to the roadmap.}
     134The thesis is organization as follows.
     135The next section and parts of \autoref{c:existing} cover existing EHMs.
     136New \CFA EHM features are introduced in \autoref{c:features},
     137covering their usage and design.
     138That is followed by the implementation of these features in
    101139\autoref{c:implement}.
    102 The performance results are examined in \autoref{c:performance}.
    103 Possibilities to extend this project are discussed in \autoref{c:future}.
     140Performance results are presented in \autoref{c:performance}.
     141Summing up and possibilities for extending this project are discussed in \autoref{c:future}.
    104142
    105143\section{Background}
    106144\label{s:background}
    107145
    108 Exception handling is not a new concept,
    109 with papers on the subject dating back 70s.\cite{Goodenough}
    110 
    111 Early exceptions were often treated as signals. They carried no information
    112 except their identity. Ada still uses this system.
     146Exception handling is a well examined area in programming languages,
     147with papers on the subject dating back the 70s~\cite{Goodenough75}.
     148Early exceptions were often treated as signals, which carried no information
     149except their identity. Ada~\cite{Ada} still uses this system.
    113150
    114151The modern flag-ship for termination exceptions is \Cpp,
     
    116153in 1990.
    117154% https://en.cppreference.com/w/cpp/language/history
    118 \Cpp has the ability to use any value of any type as an exception.
    119 However that seems to immediately pushed aside for classes inherited from
     155While many EHMs have special exception types,
     156\Cpp has the ability to use any type as an exception.
     157However, this generality is not particularly useful, and has been pushed aside for classes, with a convention of inheriting from
    120158\code{C++}{std::exception}.
    121 Although there is a special catch-all syntax it does not allow anything to
    122 be done with the caught value becuase nothing is known about it.
    123 So instead a base type is defined with some common functionality (such as
    124 the ability to describe the reason the exception was raised) and all
    125 exceptions have that functionality.
    126 This seems to be the standard now, as the garentied functionality is worth
    127 any lost flexibility from limiting it to a single type.
    128 
    129 Java was the next popular language to use exceptions.
    130 Its exception system largely reflects that of \Cpp, except that requires
    131 you throw a child type of \code{Java}{java.lang.Throwable}
     159While \Cpp has a special catch-all syntax @catch(...)@, there is no way to discriminate its exception type, so nothing can
     160be done with the caught value because nothing is known about it.
     161Instead the base exception-type \code{C++}{std::exception} is defined with common functionality (such as
     162the ability to print a message when the exception is raised but not caught) and all
     163exceptions have this functionality.
     164Having a root exception-type seems to be the standard now, as the guaranteed functionality is worth
     165any lost in flexibility from limiting exceptions types to classes.
     166
     167Java~\cite{Java} was the next popular language to use exceptions.
     168Its exception system largely reflects that of \Cpp, except it requires
     169exceptions to be a subtype of \code{Java}{java.lang.Throwable}
    132170and it uses checked exceptions.
    133 Checked exceptions are part of the function interface they are raised from.
    134 This includes functions they propogate through, until a handler for that
    135 type of exception is found.
    136 This makes exception information explicit, which can improve clarity and
     171Checked exceptions are part of a function's interface defining all exceptions it or its called functions raise.
     172Using this information, it is possible to statically verify if a handler exists for all raised exception, \ie no uncaught exceptions.
     173Making exception information explicit, improves clarity and
    137174safety, but can slow down programming.
    138 Some of these, such as dealing with high-order methods or an overly specified
    139 throws clause, are technical. However some of the issues are much more
    140 human, in that writing/updating all the exception signatures can be enough
    141 of a burden people will hack the system to avoid them.
    142 Including the ``catch-and-ignore" pattern where a catch block is used without
    143 anything to repair or recover from the exception.
    144 
    145 %\subsection
    146 Resumption exceptions have been much less popular.
    147 Although resumption has a history as old as termination's, very few
     175For example, programming complexity increases when dealing with high-order methods or an overly specified
     176throws clause. However some of the issues are more
     177programming annoyances, such as writing/updating many exception signatures after adding or remove calls.
     178Java programmers have developed multiple programming ``hacks'' to circumvent checked exceptions negating the robustness it is suppose to provide.
     179For example, the ``catch-and-ignore" pattern, where the handler is empty because the exception does not appear relevant to the programmer versus
     180repairing or recovering from the exception.
     181
     182%\subsection
     183Resumption exceptions are less popular,
     184although resumption is as old as termination;
     185hence, few
    148186programming languages have implemented them.
    149187% http://bitsavers.informatik.uni-stuttgart.de/pdf/xerox/parc/techReports/
    150188%   CSL-79-3_Mesa_Language_Manual_Version_5.0.pdf
    151 Mesa is one programming languages that did. Experiance with Mesa
    152 is quoted as being one of the reasons resumptions were not
     189Mesa~\cite{Mesa} is one programming languages that did. Experience with Mesa
     190is quoted as being one of the reasons resumptions are not
    153191included in the \Cpp standard.
    154192% https://en.wikipedia.org/wiki/Exception_handling
    155 Since then resumptions have been ignored in the main-stream.
    156 
    157 All of this does call into question the use of resumptions, is
    158 something largely rejected decades ago worth revisiting now?
    159 Yes, even if it was the right call at the time there have been decades
    160 of other developments in computer science that have changed the situation
    161 since then.
    162 Some of these developments, such as in functional programming's resumption
    163 equivalent: algebraic effects\cite{Zhang19}, are directly related to
    164 resumptions as well.
    165 A complete rexamination of resumptions is beyond a single paper, but it is
    166 enough to try them again in \CFA.
     193As a result, resumption has ignored in main-stream programming languages.
     194However, ``what goes around comes around'' and resumption is being revisited now (like user-level threading).
     195While rejecting resumption might have been the right decision in the past, there are decades
     196of developments in computer science that have changed the situation.
     197Some of these developments, such as functional programming's resumption
     198equivalent, algebraic effects\cite{Zhang19}, are enjoying significant success.
     199A complete reexamination of resumptions is beyond this thesis, but their re-emergence is
     200enough to try them in \CFA.
    167201% Especially considering how much easier they are to implement than
    168202% termination exceptions.
    169203
    170204%\subsection
    171 Functional languages tend to use other solutions for their primary error
    172 handling mechanism, exception-like constructs still appear.
     205Functional languages tend to use other solutions for their primary EHM,
     206but exception-like constructs still appear.
    173207Termination appears in error construct, which marks the result of an
    174 expression as an error, the result of any expression that tries to use it as
    175 an error, and so on until an approprate handler is reached.
    176 Resumption appears in algebric effects, where a function dispatches its
     208expression as an error; thereafter, the result of any expression that tries to use it is also an
     209error, and so on until an appropriate handler is reached.
     210Resumption appears in algebraic effects, where a function dispatches its
    177211side-effects to its caller for handling.
    178212
    179213%\subsection
    180 More recently exceptions seem to be vanishing from newer programming
    181 languages, replaced by ``panic".
    182 In Rust a panic is just a program level abort that may be implemented by
     214Some programming languages have moved to a restricted kind of EHM
     215called ``panic".
     216In Rust~\cite{Rust}, a panic is just a program level abort that may be implemented by
    183217unwinding the stack like in termination exception handling.
    184218% https://doc.rust-lang.org/std/panic/fn.catch_unwind.html
    185 Go's panic through is very similar to a termination except it only supports
     219In Go~\cite{Go}, a panic is very similar to a termination, except it only supports
    186220a catch-all by calling \code{Go}{recover()}, simplifying the interface at
    187 the cost of flexability.
    188 
    189 %\subsection
    190 Exception handling's most common use cases are in error handling.
    191 Here are some other ways to handle errors and comparisons with exceptions.
     221the cost of flexibility.
     222
     223%\subsection
     224While exception handling's most common use cases are in error handling,
     225here are other ways to handle errors with comparisons to exceptions.
    192226\begin{itemize}
    193227\item\emph{Error Codes}:
    194 This pattern uses an enumeration (or just a set of fixed values) to indicate
    195 that an error has occured and which error it was.
    196 
    197 There are some issues if a function wants to return an error code and another
    198 value. The main issue is that it can be easy to forget checking the error
    199 code, which can lead to an error being quitely and implicitly ignored.
    200 Some new languages have tools that raise warnings if the return value is
    201 discarded to avoid this.
    202 It also puts more code on the main execution path.
     228This pattern has a function return an enumeration (or just a set of fixed values) to indicate
     229if an error occurred and possibly which error it was.
     230
     231Error codes mix exceptional and normal values, artificially enlarging the type and/or value range.
     232Some languages address this issue by returning multiple values or a tuple, separating the error code from the function result.
     233However, the main issue with error codes is forgetting to checking them,
     234which leads to an error being quietly and implicitly ignored.
     235Some new languages have tools that issue warnings, if the error code is
     236discarded to avoid this problem.
     237Checking error codes also results in bloating the main execution path, especially if an error is not dealt with locally and has to be cascaded down the call stack to a higher-level function..
     238
    203239\item\emph{Special Return with Global Store}:
    204 A function that encounters an error returns some value indicating that it
    205 encountered a value but store which error occured in a fixed global location.
    206 
    207 Perhaps the C standard @errno@ is the most famous example of this,
    208 where some standard library functions will return some non-value (often a
    209 NULL pointer) and set @errno@.
    210 
    211 This avoids the multiple results issue encountered with straight error codes
    212 but otherwise many of the same advantages and disadvantages.
    213 It does however introduce one other major disadvantage:
    214 Everything that uses that global location must agree on all possible errors.
     240Some functions only return a boolean indicating success or failure
     241and store the exact reason for the error in a fixed global location.
     242For example, many C routines return non-zero or -1, indicating success or failure,
     243and write error details into the C standard variable @errno@.
     244
     245This approach avoids the multiple results issue encountered with straight error codes
     246but otherwise has many (if not more) of the disadvantages.
     247For example, everything that uses the global location must agree on all possible errors and global variable are unsafe with concurrency.
     248
    215249\item\emph{Return Union}:
    216 Replaces error codes with a tagged union.
     250This pattern replaces error codes with a tagged union.
    217251Success is one tag and the errors are another.
    218252It is also possible to make each possible error its own tag and carry its own
     
    220254so that one type can be used everywhere in error handling code.
    221255
    222 This pattern is very popular in functional or semi-functional language,
    223 anything with primitive support for tagged unions (or algebraic data types).
     256This pattern is very popular in functional or any semi-functional language with
     257primitive support for tagged unions (or algebraic data types).
    224258% We need listing Rust/rust to format code snipits from it.
    225259% Rust's \code{rust}{Result<T, E>}
    226 
    227 The main disadvantage is again it puts code on the main execution path.
    228 This is also the first technique that allows for more information about an
    229 error, other than one of a fix-set of ids, to be sent.
    230 They can be missed but some languages can force that they are checked.
    231 It is also implicitly forced in any languages with checked union access.
     260The main advantage is providing for more information about an
     261error, other than one of a fix-set of ids.
     262While some languages use checked union access to force error-code checking,
     263it is still possible to bypass the checking.
     264The main disadvantage is again significant error code on the main execution path and cascading through called functions.
     265
    232266\item\emph{Handler Functions}:
    233 On error the function that produced the error calls another function to
     267This pattern implicitly associates functions with errors.
     268On error, the function that produced the error implicitly calls another function to
    234269handle it.
    235270The handler function can be provided locally (passed in as an argument,
    236271either directly as as a field of a structure/object) or globally (a global
    237272variable).
    238 
    239 C++ uses this as its fallback system if exception handling fails.
     273C++ uses this approach as its fallback system if exception handling fails, \eg
    240274\snake{std::terminate_handler} and for a time \snake{std::unexpected_handler}
    241275
    242 Handler functions work a lot like resumption exceptions.
    243 The difference is they are more expencive to set up but cheaper to use, and
    244 so are more suited to more fequent errors.
    245 The exception being global handlers if they are rarely change as the time
    246 in both cases strinks towards zero.
     276Handler functions work a lot like resumption exceptions, without the dynamic handler search.
     277Therefore, setting setting up the handler can be more complex/expensive, especially if the handle must be passed through multiple function calls, but cheaper to call $O(1)$, and hence,
     278are more suited to frequent exceptional situations.
     279% The exception being global handlers if they are rarely change as the time
     280% in both cases shrinks towards zero.
    247281\end{itemize}
    248282
    249283%\subsection
    250 Because of their cost exceptions are rarely used for hot paths of execution.
    251 There is an element of self-fulfilling prophocy here as implementation
    252 techniques have been designed to make exceptions cheap to set-up at the cost
    253 of making them expencive to use.
    254 Still, use of exceptions for other tasks is more common in higher-level
    255 scripting languages.
    256 An iconic example is Python's StopIteration exception which is thrown by
    257 an iterator to indicate that it is exausted. Combined with Python's heavy
    258 use of the iterator based for-loop.
     284Because of their cost, exceptions are rarely used for hot paths of execution.
     285Therefore, there is an element of self-fulfilling prophecy for implementation
     286techniques to make exceptions cheap to set-up at the cost
     287of expensive usage.
     288This cost differential is less important in higher-level scripting languages, where use of exceptions for other tasks is more common.
     289An iconic example is Python's @StopIteration@ exception that is thrown by
     290an iterator to indicate that it is exhausted, especially when combined with Python's heavy
     291use of the iterator-based for-loop.
    259292% https://docs.python.org/3/library/exceptions.html#StopIteration
  • doc/theses/andrew_beach_MMath/uw-ethesis.tex

    rd83b266 r0a061c0  
    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}}
  • doc/theses/mubeen_zulfiqar_MMath/intro.tex

    rd83b266 r0a061c0  
    2424\noindent
    2525====================
     26
     27\section{Introduction}
     28Dynamic memory allocation and management is one of the core features of C. It gives programmer the freedom to allocate, free, use, and manage dynamic memory himself. The programmer is not given the complete control of the dynamic memory management instead an interface of memory allocator is given to the progrmmer that can be used to allocate/free dynamic memory for the application's use.
     29
     30Memory allocator is a layer between thr programmer and the system. Allocator gets dynamic memory from the system in heap/mmap area of application storage and manages it for programmer's use.
     31
     32GNU C Library (FIX ME: cite this) provides an interchangeable memory allocator that can be replaced with a custom memory allocator that supports required features and fulfills application's custom needs. It also allows others to innovate in memory allocation and design their own memory allocator. GNU C Library has set guidelines that should be followed when designing a standalone memory allocator. GNU C Library requires new memory allocators to have atlease following set of functions in their allocator's interface:
     33
     34\begin{itemize}
     35\item
     36malloc: it allocates and returns a chunk of dynamic memory of requested size (FIX ME: cite man page).
     37\item
     38calloc: it allocates and returns an array in dynamic memory of requested size (FIX ME: cite man page).
     39\item
     40realloc: it reallocates and returns an already allocated chunk of dynamic memory to a new size (FIX ME: cite man page).
     41\item
     42free: it frees an already allocated piece of dynamic memory (FIX ME: cite man page).
     43\end{itemize}
     44
     45In addition to the above functions, GNU C Library also provides some more functions to increase the usability of the dynamic memory allocator. Most standalone allocators also provide all or some of the above additional functions.
     46
     47\begin{itemize}
     48\item
     49aligned_alloc
     50\item
     51malloc_usable_size
     52\item
     53memalign
     54\item
     55posix_memalign
     56\item
     57pvalloc
     58\item
     59valloc
     60\end{itemize}
     61
     62With the rise of concurrent applications, memory allocators should be able to fulfill dynamic memory requests from multiple threads in parallel without causing contention on shared resources. There needs to be a set of a standard benchmarks that can be used to evaluate an allocator's performance in different scenerios.
     63
     64\section{Background}
     65
     66\subsection{Memory Allocation}
     67With dynamic allocation being an important feature of C, there are many standalone memory allocators that have been designed for different purposes. For this thesis, we chose 7 of the most popular and widely used memory allocators.
     68
     69\paragraph{dlmalloc}
     70dlmalloc (FIX ME: cite allocator) is a thread-safe allocator that is single threaded and single heap. dlmalloc maintains free-lists of different sizes to store freed dynamic memory. (FIX ME: cite wasik)
     71
     72\paragraph{hoard}
     73Hoard (FIX ME: cite allocator) is a thread-safe allocator that is multi-threaded and using a heap layer framework. It has per-thred heaps that have thread-local free-lists, and a gloabl shared heap. (FIX ME: cite wasik)
     74
     75\paragraph{jemalloc}
     76jemalloc (FIX ME: cite allocator) is a thread-safe allocator that uses multiple arenas. Each thread is assigned an arena. Each arena has chunks that contain contagious memory regions of same size. An arena has multiple chunks that contain regions of multiple sizes.
     77
     78\paragraph{ptmalloc}
     79ptmalloc (FIX ME: cite allocator) is a modification of dlmalloc. It is a thread-safe multi-threaded memory allocator that uses multiple heaps. ptmalloc heap has similar design to dlmalloc's heap.
     80
     81\paragraph{rpmalloc}
     82rpmalloc (FIX ME: cite allocator) is a thread-safe allocator that is multi-threaded and uses per-thread heap. Each heap has multiple size-classes and each size-calss contains memory regions of the relevant size.
     83
     84\paragraph{tbb malloc}
     85tbb malloc (FIX ME: cite allocator) is a thread-safe allocator that is multi-threaded and uses private heap for each thread. Each private-heap has multiple bins of different sizes. Each bin contains free regions of the same size.
     86
     87\paragraph{tc malloc}
     88tcmalloc (FIX ME: cite allocator) is a thread-safe allocator. It uses per-thread cache to store free objects that prevents contention on shared resources in multi-threaded application. A central free-list is used to refill per-thread cache when it gets empty.
     89
     90\subsection{Benchmarks}
     91There are multiple benchmarks that are built individually and evaluate different aspects of a memory allocator. But, there is not standard set of benchamrks that can be used to evaluate multiple aspects of memory allocators.
     92
     93\paragraph{threadtest}
     94(FIX ME: cite benchmark and hoard) Each thread repeatedly allocates and then deallocates 100,000 objects. Runtime of the benchmark evaluates its efficiency.
     95
     96\paragraph{shbench}
     97(FIX ME: cite benchmark and hoard) Each thread allocates and randomly frees a number of random-sized objects. It is a stress test that also uses runtime to determine efficiency of the allocator.
     98
     99\paragraph{larson}
     100(FIX ME: cite benchmark and hoard) Larson simulates a server environment. Multiple threads are created where each thread allocator and free a number of objects within a size range. Some objects are passed from threads to the child threads to free. It caluculates memory operations per second as an indicator of memory allocator's performance.
     101
     102\section{Research Objectives}
     103Our research objective in this thesis is to:
     104
     105\begin{itemize}
     106\item
     107Design a lightweight concurrent memory allocator with added features and usability that are currently not present in the other memory allocators.
     108\item
     109Design a suite of benchmarks to evalute multiple aspects of a memory allocator.
     110\end{itemize}
     111
     112\section{An outline of the thesis}
     113LAST FIX ME: add outline at the end
  • example/io/simple/server.c

    rd83b266 r0a061c0  
    105105                                }
    106106
    107                                 printf("'%.*s'\n", cqe->res, data);
     107                                printf("'%.*s'\n", cqe->res - 1, data);
    108108
    109109                                async_read( newsock );
  • libcfa/prelude/sync-builtins.cf

    rd83b266 r0a061c0  
    297297
    298298_Bool __atomic_exchange_n(volatile _Bool *, _Bool, int);
    299 void __atomic_exchange(volatile _Bool *, volatile _Bool *, volatile _Bool *, int);
     299void __atomic_exchange(volatile _Bool *, _Bool *, _Bool *, int);
    300300char __atomic_exchange_n(volatile char *, char, int);
    301 void __atomic_exchange(volatile char *, volatile char *, volatile char *, int);
     301void __atomic_exchange(volatile char *, char *, char *, int);
    302302signed char __atomic_exchange_n(volatile signed char *, signed char, int);
    303 void __atomic_exchange(volatile signed char *, volatile signed char *, volatile signed char *, int);
     303void __atomic_exchange(volatile signed char *, signed char *, signed char *, int);
    304304unsigned char __atomic_exchange_n(volatile unsigned char *, unsigned char, int);
    305 void __atomic_exchange(volatile unsigned char *, volatile unsigned char *, volatile unsigned char *, int);
     305void __atomic_exchange(volatile unsigned char *, unsigned char *, unsigned char *, int);
    306306signed short __atomic_exchange_n(volatile signed short *, signed short, int);
    307 void __atomic_exchange(volatile signed short *, volatile signed short *, volatile signed short *, int);
     307void __atomic_exchange(volatile signed short *, signed short *, signed short *, int);
    308308unsigned short __atomic_exchange_n(volatile unsigned short *, unsigned short, int);
    309 void __atomic_exchange(volatile unsigned short *, volatile unsigned short *, volatile unsigned short *, int);
     309void __atomic_exchange(volatile unsigned short *, unsigned short *, unsigned short *, int);
    310310signed int __atomic_exchange_n(volatile signed int *, signed int, int);
    311 void __atomic_exchange(volatile signed int *, volatile signed int *, volatile signed int *, int);
     311void __atomic_exchange(volatile signed int *, signed int *, signed int *, int);
    312312unsigned int __atomic_exchange_n(volatile unsigned int *, unsigned int, int);
    313 void __atomic_exchange(volatile unsigned int *, volatile unsigned int *, volatile unsigned int *, int);
     313void __atomic_exchange(volatile unsigned int *, unsigned int *, unsigned int *, int);
    314314signed long int __atomic_exchange_n(volatile signed long int *, signed long int, int);
    315 void __atomic_exchange(volatile signed long int *, volatile signed long int *, volatile signed long int *, int);
     315void __atomic_exchange(volatile signed long int *, signed long int *, signed long int *, int);
    316316unsigned long int __atomic_exchange_n(volatile unsigned long int *, unsigned long int, int);
    317 void __atomic_exchange(volatile unsigned long int *, volatile unsigned long int *, volatile unsigned long int *, int);
     317void __atomic_exchange(volatile unsigned long int *, unsigned long int *, unsigned long int *, int);
    318318signed long long int __atomic_exchange_n(volatile signed long long int *, signed long long int, int);
    319 void __atomic_exchange(volatile signed long long int *, volatile signed long long int *, volatile signed long long int *, int);
     319void __atomic_exchange(volatile signed long long int *, signed long long int *, signed long long int *, int);
    320320unsigned long long int __atomic_exchange_n(volatile unsigned long long int *, unsigned long long int, int);
    321 void __atomic_exchange(volatile unsigned long long int *, volatile unsigned long long int *, volatile unsigned long long int *, int);
     321void __atomic_exchange(volatile unsigned long long int *, unsigned long long int *, unsigned long long int *, int);
    322322#if defined(__SIZEOF_INT128__)
    323323signed __int128 __atomic_exchange_n(volatile signed __int128 *, signed __int128, int);
    324 void __atomic_exchange(volatile signed __int128 *, volatile signed __int128 *, volatile signed __int128 *, int);
     324void __atomic_exchange(volatile signed __int128 *, signed __int128 *, signed __int128 *, int);
    325325unsigned __int128 __atomic_exchange_n(volatile unsigned __int128 *, unsigned __int128, int);
    326 void __atomic_exchange(volatile unsigned __int128 *, volatile unsigned __int128 *, volatile unsigned __int128 *, int);
     326void __atomic_exchange(volatile unsigned __int128 *, unsigned __int128 *, unsigned __int128 *, int);
    327327#endif
    328328forall(T &) T * __atomic_exchange_n(T * volatile *, T *, int);
    329 forall(T &) void __atomic_exchange(T * volatile *, T * volatile *, T * volatile *, int);
     329forall(T &) void __atomic_exchange(T * volatile *, T **, T **, int);
    330330
    331331_Bool __atomic_load_n(const volatile _Bool *, int);
    332 void __atomic_load(const volatile _Bool *, volatile _Bool *, int);
     332void __atomic_load(const volatile _Bool *, _Bool *, int);
    333333char __atomic_load_n(const volatile char *, int);
    334 void __atomic_load(const volatile char *, volatile char *, int);
     334void __atomic_load(const volatile char *, char *, int);
    335335signed char __atomic_load_n(const volatile signed char *, int);
    336 void __atomic_load(const volatile signed char *, volatile signed char *, int);
     336void __atomic_load(const volatile signed char *, signed char *, int);
    337337unsigned char __atomic_load_n(const volatile unsigned char *, int);
    338 void __atomic_load(const volatile unsigned char *, volatile unsigned char *, int);
     338void __atomic_load(const volatile unsigned char *, unsigned char *, int);
    339339signed short __atomic_load_n(const volatile signed short *, int);
    340 void __atomic_load(const volatile signed short *, volatile signed short *, int);
     340void __atomic_load(const volatile signed short *, signed short *, int);
    341341unsigned short __atomic_load_n(const volatile unsigned short *, int);
    342 void __atomic_load(const volatile unsigned short *, volatile unsigned short *, int);
     342void __atomic_load(const volatile unsigned short *, unsigned short *, int);
    343343signed int __atomic_load_n(const volatile signed int *, int);
    344 void __atomic_load(const volatile signed int *, volatile signed int *, int);
     344void __atomic_load(const volatile signed int *, signed int *, int);
    345345unsigned int __atomic_load_n(const volatile unsigned int *, int);
    346 void __atomic_load(const volatile unsigned int *, volatile unsigned int *, int);
     346void __atomic_load(const volatile unsigned int *, unsigned int *, int);
    347347signed long int __atomic_load_n(const volatile signed long int *, int);
    348 void __atomic_load(const volatile signed long int *, volatile signed long int *, int);
     348void __atomic_load(const volatile signed long int *, signed long int *, int);
    349349unsigned long int __atomic_load_n(const volatile unsigned long int *, int);
    350 void __atomic_load(const volatile unsigned long int *, volatile unsigned long int *, int);
     350void __atomic_load(const volatile unsigned long int *, unsigned long int *, int);
    351351signed long long int __atomic_load_n(const volatile signed long long int *, int);
    352 void __atomic_load(const volatile signed long long int *, volatile signed long long int *, int);
     352void __atomic_load(const volatile signed long long int *, signed long long int *, int);
    353353unsigned long long int __atomic_load_n(const volatile unsigned long long int *, int);
    354 void __atomic_load(const volatile unsigned long long int *, volatile unsigned long long int *, int);
     354void __atomic_load(const volatile unsigned long long int *, unsigned long long int *, int);
    355355#if defined(__SIZEOF_INT128__)
    356356signed __int128 __atomic_load_n(const volatile signed __int128 *, int);
    357 void __atomic_load(const volatile signed __int128 *, volatile signed __int128 *, int);
     357void __atomic_load(const volatile signed __int128 *, signed __int128 *, int);
    358358unsigned __int128 __atomic_load_n(const volatile unsigned __int128 *, int);
    359 void __atomic_load(const volatile unsigned __int128 *, volatile unsigned __int128 *, int);
     359void __atomic_load(const volatile unsigned __int128 *, unsigned __int128 *, int);
    360360#endif
    361361forall(T &) T * __atomic_load_n(T * const volatile *, int);
  • libcfa/src/fstream.cfa

    rd83b266 r0a061c0  
    1010// Created On       : Wed May 27 17:56:53 2015
    1111// Last Modified By : Peter A. Buhr
    12 // Last Modified On : Thu Jul 22 11:34:41 2021
    13 // Update Count     : 448
     12// Last Modified On : Thu Jul 29 22:34:10 2021
     13// Update Count     : 454
    1414//
    1515
     
    142142
    143143        if ( fclose( (FILE *)(os.file$) ) == EOF ) {
    144                 abort | IO_MSG "close output" | nl | strerror( errno );
     144                throw (Close_Failure){ os };
     145                // abort | IO_MSG "close output" | nl | strerror( errno );
    145146        } // if
    146147        os.file$ = 0p;
     
    149150ofstream & write( ofstream & os, const char data[], size_t size ) {
    150151        if ( fail( os ) ) {
    151                 abort | IO_MSG "attempt write I/O on failed stream";
     152                throw (Write_Failure){ os };
     153                // abort | IO_MSG "attempt write I/O on failed stream";
    152154        } // if
    153155
    154156        if ( fwrite( data, 1, size, (FILE *)(os.file$) ) != size ) {
    155                 abort | IO_MSG "write" | nl | strerror( errno );
     157                throw (Write_Failure){ os };
     158                // abort | IO_MSG "write" | nl | strerror( errno );
    156159        } // if
    157160        return os;
     
    277280
    278281        if ( fclose( (FILE *)(is.file$) ) == EOF ) {
    279                 abort | IO_MSG "close input" | nl | strerror( errno );
     282                throw (Close_Failure){ is };
     283                // abort | IO_MSG "close input" | nl | strerror( errno );
    280284        } // if
    281285        is.file$ = 0p;
     
    284288ifstream & read( ifstream & is, char data[], size_t size ) {
    285289        if ( fail( is ) ) {
    286                 abort | IO_MSG "attempt read I/O on failed stream";
     290                throw (Read_Failure){ is };
     291                // abort | IO_MSG "attempt read I/O on failed stream";
    287292        } // if
    288293
    289294        if ( fread( data, size, 1, (FILE *)(is.file$) ) == 0 ) {
    290                 abort | IO_MSG "read" | nl | strerror( errno );
     295                throw (Read_Failure){ is };
     296                // abort | IO_MSG "read" | nl | strerror( errno );
    291297        } // if
    292298        return is;
     
    338344
    339345
    340 //EHM_VIRTUAL_TABLE(Open_Failure, Open_Failure_main_table);
    341 static vtable(Open_Failure) Open_Failure_main_table;
     346static vtable(Open_Failure) Open_Failure_vt;
    342347
    343348// exception I/O constructors
    344349void ?{}( Open_Failure & this, ofstream & ostream ) {
    345         this.virtual_table = &Open_Failure_main_table;
     350        this.virtual_table = &Open_Failure_vt;
    346351        this.ostream = &ostream;
    347352        this.tag = 1;
     
    349354
    350355void ?{}( Open_Failure & this, ifstream & istream ) {
    351         this.virtual_table = &Open_Failure_main_table;
     356        this.virtual_table = &Open_Failure_vt;
    352357        this.istream = &istream;
    353358        this.tag = 0;
    354359} // ?{}
    355360
    356 void throwOpen_Failure( ofstream & ostream ) {
    357         Open_Failure exc = { ostream };
    358 }
    359 
    360 void throwOpen_Failure( ifstream & istream ) {
    361         Open_Failure exc = { istream };
    362 }
     361
     362static vtable(Close_Failure) Close_Failure_vt;
     363
     364// exception I/O constructors
     365void ?{}( Close_Failure & this, ofstream & ostream ) {
     366        this.virtual_table = &Close_Failure_vt;
     367        this.ostream = &ostream;
     368        this.tag = 1;
     369} // ?{}
     370
     371void ?{}( Close_Failure & this, ifstream & istream ) {
     372        this.virtual_table = &Close_Failure_vt;
     373        this.istream = &istream;
     374        this.tag = 0;
     375} // ?{}
     376
     377
     378static vtable(Write_Failure) Write_Failure_vt;
     379
     380// exception I/O constructors
     381void ?{}( Write_Failure & this, ofstream & ostream ) {
     382        this.virtual_table = &Write_Failure_vt;
     383        this.ostream = &ostream;
     384        this.tag = 1;
     385} // ?{}
     386
     387void ?{}( Write_Failure & this, ifstream & istream ) {
     388        this.virtual_table = &Write_Failure_vt;
     389        this.istream = &istream;
     390        this.tag = 0;
     391} // ?{}
     392
     393
     394static vtable(Read_Failure) Read_Failure_vt;
     395
     396// exception I/O constructors
     397void ?{}( Read_Failure & this, ofstream & ostream ) {
     398        this.virtual_table = &Read_Failure_vt;
     399        this.ostream = &ostream;
     400        this.tag = 1;
     401} // ?{}
     402
     403void ?{}( Read_Failure & this, ifstream & istream ) {
     404        this.virtual_table = &Read_Failure_vt;
     405        this.istream = &istream;
     406        this.tag = 0;
     407} // ?{}
     408
     409// void throwOpen_Failure( ofstream & ostream ) {
     410//      Open_Failure exc = { ostream };
     411// }
     412
     413// void throwOpen_Failure( ifstream & istream ) {
     414//      Open_Failure exc = { istream };
     415// }
    363416
    364417// Local Variables: //
  • libcfa/src/fstream.hfa

    rd83b266 r0a061c0  
    1010// Created On       : Wed May 27 17:56:53 2015
    1111// Last Modified By : Peter A. Buhr
    12 // Last Modified On : Tue Jul 20 21:18:03 2021
    13 // Update Count     : 232
     12// Last Modified On : Wed Jul 28 07:35:50 2021
     13// Update Count     : 234
    1414//
    1515
     
    160160void ?{}( Open_Failure & this, ifstream & );
    161161
     162exception Close_Failure {
     163        union {
     164                ofstream * ostream;
     165                ifstream * istream;
     166        };
     167        // TEMPORARY: need polymorphic exceptions
     168        int tag;                                                                                        // 1 => ostream; 0 => istream
     169};
     170
     171void ?{}( Close_Failure & this, ofstream & );
     172void ?{}( Close_Failure & this, ifstream & );
     173
     174exception Write_Failure {
     175        union {
     176                ofstream * ostream;
     177                ifstream * istream;
     178        };
     179        // TEMPORARY: need polymorphic exceptions
     180        int tag;                                                                                        // 1 => ostream; 0 => istream
     181};
     182
     183void ?{}( Write_Failure & this, ofstream & );
     184void ?{}( Write_Failure & this, ifstream & );
     185
     186exception Read_Failure {
     187        union {
     188                ofstream * ostream;
     189                ifstream * istream;
     190        };
     191        // TEMPORARY: need polymorphic exceptions
     192        int tag;                                                                                        // 1 => ostream; 0 => istream
     193};
     194
     195void ?{}( Read_Failure & this, ofstream & );
     196void ?{}( Read_Failure & this, ifstream & );
     197
    162198// Local Variables: //
    163199// mode: c //
  • src/ControlStruct/ExceptDecl.cc

    rd83b266 r0a061c0  
    1010// Created On       : Tue Jul 20 04:10:50 2021
    1111// Last Modified By : Henry Xue
    12 // Last Modified On : Mon Jul 26 12:55:28 2021
    13 // Update Count     : 3
     12// Last Modified On : Tue Aug 03 10:42:26 2021
     13// Update Count     : 4
    1414//
    1515
     
    278278        cloneAll( forallClause, structDecl->parameters );
    279279        return structDecl;
     280}
     281
     282ObjectDecl * ehmTypeIdExtern(
     283        const std::string & exceptionName,
     284        const std::list< Expression *> & parameters
     285) {
     286        StructInstType * typeIdType = new StructInstType(
     287                Type::Const,
     288                Virtual::typeIdType( exceptionName )
     289        );
     290        cloneAll( parameters, typeIdType->parameters );
     291        return new ObjectDecl(
     292                Virtual::typeIdName( exceptionName ),
     293                Type::Extern,
     294                LinkageSpec::Cforall,
     295                nullptr,
     296                typeIdType,
     297                nullptr,
     298                { new Attribute( "cfa_linkonce" ) }
     299        );
    280300}
    281301
     
    421441
    422442                if ( objectDecl->get_storageClasses().is_extern ) { // if extern
     443                        if ( !parameters.empty() ) { // forall variant
     444                                declsToAddBefore.push_back( ehmTypeIdExtern( exceptionName, parameters ) );
     445                        }
    423446                        return ehmExternVtable( exceptionName, parameters, tableName );
    424447                }
  • src/ControlStruct/ExceptTranslate.cc

    rd83b266 r0a061c0  
    99// Author           : Andrew Beach
    1010// Created On       : Wed Jun 14 16:49:00 2017
    11 // Last Modified By : Andrew Beach
    12 // Last Modified On : Wed Jun 24 11:18:00 2020
    13 // Update Count     : 17
     11// Last Modified By : Henry Xue
     12// Last Modified On : Tue Aug 03 10:05:51 2021
     13// Update Count     : 18
    1414//
    1515
     
    320320                                static_cast<ObjectDecl *>( handler->get_decl() );
    321321                        ObjectDecl * local_except = handler_decl->clone();
    322                         local_except->set_init(
    323                                 new ListInit({ new SingleInit(
    324                                         new VirtualCastExpr( nameOf( except_obj ),
    325                                                 local_except->get_type()
    326                                                 )
    327                                         ) })
     322                        VirtualCastExpr * vcex = new VirtualCastExpr(
     323                                nameOf( except_obj ),
     324                                local_except->get_type()
    328325                                );
     326                        vcex->location = handler->location;
     327                        local_except->set_init( new ListInit({ new SingleInit( vcex ) }) );
    329328                        block->push_back( new DeclStmt( local_except ) );
    330329
     
    392391
    393392                // Check for type match.
    394                 Expression * cond = UntypedExpr::createAssign( nameOf( local_except ),
    395                         new VirtualCastExpr( nameOf( except_obj ),
    396                                 local_except->get_type()->clone() ) );
     393                VirtualCastExpr * vcex = new VirtualCastExpr(
     394                        nameOf( except_obj ),
     395                        local_except->get_type()->clone()
     396                        );
     397                vcex->location = modded_handler->location;
     398                Expression * cond = UntypedExpr::createAssign(
     399                        nameOf( local_except ), vcex );
    397400
    398401                // Add the check on the conditional if it is provided.
Note: See TracChangeset for help on using the changeset viewer.