Changeset 35ba584c for doc/working


Ignore:
Timestamp:
Jun 15, 2017, 5:12:41 PM (7 years ago)
Author:
Andrew Beach <ajbeach@…>
Branches:
ADT, aaron-thesis, arm-eh, ast-experimental, cleanup-dtors, deferred_resn, demangler, enum, forall-pointer-decay, jacob/cs343-translation, jenkins-sandbox, master, new-ast, new-ast-unique-expr, new-env, no_list, persistent-indexer, pthread-emulation, qualifiedEnum, resolv-new, with_gc
Children:
974bcdd, cc3e4d0
Parents:
cdd1695
Message:

Added rethrow to translation.
Implemend and tested termination rethrowing.

Location:
doc/working/exception
Files:
4 edited

Legend:

Unmodified
Added
Removed
  • doc/working/exception/impl/exception.c

    rcdd1695 r35ba584c  
    7373}
    7474
    75 // Example throw routine
    7675void __throw_terminate( int val ) {
    7776        // Store the current exception
     
    107106        printf("UNWIND ERROR %d after raise exception\n", ret);
    108107        abort();
     108}
     109
     110// Nesting this the other way would probably be faster.
     111void __rethrow_terminate(void) {
     112        // DEBUG
     113        printf("Rethrowing termination exception\n");
     114
     115        __throw_terminate(shared_stack.current_exception);
    109116}
    110117
  • doc/working/exception/impl/exception.h

    rcdd1695 r35ba584c  
    88// These might be given simpler names and made public.
    99void __throw_terminate(exception except) __attribute__((noreturn));
     10void __rethrow_terminate(void) __attribute__((noreturn));
    1011void __throw_resume(exception except);
    1112
     
    2223
    2324
    24 // When I have it working in a single threaded environment.
     25
     26/* The following code is temperary. How exceptions interact with coroutines
     27 * and threads means that... well I'm going to get it working ignoring those
     28 * first, then get it working with concurrency.
     29 */
    2530struct shared_stack_t {
    2631        //struct lock lock;
  • doc/working/exception/impl/test-main.c

    rcdd1695 r35ba584c  
    289289// Terminate Rethrow:
    290290// I don't have an implementation for this.
     291void reterminate() {
     292        {
     293                void fn_try1() {
     294                        void fn_try2() {
     295                                terminate(1);
     296                        }
     297                        void fn_catch2(int index, exception except) {
     298                                switch (index) {
     299                                case 1:
     300                                        printf("reterminate 2 caught and "
     301                                               "will rethrow exception 1\n");
     302                                        __rethrow_terminate();
     303                                        break;
     304                                default:
     305                                        printf("INVALID INDEX in reterminate 2: %d (%d)\n",
     306                                                index, except);
     307                                }
     308                        }
     309                        int fn_match2(exception except) {
     310                                if (1 == except) {
     311                                        return 1;
     312                                } else {
     313                                        return 0;
     314                                }
     315                        }
     316                        __try_terminate(fn_try2, fn_catch2, fn_match2);
     317                }
     318                void fn_catch1(int index, exception except) {
     319                        switch (index) {
     320                        case 1:
     321                                printf("reterminate 1 caught exception 1\n");
     322                                break;
     323                        default:
     324                                printf("INVALID INDEX in reterminate 1: %d (%d)\n",
     325                                        index, except);
     326                        }
     327                }
     328                int fn_match1(exception except) {
     329                        if (1 == except) {
     330                                return 1;
     331                        } else {
     332                                return 0;
     333                        }
     334                }
     335                __try_terminate(fn_try1, fn_catch1, fn_match1);
     336        }
     337}
    291338
    292339// Resume Rethrow:
     
    428475        terminate_swapped(); printf("\n");
    429476        resume_swapped(); printf("\n");
     477        reterminate(); printf("\n");
    430478        reresume(); printf("\n");
    431479        fee(); printf("\n");
  • doc/working/exception/translate.c

    rcdd1695 r35ba584c  
    5454
    5555__throw_resume(exception_instance);
     56
     57
     58
     59// Rethrows (inside matching handlers):
     60"Cforall"
     61
     62throw;
     63
     64resume;
     65
     66"C"
     67
     68__rethrow_terminate();
     69
     70return false;
    5671
    5772
Note: See TracChangeset for help on using the changeset viewer.