Last-Modified: Fri, 03 Oct 2025 21:26:00 GMT Expires: Mon, 01 Oct 2035 21:26:00 GMT cpython.git - https://github.com/python/cpython.git
summaryrefslogtreecommitdiffstats
path: root/Python/graminit.c
blob: a8af5833a9af2fdc5a8fa3ec85ac6aac8361726a (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
1001
1002
1003
1004
1005
1006
1007
1008
1009
1010
1011
1012
1013
1014
1015
1016
1017
1018
1019
1020
1021
1022
1023
1024
1025
1026
1027
1028
1029
1030
1031
1032
1033
1034
1035
1036
1037
1038
1039
1040
1041
1042
1043
1044
1045
1046
1047
1048
1049
1050
1051
1052
1053
1054
1055
1056
1057
1058
1059
1060
1061
1062
1063
1064
1065
1066
1067
1068
1069
1070
1071
1072
1073
1074
1075
1076
1077
1078
1079
1080
1081
1082
1083
1084
1085
1086
1087
1088
1089
1090
1091
1092
1093
1094
1095
1096
1097
1098
1099
1100
1101
1102
1103
1104
1105
1106
1107
1108
1109
1110
1111
1112
1113
1114
1115
1116
1117
1118
1119
1120
1121
1122
1123
1124
1125
1126
1127
1128
1129
1130
1131
1132
1133
1134
1135
1136
1137
1138
1139
1140
1141
1142
1143
1144
1145
1146
1147
1148
1149
1150
1151
1152
1153
1154
1155
1156
1157
1158
1159
1160
1161
1162
1163
1164
1165
1166
1167
1168
1169
1170
1171
1172
1173
1174
1175
1176
1177
1178
1179
1180
1181
1182
1183
1184
1185
1186
1187
1188
1189
1190
1191
1192
1193
1194
1195
1196
1197
1198
1199
1200
1201
1202
1203
1204
1205
1206
1207
1208
1209
1210
1211
1212
1213
1214
1215
1216
1217
1218
1219
1220
1221
1222
1223
1224
1225
1226
1227
1228
1229
1230
1231
1232
1233
1234
1235
1236
1237
1238
1239
1240
1241
1242
1243
1244
1245
1246
1247
1248
1249
1250
1251
1252
1253
1254
1255
1256
1257
1258
1259
1260
1261
1262
1263
1264
1265
1266
1267
1268
1269
1270
1271
1272
1273
1274
1275
1276
1277
1278
1279
1280
1281
1282
1283
1284
1285
1286
1287
1288
1289
1290
1291
1292
1293
1294
1295
1296
1297
1298
1299
1300
1301
1302
1303
1304
1305
1306
1307
1308
1309
1310
1311
1312
1313
1314
1315
1316
1317
1318
1319
1320
1321
1322
1323
1324
1325
1326
1327
1328
1329
1330
1331
1332
1333
1334
1335
1336
1337
1338
1339
1340
1341
1342
1343
1344
1345
1346
1347
1348
1349
1350
1351
1352
1353
1354
1355
1356
1357
1358
1359
1360
1361
1362
1363
1364
1365
1366
1367
1368
1369
1370
1371
1372
1373
1374
1375
1376
1377
1378
1379
1380
1381
1382
1383
1384
1385
1386
1387
1388
1389
1390
1391
1392
1393
1394
1395
1396
1397
1398
1399
1400
1401
1402
1403
1404
1405
1406
1407
1408
1409
1410
1411
1412
1413
1414
1415
1416
1417
1418
1419
1420
1421
1422
1423
1424
1425
1426
1427
1428
1429
1430
1431
1432
1433
1434
1435
1436
1437
1438
1439
1440
1441
1442
1443
1444
1445
1446
1447
1448
1449
1450
1451
1452
1453
1454
1455
1456
1457
1458
1459
1460
1461
1462
1463
1464
1465
1466
1467
1468
1469
1470
1471
1472
1473
1474
1475
1476
1477
1478
1479
1480
1481
1482
1483
1484
1485
1486
1487
1488
1489
1490
1491
1492
1493
1494
1495
1496
1497
1498
1499
1500
1501
1502
1503
1504
1505
1506
1507
1508
1509
1510
1511
1512
1513
1514
1515
1516
1517
1518
1519
1520
1521
1522
1523
1524
1525
1526
1527
1528
1529
1530
1531
1532
1533
1534
1535
1536
1537
1538
1539
1540
1541
1542
1543
1544
1545
1546
1547
1548
1549
1550
1551
1552
1553
1554
1555
1556
1557
1558
1559
1560
1561
1562
1563
1564
1565
1566
1567
1568
1569
1570
1571
1572
1573
1574
1575
1576
1577
1578
1579
1580
1581
1582
1583
1584
1585
1586
1587
1588
1589
1590
1591
1592
1593
1594
1595
1596
1597
1598
1599
1600
1601
1602
1603
1604
1605
1606
1607
1608
1609
1610
1611
1612
1613
1614
1615
1616
1617
1618
1619
1620
1621
1622
1623
1624
1625
1626
1627
1628
1629
1630
1631
1632
1633
1634
1635
1636
1637
1638
1639
1640
1641
1642
1643
1644
1645
1646
1647
1648
1649
1650
1651
1652
1653
1654
1655
1656
1657
1658
1659
1660
1661
1662
1663
1664
1665
1666
1667
1668
1669
1670
1671
1672
1673
1674
1675
1676
1677
1678
1679
1680
1681
1682
1683
1684
1685
1686
1687
1688
1689
1690
1691
1692
1693
1694
1695
1696
1697
1698
1699
1700
1701
1702
1703
1704
1705
1706
1707
1708
1709
1710
1711
1712
1713
1714
1715
1716
1717
1718
1719
1720
1721
1722
1723
1724
1725
1726
1727
1728
1729
1730
1731
1732
1733
1734
1735
1736
1737
1738
1739
1740
1741
1742
1743
1744
1745
1746
1747
1748
1749
1750
1751
1752
1753
1754
1755
1756
1757
1758
1759
1760
1761
1762
1763
1764
1765
1766
1767
1768
1769
1770
1771
1772
1773
1774
1775
1776
1777
1778
1779
1780
1781
1782
1783
1784
1785
1786
1787
1788
1789
1790
1791
1792
1793
1794
1795
1796
1797
1798
1799
1800
1801
1802
1803
1804
1805
1806
1807
1808
1809
1810
1811
1812
1813
1814
1815
1816
1817
1818
1819
1820
1821
1822
1823
1824
1825
1826
1827
1828
1829
1830
1831
1832
1833
1834
1835
1836
1837
1838
1839
1840
1841
1842
1843
1844
1845
1846
1847
1848
1849
1850
1851
1852
1853
1854
1855
1856
1857
1858
1859
1860
1861
1862
1863
1864
1865
1866
1867
1868
1869
1870
1871
1872
1873
1874
1875
1876
1877
1878
1879
1880
1881
1882
1883
1884
1885
1886
1887
1888
1889
1890
1891
1892
1893
1894
1895
1896
1897
1898
1899
1900
1901
1902
1903
1904
1905
1906
1907
1908
1909
1910
1911
1912
1913
1914
1915
1916
1917
1918
1919
1920
1921
1922
1923
1924
1925
1926
1927
1928
1929
1930
1931
1932
1933
1934
1935
1936
1937
1938
1939
1940
1941
1942
1943
1944
1945
1946
1947
1948
1949
1950
1951
1952
1953
1954
1955
1956
1957
1958
1959
1960
1961
1962
1963
1964
1965
1966
1967
1968
1969
1970
1971
1972
1973
1974
1975
1976
1977
1978
1979
1980
1981
1982
1983
1984
1985
1986
1987
1988
1989
1990
1991
1992
1993
1994
1995
1996
1997
1998
1999
2000
2001
2002
2003
2004
2005
2006
2007
2008
2009
2010
2011
2012
2013
2014
2015
2016
2017
2018
2019
2020
2021
2022
2023
2024
2025
2026
2027
2028
2029
2030
2031
2032
2033
2034
2035
2036
2037
2038
2039
2040
2041
2042
2043
2044
2045
2046
2047
2048
2049
2050
2051
2052
2053
2054
2055
2056
2057
2058
2059
2060
2061
2062
2063
2064
2065
2066
2067
2068
2069
2070
2071
2072
2073
2074
2075
2076
2077
2078
2079
2080
2081
2082
2083
2084
2085
2086
2087
2088
2089
2090
2091
2092
2093
2094
2095
2096
2097
2098
2099
2100
2101
2102
2103
2104
2105
2106
2107
2108
2109
2110
2111
2112
2113
2114
2115
2116
2117
2118
2119
2120
2121
2122
2123
2124
2125
2126
2127
2128
2129
2130
2131
2132
2133
2134
2135
2136
2137
2138
2139
2140
2141
2142
2143
2144
/* Generated by Parser/pgen */

#include "pgenheaders.h"
#include "grammar.h"
PyAPI_DATA(grammar) _PyParser_Grammar;
static arc arcs_0_0[3] = {
    {2, 1},
    {3, 1},
    {4, 2},
};
static arc arcs_0_1[1] = {
    {0, 1},
};
static arc arcs_0_2[1] = {
    {2, 1},
};
static state states_0[3] = {
    {3, arcs_0_0},
    {1, arcs_0_1},
    {1, arcs_0_2},
};
static arc arcs_1_0[3] = {
    {2, 0},
    {6, 0},
    {7, 1},
};
static arc arcs_1_1[1] = {
    {0, 1},
};
static state states_1[2] = {
    {3, arcs_1_0},
    {1, arcs_1_1},
};
static arc arcs_2_0[1] = {
    {9, 1},
};
static arc arcs_2_1[2] = {
    {2, 1},
    {7, 2},
};
static arc arcs_2_2[1] = {
    {0, 2},
};
static state states_2[3] = {
    {1, arcs_2_0},
    {2, arcs_2_1},
    {1, arcs_2_2},
};
static arc arcs_3_0[1] = {
    {11, 1},
};
static arc arcs_3_1[1] = {
    {12, 2},
};
static arc arcs_3_2[2] = {
    {13, 3},
    {2, 4},
};
static arc arcs_3_3[2] = {
    {14, 5},
    {15, 6},
};
static arc arcs_3_4[1] = {
    {0, 4},
};
static arc arcs_3_5[1] = {
    {15, 6},
};
static arc arcs_3_6[1] = {
    {2, 4},
};
static state states_3[7] = {
    {1, arcs_3_0},
    {1, arcs_3_1},
    {2, arcs_3_2},
    {2, arcs_3_3},
    {1, arcs_3_4},
    {1, arcs_3_5},
    {1, arcs_3_6},
};
static arc arcs_4_0[1] = {
    {10, 1},
};
static arc arcs_4_1[2] = {
    {10, 1},
    {0, 1},
};
static state states_4[2] = {
    {1, arcs_4_0},
    {2, arcs_4_1},
};
static arc arcs_5_0[1] = {
    {16, 1},
};
static arc arcs_5_1[2] = {
    {18, 2},
    {19, 2},
};
static arc arcs_5_2[1] = {
    {0, 2},
};
static state states_5[3] = {
    {1, arcs_5_0},
    {2, arcs_5_1},
    {1, arcs_5_2},
};
static arc arcs_6_0[1] = {
    {20, 1},
};
static arc arcs_6_1[1] = {
    {21, 2},
};
static arc arcs_6_2[1] = {
    {22, 3},
};
static arc arcs_6_3[2] = {
    {23, 4},
    {25, 5},
};
static arc arcs_6_4[1] = {
    {24, 6},
};
static arc arcs_6_5[1] = {
    {26, 7},
};
static arc arcs_6_6[1] = {
    {25, 5},
};
static arc arcs_6_7[1] = {
    {0, 7},
};
static state states_6[8] = {
    {1, arcs_6_0},
    {1, arcs_6_1},
    {1, arcs_6_2},
    {2, arcs_6_3},
    {1, arcs_6_4},
    {1, arcs_6_5},
    {1, arcs_6_6},
    {1, arcs_6_7},
};
static arc arcs_7_0[1] = {
    {13, 1},
};
static arc arcs_7_1[2] = {
    {27, 2},
    {15, 3},
};
static arc arcs_7_2[1] = {
    {15, 3},
};
static arc arcs_7_3[1] = {
    {0, 3},
};
static state states_7[4] = {
    {1, arcs_7_0},
    {2, arcs_7_1},
    {1, arcs_7_2},
    {1, arcs_7_3},
};
static arc arcs_8_0[3] = {
    {28, 1},
    {31, 2},
    {32, 3},
};
static arc arcs_8_1[3] = {
    {29, 4},
    {30, 5},
    {0, 1},
};
static arc arcs_8_2[3] = {
    {28, 6},
    {30, 7},
    {0, 2},
};
static arc arcs_8_3[1] = {
    {28, 8},
};
static arc arcs_8_4[1] = {
    {24, 9},
};
static arc arcs_8_5[4] = {
    {28, 10},
    {31, 11},
    {32, 3},
    {0, 5},
};
static arc arcs_8_6[2] = {
    {30, 7},
    {0, 6},
};
static arc arcs_8_7[2] = {
    {28, 12},
    {32, 3},
};
static arc arcs_8_8[1] = {
    {0, 8},
};
static arc arcs_8_9[2] = {
    {30, 5},
    {0, 9},
};
static arc arcs_8_10[3] = {
    {30, 5},
    {29, 4},
    {0, 10},
};
static arc arcs_8_11[3] = {
    {28, 13},
    {30, 14},
    {0, 11},
};
static arc arcs_8_12[3] = {
    {30, 7},
    {29, 15},
    {0, 12},
};
static arc arcs_8_13[2] = {
    {30, 14},
    {0, 13},
};
static arc arcs_8_14[2] = {
    {28, 16},
    {32, 3},
};
static arc arcs_8_15[1] = {
    {24, 6},
};
static arc arcs_8_16[3] = {
    {30, 14},
    {29, 17},
    {0, 16},
};
static arc arcs_8_17[1] = {
    {24, 13},
};
static state states_8[18] = {
    {3, arcs_8_0},
    {3, arcs_8_1},
    {3, arcs_8_2},
    {1, arcs_8_3},
    {1, arcs_8_4},
    {4, arcs_8_5},
    {2, arcs_8_6},
    {2, arcs_8_7},
    {1, arcs_8_8},
    {2, arcs_8_9},
    {3, arcs_8_10},
    {3, arcs_8_11},
    {3, arcs_8_12},
    {2, arcs_8_13},
    {2, arcs_8_14},
    {1, arcs_8_15},
    {3, arcs_8_16},
    {1, arcs_8_17},
};
static arc arcs_9_0[1] = {
    {21, 1},
};
static arc arcs_9_1[2] = {
    {25, 2},
    {0, 1},
};
static arc arcs_9_2[1] = {
    {24, 3},
};
static arc arcs_9_3[1] = {
    {0, 3},
};
static state states_9[4] = {
    {1, arcs_9_0},
    {2, arcs_9_1},
    {1, arcs_9_2},
    {1, arcs_9_3},
};
static arc arcs_10_0[3] = {
    {34, 1},
    {31, 2},
    {32, 3},
};
static arc arcs_10_1[3] = {
    {29, 4},
    {30, 5},
    {0, 1},
};
static arc arcs_10_2[3] = {
    {34, 6},
    {30, 7},
    {0, 2},
};
static arc arcs_10_3[1] = {
    {34, 8},
};
static arc arcs_10_4[1] = {
    {24, 9},
};
static arc arcs_10_5[4] = {
    {34, 10},
    {31, 11},
    {32, 3},
    {0, 5},
};
static arc arcs_10_6[2] = {
    {30, 7},
    {0, 6},
};
static arc arcs_10_7[2] = {
    {34, 12},
    {32, 3},
};
static arc arcs_10_8[1] = {
    {0, 8},
};
static arc arcs_10_9[2] = {
    {30, 5},
    {0, 9},
};
static arc arcs_10_10[3] = {
    {30, 5},
    {29, 4},
    {0, 10},
};
static arc arcs_10_11[3] = {
    {34, 13},
    {30, 14},
    {0, 11},
};
static arc arcs_10_12[3] = {
    {30, 7},
    {29, 15},
    {0, 12},
};
static arc arcs_10_13[2] = {
    {30, 14},
    {0, 13},
};
static arc arcs_10_14[2] = {
    {34, 16},
    {32, 3},
};
static arc arcs_10_15[1] = {
    {24, 6},
};
static arc arcs_10_16[3] = {
    {30, 14},
    {29, 17},
    {0, 16},
};
static arc arcs_10_17[1] = {
    {24, 13},
};
static state states_10[18] = {
    {3, arcs_10_0},
    {3, arcs_10_1},
    {3, arcs_10_2},
    {1, arcs_10_3},
    {1, arcs_10_4},
    {4, arcs_10_5},
    {2, arcs_10_6},
    {2, arcs_10_7},
    {1, arcs_10_8},
    {2, arcs_10_9},
    {3, arcs_10_10},
    {3, arcs_10_11},
    {3, arcs_10_12},
    {2, arcs_10_13},
    {2, arcs_10_14},
    {1, arcs_10_15},
    {3, arcs_10_16},
    {1, arcs_10_17},
};
static arc arcs_11_0[1] = {
    {21, 1},
};
static arc arcs_11_1[1] = {
    {0, 1},
};
static state states_11[2] = {
    {1, arcs_11_0},
    {1, arcs_11_1},
};
static arc arcs_12_0[2] = {
    {3, 1},
    {4, 1},
};
static arc arcs_12_1[1] = {
    {0, 1},
};
static state states_12[2] = {
    {2, arcs_12_0},
    {1, arcs_12_1},
};
static arc arcs_13_0[1] = {
    {35, 1},
};
static arc arcs_13_1[2] = {
    {36, 2},
    {2, 3},
};
static arc arcs_13_2[2] = {
    {35, 1},
    {2, 3},
};
static arc arcs_13_3[1] = {
    {0, 3},
};
static state states_13[4] = {
    {1, arcs_13_0},
    {2, arcs_13_1},
    {2, arcs_13_2},
    {1, arcs_13_3},
};
static arc arcs_14_0[8] = {
    {37, 1},
    {38, 1},
    {39, 1},
    {40, 1},
    {41, 1},
    {42, 1},
    {43, 1},
    {44, 1},
};
static arc arcs_14_1[1] = {
    {0, 1},
};
static state states_14[2] = {
    {8, arcs_14_0},
    {1, arcs_14_1},
};
static arc arcs_15_0[1] = {
    {45, 1},
};
static arc arcs_15_1[3] = {
    {46, 2},
    {29, 3},
    {0, 1},
};
static arc arcs_15_2[2] = {
    {47, 4},
    {9, 4},
};
static arc arcs_15_3[2] = {
    {47, 5},
    {45, 5},
};
static arc arcs_15_4[1] = {
    {0, 4},
};
static arc arcs_15_5[2] = {
    {29, 3},
    {0, 5},
};
static state states_15[6] = {
    {1, arcs_15_0},
    {3, arcs_15_1},
    {2, arcs_15_2},
    {2, arcs_15_3},
    {1, arcs_15_4},
    {2, arcs_15_5},
};
static arc arcs_16_0[2] = {
    {24, 1},
    {48, 1},
};
static arc arcs_16_1[2] = {
    {30, 2},
    {0, 1},
};
static arc arcs_16_2[3] = {
    {24, 1},
    {48, 1},
    {0, 2},
};
static state states_16[3] = {
    {2, arcs_16_0},
    {2, arcs_16_1},
    {3, arcs_16_2},
};
static arc arcs_17_0[12] = {
    {49, 1},
    {50, 1},
    {51, 1},
    {52, 1},
    {53, 1},
    {54, 1},
    {55, 1},
    {56, 1},
    {57, 1},
    {58, 1},
    {59, 1},
    {60, 1},
};
static arc arcs_17_1[1] = {
    {0, 1},
};
static state states_17[2] = {
    {12, arcs_17_0},
    {1, arcs_17_1},
};
static arc arcs_18_0[1] = {
    {61, 1},
};
static arc arcs_18_1[1] = {
    {62, 2},
};
static arc arcs_18_2[1] = {
    {0, 2},
};
static state states_18[3] = {
    {1, arcs_18_0},
    {1, arcs_18_1},
    {1, arcs_18_2},
};
static arc arcs_19_0[1] = {
    {63, 1},
};
static arc arcs_19_1[1] = {
    {0, 1},
};
static state states_19[2] = {
    {1, arcs_19_0},
    {1, arcs_19_1},
};
static arc arcs_20_0[5] = {
    {64, 1},
    {65, 1},
    {66, 1},
    {67, 1},
    {68, 1},
};
static arc arcs_20_1[1] = {
    {0, 1},
};
static state states_20[2] = {
    {5, arcs_20_0},
    {1, arcs_20_1},
};
static arc arcs_21_0[1] = {
    {69, 1},
};
static arc arcs_21_1[1] = {
    {0, 1},
};
static state states_21[2] = {
    {1, arcs_21_0},
    {1, arcs_21_1},
};
static arc arcs_22_0[1] = {
    {70, 1},
};
static arc arcs_22_1[1] = {
    {0, 1},
};
static state states_22[2] = {
    {1, arcs_22_0},
    {1, arcs_22_1},
};
static arc arcs_23_0[1] = {
    {71, 1},
};
static arc arcs_23_1[2] = {
    {9, 2},
    {0, 1},
};
static arc arcs_23_2[1] = {
    {0, 2},
};
static state states_23[3] = {
    {1, arcs_23_0},
    {2, arcs_23_1},
    {1, arcs_23_2},
};
static arc arcs_24_0[1] = {
    {47, 1},
};
static arc arcs_24_1[1] = {
    {0, 1},
};
static state states_24[2] = {
    {1, arcs_24_0},
    {1, arcs_24_1},
};
static arc arcs_25_0[1] = {
    {72, 1},
};
static arc arcs_25_1[2] = {
    {24, 2},
    {0, 1},
};
static arc arcs_25_2[2] = {
    {73, 3},
    {0, 2},
};
static arc arcs_25_3[1] = {
    {24, 4},
};
static arc arcs_25_4[1] = {
    {0, 4},
};
static state states_25[5] = {
    {1, arcs_25_0},
    {2, arcs_25_1},
    {2, arcs_25_2},
    {1, arcs_25_3},
    {1, arcs_25_4},
};
static arc arcs_26_0[2] = {
    {74, 1},
    {75, 1},
};
static arc arcs_26_1[1] = {
    {0, 1},
};
static state states_26[2] = {
    {2, arcs_26_0},
    {1, arcs_26_1},
};
static arc arcs_27_0[1] = {
    {76, 1},
};
static arc arcs_27_1[1] = {
    {77, 2},
};
static arc arcs_27_2[1] = {
    {0, 2},
};
static state states_27[3] = {
    {1, arcs_27_0},
    {1, arcs_27_1},
    {1, arcs_27_2},
};
static arc arcs_28_0[1] = {
    {73, 1},
};
static arc arcs_28_1[3] = {
    {78, 2},
    {79, 2},
    {12, 3},
};
static arc arcs_28_2[4] = {
    {78, 2},
    {79, 2},
    {12, 3},
    {76, 4},
};
static arc arcs_28_3[1] = {
    {76, 4},
};
static arc arcs_28_4[3] = {
    {31, 5},
    {13, 6},
    {80, 5},
};
static arc arcs_28_5[1] = {
    {0, 5},
};
static arc arcs_28_6[1] = {
    {80, 7},
};
static arc arcs_28_7[1] = {
    {15, 5},
};
static state states_28[8] = {
    {1, arcs_28_0},
    {3, arcs_28_1},
    {4, arcs_28_2},
    {1, arcs_28_3},
    {3, arcs_28_4},
    {1, arcs_28_5},
    {1, arcs_28_6},
    {1, arcs_28_7},
};
static arc arcs_29_0[1] = {
    {21, 1},
};
static arc arcs_29_1[2] = {
    {82, 2},
    {0, 1},
};
static arc arcs_29_2[1] = {
    {21, 3},
};
static arc arcs_29_3[1] = {
    {0, 3},
};
static state states_29[4] = {
    {1, arcs_29_0},
    {2, arcs_29_1},
    {1, arcs_29_2},
    {1, arcs_29_3},
};
static arc arcs_30_0[1] = {
    {12, 1},
};
static arc arcs_30_1[2] = {
    {82, 2},
    {0, 1},
};
static arc arcs_30_2[1] = {
    {21, 3},
};
static arc arcs_30_3[1] = {
    {0, 3},
};
static state states_30[4] = {
    {1, arcs_30_0},
    {2, arcs_30_1},
    {1, arcs_30_2},
    {1, arcs_30_3},
};
static arc arcs_31_0[1] = {
    {81, 1},
};
static arc arcs_31_1[2] = {
    {30, 2},
    {0, 1},
};
static arc arcs_31_2[2] = {
    {81, 1},
    {0, 2},
};
static state states_31[3] = {
    {1, arcs_31_0},
    {2, arcs_31_1},
    {2, arcs_31_2},
};
static arc arcs_32_0[1] = {
    {83, 1},
};
static arc arcs_32_1[2] = {
    {30, 0},
    {0, 1},
};
static state states_32[2] = {
    {1, arcs_32_0},
    {2, arcs_32_1},
};
static arc arcs_33_0[1] = {
    {21, 1},
};
static arc arcs_33_1[2] = {
    {78, 0},
    {0, 1},
};
static state states_33[2] = {
    {1, arcs_33_0},
    {2, arcs_33_1},
};
static arc arcs_34_0[1] = {
    {84, 1},
};
static arc arcs_34_1[1] = {
    {21, 2},
};
static arc arcs_34_2[2] = {
    {30, 1},
    {0, 2},
};
static state states_34[3] = {
    {1, arcs_34_0},
    {1, arcs_34_1},
    {2, arcs_34_2},
};
static arc arcs_35_0[1] = {
    {85, 1},
};
static arc arcs_35_1[1] = {
    {21, 2},
};
static arc arcs_35_2[2] = {
    {30, 1},
    {0, 2},
};
static state states_35[3] = {
    {1, arcs_35_0},
    {1, arcs_35_1},
    {2, arcs_35_2},
};
static arc arcs_36_0[1] = {
    {86, 1},
};
static arc arcs_36_1[1] = {
    {24, 2},
};
static arc arcs_36_2[2] = {
    {30, 3},
    {0, 2},
};
static arc arcs_36_3[1] = {
    {24, 4},
};
static arc arcs_36_4[1] = {
    {0, 4},
};
static state states_36[5] = {
    {1, arcs_36_0},
    {1, arcs_36_1},
    {2, arcs_36_2},
    {1, arcs_36_3},
    {1, arcs_36_4},
};
static arc arcs_37_0[8] = {
    {87, 1},
    {88, 1},
    {89, 1},
    {90, 1},
    {91, 1},
    {19, 1},
    {18, 1},
    {17, 1},
};
static arc arcs_37_1[1] = {
    {0, 1},
};
static state states_37[2] = {
    {8, arcs_37_0},
    {1, arcs_37_1},
};
static arc arcs_38_0[1] = {
    {92, 1},
};
static arc arcs_38_1[1] = {
    {24, 2},
};
static arc arcs_38_2[1] = {
    {25, 3},
};
static arc arcs_38_3[1] = {
    {26, 4},
};
static arc arcs_38_4[3] = {
    {93, 1},
    {94, 5},
    {0, 4},
};
static arc arcs_38_5[1] = {
    {25, 6},
};
static arc arcs_38_6[1] = {
    {26, 7},
};
static arc arcs_38_7[1] = {
    {0, 7},
};
static state states_38[8] = {
    {1, arcs_38_0},
    {1, arcs_38_1},
    {1, arcs_38_2},
    {1, arcs_38_3},
    {3, arcs_38_4},
    {1, arcs_38_5},
    {1, arcs_38_6},
    {1, arcs_38_7},
};
static arc arcs_39_0[1] = {
    {95, 1},
};
static arc arcs_39_1[1] = {
    {24, 2},
};
static arc arcs_39_2[1] = {
    {25, 3},
};
static arc arcs_39_3[1] = {
    {26, 4},
};
static arc arcs_39_4[2] = {
    {94, 5},
    {0, 4},
};
static arc arcs_39_5[1] = {
    {25, 6},
};
static arc arcs_39_6[1] = {
    {26, 7},
};
static arc arcs_39_7[1] = {
    {0, 7},
};
static state states_39[8] = {
    {1, arcs_39_0},
    {1, arcs_39_1},
    {1, arcs_39_2},
    {1, arcs_39_3},
    {2, arcs_39_4},
    {1, arcs_39_5},
    {1, arcs_39_6},
    {1, arcs_39_7},
};
static arc arcs_40_0[1] = {
    {96, 1},
};
static arc arcs_40_1[1] = {
    {62, 2},
};
static arc arcs_40_2[1] = {
    {97, 3},
};
static arc arcs_40_3[1] = {
    {9, 4},
};
static arc arcs_40_4[1] = {
    {25, 5},
};
static arc arcs_40_5[1] = {
    {26, 6},
};
static arc arcs_40_6[2] = {
    {94, 7},
    {0, 6},
};
static arc arcs_40_7[1] = {
    {25, 8},
};
static arc arcs_40_8[1] = {
    {26, 9},
};
static arc arcs_40_9[1] = {
    {0, 9},
};
static state states_40[10] = {
    {1, arcs_40_0},
    {1, arcs_40_1},
    {1, arcs_40_2},
    {1, arcs_40_3},
    {1, arcs_40_4},
    {1, arcs_40_5},
    {2, arcs_40_6},
    {1, arcs_40_7},
    {1, arcs_40_8},
    {1, arcs_40_9},
};
static arc arcs_41_0[1] = {
    {98, 1},
};
static arc arcs_41_1[1] = {
    {25, 2},
};
static arc arcs_41_2[1] = {
    {26, 3},
};
static arc arcs_41_3[2] = {
    {99, 4},
    {100, 5},
};
static arc arcs_41_4[1] = {
    {25, 6},
};
static arc arcs_41_5[1] = {
    {25, 7},
};
static arc arcs_41_6[1] = {
    {26, 8},
};
static arc arcs_41_7[1] = {
    {26, 9},
};
static arc arcs_41_8[4] = {
    {99, 4},
    {94, 10},
    {100, 5},
    {0, 8},
};
static arc arcs_41_9[1] = {
    {0, 9},
};
static arc arcs_41_10[1] = {
    {25, 11},
};
static arc arcs_41_11[1] = {
    {26, 12},
};
static arc arcs_41_12[2] = {
    {100, 5},
    {0, 12},
};
static state states_41[13] = {
    {1, arcs_41_0},
    {1, arcs_41_1},
    {1, arcs_41_2},
    {2, arcs_41_3},
    {1, arcs_41_4},
    {1, arcs_41_5},
    {1, arcs_41_6},
    {1, arcs_41_7},
    {4, arcs_41_8},
    {1, arcs_41_9},
    {1, arcs_41_10},
    {1, arcs_41_11},
    {2, arcs_41_12},
};
static arc arcs_42_0[1] = {
    {101, 1},
};
static arc arcs_42_1[1] = {
    {102, 2},
};
static arc arcs_42_2[2] = {
    {30, 1},
    {25, 3},
};
static arc arcs_42_3[1] = {
    {26, 4},
};
static arc arcs_42_4[1] = {
    {0, 4},
};
static state states_42[5] = {
    {1, arcs_42_0},
    {1, arcs_42_1},
    {2, arcs_42_2},
    {1, arcs_42_3},
    {1, arcs_42_4},
};
static arc arcs_43_0[1] = {
    {24, 1},
};
static arc arcs_43_1[2] = {
    {82, 2},
    {0, 1},
};
static arc arcs_43_2[1] = {
    {103, 3},
};
static arc arcs_43_3[1] = {
    {0, 3},
};
static state states_43[4] = {
    {1, arcs_43_0},
    {2, arcs_43_1},
    {1, arcs_43_2},
    {1, arcs_43_3},
};
static arc arcs_44_0[1] = {
    {104, 1},
};
static arc arcs_44_1[2] = {
    {24, 2},
    {0, 1},
};
static arc arcs_44_2[2] = {
    {82, 3},
    {0, 2},
};
static arc arcs_44_3[1] = {
    {21, 4},
};
static arc arcs_44_4[1] = {
    {0, 4},
};
static state states_44[5] = {
    {1, arcs_44_0},
    {2, arcs_44_1},
    {2, arcs_44_2},
    {1, arcs_44_3},
    {1, arcs_44_4},
};
static arc arcs_45_0[2] = {
    {3, 1},
    {2, 2},
};
static arc arcs_45_1[1] = {
    {0, 1},
};
static arc arcs_45_2[1] = {
    {105, 3},
};
static arc arcs_45_3[1] = {
    {6, 4},
};
static arc arcs_45_4[2] = {
    {6, 4},
    {106, 1},
};
static state states_45[5] = {
    {2, arcs_45_0},
    {1, arcs_45_1},
    {1, arcs_45_2},
    {1, arcs_45_3},
    {2, arcs_45_4},
};
static arc arcs_46_0[2] = {
    {107, 1},
    {108, 2},
};
static arc arcs_46_1[2] = {
    {92, 3},
    {0, 1},
};
static arc arcs_46_2[1] = {
    {0, 2},
};
static arc arcs_46_3[1] = {
    {107, 4},
};
static arc arcs_46_4[1] = {
    {94, 5},
};
static arc arcs_46_5[1] = {
    {24, 2},
};
static state states_46[6] = {
    {2, arcs_46_0},
    {2, arcs_46_1},
    {1, arcs_46_2},
    {1, arcs_46_3},
    {1, arcs_46_4},
    {1, arcs_46_5},
};
static arc arcs_47_0[2] = {
    {107, 1},
    {110, 1},
};
static arc arcs_47_1[1] = {
    {0, 1},
};
static state states_47[2] = {
    {2, arcs_47_0},
    {1, arcs_47_1},
};
static arc arcs_48_0[1] = {
    {111, 1},
};
static arc arcs_48_1[2] = {
    {33, 2},
    {25, 3},
};
static arc arcs_48_2[1] = {
    {25, 3},
};
static arc arcs_48_3[1] = {
    {24, 4},
};
static arc arcs_48_4[1] = {
    {0, 4},
};
static state states_48[5] = {
    {1, arcs_48_0},
    {2, arcs_48_1},
    {1, arcs_48_2},
    {1, arcs_48_3},
    {1, arcs_48_4},
};
static arc arcs_49_0[1] = {
    {111, 1},
};
static arc arcs_49_1[2] = {
    {33, 2},
    {25, 3},
};
static arc arcs_49_2[1] = {
    {25, 3},
};
static arc arcs_49_3[1] = {
    {109, 4},
};
static arc arcs_49_4[1] = {
    {0, 4},
};
static state states_49[5] = {
    {1, arcs_49_0},
    {2, arcs_49_1},
    {1, arcs_49_2},
    {1, arcs_49_3},
    {1, arcs_49_4},
};
static arc arcs_50_0[1] = {
    {112, 1},
};
static arc arcs_50_1[2] = {
    {113, 0},
    {0, 1},
};
static state states_50[2] = {
    {1, arcs_50_0},
    {2, arcs_50_1},
};
static arc arcs_51_0[1] = {
    {114, 1},
};
static arc arcs_51_1[2] = {
    {115, 0},
    {0, 1},
};
static state states_51[2] = {
    {1, arcs_51_0},
    {2, arcs_51_1},
};
static arc arcs_52_0[2] = {
    {116, 1},
    {117, 2},
};
static arc arcs_52_1[1] = {
    {114, 2},
};
static arc arcs_52_2[1] = {
    {0, 2},
};
static state states_52[3] = {
    {2, arcs_52_0},
    {1, arcs_52_1},
    {1, arcs_52_2},
};
static arc arcs_53_0[1] = {
    {103, 1},
};
static arc arcs_53_1[2] = {
    {118, 0},
    {0, 1},
};
static state states_53[2] = {
    {1, arcs_53_0},
    {2, arcs_53_1},
};
static arc arcs_54_0[10] = {
    {119, 1},
    {120, 1},
    {121, 1},
    {122, 1},
    {123, 1},
    {124, 1},
    {125, 1},
    {97, 1},
    {116, 2},
    {126, 3},
};
static arc arcs_54_1[1] = {
    {0, 1},
};
static arc arcs_54_2[1] = {
    {97, 1},
};
static arc arcs_54_3[2] = {
    {116, 1},
    {0, 3},
};
static state states_54[4] = {
    {10, arcs_54_0},
    {1, arcs_54_1},
    {1, arcs_54_2},
    {2, arcs_54_3},
};
static arc arcs_55_0[1] = {
    {31, 1},
};
static arc arcs_55_1[1] = {
    {103, 2},
};
static arc arcs_55_2[1] = {
    {0, 2},
};
static state states_55[3] = {
    {1, arcs_55_0},
    {1, arcs_55_1},
    {1, arcs_55_2},
};
static arc arcs_56_0[1] = {
    {127, 1},
};
static arc arcs_56_1[2] = {
    {128, 0},
    {0, 1},
};
static state states_56[2] = {
    {1, arcs_56_0},
    {2, arcs_56_1},
};
static arc arcs_57_0[1] = {
    {129, 1},
};
static arc arcs_57_1[2] = {
    {130, 0},
    {0, 1},
};
static state states_57[2] = {
    {1, arcs_57_0},
    {2, arcs_57_1},
};
static arc arcs_58_0[1] = {
    {131, 1},
};
static arc arcs_58_1[2] = {
    {132, 0},
    {0, 1},
};
static state states_58[2] = {
    {1, arcs_58_0},
    {2, arcs_58_1},
};
static arc arcs_59_0[1] = {
    {133, 1},
};
static arc arcs_59_1[3] = {
    {134, 0},
    {135, 0},
    {0, 1},
};
static state states_59[2] = {
    {1, arcs_59_0},
    {3, arcs_59_1},
};
static arc arcs_60_0[1] = {
    {136, 1},
};
static arc arcs_60_1[3] = {
    {137, 0},
    {138, 0},
    {0, 1},
};
static state states_60[2] = {
    {1, arcs_60_0},
    {3, arcs_60_1},
};
static arc arcs_61_0[1] = {
    {139, 1},
};
static arc arcs_61_1[5] = {
    {31, 0},
    {140, 0},
    {141, 0},
    {142, 0},
    {0, 1},
};
static state states_61[2] = {
    {1, arcs_61_0},
    {5, arcs_61_1},
};
static arc arcs_62_0[4] = {
    {137, 1},
    {138, 1},
    {143, 1},
    {144, 2},
};
static arc arcs_62_1[1] = {
    {139, 2},
};
static arc arcs_62_2[1] = {
    {0, 2},
};
static state states_62[3] = {
    {4, arcs_62_0},
    {1, arcs_62_1},
    {1, arcs_62_2},
};
static arc arcs_63_0[1] = {
    {145, 1},
};
static arc arcs_63_1[3] = {
    {146, 1},
    {32, 2},
    {0, 1},
};
static arc arcs_63_2[1] = {
    {139, 3},
};
static arc arcs_63_3[1] = {
    {0, 3},
};
static state states_63[4] = {
    {1, arcs_63_0},
    {3, arcs_63_1},
    {1, arcs_63_2},
    {1, arcs_63_3},
};
static arc arcs_64_0[10] = {
    {13, 1},
    {148, 2},
    {150, 3},
    {21, 4},
    {153, 4},
    {154, 5},
    {79, 4},
    {155, 4},
    {156, 4},
    {157, 4},
};
static arc arcs_64_1[3] = {
    {47, 6},
    {147, 6},
    {15, 4},
};
static arc arcs_64_2[2] = {
    {147, 7},
    {149, 4},
};
static arc arcs_64_3[2] = {
    {151, 8},
    {152, 4},
};
static arc arcs_64_4[1] = {
    {0, 4},
};
static arc arcs_64_5[2] = {
    {154, 5},
    {0, 5},
};
static arc arcs_64_6[1] = {
    {15, 4},
};
static arc arcs_64_7[1] = {
    {149, 4},
};
static arc arcs_64_8[1] = {
    {152, 4},
};
static state states_64[9] = {
    {10, arcs_64_0},
    {3, arcs_64_1},
    {2, arcs_64_2},
    {2, arcs_64_3},
    {1, arcs_64_4},
    {2, arcs_64_5},
    {1, arcs_64_6},
    {1, arcs_64_7},
    {1, arcs_64_8},
};
static arc arcs_65_0[2] = {
    {24, 1},
    {48, 1},
};
static arc arcs_65_1[3] = {
    {158, 2},
    {30, 3},
    {0, 1},
};
static arc arcs_65_2[1] = {
    {0, 2},
};
static arc arcs_65_3[3] = {
    {24, 4},
    {48, 4},
    {0, 3},
};
static arc arcs_65_4[2] = {
    {30, 3},
    {0, 4},
};
static state states_65[5] = {
    {2, arcs_65_0},
    {3, arcs_65_1},
    {1, arcs_65_2},
    {3, arcs_65_3},
    {2, arcs_65_4},
};
static arc arcs_66_0[3] = {
    {13, 1},
    {148, 2},
    {78, 3},
};
static arc arcs_66_1[2] = {
    {14, 4},
    {15, 5},
};
static arc arcs_66_2[1] = {
    {159, 6},
};
static arc arcs_66_3[1] = {
    {21, 5},
};
static arc arcs_66_4[1] = {
    {15, 5},
};
static arc arcs_66_5[1] = {
    {0, 5},
};
static arc arcs_66_6[1] = {
    {149, 5},
};
static state states_66[7] = {
    {3, arcs_66_0},
    {2, arcs_66_1},
    {1, arcs_66_2},
    {1, arcs_66_3},
    {1, arcs_66_4},
    {1, arcs_66_5},
    {1, arcs_66_6},
};
static arc arcs_67_0[1] = {
    {160, 1},
};
static arc arcs_67_1[2] = {
    {30, 2},
    {0, 1},
};
static arc arcs_67_2[2] = {
    {160, 1},
    {0, 2},
};
static state states_67[3] = {
    {1, arcs_67_0},
    {2, arcs_67_1},
    {2, arcs_67_2},
};
static arc arcs_68_0[2] = {
    {24, 1},
    {25, 2},
};
static arc arcs_68_1[2] = {
    {25, 2},
    {0, 1},
};
static arc arcs_68_2[3] = {
    {24, 3},
    {161, 4},
    {0, 2},
};
static arc arcs_68_3[2] = {
    {161, 4},
    {0, 3},
};
static arc arcs_68_4[1] = {
    {0, 4},
};
static state states_68[5] = {
    {2, arcs_68_0},
    {2, arcs_68_1},
    {3, arcs_68_2},
    {2, arcs_68_3},
    {1, arcs_68_4},
};
static arc arcs_69_0[1] = {
    {25, 1},
};
static arc arcs_69_1[2] = {
    {24, 2},
    {0, 1},
};
static arc arcs_69_2[1] = {
    {0, 2},
};
static state states_69[3] = {
    {1, arcs_69_0},
    {2, arcs_69_1},
    {1, arcs_69_2},
};
static arc arcs_70_0[2] = {
    {103, 1},
    {48, 1},
};
static arc arcs_70_1[2] = {
    {30, 2},
    {0, 1},
};
static arc arcs_70_2[3] = {
    {103, 1},
    {48, 1},
    {0, 2},
};
static state states_70[3] = {
    {2, arcs_70_0},
    {2, arcs_70_1},
    {3, arcs_70_2},
};
static arc arcs_71_0[1] = {
    {24, 1},
};
static arc arcs_71_1[2] = {
    {30, 2},
    {0, 1},
};
static arc arcs_71_2[2] = {
    {24, 1},
    {0, 2},
};
static state states_71[3] = {
    {1, arcs_71_0},
    {2, arcs_71_1},
    {2, arcs_71_2},
};
static arc arcs_72_0[1] = {
    {24, 1},
};
static arc arcs_72_1[4] = {
    {25, 2},
    {158, 3},
    {30, 4},
    {0, 1},
};
static arc arcs_72_2[1] = {
    {24, 5},
};
static arc arcs_72_3[1] = {
    {0, 3},
};
static arc arcs_72_4[2] = {
    {24, 6},
    {0, 4},
};
static arc arcs_72_5[3] = {
    {158, 3},
    {30, 7},
    {0, 5},
};
static arc arcs_72_6[2] = {
    {30, 4},
    {0, 6},
};
static arc arcs_72_7[2] = {
    {24, 8},
    {0, 7},
};
static arc arcs_72_8[1] = {
    {25, 9},
};
static arc arcs_72_9[1] = {
    {24, 10},
};
static arc arcs_72_10[2] = {
    {30, 7},
    {0, 10},
};
static state states_72[11] = {
    {1, arcs_72_0},
    {4, arcs_72_1},
    {1, arcs_72_2},
    {1, arcs_72_3},
    {2, arcs_72_4},
    {3, arcs_72_5},
    {2, arcs_72_6},
    {2, arcs_72_7},
    {1, arcs_72_8},
    {1, arcs_72_9},
    {2, arcs_72_10},
};
static arc arcs_73_0[1] = {
    {162, 1},
};
static arc arcs_73_1[1] = {
    {21, 2},
};
static arc arcs_73_2[2] = {
    {13, 3},
    {25, 4},
};
static arc arcs_73_3[2] = {
    {14, 5},
    {15, 6},
};
static arc arcs_73_4[1] = {
    {26, 7},
};
static arc arcs_73_5[1] = {
    {15, 6},
};
static arc arcs_73_6[1] = {
    {25, 4},
};
static arc arcs_73_7[1] = {
    {0, 7},
};
static state states_73[8] = {
    {1, arcs_73_0},
    {1, arcs_73_1},
    {2, arcs_73_2},
    {2, arcs_73_3},
    {1, arcs_73_4},
    {1, arcs_73_5},
    {1, arcs_73_6},
    {1, arcs_73_7},
};
static arc arcs_74_0[3] = {
    {163, 1},
    {31, 2},
    {32, 3},
};
static arc arcs_74_1[2] = {
    {30, 4},
    {0, 1},
};
static arc arcs_74_2[1] = {
    {24, 5},
};
static arc arcs_74_3[1] = {
    {24, 6},
};
static arc arcs_74_4[4] = {
    {163, 1},
    {31, 2},
    {32, 3},
    {0, 4},
};
static arc arcs_74_5[2] = {
    {30, 7},
    {0, 5},
};
static arc arcs_74_6[1] = {
    {0, 6},
};
static arc arcs_74_7[2] = {
    {163, 5},
    {32, 3},
};
static state states_74[8] = {
    {3, arcs_74_0},
    {2, arcs_74_1},
    {1, arcs_74_2},
    {1, arcs_74_3},
    {4, arcs_74_4},
    {2, arcs_74_5},
    {1, arcs_74_6},
    {2, arcs_74_7},
};
static arc arcs_75_0[1] = {
    {24, 1},
};
static arc arcs_75_1[3] = {
    {158, 2},
    {29, 3},
    {0, 1},
};
static arc arcs_75_2[1] = {
    {0, 2},
};
static arc arcs_75_3[1] = {
    {24, 2},
};
static state states_75[4] = {
    {1, arcs_75_0},
    {3, arcs_75_1},
    {1, arcs_75_2},
    {1, arcs_75_3},
};
static arc arcs_76_0[2] = {
    {158, 1},
    {165, 1},
};
static arc arcs_76_1[1] = {
    {0, 1},
};
static state states_76[2] = {
    {2, arcs_76_0},
    {1, arcs_76_1},
};
static arc arcs_77_0[1] = {
    {96, 1},
};
static arc arcs_77_1[1] = {
    {62, 2},
};
static arc arcs_77_2[1] = {
    {97, 3},
};
static arc arcs_77_3[1] = {
    {107, 4},
};
static arc arcs_77_4[2] = {
    {164, 5},
    {0, 4},
};
static arc arcs_77_5[1] = {
    {0, 5},
};
static state states_77[6] = {
    {1, arcs_77_0},
    {1, arcs_77_1},
    {1, arcs_77_2},
    {1, arcs_77_3},
    {2, arcs_77_4},
    {1, arcs_77_5},
};
static arc arcs_78_0[1] = {
    {92, 1},
};
static arc arcs_78_1[1] = {
    {109, 2},
};
static arc arcs_78_2[2] = {
    {164, 3},
    {0, 2},
};
static arc arcs_78_3[1] = {
    {0, 3},
};
static state states_78[4] = {
    {1, arcs_78_0},
    {1, arcs_78_1},
    {2, arcs_78_2},
    {1, arcs_78_3},
};
static arc arcs_79_0[1] = {
    {21, 1},
};
static arc arcs_79_1[1] = {
    {0, 1},
};
static state states_79[2] = {
    {1, arcs_79_0},
    {1, arcs_79_1},
};
static arc arcs_80_0[1] = {
    {167, 1},
};
static arc arcs_80_1[2] = {
    {9, 2},
    {0, 1},
};
static arc arcs_80_2[1] = {
    {0, 2},
};
static state states_80[3] = {
    {1, arcs_80_0},
    {2, arcs_80_1},
    {1, arcs_80_2},
};
static dfa dfas[81] = {
    {256, "single_input", 0, 3, states_0,
     "\004\050\060\200\000\000\000\240\340\223\160\220\045\200\020\000\000\206\120\076\204"},
    {257, "file_input", 0, 2, states_1,
     "\204\050\060\200\000\000\000\240\340\223\160\220\045\200\020\000\000\206\120\076\204"},
    {258, "eval_input", 0, 3, states_2,
     "\000\040\040\000\000\000\000\000\000\200\000\000\000\200\020\000\000\206\120\076\000"},
    {259, "decorator", 0, 7, states_3,
     "\000\010\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000"},
    {260, "decorators", 0, 2, states_4,
     "\000\010\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000"},
    {261, "decorated", 0, 3, states_5,
     "\000\010\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000"},
    {262, "funcdef", 0, 8, states_6,
     "\000\000\020\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000"},
    {263, "parameters", 0, 4, states_7,
     "\000\040\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000"},
    {264, "typedargslist", 0, 18, states_8,
     "\000\000\040\200\001\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000"},
    {265, "tfpdef", 0, 4, states_9,
     "\000\000\040\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000"},
    {266, "varargslist", 0, 18, states_10,
     "\000\000\040\200\001\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000"},
    {267, "vfpdef", 0, 2, states_11,
     "\000\000\040\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000"},
    {268, "stmt", 0, 2, states_12,
     "\000\050\060\200\000\000\000\240\340\223\160\220\045\200\020\000\000\206\120\076\204"},
    {269, "simple_stmt", 0, 4, states_13,
     "\000\040\040\200\000\000\000\240\340\223\160\000\000\200\020\000\000\206\120\076\200"},
    {270, "small_stmt", 0, 2, states_14,
     "\000\040\040\200\000\000\000\240\340\223\160\000\000\200\020\000\000\206\120\076\200"},
    {271, "expr_stmt", 0, 6, states_15,
     "\000\040\040\200\000\000\000\000\000\200\000\000\000\200\020\000\000\206\120\076\000"},
    {272, "testlist_star_expr", 0, 3, states_16,
     "\000\040\040\200\000\000\000\000\000\200\000\000\000\200\020\000\000\206\120\076\000"},
    {273, "augassign", 0, 2, states_17,
     "\000\000\000\000\000\000\376\037\000\000\000\000\000\000\000\000\000\000\000\000\000"},
    {274, "del_stmt", 0, 3, states_18,
     "\000\000\000\000\000\000\000\040\000\000\000\000\000\000\000\000\000\000\000\000\000"},
    {275, "pass_stmt", 0, 2, states_19,
     "\000\000\000\000\000\000\000\200\000\000\000\000\000\000\000\000\000\000\000\000\000"},
    {276, "flow_stmt", 0, 2, states_20,
     "\000\000\000\000\000\000\000\000\340\001\000\000\000\000\000\000\000\000\000\000\200"},
    {277, "break_stmt", 0, 2, states_21,
     "\000\000\000\000\000\000\000\000\040\000\000\000\000\000\000\000\000\000\000\000\000"},
    {278, "continue_stmt", 0, 2, states_22,
     "\000\000\000\000\000\000\000\000\100\000\000\000\000\000\000\000\000\000\000\000\000"},
    {279, "return_stmt", 0, 3, states_23,
     "\000\000\000\000\000\000\000\000\200\000\000\000\000\000\000\000\000\000\000\000\000"},
    {280, "yield_stmt", 0, 2, states_24,
     "\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\200"},
    {281, "raise_stmt", 0, 5, states_25,
     "\000\000\000\000\000\000\000\000\000\001\000\000\000\000\000\000\000\000\000\000\000"},
    {282, "import_stmt", 0, 2, states_26,
     "\000\000\000\000\000\000\000\000\000\022\000\000\000\000\000\000\000\000\000\000\000"},
    {283, "import_name", 0, 3, states_27,
     "\000\000\000\000\000\000\000\000\000\020\000\000\000\000\000\000\000\000\000\000\000"},
    {284, "import_from", 0, 8, states_28,
     "\000\000\000\000\000\000\000\000\000\002\000\000\000\000\000\000\000\000\000\000\000"},
    {285, "import_as_name", 0, 4, states_29,
     "\000\000\040\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000"},
    {286, "dotted_as_name", 0, 4, states_30,
     "\000\000\040\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000"},
    {287, "import_as_names", 0, 3, states_31,
     "\000\000\040\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000"},
    {288, "dotted_as_names", 0, 2, states_32,
     "\000\000\040\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000"},
    {289, "dotted_name", 0, 2, states_33,
     "\000\000\040\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000"},
    {290, "global_stmt", 0, 3, states_34,
     "\000\000\000\000\000\000\000\000\000\000\020\000\000\000\000\000\000\000\000\000\000"},
    {291, "nonlocal_stmt", 0, 3, states_35,
     "\000\000\000\000\000\000\000\000\000\000\040\000\000\000\000\000\000\000\000\000\000"},
    {292, "assert_stmt", 0, 5, states_36,
     "\000\000\000\000\000\000\000\000\000\000\100\000\000\000\000\000\000\000\000\000\000"},
    {293, "compound_stmt", 0, 2, states_37,
     "\000\010\020\000\000\000\000\000\000\000\000\220\045\000\000\000\000\000\000\000\004"},
    {294, "if_stmt", 0, 8, states_38,
     "\000\000\000\000\000\000\000\000\000\000\000\020\000\000\000\000\000\000\000\000\000"},
    {295, "while_stmt", 0, 8, states_39,
     "\000\000\000\000\000\000\000\000\000\000\000\200\000\000\000\000\000\000\000\000\000"},
    {296, "for_stmt", 0, 10, states_40,
     "\000\000\000\000\000\000\000\000\000\000\000\000\001\000\000\000\000\000\000\000\000"},
    {297, "try_stmt", 0, 13, states_41,
     "\000\000\000\000\000\000\000\000\000\000\000\000\004\000\000\000\000\000\000\000\000"},
    {298, "with_stmt", 0, 5, states_42,
     "\000\000\000\000\000\000\000\000\000\000\000\000\040\000\000\000\000\000\000\000\000"},
    {299, "with_item", 0, 4, states_43,
     "\000\040\040\000\000\000\000\000\000\200\000\000\000\200\020\000\000\206\120\076\000"},
    {300, "except_clause", 0, 5, states_44,
     "\000\000\000\000\000\000\000\000\000\000\000\000\000\001\000\000\000\000\000\000\000"},
    {301, "suite", 0, 5, states_45,
     "\004\040\040\200\000\000\000\240\340\223\160\000\000\200\020\000\000\206\120\076\200"},
    {302, "test", 0, 6, states_46,
     "\000\040\040\000\000\000\000\000\000\200\000\000\000\200\020\000\000\206\120\076\000"},
    {303, "test_nocond", 0, 2, states_47,
     "\000\040\040\000\000\000\000\000\000\200\000\000\000\200\020\000\000\206\120\076\000"},
    {304, "lambdef", 0, 5, states_48,
     "\000\000\000\000\000\000\000\000\000\000\000\000\000\200\000\000\000\000\000\000\000"},
    {305, "lambdef_nocond", 0, 5, states_49,
     "\000\000\000\000\000\000\000\000\000\000\000\000\000\200\000\000\000\000\000\000\000"},
    {306, "or_test", 0, 2, states_50,
     "\000\040\040\000\000\000\000\000\000\200\000\000\000\000\020\000\000\206\120\076\000"},
    {307, "and_test", 0, 2, states_51,
     "\000\040\040\000\000\000\000\000\000\200\000\000\000\000\020\000\000\206\120\076\000"},
    {308, "not_test", 0, 3, states_52,
     "\000\040\040\000\000\000\000\000\000\200\000\000\000\000\020\000\000\206\120\076\000"},
    {309, "comparison", 0, 2, states_53,
     "\000\040\040\000\000\000\000\000\000\200\000\000\000\000\000\000\000\206\120\076\000"},
    {310, "comp_op", 0, 4, states_54,
     "\000\000\000\000\000\000\000\000\000\000\000\000\002\000\220\177\000\000\000\000\000"},
    {311, "star_expr", 0, 3, states_55,
     "\000\000\000\200\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000"},
    {312, "expr", 0, 2, states_56,
     "\000\040\040\000\000\000\000\000\000\200\000\000\000\000\000\000\000\206\120\076\000"},
    {313, "xor_expr", 0, 2, states_57,
     "\000\040\040\000\000\000\000\000\000\200\000\000\000\000\000\000\000\206\120\076\000"},
    {314, "and_expr", 0, 2, states_58,
     "\000\040\040\000\000\000\000\000\000\200\000\000\000\000\000\000\000\206\120\076\000"},
    {315, "shift_expr", 0, 2, states_59,
     "\000\040\040\000\000\000\000\000\000\200\000\000\000\000\000\000\000\206\120\076\000"},
    {316, "arith_expr", 0, 2, states_60,
     "\000\040\040\000\000\000\000\000\000\200\000\000\000\000\000\000\000\206\120\076\000"},
    {317, "term", 0, 2, states_61,
     "\000\040\040\000\000\000\000\000\000\200\000\000\000\000\000\000\000\206\120\076\000"},
    {318, "factor", 0, 3, states_62,
     "\000\040\040\000\000\000\000\000\000\200\000\000\000\000\000\000\000\206\120\076\000"},
    {319, "power", 0, 4, states_63,
     "\000\040\040\000\000\000\000\000\000\200\000\000\000\000\000\000\000\000\120\076\000"},
    {320, "atom", 0, 9, states_64,
     "\000\040\040\000\000\000\000\000\000\200\000\000\000\000\000\000\000\000\120\076\000"},
    {321, "testlist_comp", 0, 5, states_65,
     "\000\040\040\200\000\000\000\000\000\200\000\000\000\200\020\000\000\206\120\076\000"},
    {322, "trailer", 0, 7, states_66,
     "\000\040\000\000\000\000\000\000\000\100\000\000\000\000\000\000\000\000\020\000\000"},
    {323, "subscriptlist", 0, 3, states_67,
     "\000\040\040\002\000\000\000\000\000\200\000\000\000\200\020\000\000\206\120\076\000"},
    {324, "subscript", 0, 5, states_68,
     "\000\040\040\002\000\000\000\000\000\200\000\000\000\200\020\000\000\206\120\076\000"},
    {325, "sliceop", 0, 3, states_69,
     "\000\000\000\002\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000"},
    {326, "exprlist", 0, 3, states_70,
     "\000\040\040\200\000\000\000\000\000\200\000\000\000\000\000\000\000\206\120\076\000"},
    {327, "testlist", 0, 3, states_71,
     "\000\040\040\000\000\000\000\000\000\200\000\000\000\200\020\000\000\206\120\076\000"},
    {328, "dictorsetmaker", 0, 11, states_72,
     "\000\040\040\000\000\000\000\000\000\200\000\000\000\200\020\000\000\206\120\076\000"},
    {329, "classdef", 0, 8, states_73,
     "\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\004"},
    {330, "arglist", 0, 8, states_74,
     "\000\040\040\200\001\000\000\000\000\200\000\000\000\200\020\000\000\206\120\076\000"},
    {331, "argument", 0, 4, states_75,
     "\000\040\040\000\000\000\000\000\000\200\000\000\000\200\020\000\000\206\120\076\000"},
    {332, "comp_iter", 0, 2, states_76,
     "\000\000\000\000\000\000\000\000\000\000\000\020\001\000\000\000\000\000\000\000\000"},
    {333, "comp_for", 0, 6, states_77,
     "\000\000\000\000\000\000\000\000\000\000\000\000\001\000\000\000\000\000\000\000\000"},
    {334, "comp_if", 0, 4, states_78,
     "\000\000\000\000\000\000\000\000\000\000\000\020\000\000\000\000\000\000\000\000\000"},
    {335, "encoding_decl", 0, 2, states_79,
     "\000\000\040\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000"},
    {336, "yield_expr", 0, 3, states_80,
     "\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\200"},
};
static label labels[168] = {
    {0, "EMPTY"},
    {256, 0},
    {4, 0},
    {269, 0},
    {293, 0},
    {257, 0},
    {268, 0},
    {0, 0},
    {258, 0},
    {327, 0},
    {259, 0},
    {50, 0},
    {289, 0},
    {7, 0},
    {330, 0},
    {8, 0},
    {260, 0},
    {261, 0},
    {329, 0},
    {262, 0},
    {1, "def"},
    {1, 0},
    {263, 0},
    {51, 0},
    {302, 0},
    {11, 0},
    {301, 0},
    {264, 0},
    {265, 0},
    {22, 0},
    {12, 0},
    {16, 0},
    {36, 0},
    {266, 0},
    {267, 0},
    {270, 0},
    {13, 0},
    {271, 0},
    {274, 0},
    {275, 0},
    {276, 0},
    {282, 0},
    {290, 0},
    {291, 0},
    {292, 0},
    {272, 0},
    {273, 0},
    {336, 0},
    {311, 0},
    {37, 0},
    {38, 0},
    {39, 0},
    {40, 0},
    {41, 0},
    {42, 0},
    {43, 0},
    {44, 0},
    {45, 0},
    {46, 0},
    {47, 0},
    {49, 0},
    {1, "del"},
    {326, 0},
    {1, "pass"},
    {277, 0},
    {278, 0},
    {279, 0},
    {281, 0},
    {280, 0},
    {1, "break"},
    {1, "continue"},
    {1, "return"},
    {1, "raise"},
    {1, "from"},
    {283, 0},
    {284, 0},
    {1, "import"},
    {288, 0},
    {23, 0},
    {52, 0},
    {287, 0},
    {285, 0},
    {1, "as"},
    {286, 0},
    {1, "global"},
    {1, "nonlocal"},
    {1, "assert"},
    {294, 0},
    {295, 0},
    {296, 0},
    {297, 0},
    {298, 0},
    {1, "if"},
    {1, "elif"},
    {1, "else"},
    {1, "while"},
    {1, "for"},
    {1, "in"},
    {1, "try"},
    {300, 0},
    {1, "finally"},
    {1, "with"},
    {299, 0},
    {312, 0},
    {1, "except"},
    {5, 0},
    {6, 0},
    {306, 0},
    {304, 0},
    {303, 0},
    {305, 0},
    {1, "lambda"},
    {307, 0},
    {1, "or"},
    {308, 0},
    {1, "and"},
    {1, "not"},
    {309, 0},
    {310, 0},
    {20, 0},
    {21, 0},
    {28, 0},
    {31, 0},
    {30, 0},
    {29, 0},
    {29, 0},
    {1, "is"},
    {313, 0},
    {18, 0},
    {314, 0},
    {33, 0},
    {315, 0},
    {19, 0},
    {316, 0},
    {34, 0},
    {35, 0},
    {317, 0},
    {14, 0},
    {15, 0},
    {318, 0},
    {17, 0},
    {24, 0},
    {48, 0},
    {32, 0},
    {319, 0},
    {320, 0},
    {322, 0},
    {321, 0},
    {9, 0},
    {10, 0},
    {26, 0},
    {328, 0},
    {27, 0},
    {2, 0},
    {3, 0},
    {1, "None"},
    {1, "True"},
    {1, "False"},
    {333, 0},
    {323, 0},
    {324, 0},
    {325, 0},
    {1, "class"},
    {331, 0},
    {332, 0},
    {334, 0},
    {335, 0},
    {1, "yield"},
};
grammar _PyParser_Grammar = {
    81,
    dfas,
    {168, labels},
    256
};
num">0); /* This happens when nobody references the cell. Return None. */ ADDOP_O(c, LOAD_CONST, Py_None, consts); } ADDOP_IN_SCOPE(c, RETURN_VALUE); /* create the code object */ co = assemble(c, 1); } /* leave the new scope */ compiler_exit_scope(c); if (co == NULL) return 0; /* 2. load the 'build_class' function */ ADDOP(c, LOAD_BUILD_CLASS); /* 3. load a function (or closure) made from the code object */ compiler_make_closure(c, co, 0, NULL); Py_DECREF(co); /* 4. load class name */ ADDOP_O(c, LOAD_CONST, s->v.ClassDef.name, consts); /* 5. generate the rest of the code for the call */ if (!compiler_call_helper(c, 2, s->v.ClassDef.bases, s->v.ClassDef.keywords, s->v.ClassDef.starargs, s->v.ClassDef.kwargs)) return 0; /* 6. apply decorators */ for (i = 0; i < asdl_seq_LEN(decos); i++) { ADDOP_I(c, CALL_FUNCTION, 1); } /* 7. store into <name> */ if (!compiler_nameop(c, s->v.ClassDef.name, Store)) return 0; return 1; } static int compiler_ifexp(struct compiler *c, expr_ty e) { basicblock *end, *next; assert(e->kind == IfExp_kind); end = compiler_new_block(c); if (end == NULL) return 0; next = compiler_new_block(c); if (next == NULL) return 0; VISIT(c, expr, e->v.IfExp.test); ADDOP_JABS(c, POP_JUMP_IF_FALSE, next); VISIT(c, expr, e->v.IfExp.body); ADDOP_JREL(c, JUMP_FORWARD, end); compiler_use_next_block(c, next); VISIT(c, expr, e->v.IfExp.orelse); compiler_use_next_block(c, end); return 1; } static int compiler_lambda(struct compiler *c, expr_ty e) { PyCodeObject *co; PyObject *qualname; static identifier name; int kw_default_count = 0; Py_ssize_t arglength; arguments_ty args = e->v.Lambda.args; assert(e->kind == Lambda_kind); if (!name) { name = PyUnicode_InternFromString("<lambda>"); if (!name) return 0; } if (args->defaults) VISIT_SEQ(c, expr, args->defaults); if (args->kwonlyargs) { int res = compiler_visit_kwonlydefaults(c, args->kwonlyargs, args->kw_defaults); if (res < 0) return 0; kw_default_count = res; } if (!compiler_enter_scope(c, name, COMPILER_SCOPE_LAMBDA, (void *)e, e->lineno)) return 0; /* Make None the first constant, so the lambda can't have a docstring. */ if (compiler_add_o(c, c->u->u_consts, Py_None) < 0) return 0; c->u->u_argcount = asdl_seq_LEN(args->args); c->u->u_kwonlyargcount = asdl_seq_LEN(args->kwonlyargs); VISIT_IN_SCOPE(c, expr, e->v.Lambda.body); if (c->u->u_ste->ste_generator) { co = assemble(c, 0); } else { ADDOP_IN_SCOPE(c, RETURN_VALUE); co = assemble(c, 1); } qualname = c->u->u_qualname; Py_INCREF(qualname); compiler_exit_scope(c); if (co == NULL) return 0; arglength = asdl_seq_LEN(args->defaults); arglength |= kw_default_count << 8; compiler_make_closure(c, co, arglength, qualname); Py_DECREF(qualname); Py_DECREF(co); return 1; } static int compiler_if(struct compiler *c, stmt_ty s) { basicblock *end, *next; int constant; assert(s->kind == If_kind); end = compiler_new_block(c); if (end == NULL) return 0; constant = expr_constant(c, s->v.If.test); /* constant = 0: "if 0" * constant = 1: "if 1", "if 2", ... * constant = -1: rest */ if (constant == 0) { if (s->v.If.orelse) VISIT_SEQ(c, stmt, s->v.If.orelse); } else if (constant == 1) { VISIT_SEQ(c, stmt, s->v.If.body); } else { if (asdl_seq_LEN(s->v.If.orelse)) { next = compiler_new_block(c); if (next == NULL) return 0; } else next = end; VISIT(c, expr, s->v.If.test); ADDOP_JABS(c, POP_JUMP_IF_FALSE, next); VISIT_SEQ(c, stmt, s->v.If.body); if (asdl_seq_LEN(s->v.If.orelse)) { ADDOP_JREL(c, JUMP_FORWARD, end); compiler_use_next_block(c, next); VISIT_SEQ(c, stmt, s->v.If.orelse); } } compiler_use_next_block(c, end); return 1; } static int compiler_for(struct compiler *c, stmt_ty s) { basicblock *start, *cleanup, *end; start = compiler_new_block(c); cleanup = compiler_new_block(c); end = compiler_new_block(c); if (start == NULL || end == NULL || cleanup == NULL) return 0; ADDOP_JREL(c, SETUP_LOOP, end); if (!compiler_push_fblock(c, LOOP, start)) return 0; VISIT(c, expr, s->v.For.iter); ADDOP(c, GET_ITER); compiler_use_next_block(c, start); ADDOP_JREL(c, FOR_ITER, cleanup); VISIT(c, expr, s->v.For.target); VISIT_SEQ(c, stmt, s->v.For.body); ADDOP_JABS(c, JUMP_ABSOLUTE, start); compiler_use_next_block(c, cleanup); ADDOP(c, POP_BLOCK); compiler_pop_fblock(c, LOOP, start); VISIT_SEQ(c, stmt, s->v.For.orelse); compiler_use_next_block(c, end); return 1; } static int compiler_while(struct compiler *c, stmt_ty s) { basicblock *loop, *orelse, *end, *anchor = NULL; int constant = expr_constant(c, s->v.While.test); if (constant == 0) { if (s->v.While.orelse) VISIT_SEQ(c, stmt, s->v.While.orelse); return 1; } loop = compiler_new_block(c); end = compiler_new_block(c); if (constant == -1) { anchor = compiler_new_block(c); if (anchor == NULL) return 0; } if (loop == NULL || end == NULL) return 0; if (s->v.While.orelse) { orelse = compiler_new_block(c); if (orelse == NULL) return 0; } else orelse = NULL; ADDOP_JREL(c, SETUP_LOOP, end); compiler_use_next_block(c, loop); if (!compiler_push_fblock(c, LOOP, loop)) return 0; if (constant == -1) { VISIT(c, expr, s->v.While.test); ADDOP_JABS(c, POP_JUMP_IF_FALSE, anchor); } VISIT_SEQ(c, stmt, s->v.While.body); ADDOP_JABS(c, JUMP_ABSOLUTE, loop); /* XXX should the two POP instructions be in a separate block if there is no else clause ? */ if (constant == -1) compiler_use_next_block(c, anchor); ADDOP(c, POP_BLOCK); compiler_pop_fblock(c, LOOP, loop); if (orelse != NULL) /* what if orelse is just pass? */ VISIT_SEQ(c, stmt, s->v.While.orelse); compiler_use_next_block(c, end); return 1; } static int compiler_continue(struct compiler *c) { static const char LOOP_ERROR_MSG[] = "'continue' not properly in loop"; static const char IN_FINALLY_ERROR_MSG[] = "'continue' not supported inside 'finally' clause"; int i; if (!c->u->u_nfblocks) return compiler_error(c, LOOP_ERROR_MSG); i = c->u->u_nfblocks - 1; switch (c->u->u_fblock[i].fb_type) { case LOOP: ADDOP_JABS(c, JUMP_ABSOLUTE, c->u->u_fblock[i].fb_block); break; case EXCEPT: case FINALLY_TRY: while (--i >= 0 && c->u->u_fblock[i].fb_type != LOOP) { /* Prevent continue anywhere under a finally even if hidden in a sub-try or except. */ if (c->u->u_fblock[i].fb_type == FINALLY_END) return compiler_error(c, IN_FINALLY_ERROR_MSG); } if (i == -1) return compiler_error(c, LOOP_ERROR_MSG); ADDOP_JABS(c, CONTINUE_LOOP, c->u->u_fblock[i].fb_block); break; case FINALLY_END: return compiler_error(c, IN_FINALLY_ERROR_MSG); } return 1; } /* Code generated for "try: <body> finally: <finalbody>" is as follows: SETUP_FINALLY L <code for body> POP_BLOCK LOAD_CONST <None> L: <code for finalbody> END_FINALLY The special instructions use the block stack. Each block stack entry contains the instruction that created it (here SETUP_FINALLY), the level of the value stack at the time the block stack entry was created, and a label (here L). SETUP_FINALLY: Pushes the current value stack level and the label onto the block stack. POP_BLOCK: Pops en entry from the block stack, and pops the value stack until its level is the same as indicated on the block stack. (The label is ignored.) END_FINALLY: Pops a variable number of entries from the *value* stack and re-raises the exception they specify. The number of entries popped depends on the (pseudo) exception type. The block stack is unwound when an exception is raised: when a SETUP_FINALLY entry is found, the exception is pushed onto the value stack (and the exception condition is cleared), and the interpreter jumps to the label gotten from the block stack. */ static int compiler_try_finally(struct compiler *c, stmt_ty s) { basicblock *body, *end; body = compiler_new_block(c); end = compiler_new_block(c); if (body == NULL || end == NULL) return 0; ADDOP_JREL(c, SETUP_FINALLY, end); compiler_use_next_block(c, body); if (!compiler_push_fblock(c, FINALLY_TRY, body)) return 0; if (s->v.Try.handlers && asdl_seq_LEN(s->v.Try.handlers)) { if (!compiler_try_except(c, s)) return 0; } else { VISIT_SEQ(c, stmt, s->v.Try.body); } ADDOP(c, POP_BLOCK); compiler_pop_fblock(c, FINALLY_TRY, body); ADDOP_O(c, LOAD_CONST, Py_None, consts); compiler_use_next_block(c, end); if (!compiler_push_fblock(c, FINALLY_END, end)) return 0; VISIT_SEQ(c, stmt, s->v.Try.finalbody); ADDOP(c, END_FINALLY); compiler_pop_fblock(c, FINALLY_END, end); return 1; } /* Code generated for "try: S except E1 as V1: S1 except E2 as V2: S2 ...": (The contents of the value stack is shown in [], with the top at the right; 'tb' is trace-back info, 'val' the exception's associated value, and 'exc' the exception.) Value stack Label Instruction Argument [] SETUP_EXCEPT L1 [] <code for S> [] POP_BLOCK [] JUMP_FORWARD L0 [tb, val, exc] L1: DUP ) [tb, val, exc, exc] <evaluate E1> ) [tb, val, exc, exc, E1] COMPARE_OP EXC_MATCH ) only if E1 [tb, val, exc, 1-or-0] POP_JUMP_IF_FALSE L2 ) [tb, val, exc] POP [tb, val] <assign to V1> (or POP if no V1) [tb] POP [] <code for S1> JUMP_FORWARD L0 [tb, val, exc] L2: DUP .............................etc....................... [tb, val, exc] Ln+1: END_FINALLY # re-raise exception [] L0: <next statement> Of course, parts are not generated if Vi or Ei is not present. */ static int compiler_try_except(struct compiler *c, stmt_ty s) { basicblock *body, *orelse, *except, *end; Py_ssize_t i, n; body = compiler_new_block(c); except = compiler_new_block(c); orelse = compiler_new_block(c); end = compiler_new_block(c); if (body == NULL || except == NULL || orelse == NULL || end == NULL) return 0; ADDOP_JREL(c, SETUP_EXCEPT, except); compiler_use_next_block(c, body); if (!compiler_push_fblock(c, EXCEPT, body)) return 0; VISIT_SEQ(c, stmt, s->v.Try.body); ADDOP(c, POP_BLOCK); compiler_pop_fblock(c, EXCEPT, body); ADDOP_JREL(c, JUMP_FORWARD, orelse); n = asdl_seq_LEN(s->v.Try.handlers); compiler_use_next_block(c, except); for (i = 0; i < n; i++) { excepthandler_ty handler = (excepthandler_ty)asdl_seq_GET( s->v.Try.handlers, i); if (!handler->v.ExceptHandler.type && i < n-1) return compiler_error(c, "default 'except:' must be last"); c->u->u_lineno_set = 0; c->u->u_lineno = handler->lineno; c->u->u_col_offset = handler->col_offset; except = compiler_new_block(c); if (except == NULL) return 0; if (handler->v.ExceptHandler.type) { ADDOP(c, DUP_TOP); VISIT(c, expr, handler->v.ExceptHandler.type); ADDOP_I(c, COMPARE_OP, PyCmp_EXC_MATCH); ADDOP_JABS(c, POP_JUMP_IF_FALSE, except); } ADDOP(c, POP_TOP); if (handler->v.ExceptHandler.name) { basicblock *cleanup_end, *cleanup_body; cleanup_end = compiler_new_block(c); cleanup_body = compiler_new_block(c); if (!(cleanup_end || cleanup_body)) return 0; compiler_nameop(c, handler->v.ExceptHandler.name, Store); ADDOP(c, POP_TOP); /* try: # body except type as name: try: # body finally: name = None del name */ /* second try: */ ADDOP_JREL(c, SETUP_FINALLY, cleanup_end); compiler_use_next_block(c, cleanup_body); if (!compiler_push_fblock(c, FINALLY_TRY, cleanup_body)) return 0; /* second # body */ VISIT_SEQ(c, stmt, handler->v.ExceptHandler.body); ADDOP(c, POP_BLOCK); ADDOP(c, POP_EXCEPT); compiler_pop_fblock(c, FINALLY_TRY, cleanup_body); /* finally: */ ADDOP_O(c, LOAD_CONST, Py_None, consts); compiler_use_next_block(c, cleanup_end); if (!compiler_push_fblock(c, FINALLY_END, cleanup_end)) return 0; /* name = None */ ADDOP_O(c, LOAD_CONST, Py_None, consts); compiler_nameop(c, handler->v.ExceptHandler.name, Store); /* del name */ compiler_nameop(c, handler->v.ExceptHandler.name, Del); ADDOP(c, END_FINALLY); compiler_pop_fblock(c, FINALLY_END, cleanup_end); } else { basicblock *cleanup_body; cleanup_body = compiler_new_block(c); if (!cleanup_body) return 0; ADDOP(c, POP_TOP); ADDOP(c, POP_TOP); compiler_use_next_block(c, cleanup_body); if (!compiler_push_fblock(c, FINALLY_TRY, cleanup_body)) return 0; VISIT_SEQ(c, stmt, handler->v.ExceptHandler.body); ADDOP(c, POP_EXCEPT); compiler_pop_fblock(c, FINALLY_TRY, cleanup_body); } ADDOP_JREL(c, JUMP_FORWARD, end); compiler_use_next_block(c, except); } ADDOP(c, END_FINALLY); compiler_use_next_block(c, orelse); VISIT_SEQ(c, stmt, s->v.Try.orelse); compiler_use_next_block(c, end); return 1; } static int compiler_try(struct compiler *c, stmt_ty s) { if (s->v.Try.finalbody && asdl_seq_LEN(s->v.Try.finalbody)) return compiler_try_finally(c, s); else return compiler_try_except(c, s); } static int compiler_import_as(struct compiler *c, identifier name, identifier asname) { /* The IMPORT_NAME opcode was already generated. This function merely needs to bind the result to a name. If there is a dot in name, we need to split it and emit a LOAD_ATTR for each name. */ Py_ssize_t dot = PyUnicode_FindChar(name, '.', 0, PyUnicode_GET_LENGTH(name), 1); if (dot == -2) return -1; if (dot != -1) { /* Consume the base module name to get the first attribute */ Py_ssize_t pos = dot + 1; while (dot != -1) { PyObject *attr; dot = PyUnicode_FindChar(name, '.', pos, PyUnicode_GET_LENGTH(name), 1); if (dot == -2) return -1; attr = PyUnicode_Substring(name, pos, (dot != -1) ? dot : PyUnicode_GET_LENGTH(name)); if (!attr) return -1; ADDOP_O(c, LOAD_ATTR, attr, names); Py_DECREF(attr); pos = dot + 1; } } return compiler_nameop(c, asname, Store); } static int compiler_import(struct compiler *c, stmt_ty s) { /* The Import node stores a module name like a.b.c as a single string. This is convenient for all cases except import a.b.c as d where we need to parse that string to extract the individual module names. XXX Perhaps change the representation to make this case simpler? */ Py_ssize_t i, n = asdl_seq_LEN(s->v.Import.names); for (i = 0; i < n; i++) { alias_ty alias = (alias_ty)asdl_seq_GET(s->v.Import.names, i); int r; PyObject *level; level = PyLong_FromLong(0); if (level == NULL) return 0; ADDOP_O(c, LOAD_CONST, level, consts); Py_DECREF(level); ADDOP_O(c, LOAD_CONST, Py_None, consts); ADDOP_NAME(c, IMPORT_NAME, alias->name, names); if (alias->asname) { r = compiler_import_as(c, alias->name, alias->asname); if (!r) return r; } else { identifier tmp = alias->name; Py_ssize_t dot = PyUnicode_FindChar( alias->name, '.', 0, PyUnicode_GET_LENGTH(alias->name), 1); if (dot != -1) { tmp = PyUnicode_Substring(alias->name, 0, dot); if (tmp == NULL) return 0; } r = compiler_nameop(c, tmp, Store); if (dot != -1) { Py_DECREF(tmp); } if (!r) return r; } } return 1; } static int compiler_from_import(struct compiler *c, stmt_ty s) { Py_ssize_t i, n = asdl_seq_LEN(s->v.ImportFrom.names); PyObject *names = PyTuple_New(n); PyObject *level; static PyObject *empty_string; if (!empty_string) { empty_string = PyUnicode_FromString(""); if (!empty_string) return 0; } if (!names) return 0; level = PyLong_FromLong(s->v.ImportFrom.level); if (!level) { Py_DECREF(names); return 0; } /* build up the names */ for (i = 0; i < n; i++) { alias_ty alias = (alias_ty)asdl_seq_GET(s->v.ImportFrom.names, i); Py_INCREF(alias->name); PyTuple_SET_ITEM(names, i, alias->name); } if (s->lineno > c->c_future->ff_lineno && s->v.ImportFrom.module && !PyUnicode_CompareWithASCIIString(s->v.ImportFrom.module, "__future__")) { Py_DECREF(level); Py_DECREF(names); return compiler_error(c, "from __future__ imports must occur " "at the beginning of the file"); } ADDOP_O(c, LOAD_CONST, level, consts); Py_DECREF(level); ADDOP_O(c, LOAD_CONST, names, consts); Py_DECREF(names); if (s->v.ImportFrom.module) { ADDOP_NAME(c, IMPORT_NAME, s->v.ImportFrom.module, names); } else { ADDOP_NAME(c, IMPORT_NAME, empty_string, names); } for (i = 0; i < n; i++) { alias_ty alias = (alias_ty)asdl_seq_GET(s->v.ImportFrom.names, i); identifier store_name; if (i == 0 && PyUnicode_READ_CHAR(alias->name, 0) == '*') { assert(n == 1); ADDOP(c, IMPORT_STAR); return 1; } ADDOP_NAME(c, IMPORT_FROM, alias->name, names); store_name = alias->name; if (alias->asname) store_name = alias->asname; if (!compiler_nameop(c, store_name, Store)) { Py_DECREF(names); return 0; } } /* remove imported module */ ADDOP(c, POP_TOP); return 1; } static int compiler_assert(struct compiler *c, stmt_ty s) { static PyObject *assertion_error = NULL; basicblock *end; PyObject* msg; if (c->c_optimize) return 1; if (assertion_error == NULL) { assertion_error = PyUnicode_InternFromString("AssertionError"); if (assertion_error == NULL) return 0; } if (s->v.Assert.test->kind == Tuple_kind && asdl_seq_LEN(s->v.Assert.test->v.Tuple.elts) > 0) { msg = PyUnicode_FromString("assertion is always true, " "perhaps remove parentheses?"); if (msg == NULL) return 0; if (PyErr_WarnExplicitObject(PyExc_SyntaxWarning, msg, c->c_filename, c->u->u_lineno, NULL, NULL) == -1) { Py_DECREF(msg); return 0; } Py_DECREF(msg); } VISIT(c, expr, s->v.Assert.test); end = compiler_new_block(c); if (end == NULL) return 0; ADDOP_JABS(c, POP_JUMP_IF_TRUE, end); ADDOP_O(c, LOAD_GLOBAL, assertion_error, names); if (s->v.Assert.msg) { VISIT(c, expr, s->v.Assert.msg); ADDOP_I(c, CALL_FUNCTION, 1); } ADDOP_I(c, RAISE_VARARGS, 1); compiler_use_next_block(c, end); return 1; } static int compiler_visit_stmt(struct compiler *c, stmt_ty s) { Py_ssize_t i, n; /* Always assign a lineno to the next instruction for a stmt. */ c->u->u_lineno = s->lineno; c->u->u_col_offset = s->col_offset; c->u->u_lineno_set = 0; switch (s->kind) { case FunctionDef_kind: return compiler_function(c, s); case ClassDef_kind: return compiler_class(c, s); case Return_kind: if (c->u->u_ste->ste_type != FunctionBlock) return compiler_error(c, "'return' outside function"); if (s->v.Return.value) { VISIT(c, expr, s->v.Return.value); } else ADDOP_O(c, LOAD_CONST, Py_None, consts); ADDOP(c, RETURN_VALUE); break; case Delete_kind: VISIT_SEQ(c, expr, s->v.Delete.targets) break; case Assign_kind: n = asdl_seq_LEN(s->v.Assign.targets); VISIT(c, expr, s->v.Assign.value); for (i = 0; i < n; i++) { if (i < n - 1) ADDOP(c, DUP_TOP); VISIT(c, expr, (expr_ty)asdl_seq_GET(s->v.Assign.targets, i)); } break; case AugAssign_kind: return compiler_augassign(c, s); case For_kind: return compiler_for(c, s); case While_kind: return compiler_while(c, s); case If_kind: return compiler_if(c, s); case Raise_kind: n = 0; if (s->v.Raise.exc) { VISIT(c, expr, s->v.Raise.exc); n++; if (s->v.Raise.cause) { VISIT(c, expr, s->v.Raise.cause); n++; } } ADDOP_I(c, RAISE_VARARGS, (int)n); break; case Try_kind: return compiler_try(c, s); case Assert_kind: return compiler_assert(c, s); case Import_kind: return compiler_import(c, s); case ImportFrom_kind: return compiler_from_import(c, s); case Global_kind: case Nonlocal_kind: break; case Expr_kind: if (c->c_interactive && c->c_nestlevel <= 1) { VISIT(c, expr, s->v.Expr.value); ADDOP(c, PRINT_EXPR); } else if (s->v.Expr.value->kind != Str_kind && s->v.Expr.value->kind != Num_kind) { VISIT(c, expr, s->v.Expr.value); ADDOP(c, POP_TOP); } break; case Pass_kind: break; case Break_kind: if (!compiler_in_loop(c)) return compiler_error(c, "'break' outside loop"); ADDOP(c, BREAK_LOOP); break; case Continue_kind: return compiler_continue(c); case With_kind: return compiler_with(c, s, 0); } return 1; } static int unaryop(unaryop_ty op) { switch (op) { case Invert: return UNARY_INVERT; case Not: return UNARY_NOT; case UAdd: return UNARY_POSITIVE; case USub: return UNARY_NEGATIVE; default: PyErr_Format(PyExc_SystemError, "unary op %d should not be possible", op); return 0; } } static int binop(struct compiler *c, operator_ty op) { switch (op) { case Add: return BINARY_ADD; case Sub: return BINARY_SUBTRACT; case Mult: return BINARY_MULTIPLY; case MatMult: return BINARY_MATRIX_MULTIPLY; case Div: return BINARY_TRUE_DIVIDE; case Mod: return BINARY_MODULO; case Pow: return BINARY_POWER; case LShift: return BINARY_LSHIFT; case RShift: return BINARY_RSHIFT; case BitOr: return BINARY_OR; case BitXor: return BINARY_XOR; case BitAnd: return BINARY_AND; case FloorDiv: return BINARY_FLOOR_DIVIDE; default: PyErr_Format(PyExc_SystemError, "binary op %d should not be possible", op); return 0; } } static int cmpop(cmpop_ty op) { switch (op) { case Eq: return PyCmp_EQ; case NotEq: return PyCmp_NE; case Lt: return PyCmp_LT; case LtE: return PyCmp_LE; case Gt: return PyCmp_GT; case GtE: return PyCmp_GE; case Is: return PyCmp_IS; case IsNot: return PyCmp_IS_NOT; case In: return PyCmp_IN; case NotIn: return PyCmp_NOT_IN; default: return PyCmp_BAD; } } static int inplace_binop(struct compiler *c, operator_ty op) { switch (op) { case Add: return INPLACE_ADD; case Sub: return INPLACE_SUBTRACT; case Mult: return INPLACE_MULTIPLY; case MatMult: return INPLACE_MATRIX_MULTIPLY; case Div: return INPLACE_TRUE_DIVIDE; case Mod: return INPLACE_MODULO; case Pow: return INPLACE_POWER; case LShift: return INPLACE_LSHIFT; case RShift: return INPLACE_RSHIFT; case BitOr: return INPLACE_OR; case BitXor: return INPLACE_XOR; case BitAnd: return INPLACE_AND; case FloorDiv: return INPLACE_FLOOR_DIVIDE; default: PyErr_Format(PyExc_SystemError, "inplace binary op %d should not be possible", op); return 0; } } static int compiler_nameop(struct compiler *c, identifier name, expr_context_ty ctx) { int op, scope; Py_ssize_t arg; enum { OP_FAST, OP_GLOBAL, OP_DEREF, OP_NAME } optype; PyObject *dict = c->u->u_names; PyObject *mangled; /* XXX AugStore isn't used anywhere! */ mangled = _Py_Mangle(c->u->u_private, name); if (!mangled) return 0; assert(PyUnicode_CompareWithASCIIString(name, "None") && PyUnicode_CompareWithASCIIString(name, "True") && PyUnicode_CompareWithASCIIString(name, "False")); op = 0; optype = OP_NAME; scope = PyST_GetScope(c->u->u_ste, mangled); switch (scope) { case FREE: dict = c->u->u_freevars; optype = OP_DEREF; break; case CELL: dict = c->u->u_cellvars; optype = OP_DEREF; break; case LOCAL: if (c->u->u_ste->ste_type == FunctionBlock) optype = OP_FAST; break; case GLOBAL_IMPLICIT: if (c->u->u_ste->ste_type == FunctionBlock && !c->u->u_ste->ste_unoptimized) optype = OP_GLOBAL; break; case GLOBAL_EXPLICIT: optype = OP_GLOBAL; break; default: /* scope can be 0 */ break; } /* XXX Leave assert here, but handle __doc__ and the like better */ assert(scope || PyUnicode_READ_CHAR(name, 0) == '_'); switch (optype) { case OP_DEREF: switch (ctx) { case Load: op = (c->u->u_ste->ste_type == ClassBlock) ? LOAD_CLASSDEREF : LOAD_DEREF; break; case Store: op = STORE_DEREF; break; case AugLoad: case AugStore: break; case Del: op = DELETE_DEREF; break; case Param: default: PyErr_SetString(PyExc_SystemError, "param invalid for deref variable"); return 0; } break; case OP_FAST: switch (ctx) { case Load: op = LOAD_FAST; break; case Store: op = STORE_FAST; break; case Del: op = DELETE_FAST; break; case AugLoad: case AugStore: break; case Param: default: PyErr_SetString(PyExc_SystemError, "param invalid for local variable"); return 0; } ADDOP_O(c, op, mangled, varnames); Py_DECREF(mangled); return 1; case OP_GLOBAL: switch (ctx) { case Load: op = LOAD_GLOBAL; break; case Store: op = STORE_GLOBAL; break; case Del: op = DELETE_GLOBAL; break; case AugLoad: case AugStore: break; case Param: default: PyErr_SetString(PyExc_SystemError, "param invalid for global variable"); return 0; } break; case OP_NAME: switch (ctx) { case Load: op = LOAD_NAME; break; case Store: op = STORE_NAME; break; case Del: op = DELETE_NAME; break; case AugLoad: case AugStore: break; case Param: default: PyErr_SetString(PyExc_SystemError, "param invalid for name variable"); return 0; } break; } assert(op); arg = compiler_add_o(c, dict, mangled); Py_DECREF(mangled); if (arg < 0) return 0; return compiler_addop_i(c, op, arg); } static int compiler_boolop(struct compiler *c, expr_ty e) { basicblock *end; int jumpi; Py_ssize_t i, n; asdl_seq *s; assert(e->kind == BoolOp_kind); if (e->v.BoolOp.op == And) jumpi = JUMP_IF_FALSE_OR_POP; else jumpi = JUMP_IF_TRUE_OR_POP; end = compiler_new_block(c); if (end == NULL) return 0; s = e->v.BoolOp.values; n = asdl_seq_LEN(s) - 1; assert(n >= 0); for (i = 0; i < n; ++i) { VISIT(c, expr, (expr_ty)asdl_seq_GET(s, i)); ADDOP_JABS(c, jumpi, end); } VISIT(c, expr, (expr_ty)asdl_seq_GET(s, n)); compiler_use_next_block(c, end); return 1; } static int compiler_list(struct compiler *c, expr_ty e) { Py_ssize_t n = asdl_seq_LEN(e->v.List.elts); if (e->v.List.ctx == Store) { int i, seen_star = 0; for (i = 0; i < n; i++) { expr_ty elt = asdl_seq_GET(e->v.List.elts, i); if (elt->kind == Starred_kind && !seen_star) { if ((i >= (1 << 8)) || (n-i-1 >= (INT_MAX >> 8))) return compiler_error(c, "too many expressions in " "star-unpacking assignment"); ADDOP_I(c, UNPACK_EX, (i + ((n-i-1) << 8))); seen_star = 1; asdl_seq_SET(e->v.List.elts, i, elt->v.Starred.value); } else if (elt->kind == Starred_kind) { return compiler_error(c, "two starred expressions in assignment"); } } if (!seen_star) { ADDOP_I(c, UNPACK_SEQUENCE, n); } } VISIT_SEQ(c, expr, e->v.List.elts); if (e->v.List.ctx == Load) { ADDOP_I(c, BUILD_LIST, n); } return 1; } static int compiler_tuple(struct compiler *c, expr_ty e) { Py_ssize_t n = asdl_seq_LEN(e->v.Tuple.elts); if (e->v.Tuple.ctx == Store) { int i, seen_star = 0; for (i = 0; i < n; i++) { expr_ty elt = asdl_seq_GET(e->v.Tuple.elts, i); if (elt->kind == Starred_kind && !seen_star) { if ((i >= (1 << 8)) || (n-i-1 >= (INT_MAX >> 8))) return compiler_error(c, "too many expressions in " "star-unpacking assignment"); ADDOP_I(c, UNPACK_EX, (i + ((n-i-1) << 8))); seen_star = 1; asdl_seq_SET(e->v.Tuple.elts, i, elt->v.Starred.value); } else if (elt->kind == Starred_kind) { return compiler_error(c, "two starred expressions in assignment"); } } if (!seen_star) { ADDOP_I(c, UNPACK_SEQUENCE, n); } } VISIT_SEQ(c, expr, e->v.Tuple.elts); if (e->v.Tuple.ctx == Load) { ADDOP_I(c, BUILD_TUPLE, n); } return 1; } static int compiler_compare(struct compiler *c, expr_ty e) { Py_ssize_t i, n; basicblock *cleanup = NULL; /* XXX the logic can be cleaned up for 1 or multiple comparisons */ VISIT(c, expr, e->v.Compare.left); n = asdl_seq_LEN(e->v.Compare.ops); assert(n > 0); if (n > 1) { cleanup = compiler_new_block(c); if (cleanup == NULL) return 0; VISIT(c, expr, (expr_ty)asdl_seq_GET(e->v.Compare.comparators, 0)); } for (i = 1; i < n; i++) { ADDOP(c, DUP_TOP); ADDOP(c, ROT_THREE); ADDOP_I(c, COMPARE_OP, cmpop((cmpop_ty)(asdl_seq_GET( e->v.Compare.ops, i - 1)))); ADDOP_JABS(c, JUMP_IF_FALSE_OR_POP, cleanup); NEXT_BLOCK(c); if (i < (n - 1)) VISIT(c, expr, (expr_ty)asdl_seq_GET(e->v.Compare.comparators, i)); } VISIT(c, expr, (expr_ty)asdl_seq_GET(e->v.Compare.comparators, n - 1)); ADDOP_I(c, COMPARE_OP, cmpop((cmpop_ty)(asdl_seq_GET(e->v.Compare.ops, n - 1)))); if (n > 1) { basicblock *end = compiler_new_block(c); if (end == NULL) return 0; ADDOP_JREL(c, JUMP_FORWARD, end); compiler_use_next_block(c, cleanup); ADDOP(c, ROT_TWO); ADDOP(c, POP_TOP); compiler_use_next_block(c, end); } return 1; } static int compiler_call(struct compiler *c, expr_ty e) { VISIT(c, expr, e->v.Call.func); return compiler_call_helper(c, 0, e->v.Call.args, e->v.Call.keywords, e->v.Call.starargs, e->v.Call.kwargs); } /* shared code between compiler_call and compiler_class */ static int compiler_call_helper(struct compiler *c, Py_ssize_t n, /* Args already pushed */ asdl_seq *args, asdl_seq *keywords, expr_ty starargs, expr_ty kwargs) { int code = 0; n += asdl_seq_LEN(args); VISIT_SEQ(c, expr, args); if (keywords) { VISIT_SEQ(c, keyword, keywords); n |= asdl_seq_LEN(keywords) << 8; } if (starargs) { VISIT(c, expr, starargs); code |= 1; } if (kwargs) { VISIT(c, expr, kwargs); code |= 2; } switch (code) { case 0: ADDOP_I(c, CALL_FUNCTION, n); break; case 1: ADDOP_I(c, CALL_FUNCTION_VAR, n); break; case 2: ADDOP_I(c, CALL_FUNCTION_KW, n); break; case 3: ADDOP_I(c, CALL_FUNCTION_VAR_KW, n); break; } return 1; } /* List and set comprehensions and generator expressions work by creating a nested function to perform the actual iteration. This means that the iteration variables don't leak into the current scope. The defined function is called immediately following its definition, with the result of that call being the result of the expression. The LC/SC version returns the populated container, while the GE version is flagged in symtable.c as a generator, so it returns the generator object when the function is called. This code *knows* that the loop cannot contain break, continue, or return, so it cheats and skips the SETUP_LOOP/POP_BLOCK steps used in normal loops. Possible cleanups: - iterate over the generator sequence instead of using recursion */ static int compiler_comprehension_generator(struct compiler *c, asdl_seq *generators, int gen_index, expr_ty elt, expr_ty val, int type) { /* generate code for the iterator, then each of the ifs, and then write to the element */ comprehension_ty gen; basicblock *start, *anchor, *skip, *if_cleanup; Py_ssize_t i, n; start = compiler_new_block(c); skip = compiler_new_block(c); if_cleanup = compiler_new_block(c); anchor = compiler_new_block(c); if (start == NULL || skip == NULL || if_cleanup == NULL || anchor == NULL) return 0; gen = (comprehension_ty)asdl_seq_GET(generators, gen_index); if (gen_index == 0) { /* Receive outermost iter as an implicit argument */ c->u->u_argcount = 1; ADDOP_I(c, LOAD_FAST, 0); } else { /* Sub-iter - calculate on the fly */ VISIT(c, expr, gen->iter); ADDOP(c, GET_ITER); } compiler_use_next_block(c, start); ADDOP_JREL(c, FOR_ITER, anchor); NEXT_BLOCK(c); VISIT(c, expr, gen->target); /* XXX this needs to be cleaned up...a lot! */ n = asdl_seq_LEN(gen->ifs); for (i = 0; i < n; i++) { expr_ty e = (expr_ty)asdl_seq_GET(gen->ifs, i); VISIT(c, expr, e); ADDOP_JABS(c, POP_JUMP_IF_FALSE, if_cleanup); NEXT_BLOCK(c); } if (++gen_index < asdl_seq_LEN(generators)) if (!compiler_comprehension_generator(c, generators, gen_index, elt, val, type)) return 0; /* only append after the last for generator */ if (gen_index >= asdl_seq_LEN(generators)) { /* comprehension specific code */ switch (type) { case COMP_GENEXP: VISIT(c, expr, elt); ADDOP(c, YIELD_VALUE); ADDOP(c, POP_TOP); break; case COMP_LISTCOMP: VISIT(c, expr, elt); ADDOP_I(c, LIST_APPEND, gen_index + 1); break; case COMP_SETCOMP: VISIT(c, expr, elt); ADDOP_I(c, SET_ADD, gen_index + 1); break; case COMP_DICTCOMP: /* With 'd[k] = v', v is evaluated before k, so we do the same. */ VISIT(c, expr, val); VISIT(c, expr, elt); ADDOP_I(c, MAP_ADD, gen_index + 1); break; default: return 0; } compiler_use_next_block(c, skip); } compiler_use_next_block(c, if_cleanup); ADDOP_JABS(c, JUMP_ABSOLUTE, start); compiler_use_next_block(c, anchor); return 1; } static int compiler_comprehension(struct compiler *c, expr_ty e, int type, identifier name, asdl_seq *generators, expr_ty elt, expr_ty val) { PyCodeObject *co = NULL; expr_ty outermost_iter; PyObject *qualname = NULL; outermost_iter = ((comprehension_ty) asdl_seq_GET(generators, 0))->iter; if (!compiler_enter_scope(c, name, COMPILER_SCOPE_COMPREHENSION, (void *)e, e->lineno)) goto error; if (type != COMP_GENEXP) { int op; switch (type) { case COMP_LISTCOMP: op = BUILD_LIST; break; case COMP_SETCOMP: op = BUILD_SET; break; case COMP_DICTCOMP: op = BUILD_MAP; break; default: PyErr_Format(PyExc_SystemError, "unknown comprehension type %d", type); goto error_in_scope; } ADDOP_I(c, op, 0); } if (!compiler_comprehension_generator(c, generators, 0, elt, val, type)) goto error_in_scope; if (type != COMP_GENEXP) { ADDOP(c, RETURN_VALUE); } co = assemble(c, 1); qualname = c->u->u_qualname; Py_INCREF(qualname); compiler_exit_scope(c); if (co == NULL) goto error; if (!compiler_make_closure(c, co, 0, qualname)) goto error; Py_DECREF(qualname); Py_DECREF(co); VISIT(c, expr, outermost_iter); ADDOP(c, GET_ITER); ADDOP_I(c, CALL_FUNCTION, 1); return 1; error_in_scope: compiler_exit_scope(c); error: Py_XDECREF(qualname); Py_XDECREF(co); return 0; } static int compiler_genexp(struct compiler *c, expr_ty e) { static identifier name; if (!name) { name = PyUnicode_FromString("<genexpr>"); if (!name) return 0; } assert(e->kind == GeneratorExp_kind); return compiler_comprehension(c, e, COMP_GENEXP, name, e->v.GeneratorExp.generators, e->v.GeneratorExp.elt, NULL); } static int compiler_listcomp(struct compiler *c, expr_ty e) { static identifier name; if (!name) { name = PyUnicode_FromString("<listcomp>"); if (!name) return 0; } assert(e->kind == ListComp_kind); return compiler_comprehension(c, e, COMP_LISTCOMP, name, e->v.ListComp.generators, e->v.ListComp.elt, NULL); } static int compiler_setcomp(struct compiler *c, expr_ty e) { static identifier name; if (!name) { name = PyUnicode_FromString("<setcomp>"); if (!name) return 0; } assert(e->kind == SetComp_kind); return compiler_comprehension(c, e, COMP_SETCOMP, name, e->v.SetComp.generators, e->v.SetComp.elt, NULL); } static int compiler_dictcomp(struct compiler *c, expr_ty e) { static identifier name; if (!name) { name = PyUnicode_FromString("<dictcomp>"); if (!name) return 0; } assert(e->kind == DictComp_kind); return compiler_comprehension(c, e, COMP_DICTCOMP, name, e->v.DictComp.generators, e->v.DictComp.key, e->v.DictComp.value); } static int compiler_visit_keyword(struct compiler *c, keyword_ty k) { ADDOP_O(c, LOAD_CONST, k->arg, consts); VISIT(c, expr, k->value); return 1; } /* Test whether expression is constant. For constants, report whether they are true or false. Return values: 1 for true, 0 for false, -1 for non-constant. */ static int expr_constant(struct compiler *c, expr_ty e) { char *id; switch (e->kind) { case Ellipsis_kind: return 1; case Num_kind: return PyObject_IsTrue(e->v.Num.n); case Str_kind: return PyObject_IsTrue(e->v.Str.s); case Name_kind: /* optimize away names that can't be reassigned */ id = PyUnicode_AsUTF8(e->v.Name.id); if (id && strcmp(id, "__debug__") == 0) return !c->c_optimize; return -1; case NameConstant_kind: { PyObject *o = e->v.NameConstant.value; if (o == Py_None) return 0; else if (o == Py_True) return 1; else if (o == Py_False) return 0; } default: return -1; } } /* Implements the with statement from PEP 343. The semantics outlined in that PEP are as follows: with EXPR as VAR: BLOCK It is implemented roughly as: context = EXPR exit = context.__exit__ # not calling it value = context.__enter__() try: VAR = value # if VAR present in the syntax BLOCK finally: if an exception was raised: exc = copy of (exception, instance, traceback) else: exc = (None, None, None) exit(*exc) */ static int compiler_with(struct compiler *c, stmt_ty s, int pos) { basicblock *block, *finally; withitem_ty item = asdl_seq_GET(s->v.With.items, pos); assert(s->kind == With_kind); block = compiler_new_block(c); finally = compiler_new_block(c); if (!block || !finally) return 0; /* Evaluate EXPR */ VISIT(c, expr, item->context_expr); ADDOP_JREL(c, SETUP_WITH, finally); /* SETUP_WITH pushes a finally block. */ compiler_use_next_block(c, block); if (!compiler_push_fblock(c, FINALLY_TRY, block)) { return 0; } if (item->optional_vars) { VISIT(c, expr, item->optional_vars); } else { /* Discard result from context.__enter__() */ ADDOP(c, POP_TOP); } pos++; if (pos == asdl_seq_LEN(s->v.With.items)) /* BLOCK code */ VISIT_SEQ(c, stmt, s->v.With.body) else if (!compiler_with(c, s, pos)) return 0; /* End of try block; start the finally block */ ADDOP(c, POP_BLOCK); compiler_pop_fblock(c, FINALLY_TRY, block); ADDOP_O(c, LOAD_CONST, Py_None, consts); compiler_use_next_block(c, finally); if (!compiler_push_fblock(c, FINALLY_END, finally)) return 0; /* Finally block starts; context.__exit__ is on the stack under the exception or return information. Just issue our magic opcode. */ ADDOP(c, WITH_CLEANUP); /* Finally block ends. */ ADDOP(c, END_FINALLY); compiler_pop_fblock(c, FINALLY_END, finally); return 1; } static int compiler_visit_expr(struct compiler *c, expr_ty e) { Py_ssize_t i, n; /* If expr e has a different line number than the last expr/stmt, set a new line number for the next instruction. */ if (e->lineno > c->u->u_lineno) { c->u->u_lineno = e->lineno; c->u->u_lineno_set = 0; } /* Updating the column offset is always harmless. */ c->u->u_col_offset = e->col_offset; switch (e->kind) { case BoolOp_kind: return compiler_boolop(c, e); case BinOp_kind: VISIT(c, expr, e->v.BinOp.left); VISIT(c, expr, e->v.BinOp.right); ADDOP(c, binop(c, e->v.BinOp.op)); break; case UnaryOp_kind: VISIT(c, expr, e->v.UnaryOp.operand); ADDOP(c, unaryop(e->v.UnaryOp.op)); break; case Lambda_kind: return compiler_lambda(c, e); case IfExp_kind: return compiler_ifexp(c, e); case Dict_kind: n = asdl_seq_LEN(e->v.Dict.values); /* BUILD_MAP parameter is only used to preallocate the dictionary, it doesn't need to be exact */ ADDOP_I(c, BUILD_MAP, (n>0xFFFF ? 0xFFFF : n)); for (i = 0; i < n; i++) { VISIT(c, expr, (expr_ty)asdl_seq_GET(e->v.Dict.values, i)); VISIT(c, expr, (expr_ty)asdl_seq_GET(e->v.Dict.keys, i)); ADDOP(c, STORE_MAP); } break; case Set_kind: n = asdl_seq_LEN(e->v.Set.elts); VISIT_SEQ(c, expr, e->v.Set.elts); ADDOP_I(c, BUILD_SET, n); break; case GeneratorExp_kind: return compiler_genexp(c, e); case ListComp_kind: return compiler_listcomp(c, e); case SetComp_kind: return compiler_setcomp(c, e); case DictComp_kind: return compiler_dictcomp(c, e); case Yield_kind: if (c->u->u_ste->ste_type != FunctionBlock) return compiler_error(c, "'yield' outside function"); if (e->v.Yield.value) { VISIT(c, expr, e->v.Yield.value); } else { ADDOP_O(c, LOAD_CONST, Py_None, consts); } ADDOP(c, YIELD_VALUE); break; case YieldFrom_kind: if (c->u->u_ste->ste_type != FunctionBlock) return compiler_error(c, "'yield' outside function"); VISIT(c, expr, e->v.YieldFrom.value); ADDOP(c, GET_ITER); ADDOP_O(c, LOAD_CONST, Py_None, consts); ADDOP(c, YIELD_FROM); break; case Compare_kind: return compiler_compare(c, e); case Call_kind: return compiler_call(c, e); case Num_kind: ADDOP_O(c, LOAD_CONST, e->v.Num.n, consts); break; case Str_kind: ADDOP_O(c, LOAD_CONST, e->v.Str.s, consts); break; case Bytes_kind: ADDOP_O(c, LOAD_CONST, e->v.Bytes.s, consts); break; case Ellipsis_kind: ADDOP_O(c, LOAD_CONST, Py_Ellipsis, consts); break; case NameConstant_kind: ADDOP_O(c, LOAD_CONST, e->v.NameConstant.value, consts); break; /* The following exprs can be assignment targets. */ case Attribute_kind: if (e->v.Attribute.ctx != AugStore) VISIT(c, expr, e->v.Attribute.value); switch (e->v.Attribute.ctx) { case AugLoad: ADDOP(c, DUP_TOP); /* Fall through to load */ case Load: ADDOP_NAME(c, LOAD_ATTR, e->v.Attribute.attr, names); break; case AugStore: ADDOP(c, ROT_TWO); /* Fall through to save */ case Store: ADDOP_NAME(c, STORE_ATTR, e->v.Attribute.attr, names); break; case Del: ADDOP_NAME(c, DELETE_ATTR, e->v.Attribute.attr, names); break; case Param: default: PyErr_SetString(PyExc_SystemError, "param invalid in attribute expression"); return 0; } break; case Subscript_kind: switch (e->v.Subscript.ctx) { case AugLoad: VISIT(c, expr, e->v.Subscript.value); VISIT_SLICE(c, e->v.Subscript.slice, AugLoad); break; case Load: VISIT(c, expr, e->v.Subscript.value); VISIT_SLICE(c, e->v.Subscript.slice, Load); break; case AugStore: VISIT_SLICE(c, e->v.Subscript.slice, AugStore); break; case Store: VISIT(c, expr, e->v.Subscript.value); VISIT_SLICE(c, e->v.Subscript.slice, Store); break; case Del: VISIT(c, expr, e->v.Subscript.value); VISIT_SLICE(c, e->v.Subscript.slice, Del); break; case Param: default: PyErr_SetString(PyExc_SystemError, "param invalid in subscript expression"); return 0; } break; case Starred_kind: switch (e->v.Starred.ctx) { case Store: /* In all legitimate cases, the Starred node was already replaced * by compiler_list/compiler_tuple. XXX: is that okay? */ return compiler_error(c, "starred assignment target must be in a list or tuple"); default: return compiler_error(c, "can use starred expression only as assignment target"); } break; case Name_kind: return compiler_nameop(c, e->v.Name.id, e->v.Name.ctx); /* child nodes of List and Tuple will have expr_context set */ case List_kind: return compiler_list(c, e); case Tuple_kind: return compiler_tuple(c, e); } return 1; } static int compiler_augassign(struct compiler *c, stmt_ty s) { expr_ty e = s->v.AugAssign.target; expr_ty auge; assert(s->kind == AugAssign_kind); switch (e->kind) { case Attribute_kind: auge = Attribute(e->v.Attribute.value, e->v.Attribute.attr, AugLoad, e->lineno, e->col_offset, c->c_arena); if (auge == NULL) return 0; VISIT(c, expr, auge); VISIT(c, expr, s->v.AugAssign.value); ADDOP(c, inplace_binop(c, s->v.AugAssign.op)); auge->v.Attribute.ctx = AugStore; VISIT(c, expr, auge); break; case Subscript_kind: auge = Subscript(e->v.Subscript.value, e->v.Subscript.slice, AugLoad, e->lineno, e->col_offset, c->c_arena); if (auge == NULL) return 0; VISIT(c, expr, auge); VISIT(c, expr, s->v.AugAssign.value); ADDOP(c, inplace_binop(c, s->v.AugAssign.op)); auge->v.Subscript.ctx = AugStore; VISIT(c, expr, auge); break; case Name_kind: if (!compiler_nameop(c, e->v.Name.id, Load)) return 0; VISIT(c, expr, s->v.AugAssign.value); ADDOP(c, inplace_binop(c, s->v.AugAssign.op)); return compiler_nameop(c, e->v.Name.id, Store); default: PyErr_Format(PyExc_SystemError, "invalid node type (%d) for augmented assignment", e->kind); return 0; } return 1; } static int compiler_push_fblock(struct compiler *c, enum fblocktype t, basicblock *b) { struct fblockinfo *f; if (c->u->u_nfblocks >= CO_MAXBLOCKS) { PyErr_SetString(PyExc_SystemError, "too many statically nested blocks"); return 0; } f = &c->u->u_fblock[c->u->u_nfblocks++]; f->fb_type = t; f->fb_block = b; return 1; } static void compiler_pop_fblock(struct compiler *c, enum fblocktype t, basicblock *b) { struct compiler_unit *u = c->u; assert(u->u_nfblocks > 0); u->u_nfblocks--; assert(u->u_fblock[u->u_nfblocks].fb_type == t); assert(u->u_fblock[u->u_nfblocks].fb_block == b); } static int compiler_in_loop(struct compiler *c) { int i; struct compiler_unit *u = c->u; for (i = 0; i < u->u_nfblocks; ++i) { if (u->u_fblock[i].fb_type == LOOP) return 1; } return 0; } /* Raises a SyntaxError and returns 0. If something goes wrong, a different exception may be raised. */ static int compiler_error(struct compiler *c, const char *errstr) { PyObject *loc; PyObject *u = NULL, *v = NULL; loc = PyErr_ProgramTextObject(c->c_filename, c->u->u_lineno); if (!loc) { Py_INCREF(Py_None); loc = Py_None; } u = Py_BuildValue("(OiiO)", c->c_filename, c->u->u_lineno, c->u->u_col_offset, loc); if (!u) goto exit; v = Py_BuildValue("(zO)", errstr, u); if (!v) goto exit; PyErr_SetObject(PyExc_SyntaxError, v); exit: Py_DECREF(loc); Py_XDECREF(u); Py_XDECREF(v); return 0; } static int compiler_handle_subscr(struct compiler *c, const char *kind, expr_context_ty ctx) { int op = 0; /* XXX this code is duplicated */ switch (ctx) { case AugLoad: /* fall through to Load */ case Load: op = BINARY_SUBSCR; break; case AugStore:/* fall through to Store */ case Store: op = STORE_SUBSCR; break; case Del: op = DELETE_SUBSCR; break; case Param: PyErr_Format(PyExc_SystemError, "invalid %s kind %d in subscript\n", kind, ctx); return 0; } if (ctx == AugLoad) { ADDOP(c, DUP_TOP_TWO); } else if (ctx == AugStore) { ADDOP(c, ROT_THREE); } ADDOP(c, op); return 1; } static int compiler_slice(struct compiler *c, slice_ty s, expr_context_ty ctx) { int n = 2; assert(s->kind == Slice_kind); /* only handles the cases where BUILD_SLICE is emitted */ if (s->v.Slice.lower) { VISIT(c, expr, s->v.Slice.lower); } else { ADDOP_O(c, LOAD_CONST, Py_None, consts); } if (s->v.Slice.upper) { VISIT(c, expr, s->v.Slice.upper); } else { ADDOP_O(c, LOAD_CONST, Py_None, consts); } if (s->v.Slice.step) { n++; VISIT(c, expr, s->v.Slice.step); } ADDOP_I(c, BUILD_SLICE, n); return 1; } static int compiler_visit_nested_slice(struct compiler *c, slice_ty s, expr_context_ty ctx) { switch (s->kind) { case Slice_kind: return compiler_slice(c, s, ctx); case Index_kind: VISIT(c, expr, s->v.Index.value); break; case ExtSlice_kind: default: PyErr_SetString(PyExc_SystemError, "extended slice invalid in nested slice"); return 0; } return 1; } static int compiler_visit_slice(struct compiler *c, slice_ty s, expr_context_ty ctx) { char * kindname = NULL; switch (s->kind) { case Index_kind: kindname = "index"; if (ctx != AugStore) { VISIT(c, expr, s->v.Index.value); } break; case Slice_kind: kindname = "slice"; if (ctx != AugStore) { if (!compiler_slice(c, s, ctx)) return 0; } break; case ExtSlice_kind: kindname = "extended slice"; if (ctx != AugStore) { Py_ssize_t i, n = asdl_seq_LEN(s->v.ExtSlice.dims); for (i = 0; i < n; i++) { slice_ty sub = (slice_ty)asdl_seq_GET( s->v.ExtSlice.dims, i); if (!compiler_visit_nested_slice(c, sub, ctx)) return 0; } ADDOP_I(c, BUILD_TUPLE, n); } break; default: PyErr_Format(PyExc_SystemError, "invalid subscript kind %d", s->kind); return 0; } return compiler_handle_subscr(c, kindname, ctx); } /* End of the compiler section, beginning of the assembler section */ /* do depth-first search of basic block graph, starting with block. post records the block indices in post-order. XXX must handle implicit jumps from one block to next */ struct assembler { PyObject *a_bytecode; /* string containing bytecode */ int a_offset; /* offset into bytecode */ int a_nblocks; /* number of reachable blocks */ basicblock **a_postorder; /* list of blocks in dfs postorder */ PyObject *a_lnotab; /* string containing lnotab */ int a_lnotab_off; /* offset into lnotab */ int a_lineno; /* last lineno of emitted instruction */ int a_lineno_off; /* bytecode offset of last lineno */ }; static void dfs(struct compiler *c, basicblock *b, struct assembler *a) { int i; struct instr *instr = NULL; if (b->b_seen) return; b->b_seen = 1; if (b->b_next != NULL) dfs(c, b->b_next, a); for (i = 0; i < b->b_iused; i++) { instr = &b->b_instr[i]; if (instr->i_jrel || instr->i_jabs) dfs(c, instr->i_target, a); } a->a_postorder[a->a_nblocks++] = b; } static int stackdepth_walk(struct compiler *c, basicblock *b, int depth, int maxdepth) { int i, target_depth, effect; struct instr *instr; if (b->b_seen || b->b_startdepth >= depth) return maxdepth; b->b_seen = 1; b->b_startdepth = depth; for (i = 0; i < b->b_iused; i++) { instr = &b->b_instr[i]; effect = PyCompile_OpcodeStackEffect(instr->i_opcode, instr->i_oparg); if (effect == PY_INVALID_STACK_EFFECT) { fprintf(stderr, "opcode = %d\n", instr->i_opcode); Py_FatalError("PyCompile_OpcodeStackEffect()"); } depth += effect; if (depth > maxdepth) maxdepth = depth; assert(depth >= 0); /* invalid code or bug in stackdepth() */ if (instr->i_jrel || instr->i_jabs) { target_depth = depth; if (instr->i_opcode == FOR_ITER) { target_depth = depth-2; } else if (instr->i_opcode == SETUP_FINALLY || instr->i_opcode == SETUP_EXCEPT) { target_depth = depth+3; if (target_depth > maxdepth) maxdepth = target_depth; } else if (instr->i_opcode == JUMP_IF_TRUE_OR_POP || instr->i_opcode == JUMP_IF_FALSE_OR_POP) depth = depth - 1; maxdepth = stackdepth_walk(c, instr->i_target, target_depth, maxdepth); if (instr->i_opcode == JUMP_ABSOLUTE || instr->i_opcode == JUMP_FORWARD) { goto out; /* remaining code is dead */ } } } if (b->b_next) maxdepth = stackdepth_walk(c, b->b_next, depth, maxdepth); out: b->b_seen = 0; return maxdepth; } /* Find the flow path that needs the largest stack. We assume that * cycles in the flow graph have no net effect on the stack depth. */ static int stackdepth(struct compiler *c) { basicblock *b, *entryblock; entryblock = NULL; for (b = c->u->u_blocks; b != NULL; b = b->b_list) { b->b_seen = 0; b->b_startdepth = INT_MIN; entryblock = b; } if (!entryblock) return 0; return stackdepth_walk(c, entryblock, 0, 0); } static int assemble_init(struct assembler *a, int nblocks, int firstlineno) { memset(a, 0, sizeof(struct assembler)); a->a_lineno = firstlineno; a->a_bytecode = PyBytes_FromStringAndSize(NULL, DEFAULT_CODE_SIZE); if (!a->a_bytecode) return 0; a->a_lnotab = PyBytes_FromStringAndSize(NULL, DEFAULT_LNOTAB_SIZE); if (!a->a_lnotab) return 0; if ((size_t)nblocks > PY_SIZE_MAX / sizeof(basicblock *)) { PyErr_NoMemory(); return 0; } a->a_postorder = (basicblock **)PyObject_Malloc( sizeof(basicblock *) * nblocks); if (!a->a_postorder) { PyErr_NoMemory(); return 0; } return 1; } static void assemble_free(struct assembler *a) { Py_XDECREF(a->a_bytecode); Py_XDECREF(a->a_lnotab); if (a->a_postorder) PyObject_Free(a->a_postorder); } /* Return the size of a basic block in bytes. */ static int instrsize(struct instr *instr) { if (!instr->i_hasarg) return 1; /* 1 byte for the opcode*/ if (instr->i_oparg > 0xffff) return 6; /* 1 (opcode) + 1 (EXTENDED_ARG opcode) + 2 (oparg) + 2(oparg extended) */ return 3; /* 1 (opcode) + 2 (oparg) */ } static int blocksize(basicblock *b) { int i; int size = 0; for (i = 0; i < b->b_iused; i++) size += instrsize(&b->b_instr[i]); return size; } /* Appends a pair to the end of the line number table, a_lnotab, representing the instruction's bytecode offset and line number. See Objects/lnotab_notes.txt for the description of the line number table. */ static int assemble_lnotab(struct assembler *a, struct instr *i) { int d_bytecode, d_lineno; Py_ssize_t len; unsigned char *lnotab; d_bytecode = a->a_offset - a->a_lineno_off; d_lineno = i->i_lineno - a->a_lineno; assert(d_bytecode >= 0); assert(d_lineno >= 0); if(d_bytecode == 0 && d_lineno == 0) return 1; if (d_bytecode > 255) { int j, nbytes, ncodes = d_bytecode / 255; nbytes = a->a_lnotab_off + 2 * ncodes; len = PyBytes_GET_SIZE(a->a_lnotab); if (nbytes >= len) { if ((len <= INT_MAX / 2) && (len * 2 < nbytes)) len = nbytes; else if (len <= INT_MAX / 2) len *= 2; else { PyErr_NoMemory(); return 0; } if (_PyBytes_Resize(&a->a_lnotab, len) < 0) return 0; } lnotab = (unsigned char *) PyBytes_AS_STRING(a->a_lnotab) + a->a_lnotab_off; for (j = 0; j < ncodes; j++) { *lnotab++ = 255; *lnotab++ = 0; } d_bytecode -= ncodes * 255; a->a_lnotab_off += ncodes * 2; } assert(d_bytecode <= 255); if (d_lineno > 255) { int j, nbytes, ncodes = d_lineno / 255; nbytes = a->a_lnotab_off + 2 * ncodes; len = PyBytes_GET_SIZE(a->a_lnotab); if (nbytes >= len) { if ((len <= INT_MAX / 2) && len * 2 < nbytes) len = nbytes; else if (len <= INT_MAX / 2) len *= 2; else { PyErr_NoMemory(); return 0; } if (_PyBytes_Resize(&a->a_lnotab, len) < 0) return 0; } lnotab = (unsigned char *) PyBytes_AS_STRING(a->a_lnotab) + a->a_lnotab_off; *lnotab++ = d_bytecode; *lnotab++ = 255; d_bytecode = 0; for (j = 1; j < ncodes; j++) { *lnotab++ = 0; *lnotab++ = 255; } d_lineno -= ncodes * 255; a->a_lnotab_off += ncodes * 2; } len = PyBytes_GET_SIZE(a->a_lnotab); if (a->a_lnotab_off + 2 >= len) { if (_PyBytes_Resize(&a->a_lnotab, len * 2) < 0) return 0; } lnotab = (unsigned char *) PyBytes_AS_STRING(a->a_lnotab) + a->a_lnotab_off; a->a_lnotab_off += 2; if (d_bytecode) { *lnotab++ = d_bytecode; *lnotab++ = d_lineno; } else { /* First line of a block; def stmt, etc. */ *lnotab++ = 0; *lnotab++ = d_lineno; } a->a_lineno = i->i_lineno; a->a_lineno_off = a->a_offset; return 1; } /* assemble_emit() Extend the bytecode with a new instruction. Update lnotab if necessary. */ static int assemble_emit(struct assembler *a, struct instr *i) { int size, arg = 0, ext = 0; Py_ssize_t len = PyBytes_GET_SIZE(a->a_bytecode); char *code; size = instrsize(i); if (i->i_hasarg) { arg = i->i_oparg; ext = arg >> 16; } if (i->i_lineno && !assemble_lnotab(a, i)) return 0; if (a->a_offset + size >= len) { if (len > PY_SSIZE_T_MAX / 2) return 0; if (_PyBytes_Resize(&a->a_bytecode, len * 2) < 0) return 0; } code = PyBytes_AS_STRING(a->a_bytecode) + a->a_offset; a->a_offset += size; if (size == 6) { assert(i->i_hasarg); *code++ = (char)EXTENDED_ARG; *code++ = ext & 0xff; *code++ = ext >> 8; arg &= 0xffff; } *code++ = i->i_opcode; if (i->i_hasarg) { assert(size == 3 || size == 6); *code++ = arg & 0xff; *code++ = arg >> 8; } return 1; } static void assemble_jump_offsets(struct assembler *a, struct compiler *c) { basicblock *b; int bsize, totsize, extended_arg_count = 0, last_extended_arg_count; int i; /* Compute the size of each block and fixup jump args. Replace block pointer with position in bytecode. */ do { totsize = 0; for (i = a->a_nblocks - 1; i >= 0; i--) { b = a->a_postorder[i]; bsize = blocksize(b); b->b_offset = totsize; totsize += bsize; } last_extended_arg_count = extended_arg_count; extended_arg_count = 0; for (b = c->u->u_blocks; b != NULL; b = b->b_list) { bsize = b->b_offset; for (i = 0; i < b->b_iused; i++) { struct instr *instr = &b->b_instr[i]; /* Relative jumps are computed relative to the instruction pointer after fetching the jump instruction. */ bsize += instrsize(instr); if (instr->i_jabs) instr->i_oparg = instr->i_target->b_offset; else if (instr->i_jrel) { int delta = instr->i_target->b_offset - bsize; instr->i_oparg = delta; } else continue; if (instr->i_oparg > 0xffff) extended_arg_count++; } } /* XXX: This is an awful hack that could hurt performance, but on the bright side it should work until we come up with a better solution. The issue is that in the first loop blocksize() is called which calls instrsize() which requires i_oparg be set appropriately. There is a bootstrap problem because i_oparg is calculated in the second loop above. So we loop until we stop seeing new EXTENDED_ARGs. The only EXTENDED_ARGs that could be popping up are ones in jump instructions. So this should converge fairly quickly. */ } while (last_extended_arg_count != extended_arg_count); } static PyObject * dict_keys_inorder(PyObject *dict, Py_ssize_t offset) { PyObject *tuple, *k, *v; Py_ssize_t i, pos = 0, size = PyDict_Size(dict); tuple = PyTuple_New(size); if (tuple == NULL) return NULL; while (PyDict_Next(dict, &pos, &k, &v)) { i = PyLong_AS_LONG(v); /* The keys of the dictionary are tuples. (see compiler_add_o) The object we want is always first, though. */ k = PyTuple_GET_ITEM(k, 0); Py_INCREF(k); assert((i - offset) < size); assert((i - offset) >= 0); PyTuple_SET_ITEM(tuple, i - offset, k); } return tuple; } static int compute_code_flags(struct compiler *c) { PySTEntryObject *ste = c->u->u_ste; int flags = 0; Py_ssize_t n; if (ste->ste_type == FunctionBlock) { flags |= CO_NEWLOCALS; if (!ste->ste_unoptimized) flags |= CO_OPTIMIZED; if (ste->ste_nested) flags |= CO_NESTED; if (ste->ste_generator) flags |= CO_GENERATOR; if (ste->ste_varargs) flags |= CO_VARARGS; if (ste->ste_varkeywords) flags |= CO_VARKEYWORDS; } /* (Only) inherit compilerflags in PyCF_MASK */ flags |= (c->c_flags->cf_flags & PyCF_MASK); n = PyDict_Size(c->u->u_freevars); if (n < 0) return -1; if (n == 0) { n = PyDict_Size(c->u->u_cellvars); if (n < 0) return -1; if (n == 0) { flags |= CO_NOFREE; } } return flags; } static PyCodeObject * makecode(struct compiler *c, struct assembler *a) { PyObject *tmp; PyCodeObject *co = NULL; PyObject *consts = NULL; PyObject *names = NULL; PyObject *varnames = NULL; PyObject *name = NULL; PyObject *freevars = NULL; PyObject *cellvars = NULL; PyObject *bytecode = NULL; Py_ssize_t nlocals; int nlocals_int; int flags; int argcount, kwonlyargcount; tmp = dict_keys_inorder(c->u->u_consts, 0); if (!tmp) goto error; consts = PySequence_List(tmp); /* optimize_code requires a list */ Py_DECREF(tmp); names = dict_keys_inorder(c->u->u_names, 0); varnames = dict_keys_inorder(c->u->u_varnames, 0); if (!consts || !names || !varnames) goto error; cellvars = dict_keys_inorder(c->u->u_cellvars, 0); if (!cellvars) goto error; freevars = dict_keys_inorder(c->u->u_freevars, PyTuple_Size(cellvars)); if (!freevars) goto error; nlocals = PyDict_Size(c->u->u_varnames); assert(nlocals < INT_MAX); nlocals_int = Py_SAFE_DOWNCAST(nlocals, Py_ssize_t, int); flags = compute_code_flags(c); if (flags < 0) goto error; bytecode = PyCode_Optimize(a->a_bytecode, consts, names, a->a_lnotab); if (!bytecode) goto error; tmp = PyList_AsTuple(consts); /* PyCode_New requires a tuple */ if (!tmp) goto error; Py_DECREF(consts); consts = tmp; argcount = Py_SAFE_DOWNCAST(c->u->u_argcount, Py_ssize_t, int); kwonlyargcount = Py_SAFE_DOWNCAST(c->u->u_kwonlyargcount, Py_ssize_t, int); co = PyCode_New(argcount, kwonlyargcount, nlocals_int, stackdepth(c), flags, bytecode, consts, names, varnames, freevars, cellvars, c->c_filename, c->u->u_name, c->u->u_firstlineno, a->a_lnotab); error: Py_XDECREF(consts); Py_XDECREF(names); Py_XDECREF(varnames); Py_XDECREF(name); Py_XDECREF(freevars); Py_XDECREF(cellvars); Py_XDECREF(bytecode); return co; } /* For debugging purposes only */ #if 0 static void dump_instr(const struct instr *i) { const char *jrel = i->i_jrel ? "jrel " : ""; const char *jabs = i->i_jabs ? "jabs " : ""; char arg[128]; *arg = '\0'; if (i->i_hasarg) sprintf(arg, "arg: %d ", i->i_oparg); fprintf(stderr, "line: %d, opcode: %d %s%s%s\n", i->i_lineno, i->i_opcode, arg, jabs, jrel); } static void dump_basicblock(const basicblock *b) { const char *seen = b->b_seen ? "seen " : ""; const char *b_return = b->b_return ? "return " : ""; fprintf(stderr, "used: %d, depth: %d, offset: %d %s%s\n", b->b_iused, b->b_startdepth, b->b_offset, seen, b_return); if (b->b_instr) { int i; for (i = 0; i < b->b_iused; i++) { fprintf(stderr, " [%02d] ", i); dump_instr(b->b_instr + i); } } } #endif static PyCodeObject * assemble(struct compiler *c, int addNone) { basicblock *b, *entryblock; struct assembler a; int i, j, nblocks; PyCodeObject *co = NULL; /* Make sure every block that falls off the end returns None. XXX NEXT_BLOCK() isn't quite right, because if the last block ends with a jump or return b_next shouldn't set. */ if (!c->u->u_curblock->b_return) { NEXT_BLOCK(c); if (addNone) ADDOP_O(c, LOAD_CONST, Py_None, consts); ADDOP(c, RETURN_VALUE); } nblocks = 0; entryblock = NULL; for (b = c->u->u_blocks; b != NULL; b = b->b_list) { nblocks++; entryblock = b; } /* Set firstlineno if it wasn't explicitly set. */ if (!c->u->u_firstlineno) { if (entryblock && entryblock->b_instr) c->u->u_firstlineno = entryblock->b_instr->i_lineno; else c->u->u_firstlineno = 1; } if (!assemble_init(&a, nblocks, c->u->u_firstlineno)) goto error; dfs(c, entryblock, &a); /* Can't modify the bytecode after computing jump offsets. */ assemble_jump_offsets(&a, c); /* Emit code in reverse postorder from dfs. */ for (i = a.a_nblocks - 1; i >= 0; i--) { b = a.a_postorder[i]; for (j = 0; j < b->b_iused; j++) if (!assemble_emit(&a, &b->b_instr[j])) goto error; } if (_PyBytes_Resize(&a.a_lnotab, a.a_lnotab_off) < 0) goto error; if (_PyBytes_Resize(&a.a_bytecode, a.a_offset) < 0) goto error; co = makecode(c, &a); error: assemble_free(&a); return co; } #undef PyAST_Compile PyAPI_FUNC(PyCodeObject *) PyAST_Compile(mod_ty mod, const char *filename, PyCompilerFlags *flags, PyArena *arena) { return PyAST_CompileEx(mod, filename, flags, -1, arena); }