Skip to content

Commit

Permalink
Fix up native type post-dec to pre- optimization
Browse files Browse the repository at this point in the history
  • Loading branch information
zoffixznet committed Feb 7, 2018
1 parent a4f1f24 commit 13e6ed8
Showing 1 changed file with 17 additions and 9 deletions.
26 changes: 17 additions & 9 deletions src/Perl6/Optimizer.nqp
Expand Up @@ -1623,40 +1623,48 @@ class Perl6::Optimizer {
|| $primspec == 2) # native num
{
my $returns := $var.returns;
my $is-dec := nqp::eqat($op.name, '--', -3);

if $primspec == 1 { # native int
my $one := QAST::Want.new: :$node,
QAST::WVal.new(:value($!symbols.find_lexical: 'Int')),
'Ii', QAST::IVal.new: :value(1);
if $!void_context || nqp::eqat($op.name, '&pre', 0) {
# we can just use (or ignore) the result
return QAST::Op.new: :op<assign_i>, :$node, :$returns, $var,
QAST::Op.new: :op<add_i>, :$returns, $var, $one
QAST::Op.new: :op($is-dec ?? 'sub_i' !! 'add_i'),
:$returns, $var, $one
}
else {
# need to assign original value; it's cheaper to just
# do the reverse operation than to use a temp var
return QAST::Op.new: :op<sub_i>, :$node, :$returns,
return QAST::Op.new: :op($is-dec ?? 'add_i' !! 'sub_i'),
:$node, :$returns,
QAST::Op.new(:op<assign_i>, :$returns, $var,
QAST::Op.new: :op<add_i>, :$returns, $var, $one),
QAST::Op.new: :op($is-dec ?? 'sub_i' !! 'add_i'),
:$returns, $var, $one),
$one
}
}
elsif $primspec == 2 { # native num
my $one := QAST::Want.new: :$node,
QAST::WVal.new: :value($!symbols.find_lexical: 'Num'),
QAST::WVal.new(:value($!symbols.find_lexical: 'Num')),
'Nn', QAST::NVal.new: :value(1);
if $!void_context || nqp::eqat($op.name, '&pre', 0) {
# we can just use (or ignore) the result
return QAST::Op.new: :op<assign_n>, :$node, :$returns, $var,
QAST::Op.new: :op<add_n>, :$returns, $var, $one
QAST::Op.new: :op($is-dec ?? 'sub_n' !! 'add_n'),
:$returns, $var, $one
}
else {
# need to assign original value; it's cheaper to just
# do the reverse operation than to use a temp var
return QAST::Op.new: :op<sub_n>, :$node, :$returns,
QAST::Op.new(:op<assign_n>, :$returns, $var,
QAST::Op.new: :op<add_n>, :$returns, $var, $one),
$one
return QAST::Op.new: :op($is-dec ?? 'add_n' !! 'sub_n'),
:$node, :$returns,
QAST::Op.new(:op<assign_n>, :$returns, $var,
QAST::Op.new: :op($is-dec ?? 'sub_n' !! 'add_n'),
:$returns, $var, $one),
$one
}
}
}
Expand Down

0 comments on commit 13e6ed8

Please sign in to comment.