Skip to content

Commit

Permalink
Several unival fixups
Browse files Browse the repository at this point in the history
- make sub version just pass on whatever it gets
- mark sub / method as "is pure" for better optimizability
- make method "unival" a multi
  • Loading branch information
lizmat committed Mar 30, 2021
1 parent 932685f commit f0a345d
Show file tree
Hide file tree
Showing 3 changed files with 19 additions and 25 deletions.
10 changes: 6 additions & 4 deletions src/core.c/Cool.pm6
Original file line number Diff line number Diff line change
Expand Up @@ -97,7 +97,10 @@ my class Cool { # declared in BOOTSTRAP

method uniname() { uniname(self) }
method uninames() { uninames(self) }
method unival(Cool:D:) { self.Int.unival }

proto method unival() is pure {*}
multi method unival(Cool:D:) { self.Int.unival }

method univals(Cool:D:) { self.Str.univals }
method uniprop(|c) { uniprop(self, |c) }
method uniprop-int(|c) { uniprop-int(self, |c) }
Expand Down Expand Up @@ -590,9 +593,8 @@ multi sub unimatch(|) { die 'unimatch NYI on js backend' }
#?endif

#?if !jvm
proto sub unival($, *%) {*}
multi sub unival(Str:D $str) { $str ?? $str.ord.unival !! Nil }
multi sub unival(Int:D $code) { $code.unival }
proto sub unival($, *%) is pure {*}
multi sub unival(\what) { what.unival }

proto sub univals($, *%) {*}
multi sub univals(Str:D $str) { $str.univals }
Expand Down
32 changes: 12 additions & 20 deletions src/core.c/Int.pm6
Original file line number Diff line number Diff line change
Expand Up @@ -249,26 +249,18 @@ my class Int does Real { # declared in BOOTSTRAP

my constant $nuprop = nqp::unipropcode("Numeric_Value_Numerator");
my constant $deprop = nqp::unipropcode("Numeric_Value_Denominator");
method unival(Int:D:) {
nqp::if( # valid?
nqp::isge_I(self,0)
&& nqp::chars(my str $de = nqp::getuniprop_str(self,$deprop)),
nqp::if( # some string to work with
nqp::iseq_s($de,"NaN"),
NaN, # no value found
nqp::if(
nqp::iseq_s($de,"1"),
nqp::coerce_si( # just the numerator
nqp::getuniprop_str(self,$nuprop)
),
Rat.new( # spotted a Rat
nqp::coerce_si(nqp::getuniprop_str(self,$nuprop)),
nqp::coerce_si($de)
)
)
),
Nil # no string, so no value
)
multi method unival(Int:D:) {
nqp::isge_I(self,0) # valid?
&& nqp::chars(my str $de = nqp::getuniprop_str(self,$deprop))
?? nqp::iseq_s($de,"NaN") # some string to work with
?? NaN # no value found
!! nqp::iseq_s($de,"1") # some value
?? nqp::coerce_si(nqp::getuniprop_str(self,$nuprop))
!! Rat.new(
nqp::coerce_si(nqp::getuniprop_str(self,$nuprop)),
nqp::coerce_si($de)
)
!! Nil # not valid, so no value
}
}

Expand Down
2 changes: 1 addition & 1 deletion src/core.c/Str.pm6
Original file line number Diff line number Diff line change
Expand Up @@ -2857,7 +2857,7 @@ my class Str does Stringy { # declared in BOOTSTRAP
method NFKD() { X::NYI.new(:feature<NFKD>).throw }
#?endif

method unival(Str:D:) { nqp::ord($!value).unival }
multi method unival(Str:D:) { nqp::ord($!value).unival }
method univals(Str:D:) { self.ords.map: *.unival }

my &SMART-WORDS = / [<:L> \w* ] +% <['\-]> /;
Expand Down

0 comments on commit f0a345d

Please sign in to comment.