Skip to content

Commit

Permalink
Browse files Browse the repository at this point in the history
Some optimizer code cleanups, commenting.
  • Loading branch information
jnthn committed Aug 4, 2013
1 parent 5d9f71d commit a04ebf2
Showing 1 changed file with 10 additions and 7 deletions.
17 changes: 10 additions & 7 deletions src/Perl6/Optimizer.nqp
Expand Up @@ -29,9 +29,8 @@ class Perl6::Optimizer {
# of line numbers.
has %!worrying;

# The type type, Mu.
# Top type, Mu, and Any (the top non-junction type).
has $!Mu;
# And the Any type, important for being the "not junction" type.
has $!Any;

# The Setting, which contains things like Signature and Parameter.
Expand Down Expand Up @@ -76,14 +75,14 @@ class Perl6::Optimizer {
+%adverbs<optimize> !! 2;

# Locate UNIT and some other useful symbols.
my $unit := $past<UNIT>;
my $*GLOBALish := $past<GLOBALish>;
my $*W := $past<W>;
my $*W := $past<W>;
my $unit := $past<UNIT>;
unless nqp::istype($unit, QAST::Block) {
nqp::die("Optimizer could not find UNIT");
}
nqp::push(@!block_stack, $unit);
$!Mu := self.find_lexical('Mu');
$!Mu := self.find_lexical('Mu');
$!Any := self.find_lexical('Any');
nqp::pop(@!block_stack);

Expand Down Expand Up @@ -139,7 +138,7 @@ class Perl6::Optimizer {
my @sigsyms;
for $block.symtable() {
my $name := $_.key;
if $name ne '$_' && $name ne 'call_sig' && $name ne '$*DISPATCHER' {
if $name ne '$_' && $name ne '$*DISPATCHER' {
@sigsyms.push($name);
}
}
Expand Down Expand Up @@ -365,7 +364,9 @@ class Perl6::Optimizer {
$found := 1;
}
if $found {
# Pure operators can be constant folded.
if nqp::can($obj, 'IS_PURE') && $obj.IS_PURE {
# First ensure we're not in void context; warn if so.
sub widen($m) {
my int $from := $m.from;
my int $to := $m.to;
Expand Down Expand Up @@ -394,6 +395,8 @@ class Perl6::Optimizer {
last;
}
}

# If so, attempt to constant fold.
if $all_args_known {
my int $survived := 0;
my $ret_value;
Expand All @@ -412,7 +415,7 @@ class Perl6::Optimizer {
$wval.named($op.named);
}
# if it's an Int, Num or Str, we can create a Want
# from it witt an int, num or str value.
# from it with an int, num or str value.
my $want;
if nqp::istype($ret_value, self.find_in_setting("Int")) && !nqp::isbig_I(nqp::decont($ret_value)) {
$want := QAST::Want.new($wval,
Expand Down

0 comments on commit a04ebf2

Please sign in to comment.