develooper Front page | perl.cvs.parrot | Postings from January 2009

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

From:
jonathan
Date:
January 15, 2009 04:38
Subject:
[svn:parrot] r35586 - in trunk/languages/perl6/src: builtins classes
Message ID:
20090115123746.B1C5FCB9AE@x12.develooper.com
Author: jonathan
Date: Thu Jan 15 04:37:45 2009
New Revision: 35586

Modified:
   trunk/languages/perl6/src/builtins/op.pir
   trunk/languages/perl6/src/classes/Role.pir

Log:
[rakudo] Get parametric roles working with mixins via the does operator.

Modified: trunk/languages/perl6/src/builtins/op.pir
==============================================================================
--- trunk/languages/perl6/src/builtins/op.pir	(original)
+++ trunk/languages/perl6/src/builtins/op.pir	Thu Jan 15 04:37:45 2009
@@ -401,15 +401,17 @@
     derived = new 'Class'
     addparent derived, parrot_class
     $I0 = isa role, 'Perl6Role'
+    if $I0 goto one_role_select
+    $I0 = isa role, 'Role'
     if $I0 goto one_role
     $I0 = isa role, 'List'
     if $I0 goto many_roles
   error:
     'die'("'does' expects a role or a list of roles")
 
-  one_role:
-    # XXX Need to handle parameterized roles properly at some point.
+  one_role_select:
     role = role.'!select'()
+  one_role:
     '!keyword_does'(derived, role)
     goto added_roles
 
@@ -419,10 +421,12 @@
   roles_loop:
     unless role_it goto roles_loop_end
     cur_role = shift role_it
+    $I0 = isa cur_role, 'Role'
+    if $I0 goto have_parrot_role
     $I0 = isa cur_role, 'Perl6Role'
     unless $I0 goto error
-    # XXX Need to handle parameterized roles properly at some point.
     cur_role = cur_role.'!select'()
+  have_parrot_role:
     '!keyword_does'(derived, cur_role)
     goto roles_loop
   roles_loop_end:

Modified: trunk/languages/perl6/src/classes/Role.pir
==============================================================================
--- trunk/languages/perl6/src/classes/Role.pir	(original)
+++ trunk/languages/perl6/src/classes/Role.pir	Thu Jan 15 04:37:45 2009
@@ -24,6 +24,7 @@
     .local pmc p6meta, roleproto
     p6meta = get_hll_global ['Perl6Object'], '$!P6META'
     roleproto = p6meta.'new_class'('Perl6Role', 'parent'=>'Any', 'name'=>'Role', 'attr'=>'$!selector @!created')
+    p6meta.'register'('Role', 'proto'=>'roleproto')
 .end
 
 
@@ -103,6 +104,37 @@
     .return ($P0)
 .end
 
+
+=item postcircumfix:<[ ]>
+
+Selects a role based upon type.
+
+=cut
+
+.sub 'postcircumfix:[ ]' :method
+    .param pmc pos_args  :slurpy
+    .param pmc name_args :slurpy :named
+    
+    # Need to unwrap the arguments (they are wrapped by postcircumfix:[ ]
+    # multi), then call !select.
+    pos_args = pos_args[0]
+    .tailcall self.'!select'(pos_args :flat, name_args :flat :named)
+.end
+
+
+=item elements (vtable method)
+
+Gives the number of possible parameterized roles we can select from (but really
+just here so postcircumfix:[ ] doesn't explode).
+
+=cut
+
+.sub 'elements' :vtable
+    $P0 = getattribute self, '$!selector'
+    $I0 = elements $P0
+    .return ($I0)
+.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