Skip to content

Commit

Permalink
Implement prefix/postfix ++/-- on native num.
Browse files Browse the repository at this point in the history
Also improve the non-native versions (for Num). Things with a $
sigil compile into better assignments than unsigil'd things, and
for rw args there's no benefit with \ over $.
  • Loading branch information
jnthn committed Feb 11, 2015
1 parent 765de1d commit af05fab
Showing 1 changed file with 34 additions and 18 deletions.
52 changes: 34 additions & 18 deletions src/core/Num.pm
Expand Up @@ -233,36 +233,52 @@ my constant e = 2.71828_18284_59045_235e0;
my constant π := pi;
#?endif

multi sub prefix:<++>(Num:D \a is rw) { # XXX
a = nqp::p6box_n(nqp::add_n(nqp::unbox_n(a), 1e0))
multi sub prefix:<++>(Num:D $a is rw) {
$a = nqp::p6box_n(nqp::add_n(nqp::unbox_n($a), 1e0))
}
multi sub prefix:<++>(Num:U \a is rw) { # XXX
a = 1e0;
multi sub prefix:<++>(Num:U $a is rw) {
$a = 1e0;
}
multi sub prefix:<-->(Num:D \a is rw) { # XXX
a = nqp::p6box_n(nqp::sub_n(nqp::unbox_n(a), 1e0))
multi sub prefix:<++>(num $a is rw) {
$a = nqp::add_n($a, 1e0)
}
multi sub prefix:<-->(Num:U \a is rw) { # XXX
a = -1e0;
multi sub prefix:<-->(Num:D $a is rw) {
$a = nqp::p6box_n(nqp::sub_n(nqp::unbox_n($a), 1e0))
}
multi sub postfix:<++>(Num:D \a is rw) { # XXX
my $b = a;
a = nqp::p6box_n(nqp::add_n(nqp::unbox_n(a), 1e0));
multi sub prefix:<-->(Num:U $a is rw) {
$a = -1e0;
}
multi sub prefix:<-->(num $a is rw) {
$a = nqp::sub_n($a, 1e0)
}
multi sub postfix:<++>(Num:D $a is rw) {
my $b = $a;
$a = nqp::p6box_n(nqp::add_n(nqp::unbox_n($a), 1e0));
$b
}
multi sub postfix:<++>(Num:U \a is rw) { # XXX
a = 1e0;
multi sub postfix:<++>(Num:U $a is rw) {
$a = 1e0;
0
}
multi sub postfix:<-->(Num:D \a is rw) { # XXX
my $b = a;
a = nqp::p6box_n(nqp::sub_n(nqp::unbox_n(a), 1e0));
multi sub postfix:<++>(num $a is rw) {
my num $b = $a;
$a = nqp::add_n($a, 1e0);
$b
}
multi sub postfix:<-->(Num:D $a is rw) {
my $b = $a;
$a = nqp::p6box_n(nqp::sub_n(nqp::unbox_n($a), 1e0));
$b
}
multi sub postfix:<-->(Num:U \a is rw) { # XXX
a = -1e0;
multi sub postfix:<-->(Num:U $a is rw) {
$a = -1e0;
0e0
}
multi sub postfix:<-->(num $a is rw) {
my num $b = $a;
$a = nqp::sub_n($a, 1e0);
$b
}

multi sub prefix:<->(Num:D \a) {
nqp::p6box_n(nqp::neg_n(nqp::unbox_n(a)))
Expand Down

0 comments on commit af05fab

Please sign in to comment.