Fix building with !MICROPY_PY_ASYNC_AWAIT

This commit is contained in:
Jeff Epler 2023-08-19 17:17:50 -05:00
parent 5606d49e4d
commit b0bf36ef3b
No known key found for this signature in database
GPG Key ID: D5BF15AB975AB4DE
3 changed files with 18 additions and 4 deletions

View File

@ -741,7 +741,9 @@ extern const mp_obj_type_t mp_type_gen_instance;
// CIRCUITPY
extern const mp_obj_type_t mp_type_coro_wrap;
// CIRCUITPY
#if MICROPY_PY_ASYNC_AWAIT
extern const mp_obj_type_t mp_type_coro_instance;
#endif
extern const mp_obj_type_t mp_type_fun_builtin_0;
extern const mp_obj_type_t mp_type_fun_builtin_1;
extern const mp_obj_type_t mp_type_fun_builtin_2;

View File

@ -71,7 +71,12 @@ STATIC mp_obj_t gen_wrap_call(mp_obj_t self_in, size_t n_args, size_t n_kw, cons
// allocate the generator or coroutine object, with room for local stack and exception stack
mp_obj_gen_instance_t *o = mp_obj_malloc_var(mp_obj_gen_instance_t, byte,
n_state * sizeof(mp_obj_t) + n_exc_stack * sizeof(mp_exc_stack_t),
self_fun->base.type == &mp_type_gen_wrap ? &mp_type_gen_instance : &mp_type_coro_instance);
#if MICROPY_PY_ASYNC_AWAIT
self_fun->base.type == &mp_type_gen_wrap ? &mp_type_gen_instance : &mp_type_coro_instance
#else
&mp_type_gen_instance
#endif
);
o->pend_exc = mp_const_none;
o->code_state.fun_bc = self_fun;
@ -198,8 +203,11 @@ mp_vm_return_kind_t mp_obj_gen_resume(mp_obj_t self_in, mp_obj_t send_value, mp_
// note that self may have as its type either gen or coro,
// both of which are stored as an mp_obj_gen_instance_t .
mp_check_self(
mp_obj_is_type(self_in, &mp_type_gen_instance) ||
mp_obj_is_type(self_in, &mp_type_coro_instance));
mp_obj_is_type(self_in, &mp_type_gen_instance)
#if MICROPY_PY_ASYNC_AWAIT
|| mp_obj_is_type(self_in, &mp_type_coro_instance)
#endif
);
mp_obj_gen_instance_t *self = MP_OBJ_TO_PTR(self_in);
if (self->code_state.ip == 0) {
// Trying to resume an already stopped generator.

View File

@ -1416,7 +1416,11 @@ mp_vm_return_kind_t mp_resume(mp_obj_t self_in, mp_obj_t send_value, mp_obj_t th
const mp_obj_type_t *type = mp_obj_get_type(self_in);
// CIRCUITPY distinguishes generators and coroutines.
if (type == &mp_type_gen_instance || type == &mp_type_coro_instance) {
if (type == &mp_type_gen_instance
#if MICROPY_PY_ASYNC_AWAIT
|| type == &mp_type_coro_instance
#endif
) {
return mp_obj_gen_resume(self_in, send_value, throw_value, ret_val);
}