"Fossies" - the Fresh Open Source Software Archive  

Source code changes of the file "src/core.c/allomorphs.pm6" between
rakudo-2020.08.2.tar.gz and rakudo-2020.09.tar.gz

About: Rakudo is a compiler for the Perl 6 programming language.

allomorphs.pm6  (rakudo-2020.08.2):allomorphs.pm6  (rakudo-2020.09)
my class Allomorph is Str {
multi method Bool(::?CLASS:D:) { self.Numeric.Bool }
multi method ACCEPTS(Allomorph:D: Any:D \a) is default {
nqp::istype(a, Numeric)
?? self.Numeric.ACCEPTS(a)
!! nqp::istype(a, Str)
?? self.Str.ACCEPTS(a)
!! self.Str.ACCEPTS(a) && self.Numeric.ACCEPTS(a)
}
method succ(Allomorph:D:) { self.Numeric.succ }
method pred(Allomorph:D:) { self.Numeric.pred }
multi method Str(Allomorph:D:) {
nqp::getattr_s(self,Str,'$!value')
}
multi method WHICH(Allomorph:D:) {
nqp::box_s(
nqp::join('|',nqp::list_s(
self.^name,
self.Numeric.WHICH,
self.Str.WHICH
)),
ValueObjAt
)
}
multi method raku(Allomorph:D:) {
nqp::join("",nqp::list_s(
self.^name,'.new(',self.Numeric.raku,', ',self.Str.raku,')'
))
}
}
# the uses of add_I in this class are a trick to make bigints work right # the uses of add_I in this class are a trick to make bigints work right
my class IntStr is Int is Str { my class IntStr is Allomorph is Int {
method new(Int:D $i, Str:D $s) { method new(Int:D $i, Str:D $s) {
my \SELF = nqp::add_I($i, 0, self); my \SELF = nqp::add_I($i, 0, self);
nqp::bindattr_s(SELF, Str, '$!value', $s); nqp::bindattr_s(SELF, Str, '$!value', $s);
SELF; SELF
}
multi method ACCEPTS(IntStr:D: Any:D \a) {
nqp::if(
nqp::istype(a, Numeric),
self.Int.ACCEPTS(a),
nqp::if(
nqp::istype(a, Str),
self.Str.ACCEPTS(a),
self.Str.ACCEPTS(a) && self.Int.ACCEPTS(a)))
}
multi method Numeric(IntStr:D:) { self.Int }
multi method Numeric(IntStr:U:) {
self.Mu::Numeric; # issue warning;
0
}
multi method Real(IntStr:D:) { self.Int }
multi method Real(IntStr:U:) {
self.Mu::Real; # issue warning;
0
}
method Int(IntStr:D:) { nqp::add_I(self, 0, Int) }
multi method Str(IntStr:D:) { nqp::getattr_s(self, Str, '$!value') }
multi method raku(IntStr:D:) {
nqp::concat(self.^name,
nqp::concat('.new(',
nqp::concat(nqp::tostr_I(self),
nqp::concat(', ',
nqp::concat(nqp::getattr_s(self,Str,'$!value').raku,')'
)))))
} }
multi method Numeric(IntStr:U:) { self.Mu::Numeric }
multi method Numeric(IntStr:D:) { nqp::add_I(self,0,Int) }
multi method Real(IntStr:U:) { self.Mu::Real }
multi method Real(IntStr:D:) { nqp::add_I(self,0,Int) }
multi method Int(IntStr:D:) { nqp::add_I(self,0,Int) }
} }
my class NumStr is Num is Str { my class NumStr is Allomorph is Num {
method new(Num $n, Str $s) { method new(Num:D $n, Str:D $s) {
my \SELF = nqp::create(self); my \new = nqp::create(self);
nqp::bindattr_n(SELF, Num, '$!value', $n); nqp::bindattr_n(new,Num,'$!value',$n);
nqp::bindattr_s(SELF, Str, '$!value', $s); nqp::bindattr_s(new,Str,'$!value',$s);
SELF; new
}
multi method ACCEPTS(NumStr:D: Any:D \a) {
nqp::if(
nqp::istype(a, Numeric),
self.Num.ACCEPTS(a),
nqp::if(
nqp::istype(a, Str),
self.Str.ACCEPTS(a),
self.Str.ACCEPTS(a) && self.Num.ACCEPTS(a)))
}
multi method Numeric(NumStr:D:) { self.Num }
multi method Numeric(NumStr:U:) {
self.Mu::Numeric; # issue warning;
0e0
}
multi method Real(NumStr:D:) { self.Num }
multi method Real(NumStr:U:) {
self.Mu::Real; # issue warning;
0e0
}
method Num(NumStr:D:) { nqp::getattr_n(self, Num, '$!value') }
multi method Str(NumStr:D:) { nqp::getattr_s(self, Str, '$!value') }
multi method raku(NumStr:D:) {
nqp::concat(self.^name,
nqp::concat('.new(',
nqp::concat(nqp::getattr_n(self,Num,'$!value').raku,
nqp::concat(', ',
nqp::concat(nqp::getattr_s(self,Str,'$!value').raku,')'
)))))
} }
multi method Numeric(NumStr:U: --> 0e0) { self.Mu::Numeric }
multi method Numeric(NumStr:D:) { nqp::getattr_n(self,Num,'$!value') }
multi method Real(NumStr:U: --> 0e0) { self.Mu::Real }
multi method Real(NumStr:D:) { nqp::getattr_n(self,Num,'$!value') }
multi method Int(NumStr:D:) { nqp::getattr_n(self,Num,'$!value').Int }
} }
my class RatStr is Rat is Str { my class RatStr is Allomorph is Rat {
method new(Rat $r, Str $s) { method new(Rat:D $r, Str:D $s) {
my \SELF = nqp::create(self); my \new = nqp::create(self); # no need to normalize, so don't call .new
nqp::bindattr(SELF, Rat, '$!numerator', $r.numerator); nqp::bindattr(new,Rat,'$!numerator',
nqp::bindattr(SELF, Rat, '$!denominator', $r.denominator); nqp::getattr($r,Rat,'$!numerator'));
nqp::bindattr_s(SELF, Str, '$!value', $s); nqp::bindattr(new,Rat,'$!denominator',
SELF; nqp::getattr($r,Rat,'$!denominator'));
} nqp::bindattr_s(new,Str,'$!value',$s);
multi method ACCEPTS(RatStr:D: Any:D \a) { new
nqp::if(
nqp::istype(a, Numeric),
self.Rat.ACCEPTS(a),
nqp::if(
nqp::istype(a, Str),
self.Str.ACCEPTS(a),
self.Str.ACCEPTS(a) && self.Rat.ACCEPTS(a)))
}
method succ(RatStr:D: --> Rat:D) {
my \denominator := nqp::getattr(self,Rat,'$!denominator');
nqp::p6bindattrinvres(
nqp::p6bindattrinvres(nqp::create(Rat),Rat,'$!numerator',
nqp::add_I(nqp::getattr(self,Rat,'$!numerator'),denominator,Int)
),
Rat, '$!denominator', denominator
)
}
method pred(RatStr:D: --> Rat:D) {
my \denominator := nqp::getattr(self,Rat,'$!denominator');
nqp::p6bindattrinvres(
nqp::p6bindattrinvres(nqp::create(Rat), Rat, '$!numerator',
nqp::sub_I(nqp::getattr(self,Rat,'$!numerator'),denominator,Int)
),
Rat, '$!denominator', denominator
)
} }
method Capture(RatStr:D:) { self.Mu::Capture } method Capture(RatStr:D:) { self.Mu::Capture }
multi method Numeric(RatStr:U: --> 0.0) { self.Mu::Numeric }
multi method Numeric(RatStr:D:) { self.Rat } multi method Numeric(RatStr:D:) { self.Rat }
multi method Numeric(RatStr:U:) {
self.Mu::Numeric; # issue warning; multi method Real(RatStr:U: --> 0.0) { self.Mu::Real }
0.0
}
multi method Real(RatStr:D:) { self.Rat } multi method Real(RatStr:D:) { self.Rat }
multi method Real(RatStr:U:) {
self.Mu::Real; # issue warning; multi method Int(RatStr:D:) { self.Rat.Int }
0.0
}
method Rat(RatStr:D:) { method Rat(RatStr:D:) {
Rat.new( my \new := nqp::create(Rat); # no need to normalize, so don't call .new
nqp::getattr(self, Rat, '$!numerator'), nqp::bindattr(new,Rat,'$!numerator',
nqp::getattr(self, Rat, '$!denominator') nqp::getattr(self,Rat,'$!numerator'));
) nqp::bindattr(new,Rat,'$!denominator',
nqp::getattr(self,Rat,'$!denominator'));
new
} }
multi method Str(RatStr:D:) { nqp::getattr_s(self, Str, '$!value') }
multi method raku(RatStr:D:) { self.^name ~ '.new(' ~ self.Rat.raku ~ ', ' ~
self.Str.raku ~ ')' }
} }
my class ComplexStr is Complex is Str { my class ComplexStr is Allomorph is Complex {
method new(Complex $c, Str $s) { method new(Complex:D $c, Str $s) {
my \SELF = nqp::create(self); my \new = nqp::create(self);
nqp::bindattr_n(SELF, Complex, '$!re', $c.re); nqp::bindattr_n(new,Complex,'$!re',
nqp::bindattr_n(SELF, Complex, '$!im', $c.im); nqp::getattr_n($c,Complex,'$!re'));
nqp::bindattr_s(SELF, Str, '$!value', $s); nqp::bindattr_n(new,Complex,'$!im',
SELF; nqp::getattr_n($c,Complex,'$!im'));
} nqp::bindattr_s(new,Str,'$!value',$s);
multi method ACCEPTS(ComplexStr:D: Any:D \a) { new
nqp::if(
nqp::istype(a, Numeric),
self.Complex.ACCEPTS(a),
nqp::if(
nqp::istype(a, Str),
self.Str.ACCEPTS(a),
self.Str.ACCEPTS(a) && self.Complex.ACCEPTS(a)))
} }
method Capture(ComplexStr:D:) { self.Mu::Capture } method Capture(ComplexStr:D:) { self.Mu::Capture }
multi method Numeric(ComplexStr:U:) { self.Mu::Numeric; 0i }
multi method Numeric(ComplexStr:D:) { self.Complex } multi method Numeric(ComplexStr:D:) { self.Complex }
multi method Numeric(ComplexStr:U:) {
self.Mu::Numeric; # issue warning; method !has-imaginary($target) is hidden-from-backtrace {
<0+0i> X::Numeric::Real.new(
} target => $target,
multi method Real(ComplexStr:D:) { self.Complex.Real } source => self,
multi method Real(ComplexStr:U:) { reason => "imaginary part not zero"
self.Mu::Real; # issue warning; ).throw
<0+0i>.Real }
}
method Complex(ComplexStr:D:) { Complex.new(nqp::getattr_n(self, Complex, '$ multi method Real(ComplexStr:U: --> 0e0) { self.Mu::Real }
!re'), nqp::getattr_n(self, Complex, '$!im')) } multi method Real(ComplexStr:D:) {
multi method Str(ComplexStr:D:) { nqp::getattr_s(self, Str, '$!value') } nqp::getattr_n(self,Complex,'$!im')
?? self!has-imaginary(Real)
multi method raku(ComplexStr:D:) { self.^name ~ '.new(' ~ self.Complex.raku !! nqp::getattr_n(self,Complex,'$!re')
~ ', ' ~ self.Str.raku ~ ')' } }
}
multi method Int(ComplexStr:D:) {
# we define cmp ops for these allomorphic types as numeric first, then Str. If nqp::getattr_n(self,Complex,'$!im')
# you want just one half of the cmp, you'll need to coerce the args ?? self!has-imaginary(Int)
multi sub infix:<cmp>(IntStr:D $a, IntStr:D $b) { $a.Int cmp $b.Int !! nqp::getattr_n(self,Complex,'$!re')
|| $a.Str cmp $b.Str } }
multi sub infix:<cmp>(IntStr:D $a, RatStr:D $b) { $a.Int cmp $b.Rat
|| $a.Str cmp $b.Str } method Complex(ComplexStr:D:) {
multi sub infix:<cmp>(IntStr:D $a, NumStr:D $b) { $a.Int cmp $b.Num my \new = nqp::create(Complex);
|| $a.Str cmp $b.Str } nqp::bindattr_n(new,Complex,'$!re',
multi sub infix:<cmp>(IntStr:D $a, ComplexStr:D $b) { $a.Int cmp $b.Comp nqp::getattr_n(self,Complex,'$!re'));
lex || $a.Str cmp $b.Str } nqp::bindattr_n(new,Complex,'$!im',
nqp::getattr_n(self,Complex,'$!im'));
multi sub infix:<cmp>(RatStr:D $a, IntStr:D $b) { $a.Rat cmp $b.Int new
|| $a.Str cmp $b.Str } }
multi sub infix:<cmp>(RatStr:D $a, RatStr:D $b) { $a.Rat cmp $b.Rat }
|| $a.Str cmp $b.Str }
multi sub infix:<cmp>(RatStr:D $a, NumStr:D $b) { $a.Rat cmp $b.Num multi sub infix:<cmp>(Allomorph:D $a, Allomorph:D $b) is default {
|| $a.Str cmp $b.Str } $a.Numeric cmp $b.Numeric || $a.Str cmp $b.Str
multi sub infix:<cmp>(RatStr:D $a, ComplexStr:D $b) { $a.Rat cmp $b.Comp }
lex || $a.Str cmp $b.Str }
multi sub infix:<eqv>(Allomorph:D $a, Allomorph:D $b --> Bool:D) is default {
multi sub infix:<cmp>(NumStr:D $a, IntStr:D $b) { $a.Num cmp $b.Int nqp::eqaddr($a.WHAT,$b.WHAT)
|| $a.Str cmp $b.Str } ?? $a.Numeric eqv $b.Numeric && $a.Str eqv $b.Str
multi sub infix:<cmp>(NumStr:D $a, RatStr:D $b) { $a.Num cmp $b.Rat !! False
|| $a.Str cmp $b.Str } }
multi sub infix:<cmp>(NumStr:D $a, NumStr:D $b) { $a.Num cmp $b.Num
|| $a.Str cmp $b.Str }
multi sub infix:<cmp>(NumStr:D $a, ComplexStr:D $b) { $a.Num cmp $b.Comp
lex || $a.Str cmp $b.Str }
multi sub infix:<cmp>(ComplexStr:D $a, IntStr:D $b) { $a.Complex cmp $b.Int
|| $a.Str cmp $b.Str }
multi sub infix:<cmp>(ComplexStr:D $a, RatStr:D $b) { $a.Complex cmp $b.Rat
|| $a.Str cmp $b.Str }
multi sub infix:<cmp>(ComplexStr:D $a, NumStr:D $b) { $a.Complex cmp $b.Num
|| $a.Str cmp $b.Str }
multi sub infix:<cmp>(ComplexStr:D $a, ComplexStr:D $b) { $a.Complex cmp $b.Comp
lex || $a.Str cmp $b.Str }
multi sub infix:<eqv>(IntStr:D $a, IntStr:D $b) { $a.Int eqv $b.Int
&& $a.Str eqv $b.Str }
multi sub infix:<eqv>(IntStr:D $a, RatStr:D $b --> False) {}
multi sub infix:<eqv>(IntStr:D $a, NumStr:D $b --> False) {}
multi sub infix:<eqv>(IntStr:D $a, ComplexStr:D $b --> False) {}
multi sub infix:<eqv>(RatStr:D $a, IntStr:D $b --> False) {}
multi sub infix:<eqv>(RatStr:D $a, RatStr:D $b) { $a.Rat eqv $b.Rat
&& $a.Str eqv $b.Str }
multi sub infix:<eqv>(RatStr:D $a, NumStr:D $b --> False) {}
multi sub infix:<eqv>(RatStr:D $a, ComplexStr:D $b --> False) {}
multi sub infix:<eqv>(NumStr:D $a, IntStr:D $b --> False) {}
multi sub infix:<eqv>(NumStr:D $a, RatStr:D $b --> False) {}
multi sub infix:<eqv>(NumStr:D $a, NumStr:D $b) { $a.Num eqv $b.Num
&& $a.Str eqv $b.Str }
multi sub infix:<eqv>(NumStr:D $a, ComplexStr:D $b --> False) {}
multi sub infix:<eqv>(ComplexStr:D $a, IntStr:D $b --> False) {}
multi sub infix:<eqv>(ComplexStr:D $a, RatStr:D $b --> False) {}
multi sub infix:<eqv>(ComplexStr:D $a, NumStr:D $b --> False) {}
multi sub infix:<eqv>(ComplexStr:D $a, ComplexStr:D $b) { $a.Complex eqv $b.Comp
lex && $a.Str eqv $b.Str }
multi sub infix:<===>(IntStr:D $a, IntStr:D $b) { multi sub infix:<===>(IntStr:D $a, IntStr:D $b) {
$a.Int === $b.Int && $a.Str === $b.Str $a.Int === $b.Int && $a.Str === $b.Str
} }
multi sub infix:<===>(RatStr:D $a, RatStr:D $b) { multi sub infix:<===>(RatStr:D $a, RatStr:D $b) {
$a.Rat === $b.Rat && $a.Str === $b.Str $a.Rat === $b.Rat && $a.Str === $b.Str
} }
multi sub infix:<===>(NumStr:D $a, NumStr:D $b) { multi sub infix:<===>(NumStr:D $a, NumStr:D $b) {
$a.Num === $b.Num && $a.Str === $b.Str $a.Num === $b.Num && $a.Str === $b.Str
} }
 End of changes. 17 change blocks. 
212 lines changed or deleted 136 lines changed or added

Home  |  About  |  Features  |  All  |  Newest  |  Dox  |  Diffs  |  RSS Feeds  |  Screenshots  |  Comments  |  Imprint  |  Privacy  |  HTTP(S)