Changes in / [9373b6a:478c610]
- Files:
-
- 1 deleted
- 4 edited
-
doc/theses/andrew_beach_MMath/conclusion.tex (deleted)
-
doc/theses/andrew_beach_MMath/features.tex (modified) (32 diffs)
-
doc/theses/andrew_beach_MMath/uw-ethesis.tex (modified) (1 diff)
-
tests/io/manipulatorsOutput3.cfa (modified) (2 diffs)
-
tests/sum.cfa (modified) (5 diffs)
Legend:
- Unmodified
- Added
- Removed
-
doc/theses/andrew_beach_MMath/features.tex
r9373b6a r478c610 16 16 throw/catch as a particular kind of raise/handle. 17 17 These are the two parts that the user writes and may 18 be the only two pieces of the EHM that have any syntax in alanguage.18 be the only two pieces of the EHM that have any syntax in the language. 19 19 20 20 \paragraph{Raise} 21 The raise is the starting point for exception handling 22 by raising an exception, which passes it to21 The raise is the starting point for exception handling. It marks the beginning 22 of exception handling by raising an exception, which passes it to 23 23 the EHM. 24 24 25 25 Some well known examples include the @throw@ statements of \Cpp and Java and 26 the \code{Python}{raise} statement of Python. In real systems,a raise may27 p erform some other work (such as memory management) but for the26 the \code{Python}{raise} statement from Python. In real systems a raise may 27 preform some other work (such as memory management) but for the 28 28 purposes of this overview that can be ignored. 29 29 30 30 \paragraph{Handle} 31 The p rimary purpose of an EHM is to run some user code to handle a raised32 exception. This code is given, with some other information, in a handler.31 The purpose of most exception operations is to run some user code to handle 32 that exception. This code is given, with some other information, in a handler. 33 33 34 34 A handler has three common features: the previously mentioned user code, a 35 region of code it guards,and an exception label/condition that matches36 the raised exception.35 region of code they guard and an exception label/condition that matches 36 certain exceptions. 37 37 Only raises inside the guarded region and raising exceptions that match the 38 38 label can be handled by a given handler. 39 39 If multiple handlers could can handle an exception, 40 EHMs define a rule to pick one, such as ``best match" or ``first found".40 EHMs will define a rule to pick one, such as ``best match" or ``first found". 41 41 42 42 The @try@ statements of \Cpp, Java and Python are common examples. All three 43 show the common features of guarded region, raise, matching and handler. 44 \begin{cfa} 45 try { // guarded region 46 ... 47 throw exception; // raise 48 ... 49 } catch( exception ) { // matching condition, with exception label 50 ... // handler code 51 } 52 \end{cfa} 43 also show another common feature of handlers, they are grouped by the guarded 44 region. 53 45 54 46 \subsection{Propagation} 55 47 After an exception is raised comes what is usually the biggest step for the 56 EHM: finding and setting up the handler for execution. The propagation from raise to48 EHM: finding and setting up the handler. The propagation from raise to 57 49 handler can be broken up into three different tasks: searching for a handler, 58 50 matching against the handler and installing the handler. … … 60 52 \paragraph{Searching} 61 53 The EHM begins by searching for handlers that might be used to handle 62 the exception. The search is restricted to63 handlers that have the raise site in their guarded54 the exception. Searching is usually independent of the exception that was 55 thrown as it looks for handlers that have the raise site in their guarded 64 56 region. 65 57 The search includes handlers in the current function, as well as any in … … 67 59 68 60 \paragraph{Matching} 69 Each handler found ismatched with the raised exception. The exception70 label defines a condition that is used with theexception and decides if61 Each handler found has to be matched with the raised exception. The exception 62 label defines a condition that is used with exception and decides if 71 63 there is a match or not. 64 72 65 In languages where the first match is used, this step is intertwined with 73 searching; a match check is p erformed immediately after the search finds74 a handler.66 searching; a match check is preformed immediately after the search finds 67 a possible handler. 75 68 76 69 \paragraph{Installing} 77 After a handler is chosen ,it must be made ready to run.70 After a handler is chosen it must be made ready to run. 78 71 The implementation can vary widely to fit with the rest of the 79 72 design of the EHM. The installation step might be trivial or it could be … … 82 75 83 76 If a matching handler is not guaranteed to be found, the EHM needs a 84 different course of action for th is case.77 different course of action for the case where no handler matches. 85 78 This situation only occurs with unchecked exceptions as checked exceptions 86 (such as in Java) are guaranteed to find a matching handler.87 Th eunhandled action is usually very general, such as aborting the program.79 (such as in Java) can make the guarantee. 80 This unhandled action is usually very general, such as aborting the program. 88 81 89 82 \paragraph{Hierarchy} … … 92 85 exception hierarchy is a natural extension of the object hierarchy. 93 86 94 Consider the following exception hierarchy:87 Consider the following hierarchy of exceptions: 95 88 \begin{center} 96 89 \input{exception-hierarchy} 97 90 \end{center} 91 98 92 A handler labeled with any given exception can handle exceptions of that 99 93 type or any child type of that exception. The root of the exception hierarchy 100 (here \code{C}{exception}) acts as a catch-all, leaf types catch single types ,94 (here \code{C}{exception}) acts as a catch-all, leaf types catch single types 101 95 and the exceptions in the middle can be used to catch different groups of 102 96 related exceptions. 103 97 104 98 This system has some notable advantages, such as multiple levels of grouping, 105 the ability for libraries to add new exception types ,and the isolation99 the ability for libraries to add new exception types and the isolation 106 100 between different sub-hierarchies. 107 101 This design is used in \CFA even though it is not a object-orientated … … 116 110 is usually set up to do most of the work. 117 111 118 The EHM can return control to many different places, where112 The EHM can return control to many different places, 119 113 the most common are after the handler definition (termination) 120 114 and after the raise (resumption). … … 123 117 For effective exception handling, additional information is often passed 124 118 from the raise to the handler and back again. 125 So far , only communication of the exception's identity iscovered.126 A common communication method for passing more informationis putting fields into the exception instance119 So far only communication of the exceptions' identity has been covered. 120 A common communication method is putting fields into the exception instance 127 121 and giving the handler access to them. 128 Using reference fields pointing to data at the raise location allowsdata to be122 Passing the exception by reference instead of by value can allow data to be 129 123 passed in both directions. 130 124 131 125 \section{Virtuals} 132 126 Virtual types and casts are not part of \CFA's EHM nor are they required for 133 an EHM.134 However, one of the best ways to support an exception hierarchy127 any EHM. 128 However, it is one of the best ways to support an exception hierarchy 135 129 is via a virtual hierarchy and dispatch system. 136 130 137 Ideally, the virtual system should have been part of \CFA before the work131 Ideally, the virtual system would have been part of \CFA before the work 138 132 on exception handling began, but unfortunately it was not. 139 133 Hence, only the features and framework needed for the EHM were 140 designed and implemented for this thesis. Other features were considered to ensure that134 designed and implemented. Other features were considered to ensure that 141 135 the structure could accommodate other desirable features in the future 142 but are not implemented.143 The rest of this section only discusses the implemented subset of the144 virtual -system design.136 but they were not implemented. 137 The rest of this section will only discuss the implemented subset of the 138 virtual system design. 145 139 146 140 The virtual system supports multiple ``trees" of types. Each tree is … … 158 152 It is important to note that these are virtual members, not virtual methods 159 153 of object-orientated programming, and can be of any type. 160 161 \PAB{Need to look at these when done.162 154 163 155 \CFA still supports virtual methods as a special case of virtual members. … … 173 165 as a hidden field. 174 166 \todo{Might need a diagram for virtual structure.} 175 }%176 167 177 168 Up until this point the virtual system is similar to ones found in 178 object-orientated languages but this is where \CFA diverges. Objects encapsulate a 179 single set of methods in each type, universally across the entire program, 180 and indeed all programs that use that type definition. Even if a type inherits and adds methods, it still encapsulate a 181 single set of methods. In this sense, 182 object-oriented types are ``closed" and cannot be altered. 183 184 In \CFA, types do not encapsulate any code. Traits are local for each function and 185 types can satisfy a local trait, stop satisfying it or, satisfy the same 186 trait in a different way at any lexical location in the program where a function is call. 187 In this sense, the set of functions/variables that satisfy a trait for a type is ``open" as the set can change at every call site. 169 object-orientated languages but this where \CFA diverges. Objects encapsulate a 170 single set of behaviours in each type, universally across the entire program, 171 and indeed all programs that use that type definition. In this sense, the 172 types are ``closed" and cannot be altered. 173 174 In \CFA, types do not encapsulate any behaviour. Traits are local and 175 types can begin to satisfy a trait, stop satisfying a trait or satisfy the same 176 trait in a different way at any lexical location in the program. 177 In this sense, they are ``open" as they can change at any time. 188 178 This capability means it is impossible to pick a single set of functions 189 that represent a type's implementation across aprogram.179 that represent the type's implementation across the program. 190 180 191 181 \CFA side-steps this issue by not having a single virtual table for each 192 182 type. A user can define virtual tables that are filled in at their 193 183 declaration and given a name. Anywhere that name is visible, even if it is 194 defined locally inside a function \PAB{What does this mean?(although that means it does not have a195 static lifetime) }, it can be used.184 defined locally inside a function (although that means it does not have a 185 static lifetime), it can be used. 196 186 Specifically, a virtual type is ``bound" to a virtual table that 197 187 sets the virtual members for that object. The virtual members can be accessed … … 231 221 completing the virtual system). The imaginary assertions would probably come 232 222 from a trait defined by the virtual system, and state that the exception type 233 is a virtual type, is a descendant of @exception_t@ (the base exception type) ,223 is a virtual type, is a descendant of @exception_t@ (the base exception type) 234 224 and note its virtual table type. 235 225 … … 251 241 \end{cfa} 252 242 Both traits ensure a pair of types are an exception type, its virtual table 253 type ,243 type 254 244 and defines one of the two default handlers. The default handlers are used 255 245 as fallbacks and are discussed in detail in \vref{s:ExceptionHandling}. … … 260 250 facing way. So these three macros are provided to wrap these traits to 261 251 simplify referring to the names: 262 @IS_EXCEPTION@, @IS_TERMINATION_EXCEPTION@ ,and @IS_RESUMPTION_EXCEPTION@.252 @IS_EXCEPTION@, @IS_TERMINATION_EXCEPTION@ and @IS_RESUMPTION_EXCEPTION@. 263 253 264 254 All three take one or two arguments. The first argument is the name of the … … 282 272 \CFA provides two kinds of exception handling: termination and resumption. 283 273 These twin operations are the core of \CFA's exception handling mechanism. 284 This section coversthe general patterns shared by the two operations and285 then go es on to cover the details ofeach individual operation.274 This section will cover the general patterns shared by the two operations and 275 then go on to cover the details each individual operation. 286 276 287 277 Both operations follow the same set of steps. 288 First, a user raisesan exception.289 Second,the exception propagates up the stack.290 Third, if a handler is found,the exception is caught and the handler is run.278 Both start with the user preforming a raise on an exception. 279 Then the exception propagates up the stack. 280 If a handler is found the exception is caught and the handler is run. 291 281 After that control continues at a raise-dependent location. 292 Fourth, if a handler is not found,a default handler is run and, if it returns, then control282 If the search fails a default handler is run and, if it returns, then control 293 283 continues after the raise. 294 284 295 %This general description covers what the two kinds have in common.296 The differences in the two operations include how propagation is performed, where execution continues297 after an exception is caught and handled ,and which default handler is run.285 This general description covers what the two kinds have in common. 286 Differences include how propagation is preformed, where exception continues 287 after an exception is caught and handled and which default handler is run. 298 288 299 289 \subsection{Termination} 300 290 \label{s:Termination} 301 Termination handling is the familiar EHMand used in most programming291 Termination handling is the familiar kind and used in most programming 302 292 languages with exception handling. 303 293 It is a dynamic, non-local goto. If the raised exception is matched and … … 318 308 @is_termination_exception@ at the call site. 319 309 Through \CFA's trait system, the trait functions are implicitly passed into the 320 throw code for use bythe EHM.310 throw code and the EHM. 321 311 A new @defaultTerminationHandler@ can be defined in any scope to 322 change the throw's behaviour when a handler is not found(see below).312 change the throw's behaviour (see below). 323 313 324 314 The throw copies the provided exception into managed memory to ensure … … 330 320 % How to say propagation starts, its first sub-step is the search. 331 321 Then propagation starts with the search. \CFA uses a ``first match" rule so 332 matching is p erformed with the copied exception as the search key.333 It starts from the raise in the throwing function and proceeds towards thebase of the stack,322 matching is preformed with the copied exception as the search continues. 323 It starts from the throwing function and proceeds towards base of the stack, 334 324 from callee to caller. 335 At each stack frame, a check is made for termination handlers defined by the325 At each stack frame, a check is made for resumption handlers defined by the 336 326 @catch@ clauses of a @try@ statement. 337 327 \begin{cfa} … … 345 335 \end{cfa} 346 336 When viewed on its own, a try statement simply executes the statements 347 in the \snake{GUARDED_BLOCK},and when those are finished,337 in \snake{GUARDED_BLOCK} and when those are finished, 348 338 the try statement finishes. 349 339 … … 351 341 invoked functions, all the handlers in these statements are included in the 352 342 search path. 353 Hence, if a termination exception is raised ,these handlers may be matched343 Hence, if a termination exception is raised these handlers may be matched 354 344 against the exception and may handle it. 355 345 356 346 Exception matching checks the handler in each catch clause in the order 357 347 they appear, top to bottom. If the representation of the raised exception type 358 is the same or a descendant of @EXCEPTION_TYPE@$_i$ ,then @NAME@$_i$348 is the same or a descendant of @EXCEPTION_TYPE@$_i$ then @NAME@$_i$ 359 349 (if provided) is 360 350 bound to a pointer to the exception and the statements in @HANDLER_BLOCK@$_i$ … … 362 352 freed and control continues after the try statement. 363 353 364 If no termination handler is found during the search ,then the default handler365 (\defaultTerminationHandler) visible at the raise statement is called.366 Through \CFA's trait system the best match at the raise statement isused.354 If no termination handler is found during the search then the default handler 355 (\defaultTerminationHandler) visible at the raise statement is run. 356 Through \CFA's trait system the best match at the raise statement will be used. 367 357 This function is run and is passed the copied exception. 368 If the default handler finishes,control continues after the raise statement.358 If the default handler is run control continues after the raise statement. 369 359 370 360 There is a global @defaultTerminationHandler@ that is polymorphic over all 371 361 termination exception types. 362 Since it is so general a more specific handler can be 363 defined and is used for those types, effectively overriding the handler 364 for a particular exception type. 372 365 The global default termination handler performs a cancellation 373 (see \vref{s:Cancellation} for the justification) on the current stack with the copied exception. 374 Since it is so general, a more specific handler is usually 375 defined, possibly with a detailed message, and used for specific exception type, effectively overriding the default handler. 366 (see \vref{s:Cancellation}) on the current stack with the copied exception. 376 367 377 368 \subsection{Resumption} 378 369 \label{s:Resumption} 379 370 380 Resumption exception handling is the less familar EHM,but is371 Resumption exception handling is less common than termination but is 381 372 just as old~\cite{Goodenough75} and is simpler in many ways. 382 373 It is a dynamic, non-local function call. If the raised exception is 383 matched ,a closure is taken from up the stack and executed,374 matched a closure is taken from up the stack and executed, 384 375 after which the raising function continues executing. 385 376 The common uses for resumption exceptions include … … 387 378 function once the error is corrected, and 388 379 ignorable events, such as logging where nothing needs to happen and control 389 should always continue from the raise point.380 should always continue from the same place. 390 381 391 382 A resumption raise is started with the @throwResume@ statement: … … 401 392 the exception system while handling the exception. 402 393 403 At run-time, no exception copy is made , since404 resumption does not unwind the stack nor otherwise remove values from the405 current scope, so there is no need to manage memory to keep th e exceptionin scope.406 407 The n propagation starts with the search. Itstarts from the raise in the394 At run-time, no exception copy is made. 395 Resumption does not unwind the stack nor otherwise remove values from the 396 current scope, so there is no need to manage memory to keep things in scope. 397 398 The EHM then begins propagation. The search starts from the raise in the 408 399 resuming function and proceeds towards the base of the stack, 409 400 from callee to caller. … … 419 410 } 420 411 \end{cfa} 421 % PAB, you say this above.422 % When a try statement is executed, it simply executes the statements in the423 % @GUARDED_BLOCK@ and then finishes.424 %425 % However, while the guarded statements are being executed, including any426 % invoked functions, all the handlers in these statements are included in the427 % search path.428 % Hence, if a resumption exception is raised, these handlers may be matched429 % against the exception and may handle it.430 %431 % Exception matching checks the handler in each catch clause in the order432 % they appear, top to bottom. If the representation of the raised exception type433 % is the same or a descendant of @EXCEPTION_TYPE@$_i$, then @NAME@$_i$434 % (if provided) is bound to a pointer to the exception and the statements in435 % @HANDLER_BLOCK@$_i$ are executed.436 % If control reaches the end of the handler, execution continues after the437 % the raise statement that raised the handled exception.438 %439 % Like termination, if no resumption handler is found during the search,440 % then the default handler (\defaultResumptionHandler) visible at the raise441 % statement is called. It will use the best match at the raise sight according442 % to \CFA's overloading rules. The default handler is443 % passed the exception given to the raise. When the default handler finishes444 % execution continues after the raise statement.445 %446 % There is a global @defaultResumptionHandler{} is polymorphic over all447 % resumption exceptions and performs a termination throw on the exception.448 % The \defaultTerminationHandler{} can be overridden by providing a new449 % function that is a better match.450 451 The @GUARDED_BLOCK@ and its associated nested guarded statements work the same452 for resumption as for termination, as does exception matching at each453 @catchResume@. Similarly, if no resumption handler is found during the search,454 then the currently visible default handler (\defaultResumptionHandler) is455 called and control continues after the raise statement if it returns. Finally,456 there is also a global @defaultResumptionHandler@, which can be overridden,457 that is polymorphic over all resumption exceptions but performs a termination458 throw on the exception rather than a cancellation.459 460 Throwing the exception in @defaultResumptionHandler@ has the positive effect of461 walking the stack a second time for a recovery handler. Hence, a programmer has462 two chances for help with a problem, fixup or recovery, should either kind of463 handler appear on the stack. However, this dual stack walk leads to following464 apparent anomaly:465 \begin{cfa}466 try {467 throwResume E;468 } catch (E) {469 // this handler runs470 }471 \end{cfa}472 because the @catch@ appears to handle a @throwResume@, but a @throwResume@ only473 matches with @catchResume@. The anomaly results because the unmatched474 @catchResuem@, calls @defaultResumptionHandler@, which in turn throws @E@.475 476 412 % I wonder if there would be some good central place for this. 477 Note , terminationand resumption handlers may be used together413 Note that termination handlers and resumption handlers may be used together 478 414 in a single try statement, intermixing @catch@ and @catchResume@ freely. 479 415 Each type of handler only interacts with exceptions from the matching 480 416 kind of raise. 417 When a try statement is executed, it simply executes the statements in the 418 @GUARDED_BLOCK@ and then finishes. 419 420 However, while the guarded statements are being executed, including any 421 invoked functions, all the handlers in these statements are included in the 422 search path. 423 Hence, if a resumption exception is raised these handlers may be matched 424 against the exception and may handle it. 425 426 Exception matching checks the handler in each catch clause in the order 427 they appear, top to bottom. If the representation of the raised exception type 428 is the same or a descendant of @EXCEPTION_TYPE@$_i$ then @NAME@$_i$ 429 (if provided) is bound to a pointer to the exception and the statements in 430 @HANDLER_BLOCK@$_i$ are executed. 431 If control reaches the end of the handler, execution continues after the 432 the raise statement that raised the handled exception. 433 434 Like termination, if no resumption handler is found during the search, 435 the default handler (\defaultResumptionHandler) visible at the raise 436 statement is called. It will use the best match at the raise sight according 437 to \CFA's overloading rules. The default handler is 438 passed the exception given to the raise. When the default handler finishes 439 execution continues after the raise statement. 440 441 There is a global \defaultResumptionHandler{} is polymorphic over all 442 resumption exceptions and preforms a termination throw on the exception. 443 The \defaultTerminationHandler{} can be overridden by providing a new 444 function that is a better match. 481 445 482 446 \subsubsection{Resumption Marking} 483 447 \label{s:ResumptionMarking} 484 448 A key difference between resumption and termination is that resumption does 485 not unwind the stack. A side effect is that,when a handler is matched486 and run , its try block (the guarded statements) and every try statement449 not unwind the stack. A side effect that is that when a handler is matched 450 and run it's try block (the guarded statements) and every try statement 487 451 searched before it are still on the stack. There presence can lead to 488 the \emph{recursive resumption problem}.452 the recursive resumption problem. 489 453 490 454 The recursive resumption problem is any situation where a resumption handler … … 500 464 When this code is executed, the guarded @throwResume@ starts a 501 465 search and matches the handler in the @catchResume@ clause. This 502 call is placed on the stack above the try-block. Now the second raise in the handler503 searches the same try block , matches,and puts another instance of the466 call is placed on the stack above the try-block. The second raise then 467 searches the same try block and puts another instance of the 504 468 same handler on the stack leading to infinite recursion. 505 469 506 While this situation is trivial and easy to avoid, much more complex cycles can 507 form with multiple handlers and different exception types. The key point is 508 that the programmer's intuition expects every raise in a handler to start 509 searching \emph{below} the @try@ statement, making it difficult to understand 510 and fix the problem. 511 512 To prevent all of these cases, each try statement is ``marked" from the 513 time the exception search reaches it to either when a matching handler 514 completes or when the search reaches the base 470 While this situation is trivial and easy to avoid, much more complex cycles 471 can form with multiple handlers and different exception types. 472 473 To prevent all of these cases, a each try statement is ``marked" from the 474 time the exception search reaches it to either when the exception is being 475 handled completes the matching handler or when the search reaches the base 515 476 of the stack. 516 477 While a try statement is marked, its handlers are never matched, effectively … … 524 485 for instance, marking just the handlers that caught the exception, 525 486 would also prevent recursive resumption. 526 However, the rule selected mirrors what happens with termination, 527 and hence, matches programmer intuition that a raise searches below a try. 528 529 In detail, the marked try statements are the ones that would be removed from 530 the stack for a termination exception, \ie those on the stack 487 However, these rules mirror what happens with termination. 488 489 The try statements that are marked are the ones that would be removed from 490 the stack if this was a termination exception, that is those on the stack 531 491 between the handler and the raise statement. 532 492 This symmetry applies to the default handler as well, as both kinds of … … 562 522 // Only handle IO failure for f3. 563 523 } 564 // Handle a failure relating to f2 further down the stack.524 // Can't handle a failure relating to f2 here. 565 525 \end{cfa} 566 526 In this example the file that experienced the IO error is used to decide … … 593 553 594 554 \subsection{Comparison with Reraising} 595 Without conditional catch, the only approach to match in more detail is to reraise 596 the exception after it has been caught, if it could not be handled. 597 \begin{center} 598 \begin{tabular}{l|l} 555 A more popular way to allow handlers to match in more detail is to reraise 556 the exception after it has been caught, if it could not be handled here. 557 On the surface these two features seem interchangeable. 558 559 If @throw;@ (no argument) starts a termination reraise, 560 which is the same as a raise but reuses the last caught exception, 561 then these two statements have the same behaviour: 599 562 \begin{cfa} 600 563 try { 601 do_work_may_throw(); 602 } catch(excep_t * ex; can_handle(ex)) { 603 604 handle(ex); 605 606 607 564 do_work_may_throw(); 565 } catch(exception_t * exc ; can_handle(exc)) { 566 handle(exc); 608 567 } 609 568 \end{cfa} 610 & 569 611 570 \begin{cfa} 612 571 try { 613 do_work_may_throw();614 } catch(excep _t * ex) {615 if (can_handle(ex)) {616 handle(ex);617 } else {618 throw;619 }572 do_work_may_throw(); 573 } catch(exception_t * exc) { 574 if (can_handle(exc)) { 575 handle(exc); 576 } else { 577 throw; 578 } 620 579 } 621 580 \end{cfa} 622 \end{tabular} 623 \end{center} 624 Notice catch-and-reraise increases complexity by adding additional data and 625 code to the exception process. Nevertheless, catch-and-reraise can simulate 626 conditional catch straightforwardly, when exceptions are disjoint, \ie no 627 inheritance. 628 629 However, catch-and-reraise simulation becomes unusable for exception inheritance. 630 \begin{flushleft} 631 \begin{cfa}[xleftmargin=6pt] 632 exception E1; 633 exception E2(E1); // inheritance 634 \end{cfa} 635 \begin{tabular}{l|l} 636 \begin{cfa} 637 try { 638 ... foo(); ... // raise E1/E2 639 ... bar(); ... // raise E1/E2 640 } catch( E2 e; e.rtn == foo ) { 641 ... 642 } catch( E1 e; e.rtn == foo ) { 643 ... 644 } catch( E1 e; e.rtn == bar ) { 645 ... 646 } 647 648 \end{cfa} 649 & 650 \begin{cfa} 651 try { 652 ... foo(); ... 653 ... bar(); ... 654 } catch( E2 e ) { 655 if ( e.rtn == foo ) { ... 656 } else throw; // reraise 657 } catch( E1 e ) { 658 if (e.rtn == foo) { ... 659 } else if (e.rtn == bar) { ... 660 else throw; // reraise 661 } 662 \end{cfa} 663 \end{tabular} 664 \end{flushleft} 665 The derived exception @E2@ must be ordered first in the catch list, otherwise 666 the base exception @E1@ catches both exceptions. In the catch-and-reraise code 667 (right), the @E2@ handler catches exceptions from both @foo@ and 668 @bar@. However, the reraise misses the following catch clause. To fix this 669 problem, an enclosing @try@ statement is need to catch @E2@ for @bar@ from the 670 reraise, and its handler must duplicate the inner handler code for @bar@. To 671 generalize, this fix for any amount of inheritance and complexity of try 672 statement requires a technique called \emph{try-block 673 splitting}~\cite{Krischer02}, which is not discussed in this thesis. It is 674 sufficient to state that conditional catch is more expressive than 675 catch-and-reraise in terms of complexity. 676 677 \begin{comment} 678 That is, they have the same behaviour in isolation. 581 That is, they will have the same behaviour in isolation. 679 582 Two things can expose differences between these cases. 680 583 681 584 One is the existence of multiple handlers on a single try statement. 682 A reraise skips all later handlers for atry statement but a conditional585 A reraise skips all later handlers on this try statement but a conditional 683 586 catch does not. 684 %Hence, if an earlier handler contains a reraise later handlers are685 %implicitly skipped, with a conditional catch they are not.587 Hence, if an earlier handler contains a reraise later handlers are 588 implicitly skipped, with a conditional catch they are not. 686 589 Still, they are equivalently powerful, 687 590 both can be used two mimic the behaviour of the other, … … 734 637 % `exception_ptr current_exception() noexcept;` 735 638 % https://www.python.org/dev/peps/pep-0343/ 736 \end{comment}737 639 738 640 \section{Finally Clauses} … … 750 652 The @FINALLY_BLOCK@ is executed when the try statement is removed from the 751 653 stack, including when the @GUARDED_BLOCK@ finishes, any termination handler 752 finishes ,or during an unwind.654 finishes or during an unwind. 753 655 The only time the block is not executed is if the program is exited before 754 656 the stack is unwound. … … 766 668 767 669 Not all languages with unwinding have finally clauses. Notably \Cpp does 768 without it as des tructors, and the RAII design pattern, serve a similar role.769 Although destructors and finally clauses can be used forthe same cases,670 without it as descructors, and the RAII design pattern, serve a similar role. 671 Although destructors and finally clauses can be used in the same cases, 770 672 they have their own strengths, similar to top-level function and lambda 771 673 functions with closures. 772 Destructors take more work for their creation, but if there is clean-up code773 that needs to be run every time a type is used , they are much easier674 Destructors take more work for their first use, but if there is clean-up code 675 that needs to be run every time a type is used they soon become much easier 774 676 to set-up. 775 677 On the other hand finally clauses capture the local context, so is easy to 776 678 use when the clean-up is not dependent on the type of a variable or requires 777 679 information from multiple variables. 680 % To Peter: I think these are the main points you were going for. 778 681 779 682 \section{Cancellation} … … 788 691 raise, this exception is not used in matching only to pass information about 789 692 the cause of the cancellation. 790 Finaly, since a cancellation only unwinds and forwards, there is no default handler. 693 (This also means matching cannot fail so there is no default handler.) 791 694 792 695 After @cancel_stack@ is called the exception is copied into the EHM's memory … … 799 702 After the main stack is unwound there is a program-level abort. 800 703 801 The reasons for this semantics in a sequential program is that there is no more code to execute.802 Th is semantics also applies to concurrent programs, too, even if threads are running.803 That is, if any threads starts a cancellation, it implies all threads terminate. 804 Keeping the same behaviour in sequential and concurrent programs is simple.704 There are two reasons for these semantics. 705 The first is that it had to do this abort. 706 in a sequential program as there is nothing else to notify and the simplicity 707 of keeping the same behaviour in sequential and concurrent programs is good. 805 708 Also, even in concurrent programs there may not currently be any other stacks 806 709 and even if other stacks do exist, main has no way to know where they are. … … 847 750 caller's context and passes it to the internal report. 848 751 849 A coroutine onlyknows of two other coroutines, its starter and its last resumer.752 A coroutine knows of two other coroutines, its starter and its last resumer. 850 753 The starter has a much more distant connection, while the last resumer just 851 754 (in terms of coroutine state) called resume on this coroutine, so the message … … 855 758 cascade an error across any number of coroutines, cleaning up each in turn, 856 759 until the error is handled or a thread stack is reached. 857 858 \PAB{Part of this I do not understand. A cancellation cannot be caught. But you859 talk about handling a cancellation in the last sentence. Which is correct?} -
doc/theses/andrew_beach_MMath/uw-ethesis.tex
r9373b6a r478c610 247 247 \input{performance} 248 248 \input{future} 249 \input{conclusion}250 249 251 250 %---------------------------------------------------------------------- -
tests/io/manipulatorsOutput3.cfa
r9373b6a r478c610 1 1 // 2 2 // Cforall Version 1.0.0 Copyright (C) 2019 University of Waterloo 3 // 4 // The contents of this file are covered under the licence agreement in the 5 // file "LICENCE" distributed with Cforall. 6 // 3 // 7 4 // manipulatorsOutput3.cfa -- 8 5 // … … 10 7 // Created On : Tue Apr 13 17:54:23 2021 11 8 // Last Modified By : Peter A. Buhr 12 // Last Modified On : Sun Aug 8 22:37:20202113 // Update Count : 29 // Last Modified On : Tue Apr 13 17:54:48 2021 10 // Update Count : 1 14 11 // 15 12 -
tests/sum.cfa
r9373b6a r478c610 11 11 // Created On : Wed May 27 17:56:53 2015 12 12 // Last Modified By : Peter A. Buhr 13 // Last Modified On : T hu Aug 5 21:27:25 202114 // Update Count : 3 4613 // Last Modified On : Tue Jul 16 09:51:37 2019 14 // Update Count : 336 15 15 // 16 16 … … 20 20 trait sumable( T ) { 21 21 void ?{}( T &, zero_t ); // 0 literal constructor 22 void ?{}( T &, one_t ); // 1 literal constructor23 22 T ?+?( T, T ); // assortment of additions 24 T ?+=?( T &, T ); // get pre/post ++ with += and one_t 23 T ?+=?( T &, T ); 24 T ++?( T & ); 25 T ?++( T & ); 25 26 }; // sumable 26 27 27 forall( T | sumable( T ) ) // use trait28 forall( T | sumable( T ) ) // use trait 28 29 T sum( size_t size, T a[] ) { 29 30 T total = 0; // initialize by 0 constructor … … 34 35 35 36 int main( void ) { 37 #if 0 36 38 const int low = 5, High = 15, size = High - low; 37 39 … … 92 94 S ?+?( S t1, S t2 ) { return (S){ t1.i + t2.i, t1.j + t2.j }; } 93 95 S ?+=?( S & t1, S t2 ) { t1 = t1 + t2; return t1; } 96 S ++?( S & t ) { t += (S){1}; return t; } 97 S ?++( S & t ) { S temp = t; t += (S){1}; return temp; } 94 98 ofstream & ?|?( ofstream & os, S v ) { return os | v.i | v.j; } 95 99 void ?|?( ofstream & os, S v ) { (ofstream &)(os | v); ends( os ); } 96 100 97 S s = 0, a[size], v = { low, low };101 S s = (S){0}, a[size], v = { low, low }; 98 102 for ( int i = 0; i < size; i += 1, v += (S){1} ) { 99 103 s += (S)v; … … 118 122 | sum( size, gs.x ) | ", check" | (int)s; // add field array in generic type 119 123 delete( gs.x ); 124 #else 125 const int low = 5, High = 15, size = High - low; 126 127 signed char s = 0, a[size], v = (char)low; 128 for ( int i = 0; i < size; i += 1, v += 1hh ) { 129 s += v; 130 a[i] = v; 131 } // for 132 printf( "sum from %d to %d is %hhd, check %hhd\n", low, High, 133 sum( size, (signed char *)a ), (signed char)s ); 134 135 unsigned char s = 0, a[size], v = low; 136 for ( int i = 0; i < size; i += 1, v += 1hhu ) { 137 s += (unsigned char)v; 138 a[i] = (unsigned char)v; 139 } // for 140 printf( "sum from %d to %d is %hhu, check %hhu\n", low, High, 141 sum( size, (unsigned char *)a ), (unsigned char)s ); 142 143 short int s = 0, a[size], v = low; 144 for ( int i = 0; i < size; i += 1, v += 1h ) { 145 s += (short int)v; 146 a[i] = (short int)v; 147 } // for 148 printf( "sum from %d to %d is %hd, check %hd\n", low, High, 149 sum( size, (short int *)a ), (short int)s ); 150 151 int s = 0, a[size], v = low; 152 for ( int i = 0; i < size; i += 1, v += 1 ) { 153 s += (int)v; 154 a[i] = (int)v; 155 } // for 156 printf( "sum from %d to %d is %d, check %d\n", low, High, 157 sum( size, (int *)a ), (int)s ); 158 159 float s = 0.0f, a[size], v = low / 10.0f; 160 for ( int i = 0; i < size; i += 1, v += 0.1f ) { 161 s += (float)v; 162 a[i] = (float)v; 163 } // for 164 printf( "sum from %g to %g is %g, check %g\n", low / 10.0f, High / 10.0f, 165 sum( size, (float *)a ), (float)s ); 166 167 double s = 0.0, a[size], v = low / 10.0; 168 for ( int i = 0; i < size; i += 1, v += 0.1 ) { 169 s += (double)v; 170 a[i] = (double)v; 171 } // for 172 printf( "sum from %g to %g is %g, check %g\n", low / 10.0f, High / 10.0f, 173 sum( size, (double *)a ), (double)s ); 174 175 struct S { int i, j; }; 176 void ?{}( S & s ) { s.[i, j] = 0; } 177 void ?{}( S & s, int i ) { s.[i, j] = [i, 0]; } 178 void ?{}( S & s, int i, int j ) { s.[i, j] = [i, j]; } 179 void ?{}( S & s, zero_t ) { s.[i, j] = 0; } 180 void ?{}( S & s, one_t ) { s.[i, j] = 1; } 181 S ?+?( S t1, S t2 ) { return (S){ t1.i + t2.i, t1.j + t2.j }; } 182 S ?+=?( S & t1, S t2 ) { t1 = t1 + t2; return t1; } 183 S ++?( S & t ) { t += (S){1}; return t; } 184 S ?++( S & t ) { S temp = t; t += (S){1}; return temp; } 185 ofstream & ?|?( ofstream & os, S v ) { return os | v.i | v.j; } 186 void ?|?( ofstream & os, S v ) { (ofstream &)(os | v); ends( os ); } 187 188 S s = 0, a[size], v = { low, low }; 189 for ( int i = 0; i < size; i += 1, v += (S){1} ) { 190 s += (S)v; 191 a[i] = (S)v; 192 } // for 193 printf( "sum from %d to %d is %d %d, check %d %d\n", low, High, 194 sum( size, (S *)a ).[i, j], s.[i, j] ); 195 196 forall( Impl | sumable( Impl ) ) 197 struct GS { 198 Impl * x, * y; 199 }; 200 GS(int) gs; 201 // FIX ME, resolution problem with anew not picking up the LH type 202 gs.x = (typeof(gs.x))anew( size ); // create array storage for field 203 s = 0; v = low; 204 for ( int i = 0; i < size; i += 1, v += 1 ) { 205 s += (int)v; 206 gs.x[i] = (int)v; // set field array in generic type 207 } // for 208 printf( "sum from %d to %d is %d, check %d\n", low, High, 209 sum( size, gs.x ), (int)s ); // add field array in generic type 210 delete( gs.x ); 211 #endif 120 212 } // main 121 213
Note:
See TracChangeset
for help on using the changeset viewer.