bpo-43683: Streamline YIELD_VALUE and SEND (GH-30723)

* Split YIELD_VALUE into ASYNC_GEN_WRAP; YIELD_VALUE for async generators.

* Split SEND into SEND; YIELD_VALUE.

* Document new opcodes.
This commit is contained in:
Mark Shannon 2022-01-24 11:08:53 +00:00 committed by GitHub
parent d75a51bea3
commit 0367a36fdc
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
9 changed files with 72 additions and 43 deletions

View file

@ -2650,32 +2650,25 @@ handle_eval_breaker:
}
assert (gen_status == PYGEN_NEXT);
assert (retval != NULL);
frame->f_state = FRAME_SUSPENDED;
_PyFrame_SetStackPointer(frame, stack_pointer);
TRACE_FUNCTION_EXIT();
DTRACE_FUNCTION_EXIT();
_Py_LeaveRecursiveCall(tstate);
/* Restore previous cframe and return. */
tstate->cframe = cframe.previous;
tstate->cframe->use_tracing = cframe.use_tracing;
assert(tstate->cframe->current_frame == frame->previous);
assert(!_PyErr_Occurred(tstate));
return retval;
PUSH(retval);
DISPATCH();
}
TARGET(ASYNC_GEN_WRAP) {
PyObject *v = TOP();
assert(frame->f_code->co_flags & CO_ASYNC_GENERATOR);
PyObject *w = _PyAsyncGenValueWrapperNew(v);
if (w == NULL) {
goto error;
}
SET_TOP(w);
Py_DECREF(v);
DISPATCH();
}
TARGET(YIELD_VALUE) {
assert(frame->is_entry);
PyObject *retval = POP();
if (frame->f_code->co_flags & CO_ASYNC_GENERATOR) {
PyObject *w = _PyAsyncGenValueWrapperNew(retval);
Py_DECREF(retval);
if (w == NULL) {
retval = NULL;
goto error;
}
retval = w;
}
frame->f_state = FRAME_SUSPENDED;
_PyFrame_SetStackPointer(frame, stack_pointer);
TRACE_FUNCTION_EXIT();