[fpc-pascal] Traits Proposal
Sven Barth
pascaldragon at googlemail.com
Tue Feb 16 19:44:18 CET 2021
Ryan Joseph via fpc-pascal <fpc-pascal at lists.freepascal.org> schrieb am
Di., 16. Feb. 2021, 19:22:
>
>
> > On Feb 15, 2021, at 11:41 PM, Sven Barth via fpc-pascal <
> fpc-pascal at lists.freepascal.org> wrote:
> >
> > Again, the point of the interface would be to control which methods and
> properties of the delegated type would be available. Also it would allow
> for seamless integration with the RTTI as it's possible to query the
> implemented interface of a class and to retrieve a reference to it, thus it
> would be possible to access this at runtime as well.
> >
> > The compiler will generate a VMT for the interface with method thunks
> that adjust the Self pointer so that it works correctly. The
> GetInterfaceByEntry function uses this static data to generate an adjusted
> Self value that callers can use.
>
> As far as the "default implements property" is concerned we don't actually
> need, or even want to utilize the interfaces themselves. The idea of
> leveraging the interface syntax for exporting method names is one thing but
> if we actually have to use the interfaces internally then we open a whole
> can of worms in terms of performance. Class instantiation may be taking on
> some significant baggage now also as the compiler sets up these interface
> VMT tables, even if the user never needs or wants them.
>
> For example this code should be a compile time indirection instead of a
> hidden interface cast, right? The method forwarding syntax which works by
> modifying the VMT can hopefully be done at compile time for the default
> property also.
>
I wasn't saying anything that contradicts this, only that the original
mechanism of the delegation will be available even with the default
modifier and this mechanism will in fact be necessary to access them
through RTTI.
Regards,
Sven
>
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.freepascal.org/pipermail/fpc-pascal/attachments/20210216/429acf19/attachment.htm>
More information about the fpc-pascal
mailing list