Thread overview | |||||||
---|---|---|---|---|---|---|---|
|
September 16, 2018 Manual delegates | ||||
---|---|---|---|---|
| ||||
Anyone has any information about the ABI of delegates? In particular how to call them with a particular "this"/frame pointer? To solve a hairy problem I need a delegate with a synthesized frame pointer. https://dpaste.dzfl.pl/cf44417c98f9 The problem is that delegate forwarding seems to require GC closures. I want manually-managed closures. |
September 16, 2018 Re: Manual delegates | ||||
---|---|---|---|---|
| ||||
Posted in reply to Guillaume Piolat | On Sunday, 16 September 2018 at 14:12:27 UTC, Guillaume Piolat wrote: > In particular how to call them with a particular "this"/frame pointer? > Related thread: https://forum.dlang.org/post/wjbhpztovxratexaobpp@forum.dlang.org |
September 16, 2018 Re: Manual delegates | ||||
---|---|---|---|---|
| ||||
Posted in reply to Guillaume Piolat | On Sunday, 16 September 2018 at 14:12:27 UTC, Guillaume Piolat wrote: > Anyone has any information about the ABI of delegates? > > In particular how to call them with a particular "this"/frame pointer? > > To solve a hairy problem I need a delegate with a synthesized frame pointer. > https://dpaste.dzfl.pl/cf44417c98f9 > > The problem is that delegate forwarding seems to require GC closures. I want manually-managed closures. Have a look at the implementation of toDelegate, which does exactly this: https://github.com/dlang/phobos/blob/v2.082.0/std/functional.d#L1463 |
September 17, 2018 Re: Manual delegates | ||||
---|---|---|---|---|
| ||||
Posted in reply to Vladimir Panteleev | On Sunday, 16 September 2018 at 14:45:08 UTC, Vladimir Panteleev wrote:
> On Sunday, 16 September 2018 at 14:12:27 UTC, Guillaume Piolat wrote:
>> Anyone has any information about the ABI of delegates?
>>
>> In particular how to call them with a particular "this"/frame pointer?
>>
>> To solve a hairy problem I need a delegate with a synthesized frame pointer.
>> https://dpaste.dzfl.pl/cf44417c98f9
>>
>> The problem is that delegate forwarding seems to require GC closures. I want manually-managed closures.
>
> Have a look at the implementation of toDelegate, which does exactly this:
>
> https://github.com/dlang/phobos/blob/v2.082.0/std/functional.d#L1463
Thanks.
I ended up using toDelegate internally, and enclosing the resulting delegate with code returning a struct with `opCall`.
The conclusion is that "struct with `opCall`" is much easier to implement that faking delegate ABI, this is less brittle ; and doesn't add a lifetime of a trampoline context to extend the input delegate.
|
September 19, 2018 Re: Manual delegates | ||||
---|---|---|---|---|
| ||||
Posted in reply to Guillaume Piolat | On 2018-09-16 16:12, Guillaume Piolat wrote: > Anyone has any information about the ABI of delegates? > > In particular how to call them with a particular "this"/frame pointer? You can explicitly set the context pointer of a delegate using the ".ptr" property: class Foo { void bar() { } } void main() { auto a = new Foo; void delegate () dg; dg.ptr = cast(void*) a; dg.funcptr = &Foo.bar; dg(); } > To solve a hairy problem I need a delegate with a synthesized frame pointer. > https://dpaste.dzfl.pl/cf44417c98f9 > > The problem is that delegate forwarding seems to require GC closures. I want manually-managed closures. -- /Jacob Carlborg |
Copyright © 1999-2021 by the D Language Foundation