[M3devel] gcc 4.5.0?

Rodney M. Bates rodney_bates at lcwb.coop
Thu May 20 19:12:00 CEST 2010


gcc even extends C with nested functions, and the support is there for that.  We use it too.

Beware:  The runtime model is, IMO, bizarre.  Definitely counterintuitive and unlike anything
you will ever see elsewhere.  There are two static links.  One is used for the first step
in following a static chain and points to the expected place in the target frame.  The other
is used of subsequent steps in chain-following, and points to somewhere inside the target
frame that is dependent on the target procedure.  It's the beginning of a subrecord where
all the nonlocally-referenced variables are collected.  The second static link is also
located in there.  All the nonlocally-referenced variables and parameters are duplicated
in there too.

I'm not sure I remembered these details exactly right.  Maybe both links point to the
subrecord, but one is located at a traditional procedure-independent, fixed location
in the frame, while the second is located in the subrecord.  Also, sometimes the first
static link value is kept in a register and never stored.

What this all apparently accomplishes is simplifying an "insanely complicated" _compile-time_
scheme that, I believe came from interaction between nested procedures and inlining them.

But it's at the cost of what I would call an insanely complicated _runtime_ scheme.

It undermined m3gdb's handling of static links, and I don't think it's possible to fix
with the current design of emitting debug info very early.  The locations and target
offsets of these things aren't know until later, and m3gdb really needs to know them.


Jay K wrote:
> What I meant regarding "static chain" was more like "does gcc already have support that we can use".
> Don't any of the other languages need it already?
> Ada? Pascal? Maybe the nested C function support?
> 
>  - Jay
> 



More information about the M3devel mailing list