source:
doc/theses/andrew_beach_MMath/code/resume-finally.cfa
@
98233b3
Last change on this file since 98233b3 was 54651005, checked in by , 3 years ago | |
---|---|
|
|
File size: 911 bytes |
Rev | Line | |
---|---|---|
[ea593a3] | 1 | // Throw Across Finally |
[ee23a8d] | 2 | #include <clock.hfa> |
[ea593a3] | 3 | #include <exception.hfa> |
[ee23a8d] | 4 | #include <fstream.hfa> |
[ea593a3] | 5 | #include <stdlib.hfa> |
6 | ||
7 | EHM_EXCEPTION(empty_exception)(); | |
8 | ||
9 | EHM_VIRTUAL_TABLE(empty_exception, empty_vt); | |
10 | ||
11 | void unwind_finally(unsigned int frames) { | |
12 | if (frames) { | |
13 | try { | |
14 | unwind_finally(frames - 1); | |
15 | } finally { | |
[54651005] | 16 | asm volatile ("# finally block"); |
[ea593a3] | 17 | } |
18 | } else { | |
19 | throwResume (empty_exception){&empty_vt}; | |
20 | } | |
21 | } | |
22 | ||
23 | int main(int argc, char * argv[]) { | |
24 | unsigned int times = 1; | |
25 | unsigned int total_frames = 1; | |
[ee23a8d] | 26 | if (1 < argc) { |
[ea593a3] | 27 | times = strtol(argv[1], 0p, 10); |
28 | } | |
[ee23a8d] | 29 | if (2 < argc) { |
[ea593a3] | 30 | total_frames = strtol(argv[2], 0p, 10); |
31 | } | |
32 | ||
[ee23a8d] | 33 | Time start_time = timeHiRes(); |
[ea593a3] | 34 | for (int count = 0 ; count < times ; ++count) { |
35 | try { | |
36 | unwind_finally(total_frames); | |
37 | } catchResume (empty_exception *) { | |
[54651005] | 38 | asm volatile ("# fixup block"); |
[ea593a3] | 39 | } |
40 | } | |
[ee23a8d] | 41 | Time end_time = timeHiRes(); |
42 | sout | "Run-Time (ns): " | (end_time - start_time)`ns; | |
[ea593a3] | 43 | } |
Note: See TracBrowser
for help on using the repository browser.