Author: jonathan
Date: Wed Aug 20 15:01:35 2008
New Revision: 30406
Modified:
branches/lazyrakudo/languages/perl6/src/classes/Array.pir
branches/lazyrakudo/languages/perl6/src/classes/List.pir
branches/lazyrakudo/languages/perl6/src/classes/Object.pir
branches/lazyrakudo/languages/perl6/src/classes/Range.pir
Log:
[rakudo] More fixes, more bad assumptions removed, more things switched over to
understand lazy lists. No great breakthrough in spectest_regression, though we
move a few tests in the right direction.
Modified: branches/lazyrakudo/languages/perl6/src/classes/Array.pir
==============================================================================
--- branches/lazyrakudo/languages/perl6/src/classes/Array.pir (original)
+++ branches/lazyrakudo/languages/perl6/src/classes/Array.pir Wed Aug 20
15:01:35 2008
@@ -23,9 +23,10 @@
.param pmc source
$P0 = get_hll_global 'list'
$P0 = $P0(source)
- setattribute self, "@!unevaluated", $P0
- $P0 = new 'ResizablePMCArray'
- setattribute self, "@!evaluated", $P0
+ $P1 = getattribute $P0, "@!unevaluated"
+ setattribute self, "@!unevaluated", $P1
+ $P1 = getattribute $P0, "@!evaluated"
+ setattribute self, "@!evaluated", $P1
.return (self)
.end
@@ -64,7 +65,7 @@
evaluated = getattribute self, "@!evaluated"
$I0 = elements evaluated
if $I0 < index goto use_unevaluated
- evaluated[index] = $P0
+ evaluated[index] = value
.return ()
# Need to use the unevaluated portion of the list.
@@ -72,8 +73,7 @@
.local int upto
upto = index - 1
self.'!evaluate_upto'(upto)
- $P0 = evaluated[index]
- .return ($P0)
+ evaluated[index] = value
.end
@@ -285,6 +285,48 @@
.end
+=item values()
+
+Return the values of the Array as a List.
+
+=cut
+
+.sub 'values' :method
+ $P0 = new 'List'
+ $P1 = getattribute self, "@!unevaluated"
+ setattribute $P0, "@!unevaluated", $P1
+ $P1 = getattribute self, "@!evaluated"
+ setattribute $P0, "@!evaluated", $P1
+ .return ($P0)
+.end
+
+
+=item exists(indices :slurpy)
+
+Return true if the elements at C<indices> have been assigned to.
+
+=cut
+
+.sub 'exists' :method :multi(Perl6Array)
+ .param pmc indices :slurpy
+ .local int test
+
+ .local pmc evaluated
+ evaluated = getattribute self, "@!evaluated"
+
+ test = 0
+ indices_loop:
+ unless indices goto indices_end
+ $I0 = shift indices
+ self.'!evaluate_upto'($I0)
+ test = exists evaluated[$I0]
+ if test goto indices_loop
+ indices_end:
+ .return 'prefix:?'(test)
+.end
+
+
+
############### Below here still to review after lazy changes. ###############
@@ -328,40 +370,6 @@
.end
-=item exists(indices :slurpy)
-
-Return true if the elements at C<indices> have been assigned to.
-
-=cut
-
-.sub 'exists' :method :multi(Perl6Array)
- .param pmc indices :slurpy
- .local int test
-
- test = 0
- indices_loop:
- unless indices goto indices_end
- $I0 = shift indices
- test = exists self[$I0]
- if test goto indices_loop
- indices_end:
- .return 'prefix:?'(test)
-.end
-
-
-=item values()
-
-Return the values of the Array as a List.
-
-=cut
-
-.sub 'values' :method
- $P0 = new 'List'
- splice $P0, self, 0, 0
- .return ($P0)
-.end
-
-
# Local Variables:
# mode: pir
# fill-column: 100
Modified: branches/lazyrakudo/languages/perl6/src/classes/List.pir
==============================================================================
--- branches/lazyrakudo/languages/perl6/src/classes/List.pir (original)
+++ branches/lazyrakudo/languages/perl6/src/classes/List.pir Wed Aug 20
15:01:35 2008
@@ -391,8 +391,22 @@
# We have lazy bits - need to evaluate them and work out how many elements
# are in there.
- # XXX hack
- total += uneval_count
+ .local pmc it, check
+ it = iter unevaluated
+ it_loop:
+ unless it goto it_loop_end
+ check = shift it
+ $I0 = isa check, 'Range'
+ if $I0 goto is_iter
+ $I0 = isa check, 'IOIterator'
+ if $I0 goto is_iter
+ inc total
+ goto it_loop
+ is_iter:
+ $I0 = check.'elems'()
+ total += $I0
+ goto it_loop
+ it_loop_end:
done:
.return (total)
Modified: branches/lazyrakudo/languages/perl6/src/classes/Object.pir
==============================================================================
--- branches/lazyrakudo/languages/perl6/src/classes/Object.pir (original)
+++ branches/lazyrakudo/languages/perl6/src/classes/Object.pir Wed Aug 20
15:01:35 2008
@@ -122,9 +122,9 @@
=cut
.sub 'list' :method
- $P0 = new 'List'
- push $P0, self
- .return ($P0)
+ $P0 = get_hll_global 'list'
+ $P1 = $P0(self)
+ .return ($P1)
.end
Modified: branches/lazyrakudo/languages/perl6/src/classes/Range.pir
==============================================================================
--- branches/lazyrakudo/languages/perl6/src/classes/Range.pir (original)
+++ branches/lazyrakudo/languages/perl6/src/classes/Range.pir Wed Aug 20
15:01:35 2008
@@ -119,6 +119,36 @@
.end
+=item elems
+
+Gets the number of elements we'd have if we iterated this iterator.
+
+=cut
+
+.sub 'elems' :method
+ .local pmc from, fromexc, toexc, to
+ from = getattribute self, '$!from'
+ fromexc = getattribute self, '$!from_exclusive'
+ toexc = getattribute self, '$!to_exclusive'
+ to = getattribute self, '$!to'
+
+ # XXX Bad: assuming it's an Int range; needs fixing before merge.
+ .local int total
+ $I0 = to
+ $I1 = from
+ total = $I0 - $I1
+ inc total # assume inclusive first
+ unless fromexc goto not_fromexc
+ dec total
+ not_fromexc:
+ unless toexc goto not_toexc
+ dec total
+ not_toexc:
+
+ .return (total)
+.end
+
+
=item iterator() (vtable method)
Return an iterator for the Range. Since Ranges are already