D 2.0 - dalegates to function

Frits van Bommel fvbommel at REMwOVExCAPSs.nl
Thu Mar 1 04:43:10 PST 2007


Reiner Pope wrote:
> sergk wrote:
>> Perhaps it's time to to bump an old request postponed to 2.0 times =)
>>
>> So, how about to add some thunking magic - how  complex/complicated to 
>> implement it?
>>
> This works, except for the inout issue as Frits mentioned:
> 
>> T delegate(U) thunkify(T, U...)(T function(U) f)
>> {
>>     struct Foo
>>     {
>>         T function(U) _f;
>>         T run(U u) { return _f(u); }
>>     }
>>     Foo* value = new Foo;
>>     value._f = f;
>>     return &value.run;
>> }

Your version re-pushes arguments. Also, I'm pretty sure it doesn't 
handle varargs.

I'd also like to note that my version for this (delegate that calls a 
function) should be implementable right now, without re-pushing 
arguments and with vararg support (I think). The only case it _doesn't_ 
handle is if the last parameter is out/inout, and would otherwise not be 
passed in EAX. So it only breaks if a 3-byte struct or anything larger 
than 4 bytes is passed as the last parameter and that parameter is out 
or inout.
That is, aside from the fact it only supports DMD's extern(D) functions.



More information about the Digitalmars-d mailing list