diff options
author | Father Chrysostomos <sprout@cpan.org> | 2012-07-05 23:22:21 -0700 |
---|---|---|
committer | Father Chrysostomos <sprout@cpan.org> | 2012-09-15 22:44:57 -0700 |
commit | 5027875589574a2ca6c9fb86193d4c8f720ef004 (patch) | |
tree | 3e9dd7504ca98c4a28c71ba1baf65747cc4d2e0d /perly.y | |
parent | f37b842aabb9fad0fb5fe0a4803f30c6ead59c74 (diff) | |
download | perl-5027875589574a2ca6c9fb86193d4c8f720ef004.tar.gz |
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.
Diffstat (limited to 'perly.y')
-rw-r--r-- | perly.y | 27 |
1 files changed, 16 insertions, 11 deletions
@@ -314,12 +314,16 @@ barestmt: PLUGSTMT pad_add_anon(fmtcv, OP_NULL); } } - | SUB WORD startsub - { const char *const name = SvPV_nolen_const(((SVOP*)$2)->op_sv); - if (strEQ(name, "BEGIN") || strEQ(name, "END") + | SUB subname startsub + { + if ($2->op_type == OP_CONST) { + const char *const name = + SvPV_nolen_const(((SVOP*)$2)->op_sv); + if (strEQ(name, "BEGIN") || strEQ(name, "END") || strEQ(name, "INIT") || strEQ(name, "CHECK") || strEQ(name, "UNITCHECK")) CvSPECIAL_on(PL_compcv); + } PL_parser->in_my = 0; PL_parser->in_my_stash = NULL; } @@ -329,7 +333,13 @@ barestmt: PLUGSTMT #ifdef MAD { OP* o = newSVOP(OP_ANONCODE, 0, - (SV*)newATTRSUB($3, $2, $5, $6, $7)); + (SV*)( +#endif + $2->op_type == OP_CONST + ? newATTRSUB($3, $2, $5, $6, $7) + : newMYSUB($3, $2, $5, $6, $7) +#ifdef MAD + )); $$ = newOP(OP_NULL,0); op_getmad(o,$$,'&'); op_getmad($2,$$,'n'); @@ -340,7 +350,7 @@ barestmt: PLUGSTMT $7->op_madprop = 0; } #else - newATTRSUB($3, $2, $5, $6, $7); + ; $$ = (OP*)NULL; #endif intro_my(); @@ -678,12 +688,7 @@ startformsub: /* NULL */ /* start a format subroutine scope */ ; /* Name of a subroutine - must be a bareword, could be special */ -subname : WORD { const char *const name = SvPV_nolen_const(((SVOP*)$1)->op_sv); - if (strEQ(name, "BEGIN") || strEQ(name, "END") - || strEQ(name, "INIT") || strEQ(name, "CHECK") - || strEQ(name, "UNITCHECK")) - CvSPECIAL_on(PL_compcv); - $$ = $1; } +subname : WORD | PRIVATEREF ; |