|
40 | 40 |
|
41 | 41 | #if MICROPY_ENABLE_COMPILER |
42 | 42 |
|
| 43 | +#define DEBUG_PRINT(...) mp_printf(&mp_plat_print __VA_OPT__(,) __VA_ARGS__) |
| 44 | + |
43 | 45 | // TODO need to mangle __attr names |
44 | 46 |
|
45 | 47 | #define INVALID_LABEL (0xffff) |
@@ -853,7 +855,7 @@ STATIC void compile_decorated(compiler_t *comp, mp_parse_node_struct_t *pns) { |
853 | 855 | mp_parse_node_struct_t *pns0 = (mp_parse_node_struct_t*)pns_body->nodes[0]; |
854 | 856 | body_name = compile_funcdef_helper(comp, pns0, emit_options); |
855 | 857 | scope_t *fscope = (scope_t*)pns0->nodes[4]; |
856 | | - fscope->scope_flags |= MP_SCOPE_FLAG_GENERATOR; |
| 858 | + fscope->scope_flags |= MP_SCOPE_FLAG_GENERATOR | MP_SCOPE_FLAG_ASYNC; |
857 | 859 | #endif |
858 | 860 | } else { |
859 | 861 | assert(MP_PARSE_NODE_STRUCT_KIND(pns_body) == PN_classdef); // should be |
@@ -2655,11 +2657,13 @@ STATIC void compile_atom_expr_await(compiler_t *comp, mp_parse_node_struct_t *pn |
2655 | 2657 | compile_require_async_context(comp, pns); |
2656 | 2658 | compile_atom_expr_normal(comp, pns); |
2657 | 2659 |
|
2658 | | - |
| 2660 | + // If it's an awaitable thing, need to reach for the __await__ method for the coroutine. |
| 2661 | + // async def functions' __await__ return themselves, which are able to receive a send(), |
| 2662 | + // while other types with custom __await__ implementations return async generators. |
2659 | 2663 | EMIT_ARG(load_method, MP_QSTR___await__, false); |
2660 | 2664 | EMIT_ARG(call_method, 0, 0, 0); |
2661 | | - // EMIT_ARG(load_const_tok, MP_TOKEN_KW_NONE); // don't yield anything from an awaitable; only return the final result. |
2662 | | - // EMIT_ARG(yield, MP_EMIT_YIELD_FROM); |
| 2665 | + EMIT_ARG(load_const_tok, MP_TOKEN_KW_NONE); |
| 2666 | + EMIT_ARG(yield, MP_EMIT_YIELD_FROM); |
2663 | 2667 | } |
2664 | 2668 | #endif |
2665 | 2669 |
|
|
0 commit comments