Skip to content
This repository has been archived by the owner on Feb 3, 2021. It is now read-only.

Commit

Permalink
Adjust so that load_bytecode on a precompiled module automatically
Browse files Browse the repository at this point in the history
executes the mainline of the module.  This is required for
lexically-scoped subroutines to be initialized properly inside of
modules and classes.
  • Loading branch information
pmichaud committed May 15, 2010
1 parent 1232366 commit f4c4650
Showing 1 changed file with 20 additions and 5 deletions.
25 changes: 20 additions & 5 deletions src/NQP/Actions.pm
Expand Up @@ -47,11 +47,26 @@ sub colonpair_str($ast) {
}

method comp_unit($/) {
my $past := $<statementlist>.ast;
my $BLOCK := @BLOCK.shift;
$BLOCK.push($past);
$BLOCK.node($/);
make $BLOCK;
my $mainline := $<statementlist>.ast;
my $unit := @BLOCK.shift;

# We force a return here, because we have other
# :load/:init blocks to execute that we don't want
# to include as part of the mainline.
$unit.push(
PAST::Op.new( :pirop<return>, $mainline )
);

# If this code is loaded via load_bytecode, we want the unit mainline
# to be executed after all other loadinits have taken place.
$unit.push(
PAST::Block.new(
:pirflags(':load'), :lexical(0), :namespace(''),
PAST::Op.new( :pasttype<call>, PAST::Val.new( :value($unit) ) )
)
);
$unit.node($/);
make $unit;
}

method statementlist($/) {
Expand Down

0 comments on commit f4c4650

Please sign in to comment.