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