From: Andrew Parker <[EMAIL PROTECTED]> Date: Mon, 11 Feb 2008 22:27:27 +0100
Hi all, I was checking a couple of things in the compiler that I wrote and put together a simple program: let x = 1 in let x = x + 1 in x which ends up being pretty much equivalent to the perl5: my $x = 1; { my $x = $x + 1; print "$x\n"; } The generated code doesn't work however. The problem seems to come down to the problem that in PIR you cannot distinquish between lexical variables of an outer scope and an inner scope that have the same name (try running the following PIR) . . . One might think that because the .lex in "inner" comes after the find_lex it would find the outer "x" var, but it doesn't seem to. The only reason I can think of is that it is because the LexInfo is defined at compile time based on the .lexs in a scope. Yes; .lex is more of a declaration, and is scoped to the whole sub. I'm not sure what is wrong. The solutions that I can think of for this are: * mangle variable names in PAST so that we can distinquish the scopes from the var names This is what I do (for now anyway). * change how PIR and LexInfos work to pay attention to the order in which lexical vars are declared and used in scopes That would certainly require some work to implement in Parrot, but it would have the strong advantage of giving Parrot more detailed variable metadata, the sort that debuggers need to report variable values in HLL terms, and evaluate expressions in context. Any ideas? Andrew Parker A third solution, which is certainly more complicated for the compiler writer, is to split out each lexical scope into its own sub, though this may not be feasible for your language if it allows "goto" into scopes. This is the only solution for taking distinct closures within loops; see the "Lexical scopes are too coarse-grained for loops" discussion (RT#44395) of 3-Aug-07. HTH, -- Bob Rogers http://rgrjr.dyndns.org/