Skip to content
Permalink
Browse files

Revert using nqp::getattr instead of accessors

Makes operations on Rats a tiny bit slower, but makes operations on
RatStr's work again.
  • Loading branch information...
lizmat committed Jan 3, 2019
1 parent 5625ebc commit e29554f5c338cd3a53ac4f939f698087f99d71ff
Showing with 16 additions and 22 deletions.
  1. +16 −22 src/core/Rat.pm6
@@ -116,67 +116,61 @@ multi sub prefix:<->(Rat:D \a --> Rat:D) {
# Rat.new(-a.numerator, a.denominator);
nqp::p6bindattrinvres(
nqp::clone(nqp::decont(a)),
Rat,
'$!numerator',
nqp::neg_I(nqp::getattr(nqp::decont(a),Rat,'$!numerator'),Int)
Rat,'$!numerator',nqp::neg_I(a.numerator,Int)
)
}
multi sub prefix:<->(FatRat:D \a --> FatRat:D) {
# FatRat.new(-a.numerator, a.denominator);
nqp::p6bindattrinvres(
nqp::clone(nqp::decont(a)),
FatRat,
'$!numerator',
nqp::neg_I(nqp::getattr(nqp::decont(a),FatRat,'$!numerator'),Int)
FatRat,'$!numerator',nqp::neg_I(a.numerator,Int)
)
}

multi sub infix:<+>(Rational:D \a, Rational:D \b) {
my \adenom := nqp::getattr(nqp::decont(a),a.WHAT,'$!denominator');
my \bdenom := nqp::getattr(nqp::decont(b),b.WHAT,'$!denominator');
my \adenom := a.denominator;
my \bdenom := b.denominator;
DIVIDE_NUMBERS(
nqp::getattr(nqp::decont(a),a.WHAT,'$!numerator') * bdenom
+ nqp::getattr(nqp::decont(b),b.WHAT,'$!numerator') * adenom,
a.numerator * bdenom + b.numerator * adenom,
adenom * bdenom, a, b
)
}
multi sub infix:<+>(Rational:D \a, Int:D \b) {
my \adenom := nqp::getattr(nqp::decont(a),a.WHAT,'$!denominator');
my \adenom := a.denominator;
DIVIDE_NUMBERS(
nqp::getattr(nqp::decont(a),a.WHAT,'$!numerator') + b * adenom,
a.numerator + b * adenom,
adenom, a, b
)
}
multi sub infix:<+>(Int:D \a, Rational:D \b) {
my \bdenom := nqp::getattr(nqp::decont(b),b.WHAT,'$!denominator');
my \bdenom := b.denominator;
DIVIDE_NUMBERS(
a * bdenom + nqp::getattr(nqp::decont(b),b.WHAT,'$!numerator'),
a * bdenom + b.numerator,
bdenom, a, b
)
}

multi sub infix:<->(Rational:D \a, Rational:D \b) {
my \adenom := nqp::getattr(nqp::decont(a),a.WHAT,'$!denominator');
my \bdenom := nqp::getattr(nqp::decont(b),b.WHAT,'$!denominator');
my \adenom := a.denominator;
my \bdenom := b.denominator;
DIVIDE_NUMBERS(
nqp::getattr(nqp::decont(a),a.WHAT,'$!numerator') * bdenom
- nqp::getattr(nqp::decont(b),b.WHAT,'$!numerator') * adenom,
a.numerator * bdenom - b.numerator * adenom,
adenom * bdenom, a, b
)
}

multi sub infix:<->(Rational:D \a, Int:D \b) {
my \adenom := nqp::getattr(nqp::decont(a),a.WHAT,'$!denominator');
my \adenom := a.denominator;
DIVIDE_NUMBERS(
nqp::getattr(nqp::decont(a),a.WHAT,'$!numerator') - b * adenom,
a.numerator - b * adenom,
adenom, a, b
)
}

multi sub infix:<->(Int:D \a, Rational:D \b) {
my \bdenom := nqp::getattr(nqp::decont(b),b.WHAT,'$!denominator');
my \bdenom := b.denominator;
DIVIDE_NUMBERS(
a * bdenom - nqp::getattr(nqp::decont(b),b.WHAT,'$!numerator'),
a * bdenom - b.numerator,
bdenom, a, b
)
}

0 comments on commit e29554f

Please sign in to comment.
You can’t perform that action at this time.