ADTast-experimentalenumforall-pointer-decaypthread-emulationqualifiedEnum
Last change
on this file since 49b3389 was
18783b4,
checked in by Peter A. Buhr <pabuhr@…>, 3 years ago
|
attempt to remove tail-recursion optimization
|
-
Property mode set to
100644
|
File size:
965 bytes
|
Rev | Line | |
---|
[f79ee0d] | 1 | // Resume Across Fixup |
---|
| 2 | #include <clock.hfa> |
---|
| 3 | #include <fstream.hfa> |
---|
| 4 | #include <stdlib.hfa> // strto |
---|
| 5 | |
---|
[18783b4] | 6 | void nounwind_fixup(unsigned int frames, void (*raised_rtn)(int &)) { |
---|
[f79ee0d] | 7 | if (frames) { |
---|
[18783b4] | 8 | nounwind_fixup(frames - 1, raised_rtn); |
---|
| 9 | if ( frames == -1 ) printf( "42" ); // prevent recursion optimizations |
---|
[f79ee0d] | 10 | } else { |
---|
| 11 | int fixup = 17; |
---|
| 12 | raised_rtn(fixup); |
---|
| 13 | } |
---|
| 14 | } |
---|
| 15 | |
---|
| 16 | int main(int argc, char * argv[]) { |
---|
| 17 | unsigned int times = 1; |
---|
| 18 | unsigned int total_frames = 1; |
---|
| 19 | if (1 < argc) { |
---|
| 20 | times = strto(argv[1], 0p, 10); |
---|
| 21 | } |
---|
| 22 | if (2 < argc) { |
---|
| 23 | total_frames = strto(argv[2], 0p, 10); |
---|
| 24 | } |
---|
| 25 | |
---|
| 26 | void raised(int & fixup) { |
---|
| 27 | fixup = total_frames + 42; // use local scope => lexical link |
---|
[01f78e0] | 28 | if ( total_frames == 42 ) printf( "42" ); |
---|
[f79ee0d] | 29 | } |
---|
| 30 | |
---|
| 31 | Time start_time = timeHiRes(); |
---|
| 32 | for (unsigned int count = 0 ; count < times ; ++count) { |
---|
| 33 | nounwind_fixup(total_frames, raised); |
---|
| 34 | } |
---|
| 35 | Time end_time = timeHiRes(); |
---|
| 36 | sout | "Run-Time (s): " | wd(0,1, (end_time - start_time)`ns / 1_000_000_000.); |
---|
| 37 | } |
---|
Note: See
TracBrowser
for help on using the repository browser.