Skip to content

Commit

Permalink
Added inline PIR versions of Any.pm's lc, ceiling, floor and round to…
Browse files Browse the repository at this point in the history
… the P6 Any.pm class.

Squashed commit of the following:

commit 59873f07aa08081cc2d5e915ce309d733935cb54
Author: Cory Spencer <cspencer@sprocket.org>
Date:   Thu Mar 19 18:19:21 2009 -0700

    Added an inline PIR P6 version of lc

commit 65b75d2b6266adaae8caac230cc55462467c8c0c
Author: Cory Spencer <cspencer@sprocket.org>
Date:   Thu Mar 19 16:06:26 2009 -0700

    Add inline PIR versions of round, ceiling and floor

commit 9a873239e9a0fb86d4d11dc2f141d6081d2e1a23
Merge: 8592d17... f8b6aee...
Author: Cory Spencer <cspencer@sprocket.org>
Date:   Thu Mar 19 14:28:57 2009 -0700

    Merge branch 'master' of git://github.com/rakudo/rakudo

Signed-off-by: Moritz Lenz <moritz@faui2k3.org>
  • Loading branch information
cspencer authored and moritz committed Mar 20, 2009
1 parent cba1557 commit 9a08c4f
Show file tree
Hide file tree
Showing 5 changed files with 42 additions and 82 deletions.
1 change: 1 addition & 0 deletions build/Makefile.in
Expand Up @@ -109,6 +109,7 @@ BUILTINS_PIR = \

SETTING = \
src/setting/Any-list.pm \
src/setting/Any-num.pm \
src/setting/Any-str.pm \
src/setting/Array.pm \
src/setting/Bool.pm \
Expand Down
26 changes: 1 addition & 25 deletions src/builtins/any-str.pir
Expand Up @@ -23,7 +23,7 @@ the size of that file down and to emphasize their generic,
.namespace []
.sub 'onload' :anon :init :load
$P0 = get_hll_namespace ['Any']
'!EXPORT'('capitalize,chomp,chars,:d,:e,:f,index,lc,rindex,ord,substr,trim', 'from'=>$P0)
'!EXPORT'('capitalize,chomp,chars,:d,:e,:f,index,rindex,ord,substr,trim', 'from'=>$P0)
.end
Expand Down Expand Up @@ -260,30 +260,6 @@ file.
.return ($P0)
.end
=item lc
our Str multi Str::lc ( Str $string )
Returns the input string after converting each character to its lowercase
form, if uppercase.
=cut
.sub 'lc' :method :multi(_)
.local string tmps
.local pmc retv
tmps = self
downcase tmps
retv = new 'Str'
retv = tmps
.return(retv)
.end
=item match()
=cut
Expand Down
53 changes: 0 additions & 53 deletions src/builtins/math.pir
Expand Up @@ -15,59 +15,6 @@ src/builtins/math.pir - Perl6 math functions
## TODO: figure out what to get working, in order to uncomment the following
## .namespace [ 'Math::Basic' ]


=item floor

our Int multi Num::floor ( Num $x )

Returns the highest integer not greater than $x.

=cut

.sub 'floor'
.param num n
.local int i
floor i, n
.return (i)
.end


=item ceiling

our Int multi Num::ceiling ( Num $x )
&Num::ceil ::= &Num::ceiling;

Returns the lowest integer not less than $x.

=cut

.sub 'ceiling'
.param num n
.local int i
ceil i, n
.return (i)
.end


=item round

our Int multi Num::round ( Num $x )
our Int multi Int ( Num $x )

Returns the nearest integer to $x. The algorithm is floor($x + 0.5).
(Other rounding algorithms will be given extended names beginning with "round".)

=cut

.sub 'round'
.param num n
.local int i
n += 0.5
floor i, n
.return (i)
.end


=item sign

our Int multi Num::sign ( Num $x )
Expand Down
29 changes: 29 additions & 0 deletions src/setting/Any-num.pm
@@ -0,0 +1,29 @@
class Any is also {
our Int multi method ceiling (Num $x:) is export {
return Q:PIR {
$P0 = find_lex "$x"
$N0 = $P0
$I0 = ceil $N0
%r = box $I0
}
}
our Int multi method floor (Num $x:) is export {
return Q:PIR {
$P0 = find_lex "$x"
$N0 = $P0
$I0 = floor $N0
%r = box $I0
}
}
our Int multi method round (Num $x:) is export {
return Q:PIR {
$P0 = find_lex "$x"
$N0 = $P0
$N0 = $N0 + 0.5
$I0 = floor $N0
%r = box $I0
}
}
}
15 changes: 11 additions & 4 deletions src/setting/Any-str.pm
Expand Up @@ -7,6 +7,14 @@ class Any is also {
sprintf($format, self)
}

our Str multi method lc is export {
return Q:PIR {
$S0 = self
downcase $S0
%r = box $S0
}
}
our Str multi method lcfirst is export {
self gt '' ?? self.substr(0,1).lc ~ self.substr(1) !! ""
}
Expand Down Expand Up @@ -70,13 +78,12 @@ class Any is also {
}
}
}
multi method uc() is export {

our Str multi method uc is export {
return Q:PIR {
$S0 = self
upcase $S0
%r = new 'Str'
%r = $S0
%r = box $S0
}
}
Expand Down

0 comments on commit 9a08c4f

Please sign in to comment.