Skip to content

Commit b65d9e7

Browse files
committed
restore async scope flag to previous bit position
1 parent f40c2cb commit b65d9e7

File tree

3 files changed

+21
-9
lines changed

3 files changed

+21
-9
lines changed

py/dynruntime.h

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -222,13 +222,15 @@ static inline void *mp_obj_malloc_helper_dyn(size_t num_bytes, const mp_obj_type
222222
#define mp_arg_parse_all_kw_array(n_pos, n_kw, args, n_allowed, allowed, out_vals) \
223223
(mp_fun_table.arg_parse_all_kw_array((n_pos), (n_kw), (args), (n_allowed), (allowed), (out_vals)))
224224

225+
// CIRCUITPY-CHANGE: .is_async
225226
#define MP_DYNRUNTIME_INIT_ENTRY \
226227
mp_obj_t old_globals = mp_fun_table.swap_globals(self->context->module.globals); \
227228
mp_raw_code_truncated_t rc; \
228229
rc.proto_fun_indicator[0] = MP_PROTO_FUN_INDICATOR_RAW_CODE_0; \
229230
rc.proto_fun_indicator[1] = MP_PROTO_FUN_INDICATOR_RAW_CODE_1; \
230231
rc.kind = MP_CODE_NATIVE_VIPER; \
231232
rc.is_generator = 0; \
233+
rc.is_async = 0; \
232234
(void)rc;
233235

234236
#define MP_DYNRUNTIME_INIT_EXIT \

py/emitglue.c

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -192,6 +192,14 @@ mp_obj_t mp_make_function_from_proto_fun(mp_proto_fun_t proto_fun, const mp_modu
192192
const uint8_t *bc = proto_fun;
193193
mp_obj_t fun = mp_obj_new_fun_bc(def_args, bc, context, NULL);
194194
MP_BC_PRELUDE_SIG_DECODE(bc);
195+
// CIRCUITPY-CHANGE: distinguish generators and async
196+
// A coroutine is MP_SCOPE_FLAG_ASYNC | MP_SCOPE_FLAG_GENERATOR,
197+
// so check for ASYNC first.
198+
#if MICROPY_PY_ASYNC_AWAIT
199+
if (scope_flags & MP_SCOPE_FLAG_ASYNC) {
200+
((mp_obj_base_t *)MP_OBJ_TO_PTR(fun))->type = &mp_type_coro_wrap;
201+
} else
202+
#endif
195203
if (scope_flags & MP_SCOPE_FLAG_GENERATOR) {
196204
((mp_obj_base_t *)MP_OBJ_TO_PTR(fun))->type = &mp_type_gen_wrap;
197205
}
@@ -234,7 +242,7 @@ mp_obj_t mp_make_function_from_proto_fun(mp_proto_fun_t proto_fun, const mp_modu
234242
fun = mp_obj_new_fun_bc(def_args, rc->fun_data, context, rc->children);
235243
// check for generator functions and if so change the type of the object
236244
// CIRCUITPY-CHANGE: distinguish generators and async
237-
// A generator is MP_SCOPE_FLAG_ASYNC | MP_SCOPE_FLAG_GENERATOR,
245+
// A coroutine is MP_SCOPE_FLAG_ASYNC | MP_SCOPE_FLAG_GENERATOR,
238246
// so check for ASYNC first.
239247
#if MICROPY_PY_ASYNC_AWAIT
240248
if ((rc->is_async) != 0) {

py/runtime0.h

Lines changed: 10 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -28,22 +28,24 @@
2828

2929
// These constants are used by:
3030
// - mp_raw_code_t::is_generator (only MP_SCOPE_FLAG_GENERATOR)
31+
// CIRCUITPY-CHANGE: distinguish generator and async
32+
// - mp_raw_code_t::is_generator (only MP_SCOPE_FLAG_ASYNC)
3133
// - scope_t::scope_flags (16 bits)
3234
// - MP_BC_PRELUDE_SIG_ENCODE macro, masked by MP_SCOPE_FLAG_ALL_SIG (4 bits)
3335
// - tools/mpy_ld.py, when generating mpy files (maximum 7 bits)
34-
#define MP_SCOPE_FLAG_ALL_SIG (0x0f)
36+
#define MP_SCOPE_FLAG_ALL_SIG (0x1f)
3537
#define MP_SCOPE_FLAG_GENERATOR (0x01)
3638
#define MP_SCOPE_FLAG_VARKEYWORDS (0x02)
3739
#define MP_SCOPE_FLAG_VARARGS (0x04)
3840
#define MP_SCOPE_FLAG_DEFKWARGS (0x08)
39-
#define MP_SCOPE_FLAG_REFGLOBALS (0x10) // used only if native emitter enabled
40-
#define MP_SCOPE_FLAG_HASCONSTS (0x20) // used only if native emitter enabled
41-
#define MP_SCOPE_FLAG_VIPERRET_POS (6) // 3 bits used for viper return type, to pass from compiler to native emitter
42-
#define MP_SCOPE_FLAG_VIPERRELOC (0x10) // used only when loading viper from .mpy
43-
#define MP_SCOPE_FLAG_VIPERRODATA (0x20) // used only when loading viper from .mpy
44-
#define MP_SCOPE_FLAG_VIPERBSS (0x40) // used only when loading viper from .mpy
4541
// CIRCUITPY-CHANGE: FLAG_ASYNC
46-
#define MP_SCOPE_FLAG_ASYNC (0x80)
42+
#define MP_SCOPE_FLAG_ASYNC (0x10)
43+
#define MP_SCOPE_FLAG_REFGLOBALS (0x20) // used only if native emitter enabled
44+
#define MP_SCOPE_FLAG_HASCONSTS (0x40) // used only if native emitter enabled
45+
#define MP_SCOPE_FLAG_VIPERRET_POS (7) // 3 bits used for viper return type, to pass from compiler to native emitter
46+
#define MP_SCOPE_FLAG_VIPERRELOC (0x20) // used only when loading viper from .mpy
47+
#define MP_SCOPE_FLAG_VIPERRODATA (0x40) // used only when loading viper from .mpy
48+
#define MP_SCOPE_FLAG_VIPERBSS (0x80) // used only when loading viper from .mpy
4749

4850
// types for native (viper) function signature
4951
#define MP_NATIVE_TYPE_OBJ (0x00)

0 commit comments

Comments
 (0)