Skip to content

Commit

Permalink
Browse files Browse the repository at this point in the history
Implement sub MAIN. The multi case probably works too (if you declare…
… a proto). Also should handle the case where it's not in the outermost scope (Rakudo gets that wrong...steal this fix! ;-)).
  • Loading branch information
jnthn committed Mar 13, 2011
1 parent c910ccf commit e96422c
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 0 deletions.
12 changes: 12 additions & 0 deletions src/NQP/Actions.pm
Expand Up @@ -69,6 +69,13 @@ class NQP::Actions is HLL::Actions {
PAST::Op.new( :pirop('get_class Ps'), 'LexPad' ),
PAST::Op.new( :pirop('get_class Ps'), 'NQPLexPad' )
));

# If we have a MAIN sub, call it at end of mainline.
if $*MAIN_SUB {
$mainline.push(PAST::Op.new(
:pasttype('call'), PAST::Val.new( :value($*MAIN_SUB) )
));
}

# We force a return here, because we have other
# :load/:init blocks to execute that we don't want
Expand Down Expand Up @@ -712,6 +719,11 @@ class NQP::Actions is HLL::Actions {
else {
$/.CURSOR.panic("$*SCOPE scoped routines are not supported yet");
}

# Is it the MAIN sub?
if $name eq 'MAIN' && $*MULTINESS ne 'multi' {
$*MAIN_SUB := $block;
}
}

# Apply traits.
Expand Down
1 change: 1 addition & 0 deletions src/NQP/Grammar.pm
Expand Up @@ -108,6 +108,7 @@ grammar NQP::Grammar is HLL::Grammar {

token comp_unit {
:my $*HAS_YOU_ARE_HERE := 0;
:my $*MAIN_SUB;
<.newpad>
<.outerctx>
<statementlist>
Expand Down

0 comments on commit e96422c

Please sign in to comment.