On Fri, Aug 02, 2002 at 05:20:45PM +0200, Jerome Vouillon wrote: > On Thu, Aug 01, 2002 at 10:57:34AM -0700, Sean O'Rourke wrote: > > My naive implementation would have an array of hashes for each sub, with > > one entry for each level of scope within. > > I would use an array of arrays or a linked-list of arrays. This is > hardly more difficult to implement (you just need to keep track of the > variable indices during compilation) and the generated code will be a > lot more efficient.
Sorry if I've got confused and missed a bit, but if anyone is able to eval new code in your scope, then you'll also have to keep the mapping of variable names to array indexes somewhere. Although I agree that numeric lookup in the generated code ought to be much much faster. > > Waving my hands somewhat more quickly, as an optimization, lexicals can > > just live in registers when the compiler sees no references to %MY or > > closures. Nastiness like eval and caller.MY can be handled by inserting > > fixup code to reconstruct the lexical array on demand. > > caller.MY is especially nasty because you have to pay for it even when > you don't use it: you can't know whether a function has to support it > just by looking at the function code. It will be really tricky to > implement any optimization if one can write things like: > caller(1).MY{'$y'} := $x You can't know whether a function has to support it by looking at all the bytecode in the interpreter at any given time. Some "nasty" programmer only needs to dynamicly load a library that goes up from its scope into yours and your careful check is worthless. Nicholas Clark