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).

.namespace
.sub "outer"
    new $P12, "Integer"
    assign $P12, 1
    .lex "x", $P12
    get_global $P18, "inner"
    newclosure $P18, $P18
    $P17 = $P18()
    print $P17
    print "\n"
.end

.sub "inner"  :outer("outer")
    find_lex $P14, "x"
    n_add $P15, $P14, 1
    .lex "x", $P15
    .return ($P15)
.end

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.

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 * change how PIR and LexInfos work to pay attention to the order in which lexical vars are declared and used in scopes

Any ideas?

Andrew Parker

Reply via email to