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

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

From:
moritz
Date:
December 20, 2008 02:14
Subject:
[svn:parrot] r34133 - in trunk/languages/perl6/src: builtins classes
Message ID:
20081220101417.AE9BDCBA12@x12.develooper.com
Author: moritz
Date: Sat Dec 20 02:14:12 2008
New Revision: 34133

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

Log:
[rakudo] move .map and .grep to any-list.pir to make them work on ranges.
Patch courtesy by Cory Spence, cspencer++. Closes RT #61550.


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	Sat Dec 20 02:14:12 2008
@@ -21,10 +21,9 @@
 .namespace ['Any']
 .sub 'onload' :anon :init :load
     $P0 = get_hll_namespace ['Any']
-    '!EXPORT'('end', 'from'=>$P0)
+    '!EXPORT'('end,map,grep', 'from'=>$P0)
 .end
 
-
 =item elems()
 
 =cut
@@ -56,6 +55,38 @@
     .return ($I0)
 .end
 
+=item grep(...)
+
+=cut
+
+.sub 'grep' :method :multi(_, 'Sub')
+    .param pmc test
+    .local pmc retv
+    .local pmc iter
+    .local pmc block_res
+    .local pmc block_arg
+
+    retv = new 'List'
+    iter = self.'iterator'()
+  loop:
+    unless iter goto done
+    block_arg = shift iter
+    block_res = test(block_arg)
+
+    unless block_res goto loop
+    retv.'push'(block_arg)
+    goto loop
+
+  done:
+    .return(retv)
+.end
+
+.sub 'grep' :multi('Sub')
+    .param pmc test
+    .param pmc values          :slurpy
+    .tailcall values.'grep'(test)
+.end
+
 =item join
 
 =cut
@@ -80,6 +111,59 @@
     .return ($S0)
 .end
 
+=item map()
+
+=cut
+
+.namespace []
+.sub 'map' :multi('Sub')
+    .param pmc expression
+    .param pmc values          :slurpy
+    .tailcall values.'map'(expression)
+.end
+
+.namespace ['Any']
+.sub 'map' :method :multi(_, 'Sub')
+    .param pmc expression
+    .local pmc res, elem, block, mapres, iter, args
+    .local int i, arity
+
+    arity = expression.'arity'()
+    if arity > 0 goto body
+    arity = 1
+  body:
+    res = new 'List'
+    iter = self.'iterator'()
+  map_loop:
+    unless iter goto done
+
+    # Creates arguments for closure
+    args = new 'ResizablePMCArray'
+
+    i = 0
+  args_loop:
+    if i == arity goto invoke
+    unless iter goto elem_undef
+    elem = shift iter
+    goto push_elem
+  elem_undef:
+    elem = new 'Failure'
+  push_elem:
+    push args, elem
+    inc i
+    goto args_loop
+
+  invoke:
+    (mapres :slurpy) = expression(args :flat)
+    unless mapres goto map_loop
+    mapres.'!flatten'()
+    $I0 = elements res
+    splice res, mapres, $I0, 0
+    goto map_loop
+
+  done:
+    .return(res)
+.end
 
 =item min
 

Modified: trunk/languages/perl6/src/classes/List.pir
==============================================================================
--- trunk/languages/perl6/src/classes/List.pir	(original)
+++ trunk/languages/perl6/src/classes/List.pir	Sat Dec 20 02:14:12 2008
@@ -16,7 +16,7 @@
     p6meta.'register'('ResizablePMCArray', 'parent'=>listproto, 'protoobject'=>listproto)
 
     $P0 = get_hll_namespace ['List']
-    '!EXPORT'('first,grep,keys,kv,map,pairs,reduce,values', $P0)
+    '!EXPORT'('first,keys,kv,pairs,reduce,values', $P0)
 .end
 
 =head2 Methods
@@ -375,39 +375,6 @@
     .return(retv)
 .end
 
-=item grep(...)
-
-=cut
-
-.sub 'grep' :method :multi('ResizablePMCArray', 'Sub')
-    .param pmc test
-    .local pmc retv
-    .local pmc iter
-    .local pmc block_res
-    .local pmc block_arg
-
-    retv = new 'List'
-    iter = self.'iterator'()
-  loop:
-    unless iter goto done
-    block_arg = shift iter
-    block_res = test(block_arg)
-
-    unless block_res goto loop
-    retv.'push'(block_arg)
-    goto loop
-
-  done:
-    .return(retv)
-.end
-
-.sub 'grep' :multi('Sub')
-    .param pmc test
-    .param pmc values          :slurpy
-    .tailcall values.'grep'(test)
-.end
-
-
 =item iterator()
 
 Returns an iterator for the list.
@@ -469,63 +436,6 @@
     .tailcall values.'kv'()
 .end
 
-
-=item map()
-
-Map.
-
-=cut
-
-.sub 'map' :method :multi('ResizablePMCArray', 'Sub')
-    .param pmc expression
-    .local pmc res, elem, block, mapres, iter, args
-    .local int i, arity
-
-    arity = expression.'arity'()
-    if arity > 0 goto body
-    arity = 1
-  body:
-    res = new 'List'
-    iter = self.'iterator'()
-  map_loop:
-    unless iter goto done
-
-    # Creates arguments for closure
-    args = new 'ResizablePMCArray'
-
-    i = 0
-  args_loop:
-    if i == arity goto invoke
-    unless iter goto elem_undef
-    elem = shift iter
-    goto push_elem
-  elem_undef:
-    elem = new 'Failure'
-  push_elem:
-    push args, elem
-    inc i
-    goto args_loop
-
-  invoke:
-    (mapres :slurpy) = expression(args :flat)
-    unless mapres goto map_loop
-    mapres.'!flatten'()
-    $I0 = elements res
-    splice res, mapres, $I0, 0
-    goto map_loop
-
-  done:
-    .return(res)
-.end
-
-
-.sub 'map' :multi('Sub')
-    .param pmc expression
-    .param pmc values          :slurpy
-    .tailcall values.'map'(expression)
-.end
-
-
 =item pairs()
 
 Return a list of Pair(index, value) elements for the invocant.



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