# New Ticket Created by  "Olivier Mengué" 
# Please include the string:  [perl #55872]
# in the subject line of all future correspondence about this issue. 
# <URL: http://rt.perl.org/rt3/Ticket/Display.html?id=55872 >


Improvments in Complex.pir:
- class registration (not sure about it: I'm still a newbie)
- .perl() method

Olivier Mengué (dolmen on CPAN/IRC)
Index: src/classes/Complex.pir
===================================================================
--- src/classes/Complex.pir	(révision 28404)
+++ src/classes/Complex.pir	(copie de travail)
@@ -4,23 +4,71 @@
 
 Complex - Perl 6 complex numbers
 
+
+
 =head1 SUBROUTINES
 
 =over 4
 
-=item infix:+
+=item onload
 
+Implementation is a bit different from other basic objects (Int...) because
+'Complex' is also the name of the builtin Parrot PMC.
+
 =cut
 
+.namespace [ 'Complex' ]
+
+.sub 'onload' :anon :init :load
+    .local pmc p6meta, complexproto
+    p6meta = get_hll_global ['Perl6Object'], '$!P6META'
+    #If we use this, "2i.WHAT" gives "Perl6Complex"
+    #complexproto = p6meta.'new_class'('Perl6Complex', 'parent'=>'Complex Any')
+    complexproto = get_hll_global ['Complex'], '$!P6META'
+    p6meta.'register'('Complex', 'parent'=>complexproto, 'protoobject'=>complexproto)
+.end
+
+
+# TODO ACCEPTS()
+
+
+=item perl()
+
+Returns a Perl representation of the Complex.
+
+=cut
+
+.sub 'perl' :method
+    $S0 = self
+    .return ($S0)
+.end
+
+
+=back
+
+=head1 OPERATORS
+
+=over 4
+
+=item postfix:i
+
+=cut
+
 .namespace []
 
 .sub 'postfix:i' :multi(_)
     .param num a
+    .local pmc proto
     $P0 = new 'Complex'
     $P0[1] = a
     .return ($P0)
 .end
 
+
+=item infix:+
+
+=cut
+
 .sub 'infix:+' :multi('Complex', _)
     .param pmc a
     .param pmc b
@@ -37,6 +85,11 @@
     .return ($P0)
 .end
 
+
+=item infix:-
+
+=cut
+
 .sub 'infix:-' :multi('Complex', _)
     .param pmc a
     .param pmc b
@@ -53,6 +106,11 @@
     .return ($P0)
 .end
 
+
+=item infix:*
+
+=cut
+
 .sub 'infix:*' :multi('Complex', _)
     .param pmc a
     .param pmc b
@@ -69,6 +127,11 @@
     .return ($P0)
 .end
 
+
+=item infix:/
+
+=cut
+
 .sub 'infix:/' :multi('Complex', _)
     .param pmc a
     .param pmc b

Reply via email to