[fpc-devel] Local procedures as procedural parameter

Peter Vreman peter at freepascal.org
Wed Mar 16 21:46:14 CET 2005


>>> That won't work on x86 when the static link would be on the stack,
>>> because there the callee removes the parameters from the stack (so if
>>> it's a global function, it will remove sizeof(pointer) bytes too
>>> little from the stack.
>>
>> On x86, you can generate code that checks the static link pointer at
>> runtime, to see if it is nil or not (e.g. a global function or not).
>> Then, you pass the static link pointer as the last parameter (for
>> local procedures) or not (for global procedures).
>
> Then you can do it just as well on ppc and other processors, but the
> point of the trick was to avoid having to do this. Implementing this
> sort of hacks will complicate the code generator (I'm not even
> immediately sure how it would be implemented).

This is a not possible. It is incompatible with Delphi calling conventions
and not possible with register calling conventions. Also take into account
 that modes are per unit. And other units (like the RTL) are not in
gpc/macpas mode and don't expect the extra parameter and do not remove it
from the stack.

Also generating code at runtime is a no-go for me. It is heavily CPU and
OS dependent.

Note: Also thinking with things like "On x86" is the wrong way for current
FPC. It should be possible to support things (without hacks) on all
supported CPUs.







More information about the fpc-devel mailing list