Skip to content
Permalink
Browse files

Fix re-initialization of 1dim shaped arrays

Nudged by timotimo++
  • Loading branch information...
lizmat committed Nov 18, 2018
1 parent 2e5be5b commit 7262b4e840fb8148e2f66ecf8fff5951c11f160e
Showing with 34 additions and 27 deletions.
  1. +34 −27 src/core/Shaped1Array.pm6
@@ -120,34 +120,41 @@
)
)
}
multi method STORE(::?CLASS:D: Iterable:D \in) {
nqp::stmts(
(my \list := nqp::getattr(self,List,'$!reified')),
(my \desc := nqp::getattr(self,Array,'$!descriptor')),
(my \iter := in.iterator),
(my int $elems = nqp::elems(list)),
(my int $i = -1),
nqp::until(
nqp::eqaddr((my $pulled := iter.pull-one),IterationEnd)
|| nqp::iseq_i(($i = nqp::add_i($i,1)),$elems),
nqp::ifnull(
nqp::atpos(list,$i),
nqp::bindpos(list,$i,nqp::p6scalarfromdesc(desc))
) = $pulled
),
nqp::unless(
nqp::islt_i($i,$elems) || iter.is-lazy,
nqp::atpos(list,$i) # too many values on non-lazy iter, error
),
self
)
multi method STORE(::?CLASS:D: Iterable:D \in, :$INITIALIZE) {
my \list := nqp::getattr(self,List,'$!reified');
my int $elems = nqp::elems(list);
nqp::bind( # rebind newly created list if not the first time
list,
nqp::bindattr(
self,List,'$!reified',nqp::setelems(nqp::create(list),$elems)
)
) unless $INITIALIZE;
my \desc := nqp::getattr(self,Array,'$!descriptor');
my \iter := in.iterator;
my int $i = -1;
nqp::until(
nqp::eqaddr((my \pulled := iter.pull-one),IterationEnd)
|| nqp::iseq_i(($i = nqp::add_i($i,1)),$elems),
nqp::ifnull(
nqp::atpos(list,$i),
nqp::bindpos(list,$i,nqp::p6scalarfromdesc(desc))
) = pulled
);
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) {
my \reified := nqp::getattr(self,List,'$!reified');
nqp::ifnull(
nqp::atpos(reified,0),
nqp::bindpos(reified,0,
nqp::p6scalarfromdesc(nqp::getattr(self,Array,'$!descriptor')))
multi method STORE(::?CLASS:D: Mu \item, :$INITIALIZE) {
my \list := nqp::getattr(self,List,'$!reified');
nqp::bind( # rebind newly created list if not the first time
list,
nqp::bindattr(
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;
self
}

0 comments on commit 7262b4e

Please sign in to comment.
You can’t perform that action at this time.