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
Labels
Comments
From olivier.mengue@gmail.comImprovments in Complex.pir: Olivier Mengué (dolmen on CPAN/IRC) |
From olivier.mengue@gmail.comComplex1.patchIndex: 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
|
From @pmichaudApplied in r28433 (with minor changes to the class initialization). Pm |
@pmichaud - Status changed from 'new' to 'resolved' |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Migrated from rt.perl.org#55872 (status was 'resolved')
Searchable as RT55872$
The text was updated successfully, but these errors were encountered: