py/vm: Simplify handling of MP_OBJ_STOP_ITERATION in yield-from opcode.

Signed-off-by: Damien George <damien@micropython.org>
This commit is contained in:
Damien George
2021-06-29 22:39:24 +10:00
parent 22fdb21302
commit b8255dd2e0
3 changed files with 10 additions and 15 deletions

13
py/vm.c
View File

@@ -1257,16 +1257,9 @@ yield:
PUSH(ret_value);
goto yield;
} else if (ret_kind == MP_VM_RETURN_NORMAL) {
// Pop exhausted gen
sp--;
if (ret_value == MP_OBJ_STOP_ITERATION) {
// Optimize StopIteration
// TODO: get StopIteration's value
PUSH(mp_const_none);
} else {
PUSH(ret_value);
}
// The generator has finished, and returned a value via StopIteration
// Replace exhausted generator with the returned value
SET_TOP(ret_value);
// If we injected GeneratorExit downstream, then even
// if it was swallowed, we re-raise GeneratorExit
GENERATOR_EXIT_IF_NEEDED(t_exc);