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