@@ -98,6 +98,7 @@ const mp_obj_type_t mp_type_gen_wrap = {
9898 ),
9999};
100100
101+ #if MICROPY_PY_ASYNC_AWAIT
101102const mp_obj_type_t mp_type_coro_wrap = {
102103 { & mp_type_type },
103104 .flags = MP_TYPE_FLAG_BINDS_SELF | MP_TYPE_FLAG_EXTENDED ,
@@ -110,6 +111,7 @@ const mp_obj_type_t mp_type_coro_wrap = {
110111 .unary_op = mp_generic_unary_op ,
111112 ),
112113};
114+ #endif
113115
114116/******************************************************************************/
115117// native generator wrapper
@@ -141,7 +143,13 @@ STATIC mp_obj_t native_gen_wrap_call(mp_obj_t self_in, size_t n_args, size_t n_k
141143 MP_BC_PRELUDE_SIG_DECODE (ip );
142144
143145 // Allocate the generator object, with room for local stack (exception stack not needed).
144- mp_obj_gen_instance_native_t * o = mp_obj_malloc_var (mp_obj_gen_instance_native_t , byte , n_state * sizeof (mp_obj_t ), & mp_type_gen_instance );
146+ mp_obj_gen_instance_native_t * o = mp_obj_malloc_var (mp_obj_gen_instance_native_t , byte , n_state * sizeof (mp_obj_t ),
147+ #if MICROPY_PY_ASYNC_AWAIT
148+ (self_fun -> base .type == & mp_type_native_gen_wrap ) ? & mp_type_gen_instance : & mp_type_coro_instance
149+ #else
150+ & mp_type_gen_instance
151+ #endif
152+ );
145153
146154 // Parse the input arguments and set up the code state
147155 o -> pend_exc = mp_const_none ;
@@ -177,6 +185,21 @@ const mp_obj_type_t mp_type_native_gen_wrap = {
177185 ),
178186};
179187
188+ #if MICROPY_PY_ASYNC_AWAIT
189+ const mp_obj_type_t mp_type_native_coro_wrap = {
190+ { & mp_type_type },
191+ .flags = MP_TYPE_FLAG_BINDS_SELF | MP_TYPE_FLAG_EXTENDED ,
192+ .name = MP_QSTR_coroutine ,
193+ #if MICROPY_PY_FUNCTION_ATTRS
194+ .attr = mp_obj_fun_bc_attr ,
195+ #endif
196+ MP_TYPE_EXTENDED_FIELDS (
197+ .call = native_gen_wrap_call ,
198+ .unary_op = mp_generic_unary_op ,
199+ ),
200+ };
201+ #endif
202+
180203#endif // MICROPY_EMIT_NATIVE
181204
182205/******************************************************************************/
0 commit comments