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
some array autovivification fixes/improvements #669
Comments
From @ronaldxsThis is a follow up to rt #61324 that observed, among other things, that rt #61324 was closed and that problem was fixed but a closer look It seems that when you take some slurpy params like say/print and grep, .param pmc args :slurpy your args are allocated as a ResizablePMCArray. List.pir registers The patch I include here provides a reasonably simple, pir based, Tests for related conditions were already in array_extending.t so I I also include a patch that tentatively removes some autovivification I expect to be boarding a flight to Mexico tomorrow but expect to be Hope some of this helps, |
From @ronaldxsarray_autoviv_bitbetter.patchIndex: t/spec/S02-builtin_data_types/array_extending.t
===================================================================
--- t/spec/S02-builtin_data_types/array_extending.t (revision 25127)
+++ t/spec/S02-builtin_data_types/array_extending.t (working copy)
@@ -2,7 +2,7 @@
use Test;
-plan 16;
+plan 21;
{
# Compare with Perl 5:
@@ -86,3 +86,19 @@
ok @a[1] ~~ undef, '... and the second is undef';
is @a[2], 6, '... and the third is 6';
}
+
+{
+ my @a;
+ @a[2] = 'b';
+ my @b = @a;
+ is +@b, 3, 'really a degenerative case of assigning list to array';
+ @b = (6, @a);
+ is +@b, 4, 'assigning list with extended array to an array';
+ my $s = @a.join(':');
+ is $s, '::b', 'join on extended array';
+ my $n = + @a.grep({ $_ eq 'b'});
+ is $n, 1, 'grep on extended array';
+ @a[1] = 'c'; # cmp doesn't handle undef cmp undef yet
+ my $m = @a.min();
+ ok not defined $m, 'min on list with undefined el returns undef';
+}
Index: src/classes/Array.pir
===================================================================
--- src/classes/Array.pir (revision 36120)
+++ src/classes/Array.pir (working copy)
@@ -30,7 +30,9 @@
.namespace ['Perl6Array']
.sub 'delete' :method :multi(Perl6Array)
.param pmc indices :slurpy
- .local pmc result
+ .local pmc super_class_accessor, result
+
+ super_class_accessor = getattribute self, ['ResizablePMCArray'], 'proxy'
result = new 'List'
null $P99
@@ -47,7 +49,7 @@
dec $I0
shorten_loop:
if $I0 < 0 goto shorten_end
- $P0 = self[$I0]
+ $P0 = super_class_accessor[$I0]
unless null $P0 goto shorten_end
delete self[$I0]
dec $I0
@@ -267,6 +269,29 @@
=cut
+=item get_pmc_keyed_int() (vtable method)
+
+Try to return undef/Failure rather than null for null index. Also
+autovivifies for now.
+
+=cut
+
+# autovivification will happen here for rvalues which will need fixing later ...
+
+.sub get_pmc_keyed_int :vtable :method
+ .param int key
+ .local pmc super_class_accessor, retval
+
+ super_class_accessor = getattribute self, ['ResizablePMCArray'], 'proxy'
+ retval = super_class_accessor[ key ]
+ unless null retval goto done
+ retval = 'undef'()
+ super_class_accessor[ key ] = retval
+done:
+ .return (retval)
+.end
+
+
# Local Variables:
# mode: pir
# fill-column: 100
Index: src/classes/Positional.pir
===================================================================
--- src/classes/Positional.pir (revision 36120)
+++ src/classes/Positional.pir (working copy)
@@ -46,9 +46,10 @@
goto end
result_fetch:
result = self[$I0]
- unless null result goto end
- result = 'undef'()
- self[$I0] = result
+# -- not clear on whether autovivication is part of positional role (maybe?) --
+# unless null result goto end
+# result = 'undef'()
+# self[$I0] = result
goto end
result_whatever:
result = 'list'(self)
Index: src/builtins/io.pir
===================================================================
--- src/builtins/io.pir (revision 36120)
+++ src/builtins/io.pir (working copy)
@@ -20,9 +20,6 @@
iter_loop:
unless it goto iter_end
$P0 = shift it
- unless null $P0 goto iter_nonull
- $P0 = new 'Failure'
- iter_nonull:
print $P0
goto iter_loop
iter_end:
|
From @ronaldxsOn Fri Jan 30 17:19:56 2009, ronaldxs wrote:
It is now many months later and all of test cases above, except the Ron |
@ronaldxs - Status changed from 'new' to 'resolved' |
Migrated from rt.perl.org#62948 (status was 'resolved')
Searchable as RT62948$
The text was updated successfully, but these errors were encountered: