Skip to content

Commit

Permalink
RakuAST: implement IMPL-(UN)WRAP-MAP
Browse files Browse the repository at this point in the history
For handling Hashes/Maps being passed as arguments to .new
  • Loading branch information
lizmat committed Mar 29, 2023
1 parent 6eb3fa0 commit caa6d00
Showing 1 changed file with 28 additions and 0 deletions.
28 changes: 28 additions & 0 deletions src/Raku/ast/base.rakumod
Original file line number Diff line number Diff line change
Expand Up @@ -218,6 +218,34 @@ class RakuAST::Node {
}
}

method IMPL-WRAP-MAP(Mu $vm-hash) {
if nqp::istype($vm-hash, Map) {
# It already is a map
$vm-hash
}
else {
my $result := nqp::create(Map);
nqp::bindattr($result, Map, '$!storage', $vm-hash);
$result
}
}

method IMPL-UNWRAP-MAP(Mu $map) {
if nqp::ishash($map) {
# Wasn't wrapped anyway
$map
}
elsif nqp::istype($map, Map) {
my $storage := nqp::getattr($map, Map, '$!storage');
nqp::isconcrete($storage)
?? $storage
!! $map.FLATTENABLE_HASH
}
else {
nqp::die("Cannot hashify " ~ $map.HOW.name($map));
}
}

method dump-markers() {
my @markers;
@markers.push('') if nqp::istype(self, RakuAST::Sinkable) && self.sunk;
Expand Down

0 comments on commit caa6d00

Please sign in to comment.