Before it's too late: delegate calling convention
Lionello Lunesu
lio at lunesu.remove.com
Thu Nov 2 05:58:19 PST 2006
Jarrett Billingsley wrote:
> "Lionello Lunesu" <lio at lunesu.remove.com> wrote in message
> news:eic2t2$2hjj$1 at digitaldaemon.com...
>> Actually, it's passed in a register, so it could be made to work.
>
> Ahh, but so are parameters. Since the last parameter of a function is
> passed in EAX (as long as it fits), something like..
>
> void fork(int x, int y)
>
> Will take y on the stack and x in EAX. But then converting it to a
> delegate, Y would end up past the end of the arguments, x in y's spot, and
> the context in x's spot. :S
>
>
It's not EAX, but a different register :)
IIRC, Thomas has made a working example once, using inline assembly. I
think it was indeed putting the context pointer of a delegate to null
(ignoring it would work to) and calling the function-pointer as a normal
function.
To make this work without changing the ABI would mean an extra
null-check before calling the delegate:
if (dg.ptr !is null)
// push/mov for delegate ABI
else
// push/mov for function-pointer ABI
asm { call dg.func; }
Making the two calling conventions compatible would mean that the
context pointer would be stored somewhere where it doesn't interfere
with C's function-pointer ABI. ... Right?
L.
More information about the Digitalmars-d
mailing list