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

Moving methods from Str.pir to any-str.pir #345

Closed
p6rt opened this issue Sep 27, 2008 · 12 comments
Closed

Moving methods from Str.pir to any-str.pir #345

p6rt opened this issue Sep 27, 2008 · 12 comments
Labels

Comments

@p6rt
Copy link

p6rt commented Sep 27, 2008

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

Searchable as RT59398$

@p6rt
Copy link
Author

p6rt commented Sep 27, 2008

From @bacek

Hello.

For consistency sake (and removing many dummy proxy methods)

--
Bacek.

@p6rt
Copy link
Author

p6rt commented Sep 27, 2008

From @bacek

str_moving_methods.patch
commit be069166b765ed48e5e21df11498d32ece41b13d
Author: Vasily Chekalkin <bacek@bacek.com>
Date:   Sat Sep 27 22:37:34 2008 +1000

    Move many methods from Str.pir to any-str.pir

diff --git a/languages/perl6/src/builtins/any-str.pir b/languages/perl6/src/builtins/any-str.pir
index 5e20b48..2772cc4 100644
--- a/languages/perl6/src/builtins/any-str.pir
+++ b/languages/perl6/src/builtins/any-str.pir
@@ -21,7 +21,7 @@ the size of that file down and to emphasize their generic,
 .namespace []
 .sub 'onload' :anon :init :load
     $P0 = get_hll_namespace ['Any']
-    '!EXPORT'('chars ord index rindex substr', 'from'=>$P0)
+    '!EXPORT'('capitalize chop chars index lc lcfirst rindex ord substr uc ucfirst', 'from'=>$P0)
 .end
 
 
@@ -30,12 +30,89 @@ the size of that file down and to emphasize their generic,
 =cut
 
 .namespace ['Any']
+
+=item capitalize
+
+ our Str multi Str::capitalize ( Str $string )
+
+Has the effect of first doing an C<lc> on the entire string, then performing a
+C<s:g/(\w+)/{ucfirst $1}/> on it.
+
+=cut
+
+.sub 'capitalize' :method
+    .local string tmps
+    .local string fchr
+    .local pmc retv
+    .local int len
+
+    retv = new 'Perl6Str'
+    tmps = self
+
+    len = length tmps
+    if len == 0 goto done
+
+    downcase tmps
+
+    .local int pos, is_ws, is_lc
+    pos = 0
+    goto first_char
+  next_grapheme:
+    if pos == len goto done
+    is_ws = is_cclass .CCLASS_WHITESPACE, tmps, pos
+    if is_ws goto ws
+  advance:
+    pos += 1
+    goto next_grapheme
+  ws:
+    pos += 1
+  first_char:
+    is_lc = is_cclass .CCLASS_LOWERCASE, tmps, pos
+    unless is_lc goto advance
+    $S1 = substr tmps, pos, 1
+    upcase $S1
+    substr tmps, pos, 1, $S1
+    ## the length may have changed after replacement, so measure it again
+    len = length tmps
+    goto advance
+  done:
+    retv = tmps
+    .return (retv)
+.end
+
 .sub 'chars' :method :multi(_)
     $S0 = self
     $I0 = length $S0
     .return ($I0)
 .end
 
+
+=item chop
+
+ our Str method Str::chop ( Str  $string: )
+
+Returns string with one Char removed from the end.
+
+=cut
+
+.sub 'chop' :method
+    .local string tmps
+    .local pmc retv
+    .local int len
+
+    retv = new 'Perl6Str'
+    tmps = self
+
+    len = length tmps
+    if len == 0 goto done
+    dec len
+    substr tmps,tmps, 0, len
+  done:
+    retv = tmps
+    .return(retv)
+.end
+
+
 =item comb()
 
 Partial implementation for now, returns a list of strings
@@ -110,6 +187,62 @@ Partial implementation for now, returns a list of strings
     .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 
+    .local string tmps
+    .local pmc retv
+
+    tmps = self
+    downcase tmps
+
+    retv = new 'Perl6Str'
+    retv = tmps
+
+    .return(retv)
+.end
+
+=item lcfirst
+
+ our Str multi Str::lcfirst ( Str $string )
+
+Like C<lc>, but only affects the first character.
+
+=cut
+
+.sub 'lcfirst' :method
+    .local string tmps
+    .local string fchr
+    .local pmc retv
+    .local int len
+
+    retv = new 'Perl6Str'
+    tmps = self
+
+    len = length tmps
+    if len == 0 goto done
+
+    substr fchr, tmps, 0, 1
+    downcase fchr
+
+    concat retv, fchr
+    substr tmps, tmps, 1
+    concat retv, tmps
+
+  done:
+    .return(retv)
+.end
+
+
+
 =item match()
 
 =cut
@@ -643,6 +776,62 @@ Partial implementation. The :g modifier on regexps doesn't work, for example.
     .return ($I0)
 .end
 
+
+=item uc
+
+ our Str multi Str::uc ( Str $string )
+
+Returns the input string after converting each character to its uppercase
+form, if lowercase. This is not a Unicode "titlecase" operation, but a
+full "uppercase".
+
+=cut
+
+.sub 'uc' :method :multi(_)
+    .local string tmps
+    .local pmc retv
+
+    tmps = self
+    upcase tmps
+
+    retv = new 'Perl6Str'
+    retv = tmps
+
+    .return(retv)
+.end
+
+=item ucfirst
+
+ our Str multi Str::ucfirst ( Str $string )
+
+Performs a Unicode "titlecase" operation on the first character of the string.
+
+=cut
+
+.sub 'ucfirst' :method
+    .local string tmps
+    .local string fchr
+    .local pmc retv
+    .local int len
+
+    retv = new 'Perl6Str'
+    tmps = self
+
+    len = length tmps
+    if len == 0 goto done
+
+    substr fchr, tmps, 0, 1
+    upcase fchr
+
+    concat retv, fchr
+    substr tmps, tmps, 1
+    concat retv, tmps
+
+  done:
+    .return(retv)
+.end
+
+
 # Local Variables:
 #   mode: pir
 #   fill-column: 100
diff --git a/languages/perl6/src/classes/Str.pir b/languages/perl6/src/classes/Str.pir
index 65d8d98..3d4a8aa 100644
--- a/languages/perl6/src/classes/Str.pir
+++ b/languages/perl6/src/classes/Str.pir
@@ -46,134 +46,6 @@ as the Perl 6 C<Str> class.
     .return(retv)
 .end
 
-.sub lc :method
-    .local string tmps
-    .local pmc retv
-
-    tmps = self
-    downcase tmps
-
-    retv = new 'Perl6Str'
-    retv = tmps
-
-    .return(retv)
-.end
-
-.sub uc :method
-    .local string tmps
-    .local pmc retv
-
-    tmps = self
-    upcase tmps
-
-    retv = new 'Perl6Str'
-    retv = tmps
-
-    .return(retv)
-.end
-
-.sub lcfirst :method
-    .local string tmps
-    .local string fchr
-    .local pmc retv
-    .local int len
-
-    retv = new 'Perl6Str'
-    tmps = self
-
-    len = length tmps
-    if len == 0 goto done
-
-    substr fchr, tmps, 0, 1
-    downcase fchr
-
-    concat retv, fchr
-    substr tmps, tmps, 1
-    concat retv, tmps
-
-  done:
-    .return(retv)
-.end
-
-.sub ucfirst :method
-    .local string tmps
-    .local string fchr
-    .local pmc retv
-    .local int len
-
-    retv = new 'Perl6Str'
-    tmps = self
-
-    len = length tmps
-    if len == 0 goto done
-
-    substr fchr, tmps, 0, 1
-    upcase fchr
-
-    concat retv, fchr
-    substr tmps, tmps, 1
-    concat retv, tmps
-
-  done:
-    .return(retv)
-.end
-
-.sub capitalize :method
-    .local string tmps
-    .local string fchr
-    .local pmc retv
-    .local int len
-
-    retv = new 'Perl6Str'
-    tmps = self
-
-    len = length tmps
-    if len == 0 goto done
-
-    downcase tmps
-
-    .local int pos, is_ws, is_lc
-    pos = 0
-    goto first_char
-  next_grapheme:
-    if pos == len goto done
-    is_ws = is_cclass .CCLASS_WHITESPACE, tmps, pos
-    if is_ws goto ws
-  advance:
-    pos += 1
-    goto next_grapheme
-  ws:
-    pos += 1
-  first_char:
-    is_lc = is_cclass .CCLASS_LOWERCASE, tmps, pos
-    unless is_lc goto advance
-    $S1 = substr tmps, pos, 1
-    upcase $S1
-    substr tmps, pos, 1, $S1
-    ## the length may have changed after replacement, so measure it again
-    len = length tmps
-    goto advance
-  done:
-    retv = tmps
-    .return (retv)
-.end
-
-.sub 'chop' :method
-    .local string tmps
-    .local pmc retv
-    .local int len
-
-    retv = new 'Perl6Str'
-    tmps = self
-
-    len = length tmps
-    if len == 0 goto done
-    dec len
-    substr tmps,tmps, 0, len
-  done:
-    retv = tmps
-    .return(retv)
-.end
 
 
 =item perl()
@@ -254,111 +126,6 @@ Returns the identify value.
 .include 'cclass.pasm'
 
 
-=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'
-    .param string a
-    .local pmc s
-    s = new 'Perl6Str'
-    s = a
-    .return s.'lc'()
-.end
-
-
-=item lcfirst
-
- our Str multi Str::lcfirst ( Str $string )
-
-Like C<lc>, but only affects the first character.
-
-=cut
-
-.sub 'lcfirst'
-    .param string a
-    .local pmc s
-    s = new 'Perl6Str'
-    s = a
-    .return s.'lcfirst'()
-.end
-
-
-=item uc
-
- our Str multi Str::uc ( Str $string )
-
-Returns the input string after converting each character to its uppercase
-form, if lowercase. This is not a Unicode "titlecase" operation, but a
-full "uppercase".
-
-=cut
-
-.sub 'uc'
-    .param string a
-    .local pmc s
-    s = new 'Perl6Str'
-    s = a
-    .return s.'uc'()
-.end
-
-
-=item ucfirst
-
- our Str multi Str::ucfirst ( Str $string )
-
-Performs a Unicode "titlecase" operation on the first character of the string.
-
-=cut
-
-.sub 'ucfirst'
-    .param string a
-    .local pmc s
-    s = new 'Perl6Str'
-    s = a
-    .return s.'ucfirst'()
-.end
-
-
-=item capitalize
-
- our Str multi Str::capitalize ( Str $string )
-
-Has the effect of first doing an C<lc> on the entire string, then performing a
-C<s:g/(\w+)/{ucfirst $1}/> on it.
-
-=cut
-
-.sub 'capitalize'
-    .param string a
-    .local pmc s
-    s = new 'Perl6Str'
-    s = a
-    .return s.'capitalize'()
-.end
-
-=item chop
-
- our Str method Str::chop ( Str  $string: )
-
-Returns string with one Char removed from the end.
-
-=cut
-
-.sub 'chop'
-    .param string a
-    .local pmc s
-    s = new 'Perl6Str'
-    s = a
-    .return s.'chop'()
-.end
-
-
 =item infix:===
 
 Overridden for Str.

@p6rt
Copy link
Author

p6rt commented Sep 27, 2008

From @moritz

Thanks, applied as r31456.

@p6rt
Copy link
Author

p6rt commented Sep 27, 2008

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

@p6rt
Copy link
Author

p6rt commented Sep 27, 2008

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

@p6rt
Copy link
Author

p6rt commented Sep 28, 2008

From @pmichaud

On Sat, Sep 27, 2008 at 05​:44​:43AM -0700, Vasily Chekalkin wrote​:

--- a/languages/perl6/src/builtins/any-str.pir
+++ b/languages/perl6/src/builtins/any-str.pir
+
+=item capitalize
+ [...]
+=cut
+
+ .local int pos, is_ws, is_lc
+ pos = 0
+ goto first_char
+ next_grapheme​:
+ if pos == len goto done
+ is_ws = is_cclass .CCLASS_WHITESPACE, tmps, pos
+ if is_ws goto ws
+ advance​:
+ pos += 1
+ goto next_grapheme
+ ws​:
+ pos += 1
+ first_char​:
+ is_lc = is_cclass .CCLASS_LOWERCASE, tmps, pos
+ unless is_lc goto advance
...

This section of code would be much simpler (and more efficient)
by using the C<find_cclass> and C<find_not_cclass opcodes> instead of
individually examining each character one-at-a-time.

+.sub 'chop' :method
+ len = length tmps
+ if len == 0 goto done
+ dec len
+ substr tmps,tmps, 0, len
...

PIR has a C<chop> opcode, perhaps we should use it?

Pm

@p6rt
Copy link
Author

p6rt commented Sep 28, 2008

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

@p6rt
Copy link
Author

p6rt commented Sep 29, 2008

From @bacek

Patrick R. Michaud wrote​:

...

This section of code would be much simpler (and more efficient)
by using the C<find_cclass> and C<find_not_cclass opcodes> instead of
individually examining each character one-at-a-time.

+.sub 'chop' :method
+ len = length tmps
+ if len == 0 goto done
+ dec len
+ substr tmps,tmps, 0, len
...

PIR has a C<chop> opcode, perhaps we should use it?

Definitely. But I just moved code around. Should I add TODO ticket for
cleaning up this code?

--
Bacek

@p6rt
Copy link
Author

p6rt commented Sep 29, 2008

From @pmichaud

On Mon, Sep 29, 2008 at 01​:53​:44AM +1000, Vasily Chekalkin wrote​:

Patrick R. Michaud wrote​:

This section of code would be much simpler (and more efficient)
by using the C<find_cclass> and C<find_not_cclass opcodes> instead of
individually examining each character one-at-a-time.

+.sub 'chop' :method
+ len = length tmps
+ if len == 0 goto done
+ dec len
+ substr tmps,tmps, 0, len
...

PIR has a C<chop> opcode, perhaps we should use it?

Definitely. But I just moved code around. Should I add TODO ticket for
cleaning up this code?

Yes, please. And these are cleanups that someone should be able
to do with only a modest knowledge of PIR (and perhaps a good
chance to learn PIR :-).

Pm

@p6rt
Copy link
Author

p6rt commented Sep 30, 2008

From @bacek

Patrick R. Michaud wrote​:

Yes, please. And these are cleanups that someone should be able
to do with only a modest knowledge of PIR (and perhaps a good
chance to learn PIR :-).

Done. #​59486 and #​59490

--
Bacek

@p6rt
Copy link
Author

p6rt commented Oct 1, 2008

From @moritz

On Tue Sep 30 16​:30​:57 2008, bacek wrote​:

Patrick R. Michaud wrote​:

Yes, please. And these are cleanups that someone should be able
to do with only a modest knowledge of PIR (and perhaps a good
chance to learn PIR :-).

Done. #​59486 and #​59490

Since that was the last thing to do in this ticket I'm closing it now.
Thanks bacek++.

@p6rt
Copy link
Author

p6rt commented Oct 1, 2008

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

@p6rt p6rt closed this as completed Oct 1, 2008
@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