py/emitnative: Reuse mp_native_type_from_qstr when searching for a cast.

This commit is contained in:
Damien George 2018-09-15 13:50:04 +10:00
parent 9f2067288a
commit 460954734e

View File

@ -1189,23 +1189,9 @@ STATIC void emit_native_load_global(emit_t *emit, qstr qst, int kind) {
DEBUG_printf("load_global(%s)\n", qstr_str(qst)); DEBUG_printf("load_global(%s)\n", qstr_str(qst));
if (emit->do_viper_types) { if (emit->do_viper_types) {
// check for builtin casting operators // check for builtin casting operators
if (qst == MP_QSTR_int) { int native_type = mp_native_type_from_qstr(qst);
emit_post_push_imm(emit, VTYPE_BUILTIN_CAST, VTYPE_INT); if (native_type >= MP_NATIVE_TYPE_INT) {
return; emit_post_push_imm(emit, VTYPE_BUILTIN_CAST, native_type);
} else if (qst == MP_QSTR_uint) {
emit_post_push_imm(emit, VTYPE_BUILTIN_CAST, VTYPE_UINT);
return;
} else if (qst == MP_QSTR_ptr) {
emit_post_push_imm(emit, VTYPE_BUILTIN_CAST, VTYPE_PTR);
return;
} else if (qst == MP_QSTR_ptr8) {
emit_post_push_imm(emit, VTYPE_BUILTIN_CAST, VTYPE_PTR8);
return;
} else if (qst == MP_QSTR_ptr16) {
emit_post_push_imm(emit, VTYPE_BUILTIN_CAST, VTYPE_PTR16);
return;
} else if (qst == MP_QSTR_ptr32) {
emit_post_push_imm(emit, VTYPE_BUILTIN_CAST, VTYPE_PTR32);
return; return;
} }
} }