Skip to content

Commit

Permalink
Fix AST-gen for blocks in hash constructors.
Browse files Browse the repository at this point in the history
Need to migrate inner blocks out to the right scope, given that the
hash constructor does not imply one. Fixes "on" with the EnumMap
case on MoarVM, and no doubt some other things.
  • Loading branch information
jnthn committed Apr 19, 2014
1 parent f7dcaa7 commit 8232ea1
Showing 1 changed file with 23 additions and 0 deletions.
23 changes: 23 additions & 0 deletions src/Perl6/Actions.nqp
Expand Up @@ -4683,6 +4683,7 @@ class Perl6::Actions is HLL::Actions does STDActions {
}
}
if $is_hash && $past<past_block>.arity == 0 {
migrate_blocks($past<past_block>, $*W.cur_lexpad());
my @children := @($past<past_block>[1]);
$past := QAST::Op.new(
:op('call'),
Expand Down Expand Up @@ -4715,6 +4716,28 @@ class Perl6::Actions is HLL::Actions does STDActions {
make $past;
}

# Some constructs are parsed and compiled with blocks inside of them, but
# then the outer block goes away (for example, when a {...} becomes a
# hash). This is used to move blocks out of the discarded inner one to
# the outer one, so they're correctly lexically scoped.
sub migrate_blocks($from, $to) {
my @decls := @($from[0]);
my int $n := nqp::elems(@decls);
my int $i := 0;
while $i < $n {
if nqp::istype(@decls[$i], QAST::Block) {
$to[0].push(@decls[$i]);
@decls[$i] := QAST::Op.new( :op('null') );
}
elsif nqp::istype(@decls[$i], QAST::Stmt) &&
nqp::istype(@decls[$i][0], QAST::Block) {
$to[0].push(@decls[$i][0]);
@decls[$i][0] := QAST::Op.new( :op('null') );
}
$i++;
}
}

method circumfix:sym<[ ]>($/) {
make QAST::Op.new( :op('call'), :name('&circumfix:<[ ]>'), $<semilist>.ast, :node($/) );
}
Expand Down

0 comments on commit 8232ea1

Please sign in to comment.