Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

turn Wval to Want after compile-time-evaluating pure ops #125

Merged
merged 5 commits into from
Apr 15, 2013
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
59 changes: 46 additions & 13 deletions src/Perl6/Optimizer.pm
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,7 @@ class Perl6::Optimizer {

# The Setting, which contains things like Signature and Parameter.
has $!SETTING;
has %!SETTING_CACHE;

has %!foldable_junction;
has %!foldable_outer;
Expand Down Expand Up @@ -174,21 +175,34 @@ class Perl6::Optimizer {
return 0;
}

method find_setting() {
if nqp::defined($!SETTING) {
return $!SETTING;
method find_in_setting($symbol) {
if !nqp::defined($!SETTING) {
my int $i := +@!block_stack;
while $i > 0 && !nqp::defined($!SETTING) {
$i := $i - 1;
my $block := @!block_stack[$i];
my %sym := $block.symbol("!CORE_MARKER");
if +%sym {
$!SETTING := $block;
}
}
if !nqp::defined($!SETTING) {
nqp::die("Optimizer couldn't find CORE while looking for $symbol.");
}
} else {
if nqp::existskey(%!SETTING_CACHE, $symbol) {
return %!SETTING_CACHE{$symbol};
}
}
my int $i := +@!block_stack;
while $i > 0 {
$i := $i - 1;
my $block := @!block_stack[$i];
my %sym := $block.symbol("!CORE_MARKER");
if +%sym {
$!SETTING := $block;
return $block;
my %sym := $!SETTING.symbol($symbol);
if +%sym {
if nqp::existskey(%sym, 'value') {
%!SETTING_CACHE{$symbol} := %sym<value>;
return %sym<value>;
} else {
nqp::die("Optimizer: cannot find $symbol in SETTING.");
}
}
nqp::die("Optimizer couldn't find CORE.");
}

method can_chain_junction_be_warped($node) {
Expand Down Expand Up @@ -254,7 +268,7 @@ class Perl6::Optimizer {
$found := 1;
}
if $found == 1 {
my $signature := self.find_setting().symbol("Signature")<value>;
my $signature := self.find_in_setting("Signature");
my $iter := nqp::iterator(nqp::getattr($obj.signature, $signature, '$!params'));
while $iter {
my $p := nqp::shift($iter);
Expand Down Expand Up @@ -396,6 +410,25 @@ class Perl6::Optimizer {
if $op.named {
$wval.named($op.named);
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Do I want to move this down to after return $want? Or is it okay to have the .named on the WVal as well as the Want that contains it?

}
# if it's an Int, Num or Str, we can create a Want
# from it witt 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,
"Ii", QAST::IVal.new(:value(nqp::unbox_i($ret_value))));
} elsif nqp::istype($ret_value, self.find_in_setting("Num")) {
$want := QAST::Want.new($wval,
"Nn", QAST::NVal.new(:value(nqp::unbox_n($ret_value))));
} elsif nqp::istype($ret_value, self.find_in_setting("Str")) {
$want := QAST::Want.new($wval,
"Ss", QAST::SVal.new(:value(nqp::unbox_s($ret_value))));
}
if nqp::defined($want) {
if $op.named {
$want.named($op.named);
}
return $want;
}
return $wval;
}
}
Expand Down