Skip to content

Commit

Permalink
Implement postcircumfix:[ ] in Range. It doesn't know about infinite …
Browse files Browse the repository at this point in the history
…ranges, but not much else does yet either.
  • Loading branch information
jnthn committed Apr 9, 2009
1 parent 9854f25 commit 07ed756
Showing 1 changed file with 28 additions and 0 deletions.
28 changes: 28 additions & 0 deletions src/classes/Range.pir
Expand Up @@ -14,6 +14,15 @@ src/classes/Range.pir - methods for the Range class
.local pmc p6meta, rangeproto
p6meta = get_hll_global ['Perl6Object'], '$!P6META'
rangeproto = p6meta.'new_class'('Range', 'parent'=>'Any', 'attr'=>'$!by $!from $!to $!from_exclusive $!to_exclusive')

$P0 = p6meta.'get_parrotclass'(rangeproto)
$P1 = new 'ResizablePMCArray'
push $P1, 'postcircumfix:[ ]'
$P0.'resolve_method'($P1)
$P0 = get_hll_global 'Positional'
$P0 = $P0.'!select'()
p6meta.'add_role'($P0, 'to'=>rangeproto)

rangeproto.'!IMMUTABLE'()
.end

Expand Down Expand Up @@ -66,6 +75,25 @@ Generate the next element at the end of the Range.
.end


=item postcircumfix:[ ]

=cut

.sub 'postcircumfix:[ ]' :method
.param pmc pos_args :slurpy
.param pmc named_args :slurpy :named
# Since ranges aren't lazy yet anyway, we just get the .list() for
# this range and then delegate to it's postcircumfix. When they are
# truly lazy we can re-visit this and do something smarter.
$P0 = self.'list'()
.tailcall $P0.'postcircumfix:[ ]'(pos_args :flat, named_args :flat :named)
.end
.sub '' :vtable('elements')
$I0 = self.'elems'()
.return ($I0)
.end


=item shift() (vtable_method)

Generate the next element at the front of the Range.
Expand Down

0 comments on commit 07ed756

Please sign in to comment.