Ignore:
Timestamp:
Aug 30, 2021, 9:01:51 PM (3 years ago)
Author:
Peter A. Buhr <pabuhr@…>
Branches:
ADT, ast-experimental, enum, forall-pointer-decay, jacob/cs343-translation, master, pthread-emulation, qualifiedEnum
Children:
2a3f0d9
Parents:
9cb6514
Message:

add code to prevent tail recursion optimization

Location:
doc/theses/andrew_beach_MMath/code
Files:
2 edited

Legend:

Unmodified
Added
Removed
  • doc/theses/andrew_beach_MMath/code/resume-fixup-empty-f.cfa

    r9cb6514 r01f78e0  
    44#include <stdlib.hfa>                                                                   // strto
    55
    6 void nounwind_fixup(unsigned int frames, void (*raised_rtn)(int &)) {
     6int nounwind_fixup(unsigned int frames, void (*raised_rtn)(int &)) {
    77        if (frames) {
    8                 nounwind_fixup(frames - 1, raised_rtn);
     8                int rtn = nounwind_fixup(frames - 1, raised_rtn);
     9                if ( rtn == 42 ) printf( "42" );                                // make non-tail recursive
     10                return rtn;
     11
    912        } else {
    1013                int fixup = 17;
    1114                raised_rtn(fixup);
     15                return fixup;
    1216        }
    1317}
     
    2529        void raised(int & fixup) {
    2630                fixup = total_frames + 42;                                              // use local scope => lexical link
     31                if ( total_frames == 42 ) printf( "42" );
    2732        }
    2833
  • doc/theses/andrew_beach_MMath/code/resume-fixup-empty-r.cfa

    r9cb6514 r01f78e0  
    1010vtable(fixup_exception) fixup_vt;
    1111
    12 void nounwind_empty(unsigned int frames) {
     12int nounwind_empty(unsigned int frames) {
    1313        if (frames) {
    14                 nounwind_empty(frames - 1);
     14                int rtn = nounwind_empty(frames - 1);
     15                if ( rtn == 42 ) printf( "42" );                                // make non-tail recursive
     16                return rtn;
    1517        } else {
    1618                int fixup = 17;
    1719                throwResume (fixup_exception){&fixup_vt, fixup}; // change bad fixup
     20                return fixup;
    1821        }
    1922}
Note: See TracChangeset for help on using the changeset viewer.