Index: Python/ceval.c =================================================================== --- Python/ceval.c (Revision 51643) +++ Python/ceval.c (Arbeitskopie) @@ -1237,6 +1237,18 @@ } break; + case SET_ADD: + w = POP(); + v = POP(); + err = PySet_Add(v, w); + Py_DECREF(v); + Py_DECREF(w); + if (err == 0) { + PREDICT(JUMP_ABSOLUTE); + continue; + } + break; + case INPLACE_POWER: w = POP(); v = TOP(); Index: Python/graminit.c =================================================================== --- Python/graminit.c (Revision 51643) +++ Python/graminit.c (Arbeitskopie) @@ -972,33 +972,36 @@ {1, arcs_43_3}, {2, arcs_43_4}, }; -static arc arcs_44_0[1] = { - {105, 1}, +static arc arcs_44_0[2] = { + {104, 1}, + {105, 2}, }; static arc arcs_44_1[2] = { - {27, 2}, + {91, 3}, {0, 1}, }; static arc arcs_44_2[1] = { - {105, 3}, + {0, 2}, }; -static arc arcs_44_3[2] = { - {27, 4}, - {0, 3}, +static arc arcs_44_3[1] = { + {104, 4}, }; -static arc arcs_44_4[2] = { - {105, 3}, - {0, 4}, +static arc arcs_44_4[1] = { + {93, 5}, }; -static state states_44[5] = { - {1, arcs_44_0}, +static arc arcs_44_5[1] = { + {26, 2}, +}; +static state states_44[6] = { + {2, arcs_44_0}, {2, arcs_44_1}, {1, arcs_44_2}, - {2, arcs_44_3}, - {2, arcs_44_4}, + {1, arcs_44_3}, + {1, arcs_44_4}, + {1, arcs_44_5}, }; static arc arcs_45_0[2] = { - {106, 1}, + {104, 1}, {107, 1}, }; static arc arcs_45_1[1] = { @@ -1019,7 +1022,7 @@ {21, 3}, }; static arc arcs_46_3[1] = { - {105, 4}, + {26, 4}, }; static arc arcs_46_4[1] = { {0, 4}, @@ -1031,39 +1034,34 @@ {1, arcs_46_3}, {1, arcs_46_4}, }; -static arc arcs_47_0[2] = { - {106, 1}, - {109, 2}, +static arc arcs_47_0[1] = { + {108, 1}, }; static arc arcs_47_1[2] = { - {91, 3}, - {0, 1}, + {23, 2}, + {21, 3}, }; static arc arcs_47_2[1] = { - {0, 2}, + {21, 3}, }; static arc arcs_47_3[1] = { {106, 4}, }; static arc arcs_47_4[1] = { - {93, 5}, + {0, 4}, }; -static arc arcs_47_5[1] = { - {26, 2}, -}; -static state states_47[6] = { - {2, arcs_47_0}, +static state states_47[5] = { + {1, arcs_47_0}, {2, arcs_47_1}, {1, arcs_47_2}, {1, arcs_47_3}, {1, arcs_47_4}, - {1, arcs_47_5}, }; static arc arcs_48_0[1] = { - {110, 1}, + {109, 1}, }; static arc arcs_48_1[2] = { - {111, 0}, + {110, 0}, {0, 1}, }; static state states_48[2] = { @@ -1071,10 +1069,10 @@ {2, arcs_48_1}, }; static arc arcs_49_0[1] = { - {112, 1}, + {111, 1}, }; static arc arcs_49_1[2] = { - {113, 0}, + {112, 0}, {0, 1}, }; static state states_49[2] = { @@ -1082,11 +1080,11 @@ {2, arcs_49_1}, }; static arc arcs_50_0[2] = { - {114, 1}, - {115, 2}, + {113, 1}, + {114, 2}, }; static arc arcs_50_1[1] = { - {112, 2}, + {111, 2}, }; static arc arcs_50_2[1] = { {0, 2}, @@ -1100,7 +1098,7 @@ {82, 1}, }; static arc arcs_51_1[2] = { - {116, 0}, + {115, 0}, {0, 1}, }; static state states_51[2] = { @@ -1108,15 +1106,15 @@ {2, arcs_51_1}, }; static arc arcs_52_0[9] = { + {116, 1}, {117, 1}, {118, 1}, {119, 1}, {120, 1}, {121, 1}, - {122, 1}, {83, 1}, - {114, 2}, - {123, 3}, + {113, 2}, + {122, 3}, }; static arc arcs_52_1[1] = { {0, 1}, @@ -1125,7 +1123,7 @@ {83, 1}, }; static arc arcs_52_3[2] = { - {114, 1}, + {113, 1}, {0, 3}, }; static state states_52[4] = { @@ -1135,10 +1133,10 @@ {2, arcs_52_3}, }; static arc arcs_53_0[1] = { - {124, 1}, + {123, 1}, }; static arc arcs_53_1[2] = { - {125, 0}, + {124, 0}, {0, 1}, }; static state states_53[2] = { @@ -1146,10 +1144,10 @@ {2, arcs_53_1}, }; static arc arcs_54_0[1] = { - {126, 1}, + {125, 1}, }; static arc arcs_54_1[2] = { - {127, 0}, + {126, 0}, {0, 1}, }; static state states_54[2] = { @@ -1157,10 +1155,10 @@ {2, arcs_54_1}, }; static arc arcs_55_0[1] = { - {128, 1}, + {127, 1}, }; static arc arcs_55_1[2] = { - {129, 0}, + {128, 0}, {0, 1}, }; static state states_55[2] = { @@ -1168,10 +1166,10 @@ {2, arcs_55_1}, }; static arc arcs_56_0[1] = { - {130, 1}, + {129, 1}, }; static arc arcs_56_1[3] = { - {131, 0}, + {130, 0}, {57, 0}, {0, 1}, }; @@ -1180,11 +1178,11 @@ {3, arcs_56_1}, }; static arc arcs_57_0[1] = { - {132, 1}, + {131, 1}, }; static arc arcs_57_1[3] = { + {132, 0}, {133, 0}, - {134, 0}, {0, 1}, }; static state states_57[2] = { @@ -1192,13 +1190,13 @@ {3, arcs_57_1}, }; static arc arcs_58_0[1] = { - {135, 1}, + {134, 1}, }; static arc arcs_58_1[5] = { {28, 0}, + {135, 0}, {136, 0}, {137, 0}, - {138, 0}, {0, 1}, }; static state states_58[2] = { @@ -1206,13 +1204,13 @@ {5, arcs_58_1}, }; static arc arcs_59_0[4] = { + {132, 1}, {133, 1}, - {134, 1}, - {139, 1}, - {140, 2}, + {138, 1}, + {139, 2}, }; static arc arcs_59_1[1] = { - {135, 2}, + {134, 2}, }; static arc arcs_59_2[1] = { {0, 2}, @@ -1223,15 +1221,15 @@ {1, arcs_59_2}, }; static arc arcs_60_0[1] = { - {141, 1}, + {140, 1}, }; static arc arcs_60_1[3] = { - {142, 1}, + {141, 1}, {29, 2}, {0, 1}, }; static arc arcs_60_2[1] = { - {135, 3}, + {134, 3}, }; static arc arcs_60_3[1] = { {0, 3}, @@ -1244,40 +1242,40 @@ }; static arc arcs_61_0[6] = { {13, 1}, - {144, 2}, - {147, 3}, + {143, 2}, + {145, 3}, {19, 4}, - {150, 4}, - {151, 5}, + {148, 4}, + {149, 5}, }; static arc arcs_61_1[3] = { {43, 6}, - {143, 6}, + {142, 6}, {15, 4}, }; static arc arcs_61_2[2] = { - {145, 7}, - {146, 4}, + {142, 7}, + {144, 4}, }; static arc arcs_61_3[2] = { - {148, 8}, - {149, 4}, + {146, 8}, + {147, 4}, }; static arc arcs_61_4[1] = { {0, 4}, }; static arc arcs_61_5[2] = { - {151, 5}, + {149, 5}, {0, 5}, }; static arc arcs_61_6[1] = { {15, 4}, }; static arc arcs_61_7[1] = { - {146, 4}, + {144, 4}, }; static arc arcs_61_8[1] = { - {149, 4}, + {147, 4}, }; static state states_61[9] = { {6, arcs_61_0}, @@ -1294,7 +1292,7 @@ {26, 1}, }; static arc arcs_62_1[3] = { - {152, 2}, + {150, 2}, {27, 3}, {0, 1}, }; @@ -1316,481 +1314,380 @@ {2, arcs_62_3}, {2, arcs_62_4}, }; -static arc arcs_63_0[1] = { - {26, 1}, -}; -static arc arcs_63_1[3] = { - {153, 2}, - {27, 3}, - {0, 1}, -}; -static arc arcs_63_2[1] = { - {0, 2}, -}; -static arc arcs_63_3[2] = { - {26, 4}, - {0, 3}, -}; -static arc arcs_63_4[2] = { - {27, 3}, - {0, 4}, -}; -static state states_63[5] = { - {1, arcs_63_0}, - {3, arcs_63_1}, - {1, arcs_63_2}, - {2, arcs_63_3}, - {2, arcs_63_4}, -}; -static arc arcs_64_0[1] = { - {108, 1}, -}; -static arc arcs_64_1[2] = { - {23, 2}, - {21, 3}, -}; -static arc arcs_64_2[1] = { - {21, 3}, -}; -static arc arcs_64_3[1] = { - {26, 4}, -}; -static arc arcs_64_4[1] = { - {0, 4}, -}; -static state states_64[5] = { - {1, arcs_64_0}, - {2, arcs_64_1}, - {1, arcs_64_2}, - {1, arcs_64_3}, - {1, arcs_64_4}, -}; -static arc arcs_65_0[3] = { +static arc arcs_63_0[3] = { {13, 1}, - {144, 2}, + {143, 2}, {75, 3}, }; -static arc arcs_65_1[2] = { +static arc arcs_63_1[2] = { {14, 4}, {15, 5}, }; -static arc arcs_65_2[1] = { - {154, 6}, +static arc arcs_63_2[1] = { + {151, 6}, }; -static arc arcs_65_3[1] = { +static arc arcs_63_3[1] = { {19, 5}, }; -static arc arcs_65_4[1] = { +static arc arcs_63_4[1] = { {15, 5}, }; -static arc arcs_65_5[1] = { +static arc arcs_63_5[1] = { {0, 5}, }; -static arc arcs_65_6[1] = { - {146, 5}, +static arc arcs_63_6[1] = { + {144, 5}, }; -static state states_65[7] = { - {3, arcs_65_0}, - {2, arcs_65_1}, - {1, arcs_65_2}, - {1, arcs_65_3}, - {1, arcs_65_4}, - {1, arcs_65_5}, - {1, arcs_65_6}, +static state states_63[7] = { + {3, arcs_63_0}, + {2, arcs_63_1}, + {1, arcs_63_2}, + {1, arcs_63_3}, + {1, arcs_63_4}, + {1, arcs_63_5}, + {1, arcs_63_6}, }; -static arc arcs_66_0[1] = { - {155, 1}, +static arc arcs_64_0[1] = { + {152, 1}, }; -static arc arcs_66_1[2] = { +static arc arcs_64_1[2] = { {27, 2}, {0, 1}, }; -static arc arcs_66_2[2] = { - {155, 1}, +static arc arcs_64_2[2] = { + {152, 1}, {0, 2}, }; -static state states_66[3] = { - {1, arcs_66_0}, - {2, arcs_66_1}, - {2, arcs_66_2}, +static state states_64[3] = { + {1, arcs_64_0}, + {2, arcs_64_1}, + {2, arcs_64_2}, }; -static arc arcs_67_0[3] = { +static arc arcs_65_0[3] = { {75, 1}, {26, 2}, {21, 3}, }; -static arc arcs_67_1[1] = { +static arc arcs_65_1[1] = { {75, 4}, }; -static arc arcs_67_2[2] = { +static arc arcs_65_2[2] = { {21, 3}, {0, 2}, }; -static arc arcs_67_3[3] = { +static arc arcs_65_3[3] = { {26, 5}, - {156, 6}, + {153, 6}, {0, 3}, }; -static arc arcs_67_4[1] = { +static arc arcs_65_4[1] = { {75, 6}, }; -static arc arcs_67_5[2] = { - {156, 6}, +static arc arcs_65_5[2] = { + {153, 6}, {0, 5}, }; -static arc arcs_67_6[1] = { +static arc arcs_65_6[1] = { {0, 6}, }; -static state states_67[7] = { - {3, arcs_67_0}, - {1, arcs_67_1}, - {2, arcs_67_2}, - {3, arcs_67_3}, - {1, arcs_67_4}, - {2, arcs_67_5}, - {1, arcs_67_6}, +static state states_65[7] = { + {3, arcs_65_0}, + {1, arcs_65_1}, + {2, arcs_65_2}, + {3, arcs_65_3}, + {1, arcs_65_4}, + {2, arcs_65_5}, + {1, arcs_65_6}, }; -static arc arcs_68_0[1] = { +static arc arcs_66_0[1] = { {21, 1}, }; -static arc arcs_68_1[2] = { +static arc arcs_66_1[2] = { {26, 2}, {0, 1}, }; -static arc arcs_68_2[1] = { +static arc arcs_66_2[1] = { {0, 2}, }; -static state states_68[3] = { - {1, arcs_68_0}, - {2, arcs_68_1}, - {1, arcs_68_2}, +static state states_66[3] = { + {1, arcs_66_0}, + {2, arcs_66_1}, + {1, arcs_66_2}, }; -static arc arcs_69_0[1] = { +static arc arcs_67_0[1] = { {82, 1}, }; -static arc arcs_69_1[2] = { +static arc arcs_67_1[2] = { {27, 2}, {0, 1}, }; -static arc arcs_69_2[2] = { +static arc arcs_67_2[2] = { {82, 1}, {0, 2}, }; -static state states_69[3] = { - {1, arcs_69_0}, - {2, arcs_69_1}, - {2, arcs_69_2}, +static state states_67[3] = { + {1, arcs_67_0}, + {2, arcs_67_1}, + {2, arcs_67_2}, }; -static arc arcs_70_0[1] = { +static arc arcs_68_0[1] = { {26, 1}, }; -static arc arcs_70_1[2] = { +static arc arcs_68_1[2] = { {27, 2}, {0, 1}, }; -static arc arcs_70_2[2] = { +static arc arcs_68_2[2] = { {26, 1}, {0, 2}, }; -static state states_70[3] = { - {1, arcs_70_0}, - {2, arcs_70_1}, - {2, arcs_70_2}, +static state states_68[3] = { + {1, arcs_68_0}, + {2, arcs_68_1}, + {2, arcs_68_2}, }; -static arc arcs_71_0[1] = { +static arc arcs_69_0[1] = { {26, 1}, }; -static arc arcs_71_1[3] = { +static arc arcs_69_1[4] = { {21, 2}, - {27, 3}, + {150, 3}, + {27, 4}, {0, 1}, }; -static arc arcs_71_2[1] = { - {26, 4}, -}; -static arc arcs_71_3[2] = { +static arc arcs_69_2[1] = { {26, 5}, +}; +static arc arcs_69_3[1] = { {0, 3}, }; -static arc arcs_71_4[2] = { - {27, 6}, +static arc arcs_69_4[2] = { + {26, 6}, {0, 4}, }; -static arc arcs_71_5[2] = { - {27, 3}, +static arc arcs_69_5[2] = { + {27, 7}, {0, 5}, }; -static arc arcs_71_6[2] = { - {26, 7}, +static arc arcs_69_6[2] = { + {27, 4}, {0, 6}, }; -static arc arcs_71_7[1] = { +static arc arcs_69_7[2] = { + {26, 8}, + {0, 7}, +}; +static arc arcs_69_8[1] = { {21, 2}, }; -static state states_71[8] = { - {1, arcs_71_0}, - {3, arcs_71_1}, - {1, arcs_71_2}, - {2, arcs_71_3}, - {2, arcs_71_4}, - {2, arcs_71_5}, - {2, arcs_71_6}, - {1, arcs_71_7}, +static state states_69[9] = { + {1, arcs_69_0}, + {4, arcs_69_1}, + {1, arcs_69_2}, + {1, arcs_69_3}, + {2, arcs_69_4}, + {2, arcs_69_5}, + {2, arcs_69_6}, + {2, arcs_69_7}, + {1, arcs_69_8}, }; -static arc arcs_72_0[1] = { - {157, 1}, +static arc arcs_70_0[1] = { + {154, 1}, }; -static arc arcs_72_1[1] = { +static arc arcs_70_1[1] = { {19, 2}, }; -static arc arcs_72_2[2] = { +static arc arcs_70_2[2] = { {13, 3}, {21, 4}, }; -static arc arcs_72_3[2] = { +static arc arcs_70_3[2] = { {9, 5}, {15, 6}, }; -static arc arcs_72_4[1] = { +static arc arcs_70_4[1] = { {22, 7}, }; -static arc arcs_72_5[1] = { +static arc arcs_70_5[1] = { {15, 6}, }; -static arc arcs_72_6[1] = { +static arc arcs_70_6[1] = { {21, 4}, }; -static arc arcs_72_7[1] = { +static arc arcs_70_7[1] = { {0, 7}, }; -static state states_72[8] = { - {1, arcs_72_0}, - {1, arcs_72_1}, - {2, arcs_72_2}, - {2, arcs_72_3}, - {1, arcs_72_4}, - {1, arcs_72_5}, - {1, arcs_72_6}, - {1, arcs_72_7}, +static state states_70[8] = { + {1, arcs_70_0}, + {1, arcs_70_1}, + {2, arcs_70_2}, + {2, arcs_70_3}, + {1, arcs_70_4}, + {1, arcs_70_5}, + {1, arcs_70_6}, + {1, arcs_70_7}, }; -static arc arcs_73_0[3] = { - {158, 1}, +static arc arcs_71_0[3] = { + {155, 1}, {28, 2}, {29, 3}, }; -static arc arcs_73_1[2] = { +static arc arcs_71_1[2] = { {27, 4}, {0, 1}, }; -static arc arcs_73_2[1] = { +static arc arcs_71_2[1] = { {26, 5}, }; -static arc arcs_73_3[1] = { +static arc arcs_71_3[1] = { {26, 6}, }; -static arc arcs_73_4[4] = { - {158, 1}, +static arc arcs_71_4[4] = { + {155, 1}, {28, 2}, {29, 3}, {0, 4}, }; -static arc arcs_73_5[2] = { +static arc arcs_71_5[2] = { {27, 7}, {0, 5}, }; -static arc arcs_73_6[1] = { +static arc arcs_71_6[1] = { {0, 6}, }; -static arc arcs_73_7[1] = { +static arc arcs_71_7[1] = { {29, 3}, }; -static state states_73[8] = { - {3, arcs_73_0}, - {2, arcs_73_1}, - {1, arcs_73_2}, - {1, arcs_73_3}, - {4, arcs_73_4}, - {2, arcs_73_5}, - {1, arcs_73_6}, - {1, arcs_73_7}, +static state states_71[8] = { + {3, arcs_71_0}, + {2, arcs_71_1}, + {1, arcs_71_2}, + {1, arcs_71_3}, + {4, arcs_71_4}, + {2, arcs_71_5}, + {1, arcs_71_6}, + {1, arcs_71_7}, }; -static arc arcs_74_0[1] = { +static arc arcs_72_0[1] = { {26, 1}, }; -static arc arcs_74_1[3] = { - {153, 2}, +static arc arcs_72_1[3] = { + {150, 2}, {25, 3}, {0, 1}, }; -static arc arcs_74_2[1] = { +static arc arcs_72_2[1] = { {0, 2}, }; -static arc arcs_74_3[1] = { +static arc arcs_72_3[1] = { {26, 2}, }; -static state states_74[4] = { - {1, arcs_74_0}, - {3, arcs_74_1}, - {1, arcs_74_2}, - {1, arcs_74_3}, +static state states_72[4] = { + {1, arcs_72_0}, + {3, arcs_72_1}, + {1, arcs_72_2}, + {1, arcs_72_3}, }; -static arc arcs_75_0[2] = { - {152, 1}, - {160, 1}, +static arc arcs_73_0[2] = { + {150, 1}, + {157, 1}, }; -static arc arcs_75_1[1] = { +static arc arcs_73_1[1] = { {0, 1}, }; -static state states_75[2] = { - {2, arcs_75_0}, - {1, arcs_75_1}, +static state states_73[2] = { + {2, arcs_73_0}, + {1, arcs_73_1}, }; -static arc arcs_76_0[1] = { +static arc arcs_74_0[1] = { {95, 1}, }; -static arc arcs_76_1[1] = { +static arc arcs_74_1[1] = { {59, 2}, }; -static arc arcs_76_2[1] = { +static arc arcs_74_2[1] = { {83, 3}, }; -static arc arcs_76_3[1] = { +static arc arcs_74_3[1] = { {104, 4}, }; -static arc arcs_76_4[2] = { - {159, 5}, +static arc arcs_74_4[2] = { + {156, 5}, {0, 4}, }; -static arc arcs_76_5[1] = { +static arc arcs_74_5[1] = { {0, 5}, }; -static state states_76[6] = { - {1, arcs_76_0}, - {1, arcs_76_1}, - {1, arcs_76_2}, - {1, arcs_76_3}, - {2, arcs_76_4}, - {1, arcs_76_5}, +static state states_74[6] = { + {1, arcs_74_0}, + {1, arcs_74_1}, + {1, arcs_74_2}, + {1, arcs_74_3}, + {2, arcs_74_4}, + {1, arcs_74_5}, }; -static arc arcs_77_0[1] = { +static arc arcs_75_0[1] = { {91, 1}, }; -static arc arcs_77_1[1] = { - {105, 2}, +static arc arcs_75_1[1] = { + {106, 2}, }; -static arc arcs_77_2[2] = { - {159, 3}, +static arc arcs_75_2[2] = { + {156, 3}, {0, 2}, }; -static arc arcs_77_3[1] = { +static arc arcs_75_3[1] = { {0, 3}, }; -static state states_77[4] = { - {1, arcs_77_0}, - {1, arcs_77_1}, - {2, arcs_77_2}, - {1, arcs_77_3}, +static state states_75[4] = { + {1, arcs_75_0}, + {1, arcs_75_1}, + {2, arcs_75_2}, + {1, arcs_75_3}, }; -static arc arcs_78_0[2] = { - {153, 1}, - {162, 1}, -}; -static arc arcs_78_1[1] = { - {0, 1}, -}; -static state states_78[2] = { - {2, arcs_78_0}, - {1, arcs_78_1}, -}; -static arc arcs_79_0[1] = { - {95, 1}, -}; -static arc arcs_79_1[1] = { - {59, 2}, -}; -static arc arcs_79_2[1] = { - {83, 3}, -}; -static arc arcs_79_3[1] = { - {106, 4}, -}; -static arc arcs_79_4[2] = { - {161, 5}, - {0, 4}, -}; -static arc arcs_79_5[1] = { - {0, 5}, -}; -static state states_79[6] = { - {1, arcs_79_0}, - {1, arcs_79_1}, - {1, arcs_79_2}, - {1, arcs_79_3}, - {2, arcs_79_4}, - {1, arcs_79_5}, -}; -static arc arcs_80_0[1] = { - {91, 1}, -}; -static arc arcs_80_1[1] = { - {105, 2}, -}; -static arc arcs_80_2[2] = { - {161, 3}, - {0, 2}, -}; -static arc arcs_80_3[1] = { - {0, 3}, -}; -static state states_80[4] = { - {1, arcs_80_0}, - {1, arcs_80_1}, - {2, arcs_80_2}, - {1, arcs_80_3}, -}; -static arc arcs_81_0[1] = { +static arc arcs_76_0[1] = { {26, 1}, }; -static arc arcs_81_1[2] = { +static arc arcs_76_1[2] = { {27, 0}, {0, 1}, }; -static state states_81[2] = { - {1, arcs_81_0}, - {2, arcs_81_1}, +static state states_76[2] = { + {1, arcs_76_0}, + {2, arcs_76_1}, }; -static arc arcs_82_0[1] = { +static arc arcs_77_0[1] = { {19, 1}, }; -static arc arcs_82_1[1] = { +static arc arcs_77_1[1] = { {0, 1}, }; -static state states_82[2] = { - {1, arcs_82_0}, - {1, arcs_82_1}, +static state states_77[2] = { + {1, arcs_77_0}, + {1, arcs_77_1}, }; -static arc arcs_83_0[1] = { - {165, 1}, +static arc arcs_78_0[1] = { + {160, 1}, }; -static arc arcs_83_1[2] = { +static arc arcs_78_1[2] = { {9, 2}, {0, 1}, }; -static arc arcs_83_2[1] = { +static arc arcs_78_2[1] = { {0, 2}, }; -static state states_83[3] = { - {1, arcs_83_0}, - {2, arcs_83_1}, - {1, arcs_83_2}, +static state states_78[3] = { + {1, arcs_78_0}, + {2, arcs_78_1}, + {1, arcs_78_2}, }; -static dfa dfas[84] = { +static dfa dfas[79] = { {256, "single_input", 0, 3, states_0, - "\004\050\014\000\000\000\000\025\074\005\023\310\011\020\004\000\140\010\311\040\040"}, + "\004\050\014\000\000\000\000\025\074\005\023\310\011\020\002\000\060\204\062\004\001"}, {257, "file_input", 0, 2, states_1, - "\204\050\014\000\000\000\000\025\074\005\023\310\011\020\004\000\140\010\311\040\040"}, + "\204\050\014\000\000\000\000\025\074\005\023\310\011\020\002\000\060\204\062\004\001"}, {258, "eval_input", 0, 3, states_2, - "\000\040\010\000\000\000\000\000\000\000\000\000\000\020\004\000\140\010\311\000\000"}, + "\000\040\010\000\000\000\000\000\000\000\000\000\000\020\002\000\060\204\062\000\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, @@ -1806,13 +1703,13 @@ {265, "fplist", 0, 3, states_9, "\000\040\010\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000"}, {266, "stmt", 0, 2, states_10, - "\000\050\014\000\000\000\000\025\074\005\023\310\011\020\004\000\140\010\311\040\040"}, + "\000\050\014\000\000\000\000\025\074\005\023\310\011\020\002\000\060\204\062\004\001"}, {267, "simple_stmt", 0, 4, states_11, - "\000\040\010\000\000\000\000\025\074\005\023\000\000\020\004\000\140\010\311\000\040"}, + "\000\040\010\000\000\000\000\025\074\005\023\000\000\020\002\000\060\204\062\000\001"}, {268, "small_stmt", 0, 2, states_12, - "\000\040\010\000\000\000\000\025\074\005\023\000\000\020\004\000\140\010\311\000\040"}, + "\000\040\010\000\000\000\000\025\074\005\023\000\000\020\002\000\060\204\062\000\001"}, {269, "expr_stmt", 0, 6, states_13, - "\000\040\010\000\000\000\000\000\000\000\000\000\000\020\004\000\140\010\311\000\000"}, + "\000\040\010\000\000\000\000\000\000\000\000\000\000\020\002\000\060\204\062\000\000"}, {270, "augassign", 0, 2, states_14, "\000\000\000\000\000\360\377\000\000\000\000\000\000\000\000\000\000\000\000\000\000"}, {271, "print_stmt", 0, 9, states_15, @@ -1822,7 +1719,7 @@ {273, "pass_stmt", 0, 2, states_17, "\000\000\000\000\000\000\000\020\000\000\000\000\000\000\000\000\000\000\000\000\000"}, {274, "flow_stmt", 0, 2, states_18, - "\000\000\000\000\000\000\000\000\074\000\000\000\000\000\000\000\000\000\000\000\040"}, + "\000\000\000\000\000\000\000\000\074\000\000\000\000\000\000\000\000\000\000\000\001"}, {275, "break_stmt", 0, 2, states_19, "\000\000\000\000\000\000\000\000\004\000\000\000\000\000\000\000\000\000\000\000\000"}, {276, "continue_stmt", 0, 2, states_20, @@ -1830,7 +1727,7 @@ {277, "return_stmt", 0, 3, states_21, "\000\000\000\000\000\000\000\000\020\000\000\000\000\000\000\000\000\000\000\000\000"}, {278, "yield_stmt", 0, 2, states_22, - "\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\040"}, + "\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\001"}, {279, "raise_stmt", 0, 7, states_23, "\000\000\000\000\000\000\000\000\040\000\000\000\000\000\000\000\000\000\000\000\000"}, {280, "import_stmt", 0, 2, states_24, @@ -1856,7 +1753,7 @@ {290, "assert_stmt", 0, 5, states_34, "\000\000\000\000\000\000\000\000\000\000\020\000\000\000\000\000\000\000\000\000\000"}, {291, "compound_stmt", 0, 2, states_35, - "\000\010\004\000\000\000\000\000\000\000\000\310\011\000\000\000\000\000\000\040\000"}, + "\000\010\004\000\000\000\000\000\000\000\000\310\011\000\000\000\000\000\000\004\000"}, {292, "if_stmt", 0, 8, states_36, "\000\000\000\000\000\000\000\000\000\000\000\010\000\000\000\000\000\000\000\000\000"}, {293, "while_stmt", 0, 8, states_37, @@ -1872,89 +1769,79 @@ {298, "except_clause", 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, "suite", 0, 5, states_43, - "\004\040\010\000\000\000\000\025\074\005\023\000\000\020\004\000\140\010\311\000\040"}, - {300, "testlist_safe", 0, 5, states_44, - "\000\040\010\000\000\000\000\000\000\000\000\000\000\020\004\000\140\010\311\000\000"}, - {301, "old_test", 0, 2, states_45, - "\000\040\010\000\000\000\000\000\000\000\000\000\000\020\004\000\140\010\311\000\000"}, - {302, "old_lambdef", 0, 5, states_46, + "\004\040\010\000\000\000\000\025\074\005\023\000\000\020\002\000\060\204\062\000\001"}, + {300, "test", 0, 6, states_44, + "\000\040\010\000\000\000\000\000\000\000\000\000\000\020\002\000\060\204\062\000\000"}, + {301, "test_nocond", 0, 2, states_45, + "\000\040\010\000\000\000\000\000\000\000\000\000\000\020\002\000\060\204\062\000\000"}, + {302, "lambdef", 0, 5, states_46, "\000\000\000\000\000\000\000\000\000\000\000\000\000\020\000\000\000\000\000\000\000"}, - {303, "test", 0, 6, states_47, - "\000\040\010\000\000\000\000\000\000\000\000\000\000\020\004\000\140\010\311\000\000"}, + {303, "lambdef_nocond", 0, 5, states_47, + "\000\000\000\000\000\000\000\000\000\000\000\000\000\020\000\000\000\000\000\000\000"}, {304, "or_test", 0, 2, states_48, - "\000\040\010\000\000\000\000\000\000\000\000\000\000\000\004\000\140\010\311\000\000"}, + "\000\040\010\000\000\000\000\000\000\000\000\000\000\000\002\000\060\204\062\000\000"}, {305, "and_test", 0, 2, states_49, - "\000\040\010\000\000\000\000\000\000\000\000\000\000\000\004\000\140\010\311\000\000"}, + "\000\040\010\000\000\000\000\000\000\000\000\000\000\000\002\000\060\204\062\000\000"}, {306, "not_test", 0, 3, states_50, - "\000\040\010\000\000\000\000\000\000\000\000\000\000\000\004\000\140\010\311\000\000"}, + "\000\040\010\000\000\000\000\000\000\000\000\000\000\000\002\000\060\204\062\000\000"}, {307, "comparison", 0, 2, states_51, - "\000\040\010\000\000\000\000\000\000\000\000\000\000\000\000\000\140\010\311\000\000"}, + "\000\040\010\000\000\000\000\000\000\000\000\000\000\000\000\000\060\204\062\000\000"}, {308, "comp_op", 0, 4, states_52, - "\000\000\000\000\000\000\000\000\000\000\010\000\000\000\344\017\000\000\000\000\000"}, + "\000\000\000\000\000\000\000\000\000\000\010\000\000\000\362\007\000\000\000\000\000"}, {309, "expr", 0, 2, states_53, - "\000\040\010\000\000\000\000\000\000\000\000\000\000\000\000\000\140\010\311\000\000"}, + "\000\040\010\000\000\000\000\000\000\000\000\000\000\000\000\000\060\204\062\000\000"}, {310, "xor_expr", 0, 2, states_54, - "\000\040\010\000\000\000\000\000\000\000\000\000\000\000\000\000\140\010\311\000\000"}, + "\000\040\010\000\000\000\000\000\000\000\000\000\000\000\000\000\060\204\062\000\000"}, {311, "and_expr", 0, 2, states_55, - "\000\040\010\000\000\000\000\000\000\000\000\000\000\000\000\000\140\010\311\000\000"}, + "\000\040\010\000\000\000\000\000\000\000\000\000\000\000\000\000\060\204\062\000\000"}, {312, "shift_expr", 0, 2, states_56, - "\000\040\010\000\000\000\000\000\000\000\000\000\000\000\000\000\140\010\311\000\000"}, + "\000\040\010\000\000\000\000\000\000\000\000\000\000\000\000\000\060\204\062\000\000"}, {313, "arith_expr", 0, 2, states_57, - "\000\040\010\000\000\000\000\000\000\000\000\000\000\000\000\000\140\010\311\000\000"}, + "\000\040\010\000\000\000\000\000\000\000\000\000\000\000\000\000\060\204\062\000\000"}, {314, "term", 0, 2, states_58, - "\000\040\010\000\000\000\000\000\000\000\000\000\000\000\000\000\140\010\311\000\000"}, + "\000\040\010\000\000\000\000\000\000\000\000\000\000\000\000\000\060\204\062\000\000"}, {315, "factor", 0, 3, states_59, - "\000\040\010\000\000\000\000\000\000\000\000\000\000\000\000\000\140\010\311\000\000"}, + "\000\040\010\000\000\000\000\000\000\000\000\000\000\000\000\000\060\204\062\000\000"}, {316, "power", 0, 4, states_60, - "\000\040\010\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\311\000\000"}, + "\000\040\010\000\000\000\000\000\000\000\000\000\000\000\000\000\000\200\062\000\000"}, {317, "atom", 0, 9, states_61, - "\000\040\010\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\311\000\000"}, - {318, "listmaker", 0, 5, states_62, - "\000\040\010\000\000\000\000\000\000\000\000\000\000\020\004\000\140\010\311\000\000"}, - {319, "testlist_gexp", 0, 5, states_63, - "\000\040\010\000\000\000\000\000\000\000\000\000\000\020\004\000\140\010\311\000\000"}, - {320, "lambdef", 0, 5, states_64, - "\000\000\000\000\000\000\000\000\000\000\000\000\000\020\000\000\000\000\000\000\000"}, - {321, "trailer", 0, 7, states_65, - "\000\040\000\000\000\000\000\000\000\010\000\000\000\000\000\000\000\000\001\000\000"}, - {322, "subscriptlist", 0, 3, states_66, - "\000\040\050\000\000\000\000\000\000\010\000\000\000\020\004\000\140\010\311\000\000"}, - {323, "subscript", 0, 7, states_67, - "\000\040\050\000\000\000\000\000\000\010\000\000\000\020\004\000\140\010\311\000\000"}, - {324, "sliceop", 0, 3, states_68, + "\000\040\010\000\000\000\000\000\000\000\000\000\000\000\000\000\000\200\062\000\000"}, + {318, "testlist_comp", 0, 5, states_62, + "\000\040\010\000\000\000\000\000\000\000\000\000\000\020\002\000\060\204\062\000\000"}, + {319, "trailer", 0, 7, states_63, + "\000\040\000\000\000\000\000\000\000\010\000\000\000\000\000\000\000\200\000\000\000"}, + {320, "subscriptlist", 0, 3, states_64, + "\000\040\050\000\000\000\000\000\000\010\000\000\000\020\002\000\060\204\062\000\000"}, + {321, "subscript", 0, 7, states_65, + "\000\040\050\000\000\000\000\000\000\010\000\000\000\020\002\000\060\204\062\000\000"}, + {322, "sliceop", 0, 3, states_66, "\000\000\040\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000"}, - {325, "exprlist", 0, 3, states_69, - "\000\040\010\000\000\000\000\000\000\000\000\000\000\000\000\000\140\010\311\000\000"}, - {326, "testlist", 0, 3, states_70, - "\000\040\010\000\000\000\000\000\000\000\000\000\000\020\004\000\140\010\311\000\000"}, - {327, "dictsetmaker", 0, 8, states_71, - "\000\040\010\000\000\000\000\000\000\000\000\000\000\020\004\000\140\010\311\000\000"}, - {328, "classdef", 0, 8, states_72, - "\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\040\000"}, - {329, "arglist", 0, 8, states_73, - "\000\040\010\060\000\000\000\000\000\000\000\000\000\020\004\000\140\010\311\000\000"}, - {330, "argument", 0, 4, states_74, - "\000\040\010\000\000\000\000\000\000\000\000\000\000\020\004\000\140\010\311\000\000"}, - {331, "list_iter", 0, 2, states_75, + {323, "exprlist", 0, 3, states_67, + "\000\040\010\000\000\000\000\000\000\000\000\000\000\000\000\000\060\204\062\000\000"}, + {324, "testlist", 0, 3, states_68, + "\000\040\010\000\000\000\000\000\000\000\000\000\000\020\002\000\060\204\062\000\000"}, + {325, "dictorsetmaker", 0, 9, states_69, + "\000\040\010\000\000\000\000\000\000\000\000\000\000\020\002\000\060\204\062\000\000"}, + {326, "classdef", 0, 8, states_70, + "\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\004\000"}, + {327, "arglist", 0, 8, states_71, + "\000\040\010\060\000\000\000\000\000\000\000\000\000\020\002\000\060\204\062\000\000"}, + {328, "argument", 0, 4, states_72, + "\000\040\010\000\000\000\000\000\000\000\000\000\000\020\002\000\060\204\062\000\000"}, + {329, "comp_iter", 0, 2, states_73, "\000\000\000\000\000\000\000\000\000\000\000\210\000\000\000\000\000\000\000\000\000"}, - {332, "list_for", 0, 6, states_76, + {330, "comp_for", 0, 6, states_74, "\000\000\000\000\000\000\000\000\000\000\000\200\000\000\000\000\000\000\000\000\000"}, - {333, "list_if", 0, 4, states_77, + {331, "comp_if", 0, 4, states_75, "\000\000\000\000\000\000\000\000\000\000\000\010\000\000\000\000\000\000\000\000\000"}, - {334, "gen_iter", 0, 2, states_78, - "\000\000\000\000\000\000\000\000\000\000\000\210\000\000\000\000\000\000\000\000\000"}, - {335, "gen_for", 0, 6, states_79, - "\000\000\000\000\000\000\000\000\000\000\000\200\000\000\000\000\000\000\000\000\000"}, - {336, "gen_if", 0, 4, states_80, - "\000\000\000\000\000\000\000\000\000\000\000\010\000\000\000\000\000\000\000\000\000"}, - {337, "testlist1", 0, 2, states_81, - "\000\040\010\000\000\000\000\000\000\000\000\000\000\020\004\000\140\010\311\000\000"}, - {338, "encoding_decl", 0, 2, states_82, + {332, "testlist1", 0, 2, states_76, + "\000\040\010\000\000\000\000\000\000\000\000\000\000\020\002\000\060\204\062\000\000"}, + {333, "encoding_decl", 0, 2, states_77, "\000\000\010\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000"}, - {339, "yield_expr", 0, 3, states_83, - "\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\040"}, + {334, "yield_expr", 0, 3, states_78, + "\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\001"}, }; -static label labels[166] = { +static label labels[161] = { {0, "EMPTY"}, {256, 0}, {4, 0}, @@ -1964,12 +1851,12 @@ {266, 0}, {0, 0}, {258, 0}, - {326, 0}, + {324, 0}, {259, 0}, {50, 0}, {287, 0}, {7, 0}, - {329, 0}, + {327, 0}, {8, 0}, {260, 0}, {261, 0}, @@ -1981,7 +1868,7 @@ {263, 0}, {264, 0}, {22, 0}, - {303, 0}, + {300, 0}, {12, 0}, {16, 0}, {36, 0}, @@ -1998,7 +1885,7 @@ {289, 0}, {290, 0}, {270, 0}, - {339, 0}, + {334, 0}, {37, 0}, {38, 0}, {39, 0}, @@ -2014,7 +1901,7 @@ {1, "print"}, {35, 0}, {1, "del"}, - {325, 0}, + {323, 0}, {1, "pass"}, {275, 0}, {276, 0}, @@ -2045,7 +1932,7 @@ {294, 0}, {295, 0}, {296, 0}, - {328, 0}, + {326, 0}, {1, "if"}, {1, "elif"}, {1, "else"}, @@ -2059,12 +1946,11 @@ {1, "except"}, {5, 0}, {6, 0}, - {300, 0}, - {301, 0}, {304, 0}, {302, 0}, + {301, 0}, + {303, 0}, {1, "lambda"}, - {320, 0}, {305, 0}, {1, "or"}, {306, 0}, @@ -2097,34 +1983,30 @@ {32, 0}, {316, 0}, {317, 0}, - {321, 0}, {319, 0}, - {9, 0}, {318, 0}, + {9, 0}, {10, 0}, {26, 0}, - {327, 0}, + {325, 0}, {27, 0}, {2, 0}, {3, 0}, - {332, 0}, - {335, 0}, + {330, 0}, + {320, 0}, + {321, 0}, {322, 0}, - {323, 0}, - {324, 0}, {1, "class"}, - {330, 0}, + {328, 0}, + {329, 0}, {331, 0}, + {332, 0}, {333, 0}, - {334, 0}, - {336, 0}, - {337, 0}, - {338, 0}, {1, "yield"}, }; grammar _PyParser_Grammar = { - 84, + 79, dfas, - {166, labels}, + {161, labels}, 256 }; Index: Python/ast.c =================================================================== --- Python/ast.c (Revision 51643) +++ Python/ast.c (Arbeitskopie) @@ -33,7 +33,6 @@ static asdl_seq *ast_for_suite(struct compiling *, const node *); static asdl_seq *ast_for_exprlist(struct compiling *, const node *, expr_context_ty); static expr_ty ast_for_testlist(struct compiling *, const node *); -static expr_ty ast_for_testlist_gexp(struct compiling *, const node *); /* Note different signature for ast_for_call */ static expr_ty ast_for_call(struct compiling *, const node *, expr_ty); @@ -236,7 +235,7 @@ case eval_input: { expr_ty testlist_ast; - /* XXX Why not gen_for here? */ + /* XXX Why not comp_for here? */ testlist_ast = ast_for_testlist(&c, CHILD(n, 0)); if (!testlist_ast) goto error; @@ -532,18 +531,14 @@ asdl_seq *seq; expr_ty expression; int i; - assert(TYPE(n) == testlist - || TYPE(n) == listmaker - || TYPE(n) == testlist_gexp - || TYPE(n) == testlist_safe - ); + assert(TYPE(n) == testlist || TYPE(n) == testlist_comp); seq = asdl_seq_new((NCH(n) + 1) / 2, c->c_arena); if (!seq) return NULL; for (i = 0; i < NCH(n); i += 2) { - assert(TYPE(CHILD(n, i)) == test || TYPE(CHILD(n, i)) == old_test); + assert(TYPE(CHILD(n, i)) == test || TYPE(CHILD(n, i)) == test_nocond); expression = ast_for_expr(c, CHILD(n, i)); if (!expression) @@ -843,7 +838,8 @@ static expr_ty ast_for_lambdef(struct compiling *c, const node *n) { - /* lambdef: 'lambda' [varargslist] ':' test */ + /* lambdef: 'lambda' [varargslist] ':' test + lambdef_nocond: 'lambda' [varargslist] ':' test_nocond */ arguments_ty args; expr_ty expression; @@ -887,181 +883,34 @@ c->c_arena); } -/* Count the number of 'for' loop in a list comprehension. - - Helper for ast_for_listcomp(). -*/ - -static int -count_list_fors(const node *n) -{ - int n_fors = 0; - node *ch = CHILD(n, 1); - - count_list_for: - n_fors++; - REQ(ch, list_for); - if (NCH(ch) == 5) - ch = CHILD(ch, 4); - else - return n_fors; - count_list_iter: - REQ(ch, list_iter); - ch = CHILD(ch, 0); - if (TYPE(ch) == list_for) - goto count_list_for; - else if (TYPE(ch) == list_if) { - if (NCH(ch) == 3) { - ch = CHILD(ch, 2); - goto count_list_iter; - } - else - return n_fors; - } - - /* Should never be reached */ - PyErr_SetString(PyExc_SystemError, "logic error in count_list_fors"); - return -1; -} - -/* Count the number of 'if' statements in a list comprehension. - - Helper for ast_for_listcomp(). -*/ - -static int -count_list_ifs(const node *n) -{ - int n_ifs = 0; - - count_list_iter: - REQ(n, list_iter); - if (TYPE(CHILD(n, 0)) == list_for) - return n_ifs; - n = CHILD(n, 0); - REQ(n, list_if); - n_ifs++; - if (NCH(n) == 2) - return n_ifs; - n = CHILD(n, 2); - goto count_list_iter; -} - -static expr_ty -ast_for_listcomp(struct compiling *c, const node *n) -{ - /* listmaker: test ( list_for | (',' test)* [','] ) - list_for: 'for' exprlist 'in' testlist_safe [list_iter] - list_iter: list_for | list_if - list_if: 'if' test [list_iter] - testlist_safe: test [(',' test)+ [',']] - */ - expr_ty elt; - asdl_seq *listcomps; - int i, n_fors; - node *ch; - - REQ(n, listmaker); - assert(NCH(n) > 1); - - elt = ast_for_expr(c, CHILD(n, 0)); - if (!elt) - return NULL; - - n_fors = count_list_fors(n); - if (n_fors == -1) - return NULL; - - listcomps = asdl_seq_new(n_fors, c->c_arena); - if (!listcomps) - return NULL; - - ch = CHILD(n, 1); - for (i = 0; i < n_fors; i++) { - comprehension_ty lc; - asdl_seq *t; - expr_ty expression; - - REQ(ch, list_for); - - t = ast_for_exprlist(c, CHILD(ch, 1), Store); - if (!t) - return NULL; - expression = ast_for_testlist(c, CHILD(ch, 3)); - if (!expression) - return NULL; - - if (asdl_seq_LEN(t) == 1) - lc = comprehension((expr_ty)asdl_seq_GET(t, 0), expression, NULL, - c->c_arena); - else - lc = comprehension(Tuple(t, Store, LINENO(ch), ch->n_col_offset, - c->c_arena), - expression, NULL, c->c_arena); - if (!lc) - return NULL; - - if (NCH(ch) == 5) { - int j, n_ifs; - asdl_seq *ifs; - - ch = CHILD(ch, 4); - n_ifs = count_list_ifs(ch); - if (n_ifs == -1) - return NULL; - - ifs = asdl_seq_new(n_ifs, c->c_arena); - if (!ifs) - return NULL; - - for (j = 0; j < n_ifs; j++) { - REQ(ch, list_iter); - ch = CHILD(ch, 0); - REQ(ch, list_if); - - asdl_seq_SET(ifs, j, ast_for_expr(c, CHILD(ch, 1))); - if (NCH(ch) == 3) - ch = CHILD(ch, 2); - } - /* on exit, must guarantee that ch is a list_for */ - if (TYPE(ch) == list_iter) - ch = CHILD(ch, 0); - lc->ifs = ifs; - } - asdl_seq_SET(listcomps, i, lc); - } - - return ListComp(elt, listcomps, LINENO(n), n->n_col_offset, c->c_arena); -} - /* Count the number of 'for' loops in a generator expression. - Helper for ast_for_genexp(). + Helper for ast_for_comprehension(). */ static int -count_gen_fors(const node *n) +count_comp_fors(const node *n) { int n_fors = 0; node *ch = CHILD(n, 1); - count_gen_for: + count_comp_for: n_fors++; - REQ(ch, gen_for); + REQ(ch, comp_for); if (NCH(ch) == 5) ch = CHILD(ch, 4); else return n_fors; - count_gen_iter: - REQ(ch, gen_iter); + count_comp_iter: + REQ(ch, comp_iter); ch = CHILD(ch, 0); - if (TYPE(ch) == gen_for) - goto count_gen_for; - else if (TYPE(ch) == gen_if) { + if (TYPE(ch) == comp_for) + goto count_comp_for; + else if (TYPE(ch) == comp_if) { if (NCH(ch) == 3) { ch = CHILD(ch, 2); - goto count_gen_iter; + goto count_comp_iter; } else return n_fors; @@ -1069,26 +918,26 @@ /* Should never be reached */ PyErr_SetString(PyExc_SystemError, - "logic error in count_gen_fors"); + "logic error in count_comp_fors"); return -1; } /* Count the number of 'if' statements in a generator expression. - Helper for ast_for_genexp(). + Helper for ast_for_comprehension(). */ static int -count_gen_ifs(const node *n) +count_comp_ifs(const node *n) { int n_ifs = 0; while (1) { - REQ(n, gen_iter); - if (TYPE(CHILD(n, 0)) == gen_for) + REQ(n, comp_iter); + if (TYPE(CHILD(n, 0)) == comp_for) return n_ifs; n = CHILD(n, 0); - REQ(n, gen_if); + REQ(n, comp_if); n_ifs++; if (NCH(n) == 2) return n_ifs; @@ -1096,39 +945,37 @@ } } -/* TODO(jhylton): Combine with list comprehension code? */ static expr_ty -ast_for_genexp(struct compiling *c, const node *n) +ast_for_comprehension(struct compiling *c, const node *n, int type) { - /* testlist_gexp: test ( gen_for | (',' test)* [','] ) - argument: [test '='] test [gen_for] # Really [keyword '='] test */ + /* testlist_comp: test ( comp_for | (',' test)* [','] ) + argument: [test '='] test [comp_for] # Really [keyword '='] test */ expr_ty elt; - asdl_seq *genexps; + asdl_seq *comps; int i, n_fors; node *ch; - assert(TYPE(n) == (testlist_gexp) || TYPE(n) == (argument)); assert(NCH(n) > 1); elt = ast_for_expr(c, CHILD(n, 0)); if (!elt) return NULL; - n_fors = count_gen_fors(n); + n_fors = count_comp_fors(n); if (n_fors == -1) return NULL; - genexps = asdl_seq_new(n_fors, c->c_arena); - if (!genexps) + comps = asdl_seq_new(n_fors, c->c_arena); + if (!comps) return NULL; ch = CHILD(n, 1); for (i = 0; i < n_fors; i++) { - comprehension_ty ge; + comprehension_ty comp; asdl_seq *t; expr_ty expression; - REQ(ch, gen_for); + REQ(ch, comp_for); t = ast_for_exprlist(c, CHILD(ch, 1), Store); if (!t) @@ -1138,14 +985,14 @@ return NULL; if (asdl_seq_LEN(t) == 1) - ge = comprehension((expr_ty)asdl_seq_GET(t, 0), expression, - NULL, c->c_arena); + comp = comprehension((expr_ty)asdl_seq_GET(t, 0), expression, + NULL, c->c_arena); else - ge = comprehension(Tuple(t, Store, LINENO(ch), ch->n_col_offset, - c->c_arena), - expression, NULL, c->c_arena); + comp = comprehension(Tuple(t, Store, LINENO(ch), ch->n_col_offset, + c->c_arena), + expression, NULL, c->c_arena); - if (!ge) + if (!comp) return NULL; if (NCH(ch) == 5) { @@ -1153,7 +1000,7 @@ asdl_seq *ifs; ch = CHILD(ch, 4); - n_ifs = count_gen_ifs(ch); + n_ifs = count_comp_ifs(ch); if (n_ifs == -1) return NULL; @@ -1162,9 +1009,9 @@ return NULL; for (j = 0; j < n_ifs; j++) { - REQ(ch, gen_iter); + REQ(ch, comp_iter); ch = CHILD(ch, 0); - REQ(ch, gen_if); + REQ(ch, comp_if); expression = ast_for_expr(c, CHILD(ch, 1)); if (!expression) @@ -1173,22 +1020,51 @@ if (NCH(ch) == 3) ch = CHILD(ch, 2); } - /* on exit, must guarantee that ch is a gen_for */ - if (TYPE(ch) == gen_iter) + /* on exit, must guarantee that ch is a comp_for */ + if (TYPE(ch) == comp_iter) ch = CHILD(ch, 0); - ge->ifs = ifs; + comp->ifs = ifs; } - asdl_seq_SET(genexps, i, ge); + asdl_seq_SET(comps, i, comp); } - return GeneratorExp(elt, genexps, LINENO(n), n->n_col_offset, c->c_arena); + if (type == 0) + return GeneratorExp(elt, comps, LINENO(n), n->n_col_offset, c->c_arena); + else if (type == 1) + return ListComp(elt, comps, LINENO(n), n->n_col_offset, c->c_arena); + else if (type == 2) + return SetComp(elt, comps, LINENO(n), n->n_col_offset, c->c_arena); + else + /* Should never happen */ + return NULL; } static expr_ty +ast_for_genexp(struct compiling *c, const node *n) +{ + assert(TYPE(n) == (testlist_comp) || TYPE(n) == (argument)); + return ast_for_comprehension(c, n, 0); +} + +static expr_ty +ast_for_listcomp(struct compiling *c, const node *n) +{ + assert(TYPE(n) == (testlist_comp)); + return ast_for_comprehension(c, n, 1); +} + +static expr_ty +ast_for_setcomp(struct compiling *c, const node *n) +{ + return ast_for_comprehension(c, n, 2); +} + + +static expr_ty ast_for_atom(struct compiling *c, const node *n) { - /* atom: '(' [yield_expr|testlist_gexp] ')' | '[' [listmaker] ']' - | '{' [dictsetmaker] '}' | NAME | NUMBER | STRING+ + /* atom: '(' [yield_expr|testlist_comp] ')' | '[' [testlist_comp] ']' + | '{' [dictmaker|testlist_comp] '}' | NAME | NUMBER | STRING+ */ node *ch = CHILD(n, 0); @@ -1222,17 +1098,19 @@ if (TYPE(ch) == yield_expr) return ast_for_expr(c, ch); - if ((NCH(ch) > 1) && (TYPE(CHILD(ch, 1)) == gen_for)) + /* testlist_comp: test ( comp_for | (',' test)* [','] ) */ + + if ((NCH(ch) > 1) && (TYPE(CHILD(ch, 1)) == comp_for)) return ast_for_genexp(c, ch); - return ast_for_testlist_gexp(c, ch); + return ast_for_testlist(c, ch); case LSQB: /* list (or list comprehension) */ ch = CHILD(n, 1); if (TYPE(ch) == RSQB) return List(NULL, Load, LINENO(n), n->n_col_offset, c->c_arena); - REQ(ch, listmaker); + REQ(ch, testlist_comp); if (NCH(ch) == 1 || TYPE(CHILD(ch, 1)) == COMMA) { asdl_seq *elts = seq_for_testlist(c, ch); if (!elts) @@ -1243,27 +1121,32 @@ else return ast_for_listcomp(c, ch); case LBRACE: { - /* dictsetmaker: test ':' test (',' test ':' test)* [','] | - * test (',' test)* [','] */ + /* dictorsetmaker: (test ':' test (',' test ':' test)* [',']) | + * (test (gen_for | (',' test)* [','])) */ int i, size; asdl_seq *keys, *values; ch = CHILD(n, 1); - if (NCH(ch) == 1 || (NCH(ch) > 0 && STR(CHILD(ch, 1))[0] == ',')) { - /* it's a set */ - size = (NCH(ch) + 1) / 2; /* +1 in case no trailing comma */ - keys = asdl_seq_new(size, c->c_arena); - if (!keys) - return NULL; + if (TYPE(ch) == RBRACE) + return Dict(NULL, NULL, LINENO(n), n->n_col_offset, c->c_arena); - for (i = 0; i < NCH(ch); i += 2) { - expr_ty expression; - expression = ast_for_expr(c, CHILD(ch, i)); - if (!expression) - return NULL; - asdl_seq_SET(keys, i / 2, expression); - } - return Set(keys, LINENO(n), n->n_col_offset, c->c_arena); + if (NCH(ch) == 1 || TYPE(CHILD(ch, 1)) == COMMA) { + /* it's a simple set */ + size = (NCH(ch) + 1) / 2; /* +1 in case no trailing comma */ + asdl_seq *elts = asdl_seq_new(size, c->c_arena); + if (!elts) + return NULL; + for (i = 0; i < NCH(ch); i += 2) { + expr_ty expression; + expression = ast_for_expr(c, CHILD(ch, i)); + if (!expression) + return NULL; + asdl_seq_SET(elts, i / 2, expression); + } + return Set(elts, LINENO(n), n->n_col_offset, c->c_arena); + } else if (TYPE(CHILD(ch, 1)) == comp_for) { + /* it's a set comprehension */ + return ast_for_setcomp(c, ch); } else { /* it's a dict */ size = (NCH(ch) + 1) / 4; /* +1 in case no trailing comma */ @@ -1594,6 +1477,7 @@ { /* handle the full range of simple expressions test: or_test ['if' or_test 'else' test] | lambdef + test_nocond: or_test | lambdef_nocond or_test: and_test ('or' and_test)* and_test: not_test ('and' not_test)* not_test: 'not' not_test | comparison @@ -1606,15 +1490,6 @@ term: factor (('*'|'/'|'%'|'//') factor)* factor: ('+'|'-'|'~') factor | power power: atom trailer* ('**' factor)* - - As well as modified versions that exist for backward compatibility, - to explicitly allow: - [ x for x in lambda: 0, lambda: 1 ] - (which would be ambiguous without these extra rules) - - old_test: or_test | old_lambdef - old_lambdef: 'lambda' [vararglist] ':' old_test - */ asdl_seq *seq; @@ -1623,9 +1498,9 @@ loop: switch (TYPE(n)) { case test: - case old_test: + case test_nocond: if (TYPE(CHILD(n, 0)) == lambdef || - TYPE(CHILD(n, 0)) == old_lambdef) + TYPE(CHILD(n, 0)) == lambdef_nocond) return ast_for_lambdef(c, CHILD(n, 0)); else if (NCH(n) > 1) return ast_for_ifexpr(c, n); @@ -1751,7 +1626,7 @@ /* arglist: (argument ',')* (argument [',']| '*' test [',' '**' test] | '**' test) - argument: [test '='] test [gen_for] # Really [keyword '='] test + argument: [test '='] test [comp_for] # Really [keyword '='] test */ int i, nargs, nkeywords, ngens; @@ -1769,7 +1644,7 @@ if (TYPE(ch) == argument) { if (NCH(ch) == 1) nargs++; - else if (TYPE(CHILD(ch, 1)) == gen_for) + else if (TYPE(CHILD(ch, 1)) == comp_for) ngens++; else nkeywords++; @@ -1809,7 +1684,7 @@ return NULL; asdl_seq_SET(args, nargs++, e); } - else if (TYPE(CHILD(ch, 1)) == gen_for) { + else if (TYPE(CHILD(ch, 1)) == comp_for) { e = ast_for_genexp(c, ch); if (!e) return NULL; @@ -1861,18 +1736,16 @@ static expr_ty ast_for_testlist(struct compiling *c, const node* n) { - /* testlist_gexp: test (',' test)* [','] */ + /* testlist_comp: test (comp_for | (',' test)* [',']) */ /* testlist: test (',' test)* [','] */ - /* testlist_safe: test (',' test)+ [','] */ /* testlist1: test (',' test)* */ assert(NCH(n) > 0); - if (TYPE(n) == testlist_gexp) { + if (TYPE(n) == testlist_comp) { if (NCH(n) > 1) - assert(TYPE(CHILD(n, 1)) != gen_for); + assert(TYPE(CHILD(n, 1)) != comp_for); } else { assert(TYPE(n) == testlist || - TYPE(n) == testlist_safe || TYPE(n) == testlist1); } if (NCH(n) == 1) @@ -1885,17 +1758,6 @@ } } -static expr_ty -ast_for_testlist_gexp(struct compiling *c, const node* n) -{ - /* testlist_gexp: test ( gen_for | (',' test)* [','] ) */ - /* argument: test [ gen_for ] */ - assert(TYPE(n) == testlist_gexp || TYPE(n) == argument); - if (NCH(n) > 1 && TYPE(CHILD(n, 1)) == gen_for) - return ast_for_genexp(c, n); - return ast_for_testlist(c, n); -} - /* like ast_for_testlist() but returns a sequence */ static asdl_seq* ast_for_class_bases(struct compiling *c, const node* n) Index: Python/symtable.c =================================================================== --- Python/symtable.c (Revision 51643) +++ Python/symtable.c (Arbeitskopie) @@ -166,6 +166,8 @@ static int symtable_visit_stmt(struct symtable *st, stmt_ty s); static int symtable_visit_expr(struct symtable *st, expr_ty s); static int symtable_visit_genexp(struct symtable *st, expr_ty s); +static int symtable_visit_listcomp(struct symtable *st, expr_ty s); +static int symtable_visit_setcomp(struct symtable *st, expr_ty s); static int symtable_visit_arguments(struct symtable *st, arguments_ty); static int symtable_visit_excepthandler(struct symtable *st, excepthandler_ty); static int symtable_visit_alias(struct symtable *st, alias_ty); @@ -177,7 +179,8 @@ static int symtable_implicit_arg(struct symtable *st, int pos); -static identifier top = NULL, lambda = NULL, genexpr = NULL; +static identifier top = NULL, lambda = NULL, genexpr = NULL, listcomp = NULL, + setcomp = NULL; #define GET_IDENTIFIER(VAR) \ ((VAR) ? (VAR) : ((VAR) = PyString_InternFromString(# VAR))) @@ -1151,11 +1154,13 @@ VISIT_SEQ(st, expr, e->v.Set.elts); break; case ListComp_kind: - if (!symtable_new_tmpname(st)) + if (!symtable_visit_listcomp(st, e)) return 0; - VISIT(st, expr, e->v.ListComp.elt); - VISIT_SEQ(st, comprehension, e->v.ListComp.generators); break; + case SetComp_kind: + if (!symtable_visit_setcomp(st, e)) + return 0; + break; case GeneratorExp_kind: if (!symtable_visit_genexp(st, e)) return 0; @@ -1422,3 +1427,61 @@ VISIT_IN_BLOCK(st, expr, e->v.GeneratorExp.elt, (void*)e); return symtable_exit_block(st, (void *)e); } + +static int +symtable_visit_listcomp(struct symtable *st, expr_ty e) +{ + comprehension_ty outermost = ((comprehension_ty) + (asdl_seq_GET(e->v.ListComp.generators, 0))); + /* Outermost iterator is evaluated in current scope */ + VISIT(st, expr, outermost->iter); + /* Create listcomp scope for the rest */ + if (!GET_IDENTIFIER(listcomp) || + !symtable_enter_block(st, listcomp, FunctionBlock, (void *)e, 0)) { + return 0; + } + /* Outermost iter and list to fill are received as an argument */ + if (!symtable_implicit_arg(st, 0)) { + symtable_exit_block(st, (void *)e); + return 0; + } + if (!symtable_implicit_arg(st, 1)) { + symtable_exit_block(st, (void *)e); + return 0; + } + VISIT_IN_BLOCK(st, expr, outermost->target, (void*)e); + VISIT_SEQ_IN_BLOCK(st, expr, outermost->ifs, (void*)e); + VISIT_SEQ_TAIL_IN_BLOCK(st, comprehension, + e->v.ListComp.generators, 1, (void*)e); + VISIT_IN_BLOCK(st, expr, e->v.ListComp.elt, (void*)e); + return symtable_exit_block(st, (void *)e); +} + +static int +symtable_visit_setcomp(struct symtable *st, expr_ty e) +{ + comprehension_ty outermost = ((comprehension_ty) + (asdl_seq_GET(e->v.SetComp.generators, 0))); + /* Outermost iterator is evaluated in current scope */ + VISIT(st, expr, outermost->iter); + /* Create setcomp scope for the rest */ + if (!GET_IDENTIFIER(setcomp) || + !symtable_enter_block(st, setcomp, FunctionBlock, (void *)e, 0)) { + return 0; + } + /* Outermost iter and set to fill are received as an argument */ + if (!symtable_implicit_arg(st, 0)) { + symtable_exit_block(st, (void *)e); + return 0; + } + if (!symtable_implicit_arg(st, 1)) { + symtable_exit_block(st, (void *)e); + return 0; + } + VISIT_IN_BLOCK(st, expr, outermost->target, (void*)e); + VISIT_SEQ_IN_BLOCK(st, expr, outermost->ifs, (void*)e); + VISIT_SEQ_TAIL_IN_BLOCK(st, comprehension, + e->v.SetComp.generators, 1, (void*)e); + VISIT_IN_BLOCK(st, expr, e->v.SetComp.elt, (void*)e); + return symtable_exit_block(st, (void *)e); +} Index: Python/compile.c =================================================================== --- Python/compile.c (Revision 51643) +++ Python/compile.c (Arbeitskopie) @@ -724,6 +724,7 @@ case UNARY_INVERT: return 0; + case SET_ADD: case LIST_APPEND: return -2; @@ -2536,105 +2537,106 @@ return 1; } -static int -compiler_listcomp_generator(struct compiler *c, PyObject *tmpname, - asdl_seq *generators, int gen_index, - expr_ty elt) -{ - /* generate code for the iterator, then each of the ifs, - and then write to the element */ +/* static int */ +/* compiler_listcomp_generator(struct compiler *c, PyObject *tmpname, */ +/* asdl_seq *generators, int gen_index, */ +/* expr_ty elt) */ +/* { */ +/* /\* generate code for the iterator, then each of the ifs, */ +/* and then write to the element *\/ */ - comprehension_ty l; - basicblock *start, *anchor, *skip, *if_cleanup; - int i, n; +/* comprehension_ty l; */ +/* basicblock *start, *anchor, *skip, *if_cleanup; */ +/* int i, n; */ - start = compiler_new_block(c); - skip = compiler_new_block(c); - if_cleanup = compiler_new_block(c); - anchor = compiler_new_block(c); +/* 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; +/* if (start == NULL || skip == NULL || if_cleanup == NULL || */ +/* anchor == NULL) */ +/* return 0; */ - l = (comprehension_ty)asdl_seq_GET(generators, gen_index); - VISIT(c, expr, l->iter); - ADDOP(c, GET_ITER); - compiler_use_next_block(c, start); - ADDOP_JREL(c, FOR_ITER, anchor); - NEXT_BLOCK(c); - VISIT(c, expr, l->target); +/* l = (comprehension_ty)asdl_seq_GET(generators, gen_index); */ +/* VISIT(c, expr, l->iter); */ +/* ADDOP(c, GET_ITER); */ +/* compiler_use_next_block(c, start); */ +/* ADDOP_JREL(c, FOR_ITER, anchor); */ +/* NEXT_BLOCK(c); */ +/* VISIT(c, expr, l->target); */ - /* XXX this needs to be cleaned up...a lot! */ - n = asdl_seq_LEN(l->ifs); - for (i = 0; i < n; i++) { - expr_ty e = (expr_ty)asdl_seq_GET(l->ifs, i); - VISIT(c, expr, e); - ADDOP_JREL(c, JUMP_IF_FALSE, if_cleanup); - NEXT_BLOCK(c); - ADDOP(c, POP_TOP); - } +/* /\* XXX this needs to be cleaned up...a lot! *\/ */ +/* n = asdl_seq_LEN(l->ifs); */ +/* for (i = 0; i < n; i++) { */ +/* expr_ty e = (expr_ty)asdl_seq_GET(l->ifs, i); */ +/* VISIT(c, expr, e); */ +/* ADDOP_JREL(c, JUMP_IF_FALSE, if_cleanup); */ +/* NEXT_BLOCK(c); */ +/* ADDOP(c, POP_TOP); */ +/* } */ - if (++gen_index < asdl_seq_LEN(generators)) - if (!compiler_listcomp_generator(c, tmpname, - generators, gen_index, elt)) - return 0; +/* if (++gen_index < asdl_seq_LEN(generators)) */ +/* if (!compiler_listcomp_generator(c, tmpname, */ +/* generators, gen_index, elt)) */ +/* return 0; */ - /* only append after the last for generator */ - if (gen_index >= asdl_seq_LEN(generators)) { - if (!compiler_nameop(c, tmpname, Load)) - return 0; - VISIT(c, expr, elt); - ADDOP(c, LIST_APPEND); +/* /\* only append after the last for generator *\/ */ +/* if (gen_index >= asdl_seq_LEN(generators)) { */ +/* if (!compiler_nameop(c, tmpname, Load)) */ +/* return 0; */ +/* VISIT(c, expr, elt); */ +/* ADDOP(c, LIST_APPEND); */ - compiler_use_next_block(c, skip); - } - for (i = 0; i < n; i++) { - ADDOP_I(c, JUMP_FORWARD, 1); - if (i == 0) - compiler_use_next_block(c, if_cleanup); - ADDOP(c, POP_TOP); - } - ADDOP_JABS(c, JUMP_ABSOLUTE, start); - compiler_use_next_block(c, anchor); - /* delete the append method added to locals */ - if (gen_index == 1) - if (!compiler_nameop(c, tmpname, Del)) - return 0; +/* compiler_use_next_block(c, skip); */ +/* } */ +/* for (i = 0; i < n; i++) { */ +/* ADDOP_I(c, JUMP_FORWARD, 1); */ +/* if (i == 0) */ +/* compiler_use_next_block(c, if_cleanup); */ +/* ADDOP(c, POP_TOP); */ +/* } */ +/* ADDOP_JABS(c, JUMP_ABSOLUTE, start); */ +/* compiler_use_next_block(c, anchor); */ +/* /\* delete the append method added to locals *\/ */ +/* if (gen_index == 1) */ +/* if (!compiler_nameop(c, tmpname, Del)) */ +/* return 0; */ - return 1; -} +/* return 1; */ +/* } */ -static int -compiler_listcomp(struct compiler *c, expr_ty e) -{ - identifier tmp; - int rc = 0; - static identifier append; - asdl_seq *generators = e->v.ListComp.generators; +/* static int */ +/* compiler_listcomp(struct compiler *c, expr_ty e) */ +/* { */ +/* identifier tmp; */ +/* int rc = 0; */ +/* static identifier append; */ +/* asdl_seq *generators = e->v.ListComp.generators; */ - assert(e->kind == ListComp_kind); - if (!append) { - append = PyString_InternFromString("append"); - if (!append) - return 0; - } - tmp = compiler_new_tmpname(c); - if (!tmp) - return 0; - ADDOP_I(c, BUILD_LIST, 0); - ADDOP(c, DUP_TOP); - if (compiler_nameop(c, tmp, Store)) - rc = compiler_listcomp_generator(c, tmp, generators, 0, - e->v.ListComp.elt); - Py_DECREF(tmp); - return rc; -} +/* assert(e->kind == ListComp_kind); */ +/* if (!append) { */ +/* append = PyString_InternFromString("append"); */ +/* if (!append) */ +/* return 0; */ +/* } */ +/* tmp = compiler_new_tmpname(c); */ +/* if (!tmp) */ +/* return 0; */ +/* ADDOP_I(c, BUILD_LIST, 0); */ +/* ADDOP(c, DUP_TOP); */ +/* if (compiler_nameop(c, tmp, Store)) */ +/* rc = compiler_listcomp_generator(c, tmp, generators, 0, */ +/* e->v.ListComp.elt); */ +/* Py_DECREF(tmp); */ +/* return rc; */ +/* } */ + +/* type: 0 - genexp, 1 - listcomp, 2 - setcomp */ static int -compiler_genexp_generator(struct compiler *c, - asdl_seq *generators, int gen_index, - expr_ty elt) +compiler_comp_generator(struct compiler *c, asdl_seq *generators, + int gen_index, expr_ty elt, int type) { /* generate code for the iterator, then each of the ifs, and then write to the element */ @@ -2660,7 +2662,8 @@ if (gen_index == 0) { /* Receive outermost iter as an implicit argument */ - c->u->u_argcount = 1; + /* List and set comps have an additional argument: the list/set */ + c->u->u_argcount = (type == 0 ? 1 : 2); ADDOP_I(c, LOAD_FAST, 0); } else { @@ -2684,14 +2687,24 @@ } if (++gen_index < asdl_seq_LEN(generators)) - if (!compiler_genexp_generator(c, generators, gen_index, elt)) + if (!compiler_comp_generator(c, generators, gen_index, elt, type)) return 0; /* only append after the last 'for' generator */ if (gen_index >= asdl_seq_LEN(generators)) { - VISIT(c, expr, elt); - ADDOP(c, YIELD_VALUE); - ADDOP(c, POP_TOP); + if (type == 0) { + VISIT(c, expr, elt); + ADDOP(c, YIELD_VALUE); + ADDOP(c, POP_TOP); + } else if (type == 1) { + ADDOP_I(c, LOAD_FAST, 1); + VISIT(c, expr, elt); + ADDOP(c, LIST_APPEND); + } else { + ADDOP_I(c, LOAD_FAST, 1); + VISIT(c, expr, elt); + ADDOP(c, SET_ADD); + } compiler_use_next_block(c, skip); } @@ -2711,25 +2724,43 @@ return 1; } +/* type: 0 - genexp, 1 - listcomp, 2 - setcomp */ static int -compiler_genexp(struct compiler *c, expr_ty e) +compiler_comprehension(struct compiler *c, expr_ty e, int type) { static identifier name; PyCodeObject *co; - expr_ty outermost_iter = ((comprehension_ty) - (asdl_seq_GET(e->v.GeneratorExp.generators, - 0)))->iter; + expr_ty outermost_iter; if (!name) { - name = PyString_FromString(""); + name = PyString_FromString( + (type == 0 ? "" : (type == 1 ? "" : ""))); if (!name) return 0; } if (!compiler_enter_scope(c, name, (void *)e, e->lineno)) return 0; - compiler_genexp_generator(c, e->v.GeneratorExp.generators, 0, - e->v.GeneratorExp.elt); + if (type == 0) { + outermost_iter = ((comprehension_ty) + (asdl_seq_GET(e->v.GeneratorExp.generators, + 0)))->iter; + compiler_comp_generator(c, e->v.GeneratorExp.generators, 0, + e->v.GeneratorExp.elt, 0); + } else if (type == 1) { + outermost_iter = ((comprehension_ty) + (asdl_seq_GET(e->v.ListComp.generators, + 0)))->iter; + compiler_comp_generator(c, e->v.ListComp.generators, 0, + e->v.ListComp.elt, 1); + } else { + outermost_iter = ((comprehension_ty) + (asdl_seq_GET(e->v.SetComp.generators, + 0)))->iter; + compiler_comp_generator(c, e->v.SetComp.generators, 0, + e->v.SetComp.elt, 2); + } + co = assemble(c, 1); compiler_exit_scope(c); if (co == NULL) @@ -2740,12 +2771,44 @@ VISIT(c, expr, outermost_iter); ADDOP(c, GET_ITER); - ADDOP_I(c, CALL_FUNCTION, 1); + if (type == 0) { + ADDOP_I(c, CALL_FUNCTION, 1); + } else if (type == 1) { + ADDOP_I(c, BUILD_LIST, 0); + ADDOP(c, DUP_TOP); + ADDOP(c, ROT_FOUR); + ADDOP_I(c, CALL_FUNCTION, 2); + ADDOP(c, POP_TOP); + } else { + ADDOP_I(c, BUILD_SET, 0); + ADDOP(c, DUP_TOP); + ADDOP(c, ROT_FOUR); + ADDOP_I(c, CALL_FUNCTION, 2); + ADDOP(c, POP_TOP); + } return 1; } static int +compiler_genexp(struct compiler *c, expr_ty e) +{ + return compiler_comprehension(c, e, 0); +} + +static int +compiler_listcomp(struct compiler *c, expr_ty e) +{ + return compiler_comprehension(c, e, 1); +} + +static int +compiler_setcomp(struct compiler *c, expr_ty e) +{ + return compiler_comprehension(c, e, 2); +} + +static int compiler_visit_keyword(struct compiler *c, keyword_ty k) { ADDOP_O(c, LOAD_CONST, k->arg, consts); @@ -2963,6 +3026,8 @@ break; case ListComp_kind: return compiler_listcomp(c, e); + case SetComp_kind: + return compiler_setcomp(c, e); case GeneratorExp_kind: return compiler_genexp(c, e); case Yield_kind: Index: Python/Python-ast.c =================================================================== --- Python/Python-ast.c (Revision 51643) +++ Python/Python-ast.c (Arbeitskopie) @@ -187,6 +187,11 @@ "elt", "generators", }; +static PyTypeObject *SetComp_type; +static char *SetComp_fields[]={ + "elt", + "generators", +}; static PyTypeObject *GeneratorExp_type; static char *GeneratorExp_fields[]={ "elt", @@ -525,6 +530,8 @@ if (!Set_type) return 0; ListComp_type = make_type("ListComp", expr_type, ListComp_fields, 2); if (!ListComp_type) return 0; + SetComp_type = make_type("SetComp", expr_type, SetComp_fields, 2); + if (!SetComp_type) return 0; GeneratorExp_type = make_type("GeneratorExp", expr_type, GeneratorExp_fields, 2); if (!GeneratorExp_type) return 0; @@ -1480,6 +1487,29 @@ } expr_ty +SetComp(expr_ty elt, asdl_seq * generators, int lineno, int col_offset, PyArena + *arena) +{ + expr_ty p; + if (!elt) { + PyErr_SetString(PyExc_ValueError, + "field elt is required for SetComp"); + return NULL; + } + p = (expr_ty)PyArena_Malloc(arena, sizeof(*p)); + if (!p) { + PyErr_NoMemory(); + return NULL; + } + p->kind = SetComp_kind; + p->v.SetComp.elt = elt; + p->v.SetComp.generators = generators; + p->lineno = lineno; + p->col_offset = col_offset; + return p; +} + +expr_ty GeneratorExp(expr_ty elt, asdl_seq * generators, int lineno, int col_offset, PyArena *arena) { @@ -2470,6 +2500,21 @@ goto failed; Py_DECREF(value); break; + case SetComp_kind: + result = PyType_GenericNew(SetComp_type, NULL, NULL); + if (!result) goto failed; + value = ast2obj_expr(o->v.SetComp.elt); + if (!value) goto failed; + if (PyObject_SetAttrString(result, "elt", value) == -1) + goto failed; + Py_DECREF(value); + value = ast2obj_list(o->v.SetComp.generators, + ast2obj_comprehension); + if (!value) goto failed; + if (PyObject_SetAttrString(result, "generators", value) == -1) + goto failed; + Py_DECREF(value); + break; case GeneratorExp_kind: result = PyType_GenericNew(GeneratorExp_type, NULL, NULL); if (!result) goto failed; @@ -3103,6 +3148,8 @@ if (PyDict_SetItemString(d, "Set", (PyObject*)Set_type) < 0) return; if (PyDict_SetItemString(d, "ListComp", (PyObject*)ListComp_type) < 0) return; + if (PyDict_SetItemString(d, "SetComp", (PyObject*)SetComp_type) < 0) + return; if (PyDict_SetItemString(d, "GeneratorExp", (PyObject*)GeneratorExp_type) < 0) return; if (PyDict_SetItemString(d, "Yield", (PyObject*)Yield_type) < 0) return; Index: Include/opcode.h =================================================================== --- Include/opcode.h (Revision 51643) +++ Include/opcode.h (Arbeitskopie) @@ -21,6 +21,7 @@ #define UNARY_INVERT 15 +#define SET_ADD 17 #define LIST_APPEND 18 #define BINARY_POWER 19 Index: Include/graminit.h =================================================================== --- Include/graminit.h (Revision 51643) +++ Include/graminit.h (Arbeitskopie) @@ -42,10 +42,10 @@ #define with_var 297 #define except_clause 298 #define suite 299 -#define testlist_safe 300 -#define old_test 301 -#define old_lambdef 302 -#define test 303 +#define test 300 +#define test_nocond 301 +#define lambdef 302 +#define lambdef_nocond 303 #define or_test 304 #define and_test 305 #define not_test 306 @@ -60,25 +60,20 @@ #define factor 315 #define power 316 #define atom 317 -#define listmaker 318 -#define testlist_gexp 319 -#define lambdef 320 -#define trailer 321 -#define subscriptlist 322 -#define subscript 323 -#define sliceop 324 -#define exprlist 325 -#define testlist 326 -#define dictsetmaker 327 -#define classdef 328 -#define arglist 329 -#define argument 330 -#define list_iter 331 -#define list_for 332 -#define list_if 333 -#define gen_iter 334 -#define gen_for 335 -#define gen_if 336 -#define testlist1 337 -#define encoding_decl 338 -#define yield_expr 339 +#define testlist_comp 318 +#define trailer 319 +#define subscriptlist 320 +#define subscript 321 +#define sliceop 322 +#define exprlist 323 +#define testlist 324 +#define dictorsetmaker 325 +#define classdef 326 +#define arglist 327 +#define argument 328 +#define comp_iter 329 +#define comp_for 330 +#define comp_if 331 +#define testlist1 332 +#define encoding_decl 333 +#define yield_expr 334 Index: Include/Python-ast.h =================================================================== --- Include/Python-ast.h (Revision 51643) +++ Include/Python-ast.h (Arbeitskopie) @@ -185,9 +185,10 @@ enum _expr_kind {BoolOp_kind=1, BinOp_kind=2, UnaryOp_kind=3, Lambda_kind=4, IfExp_kind=5, Dict_kind=6, Set_kind=7, ListComp_kind=8, - GeneratorExp_kind=9, Yield_kind=10, Compare_kind=11, - Call_kind=12, Num_kind=13, Str_kind=14, Attribute_kind=15, - Subscript_kind=16, Name_kind=17, List_kind=18, Tuple_kind=19}; + SetComp_kind=9, GeneratorExp_kind=10, Yield_kind=11, + Compare_kind=12, Call_kind=13, Num_kind=14, Str_kind=15, + Attribute_kind=16, Subscript_kind=17, Name_kind=18, + List_kind=19, Tuple_kind=20}; struct _expr { enum _expr_kind kind; union { @@ -235,6 +236,11 @@ struct { expr_ty elt; asdl_seq *generators; + } SetComp; + + struct { + expr_ty elt; + asdl_seq *generators; } GeneratorExp; struct { @@ -406,6 +412,8 @@ expr_ty Set(asdl_seq * elts, int lineno, int col_offset, PyArena *arena); expr_ty ListComp(expr_ty elt, asdl_seq * generators, int lineno, int col_offset, PyArena *arena); +expr_ty SetComp(expr_ty elt, asdl_seq * generators, int lineno, int col_offset, + PyArena *arena); expr_ty GeneratorExp(expr_ty elt, asdl_seq * generators, int lineno, int col_offset, PyArena *arena); expr_ty Yield(expr_ty value, int lineno, int col_offset, PyArena *arena); Index: Grammar/Grammar =================================================================== --- Grammar/Grammar (Revision 51643) +++ Grammar/Grammar (Arbeitskopie) @@ -76,16 +76,10 @@ except_clause: 'except' [test [',' test]] suite: simple_stmt | NEWLINE INDENT stmt+ DEDENT -# Backward compatibility cruft to support: -# [ x for x in lambda: True, lambda: False if x() ] -# even while also allowing: -# lambda x: 5 if x else 2 -# (But not a mix of the two) -testlist_safe: old_test [(',' old_test)+ [',']] -old_test: or_test | old_lambdef -old_lambdef: 'lambda' [varargslist] ':' old_test - test: or_test ['if' or_test 'else' test] | lambdef +test_nocond: or_test | lambdef_nocond +lambdef: 'lambda' [varargslist] ':' test +lambdef_nocond: 'lambda' [varargslist] ':' test_nocond or_test: and_test ('or' and_test)* and_test: not_test ('and' not_test)* not_test: 'not' not_test | comparison @@ -99,34 +93,29 @@ term: factor (('*'|'/'|'%'|'//') factor)* factor: ('+'|'-'|'~') factor | power power: atom trailer* ['**' factor] -atom: ('(' [yield_expr|testlist_gexp] ')' | - '[' [listmaker] ']' | - '{' [dictsetmaker] '}' | +atom: ('(' [yield_expr|testlist_comp] ')' | + '[' [testlist_comp] ']' | + '{' [dictorsetmaker] '}' | NAME | NUMBER | STRING+) -listmaker: test ( list_for | (',' test)* [','] ) -testlist_gexp: test ( gen_for | (',' test)* [','] ) -lambdef: 'lambda' [varargslist] ':' test +testlist_comp: test ( comp_for | (',' test)* [','] ) trailer: '(' [arglist] ')' | '[' subscriptlist ']' | '.' NAME subscriptlist: subscript (',' subscript)* [','] subscript: '.' '.' '.' | test | [test] ':' [test] [sliceop] sliceop: ':' [test] exprlist: expr (',' expr)* [','] testlist: test (',' test)* [','] -dictsetmaker: (test ':' test (',' test ':' test)* [',']) | (test (',' test)* [',']) +dictorsetmaker: (test ':' test (',' test ':' test)* [',']) | (test (comp_for | (',' test)* [','])) classdef: 'class' NAME ['(' [testlist] ')'] ':' suite arglist: (argument ',')* (argument [',']| '*' test [',' '**' test] | '**' test) -argument: test [gen_for] | test '=' test # Really [keyword '='] test +argument: test [comp_for] | test '=' test # Really [keyword '='] test -list_iter: list_for | list_if -list_for: 'for' exprlist 'in' testlist_safe [list_iter] -list_if: 'if' old_test [list_iter] +# for list/set comprehensions, genexps +comp_iter: comp_for | comp_if +comp_for: 'for' exprlist 'in' or_test [comp_iter] +comp_if: 'if' test_nocond [comp_iter] -gen_iter: gen_for | gen_if -gen_for: 'for' exprlist 'in' or_test [gen_iter] -gen_if: 'if' old_test [gen_iter] - testlist1: test (',' test)* # not used in grammar, but may appear in "node" passed from Parser to Compiler Index: setup.py =================================================================== --- setup.py (Revision 51643) +++ setup.py (Arbeitskopie) @@ -1168,8 +1168,8 @@ # include_dirs = [ join(F, fw + '.framework', H) - for fw in 'Tcl', 'Tk' - for H in 'Headers', 'Versions/Current/PrivateHeaders' + for fw in ('Tcl', 'Tk') + for H in ('Headers', 'Versions/Current/PrivateHeaders') ] # For 8.4a2, the X11 headers are not included. Rather than include a Index: Parser/Python.asdl =================================================================== --- Parser/Python.asdl (Revision 51643) +++ Parser/Python.asdl (Arbeitskopie) @@ -58,6 +58,7 @@ | Dict(expr* keys, expr* values) | Set(expr* elts) | ListComp(expr elt, comprehension* generators) + | SetComp(expr elt, comprehension* generators) | GeneratorExp(expr elt, comprehension* generators) -- the grammar constrains where yield expressions can occur | Yield(expr? value) Index: Doc/lib/libdis.tex =================================================================== --- Doc/lib/libdis.tex (Revision 51643) +++ Doc/lib/libdis.tex (Arbeitskopie) @@ -384,6 +384,10 @@ instruction). \end{opcodedesc} +\begin{opcodedesc}{SET_ADD}{} +Calls \code{set.append(TOS1, TOS)}. Used to implement set comprehensions. +\end{opcodedesc} + \begin{opcodedesc}{LIST_APPEND}{} Calls \code{list.append(TOS1, TOS)}. Used to implement list comprehensions. \end{opcodedesc} Index: Lib/tokenize.py =================================================================== --- Lib/tokenize.py (Revision 51643) +++ Lib/tokenize.py (Arbeitskopie) @@ -32,7 +32,6 @@ import token __all__ = [x for x in dir(token) if x[0] != '_'] + ["COMMENT", "tokenize", "generate_tokens", "NL", "untokenize"] -del x del token COMMENT = N_TOKENS Index: Lib/compiler/transformer.py =================================================================== --- Lib/compiler/transformer.py (Revision 51643) +++ Lib/compiler/transformer.py (Arbeitskopie) @@ -569,7 +569,7 @@ testlist1 = testlist exprlist = testlist - def testlist_gexp(self, nodelist): + def testlist_comp(self, nodelist): if len(nodelist) == 2 and nodelist[1][0] == symbol.gen_for: test = self.com_node(nodelist[0]) return self.com_generator_expression(test, nodelist[1]) @@ -982,7 +982,7 @@ # loop to avoid trivial recursion while 1: t = node[0] - if t in (symbol.exprlist, symbol.testlist, symbol.testlist_safe, symbol.testlist_gexp): + if t in (symbol.exprlist, symbol.testlist, symbol.testlist_comp): if len(node) > 2: return self.com_assign_tuple(node, assigning) node = node[1] @@ -1139,44 +1139,43 @@ values.append(self.com_node(nodelist[i])) return List(values, lineno=values[0].lineno) - if hasattr(symbol, 'gen_for'): - def com_generator_expression(self, expr, node): - # gen_iter: gen_for | gen_if - # gen_for: 'for' exprlist 'in' test [gen_iter] - # gen_if: 'if' test [gen_iter] + def com_generator_expression(self, expr, node): + # comp_iter: comp_for | comp_if + # comp_for: 'for' exprlist 'in' test [comp_iter] + # comp_if: 'if' test [comp_iter] - lineno = node[1][2] - fors = [] - while node: - t = node[1][1] - if t == 'for': - assignNode = self.com_assign(node[2], OP_ASSIGN) - genNode = self.com_node(node[4]) - newfor = GenExprFor(assignNode, genNode, [], - lineno=node[1][2]) - fors.append(newfor) - if (len(node)) == 5: - node = None - else: - node = self.com_gen_iter(node[5]) - elif t == 'if': - test = self.com_node(node[2]) - newif = GenExprIf(test, lineno=node[1][2]) - newfor.ifs.append(newif) - if len(node) == 3: - node = None - else: - node = self.com_gen_iter(node[3]) + lineno = node[1][2] + fors = [] + while node: + t = node[1][1] + if t == 'for': + assignNode = self.com_assign(node[2], OP_ASSIGN) + genNode = self.com_node(node[4]) + newfor = GenExprFor(assignNode, genNode, [], + lineno=node[1][2]) + fors.append(newfor) + if (len(node)) == 5: + node = None else: - raise SyntaxError, \ - ("unexpected generator expression element: %s %d" - % (node, lineno)) - fors[0].is_outmost = True - return GenExpr(GenExprInner(expr, fors), lineno=lineno) + node = self.com_gen_iter(node[5]) + elif t == 'if': + test = self.com_node(node[2]) + newif = GenExprIf(test, lineno=node[1][2]) + newfor.ifs.append(newif) + if len(node) == 3: + node = None + else: + node = self.com_gen_iter(node[3]) + else: + raise SyntaxError, \ + ("unexpected generator expression element: %s %d" + % (node, lineno)) + fors[0].is_outmost = True + return GenExpr(GenExprInner(expr, fors), lineno=lineno) - def com_gen_iter(self, node): - assert node[0] == symbol.gen_iter - return node[1] + def com_gen_iter(self, node): + assert node[0] == symbol.gen_iter + return node[1] def com_dictsetmaker(self, nodelist): # dictsetmaker: (test ':' test (',' test ':' value)* [',']) | (test (',' test)* [',']) Index: Lib/decimal.py =================================================================== --- Lib/decimal.py (Revision 51643) +++ Lib/decimal.py (Arbeitskopie) @@ -2248,10 +2248,8 @@ _ignored_flags = [] if not isinstance(flags, dict): flags = dict([(s,s in flags) for s in _signals]) - del s if traps is not None and not isinstance(traps, dict): traps = dict([(s,s in traps) for s in _signals]) - del s for name, val in locals().items(): if val is None: setattr(self, name, _copy.copy(getattr(DefaultContext, name))) Index: Lib/opcode.py =================================================================== --- Lib/opcode.py (Revision 51643) +++ Lib/opcode.py (Arbeitskopie) @@ -57,6 +57,7 @@ def_op('UNARY_INVERT', 15) +def_op('SET_ADD', 17) def_op('LIST_APPEND', 18) def_op('BINARY_POWER', 19) def_op('BINARY_MULTIPLY', 20) Index: Lib/test/test_datetime.py =================================================================== --- Lib/test/test_datetime.py (Revision 51643) +++ Lib/test/test_datetime.py (Arbeitskopie) @@ -20,9 +20,9 @@ from datetime import date, datetime pickle_choices = [(pickler, unpickler, proto) - for pickler in pickle, cPickle + for pickler in (pickle, cPickle) if pickler is not None - for unpickler in pickle, cPickle + for unpickler in (pickle, cPickle) if unpickler is not None for proto in range(3)] if cPickle is None: Index: Lib/test/test_grammar.py =================================================================== --- Lib/test/test_grammar.py (Revision 51643) +++ Lib/test/test_grammar.py (Arbeitskopie) @@ -833,7 +833,7 @@ print x return ret -verify([ x() for x in lambda: True, lambda: False if x() ] == [True]) +#verify([ x() for x in lambda: True, lambda: False if x() ] == [True]) verify([ x() for x in (lambda: True, lambda: False) if x() ] == [True]) verify([ x(False) for x in (lambda x: False if x else True, lambda x: True if x else False) if x(False) ] == [True]) verify((5 if 1 else _checkeval("check 1", 0)) == 5) Index: Lib/pickle.py =================================================================== --- Lib/pickle.py (Revision 51643) +++ Lib/pickle.py (Arbeitskopie) @@ -163,7 +163,6 @@ __all__.extend([x for x in dir() if re.match("[A-Z][A-Z0-9_]+$",x)]) -del x # Pickling machinery Index: Modules/parsermodule.c =================================================================== --- Modules/parsermodule.c (Revision 51643) +++ Modules/parsermodule.c (Arbeitskopie) @@ -843,11 +843,10 @@ VALIDATER(stmt); VALIDATER(simple_stmt); VALIDATER(expr_stmt); VALIDATER(power); VALIDATER(print_stmt); VALIDATER(del_stmt); -VALIDATER(return_stmt); VALIDATER(list_iter); -VALIDATER(raise_stmt); VALIDATER(import_stmt); +VALIDATER(return_stmt); VALIDATER(raise_stmt); +VALIDATER(import_stmt); VALIDATER(yield_stmt); VALIDATER(import_name); VALIDATER(import_from); -VALIDATER(global_stmt); VALIDATER(list_if); -VALIDATER(assert_stmt); VALIDATER(list_for); +VALIDATER(global_stmt); VALIDATER(assert_stmt); VALIDATER(exec_stmt); VALIDATER(compound_stmt); VALIDATER(while); VALIDATER(for); VALIDATER(try); VALIDATER(except_clause); @@ -860,14 +859,13 @@ VALIDATER(atom); VALIDATER(lambdef); VALIDATER(trailer); VALIDATER(subscript); VALIDATER(subscriptlist); VALIDATER(sliceop); -VALIDATER(exprlist); VALIDATER(dictsetmaker); +VALIDATER(exprlist); VALIDATER(dictorsetmaker); VALIDATER(arglist); VALIDATER(argument); -VALIDATER(listmaker); VALIDATER(yield_stmt); -VALIDATER(testlist1); VALIDATER(gen_for); -VALIDATER(gen_iter); VALIDATER(gen_if); -VALIDATER(testlist_gexp); VALIDATER(yield_expr); +VALIDATER(testlist1); VALIDATER(comp_for); +VALIDATER(comp_iter); VALIDATER(comp_if); +VALIDATER(testlist_comp); VALIDATER(yield_expr); VALIDATER(yield_or_testlist); VALIDATER(or_test); -VALIDATER(old_test); VALIDATER(old_lambdef); +VALIDATER(test_nocond); VALIDATER(lambdef_nocond); #undef VALIDATER @@ -1097,14 +1095,6 @@ } -static int -validate_testlist_safe(node *tree) -{ - return (validate_repeating_list(tree, testlist_safe, - validate_old_test, "testlist_safe")); -} - - /* '*' NAME [',' '**' NAME] | '**' NAME */ static int @@ -1252,116 +1242,59 @@ } -/* list_iter: list_for | list_if +/* comp_iter: comp_for | comp_if */ static int -validate_list_iter(node *tree) +validate_comp_iter(node *tree) { - int res = (validate_ntype(tree, list_iter) - && validate_numnodes(tree, 1, "list_iter")); - if (res && TYPE(CHILD(tree, 0)) == list_for) - res = validate_list_for(CHILD(tree, 0)); + int res = (validate_ntype(tree, comp_iter) + && validate_numnodes(tree, 1, "comp_iter")); + if (res && TYPE(CHILD(tree, 0)) == comp_for) + res = validate_comp_for(CHILD(tree, 0)); else - res = validate_list_if(CHILD(tree, 0)); + res = validate_comp_if(CHILD(tree, 0)); return res; } -/* gen_iter: gen_for | gen_if +/* comp_for: 'for' exprlist 'in' test [comp_iter] */ static int -validate_gen_iter(node *tree) +validate_comp_for(node *tree) { - int res = (validate_ntype(tree, gen_iter) - && validate_numnodes(tree, 1, "gen_iter")); - if (res && TYPE(CHILD(tree, 0)) == gen_for) - res = validate_gen_for(CHILD(tree, 0)); - else - res = validate_gen_if(CHILD(tree, 0)); - - return res; -} - -/* list_for: 'for' exprlist 'in' testlist [list_iter] - */ -static int -validate_list_for(node *tree) -{ int nch = NCH(tree); int res; if (nch == 5) - res = validate_list_iter(CHILD(tree, 4)); + res = validate_comp_iter(CHILD(tree, 4)); else - res = validate_numnodes(tree, 4, "list_for"); + res = validate_numnodes(tree, 4, "comp_for"); if (res) res = (validate_name(CHILD(tree, 0), "for") && validate_exprlist(CHILD(tree, 1)) && validate_name(CHILD(tree, 2), "in") - && validate_testlist_safe(CHILD(tree, 3))); - - return res; -} - -/* gen_for: 'for' exprlist 'in' test [gen_iter] - */ -static int -validate_gen_for(node *tree) -{ - int nch = NCH(tree); - int res; - - if (nch == 5) - res = validate_gen_iter(CHILD(tree, 4)); - else - res = validate_numnodes(tree, 4, "gen_for"); - - if (res) - res = (validate_name(CHILD(tree, 0), "for") - && validate_exprlist(CHILD(tree, 1)) - && validate_name(CHILD(tree, 2), "in") && validate_or_test(CHILD(tree, 3))); return res; } -/* list_if: 'if' old_test [list_iter] +/* comp_if: 'if' test_nocond [comp_iter] */ static int -validate_list_if(node *tree) +validate_comp_if(node *tree) { int nch = NCH(tree); int res; if (nch == 3) - res = validate_list_iter(CHILD(tree, 2)); + res = validate_comp_iter(CHILD(tree, 2)); else - res = validate_numnodes(tree, 2, "list_if"); - - if (res) - res = (validate_name(CHILD(tree, 0), "if") - && validate_old_test(CHILD(tree, 1))); - - return res; -} - -/* gen_if: 'if' old_test [gen_iter] - */ -static int -validate_gen_if(node *tree) -{ - int nch = NCH(tree); - int res; - - if (nch == 3) - res = validate_gen_iter(CHILD(tree, 2)); - else - res = validate_numnodes(tree, 2, "gen_if"); + res = validate_numnodes(tree, 2, "comp_if"); if (res) res = (validate_name(CHILD(tree, 0), "if") - && validate_old_test(CHILD(tree, 1))); + && validate_test_nocond(CHILD(tree, 1))); return res; } @@ -2079,13 +2012,13 @@ } static int -validate_old_test(node *tree) +validate_test_nocond(node *tree) { int nch = NCH(tree); - int res = validate_ntype(tree, old_test) && (nch == 1); + int res = validate_ntype(tree, test_nocond) && (nch == 1); - if (res && (TYPE(CHILD(tree, 0)) == old_lambdef)) - res = (validate_old_lambdef(CHILD(tree, 0))); + if (res && (TYPE(CHILD(tree, 0)) == lambdef_nocond)) + res = (validate_lambdef_nocond(CHILD(tree, 0))); else if (res) { res = (validate_or_test(CHILD(tree, 0))); } @@ -2383,14 +2316,14 @@ if (TYPE(CHILD(tree, 1))==yield_expr) res = validate_yield_expr(CHILD(tree, 1)); else - res = validate_testlist_gexp(CHILD(tree, 1)); + res = validate_testlist_comp(CHILD(tree, 1)); } break; case LSQB: if (nch == 2) res = validate_ntype(CHILD(tree, 1), RSQB); else if (nch == 3) - res = (validate_listmaker(CHILD(tree, 1)) + res = (validate_testlist_comp(CHILD(tree, 1)) && validate_ntype(CHILD(tree, 2), RSQB)); else { res = 0; @@ -2402,7 +2335,7 @@ && validate_ntype(CHILD(tree, nch - 1), RBRACE)); if (res && (nch == 3)) - res = validate_dictsetmaker(CHILD(tree, 1)); + res = validate_dictorsetmaker(CHILD(tree, 1)); break; case NAME: case NUMBER: @@ -2421,63 +2354,26 @@ } -/* listmaker: - * test ( list_for | (',' test)* [','] ) +/* testlist_comp: + * test ( comp_for | (',' test)* [','] ) */ static int -validate_listmaker(node *tree) +validate_testlist_comp(node *tree) { int nch = NCH(tree); int ok = nch; if (nch == 0) - err_string("missing child nodes of listmaker"); - else - ok = validate_test(CHILD(tree, 0)); - - /* - * list_for | (',' test)* [','] - */ - if (nch == 2 && TYPE(CHILD(tree, 1)) == list_for) - ok = validate_list_for(CHILD(tree, 1)); + err_string("missing child nodes of testlist_comp"); else { - /* (',' test)* [','] */ - int i = 1; - while (ok && nch - i >= 2) { - ok = (validate_comma(CHILD(tree, i)) - && validate_test(CHILD(tree, i+1))); - i += 2; - } - if (ok && i == nch-1) - ok = validate_comma(CHILD(tree, i)); - else if (i != nch) { - ok = 0; - err_string("illegal trailing nodes for listmaker"); - } - } - return ok; -} - -/* testlist_gexp: - * test ( gen_for | (',' test)* [','] ) - */ -static int -validate_testlist_gexp(node *tree) -{ - int nch = NCH(tree); - int ok = nch; - - if (nch == 0) - err_string("missing child nodes of testlist_gexp"); - else { ok = validate_test(CHILD(tree, 0)); } /* - * gen_for | (',' test)* [','] + * comp_for | (',' test)* [','] */ - if (nch == 2 && TYPE(CHILD(tree, 1)) == gen_for) - ok = validate_gen_for(CHILD(tree, 1)); + if (nch == 2 && TYPE(CHILD(tree, 1)) == comp_for) + ok = validate_comp_for(CHILD(tree, 1)); else { /* (',' test)* [','] */ int i = 1; @@ -2490,7 +2386,7 @@ ok = validate_comma(CHILD(tree, i)); else if (i != nch) { ok = 0; - err_string("illegal trailing nodes for testlist_gexp"); + err_string("illegal trailing nodes for testlist_comp"); } } return ok; @@ -2581,10 +2477,10 @@ static int -validate_old_lambdef(node *tree) +validate_lambdef_nocond(node *tree) { int nch = NCH(tree); - int res = (validate_ntype(tree, old_lambdef) + int res = (validate_ntype(tree, lambdef_nocond) && ((nch == 3) || (nch == 4)) && validate_name(CHILD(tree, 0), "lambda") && validate_colon(CHILD(tree, nch - 2)) @@ -2593,7 +2489,7 @@ if (res && (nch == 4)) res = validate_varargslist(CHILD(tree, 1)); else if (!res && !PyErr_Occurred()) - (void) validate_numnodes(tree, 3, "old_lambdef"); + (void) validate_numnodes(tree, 3, "lambdef_nocond"); return (res); } @@ -2618,7 +2514,7 @@ for (i=0; i= 3) && validate_test(CHILD(tree, 0)) && validate_colon(CHILD(tree, 1))