py/emitnative: Simplify viper mode handling in emit_native_import_name.

This commit is contained in:
Damien George 2018-10-14 23:06:09 +11:00
parent 175739cd37
commit 7c16bc0406
1 changed files with 10 additions and 26 deletions

View File

@ -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);