<html><body style="word-wrap: break-word; -webkit-nbsp-mode: space; -webkit-line-break: after-white-space;" class=""><span style="font-family: monospace; white-space: pre-wrap;" class="">></span><div class=""><span style="font-family: monospace; white-space: pre-wrap;" class="">> </span><font face="monospace" class=""><span style="white-space: pre-wrap;" class="">Wouldn't you need a frame pointer to implement it? The current</span></font><div class=""><font face="monospace" class=""><span style="white-space: pre-wrap;" class="">> compiler does not need one, since the stack frame size is know</span></font></div><div class=""><font face="monospace" class=""><span style="white-space: pre-wrap;" class="">> at compile time, adding this feature would break this invariant.</span></font></div><div class=""><font face="monospace" class=""><span style="white-space: pre-wrap;" class="">> Am I missing something?
></span></font></div><div class=""><font face="monospace" class=""><span style="white-space: pre-wrap;" class=""><br class="Apple-interchange-newline">Luca - good point. I am not sure whether it can be done without </span></font></div><div class=""><font face="monospace" class=""><span style="white-space: pre-wrap;" class="">re-introducing the FP concept. </span></font><span style="font-family: monospace; white-space: pre-wrap;" class="">Perhaps we should add Chris who</span></div><div class=""><span style="font-family: monospace; white-space: pre-wrap;" class="">has actually implemented it in the Astrobe products.</span></div><div class=""><div class=""><br class=""></div></div><div class=""><font face="monospace" class=""><span style="white-space: pre-wrap;" class="">My first reaction:</span></font></div><div class=""><font face="monospace" class=""><span style="white-space: pre-wrap;" class=""><br class=""></span></font></div><div class=""><font face="monospace" class=""><span style="white-space: pre-wrap;" class="">1. From the caller’s point of view, the </span></font><font face="monospace" class=""><span style="white-space: pre-wrap;" class="">size of </span></font><span style="white-space: pre-wrap; font-family: monospace;" class="">the stack frame</span></div><div class=""><span style="white-space: pre-wrap; font-family: monospace;" class="">is </span><span style="white-space: pre-wrap; font-family: monospace;" class="">of course still known, so the procedure </span><span style="white-space: pre-wrap; font-family: monospace;" class="">prologue </span><span style="white-space: pre-wrap; font-family: monospace;" class="">and </span><span style="white-space: pre-wrap; font-family: monospace;" class="">epilogue</span></div><div class=""><span style="white-space: pre-wrap; font-family: monospace;" class="">should be unchanged (I think). </span><span style="white-space: pre-wrap; font-family: monospace;" class="">It is only *inside* the </span><span style="white-space: pre-wrap; font-family: monospace;" class="">local</span></div><div class=""><font face="monospace" class=""><span style="white-space: pre-wrap;" class="">procedure </span></font><span style="white-space: pre-wrap; font-family: monospace;" class="">that additional data gets </span><span style="white-space: pre-wrap; font-family: monospace;" class="">allocated on the stack</span></div><div class=""><span style="white-space: pre-wrap; font-family: monospace;" class="">via calls to NEW(array, size).</span></div><div class=""><span style="white-space: pre-wrap; font-family: monospace;" class=""><br class=""></span></div><div class=""><span style="white-space: pre-wrap; font-family: monospace;" class="">2. If this is </span><span style="white-space: pre-wrap; font-family: monospace;" class="">implemented by </span><span style="font-family: monospace; white-space: pre-wrap;" class="">adjusting </span><span style="font-family: monospace; white-space: pre-wrap;" class="">the stack pointer, then</span></div><div class=""><span style="font-family: monospace; white-space: pre-wrap;" class="">you </span><span style="font-family: monospace; white-space: pre-wrap;" class="">do have a </span><span style="font-family: monospace; white-space: pre-wrap;" class="">point: i.e. the question </span><span style="font-family: monospace; white-space: pre-wrap;" class="">is how the </span><font face="monospace" class=""><span style="white-space: pre-wrap;" class="">stack pointer </span></font></div><div class=""><font face="monospace" class=""><span style="white-space: pre-wrap;" class="">gets </span></font><font face="monospace" class=""><span style="white-space: pre-wrap;" class="">readjusted </span></font><font face="monospace" class=""><span style="white-space: pre-wrap;" class="">in the "right way” at </span></font><span style="font-family: monospace; white-space: pre-wrap;" class="">the </span><span style="font-family: monospace; white-space: pre-wrap;" class="">end of the procedure,</span></div><div class=""><span style="font-family: monospace; white-space: pre-wrap;" class="">given </span><span style="font-family: monospace; white-space: pre-wrap;" class="">that the amount by how much it needs to adjusted is not</span></div><div class=""><span style="font-family: monospace; white-space: pre-wrap;" class="">known </span><span style="font-family: monospace; white-space: pre-wrap;" class="">at compile time?</span></div><div class=""><span style="font-family: monospace; white-space: pre-wrap;" class=""><br class=""></span></div><div class=""><span style="font-family: monospace; white-space: pre-wrap;" class="">3. But what if the compiler reserves - and does this *only*</span></div><div class=""><span style="font-family: monospace; white-space: pre-wrap;" class="">for procedures that actually </span><span style="font-family: monospace; white-space: pre-wrap;" class="">contain calls to NEW(a, size) -</span></div><div class=""><span style="font-family: monospace; white-space: pre-wrap;" class="">one</span><span style="font-family: monospace; white-space: pre-wrap;" class=""> additional hidden local </span><span style="font-family: monospace; white-space: pre-wrap;" class="">variable on the stack that</span></div><div class=""><span style="font-family: monospace; white-space: pre-wrap;" class="">simply keeps track of allocations: each </span><span style="font-family: monospace; white-space: pre-wrap;" class="">time NEW(a, size)</span></div><div class=""><span style="white-space: pre-wrap; font-family: monospace;" class="">is called, that counter gets incremented </span><span style="white-space: pre-wrap; font-family: monospace;" class="">by ’size’. And</span></div><div class=""><span style="white-space: pre-wrap; font-family: monospace;" class="">before </span><span style="white-space: pre-wrap; font-family: monospace;" class="">the procedure epilogue gets executed, the </span><span style="white-space: pre-wrap; font-family: monospace;" class="">compiler</span></div><div class=""><span style="white-space: pre-wrap; font-family: monospace;" class="">could simply insert an instruction, that adjusts the stack</span></div><div class=""><font face="monospace" class=""><span style="white-space: pre-wrap;" class="">pointer by the amount stored in the hidden variable, i.e.</span></font></div><div class=""><font face="monospace" class=""><span style="white-space: pre-wrap;" class="">by how much the stack pointer has been adjusted during</span></font></div><div class=""><font face="monospace" class=""><span style="white-space: pre-wrap;" class="">execution of the local procedure.</span></font></div><div class=""><font face="monospace" class=""><span style="white-space: pre-wrap;" class=""><br class=""></span></font></div><div class=""><div class=""><font face="monospace" class=""><span style="white-space: pre-wrap;" class="">The cost is (a) 4 bytes extra local stack space for the counter</span></font></div><div class=""><font face="monospace" class=""><span style="white-space: pre-wrap;" class="">and (b) the fact that NEW contains one addition </span></font><span style="white-space: pre-wrap; font-family: monospace;" class="">instruction.</span></div></div><div class=""><span style="white-space: pre-wrap; font-family: monospace;" class=""><br class=""></span></div><div class=""><font face="monospace" class=""><span style="white-space: pre-wrap;" class="">I guess that is one implementation option I would</span></font></div><div class=""><font face="monospace" class=""><span style="white-space: pre-wrap;" class="">probably consider. </span></font><span style="white-space: pre-wrap; font-family: monospace;" class="">It seems fairly easy to implement</span></div><div class=""><span style="white-space: pre-wrap; font-family: monospace;" class="">with only a few lines of extra code in the </span><span style="white-space: pre-wrap; font-family: monospace;" class="">compiler),</span></div><div class=""><span style="white-space: pre-wrap; font-family: monospace;" class="">but perhaps there are other - better - ways </span><span style="white-space: pre-wrap; font-family: monospace;" class="">to do it.</span></div><div class=""><font face="monospace" class=""><span style="white-space: pre-wrap;" class=""><br class=""></span></font></div><div class=""><font face="monospace" class=""><span style="white-space: pre-wrap;" class="">-AP</span></font></div><div class=""><font face="monospace" class=""><span style="white-space: pre-wrap;" class=""><br class=""></span></font></div></div></body></html>