39 #if MICROPY_ENABLE_COMPILER 43 #define INVALID_LABEL (0xffff) 47 #define DEF_RULE(rule, comp, kind, ...) PN_##rule, 48 #define DEF_RULE_NC(rule, kind, ...) 54 #define DEF_RULE(rule, comp, kind, ...) 55 #define DEF_RULE_NC(rule, kind, ...) PN_##rule, 61 #define NEED_METHOD_TABLE MICROPY_EMIT_NATIVE 66 #define EMIT(fun) (comp->emit_method_table->fun(comp->emit)) 67 #define EMIT_ARG(fun, ...) (comp->emit_method_table->fun(comp->emit, __VA_ARGS__)) 68 #define EMIT_LOAD_FAST(qst, local_num) (comp->emit_method_table->load_id.fast(comp->emit, qst, local_num)) 69 #define EMIT_LOAD_GLOBAL(qst) (comp->emit_method_table->load_id.global(comp->emit, qst)) 74 #define EMIT(fun) (mp_emit_bc_##fun(comp->emit)) 75 #define EMIT_ARG(fun, ...) (mp_emit_bc_##fun(comp->emit, __VA_ARGS__)) 76 #define EMIT_LOAD_FAST(qst, local_num) (mp_emit_bc_load_fast(comp->emit, qst, local_num)) 77 #define EMIT_LOAD_GLOBAL(qst) (mp_emit_bc_load_global(comp->emit, qst)) 81 #if MICROPY_EMIT_NATIVE 84 #define NATIVE_EMITTER(f) emit_native_x64_##f 85 #elif MICROPY_EMIT_X86 86 #define NATIVE_EMITTER(f) emit_native_x86_##f 87 #elif MICROPY_EMIT_THUMB 88 #define NATIVE_EMITTER(f) emit_native_thumb_##f 89 #elif MICROPY_EMIT_ARM 90 #define NATIVE_EMITTER(f) emit_native_arm_##f 91 #elif MICROPY_EMIT_XTENSA 92 #define NATIVE_EMITTER(f) emit_native_xtensa_##f 94 #error "unknown native emitter" 98 #if MICROPY_EMIT_INLINE_ASM 100 #if MICROPY_EMIT_INLINE_THUMB 101 #define ASM_DECORATOR_QSTR MP_QSTR_asm_thumb 102 #define ASM_EMITTER(f) emit_inline_thumb_##f 103 #elif MICROPY_EMIT_INLINE_XTENSA 104 #define ASM_DECORATOR_QSTR MP_QSTR_asm_xtensa 105 #define ASM_EMITTER(f) emit_inline_xtensa_##f 107 #error "unknown asm emitter" 111 #define EMIT_INLINE_ASM(fun) (comp->emit_inline_asm_method_table->fun(comp->emit_inline_asm)) 112 #define EMIT_INLINE_ASM_ARG(fun, ...) (comp->emit_inline_asm_method_table->fun(comp->emit_inline_asm, __VA_ARGS__)) 115 typedef struct _compiler_t {
124 size_t compile_error_line;
134 uint16_t break_continue_except_level;
140 #if NEED_METHOD_TABLE 144 #if MICROPY_EMIT_INLINE_ASM 161 compile_error_set_line(comp, pn);
165 STATIC void compile_trailer_paren_helper(compiler_t *comp,
mp_parse_node_t pn_arglist,
bool is_method_call,
int n_positional_extra);
169 STATIC uint comp_next_label(compiler_t *comp) {
170 return comp->next_label++;
173 STATIC void compile_increase_except_level(compiler_t *comp) {
174 comp->cur_except_level += 1;
175 if (comp->cur_except_level > comp->scope_cur->exc_stack_size) {
176 comp->scope_cur->exc_stack_size = comp->cur_except_level;
180 STATIC void compile_decrease_except_level(compiler_t *comp) {
181 assert(comp->cur_except_level > 0);
182 comp->cur_except_level -= 1;
187 scope->
parent = comp->scope_cur;
189 if (comp->scope_head ==
NULL) {
190 comp->scope_head = scope;
201 typedef void (*apply_list_fun_t)(compiler_t *comp,
mp_parse_node_t pn);
203 STATIC void apply_to_single_or_list(compiler_t *comp,
mp_parse_node_t pn, pn_kind_t pn_list_kind, apply_list_fun_t f) {
207 for (
int i = 0; i < num_nodes; i++) {
208 f(comp, pns->
nodes[i]);
217 for (
int i = 0; i < num_nodes; i++) {
218 compile_node(comp, pns->
nodes[i]);
221 compile_error_set_line(comp, pns->
nodes[i]);
227 STATIC void compile_load_id(compiler_t *comp,
qstr qst) {
231 #if NEED_METHOD_TABLE 239 STATIC void compile_store_id(compiler_t *comp,
qstr qst) {
243 #if NEED_METHOD_TABLE 251 STATIC void compile_delete_id(compiler_t *comp,
qstr qst) {
255 #if NEED_METHOD_TABLE 266 compile_node(comp, pn);
269 if (pns_list !=
NULL) {
271 for (
int i = 0; i < n; i++) {
272 compile_node(comp, pns_list->
nodes[i]);
276 EMIT_ARG(build_tuple, total);
286 if (jump_if ==
false) {
287 EMIT_ARG(jump, label);
291 if (jump_if ==
true) {
292 EMIT_ARG(jump, label);
299 if (jump_if ==
false) {
301 uint label2 = comp_next_label(comp);
302 for (
int i = 0; i < n - 1; i++) {
303 c_if_cond(comp, pns->
nodes[i], !jump_if, label2);
305 c_if_cond(comp, pns->
nodes[n - 1], jump_if, label);
306 EMIT_ARG(label_assign, label2);
309 for (
int i = 0; i < n; i++) {
310 c_if_cond(comp, pns->
nodes[i], jump_if, label);
315 if (jump_if ==
false) {
321 c_if_cond(comp, pns->
nodes[0], !jump_if, label);
327 if (jump_if ==
false) {
328 EMIT_ARG(jump, label);
333 if (jump_if ==
true) {
334 EMIT_ARG(jump, label);
342 compile_node(comp, pn);
343 EMIT_ARG(pop_jump_if, jump_if, label);
346 typedef enum { ASSIGN_STORE, ASSIGN_AUG_LOAD, ASSIGN_AUG_STORE } assign_kind_t;
350 if (assign_kind != ASSIGN_AUG_STORE) {
351 compile_node(comp, pns->
nodes[0]);
358 if (assign_kind != ASSIGN_AUG_STORE) {
359 for (
int i = 0; i < n - 1; i++) {
360 compile_node(comp, pns1->
nodes[i]);
367 if (assign_kind == ASSIGN_AUG_STORE) {
371 compile_node(comp, pns1->
nodes[0]);
372 if (assign_kind == ASSIGN_AUG_LOAD) {
381 if (assign_kind == ASSIGN_AUG_LOAD) {
385 if (assign_kind == ASSIGN_AUG_STORE) {
400 compile_syntax_error(comp, (
mp_parse_node_t)pns,
"can't assign to expression");
408 uint have_star_index = -1;
410 EMIT_ARG(unpack_ex, 0, num_tail);
413 for (
uint i = 0; i < num_tail; i++) {
415 if (have_star_index == (
uint)-1) {
416 EMIT_ARG(unpack_ex, num_head + i, num_tail - i - 1);
417 have_star_index = num_head + i;
419 compile_syntax_error(comp, nodes_tail[i],
"multiple *x in assignment");
424 if (have_star_index == (
uint)-1) {
425 EMIT_ARG(unpack_sequence, num_head + num_tail);
428 if (0 == have_star_index) {
431 c_assign(comp, node_head, ASSIGN_STORE);
434 for (
uint i = 0; i < num_tail; i++) {
435 if (num_head + i == have_star_index) {
438 c_assign(comp, nodes_tail[i], ASSIGN_STORE);
449 switch (assign_kind) {
451 case ASSIGN_AUG_STORE:
452 compile_store_id(comp, arg);
454 case ASSIGN_AUG_LOAD:
456 compile_load_id(comp, arg);
466 case PN_atom_expr_normal:
468 c_assign_atom_expr(comp, pns, assign_kind);
471 case PN_testlist_star_expr:
474 if (assign_kind != ASSIGN_STORE) {
487 if (assign_kind != ASSIGN_STORE) {
495 case PN_atom_bracket:
497 if (assign_kind != ASSIGN_STORE) {
508 c_assign_tuple(comp, pns->
nodes[0], 0,
NULL);
524 c_assign_tuple(comp, pns->
nodes[0], 0,
NULL);
528 c_assign_tuple(comp, pns->
nodes[0], n, pns2->
nodes);
533 goto sequence_with_2_items;
537 sequence_with_2_items:
545 compile_syntax_error(comp, pn,
"can't assign to expression");
552 STATIC void close_over_variables_etc(compiler_t *comp,
scope_t *this_scope,
int n_pos_defaults,
int n_kw_defaults) {
553 assert(n_pos_defaults >= 0);
554 assert(n_kw_defaults >= 0);
557 if (n_kw_defaults > 0) {
566 for (
int i = 0; i < comp->scope_cur->id_info_len; i++) {
567 id_info_t *
id = &comp->scope_cur->id_info[i];
569 for (
int j = 0; j < this_scope->
id_info_len; j++) {
583 EMIT_ARG(make_function, this_scope, n_pos_defaults, n_kw_defaults);
585 EMIT_ARG(make_closure, this_scope, nfree, n_pos_defaults, n_kw_defaults);
599 if (pn_kind == PN_typedargslist_star || pn_kind == PN_varargslist_star) {
600 comp->have_star =
true;
610 }
else if (pn_kind == PN_typedargslist_dbl_star || pn_kind == PN_varargslist_dbl_star) {
623 }
else if (pn_kind == PN_typedargslist_name) {
627 pn_id = pns->
nodes[0];
629 pn_equal = pns->
nodes[2];
632 assert(pn_kind == PN_varargslist_name);
636 pn_id = pns->
nodes[0];
637 pn_equal = pns->
nodes[1];
644 if (!comp->have_star && comp->num_default_params != 0) {
645 compile_syntax_error(comp, pn,
"non-default argument follows default argument");
653 if (comp->have_star) {
654 comp->num_dict_params += 1;
656 if (comp->num_dict_params == 1) {
659 if (comp->num_default_params > 0) {
660 EMIT_ARG(build_tuple, comp->num_default_params);
665 EMIT_ARG(build_map, 0);
669 compile_node(comp, pn_equal);
673 comp->num_default_params += 1;
674 compile_node(comp, pn_equal);
684 bool orig_have_star = comp->have_star;
685 uint16_t orig_num_dict_params = comp->num_dict_params;
686 uint16_t orig_num_default_params = comp->num_default_params;
689 comp->have_star =
false;
690 comp->num_dict_params = 0;
691 comp->num_default_params = 0;
692 apply_to_single_or_list(comp, pn_params, pn_list_kind, compile_funcdef_lambdef_param);
700 if (comp->num_default_params > 0 && comp->num_dict_params == 0) {
701 EMIT_ARG(build_tuple, comp->num_default_params);
706 close_over_variables_etc(comp, scope, comp->num_default_params, comp->num_dict_params);
709 comp->have_star = orig_have_star;
710 comp->num_dict_params = orig_num_dict_params;
711 comp->num_default_params = orig_num_default_params;
728 compile_funcdef_lambdef(comp, fscope, pns->
nodes[1], PN_typedargslist);
744 EMIT(load_build_class);
750 close_over_variables_etc(comp, cscope, 0, 0);
761 compile_trailer_paren_helper(comp, parents,
false, 2);
768 STATIC bool compile_built_in_decorator(compiler_t *comp,
int name_len,
mp_parse_node_t *name_nodes,
uint *emit_options) {
774 compile_syntax_error(comp, name_nodes[0],
"invalid micropython decorator");
779 if (
attr == MP_QSTR_bytecode) {
781 #if MICROPY_EMIT_NATIVE 782 }
else if (
attr == MP_QSTR_native) {
784 }
else if (
attr == MP_QSTR_viper) {
787 #if MICROPY_EMIT_INLINE_ASM 788 }
else if (
attr == ASM_DECORATOR_QSTR) {
792 compile_syntax_error(comp, name_nodes[1],
"invalid micropython decorator");
804 uint emit_options = comp->scope_cur->emit_options;
807 int num_built_in_decorators = 0;
808 for (
int i = 0; i < n; i++) {
817 if (compile_built_in_decorator(comp, name_len, name_nodes, &emit_options)) {
819 num_built_in_decorators += 1;
825 compile_node(comp, name_nodes[0]);
826 for (
int j = 1; j < name_len; j++) {
834 compile_node(comp, pns_decorator->
nodes[1]);
843 body_name = compile_funcdef_helper(comp, pns_body, emit_options);
844 #if MICROPY_PY_ASYNC_AWAIT 848 body_name = compile_funcdef_helper(comp, pns0, emit_options);
854 body_name = compile_classdef_helper(comp, pns_body, emit_options);
858 for (
int i = 0; i < n - num_built_in_decorators; i++) {
859 EMIT_ARG(call_function, 1, 0, 0);
863 compile_store_id(comp, body_name);
867 qstr fname = compile_funcdef_helper(comp, pns, comp->scope_cur->emit_options);
869 compile_store_id(comp, fname);
878 compile_node(comp, pns->
nodes[0]);
884 for (
int i = 0; i < n - 1; i++) {
885 compile_node(comp, pns1->
nodes[i]);
891 compile_node(comp, pns1->
nodes[0]);
917 c_del_stmt(comp, pns->
nodes[0]);
921 c_del_stmt(comp, pns->
nodes[0]);
922 for (
int i = 0; i < n; i++) {
923 c_del_stmt(comp, pns1->
nodes[i]);
929 goto sequence_with_2_items;
933 sequence_with_2_items:
934 c_del_stmt(comp, pns->
nodes[0]);
935 c_del_stmt(comp, pns->
nodes[1]);
946 compile_syntax_error(comp, (
mp_parse_node_t)pn,
"can't delete expression");
950 apply_to_single_or_list(comp, pns->
nodes[0], PN_exprlist, c_del_stmt);
954 if (comp->break_label == INVALID_LABEL) {
955 compile_syntax_error(comp, (
mp_parse_node_t)pns,
"'break' outside loop");
957 assert(comp->cur_except_level >= comp->break_continue_except_level);
958 EMIT_ARG(break_loop, comp->break_label, comp->cur_except_level - comp->break_continue_except_level);
962 if (comp->continue_label == INVALID_LABEL) {
963 compile_syntax_error(comp, (
mp_parse_node_t)pns,
"'continue' outside loop");
965 assert(comp->cur_except_level >= comp->break_continue_except_level);
966 EMIT_ARG(continue_loop, comp->continue_label, comp->cur_except_level - comp->break_continue_except_level);
971 compile_syntax_error(comp, (
mp_parse_node_t)pns,
"'return' outside function");
983 uint l_fail = comp_next_label(comp);
984 c_if_cond(comp, pns_test_if_else->nodes[0],
false, l_fail);
985 compile_node(comp, pns_test_if_expr->
nodes[0]);
987 EMIT_ARG(label_assign, l_fail);
988 compile_node(comp, pns_test_if_else->nodes[1]);
990 compile_node(comp, pns->
nodes[0]);
996 compile_node(comp, pns->
nodes[0]);
1003 EMIT_ARG(raise_varargs, 0);
1007 compile_node(comp, pns->
nodes[0]);
1008 compile_node(comp, pns->
nodes[1]);
1009 EMIT_ARG(raise_varargs, 2);
1012 compile_node(comp, pns->
nodes[0]);
1013 EMIT_ARG(raise_varargs, 1);
1032 EMIT_ARG(import_name, MP_QSTR_);
1039 EMIT_ARG(import_name, q_full);
1050 for (
int i = 0; i < n; i++) {
1055 for (
int i = 0; i < n; i++) {
1061 memcpy(str_dest, str_src, str_src_len);
1062 str_dest += str_src_len;
1065 EMIT_ARG(import_name, q_full);
1067 for (
int i = 1; i < n; i++) {
1076 EMIT_ARG(load_const_small_int, 0);
1079 do_import_name(comp, pn, &q_base);
1080 compile_store_id(comp, q_base);
1084 apply_to_single_or_list(comp, pns->
nodes[0], PN_dotted_as_names, compile_dotted_as_name);
1091 uint import_level = 0;
1096 pn_rel = pn_import_source;
1101 pn_rel = pns_2b->
nodes[0];
1102 pn_import_source = pns_2b->
nodes[1];
1114 for (
int i = 0; i < n; i++) {
1125 EMIT_ARG(load_const_small_int, import_level);
1128 EMIT_ARG(load_const_str, MP_QSTR__star_);
1129 EMIT_ARG(build_tuple, 1);
1133 do_import_name(comp, pn_import_source, &dummy_q);
1137 EMIT_ARG(load_const_small_int, import_level);
1142 for (
int i = 0; i < n; i++) {
1146 EMIT_ARG(load_const_str, id2);
1148 EMIT_ARG(build_tuple, n);
1152 do_import_name(comp, pn_import_source, &dummy_q);
1153 for (
int i = 0; i < n; i++) {
1157 EMIT_ARG(import_from, id2);
1159 compile_store_id(comp, id2);
1172 compile_syntax_error(comp, pn,
"identifier redefined as global");
1179 if (id_info !=
NULL) {
1188 for (
int i = 0; i < n; i++) {
1200 compile_syntax_error(comp, pn,
"no binding for nonlocal found");
1203 compile_syntax_error(comp, pn,
"identifier redefined as nonlocal");
1210 compile_syntax_error(comp, (
mp_parse_node_t)pns,
"can't declare nonlocal in outer code");
1215 for (
int i = 0; i < n; i++) {
1227 uint l_end = comp_next_label(comp);
1228 c_if_cond(comp, pns->
nodes[0],
true, l_end);
1229 EMIT_LOAD_GLOBAL(MP_QSTR_AssertionError);
1232 compile_node(comp, pns->
nodes[1]);
1233 EMIT_ARG(call_function, 1, 0, 0);
1235 EMIT_ARG(raise_varargs, 1);
1236 EMIT_ARG(label_assign, l_end);
1240 uint l_end = comp_next_label(comp);
1244 uint l_fail = comp_next_label(comp);
1245 c_if_cond(comp, pns->
nodes[0],
false, l_fail);
1247 compile_node(comp, pns->
nodes[1]);
1258 && !EMIT(last_emit_was_return_value)
1261 EMIT_ARG(jump, l_end);
1264 EMIT_ARG(label_assign, l_fail);
1270 for (
int i = 0; i < n_elif; i++) {
1276 uint l_fail = comp_next_label(comp);
1277 c_if_cond(comp, pns_elif->
nodes[0],
false, l_fail);
1279 compile_node(comp, pns_elif->
nodes[1]);
1287 if (!EMIT(last_emit_was_return_value)) {
1288 EMIT_ARG(jump, l_end);
1290 EMIT_ARG(label_assign, l_fail);
1295 compile_node(comp, pns->
nodes[3]);
1298 EMIT_ARG(label_assign, l_end);
1301 #define START_BREAK_CONTINUE_BLOCK \ 1302 uint16_t old_break_label = comp->break_label; \ 1303 uint16_t old_continue_label = comp->continue_label; \ 1304 uint16_t old_break_continue_except_level = comp->break_continue_except_level; \ 1305 uint break_label = comp_next_label(comp); \ 1306 uint continue_label = comp_next_label(comp); \ 1307 comp->break_label = break_label; \ 1308 comp->continue_label = continue_label; \ 1309 comp->break_continue_except_level = comp->cur_except_level; 1311 #define END_BREAK_CONTINUE_BLOCK \ 1312 comp->break_label = old_break_label; \ 1313 comp->continue_label = old_continue_label; \ 1314 comp->break_continue_except_level = old_break_continue_except_level; 1317 START_BREAK_CONTINUE_BLOCK
1320 uint top_label = comp_next_label(comp);
1322 EMIT_ARG(jump, continue_label);
1324 EMIT_ARG(label_assign, top_label);
1325 compile_node(comp, pns->
nodes[1]);
1326 EMIT_ARG(label_assign, continue_label);
1327 c_if_cond(comp, pns->
nodes[0],
true, top_label);
1331 END_BREAK_CONTINUE_BLOCK
1333 compile_node(comp, pns->
nodes[2]);
1335 EMIT_ARG(label_assign, break_label);
1355 START_BREAK_CONTINUE_BLOCK
1357 uint top_label = comp_next_label(comp);
1358 uint entry_label = comp_next_label(comp);
1363 compile_node(comp, pn_end);
1367 compile_node(comp, pn_start);
1369 EMIT_ARG(jump, entry_label);
1370 EMIT_ARG(label_assign, top_label);
1374 c_assign(comp, pn_var, ASSIGN_STORE);
1377 compile_node(comp, pn_body);
1379 EMIT_ARG(label_assign, continue_label);
1382 compile_node(comp, pn_step);
1385 EMIT_ARG(label_assign, entry_label);
1393 compile_node(comp, pn_end);
1401 EMIT_ARG(pop_jump_if,
true, top_label);
1404 END_BREAK_CONTINUE_BLOCK
1415 compile_node(comp, pn_else);
1416 end_label = comp_next_label(comp);
1417 EMIT_ARG(jump, end_label);
1418 EMIT_ARG(adjust_stack_size, 1 + end_on_stack);
1421 EMIT_ARG(label_assign, break_label);
1432 EMIT_ARG(label_assign, end_label);
1451 bool optimize =
false;
1452 if (1 <= n_args && n_args <= 3) {
1455 pn_range_start = mp_parse_node_new_small_int(0);
1456 pn_range_end =
args[0];
1457 pn_range_step = mp_parse_node_new_small_int(1);
1458 }
else if (n_args == 2) {
1459 pn_range_start =
args[0];
1460 pn_range_end =
args[1];
1461 pn_range_step = mp_parse_node_new_small_int(1);
1463 pn_range_start =
args[0];
1464 pn_range_end =
args[1];
1465 pn_range_step =
args[2];
1475 if (k == PN_arglist_star || k == PN_arglist_dbl_star || k == PN_argument) {
1481 if (k == PN_arglist_star || k == PN_arglist_dbl_star || k == PN_argument) {
1487 compile_for_stmt_optimised_range(comp, pns->
nodes[0], pn_range_start, pn_range_end, pn_range_step, pns->
nodes[2], pns->
nodes[3]);
1493 START_BREAK_CONTINUE_BLOCK
1496 uint pop_label = comp_next_label(comp);
1498 compile_node(comp, pns->
nodes[1]);
1499 EMIT_ARG(get_iter,
true);
1500 EMIT_ARG(label_assign, continue_label);
1501 EMIT_ARG(for_iter, pop_label);
1502 c_assign(comp, pns->
nodes[0], ASSIGN_STORE);
1503 compile_node(comp, pns->
nodes[2]);
1504 if (!EMIT(last_emit_was_return_value)) {
1505 EMIT_ARG(jump, continue_label);
1507 EMIT_ARG(label_assign, pop_label);
1511 END_BREAK_CONTINUE_BLOCK
1513 compile_node(comp, pns->
nodes[3]);
1515 EMIT_ARG(label_assign, break_label);
1520 uint l1 = comp_next_label(comp);
1521 uint success_label = comp_next_label(comp);
1523 EMIT_ARG(setup_except, l1);
1524 compile_increase_except_level(comp);
1526 compile_node(comp, pn_body);
1528 EMIT_ARG(jump, success_label);
1530 EMIT_ARG(label_assign, l1);
1531 EMIT(start_except_handler);
1535 uint l2 = comp_next_label(comp);
1537 for (
int i = 0; i < n_except; i++) {
1541 qstr qstr_exception_local = 0;
1542 uint end_finally_label = comp_next_label(comp);
1546 if (i + 1 != n_except) {
1547 compile_syntax_error(comp, pn_excepts[i],
"default 'except' must be last");
1548 compile_decrease_except_level(comp);
1558 pns_exception_expr = pns3->
nodes[0];
1563 compile_node(comp, pns_exception_expr);
1565 EMIT_ARG(pop_jump_if,
false, end_finally_label);
1569 if (qstr_exception_local == 0) {
1572 compile_store_id(comp, qstr_exception_local);
1576 if (qstr_exception_local != 0) {
1577 l3 = comp_next_label(comp);
1578 EMIT_ARG(setup_finally, l3);
1579 compile_increase_except_level(comp);
1581 compile_node(comp, pns_except->
nodes[1]);
1582 if (qstr_exception_local != 0) {
1586 if (qstr_exception_local != 0) {
1588 EMIT_ARG(label_assign, l3);
1590 compile_store_id(comp, qstr_exception_local);
1591 compile_delete_id(comp, qstr_exception_local);
1593 compile_decrease_except_level(comp);
1597 EMIT_ARG(label_assign, end_finally_label);
1598 EMIT_ARG(adjust_stack_size, 1);
1601 compile_decrease_except_level(comp);
1603 EMIT(end_except_handler);
1605 EMIT_ARG(label_assign, success_label);
1606 compile_node(comp, pn_else);
1607 EMIT_ARG(label_assign, l2);
1611 uint l_finally_block = comp_next_label(comp);
1613 EMIT_ARG(setup_finally, l_finally_block);
1614 compile_increase_except_level(comp);
1616 if (n_except == 0) {
1618 EMIT_ARG(adjust_stack_size, 3);
1619 compile_node(comp, pn_body);
1620 EMIT_ARG(adjust_stack_size, -3);
1622 compile_try_except(comp, pn_body, n_except, pn_except, pn_else);
1626 EMIT_ARG(label_assign, l_finally_block);
1627 compile_node(comp, pn_finally);
1629 compile_decrease_except_level(comp);
1646 compile_try_except(comp, pns->
nodes[0], n_except, pn_excepts, pns2->
nodes[1]);
1663 compile_node(comp, body);
1665 uint l_end = comp_next_label(comp);
1669 comp_next_label(comp);
1674 compile_node(comp, pns->
nodes[0]);
1675 EMIT_ARG(setup_with, l_end);
1676 c_assign(comp, pns->
nodes[1], ASSIGN_STORE);
1679 compile_node(comp, nodes[0]);
1680 EMIT_ARG(setup_with, l_end);
1683 compile_increase_except_level(comp);
1685 compile_with_stmt_helper(comp, n - 1, nodes + 1, body);
1687 EMIT_ARG(with_cleanup, l_end);
1688 compile_decrease_except_level(comp);
1700 compile_with_stmt_helper(comp, n, nodes, pns->
nodes[1]);
1703 STATIC void compile_yield_from(compiler_t *comp) {
1704 EMIT_ARG(get_iter,
false);
1709 #if MICROPY_PY_ASYNC_AWAIT 1710 STATIC void compile_await_object_method(compiler_t *comp,
qstr method) {
1711 EMIT_ARG(load_method, method,
false);
1712 EMIT_ARG(call_method, 0, 0, 0);
1713 compile_yield_from(comp);
1720 uint while_else_label = comp_next_label(comp);
1721 uint try_exception_label = comp_next_label(comp);
1722 uint try_else_label = comp_next_label(comp);
1723 uint try_finally_label = comp_next_label(comp);
1725 compile_node(comp, pns->
nodes[1]);
1726 compile_await_object_method(comp, MP_QSTR___aiter__);
1727 compile_store_id(comp, context);
1729 START_BREAK_CONTINUE_BLOCK
1731 EMIT_ARG(label_assign, continue_label);
1733 EMIT_ARG(setup_except, try_exception_label);
1734 compile_increase_except_level(comp);
1736 compile_load_id(comp, context);
1737 compile_await_object_method(comp, MP_QSTR___anext__);
1738 c_assign(comp, pns->
nodes[0], ASSIGN_STORE);
1740 EMIT_ARG(jump, try_else_label);
1742 EMIT_ARG(label_assign, try_exception_label);
1743 EMIT(start_except_handler);
1745 EMIT_LOAD_GLOBAL(MP_QSTR_StopAsyncIteration);
1747 EMIT_ARG(pop_jump_if,
false, try_finally_label);
1750 EMIT_ARG(jump, while_else_label);
1752 EMIT_ARG(label_assign, try_finally_label);
1753 EMIT_ARG(adjust_stack_size, 1);
1754 compile_decrease_except_level(comp);
1756 EMIT(end_except_handler);
1758 EMIT_ARG(label_assign, try_else_label);
1759 compile_node(comp, pns->
nodes[2]);
1761 EMIT_ARG(jump, continue_label);
1763 END_BREAK_CONTINUE_BLOCK
1765 EMIT_ARG(label_assign, while_else_label);
1766 compile_node(comp, pns->
nodes[3]);
1768 EMIT_ARG(label_assign, break_label);
1774 compile_node(comp, body);
1776 uint try_exception_label = comp_next_label(comp);
1777 uint no_reraise_label = comp_next_label(comp);
1778 uint try_else_label = comp_next_label(comp);
1779 uint end_label = comp_next_label(comp);
1785 compile_node(comp, pns->
nodes[0]);
1787 compile_store_id(comp, context);
1788 compile_load_id(comp, context);
1789 compile_await_object_method(comp, MP_QSTR___aenter__);
1790 c_assign(comp, pns->
nodes[1], ASSIGN_STORE);
1793 compile_node(comp, nodes[0]);
1795 compile_store_id(comp, context);
1796 compile_load_id(comp, context);
1797 compile_await_object_method(comp, MP_QSTR___aenter__);
1801 compile_load_id(comp, context);
1802 EMIT_ARG(load_method, MP_QSTR___aexit__,
false);
1804 EMIT_ARG(setup_except, try_exception_label);
1805 compile_increase_except_level(comp);
1807 compile_async_with_stmt_helper(comp, n - 1, nodes + 1, body);
1810 EMIT_ARG(jump, try_else_label);
1812 EMIT_ARG(label_assign, try_exception_label);
1813 EMIT(start_except_handler);
1817 #if MICROPY_CPYTHON_COMPAT 1818 EMIT_ARG(load_attr, MP_QSTR___class__);
1820 compile_load_id(comp, MP_QSTR_type);
1822 EMIT_ARG(call_function, 1, 0, 0);
1827 EMIT_ARG(call_method, 3, 0, 0);
1829 compile_yield_from(comp);
1830 EMIT_ARG(pop_jump_if,
true, no_reraise_label);
1831 EMIT_ARG(raise_varargs, 0);
1833 EMIT_ARG(label_assign, no_reraise_label);
1835 EMIT_ARG(jump, end_label);
1837 EMIT_ARG(adjust_stack_size, 3);
1838 compile_decrease_except_level(comp);
1840 EMIT(end_except_handler);
1842 EMIT_ARG(label_assign, try_else_label);
1846 EMIT_ARG(call_method, 3, 0, 0);
1847 compile_yield_from(comp);
1850 EMIT_ARG(label_assign, end_label);
1862 compile_async_with_stmt_helper(comp, n, nodes, pns->
nodes[1]);
1870 compile_funcdef(comp, pns0);
1875 compile_async_for_stmt(comp, pns0);
1879 compile_async_with_stmt(comp, pns0);
1886 if (comp->is_repl && comp->scope_cur->kind ==
SCOPE_MODULE) {
1888 compile_load_id(comp, MP_QSTR___repl_print__);
1889 compile_node(comp, pns->
nodes[0]);
1890 EMIT_ARG(call_function, 1, 0, 0);
1899 compile_node(comp, pns->
nodes[0]);
1906 if (kind == PN_expr_stmt_augassign) {
1907 c_assign(comp, pns->
nodes[0], ASSIGN_AUG_LOAD);
1908 compile_node(comp, pns1->
nodes[1]);
1925 EMIT_ARG(binary_op, op);
1926 c_assign(comp, pns->
nodes[0], ASSIGN_AUG_STORE);
1927 }
else if (kind == PN_expr_stmt_assign_list) {
1929 compile_node(comp, pns1->
nodes[rhs]);
1934 c_assign(comp, pns->
nodes[0], ASSIGN_STORE);
1935 for (
int i = 0; i < rhs; i++) {
1939 c_assign(comp, pns1->
nodes[i], ASSIGN_STORE);
1954 goto no_optimisation;
1956 compile_node(comp, pns10->
nodes[0]);
1957 compile_node(comp, pns10->
nodes[1]);
1959 c_assign(comp, pns0->
nodes[0], ASSIGN_STORE);
1960 c_assign(comp, pns0->
nodes[1], ASSIGN_STORE);
1973 goto no_optimisation;
1975 compile_node(comp, pns10->
nodes[0]);
1976 compile_node(comp, pns10->
nodes[1]);
1977 compile_node(comp, pns10->
nodes[2]);
1980 c_assign(comp, pns0->
nodes[0], ASSIGN_STORE);
1981 c_assign(comp, pns0->
nodes[1], ASSIGN_STORE);
1982 c_assign(comp, pns0->
nodes[2], ASSIGN_STORE);
1985 compile_node(comp, pns->
nodes[1]);
1986 c_assign(comp, pns->
nodes[0], ASSIGN_STORE);
1996 compile_node(comp, pns->
nodes[0]);
1997 for (
int i = 1; i < num_nodes; i += 1) {
1998 compile_node(comp, pns->
nodes[i]);
1999 EMIT_ARG(binary_op, binary_op);
2007 uint l_fail = comp_next_label(comp);
2008 uint l_end = comp_next_label(comp);
2009 c_if_cond(comp, pns_test_if_else->
nodes[0],
false, l_fail);
2010 compile_node(comp, pns->
nodes[0]);
2011 EMIT_ARG(jump, l_end);
2012 EMIT_ARG(label_assign, l_fail);
2013 EMIT_ARG(adjust_stack_size, -1);
2014 compile_node(comp, pns_test_if_else->
nodes[1]);
2015 EMIT_ARG(label_assign, l_end);
2030 compile_funcdef_lambdef(comp, this_scope, pns->
nodes[0], PN_varargslist);
2034 uint l_end = comp_next_label(comp);
2036 for (
int i = 0; i < n; i += 1) {
2037 compile_node(comp, pns->
nodes[i]);
2039 EMIT_ARG(jump_if_or_pop, cond, l_end);
2042 EMIT_ARG(label_assign, l_end);
2046 compile_or_and_test(comp, pns,
true);
2050 compile_or_and_test(comp, pns,
false);
2054 compile_node(comp, pns->
nodes[0]);
2060 compile_node(comp, pns->
nodes[0]);
2061 bool multi = (num_nodes > 3);
2064 l_fail = comp_next_label(comp);
2066 for (
int i = 1; i + 1 < num_nodes; i += 2) {
2067 compile_node(comp, pns->
nodes[i + 1]);
2068 if (i + 2 < num_nodes) {
2083 EMIT_ARG(binary_op, op);
2088 if (kind == PN_comp_op_not_in) {
2091 assert(kind == PN_comp_op_is);
2099 if (i + 2 < num_nodes) {
2100 EMIT_ARG(jump_if_or_pop,
false, l_fail);
2104 uint l_end = comp_next_label(comp);
2105 EMIT_ARG(jump, l_end);
2106 EMIT_ARG(label_assign, l_fail);
2107 EMIT_ARG(adjust_stack_size, 1);
2110 EMIT_ARG(label_assign, l_end);
2115 compile_syntax_error(comp, (
mp_parse_node_t)pns,
"*x must be assignment target");
2132 compile_node(comp, pns->
nodes[0]);
2133 for (
int i = 1; i + 1 < num_nodes; i += 2) {
2134 compile_node(comp, pns->
nodes[i + 1]);
2150 EMIT_ARG(binary_op, op);
2155 compile_node(comp, pns->
nodes[1]);
2166 EMIT_ARG(unary_op, op);
2171 compile_node(comp, pns->
nodes[0]);
2179 size_t num_trail = 1;
2198 compile_load_id(comp, MP_QSTR___class__);
2202 id_info_t *
id = &comp->scope_cur->id_info[0];
2203 for (
size_t n = comp->scope_cur->id_info_len; n > 0; --n, ++
id) {
2206 compile_load_id(comp, id->
qst);
2213 "super() can't find self");
2224 compile_trailer_paren_helper(comp, pns_paren->
nodes[0],
true, 0);
2228 EMIT_ARG(call_function, 2, 0, 0);
2234 for (; i < num_trail; i++) {
2235 if (i + 1 < num_trail
2242 compile_trailer_paren_helper(comp, pns_paren->
nodes[0],
true, 0);
2252 compile_generic_all_nodes(comp, pns);
2256 STATIC void compile_trailer_paren_helper(compiler_t *comp,
mp_parse_node_t pn_arglist,
bool is_method_call,
int n_positional_extra) {
2267 int n_positional = n_positional_extra;
2269 uint star_flags = 0;
2271 for (
int i = 0; i < n_args; i++) {
2276 compile_syntax_error(comp, (
mp_parse_node_t)pns_arg,
"can't have multiple *x");
2280 star_args_node = pns_arg;
2283 compile_syntax_error(comp, (
mp_parse_node_t)pns_arg,
"can't have multiple **x");
2287 dblstar_args_node = pns_arg;
2291 compile_syntax_error(comp, (
mp_parse_node_t)pns_arg,
"LHS of keyword arg must be an id");
2295 compile_node(comp, pns_arg->
nodes[1]);
2302 goto normal_argument;
2307 compile_syntax_error(comp,
args[i],
"non-keyword arg after */**");
2310 if (n_keyword > 0) {
2311 compile_syntax_error(comp,
args[i],
"non-keyword arg after keyword arg");
2314 compile_node(comp,
args[i]);
2321 if (star_flags != 0) {
2322 if (star_args_node ==
NULL) {
2325 compile_node(comp, star_args_node->
nodes[0]);
2327 if (dblstar_args_node ==
NULL) {
2330 compile_node(comp, dblstar_args_node->nodes[0]);
2335 if (is_method_call) {
2336 EMIT_ARG(call_method, n_positional, n_keyword, star_flags);
2338 EMIT_ARG(call_function, n_positional, n_keyword, star_flags);
2359 close_over_variables_etc(comp, this_scope, 0, 0);
2361 compile_node(comp, pns_comp_for->
nodes[1]);
2363 EMIT_ARG(get_iter,
false);
2365 EMIT_ARG(call_function, 1, 0, 0);
2384 c_tuple(comp, pns->
nodes[0], pns2);
2390 goto tuple_with_2_items;
2403 EMIT_ARG(build_list, 0);
2411 compile_node(comp, pns2->
nodes[0]);
2412 EMIT_ARG(build_list, 1);
2415 compile_node(comp, pns2->
nodes[0]);
2416 compile_generic_all_nodes(comp, pns3);
2423 goto list_with_2_items;
2428 compile_node(comp, pns2->
nodes[0]);
2429 compile_node(comp, pns2->
nodes[1]);
2430 EMIT_ARG(build_list, 2);
2434 compile_node(comp, pns->
nodes[0]);
2435 EMIT_ARG(build_list, 1);
2443 EMIT_ARG(build_map, 0);
2448 EMIT_ARG(build_map, 1);
2449 compile_node(comp, pn);
2465 EMIT_ARG(build_map, 1 + n);
2466 compile_node(comp, pns->
nodes[0]);
2471 compile_node(comp, pns->
nodes[0]);
2476 for (
int i = 0; i < n; i++) {
2479 compile_node(comp, pn_i);
2481 if (!is_key_value) {
2485 compile_syntax_error(comp, (
mp_parse_node_t)pns,
"expecting key:value for dict");
2495 compile_syntax_error(comp, (
mp_parse_node_t)pns,
"expecting just a value for set");
2502 #if MICROPY_PY_BUILTINS_SET 2505 EMIT_ARG(build_set, 1 + n);
2521 goto set_with_one_element;
2525 set_with_one_element:
2526 #if MICROPY_PY_BUILTINS_SET 2527 compile_node(comp, pn);
2528 EMIT_ARG(build_set, 1);
2536 compile_trailer_paren_helper(comp, pns->
nodes[0],
false, 0);
2541 compile_node(comp, pns->
nodes[0]);
2550 #if MICROPY_PY_BUILTINS_SLICE 2557 EMIT_ARG(build_slice, 2);
2565 EMIT_ARG(build_slice, 2);
2568 compile_node(comp, pn);
2569 EMIT_ARG(build_slice, 3);
2572 compile_node(comp, pns->
nodes[0]);
2578 EMIT_ARG(build_slice, 2);
2581 compile_node(comp, pns->
nodes[0]);
2582 EMIT_ARG(build_slice, 3);
2586 compile_node(comp, pn);
2587 EMIT_ARG(build_slice, 2);
2591 compile_node(comp, pn);
2592 EMIT_ARG(build_slice, 2);
2597 compile_node(comp, pns->
nodes[0]);
2604 compile_subscript_3_helper(comp, pns);
2606 #endif // MICROPY_PY_BUILTINS_SLICE 2610 compile_node(comp, pns->
nodes[1]);
2611 compile_node(comp, pns->
nodes[0]);
2615 qstr cname = compile_classdef_helper(comp, pns, comp->scope_cur->emit_options);
2617 compile_store_id(comp, cname);
2622 compile_syntax_error(comp, (
mp_parse_node_t)pns,
"'yield' outside function");
2630 compile_node(comp, pns->
nodes[0]);
2631 compile_yield_from(comp);
2633 compile_node(comp, pns->
nodes[0]);
2638 #if MICROPY_PY_ASYNC_AWAIT 2641 compile_syntax_error(comp, (
mp_parse_node_t)pns,
"'await' outside function");
2644 compile_atom_expr_normal(comp, pns);
2645 compile_yield_from(comp);
2650 #if MICROPY_OBJ_REPR == MICROPY_OBJ_REPR_D 2659 EMIT_ARG(load_const_obj, get_const_object(pns));
2663 STATIC const compile_function_t compile_function[] = {
2665 #define c(f) compile_##f 2666 #define DEF_RULE(rule, comp, kind, ...) comp, 2667 #define DEF_RULE_NC(rule, kind, ...) 2672 compile_const_object,
2680 #if MICROPY_DYNAMIC_COMPILER 2681 mp_uint_t sign_mask = -(1 << (mp_dynamic_compiler.small_int_bits - 1));
2682 if ((arg & sign_mask) == 0 || (arg & sign_mask) == sign_mask) {
2684 EMIT_ARG(load_const_small_int, arg);
2695 EMIT_ARG(load_const_small_int, arg);
2718 EMIT_ARG(load_const_tok, arg);
2731 STATIC void compile_scope_func_lambda_param(compiler_t *comp,
mp_parse_node_t pn, pn_kind_t pn_name, pn_kind_t pn_star, pn_kind_t pn_dbl_star) {
2734 compile_syntax_error(comp, pn,
"invalid syntax");
2738 qstr param_name = MP_QSTR_NULL;
2742 if (comp->have_star) {
2744 comp->scope_cur->num_kwonly_args += 1;
2747 comp->scope_cur->num_pos_args += 1;
2754 if (comp->have_star) {
2756 comp->scope_cur->num_kwonly_args += 1;
2759 comp->scope_cur->num_pos_args += 1;
2762 if (comp->have_star) {
2764 compile_syntax_error(comp, pn,
"invalid syntax");
2767 comp->have_star =
true;
2792 if (param_name != MP_QSTR_NULL) {
2796 compile_syntax_error(comp, pn,
"name reused for argument");
2800 id_info->
flags = param_flag;
2805 compile_scope_func_lambda_param(comp, pn, PN_typedargslist_name, PN_typedargslist_star, PN_typedargslist_dbl_star);
2809 compile_scope_func_lambda_param(comp, pn, PN_varargslist_name, PN_varargslist_star, PN_varargslist_dbl_star);
2812 #if MICROPY_EMIT_NATIVE 2849 compile_syntax_error(comp, pn_annotation,
"parameter annotation must be an identifier");
2853 #endif // MICROPY_EMIT_NATIVE 2856 uint l_top = comp_next_label(comp);
2857 uint l_end = comp_next_label(comp);
2858 EMIT_ARG(label_assign, l_top);
2859 EMIT_ARG(for_iter, l_end);
2860 c_assign(comp, pns_comp_for->
nodes[0], ASSIGN_STORE);
2866 compile_node(comp, pn_inner_expr);
2871 EMIT_ARG(store_comp, comp->scope_cur->kind, 4 * for_depth + 5);
2876 c_if_cond(comp, pns_comp_if->
nodes[0],
false, l_top);
2877 pn_iter = pns_comp_if->
nodes[1];
2878 goto tail_recursion;
2883 compile_node(comp, pns_comp_for2->
nodes[1]);
2884 EMIT_ARG(get_iter,
true);
2885 compile_scope_comp_iter(comp, pns_comp_for2, pn_inner_expr, for_depth + 1);
2888 EMIT_ARG(jump, l_top);
2889 EMIT_ARG(label_assign, l_end);
2894 #if MICROPY_ENABLE_DOC_STRING 2904 for (
int i = 0; i < num_nodes; i++) {
2927 compile_node(comp, pns->
nodes[0]);
2929 compile_store_id(comp, MP_QSTR___doc__);
2940 comp->scope_cur = scope;
2941 comp->next_label = 0;
2942 EMIT_ARG(start_pass, pass, scope);
2955 compile_node(comp, pns->
nodes[0]);
2958 if (!comp->is_repl) {
2959 check_for_doc_string(comp, scope->
pn);
2961 compile_node(comp, scope->
pn);
2972 comp->have_star =
false;
2973 apply_to_single_or_list(comp, pns->
nodes[1], PN_typedargslist, compile_scope_func_param);
2975 #if MICROPY_EMIT_NATIVE 2981 apply_to_single_or_list(comp, pns->
nodes[1], PN_typedargslist, compile_scope_func_annotations);
2991 compile_syntax_error(comp, pn_annotation,
"return annotation must be an identifier");
2995 #endif // MICROPY_EMIT_NATIVE 2997 compile_node(comp, pns->
nodes[3]);
2999 if (!EMIT(last_emit_was_return_value)) {
3011 comp->have_star =
false;
3012 apply_to_single_or_list(comp, pns->
nodes[0], PN_varargslist, compile_scope_lambda_param);
3015 compile_node(comp, pns->
nodes[1]);
3036 qstr qstr_arg = MP_QSTR_;
3046 EMIT_ARG(build_list, 0);
3048 EMIT_ARG(build_map, 0);
3049 #if MICROPY_PY_BUILTINS_SET 3051 EMIT_ARG(build_set, 0);
3060 compile_load_id(comp, qstr_arg);
3064 compile_load_id(comp, qstr_arg);
3065 EMIT_ARG(get_iter,
true);
3068 compile_scope_comp_iter(comp, pns_comp_for, pns->
nodes[0], 0);
3087 compile_load_id(comp, MP_QSTR___name__);
3088 compile_store_id(comp, MP_QSTR___module__);
3090 compile_store_id(comp, MP_QSTR___qualname__);
3092 check_for_doc_string(comp, pns->
nodes[2]);
3093 compile_node(comp, pns->
nodes[2]);
3100 EMIT_LOAD_FAST(MP_QSTR___class__, id->
local_num);
3108 assert(comp->cur_except_level == 0);
3111 #if MICROPY_EMIT_INLINE_ASM 3115 comp->scope_cur = scope;
3116 comp->next_label = 0;
3119 compile_syntax_error(comp,
MP_PARSE_NODE_NULL,
"inline assembler must be a function");
3124 EMIT_INLINE_ASM_ARG(start_pass, comp->pass, &comp->compile_error);
3138 scope->
num_pos_args = EMIT_INLINE_ASM_ARG(count_params, n_params, pn_params);
3140 goto inline_asm_error;
3156 default: compile_syntax_error(comp, pn_annotation,
"unknown type");
return;
3159 compile_syntax_error(comp, pn_annotation,
"return annotation must be an identifier");
3167 for (
int i = 0; i < num; i++) {
3176 compile_syntax_error(comp, nodes[i],
"expecting an assembler instruction");
3183 goto not_an_instruction;
3187 goto not_an_instruction;
3190 goto not_an_instruction;
3193 goto not_an_instruction;
3204 if (op == MP_QSTR_label) {
3206 compile_syntax_error(comp, nodes[i],
"'label' requires 1 argument");
3209 uint lab = comp_next_label(comp);
3212 compile_syntax_error(comp, nodes[i],
"label redefined");
3216 }
else if (op == MP_QSTR_align) {
3218 compile_syntax_error(comp, nodes[i],
"'align' requires 1 argument");
3225 }
else if (op == MP_QSTR_data) {
3227 compile_syntax_error(comp, nodes[i],
"'data' requires at least 2 arguments");
3232 for (
uint j = 1; j < n_args; j++) {
3234 compile_syntax_error(comp, nodes[i],
"'data' requires integer arguments");
3243 EMIT_INLINE_ASM_ARG(op, op, n_args, pn_arg);
3249 goto inline_asm_error;
3254 EMIT_INLINE_ASM_ARG(end_pass, type_sig);
3257 void *f = mp_asm_base_get_code((
mp_asm_base_t*)comp->emit_inline_asm);
3259 f, mp_asm_base_get_code_size((
mp_asm_base_t*)comp->emit_inline_asm),
3260 NULL, comp->scope_cur->num_pos_args, 0, type_sig);
3276 for (
int i = scope->
id_info_len - 1; i >= 0; i--) {
3279 if (id_param !=
NULL) {
3281 id_info_t temp = *id_param; *id_param = *id; *
id = temp;
3352 #if !MICROPY_PERSISTENT_CODE_SAVE 3357 compiler_t comp_state = {0};
3358 compiler_t *comp = &comp_state;
3360 comp->source_file = source_file;
3361 comp->is_repl = is_repl;
3362 comp->break_label = INVALID_LABEL;
3363 comp->continue_label = INVALID_LABEL;
3372 comp->emit = emit_bc;
3373 #if MICROPY_EMIT_NATIVE 3376 uint max_num_labels = 0;
3379 #if MICROPY_EMIT_INLINE_ASM 3388 if (comp->next_label > max_num_labels) {
3389 max_num_labels = comp->next_label;
3395 scope_compute_things(s);
3402 #if MICROPY_EMIT_NATIVE 3409 #if MICROPY_EMIT_INLINE_ASM 3412 if (comp->emit_inline_asm ==
NULL) {
3413 comp->emit_inline_asm = ASM_EMITTER(
new)(max_num_labels);
3416 comp->emit_inline_asm_method_table = &ASM_EMITTER(method_table);
3418 #if MICROPY_EMIT_INLINE_XTENSA 3435 #if MICROPY_EMIT_NATIVE 3438 if (emit_native ==
NULL) {
3439 emit_native = NATIVE_EMITTER(
new)(&comp->compile_error, max_num_labels);
3441 comp->emit_method_table = &NATIVE_EMITTER(method_table);
3442 comp->emit = emit_native;
3445 #endif // MICROPY_EMIT_NATIVE 3448 comp->emit = emit_bc;
3449 #if MICROPY_EMIT_NATIVE 3473 compile_error_set_line(comp, comp->scope_cur->pn);
3476 comp->compile_error_line, comp->scope_cur->simple_name);
3482 #if MICROPY_EMIT_NATIVE 3483 if (emit_native !=
NULL) {
3484 NATIVE_EMITTER(
free)(emit_native);
3487 #if MICROPY_EMIT_INLINE_ASM 3488 if (comp->emit_inline_asm !=
NULL) {
3489 ASM_EMITTER(
free)(comp->emit_inline_asm);
3498 for (
scope_t *s = module_scope; s;) {
3507 return outer_raw_code;
3512 mp_raw_code_t *rc = mp_compile_to_raw_code(parse_tree, source_file, emit_opt, is_repl);
3517 #endif // MICROPY_ENABLE_COMPILER
bool mp_parse_node_is_const_true(mp_parse_node_t pn)
#define MICROPY_COMP_DOUBLE_TUPLE_ASSIGN
bool mp_parse_node_is_const_false(mp_parse_node_t pn)
void mp_emit_common_id_op(emit_t *emit, const mp_emit_method_table_id_ops_t *emit_method_table, scope_t *scope, qstr qst)
id_info_t * scope_find_global(scope_t *scope, qstr qstr)
#define MICROPY_ERROR_REPORTING_TERSE
#define MP_SCOPE_FLAG_VARKEYWORDS
#define MP_PARSE_NODE_STRUCT_KIND(pns)
STATIC const uint8_t attr[]
#define MP_PARSE_NODE_LEAF_KIND(pn)
#define MP_PARSE_NODE_LEAF_SMALL_INT(pn)
#define MP_PARSE_NODE_IS_SMALL_INT(pn)
#define MICROPY_EMIT_NATIVE
#define MP_SCOPE_FLAG_VARARGS
void emit_bc_free(emit_t *emit)
LIBA_BEGIN_DECLS void free(void *ptr)
#define MP_NATIVE_TYPE_OBJ
#define MP_SCOPE_FLAG_GENERATOR
#define MP_EMIT_STAR_FLAG_DOUBLE
mp_obj_t mp_obj_new_int_from_ll(long long val)
uintptr_t mp_parse_node_t
#define MP_PARSE_NODE_STRUCT_NUM_NODES(pns)
#define MP_EMIT_BREAK_FROM_FOR
enum _mp_token_kind_t mp_token_kind_t
const mp_obj_type_t mp_type_SyntaxError
void mp_asm_base_align(mp_asm_base_t *as, unsigned int align)
emit_t * emit_bc_new(void)
#define MICROPY_PY_BUILTINS_SET
#define MP_EMIT_NATIVE_TYPE_ARG
mp_obj_t mp_obj_new_exception_msg(const mp_obj_type_t *exc_type, const char *msg)
id_info_t * scope_find(scope_t *scope, qstr qstr)
void mp_asm_base_data(mp_asm_base_t *as, unsigned int bytesize, uintptr_t val)
#define MP_EMIT_NATIVE_TYPE_RETURN
void mp_emit_glue_assign_native(mp_raw_code_t *rc, mp_raw_code_kind_t kind, void *fun_data, mp_uint_t fun_len, const mp_uint_t *const_table, mp_uint_t n_pos_args, mp_uint_t scope_flags, mp_uint_t type_sig)
#define MP_PARSE_NODE_IS_ID(pn)
#define MICROPY_ERROR_REPORTING
#define MP_PARSE_NODE_BYTES
#define MP_PARSE_NODE_IS_TOKEN_KIND(pn, k)
#define MP_PARSE_NODE_IS_STRUCT_KIND(pn, k)
#define MP_PARSE_NODE_IS_TOKEN(pn)
mp_obj_t mp_compile(mp_parse_tree_t *parse_tree, qstr source_file, uint emit_opt, bool is_repl)
int mp_parse_node_extract_list(mp_parse_node_t *pn, size_t pn_kind, mp_parse_node_t **nodes)
const mp_emit_method_table_id_ops_t mp_emit_bc_method_table_delete_id_ops
#define MP_PARSE_NODE_STRING
#define MP_PARSE_NODE_TOKEN
unsigned long long uint64_t
void mp_emit_common_get_id_for_load(scope_t *scope, qstr qst)
#define MP_EMIT_NATIVE_TYPE_ENABLE
mp_obj_t mp_obj_new_bytes(const byte *data, size_t len)
mp_obj_t mp_make_function_from_raw_code(const mp_raw_code_t *rc, mp_obj_t def_args, mp_obj_t def_kw_args)
id_info_t * scope_find_or_add_id(scope_t *scope, qstr qstr, bool *added)
#define MP_NATIVE_TYPE_UINT
void scope_free(scope_t *scope)
#define MICROPY_COMP_RETURN_IF_EXPR
scope_t * scope_new(scope_kind_t kind, mp_parse_node_t pn, qstr source_file, mp_uint_t emit_options)
void mp_emit_common_get_id_for_modification(scope_t *scope, qstr qst)
void mp_obj_exception_add_traceback(mp_obj_t self_in, qstr file, size_t line, qstr block)
#define MP_NATIVE_TYPE_BOOL
const byte * qstr_data(qstr q, size_t *len)
const mp_emit_method_table_id_ops_t mp_emit_bc_method_table_store_id_ops
#define MP_PARSE_NODE_LEAF_ARG(pn)
const mp_emit_method_table_id_ops_t mp_emit_bc_method_table_load_id_ops
#define SCOPE_IS_FUNC_LIKE(s)
byte * qstr_build_start(size_t len, byte **q_ptr)
void scope_find_local_and_close_over(scope_t *scope, id_info_t *id, qstr qst)
qstr qstr_build_end(byte *q_ptr)
#define MP_PARSE_NODE_IS_STRUCT(pn)
#define MP_EMIT_STAR_FLAG_SINGLE
const emit_method_table_t emit_bc_method_table
#define MICROPY_COMP_TRIPLE_TUPLE_ASSIGN
#define MP_PARSE_NODE_IS_LEAF(pn)
#define MP_PARSE_NODE_IS_NULL(pn)
void emit_bc_set_max_num_labels(emit_t *emit, mp_uint_t max_num_labels)
void mp_parse_tree_clear(mp_parse_tree_t *tree)
#define MP_SCOPE_FLAG_DEFKWARGS
uint16_t num_def_pos_args
#define MP_NATIVE_TYPE_INT
void * memcpy(void *dst, const void *src, size_t n)
#define MP_PARSE_NODE_NULL
struct _emit_inline_asm_t emit_inline_asm_t