aboutsummaryrefslogtreecommitdiff
path: root/py/emitnative.c
diff options
context:
space:
mode:
authorDamien George <damien.p.george@gmail.com>2018-10-14 23:06:09 +1100
committerDamien George <damien.p.george@gmail.com>2018-10-15 00:20:49 +1100
commit7c16bc0406044c3ecb978a03894d1a59bd4bd0d2 (patch)
tree8588b9ae6b3dea3c200944e32b35490c46545bfb /py/emitnative.c
parent175739cd377948c4ac6810ab2fef7b1cd3cfe2e0 (diff)
py/emitnative: Simplify viper mode handling in emit_native_import_name.
Diffstat (limited to 'py/emitnative.c')
-rw-r--r--py/emitnative.c36
1 files changed, 10 insertions, 26 deletions
diff --git a/py/emitnative.c b/py/emitnative.c
index ca6ff8ee9..459290bef 100644
--- a/py/emitnative.c
+++ b/py/emitnative.c
@@ -1170,32 +1170,16 @@ STATIC void emit_native_import_name(emit_t *emit, qstr qst) {
DEBUG_printf("import_name %s\n", qstr_str(qst));
// get arguments from stack: arg2 = fromlist, arg3 = level
- // if using viper types these arguments must be converted to proper objects
- if (emit->do_viper_types) {
- // fromlist should be None or a tuple
- stack_info_t *top = peek_stack(emit, 0);
- if (top->vtype == VTYPE_PTR_NONE) {
- emit_pre_pop_discard(emit);
- ASM_MOV_REG_IMM(emit->as, REG_ARG_2, (mp_uint_t)mp_const_none);
- } else {
- vtype_kind_t vtype_fromlist;
- emit_pre_pop_reg(emit, &vtype_fromlist, REG_ARG_2);
- assert(vtype_fromlist == VTYPE_PYOBJ);
- }
-
- // level argument should be an immediate integer
- top = peek_stack(emit, 0);
- assert(top->vtype == VTYPE_INT && top->kind == STACK_IMM);
- ASM_MOV_REG_IMM(emit->as, REG_ARG_3, (mp_uint_t)MP_OBJ_NEW_SMALL_INT(top->data.u_imm));
- emit_pre_pop_discard(emit);
-
- } else {
- vtype_kind_t vtype_fromlist;
- vtype_kind_t vtype_level;
- emit_pre_pop_reg_reg(emit, &vtype_fromlist, REG_ARG_2, &vtype_level, REG_ARG_3);
- assert(vtype_fromlist == VTYPE_PYOBJ);
- assert(vtype_level == VTYPE_PYOBJ);
- }
+ // If using viper types these arguments must be converted to proper objects, and
+ // to accomplish this viper types are turned off for the emit_pre_pop_reg_reg call.
+ bool orig_do_viper_types = emit->do_viper_types;
+ emit->do_viper_types = false;
+ vtype_kind_t vtype_fromlist;
+ vtype_kind_t vtype_level;
+ emit_pre_pop_reg_reg(emit, &vtype_fromlist, REG_ARG_2, &vtype_level, REG_ARG_3);
+ assert(vtype_fromlist == VTYPE_PYOBJ);
+ assert(vtype_level == VTYPE_PYOBJ);
+ emit->do_viper_types = orig_do_viper_types;
emit_call_with_imm_arg(emit, MP_F_IMPORT_NAME, qst, REG_ARG_1); // arg1 = import name
emit_post_push_reg(emit, VTYPE_PYOBJ, REG_RET);