Skip to content

Commit

Permalink
Browse files Browse the repository at this point in the history
Make 'return' a term taking an optional argument.
This way, 'return;' won't be silently ignored in a function. Closes #127.
  • Loading branch information
arnsholt committed Oct 28, 2013
1 parent e13e2f4 commit 724a9b1
Show file tree
Hide file tree
Showing 2 changed files with 5 additions and 4 deletions.
5 changes: 3 additions & 2 deletions src/NQP/Actions.nqp
Expand Up @@ -1559,8 +1559,9 @@ class NQP::Actions is HLL::Actions {

method postfix:sym<.>($/) { make $<dotty>.ast; }

method prefix:sym<return>($/) {
make QAST::Op.new( :op('call'), :name('RETURN') );
method term:sym<return>($/) {
make QAST::Op.new( :op('call'), :name('RETURN'),
$<EXPR> ?? $<EXPR>.ast !! QAST::WVal.new( :value($*W.find_sym(['NQPMu'])) ));
}

method prefix:sym<make>($/) {
Expand Down
4 changes: 2 additions & 2 deletions src/NQP/Grammar.nqp
Expand Up @@ -629,7 +629,7 @@ grammar NQP::Grammar is HLL::Grammar {
}

token term:sym<name> {
<name> <args>**0..1
<name> <?{ ~$<name> ne 'return' }> <args>**0..1
}

token args {
Expand Down Expand Up @@ -796,8 +796,8 @@ grammar NQP::Grammar is HLL::Grammar {

token infix:sym<,> { <sym> <O('%comma, :op<list>')> }

token prefix:sym<return> { <sym> \s <O('%list_prefix')> { $*RETURN_USED := 1 } }
token prefix:sym<make> { <sym> \s <O('%list_prefix')> }
token term:sym<return> { <sym> [\s <EXPR>]? { $*RETURN_USED := 1 } }

method smartmatch($/) {
# swap rhs into invocant position
Expand Down

0 comments on commit 724a9b1

Please sign in to comment.