Skip to content

Commit

Permalink
Browse files Browse the repository at this point in the history
Fix .perl.EVAL roundtripping for circular Arrays and Hashes
Currently generated my \foo = [\foo] thing doesn't have the
correct value when EVALed (foo is still a Mu when its value is used).

Fix for Array and Hashes by using (my @foo) = … and (my %foo) = …
thing instead. Everything else will still get the \foo thing.

This can probably fixed for the rest of circular stuff like Pairs
and classes with (my $foo) = … but I don't know if the containerization
has some sort of impact that would produce the wrong results.
  • Loading branch information
zoffixznet committed Feb 16, 2017
1 parent 4b85db6 commit 67aeefa
Showing 1 changed file with 4 additions and 2 deletions.
6 changes: 4 additions & 2 deletions src/core/Mu.pm
Expand Up @@ -501,20 +501,22 @@ my class Mu { # declared in BOOTSTRAP
multi method gist(Mu:D:) { self.perl }

method perlseen(Mu:D \SELF: $id, $perl, *%named) {
my $sigil = nqp::iseq_s($id, 'Array') ?? '@'
!! nqp::iseq_s($id, 'Hash') ?? '%' !! '\\';
if nqp::not_i(nqp::isnull(nqp::getlexdyn('$*perlseen'))) {
my \sems := $*perlseen;
my str $WHICH = nqp::unbox_s(self.WHICH);
if nqp::existskey(sems,$WHICH) && nqp::atkey(sems,$WHICH) {
nqp::bindkey(sems,$WHICH,2);
"{$id}_{nqp::objectid(SELF)}";
"{$sigil}{$id}_{nqp::objectid(SELF)}";
}
else {
nqp::bindkey(sems,$WHICH,1);
my $result := $perl(|%named);
my int $value = nqp::atkey(sems,$WHICH);
nqp::deletekey(sems,$WHICH);
$value == 2
?? "(my \\{$id}_{nqp::objectid(SELF)} = $result)"
?? "((my {$sigil}{$id}_{nqp::objectid(SELF)}) = $result)"
!! $result
}
}
Expand Down

0 comments on commit 67aeefa

Please sign in to comment.