[fpc-pascal] Caller agnostic procedure variables
Sven Barth
pascaldragon at googlemail.com
Tue Feb 15 14:32:09 CET 2022
Ryan Joseph via fpc-pascal <fpc-pascal at lists.freepascal.org> schrieb am
Di., 15. Feb. 2022, 13:14:
>
>
> > On Feb 15, 2022, at 5:15 PM, Sven Barth <pascaldragon at googlemail.com>
> wrote:
> >
> > It contains a capture object that backs the method.
> > If nothing is captured and the right hand side is a direct function or
> method pointer then the compiler could in principle create something that
> is essentially static to avoid allocations, but that would be a future
> optimization.
> >
>
> So if we do this there is nothing being captured right? In that case we
> get an interface which can call a function pointer? Does the interface then
> know about "of object" and "is nested" types at all or does it use a
> totally different mechanism to call those?
>
A function reference is simply an interface of which the Invoke method can
be called on the instance instead of manually doing "Foo.Invoke".
The real "magic" is when the compiler generates the *implementation* of
said interface. So in the end what can be assigned to a function reference
depends on the compiler being able to generate suitable implementations.
Anonymous functions are a given. Global functions and methods are required
to work as well. Nested functions can be made to use as well. Function and
method variables can be supported relatively easily as well. Only nested
function variables are hard to support.
Regards,
Sven
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.freepascal.org/pipermail/fpc-pascal/attachments/20220215/3e72ae20/attachment-0001.htm>
More information about the fpc-pascal
mailing list