From 893a5c83412d75c1da8c429d4809650660c2ee94 Mon Sep 17 00:00:00 2001 From: Damien George Date: Tue, 12 Jul 2022 22:41:10 +1000 Subject: [PATCH] py/vm: In YIELD_FROM opcode, expand helper macros and remove them. The GENERATOR_EXIT_IF_NEEDED macro is only used once and it's easier to read and understand the code if this macro body is written in the code. Then the comment just before it makes more sense. Signed-off-by: Damien George --- py/vm.c | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-) diff --git a/py/vm.c b/py/vm.c index 9157fc7d1e..80e271845f 100644 --- a/py/vm.c +++ b/py/vm.c @@ -1188,9 +1188,6 @@ yield: ENTRY(MP_BC_YIELD_FROM): { MARK_EXC_IP_SELECTIVE(); -//#define EXC_MATCH(exc, type) mp_obj_is_type(exc, type) -#define EXC_MATCH(exc, type) mp_obj_exception_match(exc, type) -#define GENERATOR_EXIT_IF_NEEDED(t) if (t != MP_OBJ_NULL && EXC_MATCH(t, MP_OBJ_FROM_PTR(&mp_type_GeneratorExit))) { mp_obj_t raise_t = mp_make_raise_obj(t); RAISE(raise_t); } mp_vm_return_kind_t ret_kind; mp_obj_t send_value = POP(); mp_obj_t t_exc = MP_OBJ_NULL; @@ -1214,11 +1211,14 @@ yield: 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); + if (t_exc != MP_OBJ_NULL && mp_obj_exception_match(t_exc, MP_OBJ_FROM_PTR(&mp_type_GeneratorExit))) { + mp_obj_t raise_t = mp_make_raise_obj(t_exc); + RAISE(raise_t); + } DISPATCH(); } else { assert(ret_kind == MP_VM_RETURN_EXCEPTION); - assert(!EXC_MATCH(ret_value, MP_OBJ_FROM_PTR(&mp_type_StopIteration))); + assert(!mp_obj_exception_match(ret_value, MP_OBJ_FROM_PTR(&mp_type_StopIteration))); // Pop exhausted gen sp--; RAISE(ret_value);