Permalink
Browse files

PAST::Compiler - fix tempregs

1) I stored the "constant" TEMPREG_BASE in the tempreg frames.  This
meant that there was only one tempreg counter for all types that never
decremented.  Fix by cloning the Integer PMC.

2) The PIR code for tempreg() used the value before incrementing to
generate the register value.  Do this in NQP too, so that the
generated PIR is identical.
  • Loading branch information...
1 parent 9da949d commit a613ae8c99f3c56bcd794b2dd5e6bac7b0003bea @Benabik Benabik committed Aug 20, 2011
Showing with 7,461 additions and 7,432 deletions.
  1. +7,452 −7,425 compilers/pct/src/PAST/Compiler.pir
  2. +9 −7 compilers/pct/src/PAST/Compiler.pm
View
14,877 compilers/pct/src/PAST/Compiler.pir
7,452 additions, 7,425 deletions not shown because the diff is too large. Please use a local Git client to view these changes.
View
16 compilers/pct/src/PAST/Compiler.pm
@@ -160,7 +160,7 @@ INIT {
$TEMPREG_BASE := 100;
$UNIQUE_BASE := 1000;
- # XXX: clone protects the "constant" from the var incrementing
+ # XXX: clone protects the "constant" from the var incrementing
$serno := pir::clone($UNIQUE_BASE);
}
@@ -242,10 +242,11 @@ identifiers TEMPREG_BASE up to UNIQUE_BASE.
method tempreg_frame() {
my %tempregs;
- %tempregs<I> := $TEMPREG_BASE;
- %tempregs<N> := $TEMPREG_BASE;
- %tempregs<S> := $TEMPREG_BASE;
- %tempregs<P> := $TEMPREG_BASE;
+ # pir::clone protects the "constant" from getting incremented
+ %tempregs<I> := pir::clone($TEMPREG_BASE);
+ %tempregs<N> := pir::clone($TEMPREG_BASE);
+ %tempregs<S> := pir::clone($TEMPREG_BASE);
+ %tempregs<P> := pir::clone($TEMPREG_BASE);
%tempregs;
}
@@ -282,9 +283,10 @@ method tempreg($rtype) {
# if we've run out of temporary registers, just make a unique one
return self.unique('$' ~ $rtype) if $rnum >= $UNIQUE_BASE;
+ my $S0 := ~$rnum;
$rnum++;
%*TEMPREGS{$rtype} := $rnum;
- $reg := '$' ~ $rtype ~ $rnum;
+ $reg := '$' ~ $rtype ~ $S0;
}
$reg;
@@ -658,7 +660,7 @@ multi method as_post(PAST::Stmt $node, *%options) {
if %outerregs
&& %options<rtype> ne 'v'
&& pir::substr($result, 0, 1) eq '$'
- {
+ {
%outerregs{$result} := 1
}

0 comments on commit a613ae8

Please sign in to comment.