Changes in / [42b0d73:4aa2fb2]


Ignore:
Location:
doc/working/exception
Files:
4 edited

Legend:

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

    r42b0d73 r4aa2fb2  
    4444        __throw_terminate(except);
    4545        // TODO: Default handler for resumption.
    46 }
    47 
    48 /* QUESTION: Could interupts interact with exception handling?
    49 Ex. could an context switch stop execution, and we get an exception when we
    50 come back? Is so resumption has to go:
    51 + create node (init next and handler)
    52 + prepare cleanup (add a cleanup hook with the ..._cleaup function)
    53   also the cleanup has to be the next node, not just a pop from the list.
    54 + push node on the list (change the existing node)
    55 Which if an exception can come from anywhere, might just be required to ensure
    56 the list is valid.
    57 
    58 void __try_resume_setup(struct __try_resume_node * node,
    59                         bool (*handler)(exception except) {
    60         node->next = shared_stack.top_resume;
    61         node->try_to_handle = handler;
    62         shared_stack.top_resume = node;
    63 }*/
    64 
    65 // We have a single cleanup function
    66 void __try_resume_cleanup(struct __try_resume_node * node) {
    67         shared_stack.top_resume = node->next;
    6846}
    6947
  • doc/working/exception/impl/exception.h

    r42b0d73 r4aa2fb2  
    66
    77
     8// These might be given simpler names and made public.
    89void __throw_terminate(exception except) __attribute__((noreturn));
    910void __rethrow_terminate(void) __attribute__((noreturn));
     
    1920};
    2021
    21 void __try_resume_cleanup(struct __try_resume_node * node);
    22 
    2322struct __cleanup_hook {};
    2423
     
    2827 * and threads means that... well I'm going to get it working ignoring those
    2928 * first, then get it working with concurrency.
    30  * Eventually there should be some global name that just gets you the right
    31  * data block.
    3229 */
    3330struct shared_stack_t {
     31        //struct lock lock;
    3432        struct __try_resume_node * top_resume;
    3533        struct __try_resume_node * current_resume;
  • doc/working/exception/impl/test-main.c

    r42b0d73 r4aa2fb2  
    66#include <stdbool.h>
    77
    8 // Helps with manual translation. It may or may not get folded into the
    9 // header, that depends on how it interacts with concurancy.
     8// Translation Helpers:
     9#define CLEANUP(function) \
     10        struct __cleanup_hook __hidden_hook __attribute__((cleanup(function)))
     11
     12#define SET_UP_RESUME_NODE(handler_function) \
     13        struct __try_resume_node node \
     14                __attribute__((cleanup(__try_resume_node_delete))); \
     15        __try_resume_node_new(&node, handler_function)
     16
    1017void __try_resume_node_new(struct __try_resume_node * node,
    1118        _Bool (*handler)(exception except)) {
     
    1320    shared_stack.top_resume = node;
    1421    node->try_to_handle = handler;
     22}
     23
     24void __try_resume_node_delete(struct __try_resume_node * node) {
     25    shared_stack.top_resume = node->next;
    1526}
    1627
     
    111122                }
    112123                struct __try_resume_node node
    113                         __attribute__((cleanup(__try_resume_cleanup)));
     124                        __attribute__((cleanup(__try_resume_node_delete)));
    114125                __try_resume_node_new(&node, beta_handle1);
    115126                {
     
    133144                }
    134145                struct __try_resume_node node
    135                         __attribute__((cleanup(__try_resume_cleanup)));
     146                        __attribute__((cleanup(__try_resume_node_delete)));
    136147                __try_resume_node_new(&node, alpha_handle1);
    137148                {
     
    142153
    143154// Finally Test:
    144 void farewell(bool jump) {
     155void farewell() {
    145156        {
    146157                void farewell_finally1() {
     
    150161                        __attribute__((cleanup(farewell_finally1)));
    151162                {
    152                         if (jump) {
    153                                 printf("jump out of farewell\n");
    154                                 goto endoffunction;
    155                         } else {
    156                                 printf("walk out of farewell\n");
    157                         }
    158                 }
    159         }
    160         endoffunction:
    161         printf("leaving farewell\n");
     163                        printf("walk out of farewell\n");
     164                }
     165        }
    162166}
    163167
     
    256260                }
    257261                struct __try_resume_node node
    258                         __attribute__((cleanup(__try_resume_cleanup)));
     262                        __attribute__((cleanup(__try_resume_node_delete)));
    259263                __try_resume_node_new(&node, fn_handle1);
    260264                {
     
    275279                }
    276280                struct __try_resume_node node
    277                         __attribute__((cleanup(__try_resume_cleanup)));
     281                        __attribute__((cleanup(__try_resume_node_delete)));
    278282                __try_resume_node_new(&node, fn_handle1);
    279283                {
     
    345349                }
    346350                struct __try_resume_node node
    347                         __attribute__((cleanup(__try_resume_cleanup)));
     351                        __attribute__((cleanup(__try_resume_node_delete)));
    348352                __try_resume_node_new(&node, reresume_handle1);
    349353                {
     
    357361                        }
    358362                        struct __try_resume_node node
    359                                 __attribute__((cleanup(__try_resume_cleanup)));
     363                                __attribute__((cleanup(__try_resume_node_delete)));
    360364                        __try_resume_node_new(&node, reresume_handle2);
    361365                        {
     
    405409                }
    406410                struct __try_resume_node node
    407                         __attribute__((cleanup(__try_resume_cleanup)));
     411                        __attribute__((cleanup(__try_resume_node_delete)));
    408412                __try_resume_node_new(&node, foe_handle1);
    409413                {
     
    452456                }
    453457                struct __try_resume_node node
    454                         __attribute__((cleanup(__try_resume_cleanup)));
     458                        __attribute__((cleanup(__try_resume_node_delete)));
    455459                __try_resume_node_new(&node, fee_handle1);
    456460                {
     
    467471        foo(); printf("\n");
    468472        alpha(); printf("\n");
    469         farewell(false); printf("\n");
    470         farewell(true); printf("\n");
     473        farewell(); printf("\n");
    471474        fallback(); printf("\n");
    472475        terminate_swapped(); printf("\n");
  • doc/working/exception/translate.c

    r42b0d73 r4aa2fb2  
    1717
    1818void __throw_terminate(exception except) __attribute__((noreturn));
    19 void __rethrow_terminate() __attribute__((noreturn));
    2019void __throw_resume(exception except);
    2120
     
    2827        bool (*try_to_handle)(exception except);
    2928};
    30 
    31 void __try_resume_cleanup(struct __try_resume_node * node);
    3229
    3330struct __cleanup_hook {};
     
    150147void try_resume() {
    151148        {
    152                 bool handle1(exception except) {
     149                bool catch1(exception except) {
    153150                        OtherException inner_except;
    154151                        if (dynamic_cast__SomeException(except)) {
     
    164161                }
    165162                struct __try_resume_node data =
    166                         {.next = stack.except.top_resume, .try_to_handle = handle1};
     163                        {.next = stack.except.top_resume, .try_to_handle = catch1};
    167164                stack.except.top_resume = &data;
    168165
     
    207204
    208205
    209 // Resume + Finally:
    210 "Cforall"
    211 
    212 void try_resume_finally() {
    213         try {
    214                 insideTry();
    215         }
    216         catch resume (SomeException) {
    217                 fiddleThing();
    218         }
    219         finally {
    220                 twiddleWidget();
    221         }
    222 }
    223 
    224 "C"
    225 
    226 void try_resume_finally() {
    227         {
    228                 void finally1() {
    229                         twiddleWidget();
    230                 }
    231                 bool handle1(exception except) {
    232                         if (dynamic_cast__SomeException(except)) {
    233                                 fiddleThing();
    234                                 return true;
    235                         } else {
    236                                 return false;
    237                         }
    238                 }
    239                 struct __cleanup_hook generated_name
    240                         __attribute__((cleanup(finally1)));
    241 
    242                 struct __try_resume_node data =
    243                         {.next = stack.except.top_resume, .try_to_handle = handle1};
    244                 stack.except.top_resume = &data;
    245 
    246                 struct __cleanup_hook generated_name
    247                         __attribute__((cleanup(__try_resume_cleanup)));
    248         }
    249 }
    250 
    251 
    252 // Terminate + Resume + Finally:
     206// Combining the Above:
    253207"Cforall"
    254208
     
    272226void try_all() {
    273227        {
    274                 bool handle1() {
    275                         if (dynamic_cast__OtherException(except)) {
    276                                 twiddleWidget();
    277                                 return true;
    278                         }
    279                         return false;
    280                 }
    281228                void try1 () {
    282                         struct __try_resume_node generated_name =
    283                                 {.next = stack.except.top_resume, .try_to_handle = handle1}
    284                                 __attribute__((cleanup(__try_resume_cleanup)));
    285                         stack.except.top_resume = &data;
    286 
    287229                        insideTry();
    288230                }
     
    302244                        return 0;
    303245                }
     246                bool catch2() {
     247                        if (dynamic_cast__OtherException(except)) {
     248                                twiddleWidget();
     249                                return true;
     250                        }
     251                        return false;
     252                }
    304253                void finally1() {
     254                        // Finally, because of timing, also works for resume.
     255                        // However this might not actually be better in any way.
     256                        __try_resume_cleanup();
    305257
    306258                        twiddleWidget();
    307259                }
     260
     261                struct __try_resume_node generated_name =
     262                        {.next = stack.except.top_resume, .try_to_handle = catch2};
     263                stack.except.top_resume = &data;
    308264                struct __cleanup_hook generated_name
    309265                        __attribute__((cleanup(finally1)));
Note: See TracChangeset for help on using the changeset viewer.