Changeset f79ee0d for doc/theses/andrew_beach_MMath/code/throw-finally.cfa
- Timestamp:
- Aug 19, 2021, 1:58:46 PM (3 years ago)
- Branches:
- ADT, ast-experimental, enum, forall-pointer-decay, jacob/cs343-translation, master, pthread-emulation, qualifiedEnum
- Children:
- 262deda0
- Parents:
- 8a1d95af
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
doc/theses/andrew_beach_MMath/code/throw-finally.cfa
r8a1d95af rf79ee0d 3 3 #include <exception.hfa> 4 4 #include <fstream.hfa> 5 #include <stdlib.hfa> 5 #include <stdlib.hfa> // strto 6 6 7 EHM_EXCEPTION(empty_exception)(); 7 exception empty_exception; 8 vtable(empty_exception) empty_vt; 8 9 9 EHM_VIRTUAL_TABLE(empty_exception, empty_vt); 10 unsigned int frames; // use global because of gcc thunk problem 10 11 11 void unwind_finally(unsigned int frames) {12 void unwind_finally(unsigned int dummy) { 12 13 if (frames) { 14 frames -= 1; 13 15 try { 14 unwind_finally( frames - 1);16 unwind_finally(42); 15 17 } finally { 16 18 asm volatile ("# finally block"); 17 19 } 18 20 } else { 21 dummy = 42; 19 22 throw (empty_exception){&empty_vt}; 20 23 } … … 25 28 unsigned int total_frames = 1; 26 29 if (1 < argc) { 27 times = strto l(argv[1], 0p, 10);30 times = strto(argv[1], 0p, 10); 28 31 } 29 32 if (2 < argc) { 30 total_frames = strto l(argv[2], 0p, 10);33 total_frames = strto(argv[2], 0p, 10); 31 34 } 35 frames = total_frames; 32 36 33 37 Time start_time = timeHiRes(); 34 38 for (int count = 0 ; count < times ; ++count) { 35 39 try { 36 unwind_finally( total_frames);40 unwind_finally(42); 37 41 } catch (empty_exception *) { 38 42 asm volatile ("# catch block"); … … 40 44 } 41 45 Time end_time = timeHiRes(); 42 sout | "Run-Time ( ns): " | (end_time - start_time)`ns;46 sout | "Run-Time (s): " | wd(0,1, (end_time - start_time)`ns / 1_000_000_000.); 43 47 }
Note: See TracChangeset
for help on using the changeset viewer.