Changeset 02b73ea for doc/theses/andrew_beach_MMath/features.tex
- Timestamp:
- Jan 15, 2021, 6:27:20 PM (4 years ago)
- Branches:
- ADT, arm-eh, ast-experimental, enum, forall-pointer-decay, jacob/cs343-translation, master, new-ast-unique-expr, pthread-emulation, qualifiedEnum
- Children:
- 0cc43e1, 35ea4f3
- Parents:
- 77ff383
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
doc/theses/andrew_beach_MMath/features.tex
r77ff383 r02b73ea 10 10 of they virtual system was designed and implemented. 11 11 12 Virtual types are organiz ied in simple hierarchies. Each virtual type may have12 Virtual types are organized in simple hierarchies. Each virtual type may have 13 13 a parent and can have any number of children. A type's descendants are its 14 14 children and its children's descendants. A type may not be its own descendant. … … 17 17 structure that has fields for all the virtual members of a type. A virtual 18 18 type has all the virtual members of its parent and can add more. It may also 19 update the values of the virtual members .19 update the values of the virtual members and should in many cases. 20 20 21 21 Except for virtual casts, this is only used internally in the exception … … 27 27 \end{lstlisting} 28 28 29 This has the same prec idence as a traditional C-cast and can be used in the29 This has the same precedence as a traditional C-cast and can be used in the 30 30 same places. This will convert the result of EXPRESSION to the type TYPE. Both 31 31 the type of EXPRESSION and TYPE must be pointers to virtual types. … … 41 41 % features all exceptions support. 42 42 43 \subsection{Exception Traits} 44 Exceptions are defined by the trait system; there are a series of traits and 45 if a type satisfies them then they can be used as exceptions. 46 47 \begin{lstlisting} 48 trait is_exception(dtype exceptT, dtype virtualT) { 49 virtualT const & get_exception_vtable(exceptT *); 50 }; 51 \end{lstlisting} 52 This is the base trait that all exceptions need to match. 53 The single function takes any pointer (including the null pointer) and 54 returns a reference to the virtual table instance. Defining this function 55 also establishes the virtual type and virtual table pair to the resolver 56 and promises that \codeCFA{exceptT} is a virtual type and a child of the 57 base exception type. 58 59 One odd thing about \codeCFA{get_exception_vtable} is that it should always 60 be a constant function, returning the same value regardless of its argument. 61 A pointer or reference to the virtual table instance could be used instead, 62 however using a function has some ease of implementation advantages and 63 allows for easier disambiguation because the virtual type name (or the 64 address of an instance that is in scope) can be used instead of the mangled 65 virtual table name. 66 67 Also note the use of the word ``promise" in the trait description. \CFA 68 cannot currently check to see if either \codeCFA{exceptT} or 69 \codeCFA{virtualT} match the layout requirements. Currently this is 70 considered part of \codeCFA{get_exception_vtable}'s correct implementation. 71 72 \begin{lstlisting} 73 trait is_termination_exception( 74 dtype exceptT, dtype virtualT | is_exception(exceptT, virtualT)) { 75 void defaultTerminationHandler(exceptT &); 76 }; 77 \end{lstlisting} 78 The only additional function required to make the exception usable with 79 termination is a default handler. This function is called whenever a 80 termination throw on an exception of this type is preformed and no handler 81 is found. 82 83 \begin{lstlisting} 84 trait is_resumption_exception( 85 dtype exceptT, dtype virtualT | is_exception(exceptT, virtualT)) { 86 void defaultResumptionHandler(exceptT &); 87 }; 88 \end{lstlisting} 89 Creating a resumption exception is exactly the same except for resumption. 90 The name change reflects that and the function is called when a resumption 91 throw on an exception of this type is preformed and no handler is found. 92 93 Finally there are three additional macros that can be used to refer to the 94 these traits. They are \codeCFA{IS_EXCEPTION}, 95 \codeCFA{IS_TERMINATION_EXCEPTION} and \codeCFA{IS_RESUMPTION_EXCEPTION}. 96 Each takes the virtual type's name and, for polymorphic types only, the 97 parenthesized list of polymorphic arguments. These do the name mangling to 98 get the virtual table name and provide the arguments to both sides. 99 43 100 \section{Termination} 44 101 45 Termination exception throws are likely the most f ramilar kind, as they are102 Termination exception throws are likely the most familiar kind, as they are 46 103 used in several popular programming languages. A termination will throw an 47 104 exception, search the stack for a handler, unwind the stack to where the … … 66 123 67 124 Then the exception system will search the stack starting from the throw and 68 proce ding towards the base of the stack, from callee to caller. As it goes125 proceeding towards the base of the stack, from callee to caller. As it goes 69 126 it will check any termination handlers it finds: 70 127 … … 111 168 \paragraph{Re-Throwing} 112 169 113 You can also re throw the most recent termination exception with170 You can also re-throw the most recent termination exception with 114 171 \codeCFA{throw;}. % This is terrible and you should never do it. 115 172 This can be done in a handler or any function that could be called from a … … 135 192 \end{lstlisting} 136 193 The result of EXPRESSION must be a resumption exception type. A resumption 137 exception type is any type that sati fies the assertion194 exception type is any type that satisfies the assertion 138 195 \codeCFA{void defaultResumptionHandler(T &);} (the default handler). When the 139 196 statement is executed the expression is evaluated and the result is thrown. … … 159 216 continues from the throw statement. 160 217 161 If no appropr ate handler is found then the default handler is called. The218 If no appropriate handler is found then the default handler is called. The 162 219 throw statement acts as a regular function call passing the exception to 163 220 the default handler and after the handler finishes executing control continues … … 174 231 which is what most users expect. 175 232 176 % This might need a diagram. But it is an important part of the justif action233 % This might need a diagram. But it is an important part of the justification 177 234 % of the design of the traversal order. 178 235 It also avoids the recursive resumption problem. If the entire stack is … … 184 241 system an A resumed from the top of the stack will be handled by the first 185 242 handler. A B resumed from the top or from the first handler it will be handled 186 by the second hand er. The only difference is when A is thrown from the second243 by the second handler. The only difference is when A is thrown from the second 187 244 handler. The entire stack search will call the first handler again, creating a 188 245 loop. Starting from the position in the stack though will break this loop. … … 198 255 It also has the same behaviour, after the exception type has been matched 199 256 with the EXCEPTION\_TYPE the CONDITION is evaluated with NAME in scope. If 200 the result is true then the hand er is run, otherwise the search continues257 the result is true then the handler is run, otherwise the search continues 201 258 just as if there had been a type mismatch. 202 259 … … 241 298 the finally block. Other ways to leave the finally block - such as a long 242 299 jump or termination - are much harder to check, at best requiring additional 243 run time overhead, and so are merely discouraged.300 run-time overhead, and so are merely discouraged. 244 301 245 302 \section{Cancellation} … … 250 307 251 308 There is no special statement for starting a cancellation, instead you call 252 the standard lib ary function \codeCFA{cancel\_stack} which takes an exception.309 the standard library function \codeCFA{cancel\_stack} which takes an exception. 253 310 Unlike in a throw this exception is not used in control flow but is just there 254 311 to pass information about why the cancellation happened. 255 312 256 The handler is decided entirely by which stack is being cancel led. There are313 The handler is decided entirely by which stack is being canceled. There are 257 314 three handlers that apply to three different groups of stacks: 258 315 \begin{itemize} … … 266 323 267 324 \item Thread Stack: 268 Thread stacks are those created \codeCFA{thread} or otherwise sati fy the325 Thread stacks are those created \codeCFA{thread} or otherwise satisfy the 269 326 \codeCFA{is\_thread} trait. 270 327 … … 288 345 context required for the other. This can happen with join but as the 289 346 destructors will always be run when the stack is being unwound and one 290 termination/cancellation is already active. Also since they are implicit ethey347 termination/cancellation is already active. Also since they are implicit they 291 348 are easier to forget about. 292 349 293 350 \item Coroutine Stack: 294 351 Coroutine stacks are those created with \codeCFA{coroutine} or otherwise 295 sati fy the \codeCFA{is\_coroutine} trait.352 satisfy the \codeCFA{is\_coroutine} trait. 296 353 297 354 A coroutine knows of two other coroutines, its starter and its last resumer. … … 301 358 Resume will resume throw a \codeCFA{CoroutineCancelled} exception, which is 302 359 polymorphic over the coroutine type and has a pointer to the coroutine being 303 cancel led and the cancelling exception. The resume function also has an360 canceled and the canceling exception. The resume function also has an 304 361 assertion that the \codeCFA{defaultResumptionHandler} for the exception. So it 305 362 will use the default handler like a regular throw.
Note: See TracChangeset
for help on using the changeset viewer.