Changes in src/tests/except-0.c [fcc88a4:e9145a3]
- File:
-
- 1 edited
-
src/tests/except-0.c (modified) (18 diffs)
Legend:
- Unmodified
- Added
- Removed
-
src/tests/except-0.c
rfcc88a4 re9145a3 7 7 #include <stdio.h> 8 8 #include <stdbool.h> 9 10 #include "except-mac.h" 11 TRIVIAL_EXCEPTION(yin) 12 TRIVIAL_EXCEPTION(yang) 13 TRIVIAL_EXCEPTION(zen) 14 9 15 10 16 // Local type to mark exits from scopes. (see ERROR) … … 23 29 24 30 25 // Local Exception Types and manual vtable types. 26 //#define TRIVIAL_EXCEPTION(name) //TRIVAL_EXCEPTION(yin) 27 struct yin; 28 struct yin_vtable { 29 struct exception_t_vtable const * parent; 30 size_t size; 31 void (*copy)(yin *this, yin * other); 32 void (*free)(yin *this); 33 const char (*msg)(yin *this); 34 }; 35 struct yin { 36 struct yin_vtable const * parent; 37 }; 38 void yin_msg(yin) { 39 return "in"; 40 } 41 yin_vtable _yin_vtable_instance = { 42 &_exception_t_vtable_instance, sizeof(yin), ?{}, ^?{}, yin_msg 43 } 44 45 46 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) { 47 34 signal_exit a = {"terminate function"}; 48 throw except_value;35 THROW(except_value); 49 36 printf("terminate returned\n"); 50 37 } 51 38 52 void resume(exception * except_value) { 39 forall(dtype T) 40 void resume(T * except_value) { 53 41 signal_exit a = {"resume function"}; 54 throwResume except_value;42 THROW_RESUME(except_value); 55 43 printf("resume returned\n"); 56 44 } … … 60 48 signal_exit a = {"bar function"}; 61 49 try { 62 terminate( 4);63 } catch ( 3) {64 printf("bar caught exception 3.\n");50 terminate(&(zen){}); 51 } catch (yin * error) { 52 printf("bar caught exception yin.\n"); 65 53 } 66 54 } … … 70 58 try { 71 59 bar(); 72 } catch ( 4) {73 printf("foo caught exception 4.\n");74 } catch ( 2) {75 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"); 76 64 } 77 65 } … … 81 69 signal_exit a = {"beta function"}; 82 70 try { 83 resume(4); 84 } catchResume (3) { 85 printf("beta caught exception 3\n"); 71 zen x; 72 resume(&x); 73 } catchResume (yin * error) { 74 printf("beta caught exception yin\n"); 86 75 } 87 76 } … … 91 80 try { 92 81 beta(); 93 } catchResume ( 2) {94 printf("alpha caught exception 2\n");95 } catchResume ( 4) {96 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"); 97 86 } 98 87 } … … 117 106 void fallback() { 118 107 try { 119 resume(2); 120 } catch (2) { 121 printf("fallback caught termination 2\n"); 108 zen x; 109 resume(&x); 110 } catch (zen * error) { 111 printf("fallback caught termination zen\n"); 122 112 } 123 113 } … … 127 117 signal_exit a = {"terminate_swap"}; 128 118 try { 129 terminate(2); 130 } catch (2) { 131 terminate(3); 119 yin x; 120 terminate(&x); 121 } catch (yin * error) { 122 yang y; 123 terminate(&y); 132 124 } 133 125 } … … 137 129 try { 138 130 terminate_swap(); 139 } catch ( 3) {140 printf("terminate_swapped caught exception 3\n");131 } catch (yang * error) { 132 printf("terminate_swapped caught exception yang\n"); 141 133 } 142 134 } … … 146 138 signal_exit a = {"resume_swap"}; 147 139 try { 148 resume(2); 149 } catchResume (2) { 150 resume(3); 140 yin x; 141 resume(&x); 142 } catchResume (yin * error) { 143 yang y; 144 resume(&y); 151 145 } 152 146 } … … 155 149 try { 156 150 resume_swap(); 157 } catchResume ( 3) {158 printf("resume_swapped caught exception 3\n");151 } catchResume (yang * error) { 152 printf("resume_swapped caught exception yang\n"); 159 153 } 160 154 } … … 164 158 try { 165 159 try { 166 terminate(2); 167 } catch (2) { 168 printf("reterminate 2 caught and " 169 "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"); 170 165 throw; 171 166 } 172 } catch ( 2) {173 printf("reterminate 1 caught exception 2\n");167 } catch (zen * error) { 168 printf("reterminate 1 caught exception zen\n"); 174 169 } 175 170 } … … 179 174 try { 180 175 try { 181 resume(2); 182 } catchResume (2) { 183 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"); 184 180 throwResume; 185 181 } 186 } catchResume ( 2) {187 printf("reresume 1 caught exception 2\n");182 } catchResume (zen * error) { 183 printf("reresume 1 caught exception zen\n"); 188 184 } 189 185 } … … 193 189 // terminate block, call resume 194 190 try { 195 resume(3); 196 } catch (3) { 197 printf("fum caught exception 3\n"); 191 zen x; 192 resume(&x); 193 } catch (zen * error) { 194 printf("fum caught exception zen\n"); 198 195 } 199 196 } … … 202 199 // resume block, call terminate 203 200 try { 204 terminate(3); 205 } catchResume (3) { 206 printf("foe caught exception 3\n"); 201 zen y; 202 terminate(&y); 203 } catchResume (zen * error) { 204 printf("foe caught exception zen\n"); 207 205 } 208 206 } … … 212 210 try { 213 211 foe(); 214 } catch ( 3) {215 printf("fy caught exception 3\n");212 } catch (zen * error) { 213 printf("fy caught exception zen\n"); 216 214 fum(); 217 215 } … … 222 220 try { 223 221 fy(); 224 } catchResume ( 3) {225 printf("fee caught exception 3\n");222 } catchResume (zen * error) { 223 printf("fee caught exception zen\n"); 226 224 } 227 225 } … … 242 240 reresume(); printf("\n"); 243 241 fee(); printf("\n"); 242 244 243 // Uncaught termination test. 245 terminate(7); 246 } 244 printf("Throw uncaught.\n"); 245 yang z; 246 terminate(&z); 247 }
Note:
See TracChangeset
for help on using the changeset viewer.