develooper Front page | perl.cvs.parrot | Postings from December 2008

[svn:parrot] r34263 - in trunk/languages/perl6/src: builtins classes

From:
pmichaud
Date:
December 22, 2008 16:51
Subject:
[svn:parrot] r34263 - in trunk/languages/perl6/src: builtins classes
Message ID:
20081223005135.0DF2DCBA12@x12.develooper.com
Author: pmichaud
Date: Mon Dec 22 16:51:33 2008
New Revision: 34263

Modified:
   trunk/languages/perl6/src/builtins/any-list.pir
   trunk/languages/perl6/src/classes/Mapping.pir

Log:
[rakudo]:  refactor more "list methods" from Mapping into Any


Modified: trunk/languages/perl6/src/builtins/any-list.pir
==============================================================================
--- trunk/languages/perl6/src/builtins/any-list.pir	(original)
+++ trunk/languages/perl6/src/builtins/any-list.pir	Mon Dec 22 16:51:33 2008
@@ -152,6 +152,57 @@
     .return ($S0)
 .end
 
+=item keys()
+
+Return a List with the keys of the invocant.
+
+=cut
+
+.namespace []
+.sub 'keys' :multi()
+    .param pmc values          :slurpy
+    values.'!flatten'()
+    .tailcall values.'keys'()
+.end
+
+.namespace ['Any']
+.sub 'keys' :method
+    $I0 = self.'elems'()
+    $P0 = 'infix:^'($I0)
+    .tailcall $P0.'list'()
+.end
+
+
+=item kv
+
+=cut
+
+.namespace []
+.sub 'kv' :multi()
+    .param pmc values          :slurpy
+    values.'!flatten'()
+    .tailcall values.'kv'()
+.end
+    
+.namespace ['Any']
+.sub 'kv' :method
+    .local pmc result, it
+    result = new 'List'
+    it = self.'iterator'()
+    .local int i
+    i = 0
+  loop:
+    unless it goto done
+    $P0 = shift it
+    push result, i
+    push result, $P0
+    inc i
+    goto loop
+  done:
+    .return (result)
+.end
+
+
 =item map()
 
 =cut
@@ -298,6 +349,35 @@
 .end
 
 
+=item pairs()
+
+=cut
+
+.namespace []
+.sub 'pairs' :multi()
+    .param pmc values          :slurpy
+    values.'!flatten'()
+    .tailcall values.'pairs'()
+.end
+
+.namespace ['Any']
+.sub 'pairs' :method
+    .local pmc result, it
+    result = new 'List'
+    it = self.'iterator'()
+    .local int i
+    i = 0
+  loop:
+    unless it goto done
+    $P0 = shift it
+    $P1 = 'infix:=>'(i, $P0)
+    push result, $P1
+    inc i
+    goto loop
+  done:
+    .return (result)
+.end
+
 
 =item pick($num, :$repl)
 
@@ -570,6 +650,25 @@
 .end
 
 
+=item values
+
+Return values of the list
+
+=cut
+
+.namespace []
+.sub 'values' :multi()
+    .param pmc values          :slurpy
+    .tailcall values.'!flatten'()
+.end
+
+.namespace ['Any']
+.sub 'values' :method
+    self.'!flatten'()
+    .return (self)
+.end
+
+
 =back
 
 =cut

Modified: trunk/languages/perl6/src/classes/Mapping.pir
==============================================================================
--- trunk/languages/perl6/src/classes/Mapping.pir	(original)
+++ trunk/languages/perl6/src/classes/Mapping.pir	Mon Dec 22 16:51:33 2008
@@ -6,8 +6,6 @@
 
 =head1 Methods
 
-=over 4
-
 =cut
 
 .namespace ['Mapping']
@@ -23,21 +21,9 @@
     '!EXPORT'('keys,kv,values,reverse', $P0)
 .end
 
+=head2 Methods
 
-=item Scalar
-
-When we're going to be stored as an item, become a Hash and
-return an ObjectRef to it.
-
-=cut
-
-.namespace ['Mapping']
-.sub 'Scalar' :method
-    $P0 = self.'Hash'()
-    $P0 = new 'ObjectRef', $P0
-    .return ($P0)
-.end
-
+=over
 
 =item fmt
 
@@ -81,35 +67,6 @@
 .end
 
 
-=item hash()
-
-Return invocant as a Hash
-
-=cut
-
-.sub 'hash' :method
-    .local pmc rv
-    .local pmc it
-
-    rv = new 'Perl6Hash'
-    it = self.'iterator'()
-
-  loop:
-    .local string key
-    .local pmc val
-
-    unless it goto end
-    key = shift it
-    val = self[$S0]
-
-    rv[key] = val
-    goto loop
-
-  end:
-    .return (rv)
-.end
-
-
 =item iterator()
 
 =cut
@@ -233,34 +190,15 @@
 
     rv = '{'
     it = self.'iterator'()
-
-   loop:
-    .local string str	   
-    .local pmc pair
-    .local pmc key
-    .local pmc val
-
-    unless it goto end
-
-    pair = shift it
-
-    key = pair.'key'()
-    val = pair.'value'()
-
-    str = key.'perl'()
-    rv .= str
-
-    rv .= ' => '
-
-    str = val.'perl'()
-    rv .= str
-
-    unless it goto end
-
+    unless it goto done
+  loop:
+    $P1 = shift it
+    $S1 = $P1.'perl'()
+    rv .= $S1
+    unless it goto done
     rv .= ', '
     goto loop
-
-  end:
+  done:
     rv .= '}'
     .return (rv)
 .end
@@ -323,39 +261,41 @@
     .return (rv)
 .end
 
+=back
 
-=head2 Private methods
 
-=over 4
+=head2 Coercion methods
 
-=item !flatten()
+=over
 
-Flatten the invocant, as in list context.
+=item Scalar
+
+When we're going to be stored as an item, become a Hash and
+return an ObjectRef to it.
 
 =cut
 
-.sub '!flatten' :method
-    .tailcall self.'iterator'()
+.namespace ['Mapping']
+.sub 'Scalar' :method
+    $P0 = self.'Hash'()
+    $P0 = new 'ObjectRef', $P0
+    .return ($P0)
 .end
 
-=back
-
-
-=head2 Vtable functions
-
-=over 4
+=item Str
 
-=item ''
+Stringification of a Mapping
 
 =cut
 
-.sub '' :vtable('get_string') :method
+## FIXME: :vtable('get_string') is wrong here
+.namespace ['Mapping']
+.sub 'Str' :vtable('get_string') :method
     .local string rv
     .local pmc it
 
     it = self.'iterator'()
     rv = ''
-
   loop:
     .local string str
 
@@ -369,6 +309,21 @@
     .return (rv)
 .end
 
+
+=head2 Private methods
+
+=over 4
+
+=item !flatten()
+
+Flatten the invocant, as in list context.
+
+=cut
+
+.sub '!flatten' :method
+    .tailcall self.'iterator'()
+.end
+
 =back
 
 =cut



nntp.perl.org: Perl Programming lists via nntp and http.
Comments to Ask Bjørn Hansen at ask@perl.org | Group listing | About