Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Complex.pir: class registration, .perl() #132

Closed
p6rt opened this issue Jun 16, 2008 · 4 comments
Closed

Complex.pir: class registration, .perl() #132

p6rt opened this issue Jun 16, 2008 · 4 comments
Labels

Comments

@p6rt
Copy link

p6rt commented Jun 16, 2008

Migrated from rt.perl.org#55872 (status was 'resolved')

Searchable as RT55872$

@p6rt
Copy link
Author

p6rt commented Jun 16, 2008

From olivier.mengue@gmail.com

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

Olivier Mengué (dolmen on CPAN/IRC)

@p6rt
Copy link
Author

p6rt commented Jun 16, 2008

From olivier.mengue@gmail.com

Complex1.patch
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

@p6rt
Copy link
Author

p6rt commented Jun 16, 2008

From @pmichaud

Applied in r28433 (with minor changes to the class initialization).
Thanks!

Pm

@p6rt
Copy link
Author

p6rt commented Jun 16, 2008

@pmichaud - Status changed from 'new' to 'resolved'

@p6rt p6rt closed this as completed Jun 16, 2008
@p6rt p6rt added the patch label Jan 5, 2020
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests

1 participant