Changeset 42b0d73
- Timestamp:
- Jun 16, 2017, 9:07:33 PM (8 years ago)
- 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:
- 436c0de, e1c1829, ec35498
- Parents:
- 4aa2fb2 (diff), e1055441 (diff)
Note: this is a merge changeset, the changes displayed below correspond to the merge itself.
Use the(diff)
links above to see all the changes relative to each parent. - Location:
- doc/working/exception
- Files:
-
- 4 edited
Legend:
- Unmodified
- Added
- Removed
-
doc/working/exception/impl/exception.c
r4aa2fb2 r42b0d73 44 44 __throw_terminate(except); 45 45 // 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; 46 68 } 47 69 -
doc/working/exception/impl/exception.h
r4aa2fb2 r42b0d73 6 6 7 7 8 // These might be given simpler names and made public.9 8 void __throw_terminate(exception except) __attribute__((noreturn)); 10 9 void __rethrow_terminate(void) __attribute__((noreturn)); … … 20 19 }; 21 20 21 void __try_resume_cleanup(struct __try_resume_node * node); 22 22 23 struct __cleanup_hook {}; 23 24 … … 27 28 * and threads means that... well I'm going to get it working ignoring those 28 29 * first, then get it working with concurrency. 30 * Eventually there should be some global name that just gets you the right 31 * data block. 29 32 */ 30 33 struct shared_stack_t { 31 //struct lock lock;32 34 struct __try_resume_node * top_resume; 33 35 struct __try_resume_node * current_resume; -
doc/working/exception/impl/test-main.c
r4aa2fb2 r42b0d73 6 6 #include <stdbool.h> 7 7 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 8 // Helps with manual translation. It may or may not get folded into the 9 // header, that depends on how it interacts with concurancy. 17 10 void __try_resume_node_new(struct __try_resume_node * node, 18 11 _Bool (*handler)(exception except)) { … … 20 13 shared_stack.top_resume = node; 21 14 node->try_to_handle = handler; 22 }23 24 void __try_resume_node_delete(struct __try_resume_node * node) {25 shared_stack.top_resume = node->next;26 15 } 27 16 … … 122 111 } 123 112 struct __try_resume_node node 124 __attribute__((cleanup(__try_resume_ node_delete)));113 __attribute__((cleanup(__try_resume_cleanup))); 125 114 __try_resume_node_new(&node, beta_handle1); 126 115 { … … 144 133 } 145 134 struct __try_resume_node node 146 __attribute__((cleanup(__try_resume_ node_delete)));135 __attribute__((cleanup(__try_resume_cleanup))); 147 136 __try_resume_node_new(&node, alpha_handle1); 148 137 { … … 153 142 154 143 // Finally Test: 155 void farewell( ) {144 void farewell(bool jump) { 156 145 { 157 146 void farewell_finally1() { … … 161 150 __attribute__((cleanup(farewell_finally1))); 162 151 { 163 printf("walk out of farewell\n"); 164 } 165 } 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"); 166 162 } 167 163 … … 260 256 } 261 257 struct __try_resume_node node 262 __attribute__((cleanup(__try_resume_ node_delete)));258 __attribute__((cleanup(__try_resume_cleanup))); 263 259 __try_resume_node_new(&node, fn_handle1); 264 260 { … … 279 275 } 280 276 struct __try_resume_node node 281 __attribute__((cleanup(__try_resume_ node_delete)));277 __attribute__((cleanup(__try_resume_cleanup))); 282 278 __try_resume_node_new(&node, fn_handle1); 283 279 { … … 349 345 } 350 346 struct __try_resume_node node 351 __attribute__((cleanup(__try_resume_ node_delete)));347 __attribute__((cleanup(__try_resume_cleanup))); 352 348 __try_resume_node_new(&node, reresume_handle1); 353 349 { … … 361 357 } 362 358 struct __try_resume_node node 363 __attribute__((cleanup(__try_resume_ node_delete)));359 __attribute__((cleanup(__try_resume_cleanup))); 364 360 __try_resume_node_new(&node, reresume_handle2); 365 361 { … … 409 405 } 410 406 struct __try_resume_node node 411 __attribute__((cleanup(__try_resume_ node_delete)));407 __attribute__((cleanup(__try_resume_cleanup))); 412 408 __try_resume_node_new(&node, foe_handle1); 413 409 { … … 456 452 } 457 453 struct __try_resume_node node 458 __attribute__((cleanup(__try_resume_ node_delete)));454 __attribute__((cleanup(__try_resume_cleanup))); 459 455 __try_resume_node_new(&node, fee_handle1); 460 456 { … … 471 467 foo(); printf("\n"); 472 468 alpha(); printf("\n"); 473 farewell(); printf("\n"); 469 farewell(false); printf("\n"); 470 farewell(true); printf("\n"); 474 471 fallback(); printf("\n"); 475 472 terminate_swapped(); printf("\n"); -
doc/working/exception/translate.c
r4aa2fb2 r42b0d73 17 17 18 18 void __throw_terminate(exception except) __attribute__((noreturn)); 19 void __rethrow_terminate() __attribute__((noreturn)); 19 20 void __throw_resume(exception except); 20 21 … … 27 28 bool (*try_to_handle)(exception except); 28 29 }; 30 31 void __try_resume_cleanup(struct __try_resume_node * node); 29 32 30 33 struct __cleanup_hook {}; … … 147 150 void try_resume() { 148 151 { 149 bool catch1(exception except) {152 bool handle1(exception except) { 150 153 OtherException inner_except; 151 154 if (dynamic_cast__SomeException(except)) { … … 161 164 } 162 165 struct __try_resume_node data = 163 {.next = stack.except.top_resume, .try_to_handle = catch1};166 {.next = stack.except.top_resume, .try_to_handle = handle1}; 164 167 stack.except.top_resume = &data; 165 168 … … 204 207 205 208 206 // Combining the Above: 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: 207 253 "Cforall" 208 254 … … 226 272 void try_all() { 227 273 { 274 bool handle1() { 275 if (dynamic_cast__OtherException(except)) { 276 twiddleWidget(); 277 return true; 278 } 279 return false; 280 } 228 281 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 229 287 insideTry(); 230 288 } … … 244 302 return 0; 245 303 } 246 bool catch2() {247 if (dynamic_cast__OtherException(except)) {248 twiddleWidget();249 return true;250 }251 return false;252 }253 304 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();257 305 258 306 twiddleWidget(); 259 307 } 260 261 struct __try_resume_node generated_name =262 {.next = stack.except.top_resume, .try_to_handle = catch2};263 stack.except.top_resume = &data;264 308 struct __cleanup_hook generated_name 265 309 __attribute__((cleanup(finally1)));
Note: See TracChangeset
for help on using the changeset viewer.