STATIC mp_obj_t gen_instance_send(mp_obj_t self_in, mp_obj_t send_value) { mp_obj_t ret = gen_resume_and_raise(self_in, send_value, MP_OBJ_NULL); if (ret == MP_OBJ_STOP_ITERATION) { nlr_raise(mp_obj_new_exception(&mp_type_StopIteration)); } else { return ret; } }
STATIC mp_obj_t gen_instance_throw(size_t n_args, const mp_obj_t *args) { mp_obj_t exc = (n_args == 2) ? args[1] : args[2]; mp_obj_t ret = gen_resume_and_raise(args[0], mp_const_none, exc); if (ret == MP_OBJ_STOP_ITERATION) { nlr_raise(mp_obj_new_exception(&mp_type_StopIteration)); } else { return ret; } }
STATIC mp_obj_t gen_instance_throw(uint n_args, const mp_obj_t *args) { mp_obj_t exc = (n_args == 2) ? args[1] : args[2]; exc = mp_make_raise_obj(exc); if (mp_obj_is_subclass_fast(mp_obj_get_type(exc), &mp_type_GeneratorExit)) { // Throwing GeneratorExit is equivalent of calling close aka // GeneratorExit should be handled specially // TODO: Calling .close() will throw new exception instance, not one // given to throw, which is not ok. return gen_instance_close(args[0]); } mp_obj_t ret = gen_resume_and_raise(args[0], mp_const_none, exc); if (ret == MP_OBJ_NULL) { nlr_jump(mp_obj_new_exception(&mp_type_StopIteration)); } else { return ret; } }
mp_obj_t gen_instance_iternext(mp_obj_t self_in) { return gen_resume_and_raise(self_in, mp_const_none, MP_OBJ_NULL); }