Skip to content

Commit

Permalink
Browse files Browse the repository at this point in the history
Ensure loop bodies are sunk.
In the future we need to implement the non-sink-context loop stuff,
but since it's never worked before (except for 'for' of course) and
is untested, it's fine to put that aside for now.
  • Loading branch information
jnthn committed Dec 9, 2012
1 parent 63659db commit 469768f
Showing 1 changed file with 10 additions and 4 deletions.
14 changes: 10 additions & 4 deletions src/Perl6/Actions.pm
Expand Up @@ -834,7 +834,7 @@ class Perl6::Actions is HLL::Actions does STDActions {
method statement_control:sym<while>($/) {
my $past := xblock_immediate( $<xblock>.ast );
$past.op(~$<sym>);
make loop_phasers($past);
make tweak_loop($past);
}

method statement_control:sym<repeat>($/) {
Expand All @@ -848,7 +848,7 @@ class Perl6::Actions is HLL::Actions does STDActions {
$past := QAST::Op.new( $<EXPR>.ast, pblock_immediate( $<pblock>.ast ),
:op($op), :node($/) );
}
make loop_phasers($past);
make tweak_loop($past);
}

method statement_control:sym<for>($/) {
Expand All @@ -869,14 +869,20 @@ class Perl6::Actions is HLL::Actions does STDActions {
if $<e3> {
$loop.push($<e3>[0].ast);
}
$loop := loop_phasers($loop);
$loop := tweak_loop($loop);
if $<e1> {
$loop := QAST::Stmts.new( $<e1>[0].ast, $loop, :node($/) );
}
make $loop;
}

sub loop_phasers($loop) {
sub tweak_loop($loop) {
# Make sure the body is in sink context (for now; in the long run,
# need to handle the l-value case).
my $body_past := $loop[1][1];
$body_past.push(QAST::Var.new( :name('Nil'), :scope('lexical') ));

# Handle phasers.
my $code := $loop[1]<code_object>;
my $block_type := $*W.find_symbol(['Block']);
my $phasers := nqp::getattr($code, $block_type, '$!phasers');
Expand Down

0 comments on commit 469768f

Please sign in to comment.