summaryrefslogtreecommitdiffstatshomepage
diff options
context:
space:
mode:
-rw-r--r--py/compile.c22
-rw-r--r--py/emit.h6
-rw-r--r--py/emitbc.c32
-rw-r--r--py/emitcpy.c36
-rw-r--r--py/emitnative.c41
-rw-r--r--py/emitpass1.c2
6 files changed, 53 insertions, 86 deletions
diff --git a/py/compile.c b/py/compile.c
index 7b46a4c42b..7245ff0a34 100644
--- a/py/compile.c
+++ b/py/compile.c
@@ -639,11 +639,7 @@ STATIC void cpython_c_if_cond(compiler_t *comp, mp_parse_node_t pn, bool jump_if
// nothing special, fall back to default compiling for node and jump
compile_node(comp, pn);
- if (jump_if == false) {
- EMIT_ARG(pop_jump_if_false, label);
- } else {
- EMIT_ARG(pop_jump_if_true, label);
- }
+ EMIT_ARG(pop_jump_if, jump_if, label);
}
#endif
@@ -711,11 +707,7 @@ STATIC void c_if_cond(compiler_t *comp, mp_parse_node_t pn, bool jump_if, int la
// nothing special, fall back to default compiling for node and jump
compile_node(comp, pn);
- if (jump_if == false) {
- EMIT_ARG(pop_jump_if_false, label);
- } else {
- EMIT_ARG(pop_jump_if_true, label);
- }
+ EMIT_ARG(pop_jump_if, jump_if, label);
#endif
}
@@ -1825,7 +1817,7 @@ STATIC void compile_for_stmt_optimised_range(compiler_t *comp, mp_parse_node_t p
} else {
EMIT_ARG(binary_op, MP_BINARY_OP_MORE);
}
- EMIT_ARG(pop_jump_if_true, top_label);
+ EMIT_ARG(pop_jump_if, true, top_label);
// break/continue apply to outer loop (if any) in the else block
END_BREAK_CONTINUE_BLOCK
@@ -1971,7 +1963,7 @@ STATIC void compile_try_except(compiler_t *comp, mp_parse_node_t pn_body, int n_
EMIT(dup_top);
compile_node(comp, pns_exception_expr);
EMIT_ARG(binary_op, MP_BINARY_OP_EXCEPTION_MATCH);
- EMIT_ARG(pop_jump_if_false, end_finally_label);
+ EMIT_ARG(pop_jump_if, false, end_finally_label);
}
EMIT(pop_top);
@@ -2267,7 +2259,7 @@ STATIC void compile_or_test(compiler_t *comp, mp_parse_node_struct_t *pns) {
for (int i = 0; i < n; i += 1) {
compile_node(comp, pns->nodes[i]);
if (i + 1 < n) {
- EMIT_ARG(jump_if_true_or_pop, l_end);
+ EMIT_ARG(jump_if_or_pop, true, l_end);
}
}
EMIT_ARG(label_assign, l_end);
@@ -2279,7 +2271,7 @@ STATIC void compile_and_test(compiler_t *comp, mp_parse_node_struct_t *pns) {
for (int i = 0; i < n; i += 1) {
compile_node(comp, pns->nodes[i]);
if (i + 1 < n) {
- EMIT_ARG(jump_if_false_or_pop, l_end);
+ EMIT_ARG(jump_if_or_pop, false, l_end);
}
}
EMIT_ARG(label_assign, l_end);
@@ -2332,7 +2324,7 @@ STATIC void compile_comparison(compiler_t *comp, mp_parse_node_struct_t *pns) {
}
}
if (i + 2 < num_nodes) {
- EMIT_ARG(jump_if_false_or_pop, l_fail);
+ EMIT_ARG(jump_if_or_pop, false, l_fail);
}
}
if (multi) {
diff --git a/py/emit.h b/py/emit.h
index 47ea4ec8c8..ea8c3a655a 100644
--- a/py/emit.h
+++ b/py/emit.h
@@ -106,10 +106,8 @@ typedef struct _emit_method_table_t {
void (*rot_two)(emit_t *emit);
void (*rot_three)(emit_t *emit);
void (*jump)(emit_t *emit, mp_uint_t label);
- void (*pop_jump_if_true)(emit_t *emit, mp_uint_t label);
- void (*pop_jump_if_false)(emit_t *emit, mp_uint_t label);
- void (*jump_if_true_or_pop)(emit_t *emit, mp_uint_t label);
- void (*jump_if_false_or_pop)(emit_t *emit, mp_uint_t label);
+ void (*pop_jump_if)(emit_t *emit, bool cond, mp_uint_t label);
+ void (*jump_if_or_pop)(emit_t *emit, bool cond, mp_uint_t label);
void (*break_loop)(emit_t *emit, mp_uint_t label, mp_uint_t except_depth);
void (*continue_loop)(emit_t *emit, mp_uint_t label, mp_uint_t except_depth);
void (*setup_with)(emit_t *emit, mp_uint_t label);
diff --git a/py/emitbc.c b/py/emitbc.c
index 53cae59ee2..60da170fce 100644
--- a/py/emitbc.c
+++ b/py/emitbc.c
@@ -652,24 +652,22 @@ STATIC void emit_bc_jump(emit_t *emit, mp_uint_t label) {
emit_write_bytecode_byte_signed_label(emit, MP_BC_JUMP, label);
}
-STATIC void emit_bc_pop_jump_if_true(emit_t *emit, mp_uint_t label) {
+STATIC void emit_bc_pop_jump_if(emit_t *emit, bool cond, mp_uint_t label) {
emit_bc_pre(emit, -1);
- emit_write_bytecode_byte_signed_label(emit, MP_BC_POP_JUMP_IF_TRUE, label);
-}
-
-STATIC void emit_bc_pop_jump_if_false(emit_t *emit, mp_uint_t label) {
- emit_bc_pre(emit, -1);
- emit_write_bytecode_byte_signed_label(emit, MP_BC_POP_JUMP_IF_FALSE, label);
-}
-
-STATIC void emit_bc_jump_if_true_or_pop(emit_t *emit, mp_uint_t label) {
- emit_bc_pre(emit, -1);
- emit_write_bytecode_byte_signed_label(emit, MP_BC_JUMP_IF_TRUE_OR_POP, label);
+ if (cond) {
+ emit_write_bytecode_byte_signed_label(emit, MP_BC_POP_JUMP_IF_TRUE, label);
+ } else {
+ emit_write_bytecode_byte_signed_label(emit, MP_BC_POP_JUMP_IF_FALSE, label);
+ }
}
-STATIC void emit_bc_jump_if_false_or_pop(emit_t *emit, mp_uint_t label) {
+STATIC void emit_bc_jump_if_or_pop(emit_t *emit, bool cond, mp_uint_t label) {
emit_bc_pre(emit, -1);
- emit_write_bytecode_byte_signed_label(emit, MP_BC_JUMP_IF_FALSE_OR_POP, label);
+ if (cond) {
+ emit_write_bytecode_byte_signed_label(emit, MP_BC_JUMP_IF_TRUE_OR_POP, label);
+ } else {
+ emit_write_bytecode_byte_signed_label(emit, MP_BC_JUMP_IF_FALSE_OR_POP, label);
+ }
}
STATIC void emit_bc_unwind_jump(emit_t *emit, mp_uint_t label, mp_uint_t except_depth) {
@@ -951,10 +949,8 @@ const emit_method_table_t emit_bc_method_table = {
emit_bc_rot_two,
emit_bc_rot_three,
emit_bc_jump,
- emit_bc_pop_jump_if_true,
- emit_bc_pop_jump_if_false,
- emit_bc_jump_if_true_or_pop,
- emit_bc_jump_if_false_or_pop,
+ emit_bc_pop_jump_if,
+ emit_bc_jump_if_or_pop,
emit_bc_unwind_jump,
emit_bc_unwind_jump,
emit_bc_setup_with,
diff --git a/py/emitcpy.c b/py/emitcpy.c
index 355ed10517..be469f45d0 100644
--- a/py/emitcpy.c
+++ b/py/emitcpy.c
@@ -415,31 +415,25 @@ STATIC void emit_cpy_jump(emit_t *emit, mp_uint_t label) {
}
}
-STATIC void emit_cpy_pop_jump_if_true(emit_t *emit, mp_uint_t label) {
+STATIC void emit_cpy_pop_jump_if(emit_t *emit, bool cond, mp_uint_t label) {
emit_pre(emit, -1, 3);
if (emit->pass == MP_PASS_EMIT) {
- printf("POP_JUMP_IF_TRUE " UINT_FMT "\n", emit->label_offsets[label]);
- }
-}
-
-STATIC void emit_cpy_pop_jump_if_false(emit_t *emit, mp_uint_t label) {
- emit_pre(emit, -1, 3);
- if (emit->pass == MP_PASS_EMIT) {
- printf("POP_JUMP_IF_FALSE " UINT_FMT "\n", emit->label_offsets[label]);
- }
-}
-
-STATIC void emit_cpy_jump_if_true_or_pop(emit_t *emit, mp_uint_t label) {
- emit_pre(emit, -1, 3);
- if (emit->pass == MP_PASS_EMIT) {
- printf("JUMP_IF_TRUE_OR_POP " UINT_FMT "\n", emit->label_offsets[label]);
+ if (cond) {
+ printf("POP_JUMP_IF_TRUE " UINT_FMT "\n", emit->label_offsets[label]);
+ } else {
+ printf("POP_JUMP_IF_FALSE " UINT_FMT "\n", emit->label_offsets[label]);
+ }
}
}
-STATIC void emit_cpy_jump_if_false_or_pop(emit_t *emit, mp_uint_t label) {
+STATIC void emit_cpy_jump_if_or_pop(emit_t *emit, bool cond, mp_uint_t label) {
emit_pre(emit, -1, 3);
if (emit->pass == MP_PASS_EMIT) {
- printf("JUMP_IF_FALSE_OR_POP " UINT_FMT "\n", emit->label_offsets[label]);
+ if (cond) {
+ printf("JUMP_IF_TRUE_OR_POP " UINT_FMT "\n", emit->label_offsets[label]);
+ } else {
+ printf("JUMP_IF_FALSE_OR_POP " UINT_FMT "\n", emit->label_offsets[label]);
+ }
}
}
@@ -854,10 +848,8 @@ const emit_method_table_t emit_cpython_method_table = {
emit_cpy_rot_two,
emit_cpy_rot_three,
emit_cpy_jump,
- emit_cpy_pop_jump_if_true,
- emit_cpy_pop_jump_if_false,
- emit_cpy_jump_if_true_or_pop,
- emit_cpy_jump_if_false_or_pop,
+ emit_cpy_pop_jump_if,
+ emit_cpy_jump_if_or_pop,
emit_cpy_break_loop,
emit_cpy_continue_loop,
emit_cpy_setup_with,
diff --git a/py/emitnative.c b/py/emitnative.c
index dae3d6c1e5..dcf6822ffc 100644
--- a/py/emitnative.c
+++ b/py/emitnative.c
@@ -1744,32 +1744,25 @@ STATIC void emit_native_jump_helper(emit_t *emit, bool pop) {
need_stack_settled(emit);
}
-STATIC void emit_native_pop_jump_if_true(emit_t *emit, mp_uint_t label) {
- DEBUG_printf("pop_jump_if_true(label=" UINT_FMT ")\n", label);
+STATIC void emit_native_pop_jump_if(emit_t *emit, bool cond, mp_uint_t label) {
+ DEBUG_printf("pop_jump_if(cond=%u, label=" UINT_FMT ")\n", cond, label);
emit_native_jump_helper(emit, true);
- ASM_JUMP_IF_REG_NONZERO(emit->as, REG_RET, label);
- emit_post(emit);
-}
-
-STATIC void emit_native_pop_jump_if_false(emit_t *emit, mp_uint_t label) {
- DEBUG_printf("pop_jump_if_false(label=" UINT_FMT ")\n", label);
- emit_native_jump_helper(emit, true);
- ASM_JUMP_IF_REG_ZERO(emit->as, REG_RET, label);
- emit_post(emit);
-}
-
-STATIC void emit_native_jump_if_true_or_pop(emit_t *emit, mp_uint_t label) {
- DEBUG_printf("jump_if_true_or_pop(label=" UINT_FMT ")\n", label);
- emit_native_jump_helper(emit, false);
- ASM_JUMP_IF_REG_NONZERO(emit->as, REG_RET, label);
- adjust_stack(emit, -1);
+ if (cond) {
+ ASM_JUMP_IF_REG_NONZERO(emit->as, REG_RET, label);
+ } else {
+ ASM_JUMP_IF_REG_ZERO(emit->as, REG_RET, label);
+ }
emit_post(emit);
}
-STATIC void emit_native_jump_if_false_or_pop(emit_t *emit, mp_uint_t label) {
- DEBUG_printf("jump_if_false_or_pop(label=" UINT_FMT ")\n", label);
+STATIC void emit_native_jump_if_or_pop(emit_t *emit, bool cond, mp_uint_t label) {
+ DEBUG_printf("jump_if_or_pop(cond=%u, label=" UINT_FMT ")\n", cond, label);
emit_native_jump_helper(emit, false);
- ASM_JUMP_IF_REG_ZERO(emit->as, REG_RET, label);
+ if (cond) {
+ ASM_JUMP_IF_REG_NONZERO(emit->as, REG_RET, label);
+ } else {
+ ASM_JUMP_IF_REG_ZERO(emit->as, REG_RET, label);
+ }
adjust_stack(emit, -1);
emit_post(emit);
}
@@ -2329,10 +2322,8 @@ const emit_method_table_t EXPORT_FUN(method_table) = {
emit_native_rot_two,
emit_native_rot_three,
emit_native_jump,
- emit_native_pop_jump_if_true,
- emit_native_pop_jump_if_false,
- emit_native_jump_if_true_or_pop,
- emit_native_jump_if_false_or_pop,
+ emit_native_pop_jump_if,
+ emit_native_jump_if_or_pop,
emit_native_break_loop,
emit_native_continue_loop,
emit_native_setup_with,
diff --git a/py/emitpass1.c b/py/emitpass1.c
index b5e5f8e7aa..b31973b7df 100644
--- a/py/emitpass1.c
+++ b/py/emitpass1.c
@@ -190,8 +190,6 @@ const emit_method_table_t emit_pass1_method_table = {
(void*)emit_pass1_dummy,
(void*)emit_pass1_dummy,
(void*)emit_pass1_dummy,
- (void*)emit_pass1_dummy,
- (void*)emit_pass1_dummy,
#if MICROPY_PY_BUILTINS_SET
(void*)emit_pass1_dummy,
(void*)emit_pass1_dummy,