[fpc-pascal] Creating capturers

Hairy Pixels genericptr at gmail.com
Thu Nov 2 13:56:47 CET 2023



> On Nov 2, 2023, at 1:44 PM, Sven Barth <pascaldragon at googlemail.com> wrote:
> 
> The most important piece of knowledge is that in a routine with nested (or anonymous) routines the nested (or anonymous) routines aren't compiled down to machine code right away. The compiler first parses the whole hierarchy until it's on the global/method level again and only *then* it compiles the outermost routine followed by the nested ones.
> 
> Now for nested as well as anonymous routines the compiler determines whether a capturer is required at the point that the nested or anonymous routine is assigned to a function reference (cause otherwise it can be handled as a nested function or even a function or method pointer). This requirement is detected during the parsing of the routine.
> 
> If the routine requires a capturer then after the whole hierarchy has been parsed, then all the captured variables will be moved from the local symtable of the routine to the capturer or corresponding capture variables for parameters will be introduced and then the whole nodetree will be walked to adjust usages of the involved symbols.
> 
> So, no, there is no copy involved (except for parameter values right at the start of a routine where a parameter is captured) as the whole variables are relocated into the capturer and they're only ever accessed from there.

Ok that makes sense to move the symbols to another table before the function ends. Thanks for your detailed answer.

Regards,
Ryan Joseph



More information about the fpc-pascal mailing list