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