diff options
Diffstat (limited to 'py/emitcpy.c')
-rw-r--r-- | py/emitcpy.c | 55 |
1 files changed, 32 insertions, 23 deletions
diff --git a/py/emitcpy.c b/py/emitcpy.c index 119cf818cf..a041c4f1e0 100644 --- a/py/emitcpy.c +++ b/py/emitcpy.c @@ -221,11 +221,9 @@ STATIC void emit_cpy_load_const_str(emit_t *emit, qstr qstr, bool bytes) { } } -STATIC void emit_cpy_load_const_verbatim_str(emit_t *emit, const char *str) { - emit_pre(emit, 1, 3); - if (emit->pass == PASS_3) { - printf("LOAD_CONST %s\n", str); - } +STATIC void emit_cpy_load_null(emit_t *emit) { + // unused for cpy + assert(0); } STATIC void emit_cpy_load_fast(emit_t *emit, qstr qstr, uint id_flags, int local_num) { @@ -242,13 +240,6 @@ STATIC void emit_cpy_load_deref(emit_t *emit, qstr qstr, int local_num) { } } -STATIC void emit_cpy_load_closure(emit_t *emit, qstr qstr, int local_num) { - emit_pre(emit, 1, 3); - if (emit->pass == PASS_3) { - printf("LOAD_CLOSURE %d %s\n", local_num, qstr_str(qstr)); - } -} - STATIC void emit_cpy_load_name(emit_t *emit, qstr qstr) { emit_pre(emit, 1, 3); if (emit->pass == PASS_3) { @@ -447,13 +438,6 @@ STATIC void emit_cpy_jump_if_false_or_pop(emit_t *emit, uint label) { } } -STATIC void emit_cpy_setup_loop(emit_t *emit, uint label) { - emit_pre(emit, 0, 3); - if (emit->pass == PASS_3) { - printf("SETUP_LOOP %d\n", emit->label_offsets[label]); - } -} - STATIC void emit_cpy_break_loop(emit_t *emit, uint label, int except_depth) { emit_pre(emit, 0, 1); if (emit->pass == PASS_3) { @@ -764,7 +748,8 @@ STATIC void emit_cpy_make_function(emit_t *emit, scope_t *scope, uint n_pos_defa } } -STATIC void emit_cpy_make_closure(emit_t *emit, scope_t *scope, uint n_pos_defaults, uint n_kw_defaults) { +STATIC void emit_cpy_make_closure(emit_t *emit, scope_t *scope, uint n_closed_over, uint n_pos_defaults, uint n_kw_defaults) { + emit_cpy_build_tuple(emit, n_closed_over); load_cpy_const_code_and_name(emit, scope->simple_name); emit_pre(emit, -2 - n_pos_defaults - 2 * n_kw_defaults, 3); if (emit->pass == PASS_3) { @@ -792,6 +777,27 @@ STATIC void emit_cpy_yield_from(emit_t *emit) { } } +STATIC void emit_cpy_load_const_verbatim_str(emit_t *emit, const char *str) { + emit_pre(emit, 1, 3); + if (emit->pass == PASS_3) { + printf("LOAD_CONST %s\n", str); + } +} + +STATIC void emit_cpy_load_closure(emit_t *emit, qstr qstr, int local_num) { + emit_pre(emit, 1, 3); + if (emit->pass == PASS_3) { + printf("LOAD_CLOSURE %d %s\n", local_num, qstr_str(qstr)); + } +} + +STATIC void emit_cpy_setup_loop(emit_t *emit, uint label) { + emit_pre(emit, 0, 3); + if (emit->pass == PASS_3) { + printf("SETUP_LOOP %d\n", emit->label_offsets[label]); + } +} + const emit_method_table_t emit_cpython_method_table = { emit_cpy_set_native_types, emit_cpy_start_pass, @@ -814,10 +820,9 @@ const emit_method_table_t emit_cpython_method_table = { emit_cpy_load_const_dec, emit_cpy_load_const_id, emit_cpy_load_const_str, - emit_cpy_load_const_verbatim_str, + emit_cpy_load_null, emit_cpy_load_fast, emit_cpy_load_deref, - emit_cpy_load_closure, emit_cpy_load_name, emit_cpy_load_global, emit_cpy_load_attr, @@ -846,7 +851,6 @@ const emit_method_table_t emit_cpython_method_table = { emit_cpy_pop_jump_if_false, emit_cpy_jump_if_true_or_pop, emit_cpy_jump_if_false_or_pop, - emit_cpy_setup_loop, emit_cpy_break_loop, emit_cpy_continue_loop, emit_cpy_setup_with, @@ -880,6 +884,11 @@ const emit_method_table_t emit_cpython_method_table = { emit_cpy_raise_varargs, emit_cpy_yield_value, emit_cpy_yield_from, + + // emitcpy specific functions + emit_cpy_load_const_verbatim_str, + emit_cpy_load_closure, + emit_cpy_setup_loop, }; #endif // MICROPY_EMIT_CPYTHON |