In perl.git, the branch sprout/lexsub has been created
<http://perl5.git.perl.org/perl.git/commitdiff/02fff5030233b100f6a78bec7a7982efa90cf52d?hp=0000000000000000000000000000000000000000>
at 02fff5030233b100f6a78bec7a7982efa90cf52d (commit)
- Log -----------------------------------------------------------------
commit 02fff5030233b100f6a78bec7a7982efa90cf52d
Author: Father Chrysostomos <[email protected]>
Date: Sat Sep 8 19:28:00 2012 -0700
Honour lexical prototypes
newCVREF is changed to return a PADCV op, not an RV2CV with a PADCV
kid, to keep the rv2cv_op_cv changes to a minimum. (For some reason,
if newCVREF returns an RV2CV, we end up with two inside each other.)
I also added a test for recursion, since I nearly broke it.
M op.c
M t/cmd/lexsub.t
commit 71eee7327ed8968dd2776b7471e1e24646637e8e
Author: Father Chrysostomos <[email protected]>
Date: Thu Sep 6 22:57:50 2012 -0700
Donât mention pkg in proto warnings for lex subs
M t/lib/warnings/toke
M toke.c
commit c60deeb444ee731a2c7ef908f7e1c29236889186
Author: Father Chrysostomos <[email protected]>
Date: Thu Sep 6 22:11:36 2012 -0700
pad.c: Put unavailability warning in one spot
M pad.c
commit ae34bcf1f650ed55b0c572f81f38e9b866371711
Author: Father Chrysostomos <[email protected]>
Date: Thu Sep 6 20:32:47 2012 -0700
Use the same outside logic for mysubs and formats
By using find_runcv_where both for formats and my subs nested in inner
clonable subs, we can simplify the code.
It happens to make this work ($x is visible):
use 5.01;
sub not_lexical8 {
my sub foo;
foo();
sub not_lexical9 {
my sub bar {
my $x = 'khaki car keys for the khaki car';
not_lexical8();
sub foo { warn $x }
}
bar()
}
}
not_lexical9();
This is definitely iffy code, but if making it work makes the imple-
mentation simpler, so why not?
M pad.c
M t/cmd/lexsub.t
commit bf605df330e210a7fa6df35978deecd5001b111e
Author: Father Chrysostomos <[email protected]>
Date: Thu Sep 6 18:05:35 2012 -0700
Fix subroutine unavailability during cloning
sub foo {
my $x;
format =
@
$x||'#'
.
}
write;
__END__
Variable "$x" is not available at - line 9.
That oneâs OK.
sub foo {
my sub x {};
format =
@
&x
.
}
write;
__END__
Variable "&x" is not available at - line 9.
Assertion failed: (SvTYPE(_svmagic) >= SVt_PVMG), function
S_mg_findext_flags, file mg.c, line 404.
Abort trap
That should say âSubroutineâ. And it shouldnât crash.
The my-sub-cloning code was not taking this case into account. The
value in the proto pad is an undef scalar.
M pad.c
M t/cmd/lexsub.t
commit 5a05e28d433b4c47fa5b086b04df92931138efc4
Author: Father Chrysostomos <[email protected]>
Date: Thu Sep 6 16:03:20 2012 -0700
âSubroutine "&x" is not availableâ during compilation
sub {
my $x;
sub { eval '$x' }
}->()()
__END__
Variable "$x" is not available at (eval 1) line 2.
That oneâs OK (though I wonder about the line number).
sub {
my sub x {};
sub { eval '\&x' }
}->()()
__END__
Variable "&x" is not available at (eval 1) line 1.
That should say âSubroutineâ.
M pad.c
M pod/perldiag.pod
M t/cmd/lexsub.t
M t/porting/diag.t
commit c04d8f8637cc416ac23283d9628bc11b102c92a2
Author: Father Chrysostomos <[email protected]>
Date: Tue Sep 4 10:24:57 2012 -0700
In cv_clone, use pad ID to identify mysub outside
This code prints ARRAY(0x802e10), whereas it should print
SCALAR(0xfedbee):
undef &bar;
eval 'sub bar { my @x }';
{
my sub foo;
foo();
sub bar {
CORE::state $x;
sub foo { warn \$x }
}
}
The foo sub has a strong CvOUTSIDE pointer, but what it points to
can still be undefined and redefined. So we need to identify it
by its pad.
M pad.c
M t/cmd/lexsub.t
commit c28fcee8c7fba883ec3e47f4247ea873e83f6946
Author: Father Chrysostomos <[email protected]>
Date: Mon Sep 3 21:26:37 2012 -0700
CvOUTSIDE should be strong for lexsub declared in inner pack sub
PadnameOUTER (SvFAKE) entries in pads of clonable subs contain the
offset in the parent pad where the closed-over entry is to be found.
The pad itself does not reference the outer lexical until the sub is
cloned at run time.
newMYSUB had to account for that by following CvOUTSIDE for
PadnameOUTER entries, to account for cases like this:
my sub foo;
my sub bar { sub foo {} }
The sub foo{} definition would have to find the my sub foo declaration
from outside and store the sub there.
That code was not accounting for named package subs, which close over
variables at compile time, so they donât need (and donât) store a par-
ent offset.
So outcv would point to bar in this case:
my sub foo;
sub bar { sub foo {} }
If outcv matched CvOUTSIDE(foo), then CvOUTSIDE was made weak.
That does not help in cases like this:
undef *bar;
{
my sub foo;
sub bar { sub foo {} }
}
If foo has a weak CvOUTSIDE pointer, then it will still point to bar
after bar is freed, which does not help when the sub is cloned and
tries to look at CvROOT(CvOUTSIDE).
If the pad name is marked PadnameOUTER, even if it has no parent pad
index, newMYSUB needs to leave the CvOUTSIDE pointer strongc.
Also, pad_fixup_inner_anons did not account for subs with strong
CvOUTSIDE pointers whose CvOUTSIDE point to the sub whose pad is being
iterated through.
M op.c
M pad.c
M t/cmd/lexsub.t
commit ce134adc21cdc53144fcb8febf8d3e9e0356974d
Author: Father Chrysostomos <[email protected]>
Date: Tue Aug 14 18:10:40 2012 -0700
Use the right outside for my subs defined in inner subs
In this example,
{
my sub foo;
sub bar {
sub foo { }
}
}
the foo sub is cloned when the scope containing the âmy subâ declara-
tion is entered, but fooâs CvOUTSIDE pointer points to something other
than the active sub. cv_clone assumes that the currently-running sub
is the right sub to close over (at least for subs; formats are another
matter). That was true in the absence of my subs. This commit
changes it to account.
I had to tweak the test, which was wrong, because sub foo was closing
over a stale var.
M pad.c
M t/cmd/lexsub.t
commit 7b99d801ef40ffe03160ebba7884b4527f4eacdd
Author: Father Chrysostomos <[email protected]>
Date: Tue Aug 14 12:24:43 2012 -0700
Fix Peek.t
M ext/Devel-Peek/t/Peek.t
commit 8b82a76c0956e16191a82c03b5139b0f3cccbe4c
Author: Father Chrysostomos <[email protected]>
Date: Mon Aug 13 22:56:05 2012 -0700
Preserve outside pointers of my subs with string eval
The CvHASEVAL flag lets cv_clone know that the clone needs to have its
CvOUTSIDE pointer set, for the sake of string evalsâ being able to
look up variables.
It was only being set on anonymous subs. It should be set for all
clonable subs. It doesnât actually hurt to set it on all types of
subs, whether clonable or not, since it has no effect on non-clon-
able subs.
M pad.c
M t/cmd/lexsub.t
commit fb092070dcc29f82b9dbe2e401a86b1b7b746bca
Author: Father Chrysostomos <[email protected]>
Date: Sun Aug 12 17:57:35 2012 -0700
Fix up outside pointers for my subs
I had not yet fixed Perl_pad_fixup_inner_anons to account for the
fact that my sub prototype CVs are stored in magic attached to
the SV slot in the pad, rather than directly in the pad. It also
did not like & entries that close over subs defined in outer
or inner subs (âmy sub foo; sub bar; sub bar { &foo } }â and
âsub bar; sub bar { my sub foo; sub { sub foo { } } }â respectively).
This was resulting in assertion failures, unsurprisingly.
Some of the tests I added, which were causing assertion failures, are
now failing for other reasons, and are marked as to-do.
M pad.c
M t/cmd/lexsub.t
commit bda9e61ed2c7d15e7f74b008c08174bc877ffc15
Author: Father Chrysostomos <[email protected]>
Date: Fri Aug 3 18:01:06 2012 -0700
perly.y: Remove MYSUB
This token is not used any more.
M perly.act
M perly.h
M perly.tab
M perly.y
M toke.c
commit 854a0634b6e4df9decc16682f59ecf66b259e1e7
Author: Father Chrysostomos <[email protected]>
Date: Fri Aug 3 12:41:11 2012 -0700
CvNAME_HEK_set
M cv.h
M op.c
M pad.c
M scope.c
commit 2d07beed7ad3186e5cf3c1febf211c085d0549b0
Author: Father Chrysostomos <[email protected]>
Date: Fri Aug 3 09:23:15 2012 -0700
Clone my subs on scope entry
The pad slot for a my sub now holds a stub with a prototype CV
attached to it by proto magic.
The prototype is cloned on scope entry. The stub in the pad is used
when cloning, so any code that references the sub before scope entry
will be able to see that stub become defined, making these behave
similarly:
our $x;
BEGIN { $x = \&foo }
sub foo { }
our $x;
my sub foo { }
BEGIN { $x = \&foo }
Constants are currently not cloned, but that may cause bugs in
pad_push. Iâll have to look into that.
On scope exit, lexical CVs go through leave_scopeâs SAVEt_CLEARSV sec-
tion, like lexical variables. If the sub is referenced elsewhere, it
is abandoned, and its proto magic is stolen and attached to a new stub
stored in the pad. If the sub is not referenced elsewhere, it is
undefined via cv_undef.
To clone my subs on scope entry, we create a sequence of introcv and
clonecv ops. See the huge comment in block_end that explains why we
need two separate ops for each CV.
To allow my subs to be defined in inner subs (my sub foo; sub { sub
foo {} }), pad_add_name_pvn and S_pad_findlex now upgrade the entry
for a my sub to a CV to begin with, so that fake entries added to pads
(fake entries are those that reference outer pads) can share the same
CV. Otherwise newMYSUB would have to add the CV to every pad that
closes over the âmy subâ declaration. newMYSUB no longer throws away
the initial value replacing it with a new one.
Prototypes are not currently visible to sub calls at compile time,
because the lexer sees the empty stub. A future commit will
solve that.
When I added name heks to CVâs I made mistakes in a few places, by not
turning on the CVf_NAMED flag, or by not clearing the field when free-
ing the hek. Those code paths were not exercised enough by state
subs, so the problems did not show up till now. So this commit fixes
those, too.
One of the tests in lexsub.t, involving foreach loops, was incorrect,
and has been fixed. Another test has been added to the end for a par-
ticular case of state subs closing over my subs that I broke when ini-
tially trying to get sibling my subs to close over each other, before
I had separate introcv and clonecv ops.
M embed.fnc
M embed.h
M op.c
M pad.c
M perly.act
M perly.h
M perly.tab
M perly.y
M pp.c
M proto.h
M scope.c
M t/cmd/lexsub.t
commit 9a5b39692b89e4ee3fed0b8f589995953f874c52
Author: Father Chrysostomos <[email protected]>
Date: Fri Aug 3 09:29:38 2012 -0700
cv_clone: panic for no pad
cv_clone has serendipitously gained the ability to clone CVs without
pads. It is not clear that we want to add this ability to this API
function, because we would be stuck supporting it, even if we came up
with a better interface. It used to crash or fail an assertion if
there was no pad.
M pad.c
commit 629f9d750dac31b47e4cd73d6dd979129abbf370
Author: Father Chrysostomos <[email protected]>
Date: Thu Aug 2 13:45:31 2012 -0700
pad.c: Let S_cv_clone clone stubs
This will be used by cv_clone_into (which does not exist yet) in a
later commit. pp_clonecv will use cv_clone_into.
Teasing out the pad-related and non-pad-related parts of cv_clone
was the easiest way to do this. Now the pad stuff is in a separate
function.
M pad.c
commit 21b5a5bcc36c71ad3bb5e028bca8b350c145327b
Author: Father Chrysostomos <[email protected]>
Date: Sun Jul 29 18:47:48 2012 -0700
op.c: Remove proto storage optimisation for lex subs
It was already #if 0âd out. This optimisation, copied from package
subs, only makes sense when there is autoloading, which lexical subs
donât do. Hence, lexical stubs will be rare indeed, so having an
optimisation for those just creates more nooks to hide bugs.
M op.c
commit 69ef84ef71e68bf1ccac5b79197776fbfefd9eed
Author: Father Chrysostomos <[email protected]>
Date: Thu Aug 2 22:11:08 2012 -0700
Add clonecv op type
This will be used for cloning a âmyâ sub on scope entry.
I was going to use pp_padcv for this, but it would end up having a
top-level if/else.
M ext/Opcode/Opcode.pm
M opcode.h
M opnames.h
M pp.c
M pp_proto.h
M regen/opcode.pl
M regen/opcodes
commit 5156d90e3494a4a64ba82570b333d2f54c51ff63
Author: Father Chrysostomos <[email protected]>
Date: Thu Jul 26 18:21:02 2012 -0700
Add introcv op type
This will be used for introducing âmyâ subs on scope entry, by turning
off the stale flag.
M ext/Opcode/Opcode.pm
M opcode.h
M opnames.h
M pp.c
M pp_proto.h
M regen/opcode.pl
M regen/opcodes
commit f4b3d7b9360dd3123e76fdf0f269220f60f18b59
Author: Father Chrysostomos <[email protected]>
Date: Thu Jul 26 12:38:14 2012 -0700
Let state sub fwd decls and nested subs work in anons
I had this working:
state sub foo;
sub other {
sub foo { # defines the state sub declared outside
...
}
}
But it failed inside an anonymous subroutine:
sub {
state sub foo;
sub other {
sub foo { # defines the state sub declared outside
...
}
}
}
When an anonymous (or otherwise clonable) sub is cloned, any state
vars, and, likewise, any state subs, inside it are cloned, too.
In the first example above the state sub forward declaration creates
a subroutine stub. The âotherâ subâs âsub fooâ declaration
creates a
pad entry in otherâs pad that closes over the outer foo immediately,
so the same stub is visible in two pads. The sub foo {} declaration
uses that stub.
When the outer sub containing the forward declaration is clonable,
the pad entry is not closed over immediately at compile time, because
the pad entry is just a prototype, not the actual value that will be
shared by the clone and its nested subs. So the inner pad entry does
not contain the sub.
So the actual creation of the sub, if it only looks at the inner
pad (otherâs pad), will not see the stub, and will not attach a
body to it.
This was the result:
$ ./miniperl -e 'CORE::state sub foo; CORE::state sub bar { sub foo {warn
called} }; foo()'
called at -e line 1.
$ ./miniperl -e 'sub { CORE::state sub foo; CORE::state sub bar { sub foo
{warn called} }; foo() }->()'
Undefined subroutine &foo called at -e line 1.
This commit fixes that by having newMYSUB follow the CvOUTSIDE chain
to find the original pad entry where it defines the sub, if the for-
ward declaration is occurs outside and has not been closed over yet.
M op.c
M t/cmd/lexsub.t
commit b472ff182876293488c0a12b3036e1eccabf969f
Author: Father Chrysostomos <[email protected]>
Date: Thu Jul 12 23:31:52 2012 -0700
Add proto magic type
This will be used for storing the prototype CV of a âmyâ sub. The
clone needs to occupy the pad entry so that padcv ops will be able to
find it. That means the clone has to displace its prototype. In case
the same sub is called recursively, we still need to be able to access
the prototype.
M mg_names.c
M mg_raw.h
M mg_vtable.h
M pod/perlguts.pod
M regen/mg_vtable.pl
commit f559593288b6f33f8590220845fe54bc7cdfe680
Author: Father Chrysostomos <[email protected]>
Date: Tue Jul 10 20:18:48 2012 -0700
First stab at my sub
This does just enough to get things to compile.
They currently do weird things in edge cases, including âBizarre
copy of CODEâ.
âmy subâ now produces a SUB token, and goes through the same grammar
rule as âstate subâ and just plain âsubâ. The separate MYSUB branch
of the barestmt rule will go soon, as it is now unused.
M op.c
M t/cmd/lexsub.t
M t/lib/croak/op
M toke.c
commit 9daf0b6225a763dfe2dc1a23b227b8c231bc31b0
Author: Father Chrysostomos <[email protected]>
Date: Mon Jul 9 22:25:24 2012 -0700
op.c:newMYSUB: Pop scope after creating sub
I was popping the scope before creating the sub in order to expose the
parent pad, where the new sub is to be stored.
That can cause problems, since ops may still be created that get
attached to the new sub. Those ops will end up using the parent subâs
slab in that case. If the parent sub does not finish compiling, due
to an error, it may clean out its slab, freeing ops that the inner sub
is using, so the inner sub, when freed, will try to free ops that are
no longer in allocated memory, as the slab is gone. Most of the time,
the inner ops wonât have been reused for anything, so the op type will
still be OP_FREED, and op_free will do nothing (except a single bad
read). But debugging builds detect that and fail an assertion.
Popping the scope afterwards actually does simplify things, surpris-
ingly enough.
I was able to produce this bug with a one-liner, but it did not fail
as part of the test suite. So this fix includes no test.
Since the o variable in newMYSUB is a padop, it can only be freed when
its pad is active. It is created before the sub, so it cannot be
freed until the scope has been popped, so it has to go at the bot-
tom. If an error occurs during newMYSUB, opslab_force_free will take
care of it.
M op.c
commit 43c317d24dda90b788fbecd6f0606f7b8ddfb502
Author: Father Chrysostomos <[email protected]>
Date: Mon Jul 9 18:02:33 2012 -0700
dump.c: Dump CvNAME_HEK
M dump.c
commit d658a2f861ba37843a9fa3a84e3bdf602dfb0ce4
Author: Father Chrysostomos <[email protected]>
Date: Mon Jul 9 13:00:28 2012 -0700
Remove & from redef warnings for lex subs
I started to write this, creating a special SV to hold the name with-
out the ampersand, but then never used that SV.
This is just for consistency with package subs.
I also made this slightly more efficient when warnings are off.
M op.c
M t/cmd/lexsub.t
commit 0016206108f57f5df21fa91f2de1a89d8be6c3a9
Author: Father Chrysostomos <[email protected]>
Date: Mon Jul 9 12:52:48 2012 -0700
lexsub.t: Fix another test
The problem with writing to-do tests is that it is very easy to get
the tests wrong, such that they continue to fail even when the prob-
lems they test for are fixed.
M t/cmd/lexsub.t
commit bc86080964f01c12247ecc74162e29bfbad7ba84
Author: Father Chrysostomos <[email protected]>
Date: Mon Jul 9 06:29:09 2012 -0700
Clone state subs in anon subs
Since state variables are not shared between closures, but only
between invocations of the same closure, state subs should behave
the same way.
This was a little tricky. When we clone a sub, we now clone inner
state subs at the same time. When walking through the pad, cloning
items, we cannot simply clone the inner sub when we see it, because it
may close over things we havenât cloned yet:
sub {
state sub foo;
my $x
sub foo { $x }
}
We canât just delay cloning it and do it afterwards, because they may
be multiple subs closing over each other:
sub {
state sub foo;
state sub bar;
sub foo { \&bar }
sub bar { \&foo }
}
So *all* the entries in the new pad must be filled before any inner
subs can be cloned.
So what we do is put a stub in place of the cloned sub. And then
in a second pass clone the inner subs, reusing the stubs from the
first pass.
M pad.c
M perly.act
M perly.h
M perly.tab
M perly.y
M t/cmd/lexsub.t
commit ff6343e61cf7a8f224dc67782d49ae46ada294fc
Author: Father Chrysostomos <[email protected]>
Date: Sun Jul 8 14:51:10 2012 -0700
perldiag: closure referents â closure references
This goes back to 2ba9eb46.
M pod/perldiag.pod
commit 4e022feaad64f3f4e1ee96cdcda3475d6a57e288
Author: Father Chrysostomos <[email protected]>
Date: Sun Jul 8 14:42:39 2012 -0700
Donât say âvariable &fooâ in warnings
It should be âsubroutine &fooâ. (It could be âsubroutine fooâ, but
we
use both forms elsewhere, and &foo is the easier to implement, the &
already being contained in the pad name.)
M pad.c
M pod/perldiag.pod
M t/cmd/lexsub.t
commit 470902f60a6fb3e6f67e68a43a081932b0047c0a
Author: Father Chrysostomos <[email protected]>
Date: Sun Jul 8 14:28:22 2012 -0700
lexsub.t: Fix some tests
I got this working a few commits ago, but the tests mentioned the
wrong sub name.
M t/cmd/lexsub.t
commit 1757be89b3953bd5cdd6d083181310c6f9f562a7
Author: Father Chrysostomos <[email protected]>
Date: Sun Jul 8 14:18:43 2012 -0700
Make pad_fixup_inner_anons cope with closed-over subs
When a sub starts being parsed, a new CV is created. When it fin-
ishes, it is stored in its final location. If there is a stub there
already, the pad is copied to the stub and the body attached thereto.
Since there may be closures inside the sub whose CvOUTSIDE
pointers point to the temporary CV used during compilation,
pad_fixup_inner_anons is called, to reassign all those
CvOUTSIDE pointers.
This happens in cases like this:
sub f;
sub f { sub { } }
When a sub closes over a lexical item in an outer sub, the inner sub
gets its own pad entry with the same value as the outer pad entry.
This means that, now that we have lexical subs (currently just state
subs), we can end up with a pad entry (&s) holding a sub whose
CvOUTSIDE does not point to the sub (f) that owns the pad:
state sub s { }
sub f { s() }
If the f sub has to reuse a stub, then pad_fixup_inner_anons gets to
see that, and complains bitterly:
$ ./perl -Ilib -E 'state sub s; sub f; sub f { s() }'
Assertion failed: (CvOUTSIDE(innercv) == old_cv), function
Perl_pad_fixup_inner_anons, file pad.c, line 2095.
Abort trap
M pad.c
M t/cmd/lexsub.t
commit 0b75d4b04cb372ffb4c1e894bf16404623c081ab
Author: Father Chrysostomos <[email protected]>
Date: Sat Jul 7 23:46:52 2012 -0700
âUndefined subroutine &foo calledâ for lex subs
instead of just âUndefined subroutine calledâ without the name.
M pp_hot.c
M t/cmd/lexsub.t
commit ab2fcd7e0caf5355fc0ac241e9bda52c4dedc1ef
Author: Father Chrysostomos <[email protected]>
Date: Sat Jul 7 23:12:20 2012 -0700
op.c:newMYSUB: Remove unused vars
M op.c
commit db998d0b9e1edb3e9d0bbd9b8c220d7b3e64d471
Author: Father Chrysostomos <[email protected]>
Date: Sat Jul 7 23:11:23 2012 -0700
op.c:newMYSUB: inline var used only once
as of the previous commit
M op.c
commit 5648cb9cc55dca59d36da5efbcac1b049b74091c
Author: Father Chrysostomos <[email protected]>
Date: Sat Jul 7 23:07:55 2012 -0700
Lexical stubs should not AUTOLOAD
There is a feature that allows stubs to fall back to their GVsâ
CVs when called. If I reference a stub, e.g., \&bar, and then
bar is autoloaded, the AUTOLOAD sub assigning *bar = *foo or
*bar = sub {...}, I can still call the stub to which I have a refer-
ence, and it will fall back to the overloaded sub.
That is all fine and dandy, but it causes any stub that references a
GV via its CvGV pointer to call that GVâs CV. If we name a lexical
sub by pointing its CvGV pointer at the GV whose name we want it to
have, then the lexical sub, if undefined, will try to fall back to an
autoloaded sub.
That causes things to gang agley in cases like this:
use 5.01;
sub foo { } # package sub
state sub foo;
foo(); # calls lexical sub; falls back to package sub
While we could fix this by flagging the sub and checking for the flag
in pp_entersub (as we do with anonymous subs), it is better simply to
use a HEK, instead of a GV. Since a GV is quite heavyweight for stor-
ing just a name, I was going to do that anyway, eventually. Doing it
now fixes a bug.
M op.c
commit 7a9ce9e32150452c1d02bef43106200a43afc759
Author: Father Chrysostomos <[email protected]>
Date: Sat Jul 7 17:35:10 2012 -0700
Allow CVs to point to HEKs rather than GVs
This will allow named lexical subs to exist independent of GVs.
M cv.h
M ext/B/B.xs
M gv.c
M pad.c
M pp.c
M sv.c
M sv.h
commit 5bc3e15e5df748cae68cdd529811b85a7fb6dd55
Author: Father Chrysostomos <[email protected]>
Date: Sat Jul 7 12:18:49 2012 -0700
Implement padcv
State subs can now be referenced and called. Most of the tests in
lexsub.t are now passing. I noticed mistakes in a couple of the
tests and corrected them. In doing so I got an assertion failure
during compilation, so the tests in question I wrapped in a skipped
string eval.
State subs are now mostly working, but there are a few things to
clean up still.
M op.c
M pp.c
M t/cmd/lexsub.t
commit 48d4b1c700473c2f632543ad55fa82e9c895b8ea
Author: Father Chrysostomos <[email protected]>
Date: Thu Jul 5 23:28:43 2012 -0700
Test state subs
Most of these tests are still to-do. The previous commit got every-
thing compiling at least. Then I went through putting eval{} around
all the dying tests and marking the failing tests as to-do.
At least this way I donât have to do everything at once (even though
that was how I wrote the tests).
About the only thing that works is constant inlining, of all things.
M t/cmd/lexsub.t
commit 7b17786e6e7ee6a06df2832e48f4bb1952473d45
Author: Father Chrysostomos <[email protected]>
Date: Fri Jul 6 23:35:15 2012 -0700
Look up state subs in the pad
This commit does just enough to get things compiling. The padcv op
is still unimplemented (in fact, converting the padany to a padcv is
still not done), so you canât actually run the code yet.
Bareword lookup in yylex now produces PRIVATEREF tokens for state
subs, so the grammar has been adjusted to accept a âsubnameâ in sub
calls (PRIVATEREF or WORD) where previously only a WORD was permitted.
M perly.act
M perly.h
M perly.tab
M perly.y
M toke.c
commit 1ecc3ff0915375e1593c5473d28c6e985f83d69c
Author: Father Chrysostomos <[email protected]>
Date: Fri Jul 6 14:31:31 2012 -0700
op.c:newMYSUB: disable stub optimisation
It will be a lot easier to get things working without this, for now.
It can be reënabled later. It might not be worth it, though, as
AUTOLOADing will ignore lexical subs, and this optimisation is mainly
for AUTOLOAD stubs that are rarely used.
M op.c
commit 2baaa350737b2ccb93f21b7ce0b56f6ea7e8d01b
Author: Father Chrysostomos <[email protected]>
Date: Thu Jul 5 23:22:21 2012 -0700
Store state subs in the pad
In making âsub fooâ respect previous âour subâ declarations in a
recent commit, I actually made âstate sub fooâ into a syntax error.
(At the time, I patched up MYSUB in perly.y to keep the tests for â"my
sub" not yet implementedâ still working.) Basically, it was creat-
ing an empty pad entry, but returning something that perly.y was not
expecting.
This commit adjusts the grammar to allow the SUB branch of barestmt to
accept a PRIVATEREF for its subname, in addition to a WORD. It reuses
the subname rule that SUB used to use (before our subs were added),
gutting it to remove the special block handling, which SUB now tokes
care of. That means the MYSUB rule will no longer turn on CvSPECIAL
on the PL_compcv that is going to be thrown away anyway.
The code for special blocks (BEGIN, END, etc.) that turns on CvSPECIAL
now checks for state subs and skips those. It only applies to our
subs and package subs.
newMYSUB has now actually been written. It basically duplicates
newATTRSUB, except for GV-specific things. It does currently vivify a
GV and set CvGV, but I am hoping to change that later. I also hope to
merge some of the code later, too.
I changed the prototype of newMYSUB to make it easier to use. It is
not used anywhere on CPAN and has always simply died, so that should
be all right.
M embed.fnc
M embed.h
M op.c
M perly.act
M perly.h
M perly.tab
M perly.y
M proto.h
commit cd8bbdb14fe0d02552270ed9643a73c640737b0a
Author: Father Chrysostomos <[email protected]>
Date: Thu Jul 5 10:41:05 2012 -0700
lexsub.t: Add test name, test override from another pkg
The bareword logic in toke.c looks up GVs in various places. This
tests that we are bypassing those correctly.
M t/cmd/lexsub.t
commit fbbb82bc51bf48f94ccf425f92b01b5d6eae95e3
Author: Father Chrysostomos <[email protected]>
Date: Wed Jul 4 23:18:32 2012 -0700
Let barewords look up our subs
These take precedence over built-in keywords (just as my $AUTOLOAD
shadows the package var), but not the keyword plugin, as the latter
takes precedence over labels, and these donât.
M t/cmd/lexsub.t
M toke.c
commit 77c9e07163f9f98e8ca4d35f5c8baaa92eee1501
Author: Father Chrysostomos <[email protected]>
Date: Wed Jul 4 14:09:46 2012 -0700
toke.c:yylex:KEY_sub can use PL_tokenbuf to begin with
There is no need to allocate a separate âtmpbufâ and then copy it into
PL_tokenbuf afterwards.
M toke.c
commit dad6246e5cda1528f8110ce129dcc336e08f068b
Author: Father Chrysostomos <[email protected]>
Date: Wed Jul 4 09:13:17 2012 -0700
Make âsub foo{}â respect âour fooâ
This commit switches all sub definitions, whether with âourâ or not,
to using S_force_ident_maybe_lex (formerly known as S_pending_ident).
This means that an unqualified (no our/my/state or package prefix)
âsub fooâ declaration does a pad lookup, just like $foo.
It turns out that the vivification that I added to the then
S_pending_ident for CVs was unnecessary and actually buggy. We
*donât* want to autovivify GVs for CVs, because they might be con-
stants or forward declarations, which are stored in a simpler form.
I also had to change the subname rule used by MYSUB in perly.y, since
it can now be fed a PRIVATEREF, which it does not expect. This may
prove to be temporary, but it keeps current tests passing.
M perly.act
M perly.h
M perly.tab
M perly.y
M t/cmd/lexsub.t
M toke.c
commit f707cb7af47d02aa2f4b4bc39131b7023d76208a
Author: Father Chrysostomos <[email protected]>
Date: Wed Jul 4 00:17:55 2012 -0700
Fix our sub with proto
yylex must emit exactly one token each time it is called. Some-
times yylex needs to parse several tokens at once. Thatâs what
the various force functions are for. But that is also what
PL_pending_ident is for.
The various force_next, force_word, force_ident, etc., functions keep
a stack of tokens (PL_nextval/PL_nexttype) that yylex will check imme-
diately when called.
PL_pending_ident is used to track a single identifier that yylex will
hand off to S_pending_ident to handle.
S_pending_ident is the only piece of code for resolving an identi-
fier that could be lexical but could also be a package variable.
force_ident assumes it is looking for a package variable.
force_* takes precedence over PL_pending_ident.
All this means that, if an identifier needs to be looked up in the pad
on the next yylex invocation, it has to use PL_pending_ident, and the
force_* functions cannot be used at the same time.
Not realising that, when I made âour sub fooâ store the sub in the
pad I also made âour sub foo ($)â into a syntax error, because it
was being parsed as âour sub ($) fooâ (the prototype being
âforcedâ);
i.e., the pending tokens were being pulled out of the âqueueâ in the
wrong order. (I put queue in quotes, because one queue and one unre-
lated buffer together donât exactly count as âa queueâ.)
Changing PL_pending_ident to have precedence over the force stack
breaks ext/XS-APItest/t/swaptwostmts.t, because the statement-parsing
interface does not localise PL_pending_ident. It could be changed to
do that, but I donât think it is the right solution.
Having two separate pending token mechanisms makes things need-
lessly fragile.
This commit eliminates the PL_pending_ident mechanism and
modifies S_pending_ident (renaming it in the process to
S_force_ident_maybe_lex) to work with the force mechanism. I was
going to merge it with force_ident, but the two make incompatible
assumptions that just complicate the code if merged. S_pending_ident
needs the sigil in the same string buffer, to pass to the pad inter-
face. force_ident needs to be able to work without a sigil present.
So now we only have one queue for pending tokens and the order is more
predictable.
M embed.fnc
M parser.h
M proto.h
M sv.c
M t/cmd/lexsub.t
M toke.c
commit 178e797206a9ffc13fcbe3917d21c9af9855a5f5
Author: Father Chrysostomos <[email protected]>
Date: Mon Jul 2 21:26:13 2012 -0700
Make do sub() respect our declarations
M t/cmd/lexsub.t
M toke.c
commit 9a5f3c046f78943e0f716d772dfe7342966b9e20
Author: Father Chrysostomos <[email protected]>
Date: Mon Jul 2 12:29:48 2012 -0700
lexsub.t: Fix a test
This is not testing what I meant it to test: that âsub dâ will respect
a preceding âour sub d;â. If âsub dâ is in the same package, it
makes
no difference, so the test tests nothing.
It turns out this does not work yet.
M t/cmd/lexsub.t
commit a8a4d051f794d768908de6382b9fc213ec110406
Author: Father Chrysostomos <[email protected]>
Date: Mon Jul 2 09:07:31 2012 -0700
Use test.pl in lexsub.t
I thought cmd/ couldnât use test.pl, but was mistaken.
M t/cmd/lexsub.t
commit d813b20ae21dd4c5df019b7363f8fffba9913757
Author: Father Chrysostomos <[email protected]>
Date: Sun Jul 1 22:53:41 2012 -0700
Make &foo respect our sub
This changes &foo to go through S_pending_ident (by setting
PL_pending_ident, which causes yylex to defer to S_pending_ident for
the next token) the way $foo and %foo do.
This necessitated reducing the maximum identifier length of &foo from
252 to 251, making it match @foo, $foo, etc. So somebodyâs JAPH might
break. :-)
M MANIFEST
A t/cmd/lexsub.t
M t/comp/parser.t
M toke.c
commit e6576eda4d63bb5a6e7f85893a2cee8fbc0b4838
Author: Father Chrysostomos <[email protected]>
Date: Sat Jun 30 23:20:25 2012 -0700
Allocate âour subâ in the pad
Currently the name is only allocated there. Nothing fetches it yet.
Notes on the implementation:
S_pending_ident contains the logic for determining whether $foo or
@foo refers to a lexical or package variable.
yylex defers to S_pending_ident if PL_pending_ident is set.
The KEY_sub case in yylex is changed to set PL_pending_ident instead
of using force_word. For package variables (including our),
S_pending_ident returns a WORD token, which is the same thing that
force_word produces. So *that* aspect of this change does not affect
the grammar. However....
The barestmt ruleâs SUB branch begins with âSUB startsub subnameâ.
startsub is a null rule that creates a new sub in PL_compcv via
start_subparse(). subname is defined in terms of WORD and also checks
whether this is a special block, turning on CvSPECIAL(PL_compcv) if
it is. That flag has to be visible during compilation of the sub.
But for a lexical name, such as âour fooâ, to be allocated in the
right pad, it has to come *before* startsub, i.e., âSUB subname
startsubâ.
But subname needs to modify the sub that startsub created, set-
ting the flag.
So I copied (not moved, because MYSUB still uses it) the name-checking
code from the subname rule into the SUB branch of barestmt. Now that
uses WORD directly instead of invoking subname. That allows the code
there to set everything up in the right order.
M perly.act
M perly.h
M perly.tab
M perly.y
M toke.c
commit e258b01f466a7bc7e75e2dad8e7844e9ddf7e79c
Author: Father Chrysostomos <[email protected]>
Date: Sat Jun 30 23:00:11 2012 -0700
Add padcv to Opcode.pm
M ext/Opcode/Opcode.pm
commit 9ceb43843b17475e9cc0308ea6c1ecb60570928e
Author: Father Chrysostomos <[email protected]>
Date: Sat Jun 30 22:29:28 2012 -0700
padcv op type
M opcode.h
M opnames.h
M pp.c
M pp_proto.h
M regen/opcodes
commit bf979f5ec3956d94d0a525a840c85c8ceb3db051
Author: Father Chrysostomos <[email protected]>
Date: Sat Jun 30 17:31:32 2012 -0700
Donât allow name after our/state sub
It was a mistake that this was ever allowed.
M pod/perldiag.pod
M t/lib/croak/toke
M toke.c
-----------------------------------------------------------------------
--
Perl5 Master Repository