Skip to content

Commit

Permalink
Refactor unit startup, add context saves.
Browse files Browse the repository at this point in the history
  • Loading branch information
pmichaud committed Jul 7, 2010
1 parent 114971b commit 67e1145
Showing 1 changed file with 10 additions and 11 deletions.
21 changes: 10 additions & 11 deletions src/Perl6/Actions.pm
Expand Up @@ -69,12 +69,8 @@ method comp_unit($/, $key?) {
my $mainparam := PAST::Var.new(:name('$MAIN'), :scope('parameter'),
:viviself( PAST::Val.new( :value(0) ) ) );
$unit.symbol('$MAIN', :scope<lexical>);
# run MAIN subs
# TODO: run this only when not in a module
# TODO: find a less hacky solution than IN_EVAL
# TODO: find a way to inject MAIN_HELPER call without modifying
# the return value of the compilation unit
if !IN_EVAL() && $unit.symbol('&MAIN') {
# If the unit defines &MAIN, add a &MAIN_HELPER.
if $unit.symbol('&MAIN') {
$mainline :=
PAST::Op.new(
:pasttype('call'),
Expand All @@ -86,18 +82,21 @@ method comp_unit($/, $key?) {
else {
$unit.push($mainparam);
}
$unit.push( self.CTXSAVE() );
$unit.push($mainline);

# Executing the compilation unit causes the mainline to be executed.
# We force a tailcall here, because we have other :load/:init blocks
# We force a return here, because we have other :load/:init blocks
# that have to be done at the end of the unit, and we don't want them
# executed by the mainline.
$outer.push(
PAST::Op.new(
:pirop('tailcall'),
PAST::Var.new( :name('!UNIT_START'), :namespace(''), :scope('package') ),
$unit,
PAST::Var.new( :scope('parameter'), :name('@_'), :slurpy(1) )
:pirop('return'),
PAST::Op.new( :pasttype<call>,
PAST::Var.new( :name('!UNIT_START'), :namespace(''), :scope('package') ),
$unit,
PAST::Var.new( :scope('parameter'), :name('@_'), :slurpy(1) )
)
)
);

Expand Down

0 comments on commit 67e1145

Please sign in to comment.