Re: clearing "return info" in a function
- Posted by PeteE May 30, 2013
- 1291 views
I have to eat my words, since I didn't try this beforehand:
function foo(integer x) if x = 0 then return 0 end if return foo(x-1) end function ? foo(1000000000)
You'd expect this to blow the stack, but it runs fine in the interpreter. And the translated code shows goto instead of recursive call! Seems Euphoria IS smart enough to detect and optimize tail calls - great job guys!
int _1foo(int _x_142) { int _9 = NOVALUE; int _0, _1, _2; L1: if (!IS_ATOM_INT(_x_142)) { _1 = (long)(DBL_PTR(_x_142)->dbl); DeRefDS(_x_142); _x_142 = _1; } /** if x = 0 then*/ if (_x_142 != 0) goto L2; // [7] 18 /** return 0*/ return 0; L2: /** return foo(x-1)*/ _9 = _x_142 - 1; if ((long)((unsigned long)_9 +(unsigned long) HIGH_BITS) >= 0){ _9 = NewDouble((double)_9); } _0 = _x_142; _x_142 = _9; DeRef(_0); DeRef(_9); _9 = NOVALUE; goto L1; // [24] 1 ; }