Author: pmichaud
Date: Sun Dec 14 09:06:47 2008
New Revision: 33893
Modified:
trunk/languages/perl6/src/classes/IO.pir
trunk/languages/perl6/src/classes/Range.pir
Log:
[rakudo]: Reorganize method ordering, other minor cleanups.
Modified: trunk/languages/perl6/src/classes/IO.pir
==============================================================================
--- trunk/languages/perl6/src/classes/IO.pir (original)
+++ trunk/languages/perl6/src/classes/IO.pir Sun Dec 14 09:06:47 2008
@@ -8,15 +8,10 @@
This file implements the IO file handle class.
-=head1 Methods
-
-=over 4
-
=cut
.namespace ['IO']
-
-.sub 'onload' :anon :init :load
+.sub '' :anon :init :load
.local pmc p6meta
p6meta = get_hll_global ['Perl6Object'], '$!P6META'
p6meta.'new_class'('IO', 'parent'=>'Any', 'attr'=>'$!PIO')
@@ -26,15 +21,54 @@
'!EXPORT'('lines', 'from'=>$P0)
.end
+=head2 Methods
+
+=over 4
+
+=item close
+
+Closes the file.
+
+=cut
+
+.namespace ['IO']
+.sub 'close' :method
+ .local pmc PIO
+ PIO = getattribute self, "$!PIO"
+ close PIO
+ .return(1)
+.end
+
+
+=item eof
+
+Tests if we have reached the end of the file.
+
+=cut
+
+.namespace ['IO']
+.sub 'eof' :method
+ .local pmc PIO
+ PIO = getattribute self, "$!PIO"
+ if PIO goto not_eof
+ $P0 = get_hll_global [ 'Bool' ], 'True'
+ .return ($P0)
+ not_eof:
+ $P0 = get_hll_global [ 'Bool' ], 'False'
+ .return ($P0)
+.end
+
=item lines
our List multi method lines (IO $handle:) is export;
-Returns all the lines of a file as a (lazy) List regardless of context. See
also slurp.
+Returns all the lines of a file as a (lazy) List regardless of context.
+See also slurp.
=cut
+.namespace ['IO']
.sub 'lines' :method :multi('IO')
.local pmc PIO, res, chomper
PIO = getattribute self, "$!PIO"
@@ -59,6 +93,7 @@
=cut
+.namespace ['IO']
.sub 'print' :method
.param pmc args :slurpy
.local pmc it
@@ -76,22 +111,6 @@
.end
-=item say
-
-Writes the given list of items to the file, then a newline character.
-
-=cut
-
-.sub 'say' :method
- .param pmc list :slurpy
- .local pmc PIO
- PIO = getattribute self, "$!PIO"
- self.'print'(list)
- print PIO, "\n"
- .return (1)
-.end
-
-
=item printf
Parses a format string and prints formatted output according to it.
@@ -123,57 +142,39 @@
.end
-=item slurp
-
-Slurp a file into a string.
-
-=cut
-
-.sub 'slurp' :method
- .local pmc PIO
- PIO = getattribute self, "$!PIO"
- $S0 = PIO.'readall'()
- .return($S0)
-.end
-
-
-=item eof
+=item say
-Tests if we have reached the end of the file.
+Writes the given list of items to the file, then a newline character.
=cut
-.sub 'eof' :method
+.sub 'say' :method
+ .param pmc list :slurpy
.local pmc PIO
PIO = getattribute self, "$!PIO"
- if PIO goto not_eof
- $P0 = get_hll_global [ 'Bool' ], 'True'
- .return ($P0)
- not_eof:
- $P0 = get_hll_global [ 'Bool' ], 'False'
- .return ($P0)
+ self.'print'(list)
+ print PIO, "\n"
+ .return (1)
.end
-=item close
+=item slurp
-Closes the file.
+Slurp a file into a string.
=cut
-.sub 'close' :method
+.sub 'slurp' :method
.local pmc PIO
PIO = getattribute self, "$!PIO"
- close PIO
- .return(1)
+ $S0 = PIO.'readall'()
+ .return($S0)
.end
-.namespace []
-
=back
-=head1 EXPORTED MULTI SUBS
+=head2 Functions
=over 4
@@ -183,6 +184,7 @@
=cut
+.namespace []
.sub 'prefix:=' :multi('IO')
.param pmc io
$P0 = get_hll_global 'IOIterator'
@@ -190,40 +192,23 @@
.return($P0)
.end
-
-.namespace [ 'IOIterator' ]
-
=back
=head1 IOIterator
The IOIterator class implements the I/O iterator.
-=over 4
-
-=cut
-
-.sub get_bool :method :vtable
- .local pmc PIO
- $P0 = getattribute self, "$!IO"
- PIO = getattribute $P0, "$!PIO"
- if PIO goto more
- .return(0)
-more:
- .return(1)
-.end
+=head2 Methods
+=over 4
-=item Scalar
+=item item() (Vtable shift_pmc)
-Return the value inside this container in item context.
+Read a single line and return it.
=cut
-.sub 'Scalar' :method
- .tailcall self.'item'()
-.end
-
+.namespace ['IOIterator']
.sub 'item' :method :vtable('shift_pmc')
.local pmc pio, chomper
$P0 = getattribute self, "$!IO"
@@ -233,6 +218,13 @@
.tailcall chomper($P0)
.end
+=item list()
+
+Read all of the lines and return them as a List.
+
+=cut
+
+.namespace ['IOIterator']
.sub 'list' :method
.local pmc pio, res, chomper
$P0 = getattribute self, "$!IO"
@@ -251,19 +243,67 @@
.return (res)
.end
-.sub 'get_string' :vtable
+
+=back
+
+=head2 Coercion methods
+
+=item Scalar
+
+Return the value inside this container in item context.
+
+=cut
+
+.namespace ['IOIterator']
+.sub 'Scalar' :method
.tailcall self.'item'()
.end
-.sub 'get_iter' :method :vtable
- .return(self)
+
+=back
+
+=head2 Private methods
+
+=over
+
+=item !flatten
+
+Return the remainder of the input in flattening context.
+
+=cut
+
+.namespace ['IOIterator']
+.sub '!flatten' :method
+ .tailcall self.'list'()
.end
=back
+=head2 Vtable functions
+
=cut
+.namespace ['IOIterator']
+.sub '' :vtable('get_bool') :method
+ .local pmc PIO
+ $P0 = getattribute self, "$!IO"
+ PIO = getattribute $P0, "$!PIO"
+ if PIO goto more
+ .return (0)
+ more:
+ .return (1)
+.end
+
+.sub '' :vtable('get_iter') :method
+ .return (self)
+.end
+
+.sub '' :vtable('get_string') :method
+ $S0 = self.'item'()
+ .return ($S0)
+.end
+
# Local Variables:
# mode: pir
Modified: trunk/languages/perl6/src/classes/Range.pir
==============================================================================
--- trunk/languages/perl6/src/classes/Range.pir (original)
+++ trunk/languages/perl6/src/classes/Range.pir Sun Dec 14 09:06:47 2008
@@ -6,48 +6,20 @@
=head1 DESCRIPTION
-=head2 Methods
-
-=over 4
-
=cut
.namespace ['Range']
-.sub 'onload' :anon :load :init
+.sub '' :anon :load :init
.local pmc p6meta, rangeproto
p6meta = get_hll_global ['Perl6Object'], '$!P6META'
rangeproto = p6meta.'new_class'('Range', 'parent'=>'Any', 'attr'=>'$!from
$!to $!from_exclusive $!to_exclusive')
rangeproto.'!IMMUTABLE'()
.end
+=head2 Methods
-=item VTABLE_get integer (vtable method)
-
-=item VTABLE_get_number (vtable method)
-
-=item VTABLE_get_string (vtable method)
-
-=cut
-
-.sub 'VTABLE_get_integer' :method :vtable('get_integer')
- $P0 = self.'list'()
- $I0 = $P0
- .return ($I0)
-.end
-
-.sub 'VTABLE_get_number' :method :vtable('get_number')
- $P0 = self.'list'()
- $N0 = $P0
- .return ($N0)
-.end
-
-.sub 'VTABLE_get_string' :method :vtable('get_string')
- $P0 = self.'list'()
- $S0 = $P0
- .return ($S0)
-.end
-
+=over 4
=item ACCEPTS(topic)
@@ -120,7 +92,7 @@
.end
-=item iterator() (vtable method)
+=item iterator() (vtable function)
Return an iterator for the Range. Since Ranges are already
iterators, we can just return a clone.
@@ -155,16 +127,20 @@
.end
+=item max()
+
=item min()
=item minmax()
-=item max()
-
=cut
.namespace ['Range']
+.sub 'max' :method
+ .tailcall self.'to'()
+.end
+
.sub 'min' :method
.tailcall self.'from'()
.end
@@ -176,8 +152,31 @@
.tailcall $P2($P0, $P1)
.end
-.sub 'max' :method
- .tailcall self.'to'()
+
+=item perl()
+
+Returns a Perl representation of the Range.
+
+=cut
+
+.sub 'perl' :method
+ .local string result, tmp
+ .local pmc from, fromexc, toexc, to
+ from = getattribute self, '$!from'
+ fromexc = getattribute self, '$!from_exclusive'
+ toexc = getattribute self, '$!to_exclusive'
+ to = getattribute self, '$!to'
+ result = from.'perl'()
+ unless fromexc goto dots
+ result .= '^'
+ dots:
+ result .= '..'
+ unless toexc goto end
+ result .= '^'
+ end:
+ tmp = to.'perl'()
+ result .= tmp
+ .return (result)
.end
@@ -244,32 +243,6 @@
.end
-=item perl()
-
-Returns a Perl representation of the Range.
-
-=cut
-
-.sub 'perl' :method
- .local string result, tmp
- .local pmc from, fromexc, toexc, to
- from = getattribute self, '$!from'
- fromexc = getattribute self, '$!from_exclusive'
- toexc = getattribute self, '$!to_exclusive'
- to = getattribute self, '$!to'
- result = from.'perl'()
- unless fromexc goto dots
- result .= '^'
- dots:
- result .= '..'
- unless toexc goto end
- result .= '^'
- end:
- tmp = to.'perl'()
- result .= tmp
- .return (result)
-.end
-
=back
=head2 Operators
@@ -353,6 +326,15 @@
=over 4
+=item !flatten()
+
+=cut
+
+.namespace ['Range']
+.sub '!flatten' :method
+ .tailcall self.'list'()
+.end
+
=item !from_test(topic)
=item !to_test(topic)
@@ -401,6 +383,38 @@
=back
+=head2 Vtable functions
+
+=over
+
+=item VTABLE_get integer (vtable method)
+
+=item VTABLE_get_number (vtable method)
+
+=item VTABLE_get_string (vtable method)
+
+=cut
+
+.sub 'VTABLE_get_integer' :method :vtable('get_integer')
+ $P0 = self.'list'()
+ $I0 = $P0
+ .return ($I0)
+.end
+
+.sub 'VTABLE_get_number' :method :vtable('get_number')
+ $P0 = self.'list'()
+ $N0 = $P0
+ .return ($N0)
+.end
+
+.sub 'VTABLE_get_string' :method :vtable('get_string')
+ $P0 = self.'list'()
+ $S0 = $P0
+ .return ($S0)
+.end
+
+=back
+
=cut
# Local Variables: