[fpc-devel] Closures

Sven Barth pascaldragon at googlemail.com
Mon Jan 16 18:36:43 CET 2012


On 16.01.2012 15:11, Blaise Thorn wrote:
> On 16.01.2012 16:05, Sven Barth wrote:
>
>> How firm are you with the implementation of generics inside the compiler?
>
> Totally blank. Since you are the person who has been working on that
> area most recently, I would actually appreciate if you could compile a
> document (on the wiki?) outlining the internal workings of generics in
> FPC; for the current documentation, I understand, is quite lacking. On
> my part, I already have a document (only in Russian, though) describing
> the implementation of closures; I will translate and publish it after my
> initial commits (which I expect to be on We/Th this week).
>

Might be an idea... currently I'm a bit busy with university, but after 
that (beginning or middle of February) I hope to fully start through 
again :)

>> If you're not that firm it might be better if I implement generic
>> procedures/methods first and then you can build on that (as that
>> should hopefully be reusable by you).
>
> For now, I don't reckon that any ordering is required.
> Note that the only thing in closures that can have type parameters is
> method references
> type M<T> = reference to procedure(const X: T);
> which are converted, internally, into generic interfaces.
> A nameless routine (closure) can only /refer/ to generic type parameters
> of the enclosing routine/class, and I hope that making it
> generic-aware/generic-safe wouldn't be that hard.
>

Ahhh, now I see. I haven't used closures yet, so I didn't know exactly 
in what context generics can be used. Depending on how you parse the 
"reference to" (are you using the parsing of procedure variables here?) 
then you might only need to add the type such a closure is parsed as to 
the types for which generics are supported. If they are indeed converted 
to interfaces you might not have to change that much at all...

Btw: in mode ObjFPC (or non-Delphi modes in general) the declaration 
would then look like this (to be conform with other generic declarations):

type
   generic M<T> = reference to procedure(const X: T);

Again you shouldn't need to change that much.

Regards,
Sven



More information about the fpc-devel mailing list