www.digitalmars.com         C & C++   DMDScript  

digitalmars.D - proposal : functions->delegates

reply Thorsten Kiefer <thorstenkiefer gmx.de> writes:
Hi,
IMHO the compiler should be able to implicitly convert function-pointers into
delegate-pointers.
Before the delegate is passed as argument, the context-pointer is filled in.
Now when I pass a function, the context-pointer could simply be filled with
null.
A problem will be, where to store the context-pointer in a function, as it has
no context-pointer (to preserve compatibility with C).

Or the compiler could implicitly create an anonymous delegate around that
function.
Mar 03 2007
parent reply Lionello Lunesu <lio lunesu.remove.com> writes:
Thorsten Kiefer wrote:
 Hi,
 IMHO the compiler should be able to implicitly convert function-pointers into
delegate-pointers.
 Before the delegate is passed as argument, the context-pointer is filled in.
 Now when I pass a function, the context-pointer could simply be filled with
null.
At the moment it can't, since delegates and function-pointers have incompatible calling conventions.
 A problem will be, where to store the context-pointer in a function, as it has
no context-pointer (to preserve compatibility with C).
There's another thread on that, "D 2.0 - dalegates to function"
 Or the compiler could implicitly create an anonymous delegate around that
function.
That would be a good transitional solution, but because it involves an extra function call, I'd still hope the delegate and function-pointer calling-convention can be made compatible. L.
Mar 03 2007
parent Stewart Gordon <smjg_1998 yahoo.com> writes:
Lionello Lunesu Wrote:

 Thorsten Kiefer wrote:
 Hi, IMHO the compiler should be able to implicitly convert 
 function-pointers into delegate-pointers.  Before the 
 delegate is passed as argument, the context-pointer is filled 
 in.  Now when I pass a function, the context-pointer could 
 simply be filled with null.
At the moment it can't, since delegates and function-pointers have incompatible calling conventions.
Well, it certainly used to work under at least some platform/compiler combinations. I've looked, and it would appear to be a mere matter of whether a context pointer is pushed to the stack as well. The ABI doesn't make it clear whether parameters/local variables are addressed from the bottom or the top of the stack frame. From my experiment, it would appear to be the bottom. <snip>
 That would be a good transitional solution, but because it 
 involves an extra function call, I'd still hope the delegate 
 and function-pointer calling-convention can be made compatible.
Indeed. And one way that's been suggested is to pass the context pointer in a register rather than pushing it to the stack. Stewart.
Mar 04 2007