Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Implement inline PIR versions of lc, ceiling, floor and round #808

Closed
p6rt opened this issue Mar 20, 2009 · 5 comments
Closed

Implement inline PIR versions of lc, ceiling, floor and round #808

p6rt opened this issue Mar 20, 2009 · 5 comments
Labels

Comments

@p6rt
Copy link

p6rt commented Mar 20, 2009

Migrated from rt.perl.org#64020 (status was 'resolved')

Searchable as RT64020$

@p6rt
Copy link
Author

p6rt commented Mar 20, 2009

From @cspencer

The following patch implements the P6 versions of Any.pm's lc,
ceiling, floor and round (implemented as inline PIR methods)

@p6rt
Copy link
Author

p6rt commented Mar 20, 2009

From @cspencer

0001-Added-inline-PIR-versions-of-Any.pm-s-lc-ceiling-f.patch
From 584bd462681e1dc54188b3c71d27ddb48237fa0f Mon Sep 17 00:00:00 2001
From: Cory Spencer <cspencer@sprocket.org>
Date: Thu, 19 Mar 2009 18:30:06 -0700
Subject: [PATCH] Added inline PIR versions of Any.pm's lc, ceiling, floor and round to 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
---
 build/Makefile.in        |    1 +
 src/builtins/any-str.pir |   26 +---------------------
 src/builtins/math.pir    |   53 ----------------------------------------------
 src/setting/Any-num.pm   |   29 +++++++++++++++++++++++++
 src/setting/Any-str.pm   |   15 +++++++++---
 5 files changed, 42 insertions(+), 82 deletions(-)
 create mode 100644 src/setting/Any-num.pm

diff --git a/build/Makefile.in b/build/Makefile.in
index b9e790b..5dc6024 100644
--- a/build/Makefile.in
+++ b/build/Makefile.in
@@ -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 \
diff --git a/src/builtins/any-str.pir b/src/builtins/any-str.pir
index cac5c17..0369a40 100644
--- a/src/builtins/any-str.pir
+++ b/src/builtins/any-str.pir
@@ -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
 
 
@@ -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
diff --git a/src/builtins/math.pir b/src/builtins/math.pir
index 1b5a31e..b148955 100644
--- a/src/builtins/math.pir
+++ b/src/builtins/math.pir
@@ -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 )
diff --git a/src/setting/Any-num.pm b/src/setting/Any-num.pm
new file mode 100644
index 0000000..f84a18c
--- /dev/null
+++ b/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
+        }
+    }
+}
diff --git a/src/setting/Any-str.pm b/src/setting/Any-str.pm
index 9c24198..be0082b 100644
--- a/src/setting/Any-str.pm
+++ b/src/setting/Any-str.pm
@@ -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) !! ""
     }
@@ -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
         }
     }
 
-- 
1.6.1.3

@p6rt
Copy link
Author

p6rt commented Mar 20, 2009

From @moritz

Applied as 9a08c4f5f0d72cd8dd0b309854f36a8dcfb3d4fa, thank you very much.

Moritz

@p6rt
Copy link
Author

p6rt commented Mar 20, 2009

The RT System itself - Status changed from 'new' to 'open'

@p6rt
Copy link
Author

p6rt commented Mar 20, 2009

@moritz - Status changed from 'open' to 'resolved'

@p6rt p6rt closed this as completed Mar 20, 2009
@p6rt p6rt added the patch label Jan 5, 2020
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests

1 participant