Recent

Author Topic: Making a plea :)  (Read 6415 times)

PascalDragon

  • Hero Member
  • *****
  • Posts: 5750
  • Compiler Developer
Re: Making a plea :)
« Reply #135 on: October 12, 2024, 05:31:14 pm »
Anonymous functions/procedure come somewhat close to providing such a facility but, they have a number of undesirable downsides that could easily be eliminated.

While technically that might be possible, conceptually it is not, because anonymous functions, or more precisely function references are supposed to work like in Delphi, because that's the main reason they've been implemented at all. It's already an extension by us that anonymous functions can also be assigned to (nested) function pointers or method pointers assuming they don't capture anything that would prohibit that conversion.

440bx

  • Hero Member
  • *****
  • Posts: 4727
Re: Making a plea :)
« Reply #136 on: October 12, 2024, 07:12:07 pm »
While technically that might be possible, conceptually it is not, because anonymous functions, or more precisely function references are supposed to work like in Delphi, because that's the main reason they've been implemented at all. It's already an extension by us that anonymous functions can also be assigned to (nested) function pointers or method pointers assuming they don't capture anything that would prohibit that conversion.
I am guilty of not being as clear as I should have been.

If a function is defined then a stack frame is almost always necessary and, the reasons you mention make it clear that, in those cases a stack frame will be necessary for no other reason than functional compatibility with Delphi (not the only one either.)

I should have made it clear, as I going to do now that, a region/grouping mechanism that is _not_ callable and is simply a grouping mechanism does not ever need a stack frame _even_ if variables are defined in it.  The compiler can simply internally "think" of the variables as having been defined in a "var" section of the containing function/procedure (with the difference that they would not be visible to code outside the region, iow, they would _not_ be function/procedure global.)

Not only that helps lower the number of variables declared in the function (which are global to the function, which is bad) and, is the ideal mechanism to localize temporary variables used by a short sequence of code that is not used anywhere else (if it were used somewhere else then, it should be a function/procedure which is what those are for, to denote that the code is re-used.)
(FPC v3.0.4 and Lazarus 1.8.2) or (FPC v3.2.2 and Lazarus v3.2) on Windows 7 SP1 64bit.

 

TinyPortal © 2005-2018