This is the mail archive of the fortran@gcc.gnu.org mailing list for the GNU Fortran project.


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]
Other format: [Raw text]

Implementing BLOCK


Hi all,

I was just thinking about ideas for implementing the Fortran 2008 BLOCK construct; that could be an interesting thing to do in parallel to the OOP stuff.

As I understand it (but haven't yet read the standard/draft about it), the main semantics of BLOCK is that it allows declaration of variables limited to an arbitrary smaller scope inside a procedure. Another thing is that F2008 allows EXIT to also jump out of BLOCKs (and IF I guess, too?), but that should be a minor issue for implementation (seems so to me at least).

I believe it should be relatively straight-forward to implement a basic BLOCK concept; in gfortran's data structure, we could make BLOCKs new EXEC-codes which reference a namespace/symtree containing the variable declarations as well as inner code. I hope that approach could reuse a lot of code already in place, for instance doing the trans'ing of local variable declarations as would be done at the start of a procedure.

Haven't checked the standard, but I would bet this is also allowed with BLOCK (and would make it nice to have, IMHO):

INTEGER :: n

...

n = <some number, not constant>

BLOCK
  INTEGER :: array(n)
  ...
END BLOCK

So one could use dynamically sized arrays on the stack without having to ALLOCATE them.

This one may need a little more thought from the implementation point-of-view, but on the other hand something similar should already be done for procedures...

All in all, I think BLOCK should not be too hard to do. What do you think about implementing BLOCK and my ideas above? If I haven't missed something essential or this approach could be problematic with issues I don't yet see, I'll start working on this as soon as I find time.

Yours,
Daniel

PS: Is there already a PR for this one or should I open one? I will look for one / create it this evening, have to leave now.

--
Done:  Arc-Bar-Cav-Ran-Rog-Sam-Tou-Val-Wiz
To go: Hea-Kni-Mon-Pri


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]