@@ -1946,35 +1946,36 @@ compiler_call_exit_with_nones(struct compiler *c) {
1946
1946
static int
1947
1947
compiler_add_yield_from (struct compiler * c , int await )
1948
1948
{
1949
- NEW_JUMP_TARGET_LABEL (c , start );
1950
- NEW_JUMP_TARGET_LABEL (c , resume );
1951
- NEW_JUMP_TARGET_LABEL (c , error );
1952
- NEW_JUMP_TARGET_LABEL (c , stopiter );
1949
+ NEW_JUMP_TARGET_LABEL (c , send );
1950
+ NEW_JUMP_TARGET_LABEL (c , fail );
1951
+ NEW_JUMP_TARGET_LABEL (c , stop );
1953
1952
NEW_JUMP_TARGET_LABEL (c , exit );
1954
- USE_LABEL (c , start );
1953
+
1954
+ USE_LABEL (c , send );
1955
1955
ADDOP_JUMP (c , SEND , exit );
1956
- USE_LABEL (c , resume );
1957
- // Set up a virtual try/except to handle StopIteration raised during a
1958
- // close() or throw():
1959
- ADDOP_JUMP (c , SETUP_FINALLY , error );
1960
- RETURN_IF_FALSE (compiler_push_fblock (c , TRY_EXCEPT , resume , NO_LABEL , NULL ));
1961
- // The only way YIELD_VALUE can raise is if close() or throw() raises:
1956
+ // Set up a virtual try/except to handle when StopIteration is raised during
1957
+ // a close or throw call. The only way YIELD_VALUE raises if they do!
1958
+ ADDOP_JUMP (c , SETUP_FINALLY , fail );
1959
+ RETURN_IF_FALSE (compiler_push_fblock (c , TRY_EXCEPT , send , NO_LABEL , NULL ));
1962
1960
ADDOP_I (c , YIELD_VALUE , 0 );
1963
- compiler_pop_fblock (c , TRY_EXCEPT , resume );
1961
+ compiler_pop_fblock (c , TRY_EXCEPT , send );
1964
1962
ADDOP_NOLINE (c , POP_BLOCK );
1965
1963
ADDOP_I (c , RESUME , await ? 3 : 2 );
1966
- ADDOP_JUMP (c , JUMP_NO_INTERRUPT , start );
1967
- USE_LABEL (c , error );
1964
+ ADDOP_JUMP (c , JUMP_NO_INTERRUPT , send );
1965
+
1966
+ USE_LABEL (c , fail );
1968
1967
ADDOP_I (c , LOAD_EXCEPTION_TYPE , 1 ); // StopIteration
1969
1968
ADDOP (c , CHECK_EXC_MATCH );
1970
- ADDOP_JUMP (c , POP_JUMP_IF_TRUE , stopiter );
1969
+ ADDOP_JUMP (c , POP_JUMP_IF_TRUE , stop );
1971
1970
ADDOP_I (c , RERAISE , 0 );
1972
- USE_LABEL (c , stopiter );
1973
- // StopIteration was raised. Push the return value and continue execution:
1971
+
1972
+ USE_LABEL (c , stop );
1973
+ // StopIteration was raised. Push the value and break out of the loop:
1974
1974
ADDOP_NAME (c , LOAD_ATTR , & _Py_ID (value ), names );
1975
1975
ADDOP_I (c , SWAP , 3 );
1976
- ADDOP (c , POP_TOP );
1977
- ADDOP (c , POP_TOP );
1976
+ ADDOP (c , POP_TOP ); // The thing we're yielding from.
1977
+ ADDOP (c , POP_TOP ); // The last sent value
1978
+
1978
1979
USE_LABEL (c , exit );
1979
1980
return 1 ;
1980
1981
}
0 commit comments