In perl.git, the branch sprout/deparse-begin has been created
<http://perl5.git.perl.org/perl.git/commitdiff/d96f97d56b40057037b3600b29fe22b2621d57d1?hp=0000000000000000000000000000000000000000>
at d96f97d56b40057037b3600b29fe22b2621d57d1 (commit)
- Log -----------------------------------------------------------------
commit d96f97d56b40057037b3600b29fe22b2621d57d1
Author: Father Chrysostomos <[email protected]>
Date: Wed Nov 19 20:20:48 2014 -0800
Abandoned attempt at deparsing BEGIN blocks in the right spot
This patch was trying to solve the problem of { foo(); BEGIN {} } deparsing
as { foo(); } BEGIN {}, by giving meaning to the differences between
sequence numbers. At scope end, the sequence number is incremented by
10, or maybe 9, or maybe 11, so subs that have outer sequence numbers
differing from the previous COP (statement) by less than 10 will be
put in the same block. The problem arises when you have multiple scope
ends and one BEGIN block that goes somewhere in there. I canât control
the exact interval between sequence numbers, because different pieces
of code expect to be able to increment it for different reasons. And
rounding to the nearest 10 is not fail-proof, because enough blocks
will make it round the wrong way.
When I realised how fragile this approach was, I stopped writing the
patch. So far, it only works for { foo(); BEGIN {} }, not for
{ { foo(); } BEGIN {} }.
M lib/B/Deparse.pm
M lib/B/Deparse.t
M pad.c
commit 70c40ebc001d2b45b1355bf723a17b536970bfec
Author: Father Chrysostomos <[email protected]>
Date: Mon Nov 17 19:17:29 2014 -0800
Localise PL_cop_seqmax when parsing subs
This means that, in code like:
my $x;
my $y;
sub foo {
my $z;
my $alef;
}
my $beth;
my $gimel;
The sequence numbers for the statements are reset when foo finishes
parsing, so the following statements end up with the same sequence
numbers is the statements in foo.
This will allow the differences between sequence numbers to become
meaningful in a future commit. I hope to use that to fix the remain-
ing issue in #77452, that BEGIN blocks may fall below the blocks that
were supposed to contain them.
It doesnât matter that we end up with unrelated, non-sequential state-
ments with the same sequence numbers. Pads use sequence numbers to
determine which lexicals are in scope, but it only applies to lexical
declared within that very sub. Outer lexicals are in scope for the
whole sub and donât use sequence numbers.
This should not affect B::Deparse either (which uses sequence numbers
to determine where to deparse subs), because d88d1fe0d1 made it ensure
that subs are deparsed inside the correct outer sub.
Nevertheless, localising the sequence number does mean that we have to
increment it after parsing each sub, and not just after âuseâ state-
ments. Also, we need to adjust the magic number in B::Concise.
M ext/B/B/Concise.pm
M op.c
M toke.c
commit 36f93292a9f843bd27b6593e9aae5ab7e71328c5
Author: Father Chrysostomos <[email protected]>
Date: Mon Nov 17 18:59:40 2014 -0800
test.pl:runperl: Allow multiline prog
Split it into multiple -e options for portability.
M t/test.pl
commit cec1c0a482dc3562553f3538da1d44e480a0dcda
Author: Father Chrysostomos <[email protected]>
Date: Mon Nov 17 18:54:04 2014 -0800
Use test.pl in Deparse.t
I like runperl. I want runperl.
M lib/B/Deparse.t
-----------------------------------------------------------------------
--
Perl5 Master Repository