Re: Lexical variables, scratchpads, closures, ...
by Nicholas Clark other posts by this author
Aug 2 2002 8:06PM messages near this date
Re: Lexical variables, scratchpads, closures, ...
|
Re: Lexical variables, scratchpads, closures, ...
On Fri, Aug 02, 2002 at 06:43:49PM +0200, Jerome Vouillon wrote:
> On Fri, Aug 02, 2002 at 08:50:27AM -0700, Sean O'Rourke wrote:
> > I don't see how you can cope with '%MY' unless you have a hash. You could
> > have a hash in addition to the array, I suppose.
>
> Sure, you need a hash. But this can be a statically allocated hash,
> mapping variable names to indices.
Which probably still works even with %MY - providing we have some way that the
pad is pointing to the static version, until something run time fiddles with
our scope, at which point we copy it to a dynamic version, and from then on
that lexical scope is dynamic.
(and only then is it slower)
We don't have to even have much of a hit of following the pointer if a
static structure looks like this
struct pad {
struct runtime_pad *in_use_pad;
struct runtime pad {
...
} default_static_pad;
};
where default_static_pad is the compile-time job, and in_use_pad points to it
until %MY is written to.
> > In any case, Dan has
> > promised us some sort of indexed "back-door" access to our hashes, so I
> > get the feeling the point is moot -- hashes will be arrays in some sense.
>
> Allocating a hash will certainly remain a lot more expensive than
> allocating an array. And we are going to allocate pads pretty
> often...
Are we? Or are we just going to copy them a lot at runtime?
[but actually allocate the beasts only at compile time, or when someone
mucks around with them using string eval or %MY]
> > And actually, thanks to %MY and caller.MY, we need a new pad even
> > for scopes without lexicals, since they can be inserted later.
>
> I really hope %MY and caller.MY will not be able to extend the lexical
> scope: we would get a really huge speed penalty for a feature which
> would hardly ever be used.
I think we need to be aware of this, but I don't think it has to be that
painful. If all scopes have a pad pointer, but lexical-free scopes start
with it null, then there won't be a really huge speed penalty.
[it might actually be faster, as this way all pads *are* equal, so there
doesn't need to be special case code distinguishing between scopes with
lexicals and scopes without.]
Nicholas Clark
--
Even better than the real thing: http://nms-cgi.sourceforge.net/
Thread:
Jerome Vouillon
Melvin Smith
Jerome Vouillon
Sean O'Rourke
Jerome Vouillon
Dan Sugalski
Dan Sugalski
Simon Cozens
Nicholas Clark
Sean O'Rourke
Jerome Vouillon
Nicholas Clark
Jerome Vouillon
Jonathan Sillito
Dave Mitchell
Melvin Smith
Sean O'Rourke
Dan Sugalski
Dan Sugalski
Jonathan Sillito
Jerome Vouillon
Melvin Smith
Jerome Vouillon
Melvin Smith
Jerome Vouillon
Jonathan Sillito
Sean O'Rourke
|