@@ -646,9 +646,8 @@ def need_cleanup(self) -> bool:
646646 return True
647647
648648 def init (self , expr_reg : Value , target_type : RType ) -> None :
649- # Define targets to contain the expression, along with the iterator that will be used
650- # for the for-loop. If we are inside of a generator function, spill these into the
651- # environment class.
649+ # Define target to contains the generator expression. It's also the iterator.
650+ # If we are inside a generator function, spill these into the environment class.
652651 builder = self .builder
653652 self .iter_target = builder .maybe_spill (expr_reg )
654653 self .target_type = target_type
@@ -661,8 +660,10 @@ def gen_condition(self) -> None:
661660 builder .assign (self .return_value , err , line )
662661
663662 # Call generated generator helper method, passing a PyObject ** as the final
664- # argument that will be used to store the return value in this register. This
665- # is faster than raising StopIteration.
663+ # argument that will be used to store the return value in the return value
664+ # register. We ignore the return value but the presence of a return value
665+ # indicates that the generator has finished. This is faster than raising
666+ # and catching StopIteration, which is the non-native way of doing this.
666667 ptr = builder .add (LoadAddress (object_pointer_rprimitive , self .return_value ))
667668 nn = builder .none_object ()
668669 helper_call = MethodCall (
@@ -675,7 +676,7 @@ def gen_condition(self) -> None:
675676 builder .add (Branch (self .next_reg , self .loop_exit , self .body_block , Branch .IS_ERROR ))
676677
677678 def begin_body (self ) -> None :
678- # Assign the value obtained from __next__ to the
679+ # Assign the value obtained from the generator helper method to the
679680 # lvalue so that it can be referenced by code in the body of the loop.
680681 builder = self .builder
681682 line = self .line
@@ -690,7 +691,7 @@ def gen_step(self) -> None:
690691
691692 def gen_cleanup (self ) -> None :
692693 # If return value is NULL (it wasn't assigned to by the generator helper method),
693- # an exception was raised.
694+ # an exception was raised that we need to propagate .
694695 self .builder .primitive_op (propagate_if_error_op , [self .return_value ], self .line )
695696
696697
0 commit comments