Skip to content

Commit

Permalink
Stub in QUIT phaser.
Browse files Browse the repository at this point in the history
  • Loading branch information
jnthn committed Aug 19, 2015
1 parent 5400fce commit e838194
Show file tree
Hide file tree
Showing 2 changed files with 37 additions and 0 deletions.
36 changes: 36 additions & 0 deletions src/Perl6/Actions.nqp
Original file line number Diff line number Diff line change
Expand Up @@ -1497,6 +1497,42 @@ Compilation unit '$file' contained the following violations:
make QAST::WVal.new( :value($*W.find_symbol(['Nil'])) );
}

method statement_control:sym<QUIT>($/) {
my $block := $<block>.ast;

# Take exception as parameter and bind into $_.
my $past := $block.ann('past_block');
$past[0].push(QAST::Op.new(
:op('bind'),
QAST::Var.new( :name('$_'), :scope('lexical') ),
QAST::Var.new( :name('__param'), :scope('local'), :decl('param') )
));

# If the handler has a succeed handler, then make sure we sink
# the exception it will produce.
if $past.ann('handlers') && nqp::existskey($past.ann('handlers'), 'SUCCEED') {
my $suc := $past.ann('handlers')<SUCCEED>;
$suc[0] := QAST::Stmts.new(
sink(QAST::Op.new(
:op('getpayload'),
QAST::Op.new( :op('exception') )
)),
QAST::WVal.new( :value($*W.find_symbol(['Nil'])) )
);
}

# If we don't handle the exception by succeeding, we'll return it.
if $past.ann('handlers') {
$past[1][0].push(QAST::Var.new( :name('$_'), :scope('lexical') ));
}
else {
$past[1].push(QAST::Var.new( :name('$_'), :scope('lexical') ));
}

# Add as a QUIT phaser, which evaluates to Nil.
make $*W.add_phaser($/, 'QUIT', $block.ann('code_object'));
}

method statement_prefix:sym<BEGIN>($/) { make $*W.add_phaser($/, 'BEGIN', ($<blorst>.ast).ann('code_object')); }
method statement_prefix:sym<COMPOSE>($/) { make $*W.add_phaser($/, 'COMPOSE', ($<blorst>.ast).ann('code_object')); }
method statement_prefix:sym<CHECK>($/) { make $*W.add_phaser($/, 'CHECK', ($<blorst>.ast).ann('code_object')); }
Expand Down
1 change: 1 addition & 0 deletions src/Perl6/Grammar.nqp
Original file line number Diff line number Diff line change
Expand Up @@ -1559,6 +1559,7 @@ grammar Perl6::Grammar is HLL::Grammar does STD {

rule statement_control:sym<CATCH> {<sym> <block(1)> }
rule statement_control:sym<CONTROL> {<sym> <block(1)> }
rule statement_control:sym<QUIT> {<sym> <block(1)> }

proto token statement_prefix { <...> }
token statement_prefix:sym<BEGIN> { :my %*MYSTERY; <sym><.kok> <blorst> <.explain_mystery> <.cry_sorrows> }
Expand Down

0 comments on commit e838194

Please sign in to comment.