Skip to content

Commit

Permalink
Switch Array vivification to not use $!whence
Browse files Browse the repository at this point in the history
  • Loading branch information
jnthn committed Jun 15, 2018
1 parent 82702e9 commit 761c0bb
Show file tree
Hide file tree
Showing 2 changed files with 28 additions and 22 deletions.
26 changes: 26 additions & 0 deletions src/Perl6/Metamodel/ContainerDescriptor.nqp
Expand Up @@ -66,3 +66,29 @@ class Perl6::Metamodel::ContainerDescriptor::BindArrayPos
nqp::bindpos($!target, $!pos, $scalar);
}
}

class Perl6::Metamodel::ContainerDescriptor::VivifyArray
does Perl6::Metamodel::ContainerDescriptor::Whence {
has $!target;
has $!array;
has int $!pos;

method new($target, $array, int $pos) {
my $self := nqp::create(self);
nqp::bindattr($self, Perl6::Metamodel::ContainerDescriptor::VivifyArray,
'$!target', $target);
nqp::bindattr($self, Perl6::Metamodel::ContainerDescriptor::VivifyArray,
'$!array', $array);
nqp::bindattr_i($self, Perl6::Metamodel::ContainerDescriptor::VivifyArray,
'$!pos', $pos);
$self
}

method assigned($scalar) {
my $target := $!target;
my $array := nqp::isconcrete($target)
?? $target
!! nqp::assign($target, $!array.new);
$array.BIND-POS($!pos, $scalar);
}
}
24 changes: 2 additions & 22 deletions src/core/Any.pm6
Expand Up @@ -251,30 +251,10 @@ my class Any { # declared in BOOTSTRAP

proto method AT-POS(|) is nodal {*}
multi method AT-POS(Any:U \SELF: int \pos) is raw {
nqp::p6bindattrinvres(
my $scalar,
Scalar,
'$!whence',
-> { nqp::if(
nqp::isconcrete(SELF),
SELF,
(SELF = Array.new)
).BIND-POS(pos, $scalar)
}
)
nqp::p6scalarfromdesc(ContainerDescriptor::VivifyArray.new(SELF, Array, pos))
}
multi method AT-POS(Any:U \SELF: Int:D \pos) is raw {
nqp::p6bindattrinvres(
my $scalar,
Scalar,
'$!whence',
-> { nqp::if(
nqp::isconcrete(SELF),
SELF,
(SELF = Array.new)
).BIND-POS(pos, $scalar)
}
)
nqp::p6scalarfromdesc(ContainerDescriptor::VivifyArray.new(SELF, Array, pos))
}
multi method AT-POS(Any:U: Num:D \pos) is raw {
nqp::isnanorinf(pos)
Expand Down

0 comments on commit 761c0bb

Please sign in to comment.