Skip to content

Commit

Permalink
Browse files Browse the repository at this point in the history
Fix CHECK phasers in r-value context; also move all CHECK handling in…
…to World.
  • Loading branch information
jnthn committed Mar 1, 2012
1 parent 01386ea commit d73f458
Show file tree
Hide file tree
Showing 3 changed files with 17 additions and 7 deletions.
2 changes: 1 addition & 1 deletion src/Perl6/Actions.pm
Expand Up @@ -881,7 +881,7 @@ class Perl6::Actions is HLL::Actions {
}

method statement_prefix:sym<BEGIN>($/) { make $*W.add_phaser($/, ($<blorst>.ast)<code_object>, 'BEGIN'); }
method statement_prefix:sym<CHECK>($/) { $*W.add_phaser($/, ($<blorst>.ast)<code_object>, 'CHECK'); }
method statement_prefix:sym<CHECK>($/) { make $*W.add_phaser($/, ($<blorst>.ast)<code_object>, 'CHECK'); }
method statement_prefix:sym<INIT>($/) { $*W.add_phaser($/, ($<blorst>.ast)<code_object>, 'INIT'); }
method statement_prefix:sym<END>($/) { $*W.add_phaser($/, ($<blorst>.ast)<code_object>, 'END'); }

Expand Down
6 changes: 1 addition & 5 deletions src/Perl6/Grammar.pm
Expand Up @@ -425,10 +425,6 @@ grammar Perl6::Grammar is HLL::Grammar {
:my $*POD_PAST;
:my $*DECLARATOR_DOCS;

# CHECK phasers for this compilation unit we'll need at
# CHECK time.
:my @*CHECK_PHASERS := [];

# Setting loading and symbol setup.
{
# Create unit outer (where we assemble any lexicals accumulated
Expand Down Expand Up @@ -494,7 +490,7 @@ grammar Perl6::Grammar is HLL::Grammar {
}

# CHECK time.
{ for @*CHECK_PHASERS { $_() } }
{ $*W.CHECK(); }
}

method import_EXPORTHOW($UNIT) {
Expand Down
16 changes: 15 additions & 1 deletion src/Perl6/World.pm
Expand Up @@ -51,6 +51,9 @@ class Perl6::World is HLL::World {
# Cached constants that we've built.
has %!const_cache;

# List of CHECK blocks to run.
has @!CHECKs;

# Creates a new lexical scope and puts it on top of the stack.
method push_lexpad($/) {
# Create pad, link to outer and add to stack.
Expand Down Expand Up @@ -1139,7 +1142,10 @@ class Perl6::World is HLL::World {
return self.add_constant_folded_result($result);
}
elsif $phaser eq 'CHECK' {
@*CHECK_PHASERS.unshift($block);
my $result_node := PAST::Stmt.new( PAST::Var.new( :name('Nil'), :scope('lexical_6model') ) );
@!CHECKs := [] unless @!CHECKs;
@!CHECKs.unshift([$block, $result_node]);
return $result_node;
}
elsif $phaser eq 'INIT' {
$*UNIT[0].push(PAST::Op.new(
Expand All @@ -1159,6 +1165,14 @@ class Perl6::World is HLL::World {
}
}

# Runs the CHECK phasers and twiddles the PAST to look them up.
method CHECK() {
for @!CHECKs {
my $result := $_[0]();
$_[1][0] := self.add_constant_folded_result($result);
}
}

# Adds required libraries to a compilation unit.
method add_libs($comp_unit) {
$comp_unit.loadlibs('nqp_group', 'nqp_ops', 'perl6_group', 'perl6_ops',
Expand Down

0 comments on commit d73f458

Please sign in to comment.