Changeset 3eb5a478
- Timestamp:
- Apr 2, 2020, 3:00:55 PM (5 years ago)
- Branches:
- ADT, arm-eh, ast-experimental, enum, forall-pointer-decay, jacob/cs343-translation, master, new-ast, new-ast-unique-expr, pthread-emulation, qualifiedEnum
- Children:
- 0f3d844
- Parents:
- 6d43cdde
- Files:
-
- 5 edited
Legend:
- Unmodified
- Added
- Removed
-
libcfa/src/exception.c
r6d43cdde r3eb5a478 10 10 // Created On : Mon Jun 26 15:13:00 2017 11 11 // Last Modified By : Andrew Beach 12 // Last Modified On : Fri Mar 27 10:19:00 202013 // Update Count : 1 212 // Last Modified On : Thr Apr 02 14:47:00 2020 13 // Update Count : 13 14 14 // 15 15 … … 53 53 // Temperary global exception context. Does not work with concurency. 54 54 struct exception_context_t { 55 struct __cfaehm_try_resume_node * top_resume; 56 struct __cfaehm_try_resume_node * current_resume; 57 58 exception_t * current_exception; 59 int current_handler_index; 60 } static shared_stack = {NULL, NULL, NULL, 0}; 55 struct __cfaehm_try_resume_node * top_resume; 56 57 exception_t * current_exception; 58 int current_handler_index; 59 } static shared_stack = {NULL, NULL, 0}; 61 60 62 61 // Get the current exception context. … … 75 74 __cfaabi_dbg_print_safe("Throwing resumption exception\n"); 76 75 77 struct __cfaehm_try_resume_node * original_head = context->current_resume; 78 struct __cfaehm_try_resume_node * current = 79 (original_head) ? original_head->next : context->top_resume; 76 struct __cfaehm_try_resume_node * original_head = context->top_resume; 77 struct __cfaehm_try_resume_node * current = context->top_resume; 80 78 81 79 for ( ; current ; current = current->next) { 82 context-> current_resume = current;80 context->top_resume = current->next; 83 81 if (current->handler(except)) { 84 context-> current_resume = original_head;82 context->top_resume = original_head; 85 83 return; 86 84 } … … 88 86 89 87 __cfaabi_dbg_print_safe("Unhandled exception\n"); 90 context-> current_resume = original_head;88 context->top_resume = original_head; 91 89 92 90 // Fall back to termination: -
tests/exceptions/.expect/interact.txt
r6d43cdde r3eb5a478 8 8 9 9 resume catch on resume 10 11 termination catch, will resume 12 outer resume catch 13 14 resumption catch, will terminate 15 inner termination catch -
tests/exceptions/.expect/resume.txt
r6d43cdde r3eb5a478 19 19 caught yin, will throw yang 20 20 caught yang 21 22 throwing first exception 23 caught first exception 24 throwing second exception 25 caught second exception 26 recaught first exception -
tests/exceptions/interact.cfa
r6d43cdde r3eb5a478 5 5 6 6 TRIVIAL_EXCEPTION(star); 7 TRIVIAL_EXCEPTION(moon); 7 8 8 9 int main(int argc, char * argv[]) { … … 51 52 printf("resume catch on resume\n"); 52 53 } 54 printf("\n"); 55 56 // Resume a termination exception. 57 try { 58 try { 59 try { 60 THROW(&(star){}); 61 } catchResume (star *) { 62 printf("inner resume catch (error)\n"); 63 } 64 } catch (star * error) { 65 printf("termination catch, will resume\n"); 66 THROW_RESUME(error); 67 } 68 } catchResume (star *) { 69 printf("outer resume catch\n"); 70 } 71 printf("\n"); 72 73 // Terminate a resumption exception. 74 try { 75 try { 76 try { 77 THROW_RESUME(&(star){}); 78 } catch (star *) { 79 printf("inner termination catch\n"); 80 } 81 } catchResume (star * error) { 82 printf("resumption catch, will terminate\n"); 83 THROW(error); 84 } 85 } catch (star *) { 86 printf("outer terminate catch (error)\n"); 87 } 88 #if 0 89 printf("\n"); 90 91 // Unwinding a resumption catch does not break the system. 92 try { 93 try { 94 try { 95 try { 96 printf("throwing resume moon\n"); 97 THROW_RESUME(&(moon){}); 98 } catch (star *) { 99 printf("termination catch\n"); 100 } 101 printf("throwing resume star\n"); 102 THROW_RESUME(&(star){}); 103 } catchResume (star *) { 104 printf("resumption star catch\n"); 105 } 106 } catchResume (moon *) { 107 printf("resumption moon catch, will terminate\n"); 108 THROW(&(star){}); 109 } 110 } catchResume (star *) { 111 printf("outermost catch (error)\n"); 112 } 113 #endif 53 114 } -
tests/exceptions/resume.cfa
r6d43cdde r3eb5a478 77 77 printf("caught yang\n"); 78 78 } 79 #ifdef FAILING80 79 printf("\n"); 81 80 … … 100 99 printf("caught second exception (bad location)\n"); 101 100 } 102 #endif103 101 }
Note: See TracChangeset
for help on using the changeset viewer.