Gale Paeper wrote:
In looking at the generated assembly code, it looks like the main program trash procedure isn't being treated by the backend as a nested routine. Both C and Pascal nested routines get a ".0" label suffix which non-nested routines don't get. Since the main program trash doesn't get the ".0" label suffix, it appears that the backend is handling it as a non-nested routine.
In fact the frontend does that -- deliberately (local routines need trampolines for routine pointers and all that stuff, and we don't want that for global (local to the main program, if you will) routines).
So, it appears that for Pascal the behavioral effects depend upon whether or not a non-nested procedure has global or non-global linkage (or in C terminalogy external or static/non-external linkage).
Static/external doesn't seem to make a difference AFAICS (neither in C nor Pascal), and I'm only considering global (i.e., non-nested) routines.
The difference really seems to be the call (from the same module), according to some debuggin I did, but I can't reproduce it in C.
Even stranger, in both compilers, optimize_tail_recursion() is called once and returns 1, according to the comment this means "the call was optimized into a goto." If that's true, it must be somehow un-optimized later!? I don't really understand this, it seems to require some deeper backend debugging for which I don't have the time now, I'm afraid.
Frank