ADT
ast-experimental
enum
forall-pointer-decay
jacob/cs343-translation
pthread-emulation
qualifiedEnum
Last change
on this file since ff3be413 was 01f78e0, checked in by Peter A. Buhr <pabuhr@…>, 4 years ago |
add code to prevent tail recursion optimization
|
-
Property mode
set to
100644
|
File size:
1.0 KB
|
Rev | Line | |
---|
[f79ee0d] | 1 | // Resume Across Empty Function
|
---|
| 2 | #include <clock.hfa>
|
---|
| 3 | #include <exception.hfa>
|
---|
| 4 | #include <fstream.hfa>
|
---|
| 5 | #include <stdlib.hfa> // strto
|
---|
| 6 |
|
---|
| 7 | exception fixup_exception {
|
---|
| 8 | int & fixup;
|
---|
| 9 | };
|
---|
| 10 | vtable(fixup_exception) fixup_vt;
|
---|
| 11 |
|
---|
[01f78e0] | 12 | int nounwind_empty(unsigned int frames) {
|
---|
[f79ee0d] | 13 | if (frames) {
|
---|
[01f78e0] | 14 | int rtn = nounwind_empty(frames - 1);
|
---|
| 15 | if ( rtn == 42 ) printf( "42" ); // make non-tail recursive
|
---|
| 16 | return rtn;
|
---|
[f79ee0d] | 17 | } else {
|
---|
| 18 | int fixup = 17;
|
---|
| 19 | throwResume (fixup_exception){&fixup_vt, fixup}; // change bad fixup
|
---|
[01f78e0] | 20 | return fixup;
|
---|
[f79ee0d] | 21 | }
|
---|
| 22 | }
|
---|
| 23 |
|
---|
| 24 | int main(int argc, char * argv[]) {
|
---|
| 25 | unsigned int times = 1;
|
---|
| 26 | unsigned int total_frames = 1;
|
---|
| 27 | if (1 < argc) {
|
---|
| 28 | times = strto(argv[1], 0p, 10);
|
---|
| 29 | }
|
---|
| 30 | if (2 < argc) {
|
---|
| 31 | total_frames = strto(argv[2], 0p, 10);
|
---|
| 32 | }
|
---|
| 33 |
|
---|
| 34 | Time start_time = timeHiRes();
|
---|
| 35 | for (unsigned int count = 0 ; count < times ; ++count) {
|
---|
| 36 | try {
|
---|
| 37 | nounwind_empty(total_frames);
|
---|
| 38 | } catchResume (fixup_exception * ex) {
|
---|
| 39 | ex->fixup = total_frames + 42;
|
---|
| 40 | }
|
---|
| 41 | }
|
---|
| 42 | Time end_time = timeHiRes();
|
---|
| 43 | sout | "Run-Time (s): " | wd(0,1, (end_time - start_time)`ns / 1_000_000_000.);
|
---|
| 44 | }
|
---|
Note:
See
TracBrowser
for help on using the repository browser.