From 2aa69eda23c3ae3cb5ce9320060ca4b1727db6b1 Mon Sep 17 00:00:00 2001 From: jnthn Date: Thu, 1 Mar 2012 14:26:29 +0100 Subject: [PATCH] Enable use of BEGIN phasers as r-values. --- src/Perl6/Actions.pm | 2 +- src/Perl6/World.pm | 3 ++- 2 files changed, 3 insertions(+), 2 deletions(-) diff --git a/src/Perl6/Actions.pm b/src/Perl6/Actions.pm index e7d36a192f6..d8ff0352d69 100644 --- a/src/Perl6/Actions.pm +++ b/src/Perl6/Actions.pm @@ -880,7 +880,7 @@ class Perl6::Actions is HLL::Actions { make PAST::Var.new( :name('Nil'), :scope('lexical') ); } - method statement_prefix:sym($/) { $*W.add_phaser($/, ($.ast), 'BEGIN'); } + method statement_prefix:sym($/) { make $*W.add_phaser($/, ($.ast), 'BEGIN'); } method statement_prefix:sym($/) { $*W.add_phaser($/, ($.ast), 'CHECK'); } method statement_prefix:sym($/) { $*W.add_phaser($/, ($.ast), 'INIT'); } method statement_prefix:sym($/) { $*W.add_phaser($/, ($.ast), 'END'); } diff --git a/src/Perl6/World.pm b/src/Perl6/World.pm index 00a609aefb4..780decbd33a 100644 --- a/src/Perl6/World.pm +++ b/src/Perl6/World.pm @@ -1135,7 +1135,8 @@ class Perl6::World is HLL::World { method add_phaser($/, $block, $phaser) { if $phaser eq 'BEGIN' { # BEGIN phasers get run immediately. - $block(); + my $result := $block(); + return self.add_constant_folded_result($result); } elsif $phaser eq 'CHECK' { @*CHECK_PHASERS.unshift($block);