Browse Source

py: Move mp_native_type_from_qstr() from emitnative.c to nativeglue.c.

pull/4588/head
Damien George 6 years ago
parent
commit
3b973a5658
  1. 2
      py/emit.h
  2. 14
      py/emitnative.c
  3. 14
      py/nativeglue.c
  4. 1
      py/runtime.h

2
py/emit.h

@ -156,8 +156,6 @@ typedef struct _emit_method_table_t {
void (*end_except_handler)(emit_t *emit);
} emit_method_table_t;
int mp_native_type_from_qstr(qstr qst);
static inline void mp_emit_common_get_id_for_load(scope_t *scope, qstr qst) {
scope_find_or_add_id(scope, qst, ID_INFO_KIND_GLOBAL_IMPLICIT);
}

14
py/emitnative.c

@ -136,20 +136,6 @@ typedef enum {
VTYPE_BUILTIN_CAST = 0x70 | MP_NATIVE_TYPE_OBJ,
} vtype_kind_t;
int mp_native_type_from_qstr(qstr qst) {
switch (qst) {
case MP_QSTR_object: return MP_NATIVE_TYPE_OBJ;
case MP_QSTR_bool: return MP_NATIVE_TYPE_BOOL;
case MP_QSTR_int: return MP_NATIVE_TYPE_INT;
case MP_QSTR_uint: return MP_NATIVE_TYPE_UINT;
case MP_QSTR_ptr: return MP_NATIVE_TYPE_PTR;
case MP_QSTR_ptr8: return MP_NATIVE_TYPE_PTR8;
case MP_QSTR_ptr16: return MP_NATIVE_TYPE_PTR16;
case MP_QSTR_ptr32: return MP_NATIVE_TYPE_PTR32;
default: return -1;
}
}
STATIC qstr vtype_to_qstr(vtype_kind_t vtype) {
switch (vtype) {
case VTYPE_PYOBJ: return MP_QSTR_object;

14
py/nativeglue.c

@ -41,6 +41,20 @@
#if MICROPY_EMIT_NATIVE
int mp_native_type_from_qstr(qstr qst) {
switch (qst) {
case MP_QSTR_object: return MP_NATIVE_TYPE_OBJ;
case MP_QSTR_bool: return MP_NATIVE_TYPE_BOOL;
case MP_QSTR_int: return MP_NATIVE_TYPE_INT;
case MP_QSTR_uint: return MP_NATIVE_TYPE_UINT;
case MP_QSTR_ptr: return MP_NATIVE_TYPE_PTR;
case MP_QSTR_ptr8: return MP_NATIVE_TYPE_PTR8;
case MP_QSTR_ptr16: return MP_NATIVE_TYPE_PTR16;
case MP_QSTR_ptr32: return MP_NATIVE_TYPE_PTR32;
default: return -1;
}
}
// convert a MicroPython object to a valid native value based on type
mp_uint_t mp_convert_obj_to_native(mp_obj_t obj, mp_uint_t type) {
DEBUG_printf("mp_convert_obj_to_native(%p, " UINT_FMT ")\n", obj, type);

1
py/runtime.h

@ -169,6 +169,7 @@ NORETURN void mp_raise_recursion_depth(void);
#endif
// helper functions for native/viper code
int mp_native_type_from_qstr(qstr qst);
mp_uint_t mp_convert_obj_to_native(mp_obj_t obj, mp_uint_t type);
mp_obj_t mp_convert_native_to_obj(mp_uint_t val, mp_uint_t type);
mp_obj_dict_t *mp_native_swap_globals(mp_obj_dict_t *new_globals);

Loading…
Cancel
Save