py: Add basic support for await expressions. · micropython/micropython@81afa7e (original) (raw)
`@@ -1272,7 +1272,8 @@ STATIC void compile_decorated(compiler_t *comp, mp_parse_node_struct_t *pns) {
`
1272
1272
`if (MP_PARSE_NODE_STRUCT_KIND(pns_body) == PN_funcdef) {
`
1273
1273
`body_name = compile_funcdef_helper(comp, pns_body, emit_options);
`
1274
1274
` } else if (MP_PARSE_NODE_STRUCT_KIND(pns_body) == PN_async_funcdef) {
`
1275
``
`-
// TODO implement async def here
`
``
1275
`+
// decorated async def
`
``
1276
`+
// TODO implement me
`
1276
1277
`assert(0);
`
1277
1278
` } else {
`
1278
1279
`assert(MP_PARSE_NODE_STRUCT_KIND(pns_body) == PN_classdef); // should be
`
`@@ -1295,8 +1296,23 @@ STATIC void compile_funcdef(compiler_t *comp, mp_parse_node_struct_t *pns) {
`
1295
1296
`}
`
1296
1297
``
1297
1298
`STATIC void compile_async_stmt(compiler_t *comp, mp_parse_node_struct_t *pns) {
`
1298
``
`-
// TODO compile async stmt here (can be def, with or for)
`
1299
``
`-
compile_node(comp, pns->nodes[0]);
`
``
1299
`+
assert(MP_PARSE_NODE_IS_STRUCT(pns->nodes[0]));
`
``
1300
`+
mp_parse_node_struct_t pns0 = (mp_parse_node_struct_t)pns->nodes[0];
`
``
1301
`+
if (MP_PARSE_NODE_STRUCT_KIND(pns0) == PN_funcdef) {
`
``
1302
`+
// async def
`
``
1303
`+
compile_funcdef(comp, pns0);
`
``
1304
`+
scope_t fscope = (scope_t)pns0->nodes[4];
`
``
1305
`+
fscope->scope_flags |= MP_SCOPE_FLAG_GENERATOR | MP_SCOPE_FLAG_COROUTINE;
`
``
1306
`+
} else if (MP_PARSE_NODE_STRUCT_KIND(pns0) == PN_for_stmt) {
`
``
1307
`+
// async for
`
``
1308
`+
// TODO implement me
`
``
1309
`+
compile_node(comp, pns->nodes[0]);
`
``
1310
`+
} else {
`
``
1311
`+
// async with
`
``
1312
`+
// TODO implement me
`
``
1313
`+
assert(MP_PARSE_NODE_STRUCT_KIND(pns0) == PN_with_stmt);
`
``
1314
`+
compile_node(comp, pns->nodes[0]);
`
``
1315
`+
}
`
1300
1316
`}
`
1301
1317
``
1302
1318
`STATIC void c_del_stmt(compiler_t *comp, mp_parse_node_t pn) {
`
`@@ -2941,8 +2957,14 @@ STATIC void compile_yield_expr(compiler_t *comp, mp_parse_node_struct_t *pns) {
`
2941
2957
`}
`
2942
2958
``
2943
2959
`STATIC void compile_await_expr(compiler_t *comp, mp_parse_node_struct_t *pns) {
`
2944
``
`-
// TODO implement await call here
`
2945
2960
`compile_node(comp, pns->nodes[0]);
`
``
2961
`+
// TODO We only support await on an object with await special
`
``
2962
`+
// method. Need to support objects that are coroutines.
`
``
2963
`+
EMIT_ARG(load_method, MP_QSTR___await__);
`
``
2964
`+
EMIT_ARG(call_method, 0, 0, 0);
`
``
2965
`+
EMIT(get_iter);
`
``
2966
`+
EMIT_ARG(load_const_tok, MP_TOKEN_KW_NONE);
`
``
2967
`+
EMIT(yield_from);
`
2946
2968
`}
`
2947
2969
``
2948
2970
`STATIC void compile_await_stmt(compiler_t *comp, mp_parse_node_struct_t *pns) {
`