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

[svn:parrot] r33645 - in branches/assign/languages/perl6/src: classes parser

From:
pmichaud
Date:
December 7, 2008 21:37
Subject:
[svn:parrot] r33645 - in branches/assign/languages/perl6/src: classes parser
Message ID:
20081208053653.F1B4ACB9AF@x12.develooper.com
Author: pmichaud
Date: Sun Dec  7 21:36:53 2008
New Revision: 33645

Modified:
   branches/assign/languages/perl6/src/classes/List.pir
   branches/assign/languages/perl6/src/parser/actions.pm

Log:
[rakudo]:  initial slice implementation -- still more to do


Modified: branches/assign/languages/perl6/src/classes/List.pir
==============================================================================
--- branches/assign/languages/perl6/src/classes/List.pir	(original)
+++ branches/assign/languages/perl6/src/classes/List.pir	Sun Dec  7 21:36:53 2008
@@ -67,6 +67,25 @@
     $S0 = join ' ', self
     .return ($S0)
 .end
+
+=item ResizablePMCArray.list
+
+This version of list morphs a ResizablePMCArray into a List.
+
+=cut
+
+.namespace ['ResizablePMCArray']
+.sub 'list' :method
+    ##  this code morphs a ResizablePMCArray into a List
+    ##  without causing a clone of any of the elements
+    $P0 = new 'ResizablePMCArray'
+    splice $P0, self, 0, 0
+    $P1 = new 'List'
+    copy self, $P1
+    splice self, $P0, 0, 0
+    .return (self)
+.end
+
     
 =item hash()
 
@@ -74,6 +93,7 @@
 
 =cut
 
+.namespace ['List']
 .sub 'hash' :method
     .local pmc result, iter
     result = new 'Perl6Hash'
@@ -115,25 +135,24 @@
 .end
 
 
-=item list()
+=back
+
+=head2 Methods
 
-Return the List as a list.
+=over
+
+=item elems()
+
+Return the number of elements in the list.
 
 =cut
 
-.namespace ['ResizablePMCArray']
-.sub 'list' :method
-    ##  this code morphs a ResizablePMCArray into a List
-    ##  without causing a clone of any of the elements
-    $P0 = new 'ResizablePMCArray'
-    splice $P0, self, 0, 0
-    $P1 = new 'List'
-    copy self, $P1
-    splice self, $P0, 0, 0
-    .return (self)
+.sub 'elems' :method :multi('ResizablePMCArray') :vtable('get_number')
+    self.'!flatten'()
+    $I0 = elements self
+    .return ($I0)
 .end
 
-
 =item perl()
 
 Returns a Perl representation of a List.
@@ -159,10 +178,54 @@
     .return (result)
 .end
 
+=back
+
+=head2 Operator methods
+
+=over
+
+=item postcircumfix:<[ ]>
+
+Returns a list element or slice.
+
+=cut
+
+.sub 'postcircumfix:[ ]' :method
+    .param pmc args            :slurpy
+    .param pmc options         :slurpy :named
+    .local pmc result
+    args.'!flatten'()
+    $I0 = args.'elems'()
+    if $I0 != 1 goto slice
+    $I0 = args[0]
+    result = self[$I0]
+    unless null result goto end
+    $P0 = get_hll_global 'Object'
+    result = new 'Failure'
+    self[$I0] = result
+    goto end
+  slice:
+    result = new 'List'
+  slice_loop:
+    unless args goto slice_done
+    $I0 = shift args
+    .local pmc elem
+    elem = self[$I0]
+    unless null elem goto slice_elem
+    elem = new 'Failure'
+    self[$I0] = elem
+  slice_elem:
+    push result, elem
+    goto slice_loop
+  slice_done:
+  end:
+    .return (result)
+.end
+
 
 =back
 
-=head2 List methods
+=head2 Private methods
 
 =over 4
 
@@ -218,18 +281,6 @@
 .end
 
 
-=item elems()
-
-Return the number of elements in the list.
-
-=cut
-
-.sub 'elems' :method :multi('ResizablePMCArray') :vtable('get_number')
-    self.'!flatten'()
-    $I0 = elements self
-    .return ($I0)
-.end
-
 
 =item first(...)
 

Modified: branches/assign/languages/perl6/src/parser/actions.pm
==============================================================================
--- branches/assign/languages/perl6/src/parser/actions.pm	(original)
+++ branches/assign/languages/perl6/src/parser/actions.pm	Sun Dec  7 21:36:53 2008
@@ -1495,13 +1495,10 @@
 method postcircumfix($/, $key) {
     my $past;
     if $key eq '[ ]' {
-        $past := PAST::Var.new(
-            $( $<semilist> ),
-            :scope('keyed_int'),
-            :vivibase('Perl6Array'),
-            :viviself('Failure'),
-            :node( $/ )
-        );
+        $past := build_call( $( $<semilist> ) );
+        $past.node($/);
+        $past.name('postcircumfix:[ ]');
+        $past.pasttype('callmethod');
     }
     elsif $key eq '( )' {
         $past := build_call( $( $<semilist> ) );



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