Changeset 8135d4c for src/tests/except-0.c
- Timestamp:
- Aug 22, 2017, 7:31:52 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:
- 9aaac6e9
- Parents:
- fc56cdbf (diff), b3d413b (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. - File:
-
- 1 edited
-
src/tests/except-0.c (modified) (19 diffs)
Legend:
- Unmodified
- Added
- Removed
-
src/tests/except-0.c
rfc56cdbf r8135d4c 1 1 // Draft of tests for exception handling. 2 // Outdated: The integer constant exceptions need to be replaced with virtual 3 // exceptions for the new system. 2 4 3 5 // ERROR: exceptions do not interact with ^?{} properly. … … 5 7 #include <stdio.h> 6 8 #include <stdbool.h> 9 10 #include "except-mac.h" 11 TRIVIAL_EXCEPTION(yin) 12 TRIVIAL_EXCEPTION(yang) 13 TRIVIAL_EXCEPTION(zen) 14 7 15 8 16 // Local type to mark exits from scopes. (see ERROR) … … 21 29 22 30 23 // Local Exception Types and manual vtable types. 24 //#define TRIVIAL_EXCEPTION(name) //TRIVAL_EXCEPTION(yin) 25 struct yin; 26 struct yin_vtable { 27 struct exception_t_vtable const * parent; 28 size_t size; 29 void (*copy)(yin *this, yin * other); 30 void (*free)(yin *this); 31 const char (*msg)(yin *this); 32 }; 33 struct yin { 34 struct yin_vtable const * parent; 35 }; 36 void yin_msg(yin) { 37 return "in"; 38 } 39 yin_vtable _yin_vtable_instance = { 40 &_exception_t_vtable_instance, sizeof(yin), ?{}, ^?{}, yin_msg 41 } 42 43 44 void terminate(exception * except_value) { 31 // Mark throws: make sure to only pass in exception types. 32 forall(dtype T) 33 void terminate(T * except_value) { 45 34 signal_exit a = {"terminate function"}; 46 throw except_value;35 THROW(except_value); 47 36 printf("terminate returned\n"); 48 37 } 49 38 50 void resume(exception * except_value) { 39 forall(dtype T) 40 void resume(T * except_value) { 51 41 signal_exit a = {"resume function"}; 52 throwResume except_value;42 THROW_RESUME(except_value); 53 43 printf("resume returned\n"); 54 44 } … … 58 48 signal_exit a = {"bar function"}; 59 49 try { 60 terminate( 4);61 } catch ( 3) {62 printf("bar caught exception 3.\n");50 terminate(&(zen){}); 51 } catch (yin * error) { 52 printf("bar caught exception yin.\n"); 63 53 } 64 54 } … … 68 58 try { 69 59 bar(); 70 } catch ( 4) {71 printf("foo caught exception 4.\n");72 } catch ( 2) {73 printf("foo caught exception 2.\n");60 } catch (yang * error) { 61 printf("foo caught exception yang.\n"); 62 } catch (zen * error) { 63 printf("foo caught exception zen.\n"); 74 64 } 75 65 } … … 79 69 signal_exit a = {"beta function"}; 80 70 try { 81 resume(4); 82 } catchResume (3) { 83 printf("beta caught exception 3\n"); 71 zen x; 72 resume(&x); 73 } catchResume (yin * error) { 74 printf("beta caught exception yin\n"); 84 75 } 85 76 } … … 89 80 try { 90 81 beta(); 91 } catchResume ( 2) {92 printf("alpha caught exception 2\n");93 } catchResume ( 4) {94 printf("alpha caught exception 4\n");82 } catchResume (yang * error) { 83 printf("alpha caught exception yang\n"); 84 } catchResume (zen * error) { 85 printf("alpha caught exception zen\n"); 95 86 } 96 87 } … … 115 106 void fallback() { 116 107 try { 117 resume(2); 118 } catch (2) { 119 printf("fallback caught termination 2\n"); 108 zen x; 109 resume(&x); 110 } catch (zen * error) { 111 printf("fallback caught termination zen\n"); 120 112 } 121 113 } … … 125 117 signal_exit a = {"terminate_swap"}; 126 118 try { 127 terminate(2); 128 } catch (2) { 129 terminate(3); 119 yin x; 120 terminate(&x); 121 } catch (yin * error) { 122 yang y; 123 terminate(&y); 130 124 } 131 125 } … … 135 129 try { 136 130 terminate_swap(); 137 } catch ( 3) {138 printf("terminate_swapped caught exception 3\n");131 } catch (yang * error) { 132 printf("terminate_swapped caught exception yang\n"); 139 133 } 140 134 } … … 144 138 signal_exit a = {"resume_swap"}; 145 139 try { 146 resume(2); 147 } catchResume (2) { 148 resume(3); 140 yin x; 141 resume(&x); 142 } catchResume (yin * error) { 143 yang y; 144 resume(&y); 149 145 } 150 146 } … … 153 149 try { 154 150 resume_swap(); 155 } catchResume ( 3) {156 printf("resume_swapped caught exception 3\n");151 } catchResume (yang * error) { 152 printf("resume_swapped caught exception yang\n"); 157 153 } 158 154 } … … 162 158 try { 163 159 try { 164 terminate(2); 165 } catch (2) { 166 printf("reterminate 2 caught and " 167 "will rethrow exception 2\n"); 160 zen x; 161 terminate(&x); 162 } catch (zen * error) { 163 printf("reterminate zen caught and " 164 "will rethrow exception zen\n"); 168 165 throw; 169 166 } 170 } catch ( 2) {171 printf("reterminate 1 caught exception 2\n");167 } catch (zen * error) { 168 printf("reterminate 1 caught exception zen\n"); 172 169 } 173 170 } … … 177 174 try { 178 175 try { 179 resume(2); 180 } catchResume (2) { 181 printf("reresume 2 caught and rethrows exception 2\n"); 176 zen x; 177 resume(&x); 178 } catchResume (zen * error) { 179 printf("reresume zen caught and rethrows exception zen\n"); 182 180 throwResume; 183 181 } 184 } catchResume ( 2) {185 printf("reresume 1 caught exception 2\n");182 } catchResume (zen * error) { 183 printf("reresume 1 caught exception zen\n"); 186 184 } 187 185 } … … 191 189 // terminate block, call resume 192 190 try { 193 resume(3); 194 } catch (3) { 195 printf("fum caught exception 3\n"); 191 zen x; 192 resume(&x); 193 } catch (zen * error) { 194 printf("fum caught exception zen\n"); 196 195 } 197 196 } … … 200 199 // resume block, call terminate 201 200 try { 202 terminate(3); 203 } catchResume (3) { 204 printf("foe caught exception 3\n"); 201 zen y; 202 terminate(&y); 203 } catchResume (zen * error) { 204 printf("foe caught exception zen\n"); 205 205 } 206 206 } … … 210 210 try { 211 211 foe(); 212 } catch ( 3) {213 printf("fy caught exception 3\n");212 } catch (zen * error) { 213 printf("fy caught exception zen\n"); 214 214 fum(); 215 215 } … … 220 220 try { 221 221 fy(); 222 } catchResume ( 3) {223 printf("fee caught exception 3\n");222 } catchResume (zen * error) { 223 printf("fee caught exception zen\n"); 224 224 } 225 225 } … … 240 240 reresume(); printf("\n"); 241 241 fee(); printf("\n"); 242 242 243 // Uncaught termination test. 243 terminate(7); 244 } 244 printf("Throw uncaught.\n"); 245 yang z; 246 terminate(&z); 247 }
Note:
See TracChangeset
for help on using the changeset viewer.