Skip to content

Commit

Permalink
Implement binding of array-slices (#3970)
Browse files Browse the repository at this point in the history
AKA @A[1,2,3] := <a b c> .  For some reason, this was not implemented
before, perhaps because of pre-GLR peculiarities making this difficult.
Implementing turned out not to be such a big thing, so here goes.

This makes one spectest fail: S32-exceptions/misc2.t, 46 which tests
for specific X::Bind::Slice throwage.

This does not make any spectest pass, suggesting we need more tests.
  • Loading branch information
lizmat committed Oct 27, 2020
1 parent 089bd59 commit 051e036
Showing 1 changed file with 22 additions and 2 deletions.
24 changes: 22 additions & 2 deletions src/core.c/array_slice.pm6
Original file line number Diff line number Diff line change
Expand Up @@ -302,8 +302,28 @@ multi sub postcircumfix:<[ ]>(\SELF, Iterable:D \pos, Mu \val ) is raw {
};
}
}
multi sub postcircumfix:<[ ]>(\SELF, Iterable:D \pos, :$BIND!) is raw {
X::Bind::Slice.new(type => SELF.WHAT).throw;
multi sub postcircumfix:<[ ]>(\SELF, Iterable:D \pos, :$BIND! is raw) is raw {
if nqp::iscont(pos) {
SELF.BIND-POS(pos, $BIND);
}
else {
my $result := nqp::create(IterationBuffer);
my $posses := pos.iterator;
my $binds := $BIND.iterator;
nqp::until(
nqp::eqaddr((my $bind := $binds.pull-one),IterationEnd)
|| nqp::eqaddr((my $pos := $posses.pull-one),IterationEnd),
nqp::push($result, SELF.BIND-POS($pos, $bind))
);

# fill up if ran out of values to bind?
nqp::until(
nqp::eqaddr(($pos := $posses.pull-one),IterationEnd),
nqp::push($result,SELF.ASSIGN-POS($pos,Nil))
) if nqp::eqaddr($bind,IterationEnd);

$result.List
}
}
multi sub postcircumfix:<[ ]>(\SELF, Iterable:D \pos,Bool() :$delete!,*%other) is raw {
nqp::iscont(pos)
Expand Down

0 comments on commit 051e036

Please sign in to comment.