@@ -693,7 +693,7 @@ opcode_stack_effect(int opcode, int oparg)
693693 return 0 ;
694694
695695 case LIST_APPEND :
696- return -2 ;
696+ return -1 ;
697697
698698 case BINARY_POWER :
699699 case BINARY_MULTIPLY :
@@ -2599,9 +2599,8 @@ compiler_call(struct compiler *c, expr_ty e)
25992599}
26002600
26012601static int
2602- compiler_listcomp_generator (struct compiler * c , PyObject * tmpname ,
2603- asdl_seq * generators , int gen_index ,
2604- expr_ty elt )
2602+ compiler_listcomp_generator (struct compiler * c , asdl_seq * generators ,
2603+ int gen_index , expr_ty elt )
26052604{
26062605 /* generate code for the iterator, then each of the ifs,
26072606 and then write to the element */
@@ -2638,16 +2637,13 @@ compiler_listcomp_generator(struct compiler *c, PyObject *tmpname,
26382637 }
26392638
26402639 if (++ gen_index < asdl_seq_LEN (generators ))
2641- if (!compiler_listcomp_generator (c , tmpname ,
2642- generators , gen_index , elt ))
2640+ if (!compiler_listcomp_generator (c , generators , gen_index , elt ))
26432641 return 0 ;
26442642
26452643 /* only append after the last for generator */
26462644 if (gen_index >= asdl_seq_LEN (generators )) {
2647- if (!compiler_nameop (c , tmpname , Load ))
2648- return 0 ;
26492645 VISIT (c , expr , elt );
2650- ADDOP (c , LIST_APPEND );
2646+ ADDOP_I (c , LIST_APPEND , gen_index + 1 );
26512647
26522648 compiler_use_next_block (c , skip );
26532649 }
@@ -2659,32 +2655,17 @@ compiler_listcomp_generator(struct compiler *c, PyObject *tmpname,
26592655 }
26602656 ADDOP_JABS (c , JUMP_ABSOLUTE , start );
26612657 compiler_use_next_block (c , anchor );
2662- /* delete the temporary list name added to locals */
2663- if (gen_index == 1 )
2664- if (!compiler_nameop (c , tmpname , Del ))
2665- return 0 ;
26662658
26672659 return 1 ;
26682660}
26692661
26702662static int
26712663compiler_listcomp (struct compiler * c , expr_ty e )
26722664{
2673- identifier tmp ;
2674- int rc = 0 ;
2675- asdl_seq * generators = e -> v .ListComp .generators ;
2676-
26772665 assert (e -> kind == ListComp_kind );
2678- tmp = compiler_new_tmpname (c );
2679- if (!tmp )
2680- return 0 ;
26812666 ADDOP_I (c , BUILD_LIST , 0 );
2682- ADDOP (c , DUP_TOP );
2683- if (compiler_nameop (c , tmp , Store ))
2684- rc = compiler_listcomp_generator (c , tmp , generators , 0 ,
2685- e -> v .ListComp .elt );
2686- Py_DECREF (tmp );
2687- return rc ;
2667+ return compiler_listcomp_generator (c , e -> v .ListComp .generators , 0 ,
2668+ e -> v .ListComp .elt );
26882669}
26892670
26902671static int
0 commit comments