Changeset 02b73ea

Ignore:
Timestamp:
Jan 15, 2021, 6:27:20 PM (8 months ago)
Branches:
arm-eh, jacob/cs343-translation, master, new-ast-unique-expr
Children:
0cc43e1, 35ea4f3
Parents:
77ff383
Message:

Andrew MMath: Added some features and cleaned up future.tex.

Location:
doc/theses/andrew_beach_MMath
Files:
2 edited

Legend:

Unmodified
 r77ff383 of they virtual system was designed and implemented. Virtual types are organizied in simple hierarchies. Each virtual type may have Virtual types are organized in simple hierarchies. Each virtual type may have a parent and can have any number of children. A type's descendants are its children and its children's descendants. A type may not be its own descendant. structure that has fields for all the virtual members of a type. A virtual type has all the virtual members of its parent and can add more. It may also update the values of the virtual members. update the values of the virtual members and should in many cases. Except for virtual casts, this is only used internally in the exception \end{lstlisting} This has the same precidence as a traditional C-cast and can be used in the This has the same precedence as a traditional C-cast and can be used in the same places. This will convert the result of EXPRESSION to the type TYPE. Both the type of EXPRESSION and TYPE must be pointers to virtual types. % features all exceptions support. \subsection{Exception Traits} Exceptions are defined by the trait system; there are a series of traits and if a type satisfies them then they can be used as exceptions. \begin{lstlisting} trait is_exception(dtype exceptT, dtype virtualT) { virtualT const & get_exception_vtable(exceptT *); }; \end{lstlisting} This is the base trait that all exceptions need to match. The single function takes any pointer (including the null pointer) and returns a reference to the virtual table instance. Defining this function also establishes the virtual type and virtual table pair to the resolver and promises that \codeCFA{exceptT} is a virtual type and a child of the base exception type. One odd thing about \codeCFA{get_exception_vtable} is that it should always be a constant function, returning the same value regardless of its argument. A pointer or reference to the virtual table instance could be used instead, however using a function has some ease of implementation advantages and allows for easier disambiguation because the virtual type name (or the address of an instance that is in scope) can be used instead of the mangled virtual table name. Also note the use of the word promise" in the trait description. \CFA cannot currently check to see if either \codeCFA{exceptT} or \codeCFA{virtualT} match the layout requirements. Currently this is considered part of \codeCFA{get_exception_vtable}'s correct implementation. \begin{lstlisting} trait is_termination_exception( dtype exceptT, dtype virtualT | is_exception(exceptT, virtualT)) { void defaultTerminationHandler(exceptT &); }; \end{lstlisting} The only additional function required to make the exception usable with termination is a default handler. This function is called whenever a termination throw on an exception of this type is preformed and no handler is found. \begin{lstlisting} trait is_resumption_exception( dtype exceptT, dtype virtualT | is_exception(exceptT, virtualT)) { void defaultResumptionHandler(exceptT &); }; \end{lstlisting} Creating a resumption exception is exactly the same except for resumption. The name change reflects that and the function is called when a resumption throw on an exception of this type is preformed and no handler is found. Finally there are three additional macros that can be used to refer to the these traits. They are \codeCFA{IS_EXCEPTION}, \codeCFA{IS_TERMINATION_EXCEPTION} and \codeCFA{IS_RESUMPTION_EXCEPTION}. Each takes the virtual type's name and, for polymorphic types only, the parenthesized list of polymorphic arguments. These do the name mangling to get the virtual table name and provide the arguments to both sides. \section{Termination} Termination exception throws are likely the most framilar kind, as they are Termination exception throws are likely the most familiar kind, as they are used in several popular programming languages. A termination will throw an exception, search the stack for a handler, unwind the stack to where the Then the exception system will search the stack starting from the throw and proceding towards the base of the stack, from callee to caller. As it goes proceeding towards the base of the stack, from callee to caller. As it goes it will check any termination handlers it finds: \paragraph{Re-Throwing} You can also rethrow the most recent termination exception with You can also re-throw the most recent termination exception with \codeCFA{throw;}. % This is terrible and you should never do it. This can be done in a handler or any function that could be called from a \end{lstlisting} The result of EXPRESSION must be a resumption exception type. A resumption exception type is any type that satifies the assertion exception type is any type that satisfies the assertion \codeCFA{void defaultResumptionHandler(T &);} (the default handler). When the statement is executed the expression is evaluated and the result is thrown. continues from the throw statement. If no approprate handler is found then the default handler is called. The If no appropriate handler is found then the default handler is called. The throw statement acts as a regular function call passing the exception to the default handler and after the handler finishes executing control continues which is what most users expect. % This might need a diagram. But it is an important part of the justifaction % This might need a diagram. But it is an important part of the justification % of the design of the traversal order. It also avoids the recursive resumption problem. If the entire stack is system an A resumed from the top of the stack will be handled by the first handler. A B resumed from the top or from the first handler it will be handled by the second hander. The only difference is when A is thrown from the second by the second handler. The only difference is when A is thrown from the second handler. The entire stack search will call the first handler again, creating a loop. Starting from the position in the stack though will break this loop. It also has the same behaviour, after the exception type has been matched with the EXCEPTION\_TYPE the CONDITION is evaluated with NAME in scope. If the result is true then the hander is run, otherwise the search continues the result is true then the handler is run, otherwise the search continues just as if there had been a type mismatch. the finally block. Other ways to leave the finally block - such as a long jump or termination - are much harder to check, at best requiring additional runtime overhead, and so are merely discouraged. run-time overhead, and so are merely discouraged. \section{Cancellation} There is no special statement for starting a cancellation, instead you call the standard libary function \codeCFA{cancel\_stack} which takes an exception. the standard library function \codeCFA{cancel\_stack} which takes an exception. Unlike in a throw this exception is not used in control flow but is just there to pass information about why the cancellation happened. The handler is decided entirely by which stack is being cancelled. There are The handler is decided entirely by which stack is being canceled. There are three handlers that apply to three different groups of stacks: \begin{itemize} \item Thread Stack: Thread stacks are those created \codeCFA{thread} or otherwise satify the Thread stacks are those created \codeCFA{thread} or otherwise satisfy the \codeCFA{is\_thread} trait. context required for the other. This can happen with join but as the destructors will always be run when the stack is being unwound and one termination/cancellation is already active. Also since they are implicite they termination/cancellation is already active. Also since they are implicit they are easier to forget about. \item Coroutine Stack: Coroutine stacks are those created with \codeCFA{coroutine} or otherwise satify the \codeCFA{is\_coroutine} trait. satisfy the \codeCFA{is\_coroutine} trait. A coroutine knows of two other coroutines, its starter and its last resumer. Resume will resume throw a \codeCFA{CoroutineCancelled} exception, which is polymorphic over the coroutine type and has a pointer to the coroutine being cancelled and the cancelling exception. The resume function also has an canceled and the canceling exception. The resume function also has an assertion that the \codeCFA{defaultResumptionHandler} for the exception. So it will use the default handler like a regular throw.