diff options
author | Father Chrysostomos <sprout@cpan.org> | 2012-08-03 09:23:15 -0700 |
---|---|---|
committer | Father Chrysostomos <sprout@cpan.org> | 2012-09-15 22:45:05 -0700 |
commit | 6d5c21479838db78689e08afd075ef4e9100ef0d (patch) | |
tree | 44db00c7bbbae895f1e3208ffcd3a43b719373cb /perly.tab | |
parent | fead5351141134064bc3069932e04930bd96eb0e (diff) | |
download | perl-6d5c21479838db78689e08afd075ef4e9100ef0d.tar.gz |
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.
Diffstat (limited to 'perly.tab')
-rw-r--r-- | perly.tab | 42 |
1 files changed, 21 insertions, 21 deletions
@@ -183,26 +183,26 @@ static const yytype_uint16 yyrline[] = 0, 141, 141, 140, 150, 149, 159, 158, 171, 170, 183, 182, 195, 194, 206, 216, 226, 229, 239, 244, 245, 255, 256, 265, 273, 277, 284, 293, 295, 300, - 318, 317, 365, 377, 393, 392, 409, 418, 427, 438, - 440, 442, 452, 462, 483, 492, 501, 510, 517, 516, - 533, 539, 549, 573, 574, 579, 581, 583, 587, 591, - 595, 599, 604, 610, 611, 617, 631, 632, 641, 647, - 648, 653, 656, 660, 665, 669, 673, 677, 678, 682, - 688, 693, 698, 699, 704, 705, 710, 711, 715, 725, - 729, 739, 740, 750, 754, 758, 762, 766, 776, 785, - 789, 794, 801, 810, 816, 822, 830, 834, 841, 840, - 851, 852, 856, 865, 870, 878, 885, 892, 902, 911, - 918, 927, 934, 940, 947, 952, 962, 966, 970, 976, - 980, 984, 988, 992, 996, 1000, 1012, 1016, 1020, 1024, - 1034, 1038, 1045, 1049, 1053, 1058, 1063, 1068, 1077, 1082, - 1087, 1093, 1099, 1110, 1114, 1118, 1130, 1143, 1151, 1163, - 1164, 1165, 1166, 1167, 1172, 1176, 1178, 1182, 1187, 1189, - 1194, 1196, 1198, 1200, 1202, 1204, 1206, 1215, 1226, 1228, - 1230, 1235, 1248, 1253, 1258, 1262, 1266, 1270, 1274, 1278, - 1282, 1286, 1288, 1291, 1295, 1301, 1303, 1308, 1311, 1320, - 1327, 1326, 1342, 1343, 1344, 1350, 1354, 1362, 1369, 1374, - 1379, 1381, 1383, 1388, 1390, 1395, 1396, 1402, 1406, 1412, - 1418, 1424, 1430, 1436, 1443, 1445, 1447, 1450 + 318, 317, 367, 379, 395, 394, 411, 420, 429, 440, + 442, 444, 454, 464, 485, 494, 503, 512, 519, 518, + 535, 541, 551, 575, 576, 581, 583, 585, 589, 593, + 597, 601, 606, 612, 613, 619, 633, 634, 643, 649, + 650, 655, 658, 662, 667, 671, 675, 679, 680, 684, + 690, 695, 700, 701, 706, 707, 712, 713, 717, 727, + 731, 741, 742, 752, 756, 760, 764, 768, 778, 787, + 791, 796, 803, 812, 818, 824, 832, 836, 843, 842, + 853, 854, 858, 867, 872, 880, 887, 894, 904, 913, + 920, 929, 936, 942, 949, 954, 964, 968, 972, 978, + 982, 986, 990, 994, 998, 1002, 1014, 1018, 1022, 1026, + 1036, 1040, 1047, 1051, 1055, 1060, 1065, 1070, 1079, 1084, + 1089, 1095, 1101, 1112, 1116, 1120, 1132, 1145, 1153, 1165, + 1166, 1167, 1168, 1169, 1174, 1178, 1180, 1184, 1189, 1191, + 1196, 1198, 1200, 1202, 1204, 1206, 1208, 1217, 1228, 1230, + 1232, 1237, 1250, 1255, 1260, 1264, 1268, 1272, 1276, 1280, + 1284, 1288, 1290, 1293, 1297, 1303, 1305, 1310, 1313, 1322, + 1329, 1328, 1344, 1345, 1346, 1352, 1356, 1364, 1371, 1376, + 1381, 1383, 1385, 1390, 1392, 1397, 1398, 1404, 1408, 1414, + 1420, 1426, 1432, 1438, 1445, 1447, 1449, 1452 }; #endif @@ -1113,6 +1113,6 @@ static const toketypes yy_type_tab[] = }; /* Generated from: - * 38ce4bf3d0e9f8cfd35795d89907c7d03583b561b55406230d749c80d62d5e06 perly.y + * 22767f994fcf1e0f0dfc8c69fd8218ca01b59a2ba367fa36181bfaa804e8af87 perly.y * 4a3ced51fe6585f6ec59e65e1ffd74bc976c498b0e6992eaab337219fee72e51 regen_perly.pl * ex: set ro: */ |