Skip to content

Commit

Permalink
Browse files Browse the repository at this point in the history
first shot at constant folding
so far it does nothing, but also breaks nothing. It seems that the multi dispatch call optimization comes first, and interferes with this one
  • Loading branch information
moritz committed Jan 31, 2013
1 parent a1bcaa6 commit 622595b
Showing 1 changed file with 20 additions and 0 deletions.
20 changes: 20 additions & 0 deletions src/Perl6/Optimizer.pm
Expand Up @@ -383,6 +383,26 @@ class Perl6::Optimizer {
}
}
}

elsif $*LEVEL >= 2 && $optype eq 'call' && $op.name && !$op<has_compile_time_value> {
my $code := try { $*W.find_symbol([$op.name]) };
if nqp::defined($code) && nqp::can($code, 'IS_PURE') && $code.IS_PURE {
# check if all arguments are known at compile time
my $all_args_known := 1;
for @($op) {
unless nqp::istype($op, QAST::Node) && $op<has_compile_time_value> && !$_.named {
$all_args_known := 0;
last;
}
}
if $all_args_known {
my $ret_value := $*W.compile_time_evalute($op.node, $op);
$*W.add_object($ret_value);
return QAST::WVal.new(:value($ret_value));

}
}
}

# If we end up here, just leave op as is.
if $op.op eq 'chain' {
Expand Down

0 comments on commit 622595b

Please sign in to comment.