source:
doc/theses/andrew_beach_MMath/code/resume-detor.cfa@
f93d7fc
      
      | Last change on this file since f93d7fc was f79ee0d, checked in by , 4 years ago | |
|---|---|
| 
 | |
| File size: 1006 bytes | |
| Rev | Line | |
|---|---|---|
| [ea593a3] | 1 | // Throw Across Destructor | 
| [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 | struct WithDestructor {}; | |
| 11 | ||
| 12 | void ^?{}(WithDestructor & this) { | |
| [54651005] | 13 | asm volatile ("# destructor body"); | 
| [ea593a3] | 14 | } | 
| 15 | ||
| 16 | void unwind_destructor(unsigned int frames) { | |
| [54651005] | 17 | if (frames) { | 
| 18 | WithDestructor object; | |
| 19 | unwind_destructor(frames - 1); | |
| 20 | } else { | |
| 21 | throwResume (empty_exception){&empty_vt}; | |
| 22 | } | |
| [ea593a3] | 23 | } | 
| 24 | ||
| 25 | int main(int argc, char * argv[]) { | |
| 26 | unsigned int times = 1; | |
| 27 | unsigned int total_frames = 1; | |
| [ee23a8d] | 28 | if (1 < argc) { | 
| [f79ee0d] | 29 | times = strto(argv[1], 0p, 10); | 
| [ea593a3] | 30 | } | 
| [ee23a8d] | 31 | if (2 < argc) { | 
| [f79ee0d] | 32 | total_frames = strto(argv[2], 0p, 10); | 
| [ea593a3] | 33 | } | 
| 34 | ||
| [ee23a8d] | 35 | Time start_time = timeHiRes(); | 
| [54651005] | 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 | } | |
| [ee23a8d] | 43 | Time end_time = timeHiRes(); | 
| [f79ee0d] | 44 | sout | "Run-Time (s): " | wd(0,1, (end_time - start_time)`ns / 1_000_000_000.); | 
| [ea593a3] | 45 | } | 
  Note:
 See   TracBrowser
 for help on using the repository browser.
    