January 24, 2022
On 21.01.22 13:55, ag0aep6g wrote:
> On 21.01.22 13:33, Mike Parker wrote:
>> ### Mathias
>> Mathias would very much like to see the unification of delegates and function pointers. There was general agreement that this is a good goal to aim for. Mathias subsequently informed me he will look into it once some other things are off his TODO list if no one else gets to it first.
> 
> I still believe it should be fairly simple:
> 
> https://forum.dlang.org/post/ofc0lj$2u4h$1@digitalmars.com

Proof of concept:

https://github.com/aG0aep6G/dmd/commit/aa0563a49536e42fe9b2c1c2d540a7f1f1b075d4

With that tiny patch, this works:

----
void func(int x, int y)
{
    import core.stdc.stdio: printf;
    printf("%d %d\n", x, y);
}
void main()
{
    void delegate(int x, int y) dg;
    dg.funcptr = &func;
    dg(1, 2); /* prints "1 2" */
}
----
January 24, 2022
On Friday, 21 January 2022 at 12:55:58 UTC, ag0aep6g wrote:
> I still believe it should be fairly simple:
>
> https://forum.dlang.org/post/ofc0lj$2u4h$1@digitalmars.com

There is a simpler solution: put the context pointer in rax.  This is currently a caller-saved register, so there is no problem with clobbering it.  It is used for c-style variadics, but not d-style ones.  Since it is a register, nothing breaks when you have more parameters than fit in registers.  Any other problems?
January 24, 2022
On Mon, Jan 24, 2022 at 10:56:57PM +0000, Elronnd via Digitalmars-d-announce wrote:
> On Friday, 21 January 2022 at 12:55:58 UTC, ag0aep6g wrote:
> > I still believe it should be fairly simple:
> > 
> > https://forum.dlang.org/post/ofc0lj$2u4h$1@digitalmars.com
> 
> There is a simpler solution: put the context pointer in rax.  This is currently a caller-saved register, so there is no problem with clobbering it.  It is used for c-style variadics, but not d-style ones.  Since it is a register, nothing breaks when you have more parameters than fit in registers.  Any other problems?

This may work for x86, but does it work for other platforms? If not, it won't fly on LDC/GDC.


T

-- 
Life is complex. It consists of real and imaginary parts. -- YHL
January 25, 2022
On Tuesday, 25 January 2022 at 00:08:54 UTC, H. S. Teoh wrote:
> This may work for x86, but does it work for other platforms? If not, it won't fly on LDC/GDC.

I don't think there's anything wrong with d having its own ABI.  But, I checked arm and riscv: both of their c calling conventions have scratch registers not used for parameter-passing.
1 2 3
Next ›   Last »