summaryrefslogtreecommitdiffstatshomepage
diff options
context:
space:
mode:
authorDamien George <damien.p.george@gmail.com>2018-09-15 13:50:04 +1000
committerDamien George <damien.p.george@gmail.com>2018-09-15 13:52:58 +1000
commit460954734e12074d29056b446d1406a27e2aed9f (patch)
tree4bd1345096a1c81cdc6e65a933b52891bdd8bc4f
parent9f2067288ac7413c4bb2b47d4f5c660fa0b23d5c (diff)
downloadmicropython-460954734e12074d29056b446d1406a27e2aed9f.tar.gz
micropython-460954734e12074d29056b446d1406a27e2aed9f.zip
py/emitnative: Reuse mp_native_type_from_qstr when searching for a cast.
-rw-r--r--py/emitnative.c20
1 files changed, 3 insertions, 17 deletions
diff --git a/py/emitnative.c b/py/emitnative.c
index 84b7f44688..c95ef889b6 100644
--- a/py/emitnative.c
+++ b/py/emitnative.c
@@ -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));
if (emit->do_viper_types) {
// check for builtin casting operators
- if (qst == MP_QSTR_int) {
- emit_post_push_imm(emit, VTYPE_BUILTIN_CAST, VTYPE_INT);
- return;
- } 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);
+ int native_type = mp_native_type_from_qstr(qst);
+ if (native_type >= MP_NATIVE_TYPE_INT) {
+ emit_post_push_imm(emit, VTYPE_BUILTIN_CAST, native_type);
return;
}
}