summaryrefslogtreecommitdiffstatshomepage
path: root/py/emitbc.c
diff options
context:
space:
mode:
Diffstat (limited to 'py/emitbc.c')
-rw-r--r--py/emitbc.c49
1 files changed, 11 insertions, 38 deletions
diff --git a/py/emitbc.c b/py/emitbc.c
index d7b309a37f..f58cec1f1f 100644
--- a/py/emitbc.c
+++ b/py/emitbc.c
@@ -16,6 +16,8 @@
#include "emit.h"
#include "bc0.h"
+#if !MICROPY_EMIT_CPYTHON
+
struct _emit_t {
pass_kind_t pass;
int stack_size;
@@ -421,11 +423,6 @@ STATIC void emit_bc_load_const_str(emit_t *emit, qstr qstr, bool bytes) {
}
}
-STATIC void emit_bc_load_const_verbatim_str(emit_t *emit, const char *str) {
- // not needed/supported for BC
- assert(0);
-}
-
STATIC void emit_bc_load_null(emit_t *emit) {
emit_bc_pre(emit, 1);
emit_write_byte_code_byte(emit, MP_BC_LOAD_NULL);
@@ -447,11 +444,6 @@ STATIC void emit_bc_load_deref(emit_t *emit, qstr qstr, int local_num) {
emit_write_byte_code_byte_uint(emit, MP_BC_LOAD_DEREF, local_num);
}
-STATIC void emit_bc_load_closure(emit_t *emit, qstr qstr, int local_num) {
- // not needed/supported for BC
- assert(0);
-}
-
STATIC void emit_bc_load_name(emit_t *emit, qstr qstr) {
emit_bc_pre(emit, 1);
emit_write_byte_code_byte_qstr(emit, MP_BC_LOAD_NAME, qstr);
@@ -598,11 +590,6 @@ STATIC void emit_bc_jump_if_false_or_pop(emit_t *emit, uint label) {
emit_write_byte_code_byte_signed_label(emit, MP_BC_JUMP_IF_FALSE_OR_POP, label);
}
-STATIC void emit_bc_setup_loop(emit_t *emit, uint label) {
- emit_bc_pre(emit, 0);
- emit_write_byte_code_byte_unsigned_label(emit, MP_BC_SETUP_LOOP, label);
-}
-
STATIC void emit_bc_unwind_jump(emit_t *emit, uint label, int except_depth) {
if (except_depth == 0) {
emit_bc_jump(emit, label);
@@ -761,35 +748,21 @@ STATIC void emit_bc_make_function(emit_t *emit, scope_t *scope, uint n_pos_defau
emit_bc_pre(emit, 1);
emit_write_byte_code_byte_ptr(emit, MP_BC_MAKE_FUNCTION, scope->raw_code);
} else {
- if (n_pos_defaults == 0) {
- // load dummy entry for non-existent positional default tuple
- emit_bc_load_null(emit);
- emit_bc_rot_two(emit);
- } else if (n_kw_defaults == 0) {
- // load dummy entry for non-existent keyword default dict
- emit_bc_load_null(emit);
- }
emit_bc_pre(emit, -1);
emit_write_byte_code_byte_ptr(emit, MP_BC_MAKE_FUNCTION_DEFARGS, scope->raw_code);
}
}
-STATIC void emit_bc_make_closure(emit_t *emit, scope_t *scope, uint n_pos_defaults, uint n_kw_defaults) {
+STATIC void emit_bc_make_closure(emit_t *emit, scope_t *scope, uint n_closed_over, uint n_pos_defaults, uint n_kw_defaults) {
if (n_pos_defaults == 0 && n_kw_defaults == 0) {
- emit_bc_pre(emit, 0);
+ emit_bc_pre(emit, -n_closed_over + 1);
emit_write_byte_code_byte_ptr(emit, MP_BC_MAKE_CLOSURE, scope->raw_code);
+ emit_write_byte_code_byte(emit, n_closed_over);
} else {
- if (n_pos_defaults == 0) {
- // load dummy entry for non-existent positional default tuple
- emit_bc_load_null(emit);
- emit_bc_rot_three(emit);
- } else if (n_kw_defaults == 0) {
- // load dummy entry for non-existent keyword default dict
- emit_bc_load_null(emit);
- emit_bc_rot_two(emit);
- }
- emit_bc_pre(emit, -2);
+ assert(n_closed_over <= 255);
+ emit_bc_pre(emit, -2 - n_closed_over + 1);
emit_write_byte_code_byte_ptr(emit, MP_BC_MAKE_CLOSURE_DEFARGS, scope->raw_code);
+ emit_write_byte_code_byte(emit, n_closed_over);
}
}
@@ -869,10 +842,9 @@ const emit_method_table_t emit_bc_method_table = {
emit_bc_load_const_dec,
emit_bc_load_const_id,
emit_bc_load_const_str,
- emit_bc_load_const_verbatim_str,
+ emit_bc_load_null,
emit_bc_load_fast,
emit_bc_load_deref,
- emit_bc_load_closure,
emit_bc_load_name,
emit_bc_load_global,
emit_bc_load_attr,
@@ -901,7 +873,6 @@ const emit_method_table_t emit_bc_method_table = {
emit_bc_pop_jump_if_false,
emit_bc_jump_if_true_or_pop,
emit_bc_jump_if_false_or_pop,
- emit_bc_setup_loop,
emit_bc_unwind_jump,
emit_bc_unwind_jump,
emit_bc_setup_with,
@@ -936,3 +907,5 @@ const emit_method_table_t emit_bc_method_table = {
emit_bc_yield_value,
emit_bc_yield_from,
};
+
+#endif // !MICROPY_EMIT_CPYTHON