Skip to content

Commit

Permalink
Fix re-initialization of 1dim shaped arrays
Browse files Browse the repository at this point in the history
Nudged by timotimo++
  • Loading branch information
lizmat committed Nov 18, 2018
1 parent 2e5be5b commit 7262b4e
Showing 1 changed file with 34 additions and 27 deletions.
61 changes: 34 additions & 27 deletions src/core/Shaped1Array.pm6
Expand Up @@ -120,34 +120,41 @@
) )
) )
} }
multi method STORE(::?CLASS:D: Iterable:D \in) { multi method STORE(::?CLASS:D: Iterable:D \in, :$INITIALIZE) {
nqp::stmts( my \list := nqp::getattr(self,List,'$!reified');
(my \list := nqp::getattr(self,List,'$!reified')), my int $elems = nqp::elems(list);
(my \desc := nqp::getattr(self,Array,'$!descriptor')), nqp::bind( # rebind newly created list if not the first time
(my \iter := in.iterator), list,
(my int $elems = nqp::elems(list)), nqp::bindattr(
(my int $i = -1), self,List,'$!reified',nqp::setelems(nqp::create(list),$elems)
nqp::until( )
nqp::eqaddr((my $pulled := iter.pull-one),IterationEnd) ) unless $INITIALIZE;
|| nqp::iseq_i(($i = nqp::add_i($i,1)),$elems), my \desc := nqp::getattr(self,Array,'$!descriptor');
nqp::ifnull( my \iter := in.iterator;
nqp::atpos(list,$i), my int $i = -1;
nqp::bindpos(list,$i,nqp::p6scalarfromdesc(desc)) nqp::until(
) = $pulled nqp::eqaddr((my \pulled := iter.pull-one),IterationEnd)
), || nqp::iseq_i(($i = nqp::add_i($i,1)),$elems),
nqp::unless( nqp::ifnull(
nqp::islt_i($i,$elems) || iter.is-lazy, nqp::atpos(list,$i),
nqp::atpos(list,$i) # too many values on non-lazy iter, error nqp::bindpos(list,$i,nqp::p6scalarfromdesc(desc))
), ) = pulled
self );
) nqp::atpos(list,$i) # too many values on non-lazy iter, error
unless nqp::islt_i($i,$elems) || iter.is-lazy;
self
} }
multi method STORE(::?CLASS:D: Mu \item) { multi method STORE(::?CLASS:D: Mu \item, :$INITIALIZE) {
my \reified := nqp::getattr(self,List,'$!reified'); my \list := nqp::getattr(self,List,'$!reified');
nqp::ifnull( nqp::bind( # rebind newly created list if not the first time
nqp::atpos(reified,0), list,
nqp::bindpos(reified,0, nqp::bindattr(
nqp::p6scalarfromdesc(nqp::getattr(self,Array,'$!descriptor'))) self,List,'$!reified',
nqp::setelems(nqp::create(list),nqp::elems(list))
)
) unless $INITIALIZE;
nqp::bindpos(list,0,
nqp::p6scalarfromdesc(nqp::getattr(self,Array,'$!descriptor'))
) = item; ) = item;
self self
} }
Expand Down

0 comments on commit 7262b4e

Please sign in to comment.