source: doc/theses/andrew_beach_MMath/code/resume-detor.cfa @ 6ff08d8

ADTast-experimentalenumforall-pointer-decayjacob/cs343-translationnew-ast-unique-exprpthread-emulationqualifiedEnum
Last change on this file since 6ff08d8 was ee23a8d, checked in by Andrew Beach <ajbeach@…>, 3 years ago

Added duration information (in nanoseconds) to EHM benchmarks.

  • Property mode set to 100644
File size: 1005 bytes
Line 
1// Throw Across Destructor
2#include <clock.hfa>
3#include <exception.hfa>
4#include <fstream.hfa>
5#include <stdlib.hfa>
6
7EHM_EXCEPTION(empty_exception)();
8
9EHM_VIRTUAL_TABLE(empty_exception, empty_vt);
10
11struct WithDestructor {};
12
13void ^?{}(WithDestructor & this) {
14    // ...
15}
16
17void unwind_destructor(unsigned int frames) {
18    if (frames) {
19
20        WithDestructor object;
21        unwind_destructor(frames - 1);
22    } else {
23        throwResume (empty_exception){&empty_vt};
24    }
25}
26
27int main(int argc, char * argv[]) {
28        unsigned int times = 1;
29        unsigned int total_frames = 1;
30        if (1 < argc) {
31                times = strtol(argv[1], 0p, 10);
32        }
33        if (2 < argc) {
34                total_frames = strtol(argv[2], 0p, 10);
35        }
36
37        Time start_time = timeHiRes();
38    for (int count = 0 ; count < times ; ++count) {
39        try {
40            unwind_destructor(total_frames);
41        } catchResume (empty_exception *) {
42            // ...
43        }
44    }
45        Time end_time = timeHiRes();
46        sout | "Run-Time (ns): " | (end_time - start_time)`ns;
47}
Note: See TracBrowser for help on using the repository browser.