Skip to content

Commit

Permalink
Browse files Browse the repository at this point in the history
Fix NQP analysis of when callstatic is valid.
Makes it match Rakudo's more closely. We can cheat in NQP, but not
/that/ hard.
  • Loading branch information
jnthn committed May 3, 2014
1 parent eafcab0 commit 43fbe2b
Showing 1 changed file with 17 additions and 5 deletions.
22 changes: 17 additions & 5 deletions src/NQP/Optimizer.nqp
Expand Up @@ -203,11 +203,11 @@ class NQP::Optimizer {

# Calls to fixed names that are compile-time known can be simplified.
elsif $opname eq 'call' && $op.name {
my %sym := self.find_lex($op.name);
if %sym {
if %sym<declared> {
# It's known at compile time, and so fixed, so we can do a more
# optimal call.
my @sym := self.find_lex_scope_level($op.name);
if @sym {
if @sym[0]<declared> && @sym[1] <= 1 {
# It's known at compile time and not closure-ish, so we can
# use a more optimal call op.
$op.op('callstatic');
}
}
Expand Down Expand Up @@ -340,6 +340,18 @@ class NQP::Optimizer {
NQPMu;
}

method find_lex_scope_level($name) {
my int $i := +@!block_stack;
while $i > 0 {
$i := $i - 1;
my %sym := @!block_stack[$i].symbol($name);
if +%sym {
return [%sym, $i];
}
}
NQPMu;
}

method find_sym($name) {
my %sym := self.find_lex($name);
if !(%sym =:= NQPMu) && nqp::existskey(%sym, 'value') {
Expand Down

0 comments on commit 43fbe2b

Please sign in to comment.