From 3e1a5c10c5bf0a38c2ed3b9986b43b8cb8227b2f Mon Sep 17 00:00:00 2001 From: Damien George Date: Sat, 29 Mar 2014 13:43:38 +0000 Subject: [PATCH] py: Rename old const type objects to mp_type_* for consistency. --- py/builtin.c | 4 +-- py/builtintables.c | 22 ++++++------- py/obj.c | 16 ++++----- py/obj.h | 78 ++++++++++++++++---------------------------- py/objdict.c | 28 ++++++++-------- py/objenumerate.c | 6 ++-- py/objfilter.c | 6 ++-- py/objfun.c | 22 ++++++------- py/objgenerator.c | 10 +++--- py/objint.c | 2 +- py/objint_longlong.c | 8 ++--- py/objint_mpz.c | 6 ++-- py/objlist.c | 42 ++++++++++++------------ py/objmap.c | 6 ++-- py/objset.c | 52 ++++++++++++++--------------- py/objslice.c | 6 ++-- py/objstr.c | 48 +++++++++++++-------------- py/objtuple.c | 6 ++-- py/objtype.c | 12 +++---- py/objzip.c | 6 ++-- py/runtime.c | 8 ++--- stmhal/help.c | 2 +- stmhal/i2c.c | 2 +- stmhal/modos.c | 8 ++--- unix/ffi.c | 2 +- unix/mpconfigport.mk | 2 +- unix/socket.c | 4 +-- 27 files changed, 197 insertions(+), 217 deletions(-) diff --git a/py/builtin.c b/py/builtin.c index e8746c55c2..6d3fc9029f 100644 --- a/py/builtin.c +++ b/py/builtin.c @@ -166,7 +166,7 @@ STATIC mp_obj_t mp_builtin_dir(uint n_args, const mp_obj_t *args) { } else { type = mp_obj_get_type(args[0]); } - if (type->locals_dict != MP_OBJ_NULL && MP_OBJ_IS_TYPE(type->locals_dict, &dict_type)) { + if (type->locals_dict != MP_OBJ_NULL && MP_OBJ_IS_TYPE(type->locals_dict, &mp_type_dict)) { map = mp_obj_dict_get_map(type->locals_dict); } } @@ -375,7 +375,7 @@ STATIC mp_obj_t mp_builtin_sorted(uint n_args, const mp_obj_t *args, mp_map_t *k nlr_jump(mp_obj_new_exception_msg(&mp_type_TypeError, "must use keyword argument for key function")); } - mp_obj_t self = list_type.make_new((mp_obj_t)&list_type, 1, 0, args); + mp_obj_t self = mp_type_list.make_new((mp_obj_t)&mp_type_list, 1, 0, args); mp_obj_list_sort(1, &self, kwargs); return self; diff --git a/py/builtintables.c b/py/builtintables.c index ac9eed8d46..2cb9240bbf 100644 --- a/py/builtintables.c +++ b/py/builtintables.c @@ -26,26 +26,26 @@ STATIC const mp_builtin_elem_t builtin_object_table[] = { // built-in types { MP_QSTR_bool, (mp_obj_t)&mp_type_bool }, - { MP_QSTR_bytes, (mp_obj_t)&bytes_type }, + { MP_QSTR_bytes, (mp_obj_t)&mp_type_bytes }, #if MICROPY_ENABLE_FLOAT { MP_QSTR_complex, (mp_obj_t)&mp_type_complex }, #endif - { MP_QSTR_dict, (mp_obj_t)&dict_type }, - { MP_QSTR_enumerate, (mp_obj_t)&enumerate_type }, - { MP_QSTR_filter, (mp_obj_t)&filter_type }, + { MP_QSTR_dict, (mp_obj_t)&mp_type_dict }, + { MP_QSTR_enumerate, (mp_obj_t)&mp_type_enumerate }, + { MP_QSTR_filter, (mp_obj_t)&mp_type_filter }, #if MICROPY_ENABLE_FLOAT { MP_QSTR_float, (mp_obj_t)&mp_type_float }, #endif - { MP_QSTR_int, (mp_obj_t)&int_type }, - { MP_QSTR_list, (mp_obj_t)&list_type }, - { MP_QSTR_map, (mp_obj_t)&map_type }, + { MP_QSTR_int, (mp_obj_t)&mp_type_int }, + { MP_QSTR_list, (mp_obj_t)&mp_type_list }, + { MP_QSTR_map, (mp_obj_t)&mp_type_map }, { MP_QSTR_object, (mp_obj_t)&mp_type_object }, - { MP_QSTR_set, (mp_obj_t)&set_type }, - { MP_QSTR_str, (mp_obj_t)&str_type }, - { MP_QSTR_super, (mp_obj_t)&super_type }, + { MP_QSTR_set, (mp_obj_t)&mp_type_set }, + { MP_QSTR_str, (mp_obj_t)&mp_type_str }, + { MP_QSTR_super, (mp_obj_t)&mp_type_super }, { MP_QSTR_tuple, (mp_obj_t)&mp_type_tuple }, { MP_QSTR_type, (mp_obj_t)&mp_type_type }, - { MP_QSTR_zip, (mp_obj_t)&zip_type }, + { MP_QSTR_zip, (mp_obj_t)&mp_type_zip }, { MP_QSTR_classmethod, (mp_obj_t)&mp_type_classmethod }, { MP_QSTR_staticmethod, (mp_obj_t)&mp_type_staticmethod }, diff --git a/py/obj.c b/py/obj.c index c2cdcdc7e2..86bc7c211c 100644 --- a/py/obj.c +++ b/py/obj.c @@ -13,9 +13,9 @@ mp_obj_type_t *mp_obj_get_type(mp_obj_t o_in) { if (MP_OBJ_IS_SMALL_INT(o_in)) { - return (mp_obj_t)&int_type; + return (mp_obj_t)&mp_type_int; } else if (MP_OBJ_IS_QSTR(o_in)) { - return (mp_obj_t)&str_type; + return (mp_obj_t)&mp_type_str; } else { mp_obj_base_t *o = o_in; return (mp_obj_t)o->type; @@ -81,7 +81,7 @@ machine_int_t mp_obj_hash(mp_obj_t o_in) { return mp_obj_str_get_hash(o_in); } else if (MP_OBJ_IS_TYPE(o_in, &mp_type_NoneType)) { return (machine_int_t)o_in; - } else if (MP_OBJ_IS_TYPE(o_in, &fun_native_type) || MP_OBJ_IS_TYPE(o_in, &fun_bc_type)) { + } else if (MP_OBJ_IS_TYPE(o_in, &mp_type_fun_native) || MP_OBJ_IS_TYPE(o_in, &mp_type_fun_bc)) { return (machine_int_t)o_in; } else if (MP_OBJ_IS_TYPE(o_in, &mp_type_tuple)) { return mp_obj_tuple_hash(o_in); @@ -116,7 +116,7 @@ bool mp_obj_equal(mp_obj_t o1, mp_obj_t o2) { return val == 0; } else if (o2 == mp_const_true) { return val == 1; - } else if (MP_OBJ_IS_TYPE(o2, &int_type)) { + } else if (MP_OBJ_IS_TYPE(o2, &mp_type_int)) { // If o2 is long int, dispatch to its virtual methods mp_obj_base_t *o = o2; if (o->type->binary_op != NULL) { @@ -161,7 +161,7 @@ machine_int_t mp_obj_get_int(mp_obj_t arg) { return 1; } else if (MP_OBJ_IS_SMALL_INT(arg)) { return MP_OBJ_SMALL_INT_VALUE(arg); - } else if (MP_OBJ_IS_TYPE(arg, &int_type)) { + } else if (MP_OBJ_IS_TYPE(arg, &mp_type_int)) { return mp_obj_int_get_checked(arg); } else { nlr_jump(mp_obj_new_exception_msg_varg(&mp_type_TypeError, "can't convert %s to int", mp_obj_get_type_str(arg))); @@ -176,7 +176,7 @@ mp_float_t mp_obj_get_float(mp_obj_t arg) { return 1; } else if (MP_OBJ_IS_SMALL_INT(arg)) { return MP_OBJ_SMALL_INT_VALUE(arg); - } else if (MP_OBJ_IS_TYPE(arg, &int_type)) { + } else if (MP_OBJ_IS_TYPE(arg, &mp_type_int)) { return mp_obj_int_as_float(arg); } else if (MP_OBJ_IS_TYPE(arg, &mp_type_float)) { return mp_obj_float_get(arg); @@ -209,7 +209,7 @@ void mp_obj_get_complex(mp_obj_t arg, mp_float_t *real, mp_float_t *imag) { void mp_obj_get_array(mp_obj_t o, uint *len, mp_obj_t **items) { if (MP_OBJ_IS_TYPE(o, &mp_type_tuple)) { mp_obj_tuple_get(o, len, items); - } else if (MP_OBJ_IS_TYPE(o, &list_type)) { + } else if (MP_OBJ_IS_TYPE(o, &mp_type_list)) { mp_obj_list_get(o, len, items); } else { nlr_jump(mp_obj_new_exception_msg_varg(&mp_type_TypeError, "object '%s' is not a tuple or list", mp_obj_get_type_str(o))); @@ -217,7 +217,7 @@ void mp_obj_get_array(mp_obj_t o, uint *len, mp_obj_t **items) { } void mp_obj_get_array_fixed_n(mp_obj_t o, uint len, mp_obj_t **items) { - if (MP_OBJ_IS_TYPE(o, &mp_type_tuple) || MP_OBJ_IS_TYPE(o, &list_type)) { + if (MP_OBJ_IS_TYPE(o, &mp_type_tuple) || MP_OBJ_IS_TYPE(o, &mp_type_list)) { uint seq_len; if (MP_OBJ_IS_TYPE(o, &mp_type_tuple)) { mp_obj_tuple_get(o, &seq_len, items); diff --git a/py/obj.h b/py/obj.h index 97d45a7962..a8cde462a9 100644 --- a/py/obj.h +++ b/py/obj.h @@ -36,8 +36,8 @@ typedef struct _mp_obj_base_t mp_obj_base_t; #define MP_OBJ_IS_QSTR(o) ((((mp_small_int_t)(o)) & 3) == 2) #define MP_OBJ_IS_OBJ(o) ((((mp_small_int_t)(o)) & 3) == 0) #define MP_OBJ_IS_TYPE(o, t) (MP_OBJ_IS_OBJ(o) && (((mp_obj_base_t*)(o))->type == (t))) // this does not work for checking a string, use below macro for that -#define MP_OBJ_IS_INT(o) (MP_OBJ_IS_SMALL_INT(o) || MP_OBJ_IS_TYPE(o, &int_type)) -#define MP_OBJ_IS_STR(o) (MP_OBJ_IS_QSTR(o) || MP_OBJ_IS_TYPE(o, &str_type)) +#define MP_OBJ_IS_INT(o) (MP_OBJ_IS_SMALL_INT(o) || MP_OBJ_IS_TYPE(o, &mp_type_int)) +#define MP_OBJ_IS_STR(o) (MP_OBJ_IS_QSTR(o) || MP_OBJ_IS_TYPE(o, &mp_type_str)) #define MP_OBJ_SMALL_INT_VALUE(o) (((mp_small_int_t)(o)) >> 1) #define MP_OBJ_NEW_SMALL_INT(small_int) ((mp_obj_t)(((small_int) << 1) | 1)) @@ -50,7 +50,7 @@ typedef struct _mp_obj_base_t mp_obj_base_t; #define MP_DECLARE_CONST_FUN_OBJ(obj_name) extern const mp_obj_fun_native_t obj_name -#define MP_DEFINE_CONST_FUN_OBJ_VOID_PTR(obj_name, is_kw, n_args_min, n_args_max, fun_name) const mp_obj_fun_native_t obj_name = {{&fun_native_type}, is_kw, n_args_min, n_args_max, (void *)fun_name} +#define MP_DEFINE_CONST_FUN_OBJ_VOID_PTR(obj_name, is_kw, n_args_min, n_args_max, fun_name) const mp_obj_fun_native_t obj_name = {{&mp_type_fun_native}, is_kw, n_args_min, n_args_max, (void *)fun_name} #define MP_DEFINE_CONST_FUN_OBJ_0(obj_name, fun_name) MP_DEFINE_CONST_FUN_OBJ_VOID_PTR(obj_name, false, 0, 0, (mp_fun_0_t)fun_name) #define MP_DEFINE_CONST_FUN_OBJ_1(obj_name, fun_name) MP_DEFINE_CONST_FUN_OBJ_VOID_PTR(obj_name, false, 1, 1, (mp_fun_1_t)fun_name) #define MP_DEFINE_CONST_FUN_OBJ_2(obj_name, fun_name) MP_DEFINE_CONST_FUN_OBJ_VOID_PTR(obj_name, false, 2, 2, (mp_fun_2_t)fun_name) @@ -64,7 +64,7 @@ typedef struct _mp_obj_base_t mp_obj_base_t; #define MP_DEFINE_CONST_DICT(dict_name, table_name) \ const mp_obj_dict_t dict_name = { \ - .base = {&dict_type}, \ + .base = {&mp_type_dict}, \ .map = { \ .all_keys_are_qstrs = 1, \ .table_is_fixed_array = 1, \ @@ -197,6 +197,31 @@ typedef struct _mp_obj_type_t mp_obj_type_t; // Constant types, globally accessible extern const mp_obj_type_t mp_type_type; +extern const mp_obj_type_t mp_type_object; +extern const mp_obj_type_t mp_type_NoneType; +extern const mp_obj_type_t mp_type_bool; +extern const mp_obj_type_t mp_type_int; +extern const mp_obj_type_t mp_type_str; +extern const mp_obj_type_t mp_type_bytes; +extern const mp_obj_type_t mp_type_float; +extern const mp_obj_type_t mp_type_complex; +extern const mp_obj_type_t mp_type_tuple; +extern const mp_obj_type_t mp_type_list; +extern const mp_obj_type_t mp_type_map; // map (the python builtin, not the dict implementation detail) +extern const mp_obj_type_t mp_type_enumerate; +extern const mp_obj_type_t mp_type_filter; +extern const mp_obj_type_t mp_type_dict; +extern const mp_obj_type_t mp_type_set; +extern const mp_obj_type_t mp_type_slice; +extern const mp_obj_type_t mp_type_zip; +extern const mp_obj_type_t mp_type_array; +extern const mp_obj_type_t mp_type_super; +extern const mp_obj_type_t mp_type_gen_instance; +extern const mp_obj_type_t mp_type_fun_native; +extern const mp_obj_type_t mp_type_fun_bc; +extern const mp_obj_type_t mp_type_module; +extern const mp_obj_type_t mp_type_staticmethod; +extern const mp_obj_type_t mp_type_classmethod; // Exceptions extern const mp_obj_type_t mp_type_BaseException; @@ -299,14 +324,7 @@ void mp_obj_get_array_fixed_n(mp_obj_t o, uint len, mp_obj_t **items); uint mp_get_index(const mp_obj_type_t *type, machine_uint_t len, mp_obj_t index, bool is_slice); mp_obj_t mp_obj_len_maybe(mp_obj_t o_in); /* may return NULL */ -// object -extern const mp_obj_type_t mp_type_object; - -// none -extern const mp_obj_type_t mp_type_NoneType; - // bool -extern const mp_obj_type_t mp_type_bool; #define MP_BOOL(x) (x ? mp_const_true : mp_const_false) // cell @@ -314,7 +332,6 @@ mp_obj_t mp_obj_cell_get(mp_obj_t self_in); void mp_obj_cell_set(mp_obj_t self_in, mp_obj_t obj); // int -extern const mp_obj_type_t int_type; // For long int, returns value truncated to machine_int_t machine_int_t mp_obj_int_get(mp_obj_t self_in); #if MICROPY_ENABLE_FLOAT @@ -333,7 +350,6 @@ void mp_obj_exception_get_traceback(mp_obj_t self_in, machine_uint_t *n, machine mp_obj_t mp_obj_exception_get_value(mp_obj_t self_in); // str -extern const mp_obj_type_t str_type; mp_obj_t mp_obj_str_builder_start(const mp_obj_type_t *type, uint len, byte **data); mp_obj_t mp_obj_str_builder_end(mp_obj_t o_in); bool mp_obj_str_equal(mp_obj_t s1, mp_obj_t s2); @@ -344,66 +360,43 @@ const char *mp_obj_str_get_str(mp_obj_t self_in); // use this only if you need t const char *mp_obj_str_get_data(mp_obj_t self_in, uint *len); void mp_str_print_quoted(void (*print)(void *env, const char *fmt, ...), void *env, const byte *str_data, uint str_len); -// bytes -extern const mp_obj_type_t bytes_type; - #if MICROPY_ENABLE_FLOAT // float typedef struct _mp_obj_float_t { mp_obj_base_t base; mp_float_t value; } mp_obj_float_t; -extern const mp_obj_type_t mp_type_float; mp_float_t mp_obj_float_get(mp_obj_t self_in); mp_obj_t mp_obj_float_binary_op(int op, mp_float_t lhs_val, mp_obj_t rhs); // complex -extern const mp_obj_type_t mp_type_complex; void mp_obj_complex_get(mp_obj_t self_in, mp_float_t *real, mp_float_t *imag); mp_obj_t mp_obj_complex_binary_op(int op, mp_float_t lhs_real, mp_float_t lhs_imag, mp_obj_t rhs_in); #endif // tuple -extern const mp_obj_type_t mp_type_tuple; void mp_obj_tuple_get(mp_obj_t self_in, uint *len, mp_obj_t **items); void mp_obj_tuple_del(mp_obj_t self_in); machine_int_t mp_obj_tuple_hash(mp_obj_t self_in); // list -extern const mp_obj_type_t list_type; mp_obj_t mp_obj_list_append(mp_obj_t self_in, mp_obj_t arg); void mp_obj_list_get(mp_obj_t self_in, uint *len, mp_obj_t **items); void mp_obj_list_store(mp_obj_t self_in, mp_obj_t index, mp_obj_t value); mp_obj_t mp_obj_list_sort(uint n_args, const mp_obj_t *args, struct _mp_map_t *kwargs); -// map (the python builtin, not the dict implementation detail) -extern const mp_obj_type_t map_type; - -// enumerate -extern const mp_obj_type_t enumerate_type; - -// filter -extern const mp_obj_type_t filter_type; - // dict -extern const mp_obj_type_t dict_type; uint mp_obj_dict_len(mp_obj_t self_in); mp_obj_t mp_obj_dict_store(mp_obj_t self_in, mp_obj_t key, mp_obj_t value); struct _mp_map_t *mp_obj_dict_get_map(mp_obj_t self_in); // set -extern const mp_obj_type_t set_type; void mp_obj_set_store(mp_obj_t self_in, mp_obj_t item); // slice -extern const mp_obj_type_t slice_type; void mp_obj_slice_get(mp_obj_t self_in, machine_int_t *start, machine_int_t *stop, machine_int_t *step); -// zip -extern const mp_obj_type_t zip_type; - // array -extern const mp_obj_type_t mp_type_array; uint mp_obj_array_len(mp_obj_t self_in); mp_obj_t mp_obj_new_bytearray_by_ref(uint n, void *items); @@ -420,33 +413,20 @@ typedef struct _mp_obj_fun_native_t { // need this so we can define const object // such functions won't be able to access the global scope, but that's probably okay } mp_obj_fun_native_t; -extern const mp_obj_type_t fun_native_type; -extern const mp_obj_type_t fun_bc_type; void mp_obj_fun_bc_get(mp_obj_t self_in, int *n_args, const byte **code); mp_obj_t mp_identity(mp_obj_t self); MP_DECLARE_CONST_FUN_OBJ(mp_identity_obj); -// super -extern const mp_obj_type_t super_type; - -// generator -extern const mp_obj_type_t gen_instance_type; - // module typedef struct _mp_obj_module_t { mp_obj_base_t base; qstr name; struct _mp_map_t *globals; } mp_obj_module_t; -extern const mp_obj_type_t mp_type_module; struct _mp_map_t *mp_obj_module_get_globals(mp_obj_t self_in); // staticmethod and classmethod types; defined here so we can make const versions - -extern const mp_obj_type_t mp_type_staticmethod; -extern const mp_obj_type_t mp_type_classmethod; - // this structure is used for instances of both staticmethod and classmethod typedef struct _mp_obj_static_class_method_t { mp_obj_base_t base; diff --git a/py/objdict.c b/py/objdict.c index 190d901055..6a1e8e08a3 100644 --- a/py/objdict.c +++ b/py/objdict.c @@ -105,7 +105,7 @@ mp_obj_t dict_it_iternext(mp_obj_t self_in) { } } -STATIC const mp_obj_type_t dict_it_type = { +STATIC const mp_obj_type_t mp_type_dict_it = { { &mp_type_type }, .name = MP_QSTR_iterator, .iternext = dict_it_iternext, @@ -113,7 +113,7 @@ STATIC const mp_obj_type_t dict_it_type = { STATIC mp_obj_t mp_obj_new_dict_iterator(mp_obj_dict_t *dict, int cur) { mp_obj_dict_it_t *o = m_new_obj(mp_obj_dict_it_t); - o->base.type = &dict_it_type; + o->base.type = &mp_type_dict_it; o->dict = dict; o->cur = cur; return o; @@ -127,7 +127,7 @@ STATIC mp_obj_t dict_getiter(mp_obj_t o_in) { /* dict methods */ STATIC mp_obj_t dict_clear(mp_obj_t self_in) { - assert(MP_OBJ_IS_TYPE(self_in, &dict_type)); + assert(MP_OBJ_IS_TYPE(self_in, &mp_type_dict)); mp_obj_dict_t *self = self_in; mp_map_clear(&self->map); @@ -137,7 +137,7 @@ STATIC mp_obj_t dict_clear(mp_obj_t self_in) { STATIC MP_DEFINE_CONST_FUN_OBJ_1(dict_clear_obj, dict_clear); STATIC mp_obj_t dict_copy(mp_obj_t self_in) { - assert(MP_OBJ_IS_TYPE(self_in, &dict_type)); + assert(MP_OBJ_IS_TYPE(self_in, &mp_type_dict)); mp_obj_dict_t *self = self_in; mp_obj_dict_t *other = mp_obj_new_dict(self->map.alloc); other->map.used = self->map.used; @@ -203,7 +203,7 @@ STATIC mp_obj_t dict_get_helper(mp_map_t *self, mp_obj_t key, mp_obj_t deflt, mp STATIC mp_obj_t dict_get(uint n_args, const mp_obj_t *args) { assert(2 <= n_args && n_args <= 3); - assert(MP_OBJ_IS_TYPE(args[0], &dict_type)); + assert(MP_OBJ_IS_TYPE(args[0], &mp_type_dict)); return dict_get_helper(&((mp_obj_dict_t *)args[0])->map, args[1], @@ -214,7 +214,7 @@ STATIC MP_DEFINE_CONST_FUN_OBJ_VAR_BETWEEN(dict_get_obj, 2, 3, dict_get); STATIC mp_obj_t dict_pop(uint n_args, const mp_obj_t *args) { assert(2 <= n_args && n_args <= 3); - assert(MP_OBJ_IS_TYPE(args[0], &dict_type)); + assert(MP_OBJ_IS_TYPE(args[0], &mp_type_dict)); return dict_get_helper(&((mp_obj_dict_t *)args[0])->map, args[1], @@ -226,7 +226,7 @@ STATIC MP_DEFINE_CONST_FUN_OBJ_VAR_BETWEEN(dict_pop_obj, 2, 3, dict_pop); STATIC mp_obj_t dict_setdefault(uint n_args, const mp_obj_t *args) { assert(2 <= n_args && n_args <= 3); - assert(MP_OBJ_IS_TYPE(args[0], &dict_type)); + assert(MP_OBJ_IS_TYPE(args[0], &mp_type_dict)); return dict_get_helper(&((mp_obj_dict_t *)args[0])->map, args[1], @@ -237,7 +237,7 @@ STATIC MP_DEFINE_CONST_FUN_OBJ_VAR_BETWEEN(dict_setdefault_obj, 2, 3, dict_setde STATIC mp_obj_t dict_popitem(mp_obj_t self_in) { - assert(MP_OBJ_IS_TYPE(self_in, &dict_type)); + assert(MP_OBJ_IS_TYPE(self_in, &mp_type_dict)); mp_obj_dict_t *self = self_in; if (self->map.used == 0) { nlr_jump(mp_obj_new_exception_msg(&mp_type_KeyError, "popitem(): dictionary is empty")); @@ -256,7 +256,7 @@ STATIC mp_obj_t dict_popitem(mp_obj_t self_in) { STATIC MP_DEFINE_CONST_FUN_OBJ_1(dict_popitem_obj, dict_popitem); STATIC mp_obj_t dict_update(mp_obj_t self_in, mp_obj_t iterable) { - assert(MP_OBJ_IS_TYPE(self_in, &dict_type)); + assert(MP_OBJ_IS_TYPE(self_in, &mp_type_dict)); mp_obj_dict_t *self = self_in; /* TODO: check for the "keys" method */ mp_obj_t iter = rt_getiter(iterable); @@ -394,7 +394,7 @@ mp_obj_t mp_obj_new_dict_view(mp_obj_dict_t *dict, mp_dict_view_kind_t kind) { } STATIC mp_obj_t dict_view(mp_obj_t self_in, mp_dict_view_kind_t kind) { - assert(MP_OBJ_IS_TYPE(self_in, &dict_type)); + assert(MP_OBJ_IS_TYPE(self_in, &mp_type_dict)); mp_obj_dict_t *self = self_in; return mp_obj_new_dict_view(self, kind); } @@ -433,7 +433,7 @@ STATIC const mp_map_elem_t dict_locals_dict_table[] = { STATIC MP_DEFINE_CONST_DICT(dict_locals_dict, dict_locals_dict_table); -const mp_obj_type_t dict_type = { +const mp_obj_type_t mp_type_dict = { { &mp_type_type }, .name = MP_QSTR_dict, .print = dict_print, @@ -446,7 +446,7 @@ const mp_obj_type_t dict_type = { mp_obj_t mp_obj_new_dict(int n_args) { mp_obj_dict_t *o = m_new_obj(mp_obj_dict_t); - o->base.type = &dict_type; + o->base.type = &mp_type_dict; mp_map_init(&o->map, n_args); return o; } @@ -456,14 +456,14 @@ uint mp_obj_dict_len(mp_obj_t self_in) { } mp_obj_t mp_obj_dict_store(mp_obj_t self_in, mp_obj_t key, mp_obj_t value) { - assert(MP_OBJ_IS_TYPE(self_in, &dict_type)); + assert(MP_OBJ_IS_TYPE(self_in, &mp_type_dict)); mp_obj_dict_t *self = self_in; mp_map_lookup(&self->map, key, MP_MAP_LOOKUP_ADD_IF_NOT_FOUND)->value = value; return self_in; } mp_map_t *mp_obj_dict_get_map(mp_obj_t self_in) { - assert(MP_OBJ_IS_TYPE(self_in, &dict_type)); + assert(MP_OBJ_IS_TYPE(self_in, &mp_type_dict)); mp_obj_dict_t *self = self_in; return &self->map; } diff --git a/py/objenumerate.c b/py/objenumerate.c index 8b33cafd7c..aaeb254e82 100644 --- a/py/objenumerate.c +++ b/py/objenumerate.c @@ -20,13 +20,13 @@ STATIC mp_obj_t enumerate_iternext(mp_obj_t self_in); STATIC mp_obj_t enumerate_make_new(mp_obj_t type_in, uint n_args, uint n_kw, const mp_obj_t *args) { assert(n_args > 0); mp_obj_enumerate_t *o = m_new_obj(mp_obj_enumerate_t); - o->base.type = &enumerate_type; + o->base.type = &mp_type_enumerate; o->iter = rt_getiter(args[0]); o->cur = n_args > 1 ? mp_obj_get_int(args[1]) : 0; return o; } -const mp_obj_type_t enumerate_type = { +const mp_obj_type_t mp_type_enumerate = { { &mp_type_type }, .name = MP_QSTR_enumerate, .make_new = enumerate_make_new, @@ -35,7 +35,7 @@ const mp_obj_type_t enumerate_type = { }; STATIC mp_obj_t enumerate_iternext(mp_obj_t self_in) { - assert(MP_OBJ_IS_TYPE(self_in, &enumerate_type)); + assert(MP_OBJ_IS_TYPE(self_in, &mp_type_enumerate)); mp_obj_enumerate_t *self = self_in; mp_obj_t next = rt_iternext(self->iter); if (next == MP_OBJ_NULL) { diff --git a/py/objfilter.c b/py/objfilter.c index 6ba1303a3d..7780940a46 100644 --- a/py/objfilter.c +++ b/py/objfilter.c @@ -20,14 +20,14 @@ STATIC mp_obj_t filter_make_new(mp_obj_t type_in, uint n_args, uint n_kw, const } assert(n_args == 2); mp_obj_filter_t *o = m_new_obj(mp_obj_filter_t); - o->base.type = &filter_type; + o->base.type = &mp_type_filter; o->fun = args[0]; o->iter = rt_getiter(args[1]); return o; } STATIC mp_obj_t filter_iternext(mp_obj_t self_in) { - assert(MP_OBJ_IS_TYPE(self_in, &filter_type)); + assert(MP_OBJ_IS_TYPE(self_in, &mp_type_filter)); mp_obj_filter_t *self = self_in; mp_obj_t next; while ((next = rt_iternext(self->iter)) != MP_OBJ_NULL) { @@ -44,7 +44,7 @@ STATIC mp_obj_t filter_iternext(mp_obj_t self_in) { return MP_OBJ_NULL; } -const mp_obj_type_t filter_type = { +const mp_obj_type_t mp_type_filter = { { &mp_type_type }, .name = MP_QSTR_filter, .make_new = filter_make_new, diff --git a/py/objfun.c b/py/objfun.c index 9370716608..2a497a6669 100644 --- a/py/objfun.c +++ b/py/objfun.c @@ -55,7 +55,7 @@ void rt_check_nargs(int n_args, machine_uint_t n_args_min, machine_uint_t n_args } STATIC mp_obj_t fun_native_call(mp_obj_t self_in, uint n_args, uint n_kw, const mp_obj_t *args) { - assert(MP_OBJ_IS_TYPE(self_in, &fun_native_type)); + assert(MP_OBJ_IS_TYPE(self_in, &mp_type_fun_native)); mp_obj_fun_native_t *self = self_in; // check number of arguments @@ -99,7 +99,7 @@ STATIC mp_obj_t fun_native_call(mp_obj_t self_in, uint n_args, uint n_kw, const } } -const mp_obj_type_t fun_native_type = { +const mp_obj_type_t mp_type_fun_native = { { &mp_type_type }, .name = MP_QSTR_function, .call = fun_native_call, @@ -108,7 +108,7 @@ const mp_obj_type_t fun_native_type = { // fun must have the correct signature for n_args fixed arguments mp_obj_t rt_make_function_n(int n_args, void *fun) { mp_obj_fun_native_t *o = m_new_obj(mp_obj_fun_native_t); - o->base.type = &fun_native_type; + o->base.type = &mp_type_fun_native; o->is_kw = false; o->n_args_min = n_args; o->n_args_max = n_args; @@ -118,7 +118,7 @@ mp_obj_t rt_make_function_n(int n_args, void *fun) { mp_obj_t rt_make_function_var(int n_args_min, mp_fun_var_t fun) { mp_obj_fun_native_t *o = m_new_obj(mp_obj_fun_native_t); - o->base.type = &fun_native_type; + o->base.type = &mp_type_fun_native; o->is_kw = false; o->n_args_min = n_args_min; o->n_args_max = MP_OBJ_FUN_ARGS_MAX; @@ -129,7 +129,7 @@ mp_obj_t rt_make_function_var(int n_args_min, mp_fun_var_t fun) { // min and max are inclusive mp_obj_t rt_make_function_var_between(int n_args_min, int n_args_max, mp_fun_var_t fun) { mp_obj_fun_native_t *o = m_new_obj(mp_obj_fun_native_t); - o->base.type = &fun_native_type; + o->base.type = &mp_type_fun_native; o->is_kw = false; o->n_args_min = n_args_min; o->n_args_max = n_args_max; @@ -297,7 +297,7 @@ arg_error: nlr_jump(mp_obj_new_exception_msg_varg(&mp_type_TypeError, "function takes %d positional arguments but %d were given", self->n_args, n_args)); } -const mp_obj_type_t fun_bc_type = { +const mp_obj_type_t mp_type_fun_bc = { { &mp_type_type }, .name = MP_QSTR_function, .call = fun_bc_call, @@ -318,7 +318,7 @@ mp_obj_t mp_obj_new_fun_bc(uint scope_flags, qstr *args, uint n_args, mp_obj_t d n_extra_args += 1; } mp_obj_fun_bc_t *o = m_new_obj_var(mp_obj_fun_bc_t, mp_obj_t, n_extra_args); - o->base.type = &fun_bc_type; + o->base.type = &mp_type_fun_bc; o->globals = rt_globals_get(); o->args = args; o->n_args = n_args; @@ -333,7 +333,7 @@ mp_obj_t mp_obj_new_fun_bc(uint scope_flags, qstr *args, uint n_args, mp_obj_t d } void mp_obj_fun_bc_get(mp_obj_t self_in, int *n_args, const byte **code) { - assert(MP_OBJ_IS_TYPE(self_in, &fun_bc_type)); + assert(MP_OBJ_IS_TYPE(self_in, &mp_type_fun_bc)); mp_obj_fun_bc_t *self = self_in; *n_args = self->n_args; *code = self->bytecode; @@ -379,7 +379,7 @@ STATIC machine_uint_t convert_obj_for_inline_asm(mp_obj_t obj) { mp_obj_t *items; mp_obj_tuple_get(obj, &len, &items); return (machine_uint_t)items; - } else if (MP_OBJ_IS_TYPE(obj, &list_type)) { + } else if (MP_OBJ_IS_TYPE(obj, &mp_type_list)) { // pointer to start of list (could pass length, but then could use len(x) for that) uint len; mp_obj_t *items; @@ -423,7 +423,7 @@ STATIC mp_obj_t fun_asm_call(mp_obj_t self_in, uint n_args, uint n_kw, const mp_ return convert_val_from_inline_asm(ret); } -STATIC const mp_obj_type_t fun_asm_type = { +STATIC const mp_obj_type_t mp_type_fun_asm = { { &mp_type_type }, .name = MP_QSTR_function, .call = fun_asm_call, @@ -431,7 +431,7 @@ STATIC const mp_obj_type_t fun_asm_type = { mp_obj_t mp_obj_new_fun_asm(uint n_args, void *fun) { mp_obj_fun_asm_t *o = m_new_obj(mp_obj_fun_asm_t); - o->base.type = &fun_asm_type; + o->base.type = &mp_type_fun_asm; o->n_args = n_args; o->fun = fun; return o; diff --git a/py/objgenerator.c b/py/objgenerator.c index a5e2b1a858..bfa1f58a64 100644 --- a/py/objgenerator.c +++ b/py/objgenerator.c @@ -22,7 +22,7 @@ typedef struct _mp_obj_gen_wrap_t { STATIC mp_obj_t gen_wrap_call(mp_obj_t self_in, uint n_args, uint n_kw, const mp_obj_t *args) { mp_obj_gen_wrap_t *self = self_in; mp_obj_t self_fun = self->fun; - assert(MP_OBJ_IS_TYPE(self_fun, &fun_bc_type)); + assert(MP_OBJ_IS_TYPE(self_fun, &mp_type_fun_bc)); int bc_n_args; const byte *bc_code; mp_obj_fun_bc_get(self_fun, &bc_n_args, &bc_code); @@ -36,7 +36,7 @@ STATIC mp_obj_t gen_wrap_call(mp_obj_t self_in, uint n_args, uint n_kw, const mp return mp_obj_new_gen_instance(bc_code, n_args, args); } -const mp_obj_type_t gen_wrap_type = { +const mp_obj_type_t mp_type_gen_wrap = { { &mp_type_type }, .name = MP_QSTR_generator, .call = gen_wrap_call, @@ -44,7 +44,7 @@ const mp_obj_type_t gen_wrap_type = { mp_obj_t mp_obj_new_gen_wrap(mp_obj_t fun) { mp_obj_gen_wrap_t *o = m_new_obj(mp_obj_gen_wrap_t); - o->base.type = &gen_wrap_type; + o->base.type = &mp_type_gen_wrap; o->fun = fun; return o; } @@ -200,7 +200,7 @@ STATIC const mp_map_elem_t gen_instance_locals_dict_table[] = { STATIC MP_DEFINE_CONST_DICT(gen_instance_locals_dict, gen_instance_locals_dict_table); -const mp_obj_type_t gen_instance_type = { +const mp_obj_type_t mp_type_gen_instance = { { &mp_type_type }, .name = MP_QSTR_generator, .print = gen_instance_print, @@ -227,7 +227,7 @@ mp_obj_t mp_obj_new_gen_instance(const byte *bytecode, int n_args, const mp_obj_ bytecode += 1; mp_obj_gen_instance_t *o = m_new_obj_var(mp_obj_gen_instance_t, byte, n_state * sizeof(mp_obj_t) + n_exc_stack * sizeof(mp_exc_stack)); - o->base.type = &gen_instance_type; + o->base.type = &mp_type_gen_instance; o->code_info = bytecode; o->ip = bytecode; o->sp = &o->state[0] - 1; // sp points to top of stack, which starts off 1 below the state diff --git a/py/objint.c b/py/objint.c index 70f44ac1e5..70f20e3cdb 100644 --- a/py/objint.c +++ b/py/objint.c @@ -109,7 +109,7 @@ mp_float_t mp_obj_int_as_float(mp_obj_t self_in) { #endif // MICROPY_LONGINT_IMPL == MICROPY_LONGINT_IMPL_NONE -const mp_obj_type_t int_type = { +const mp_obj_type_t mp_type_int = { { &mp_type_type }, .name = MP_QSTR_int, .print = int_print, diff --git a/py/objint_longlong.c b/py/objint_longlong.c index b066fa544d..3a8d3eaa86 100644 --- a/py/objint_longlong.c +++ b/py/objint_longlong.c @@ -46,7 +46,7 @@ mp_obj_t int_binary_op(int op, mp_obj_t lhs_in, mp_obj_t rhs_in) { if (MP_OBJ_IS_SMALL_INT(lhs_in)) { lhs_val = MP_OBJ_SMALL_INT_VALUE(lhs_in); - } else if (MP_OBJ_IS_TYPE(lhs_in, &int_type)) { + } else if (MP_OBJ_IS_TYPE(lhs_in, &mp_type_int)) { lhs_val = ((mp_obj_int_t*)lhs_in)->val; } else { return MP_OBJ_NULL; @@ -54,7 +54,7 @@ mp_obj_t int_binary_op(int op, mp_obj_t lhs_in, mp_obj_t rhs_in) { if (MP_OBJ_IS_SMALL_INT(rhs_in)) { rhs_val = MP_OBJ_SMALL_INT_VALUE(rhs_in); - } else if (MP_OBJ_IS_TYPE(rhs_in, &int_type)) { + } else if (MP_OBJ_IS_TYPE(rhs_in, &mp_type_int)) { rhs_val = ((mp_obj_int_t*)rhs_in)->val; } else { return MP_OBJ_NULL; @@ -131,7 +131,7 @@ mp_obj_t mp_obj_new_int_from_uint(machine_uint_t value) { mp_obj_t mp_obj_new_int_from_ll(long long val) { mp_obj_int_t *o = m_new_obj(mp_obj_int_t); - o->base.type = &int_type; + o->base.type = &mp_type_int; o->val = val; return o; } @@ -145,7 +145,7 @@ mp_obj_t mp_obj_new_int_from_long_str(const char *s) { nlr_jump(mp_obj_new_exception_msg(&mp_type_SyntaxError, "invalid syntax for number")); } mp_obj_int_t *o = m_new_obj(mp_obj_int_t); - o->base.type = &int_type; + o->base.type = &mp_type_int; o->val = v; return o; } diff --git a/py/objint_mpz.c b/py/objint_mpz.c index 25d8af70ee..bd82815bcf 100644 --- a/py/objint_mpz.c +++ b/py/objint_mpz.c @@ -16,7 +16,7 @@ STATIC mp_obj_int_t *mp_obj_int_new_mpz(void) { mp_obj_int_t *o = m_new_obj(mp_obj_int_t); - o->base.type = &int_type; + o->base.type = &mp_type_int; mpz_init_zero(&o->mpz); return o; } @@ -54,7 +54,7 @@ mp_obj_t int_binary_op(int op, mp_obj_t lhs_in, mp_obj_t rhs_in) { if (MP_OBJ_IS_SMALL_INT(lhs_in)) { mpz_init_fixed_from_int(&z_int, z_int_dig, MPZ_NUM_DIG_FOR_INT, MP_OBJ_SMALL_INT_VALUE(lhs_in)); zlhs = &z_int; - } else if (MP_OBJ_IS_TYPE(lhs_in, &int_type)) { + } else if (MP_OBJ_IS_TYPE(lhs_in, &mp_type_int)) { zlhs = &((mp_obj_int_t*)lhs_in)->mpz; } else { return MP_OBJ_NULL; @@ -64,7 +64,7 @@ mp_obj_t int_binary_op(int op, mp_obj_t lhs_in, mp_obj_t rhs_in) { if (MP_OBJ_IS_SMALL_INT(rhs_in)) { mpz_init_fixed_from_int(&z_int, z_int_dig, MPZ_NUM_DIG_FOR_INT, MP_OBJ_SMALL_INT_VALUE(rhs_in)); zrhs = &z_int; - } else if (MP_OBJ_IS_TYPE(rhs_in, &int_type)) { + } else if (MP_OBJ_IS_TYPE(rhs_in, &mp_type_int)) { zrhs = &((mp_obj_int_t*)rhs_in)->mpz; } else { return MP_OBJ_NULL; diff --git a/py/objlist.c b/py/objlist.c index 6677a8f8ce..27b2a913d8 100644 --- a/py/objlist.c +++ b/py/objlist.c @@ -67,8 +67,8 @@ STATIC mp_obj_t list_make_new(mp_obj_t type_in, uint n_args, uint n_kw, const mp // Don't pass RT_BINARY_OP_NOT_EQUAL here STATIC bool list_cmp_helper(int op, mp_obj_t self_in, mp_obj_t another_in) { - assert(MP_OBJ_IS_TYPE(self_in, &list_type)); - if (!MP_OBJ_IS_TYPE(another_in, &list_type)) { + assert(MP_OBJ_IS_TYPE(self_in, &mp_type_list)); + if (!MP_OBJ_IS_TYPE(another_in, &mp_type_list)) { return false; } mp_obj_list_t *self = self_in; @@ -92,7 +92,7 @@ STATIC mp_obj_t list_binary_op(int op, mp_obj_t lhs, mp_obj_t rhs) { case RT_BINARY_OP_SUBSCR: { #if MICROPY_ENABLE_SLICE - if (MP_OBJ_IS_TYPE(rhs, &slice_type)) { + if (MP_OBJ_IS_TYPE(rhs, &mp_type_slice)) { machine_uint_t start, stop; if (!m_seq_get_fast_slice_indexes(o->len, rhs, &start, &stop)) { assert(0); @@ -107,7 +107,7 @@ STATIC mp_obj_t list_binary_op(int op, mp_obj_t lhs, mp_obj_t rhs) { } case RT_BINARY_OP_ADD: { - if (!MP_OBJ_IS_TYPE(rhs, &list_type)) { + if (!MP_OBJ_IS_TYPE(rhs, &mp_type_list)) { return NULL; } mp_obj_list_t *p = rhs; @@ -117,7 +117,7 @@ STATIC mp_obj_t list_binary_op(int op, mp_obj_t lhs, mp_obj_t rhs) { } case RT_BINARY_OP_INPLACE_ADD: { - if (!MP_OBJ_IS_TYPE(rhs, &list_type)) { + if (!MP_OBJ_IS_TYPE(rhs, &mp_type_list)) { return NULL; } list_extend(lhs, rhs); @@ -153,7 +153,7 @@ STATIC mp_obj_t list_getiter(mp_obj_t o_in) { } mp_obj_t mp_obj_list_append(mp_obj_t self_in, mp_obj_t arg) { - assert(MP_OBJ_IS_TYPE(self_in, &list_type)); + assert(MP_OBJ_IS_TYPE(self_in, &mp_type_list)); mp_obj_list_t *self = self_in; if (self->len >= self->alloc) { self->items = m_renew(mp_obj_t, self->items, self->alloc, self->alloc * 2); @@ -165,8 +165,8 @@ mp_obj_t mp_obj_list_append(mp_obj_t self_in, mp_obj_t arg) { } STATIC mp_obj_t list_extend(mp_obj_t self_in, mp_obj_t arg_in) { - assert(MP_OBJ_IS_TYPE(self_in, &list_type)); - assert(MP_OBJ_IS_TYPE(arg_in, &list_type)); + assert(MP_OBJ_IS_TYPE(self_in, &mp_type_list)); + assert(MP_OBJ_IS_TYPE(arg_in, &mp_type_list)); mp_obj_list_t *self = self_in; mp_obj_list_t *arg = arg_in; @@ -183,7 +183,7 @@ STATIC mp_obj_t list_extend(mp_obj_t self_in, mp_obj_t arg_in) { STATIC mp_obj_t list_pop(uint n_args, const mp_obj_t *args) { assert(1 <= n_args && n_args <= 2); - assert(MP_OBJ_IS_TYPE(args[0], &list_type)); + assert(MP_OBJ_IS_TYPE(args[0], &mp_type_list)); mp_obj_list_t *self = args[0]; if (self->len == 0) { nlr_jump(mp_obj_new_exception_msg(&mp_type_IndexError, "pop from empty list")); @@ -224,7 +224,7 @@ STATIC void mp_quicksort(mp_obj_t *head, mp_obj_t *tail, mp_obj_t key_fn, bool r mp_obj_t mp_obj_list_sort(uint n_args, const mp_obj_t *args, mp_map_t *kwargs) { assert(n_args >= 1); - assert(MP_OBJ_IS_TYPE(args[0], &list_type)); + assert(MP_OBJ_IS_TYPE(args[0], &mp_type_list)); if (n_args > 1) { nlr_jump(mp_obj_new_exception_msg(&mp_type_TypeError, "list.sort takes no positional arguments")); @@ -241,7 +241,7 @@ mp_obj_t mp_obj_list_sort(uint n_args, const mp_obj_t *args, mp_map_t *kwargs) { } STATIC mp_obj_t list_clear(mp_obj_t self_in) { - assert(MP_OBJ_IS_TYPE(self_in, &list_type)); + assert(MP_OBJ_IS_TYPE(self_in, &mp_type_list)); mp_obj_list_t *self = self_in; self->len = 0; self->items = m_renew(mp_obj_t, self->items, self->alloc, LIST_MIN_ALLOC); @@ -250,26 +250,26 @@ STATIC mp_obj_t list_clear(mp_obj_t self_in) { } STATIC mp_obj_t list_copy(mp_obj_t self_in) { - assert(MP_OBJ_IS_TYPE(self_in, &list_type)); + assert(MP_OBJ_IS_TYPE(self_in, &mp_type_list)); mp_obj_list_t *self = self_in; return mp_obj_new_list(self->len, self->items); } STATIC mp_obj_t list_count(mp_obj_t self_in, mp_obj_t value) { - assert(MP_OBJ_IS_TYPE(self_in, &list_type)); + assert(MP_OBJ_IS_TYPE(self_in, &mp_type_list)); mp_obj_list_t *self = self_in; return mp_seq_count_obj(self->items, self->len, value); } STATIC mp_obj_t list_index(uint n_args, const mp_obj_t *args) { assert(2 <= n_args && n_args <= 4); - assert(MP_OBJ_IS_TYPE(args[0], &list_type)); + assert(MP_OBJ_IS_TYPE(args[0], &mp_type_list)); mp_obj_list_t *self = args[0]; return mp_seq_index_obj(self->items, self->len, n_args, args); } STATIC mp_obj_t list_insert(mp_obj_t self_in, mp_obj_t idx, mp_obj_t obj) { - assert(MP_OBJ_IS_TYPE(self_in, &list_type)); + assert(MP_OBJ_IS_TYPE(self_in, &mp_type_list)); mp_obj_list_t *self = self_in; // insert has its own strange index logic int index = MP_OBJ_SMALL_INT_VALUE(idx); @@ -294,7 +294,7 @@ STATIC mp_obj_t list_insert(mp_obj_t self_in, mp_obj_t idx, mp_obj_t obj) { } STATIC mp_obj_t list_remove(mp_obj_t self_in, mp_obj_t value) { - assert(MP_OBJ_IS_TYPE(self_in, &list_type)); + assert(MP_OBJ_IS_TYPE(self_in, &mp_type_list)); mp_obj_t args[] = {self_in, value}; args[1] = list_index(2, args); list_pop(2, args); @@ -303,7 +303,7 @@ STATIC mp_obj_t list_remove(mp_obj_t self_in, mp_obj_t value) { } STATIC mp_obj_t list_reverse(mp_obj_t self_in) { - assert(MP_OBJ_IS_TYPE(self_in, &list_type)); + assert(MP_OBJ_IS_TYPE(self_in, &mp_type_list)); mp_obj_list_t *self = self_in; int len = self->len; @@ -344,7 +344,7 @@ STATIC const mp_map_elem_t list_locals_dict_table[] = { STATIC MP_DEFINE_CONST_DICT(list_locals_dict, list_locals_dict_table); -const mp_obj_type_t list_type = { +const mp_obj_type_t mp_type_list = { { &mp_type_type }, .name = MP_QSTR_list, .print = list_print, @@ -357,7 +357,7 @@ const mp_obj_type_t list_type = { STATIC mp_obj_list_t *list_new(uint n) { mp_obj_list_t *o = m_new_obj(mp_obj_list_t); - o->base.type = &list_type; + o->base.type = &mp_type_list; o->alloc = n < LIST_MIN_ALLOC ? LIST_MIN_ALLOC : n; o->len = n; o->items = m_new(mp_obj_t, o->alloc); @@ -406,7 +406,7 @@ mp_obj_t list_it_iternext(mp_obj_t self_in) { } } -STATIC const mp_obj_type_t list_it_type = { +STATIC const mp_obj_type_t mp_type_list_it = { { &mp_type_type }, .name = MP_QSTR_iterator, .iternext = list_it_iternext, @@ -414,7 +414,7 @@ STATIC const mp_obj_type_t list_it_type = { mp_obj_t mp_obj_new_list_iterator(mp_obj_list_t *list, int cur) { mp_obj_list_it_t *o = m_new_obj(mp_obj_list_it_t); - o->base.type = &list_it_type; + o->base.type = &mp_type_list_it; o->list = list; o->cur = cur; return o; diff --git a/py/objmap.c b/py/objmap.c index cc7eae235b..efed6c93b0 100644 --- a/py/objmap.c +++ b/py/objmap.c @@ -21,7 +21,7 @@ STATIC mp_obj_t map_make_new(mp_obj_t type_in, uint n_args, uint n_kw, const mp_ } assert(n_args >= 2); mp_obj_map_t *o = m_new_obj_var(mp_obj_map_t, mp_obj_t, n_args - 1); - o->base.type = &map_type; + o->base.type = &mp_type_map; o->n_iters = n_args - 1; o->fun = args[0]; for (int i = 0; i < n_args - 1; i++) { @@ -35,7 +35,7 @@ STATIC mp_obj_t map_getiter(mp_obj_t self_in) { } STATIC mp_obj_t map_iternext(mp_obj_t self_in) { - assert(MP_OBJ_IS_TYPE(self_in, &map_type)); + assert(MP_OBJ_IS_TYPE(self_in, &mp_type_map)); mp_obj_map_t *self = self_in; mp_obj_t *nextses = m_new(mp_obj_t, self->n_iters); @@ -50,7 +50,7 @@ STATIC mp_obj_t map_iternext(mp_obj_t self_in) { return rt_call_function_n_kw(self->fun, self->n_iters, 0, nextses); } -const mp_obj_type_t map_type = { +const mp_obj_type_t mp_type_map = { { &mp_type_type }, .name = MP_QSTR_map, .make_new = map_make_new, diff --git a/py/objset.c b/py/objset.c index e6071e5385..763c17f317 100644 --- a/py/objset.c +++ b/py/objset.c @@ -70,14 +70,14 @@ STATIC mp_obj_t set_make_new(mp_obj_t type_in, uint n_args, uint n_kw, const mp_ } } -const mp_obj_type_t set_it_type = { +const mp_obj_type_t mp_type_set_it = { { &mp_type_type }, .name = MP_QSTR_iterator, .iternext = set_it_iternext, }; STATIC mp_obj_t set_it_iternext(mp_obj_t self_in) { - assert(MP_OBJ_IS_TYPE(self_in, &set_it_type)); + assert(MP_OBJ_IS_TYPE(self_in, &mp_type_set_it)); mp_obj_set_it_t *self = self_in; machine_uint_t max = self->set->set.alloc; mp_obj_t *table = self->set->set.table; @@ -94,7 +94,7 @@ STATIC mp_obj_t set_it_iternext(mp_obj_t self_in) { STATIC mp_obj_t set_getiter(mp_obj_t set_in) { mp_obj_set_it_t *o = m_new_obj(mp_obj_set_it_t); - o->base.type = &set_it_type; + o->base.type = &mp_type_set_it; o->set = (mp_obj_set_t *)set_in; o->cur = 0; return o; @@ -105,7 +105,7 @@ STATIC mp_obj_t set_getiter(mp_obj_t set_in) { /* set methods */ STATIC mp_obj_t set_add(mp_obj_t self_in, mp_obj_t item) { - assert(MP_OBJ_IS_TYPE(self_in, &set_type)); + assert(MP_OBJ_IS_TYPE(self_in, &mp_type_set)); mp_obj_set_t *self = self_in; mp_set_lookup(&self->set, item, MP_MAP_LOOKUP_ADD_IF_NOT_FOUND); return mp_const_none; @@ -113,7 +113,7 @@ STATIC mp_obj_t set_add(mp_obj_t self_in, mp_obj_t item) { STATIC MP_DEFINE_CONST_FUN_OBJ_2(set_add_obj, set_add); STATIC mp_obj_t set_clear(mp_obj_t self_in) { - assert(MP_OBJ_IS_TYPE(self_in, &set_type)); + assert(MP_OBJ_IS_TYPE(self_in, &mp_type_set)); mp_obj_set_t *self = self_in; mp_set_clear(&self->set); @@ -123,11 +123,11 @@ STATIC mp_obj_t set_clear(mp_obj_t self_in) { STATIC MP_DEFINE_CONST_FUN_OBJ_1(set_clear_obj, set_clear); STATIC mp_obj_t set_copy(mp_obj_t self_in) { - assert(MP_OBJ_IS_TYPE(self_in, &set_type)); + assert(MP_OBJ_IS_TYPE(self_in, &mp_type_set)); mp_obj_set_t *self = self_in; mp_obj_set_t *other = m_new_obj(mp_obj_set_t); - other->base.type = &set_type; + other->base.type = &mp_type_set; mp_set_init(&other->set, self->set.alloc - 1); other->set.used = self->set.used; memcpy(other->set.table, self->set.table, self->set.alloc * sizeof(mp_obj_t)); @@ -137,7 +137,7 @@ STATIC mp_obj_t set_copy(mp_obj_t self_in) { STATIC MP_DEFINE_CONST_FUN_OBJ_1(set_copy_obj, set_copy); STATIC mp_obj_t set_discard(mp_obj_t self_in, mp_obj_t item) { - assert(MP_OBJ_IS_TYPE(self_in, &set_type)); + assert(MP_OBJ_IS_TYPE(self_in, &mp_type_set)); mp_obj_set_t *self = self_in; mp_set_lookup(&self->set, item, MP_MAP_LOOKUP_REMOVE_IF_FOUND); return mp_const_none; @@ -146,7 +146,7 @@ STATIC MP_DEFINE_CONST_FUN_OBJ_2(set_discard_obj, set_discard); STATIC mp_obj_t set_diff_int(int n_args, const mp_obj_t *args, bool update) { assert(n_args > 0); - assert(MP_OBJ_IS_TYPE(args[0], &set_type)); + assert(MP_OBJ_IS_TYPE(args[0], &mp_type_set)); mp_obj_set_t *self; if (update) { self = args[0]; @@ -183,7 +183,7 @@ STATIC mp_obj_t set_diff_update(uint n_args, const mp_obj_t *args) { STATIC MP_DEFINE_CONST_FUN_OBJ_VAR(set_diff_update_obj, 1, set_diff_update); STATIC mp_obj_t set_intersect_int(mp_obj_t self_in, mp_obj_t other, bool update) { - assert(MP_OBJ_IS_TYPE(self_in, &set_type)); + assert(MP_OBJ_IS_TYPE(self_in, &mp_type_set)); if (self_in == other) { return update ? mp_const_none : set_copy(self_in); } @@ -220,7 +220,7 @@ STATIC mp_obj_t set_intersect_update(mp_obj_t self_in, mp_obj_t other) { STATIC MP_DEFINE_CONST_FUN_OBJ_2(set_intersect_update_obj, set_intersect_update); STATIC mp_obj_t set_isdisjoint(mp_obj_t self_in, mp_obj_t other) { - assert(MP_OBJ_IS_TYPE(self_in, &set_type)); + assert(MP_OBJ_IS_TYPE(self_in, &mp_type_set)); mp_obj_set_t *self = self_in; mp_obj_t iter = rt_getiter(other); @@ -237,19 +237,19 @@ STATIC MP_DEFINE_CONST_FUN_OBJ_2(set_isdisjoint_obj, set_isdisjoint); STATIC mp_obj_t set_issubset_internal(mp_obj_t self_in, mp_obj_t other_in, bool proper) { mp_obj_set_t *self; bool cleanup_self = false; - if (MP_OBJ_IS_TYPE(self_in, &set_type)) { + if (MP_OBJ_IS_TYPE(self_in, &mp_type_set)) { self = self_in; } else { - self = set_make_new((mp_obj_t)&set_type, 1, 0, &self_in); + self = set_make_new((mp_obj_t)&mp_type_set, 1, 0, &self_in); cleanup_self = true; } mp_obj_set_t *other; bool cleanup_other = false; - if (MP_OBJ_IS_TYPE(other_in, &set_type)) { + if (MP_OBJ_IS_TYPE(other_in, &mp_type_set)) { other = other_in; } else { - other = set_make_new((mp_obj_t)&set_type, 1, 0, &other_in); + other = set_make_new((mp_obj_t)&mp_type_set, 1, 0, &other_in); cleanup_other = true; } bool out = true; @@ -292,9 +292,9 @@ STATIC mp_obj_t set_issuperset_proper(mp_obj_t self_in, mp_obj_t other_in) { } STATIC mp_obj_t set_equal(mp_obj_t self_in, mp_obj_t other_in) { - assert(MP_OBJ_IS_TYPE(self_in, &set_type)); + assert(MP_OBJ_IS_TYPE(self_in, &mp_type_set)); mp_obj_set_t *self = self_in; - if (!MP_OBJ_IS_TYPE(other_in, &set_type)) { + if (!MP_OBJ_IS_TYPE(other_in, &mp_type_set)) { return mp_const_false; } mp_obj_set_t *other = other_in; @@ -305,7 +305,7 @@ STATIC mp_obj_t set_equal(mp_obj_t self_in, mp_obj_t other_in) { } STATIC mp_obj_t set_pop(mp_obj_t self_in) { - assert(MP_OBJ_IS_TYPE(self_in, &set_type)); + assert(MP_OBJ_IS_TYPE(self_in, &mp_type_set)); mp_obj_set_t *self = self_in; if (self->set.used == 0) { @@ -318,7 +318,7 @@ STATIC mp_obj_t set_pop(mp_obj_t self_in) { STATIC MP_DEFINE_CONST_FUN_OBJ_1(set_pop_obj, set_pop); STATIC mp_obj_t set_remove(mp_obj_t self_in, mp_obj_t item) { - assert(MP_OBJ_IS_TYPE(self_in, &set_type)); + assert(MP_OBJ_IS_TYPE(self_in, &mp_type_set)); mp_obj_set_t *self = self_in; if (mp_set_lookup(&self->set, item, MP_MAP_LOOKUP_REMOVE_IF_FOUND) == MP_OBJ_NULL) { nlr_jump(mp_obj_new_exception(&mp_type_KeyError)); @@ -328,7 +328,7 @@ STATIC mp_obj_t set_remove(mp_obj_t self_in, mp_obj_t item) { STATIC MP_DEFINE_CONST_FUN_OBJ_2(set_remove_obj, set_remove); STATIC mp_obj_t set_symmetric_difference_update(mp_obj_t self_in, mp_obj_t other_in) { - assert(MP_OBJ_IS_TYPE(self_in, &set_type)); + assert(MP_OBJ_IS_TYPE(self_in, &mp_type_set)); mp_obj_set_t *self = self_in; mp_obj_t iter = rt_getiter(other_in); mp_obj_t next; @@ -340,7 +340,7 @@ STATIC mp_obj_t set_symmetric_difference_update(mp_obj_t self_in, mp_obj_t other STATIC MP_DEFINE_CONST_FUN_OBJ_2(set_symmetric_difference_update_obj, set_symmetric_difference_update); STATIC mp_obj_t set_symmetric_difference(mp_obj_t self_in, mp_obj_t other_in) { - assert(MP_OBJ_IS_TYPE(self_in, &set_type)); + assert(MP_OBJ_IS_TYPE(self_in, &mp_type_set)); self_in = set_copy(self_in); set_symmetric_difference_update(self_in, other_in); return self_in; @@ -357,7 +357,7 @@ STATIC void set_update_int(mp_obj_set_t *self, mp_obj_t other_in) { STATIC mp_obj_t set_update(uint n_args, const mp_obj_t *args) { assert(n_args > 0); - assert(MP_OBJ_IS_TYPE(args[0], &set_type)); + assert(MP_OBJ_IS_TYPE(args[0], &mp_type_set)); for (int i = 1; i < n_args; i++) { set_update_int(args[0], args[i]); @@ -368,7 +368,7 @@ STATIC mp_obj_t set_update(uint n_args, const mp_obj_t *args) { STATIC MP_DEFINE_CONST_FUN_OBJ_VAR(set_update_obj, 1, set_update); STATIC mp_obj_t set_union(mp_obj_t self_in, mp_obj_t other_in) { - assert(MP_OBJ_IS_TYPE(self_in, &set_type)); + assert(MP_OBJ_IS_TYPE(self_in, &mp_type_set)); mp_obj_set_t *self = set_copy(self_in); set_update_int(self, other_in); return self; @@ -445,7 +445,7 @@ STATIC const mp_map_elem_t set_locals_dict_table[] = { STATIC MP_DEFINE_CONST_DICT(set_locals_dict, set_locals_dict_table); -const mp_obj_type_t set_type = { +const mp_obj_type_t mp_type_set = { { &mp_type_type }, .name = MP_QSTR_set, .print = set_print, @@ -457,7 +457,7 @@ const mp_obj_type_t set_type = { mp_obj_t mp_obj_new_set(int n_args, mp_obj_t *items) { mp_obj_set_t *o = m_new_obj(mp_obj_set_t); - o->base.type = &set_type; + o->base.type = &mp_type_set; mp_set_init(&o->set, n_args); for (int i = 0; i < n_args; i++) { mp_set_lookup(&o->set, items[i], MP_MAP_LOOKUP_ADD_IF_NOT_FOUND); @@ -466,7 +466,7 @@ mp_obj_t mp_obj_new_set(int n_args, mp_obj_t *items) { } void mp_obj_set_store(mp_obj_t self_in, mp_obj_t item) { - assert(MP_OBJ_IS_TYPE(self_in, &set_type)); + assert(MP_OBJ_IS_TYPE(self_in, &mp_type_set)); mp_obj_set_t *self = self_in; mp_set_lookup(&self->set, item, MP_MAP_LOOKUP_ADD_IF_NOT_FOUND); } diff --git a/py/objslice.c b/py/objslice.c index 0c28d07edb..924927db5f 100644 --- a/py/objslice.c +++ b/py/objslice.c @@ -45,7 +45,7 @@ void slice_print(void (*print)(void *env, const char *fmt, ...), void *env, mp_o print(env, "slice(" INT_FMT ", " INT_FMT ")", o->start, o->stop); } -const mp_obj_type_t slice_type = { +const mp_obj_type_t mp_type_slice = { { &mp_type_type }, .name = MP_QSTR_slice, .print = slice_print, @@ -72,14 +72,14 @@ mp_obj_t mp_obj_new_slice(mp_obj_t ostart, mp_obj_t ostop, mp_obj_t ostep) { } } mp_obj_slice_t *o = m_new(mp_obj_slice_t, 1); - o->base.type = &slice_type; + o->base.type = &mp_type_slice; o->start = start; o->stop = stop; return (mp_obj_t)o; } void mp_obj_slice_get(mp_obj_t self_in, machine_int_t *start, machine_int_t *stop, machine_int_t *step) { - assert(MP_OBJ_IS_TYPE(self_in, &slice_type)); + assert(MP_OBJ_IS_TYPE(self_in, &mp_type_slice)); mp_obj_slice_t *self = self_in; *start = self->start; *stop = self->stop; diff --git a/py/objstr.c b/py/objstr.c index cf68e95fe8..9c72584173 100644 --- a/py/objstr.c +++ b/py/objstr.c @@ -71,7 +71,7 @@ void mp_str_print_quoted(void (*print)(void *env, const char *fmt, ...), void *e STATIC void str_print(void (*print)(void *env, const char *fmt, ...), void *env, mp_obj_t self_in, mp_print_kind_t kind) { GET_STR_DATA_LEN(self_in, str_data, str_len); - bool is_bytes = MP_OBJ_IS_TYPE(self_in, &bytes_type); + bool is_bytes = MP_OBJ_IS_TYPE(self_in, &mp_type_bytes); if (kind == PRINT_STR && !is_bytes) { print(env, "%.*s", str_len, str_data); } else { @@ -100,12 +100,12 @@ STATIC mp_obj_t str_make_new(mp_obj_t type_in, uint n_args, uint n_kw, const mp_ case 3: { // TODO: validate 2nd/3rd args - if (!MP_OBJ_IS_TYPE(args[0], &bytes_type)) { + if (!MP_OBJ_IS_TYPE(args[0], &mp_type_bytes)) { nlr_jump(mp_obj_new_exception_msg(&mp_type_TypeError, "bytes expected")); } GET_STR_DATA_LEN(args[0], str_data, str_len); GET_STR_HASH(args[0], str_hash); - mp_obj_str_t *o = str_new(&str_type, NULL, str_len); + mp_obj_str_t *o = str_new(&mp_type_str, NULL, str_len); o->data = str_data; o->hash = str_hash; return o; @@ -127,7 +127,7 @@ STATIC mp_obj_t bytes_make_new(mp_obj_t type_in, uint n_args, uint n_kw, const m } GET_STR_DATA_LEN(args[0], str_data, str_len); GET_STR_HASH(args[0], str_hash); - mp_obj_str_t *o = str_new(&bytes_type, NULL, str_len); + mp_obj_str_t *o = str_new(&mp_type_bytes, NULL, str_len); o->data = str_data; o->hash = str_hash; return o; @@ -141,7 +141,7 @@ STATIC mp_obj_t bytes_make_new(mp_obj_t type_in, uint n_args, uint n_kw, const m uint len = MP_OBJ_SMALL_INT_VALUE(args[0]); byte *data; - mp_obj_t o = mp_obj_str_builder_start(&bytes_type, len, &data); + mp_obj_t o = mp_obj_str_builder_start(&mp_type_bytes, len, &data); memset(data, 0, len); return mp_obj_str_builder_end(o); } @@ -157,7 +157,7 @@ STATIC mp_obj_t bytes_make_new(mp_obj_t type_in, uint n_args, uint n_kw, const m vstr = vstr_new(); } else { len = MP_OBJ_SMALL_INT_VALUE(len_in); - o = mp_obj_str_builder_start(&bytes_type, len, &data); + o = mp_obj_str_builder_start(&mp_type_bytes, len, &data); } mp_obj_t iterable = rt_getiter(args[0]); @@ -174,7 +174,7 @@ STATIC mp_obj_t bytes_make_new(mp_obj_t type_in, uint n_args, uint n_kw, const m vstr_shrink(vstr); // TODO: Optimize, borrow buffer from vstr len = vstr_len(vstr); - o = mp_obj_str_builder_start(&bytes_type, len, &data); + o = mp_obj_str_builder_start(&mp_type_bytes, len, &data); memcpy(data, vstr_str(vstr), len); vstr_free(vstr); } @@ -220,13 +220,13 @@ STATIC mp_obj_t str_binary_op(int op, mp_obj_t lhs_in, mp_obj_t rhs_in) { // ["no", "yes"][1 == 2] is common idiom if (MP_OBJ_IS_SMALL_INT(rhs_in)) { uint index = mp_get_index(mp_obj_get_type(lhs_in), lhs_len, rhs_in, false); - if (MP_OBJ_IS_TYPE(lhs_in, &bytes_type)) { + if (MP_OBJ_IS_TYPE(lhs_in, &mp_type_bytes)) { return MP_OBJ_NEW_SMALL_INT((mp_small_int_t)lhs_data[index]); } else { return mp_obj_new_str(lhs_data + index, 1, true); } #if MICROPY_ENABLE_SLICE - } else if (MP_OBJ_IS_TYPE(rhs_in, &slice_type)) { + } else if (MP_OBJ_IS_TYPE(rhs_in, &mp_type_slice)) { machine_uint_t start, stop; if (!m_seq_get_fast_slice_indexes(lhs_len, rhs_in, &start, &stop)) { assert(0); @@ -311,7 +311,7 @@ STATIC mp_obj_t str_join(mp_obj_t self_in, mp_obj_t arg) { mp_obj_t *seq_items; if (MP_OBJ_IS_TYPE(arg, &mp_type_tuple)) { mp_obj_tuple_get(arg, &seq_len, &seq_items); - } else if (MP_OBJ_IS_TYPE(arg, &list_type)) { + } else if (MP_OBJ_IS_TYPE(arg, &mp_type_list)) { mp_obj_list_get(arg, &seq_len, &seq_items); } else { goto bad_arg; @@ -401,10 +401,10 @@ STATIC mp_obj_t str_finder(uint n_args, const mp_obj_t *args, machine_int_t dire machine_uint_t start = 0; machine_uint_t end = haystack_len; if (n_args >= 3 && args[2] != mp_const_none) { - start = mp_get_index(&str_type, haystack_len, args[2], true); + start = mp_get_index(&mp_type_str, haystack_len, args[2], true); } if (n_args >= 4 && args[3] != mp_const_none) { - end = mp_get_index(&str_type, haystack_len, args[3], true); + end = mp_get_index(&mp_type_str, haystack_len, args[3], true); } const byte *p = find_subbytes(haystack + start, end - start, needle, needle_len, direction); @@ -604,10 +604,10 @@ STATIC mp_obj_t str_count(uint n_args, const mp_obj_t *args) { machine_uint_t start = 0; machine_uint_t end = haystack_len; if (n_args >= 3 && args[2] != mp_const_none) { - start = mp_get_index(&str_type, haystack_len, args[2], true); + start = mp_get_index(&mp_type_str, haystack_len, args[2], true); } if (n_args >= 4 && args[3] != mp_const_none) { - end = mp_get_index(&str_type, haystack_len, args[3], true); + end = mp_get_index(&mp_type_str, haystack_len, args[3], true); } // if needle_len is zero then we count each gap between characters as an occurrence @@ -710,7 +710,7 @@ STATIC const mp_map_elem_t str_locals_dict_table[] = { STATIC MP_DEFINE_CONST_DICT(str_locals_dict, str_locals_dict_table); -const mp_obj_type_t str_type = { +const mp_obj_type_t mp_type_str = { { &mp_type_type }, .name = MP_QSTR_str, .print = str_print, @@ -722,7 +722,7 @@ const mp_obj_type_t str_type = { }; // Reuses most of methods from str -const mp_obj_type_t bytes_type = { +const mp_obj_type_t mp_type_bytes = { { &mp_type_type }, .name = MP_QSTR_bytes, .print = str_print, @@ -733,7 +733,7 @@ const mp_obj_type_t bytes_type = { }; // the zero-length bytes -STATIC const mp_obj_str_t empty_bytes_obj = {{&bytes_type}, 0, 0, NULL}; +STATIC const mp_obj_str_t empty_bytes_obj = {{&mp_type_bytes}, 0, 0, NULL}; const mp_obj_t mp_const_empty_bytes = (mp_obj_t)&empty_bytes_obj; mp_obj_t mp_obj_str_builder_start(const mp_obj_type_t *type, uint len, byte **data) { @@ -778,12 +778,12 @@ mp_obj_t mp_obj_new_str(const byte* data, uint len, bool make_qstr_if_not_alread return MP_OBJ_NEW_QSTR(qstr_from_strn((const char*)data, len)); } else { // no existing qstr, don't make one - return str_new(&str_type, data, len); + return str_new(&mp_type_str, data, len); } } mp_obj_t mp_obj_new_bytes(const byte* data, uint len) { - return str_new(&bytes_type, data, len); + return str_new(&mp_type_bytes, data, len); } bool mp_obj_str_equal(mp_obj_t s1, mp_obj_t s2) { @@ -832,7 +832,7 @@ uint mp_obj_str_get_len(mp_obj_t self_in) { qstr mp_obj_str_get_qstr(mp_obj_t self_in) { if (MP_OBJ_IS_QSTR(self_in)) { return MP_OBJ_QSTR_VALUE(self_in); - } else if (MP_OBJ_IS_TYPE(self_in, &str_type)) { + } else if (MP_OBJ_IS_TYPE(self_in, &mp_type_str)) { mp_obj_str_t *self = self_in; return qstr_from_strn((char*)self->data, self->len); } else { @@ -883,7 +883,7 @@ STATIC mp_obj_t str_it_iternext(mp_obj_t self_in) { } } -STATIC const mp_obj_type_t str_it_type = { +STATIC const mp_obj_type_t mp_type_str_it = { { &mp_type_type }, .name = MP_QSTR_iterator, .iternext = str_it_iternext, @@ -901,7 +901,7 @@ STATIC mp_obj_t bytes_it_iternext(mp_obj_t self_in) { } } -STATIC const mp_obj_type_t bytes_it_type = { +STATIC const mp_obj_type_t mp_type_bytes_it = { { &mp_type_type }, .name = MP_QSTR_iterator, .iternext = bytes_it_iternext, @@ -909,7 +909,7 @@ STATIC const mp_obj_type_t bytes_it_type = { mp_obj_t mp_obj_new_str_iterator(mp_obj_t str) { mp_obj_str_it_t *o = m_new_obj(mp_obj_str_it_t); - o->base.type = &str_it_type; + o->base.type = &mp_type_str_it; o->str = str; o->cur = 0; return o; @@ -917,7 +917,7 @@ mp_obj_t mp_obj_new_str_iterator(mp_obj_t str) { mp_obj_t mp_obj_new_bytes_iterator(mp_obj_t str) { mp_obj_str_it_t *o = m_new_obj(mp_obj_str_it_t); - o->base.type = &bytes_it_type; + o->base.type = &mp_type_bytes_it; o->str = str; o->cur = 0; return o; diff --git a/py/objtuple.c b/py/objtuple.c index 6f4753afa7..d8c36021b5 100644 --- a/py/objtuple.c +++ b/py/objtuple.c @@ -100,7 +100,7 @@ mp_obj_t tuple_binary_op(int op, mp_obj_t lhs, mp_obj_t rhs) { case RT_BINARY_OP_SUBSCR: { #if MICROPY_ENABLE_SLICE - if (MP_OBJ_IS_TYPE(rhs, &slice_type)) { + if (MP_OBJ_IS_TYPE(rhs, &mp_type_slice)) { machine_uint_t start, stop; if (!m_seq_get_fast_slice_indexes(o->len, rhs, &start, &stop)) { assert(0); @@ -250,7 +250,7 @@ STATIC mp_obj_t tuple_it_iternext(mp_obj_t self_in) { } } -STATIC const mp_obj_type_t tuple_it_type = { +STATIC const mp_obj_type_t mp_type_tuple_it = { { &mp_type_type }, .name = MP_QSTR_iterator, .iternext = tuple_it_iternext, @@ -258,7 +258,7 @@ STATIC const mp_obj_type_t tuple_it_type = { STATIC mp_obj_t mp_obj_new_tuple_iterator(mp_obj_tuple_t *tuple, int cur) { mp_obj_tuple_it_t *o = m_new_obj(mp_obj_tuple_it_t); - o->base.type = &tuple_it_type; + o->base.type = &mp_type_tuple_it; o->tuple = tuple; o->cur = cur; return o; diff --git a/py/objtype.c b/py/objtype.c index e553d8cf71..513dc7ab2e 100644 --- a/py/objtype.c +++ b/py/objtype.c @@ -31,7 +31,7 @@ STATIC mp_obj_t mp_obj_class_lookup(const mp_obj_type_t *type, qstr attr) { for (;;) { if (type->locals_dict != NULL) { // search locals_dict (the set of methods/attributes) - assert(MP_OBJ_IS_TYPE(type->locals_dict, &dict_type)); // Micro Python restriction, for now + assert(MP_OBJ_IS_TYPE(type->locals_dict, &mp_type_dict)); // Micro Python restriction, for now mp_map_t *locals_map = mp_obj_dict_get_map(type->locals_dict); mp_map_elem_t *elem = mp_map_lookup(locals_map, MP_OBJ_NEW_QSTR(attr), MP_MAP_LOOKUP); if (elem != NULL) { @@ -324,7 +324,7 @@ STATIC bool type_store_attr(mp_obj_t self_in, qstr attr, mp_obj_t value) { // TODO CPython allows STORE_ATTR to a class, but is this the correct implementation? if (self->locals_dict != NULL) { - assert(MP_OBJ_IS_TYPE(self->locals_dict, &dict_type)); // Micro Python restriction, for now + assert(MP_OBJ_IS_TYPE(self->locals_dict, &mp_type_dict)); // Micro Python restriction, for now mp_map_t *locals_map = mp_obj_dict_get_map(self->locals_dict); mp_map_elem_t *elem = mp_map_lookup(locals_map, MP_OBJ_NEW_QSTR(attr), MP_MAP_LOOKUP_ADD_IF_NOT_FOUND); // note that locals_map may be in ROM, so add will fail in that case @@ -349,7 +349,7 @@ const mp_obj_type_t mp_type_type = { mp_obj_t mp_obj_new_type(qstr name, mp_obj_t bases_tuple, mp_obj_t locals_dict) { assert(MP_OBJ_IS_TYPE(bases_tuple, &mp_type_tuple)); // Micro Python restriction, for now - assert(MP_OBJ_IS_TYPE(locals_dict, &dict_type)); // Micro Python restriction, for now + assert(MP_OBJ_IS_TYPE(locals_dict, &mp_type_dict)); // Micro Python restriction, for now mp_obj_type_t *o = m_new0(mp_obj_type_t, 1); o->base.type = &mp_type_type; o->name = name; @@ -394,7 +394,7 @@ STATIC mp_obj_t super_make_new(mp_obj_t type_in, uint n_args, uint n_kw, const m // for fail, do nothing; for attr, dest[0] = value; for method, dest[0] = method, dest[1] = self STATIC void super_load_attr(mp_obj_t self_in, qstr attr, mp_obj_t *dest) { - assert(MP_OBJ_IS_TYPE(self_in, &super_type)); + assert(MP_OBJ_IS_TYPE(self_in, &mp_type_super)); mp_obj_super_t *self = self_in; assert(MP_OBJ_IS_TYPE(self->type, &mp_type_type)); @@ -437,7 +437,7 @@ STATIC void super_load_attr(mp_obj_t self_in, qstr attr, mp_obj_t *dest) { } } -const mp_obj_type_t super_type = { +const mp_obj_type_t mp_type_super = { { &mp_type_type }, .name = MP_QSTR_super, .print = super_print, @@ -447,7 +447,7 @@ const mp_obj_type_t super_type = { mp_obj_t mp_obj_new_super(mp_obj_t type, mp_obj_t obj) { mp_obj_super_t *o = m_new_obj(mp_obj_super_t); - *o = (mp_obj_super_t){{&super_type}, type, obj}; + *o = (mp_obj_super_t){{&mp_type_super}, type, obj}; return o; } diff --git a/py/objzip.c b/py/objzip.c index 553dabba74..9200120899 100644 --- a/py/objzip.c +++ b/py/objzip.c @@ -17,7 +17,7 @@ STATIC mp_obj_t zip_make_new(mp_obj_t type_in, uint n_args, uint n_kw, const mp_ // TODO check n_kw == 0 mp_obj_zip_t *o = m_new_obj_var(mp_obj_zip_t, mp_obj_t, n_args); - o->base.type = &zip_type; + o->base.type = &mp_type_zip; o->n_iters = n_args; for (int i = 0; i < n_args; i++) { o->iters[i] = rt_getiter(args[i]); @@ -30,7 +30,7 @@ STATIC mp_obj_t zip_getiter(mp_obj_t self_in) { } STATIC mp_obj_t zip_iternext(mp_obj_t self_in) { - assert(MP_OBJ_IS_TYPE(self_in, &zip_type)); + assert(MP_OBJ_IS_TYPE(self_in, &mp_type_zip)); mp_obj_zip_t *self = self_in; mp_obj_t *items; if (self->n_iters == 0) { @@ -50,7 +50,7 @@ STATIC mp_obj_t zip_iternext(mp_obj_t self_in) { return o; } -const mp_obj_type_t zip_type = { +const mp_obj_type_t mp_type_zip = { { &mp_type_type }, .name = MP_QSTR_zip, .make_new = zip_make_new, diff --git a/py/runtime.c b/py/runtime.c index 4dc1c2ef53..121cfa04e0 100644 --- a/py/runtime.c +++ b/py/runtime.c @@ -558,7 +558,7 @@ mp_obj_t rt_store_set(mp_obj_t set, mp_obj_t item) { // unpacked items are stored in reverse order into the array pointed to by items void rt_unpack_sequence(mp_obj_t seq_in, uint num, mp_obj_t *items) { uint seq_len; - if (MP_OBJ_IS_TYPE(seq_in, &mp_type_tuple) || MP_OBJ_IS_TYPE(seq_in, &list_type)) { + if (MP_OBJ_IS_TYPE(seq_in, &mp_type_tuple) || MP_OBJ_IS_TYPE(seq_in, &mp_type_list)) { mp_obj_t *seq_items; if (MP_OBJ_IS_TYPE(seq_in, &mp_type_tuple)) { mp_obj_tuple_get(seq_in, &seq_len, &seq_items); @@ -646,7 +646,7 @@ STATIC void rt_load_method_maybe(mp_obj_t base, qstr attr, mp_obj_t *dest) { // generic method lookup if type didn't provide a specific one // this is a lookup in the object (ie not class or type) if (type->locals_dict != NULL) { - assert(MP_OBJ_IS_TYPE(type->locals_dict, &dict_type)); // Micro Python restriction, for now + assert(MP_OBJ_IS_TYPE(type->locals_dict, &mp_type_dict)); // Micro Python restriction, for now mp_map_t *locals_map = mp_obj_dict_get_map(type->locals_dict); mp_map_elem_t *elem = mp_map_lookup(locals_map, MP_OBJ_NEW_QSTR(attr), MP_MAP_LOOKUP); if (elem != NULL) { @@ -703,10 +703,10 @@ void rt_store_attr(mp_obj_t base, qstr attr, mp_obj_t value) { void rt_store_subscr(mp_obj_t base, mp_obj_t index, mp_obj_t value) { DEBUG_OP_printf("store subscr %p[%p] <- %p\n", base, index, value); - if (MP_OBJ_IS_TYPE(base, &list_type)) { + if (MP_OBJ_IS_TYPE(base, &mp_type_list)) { // list store mp_obj_list_store(base, index, value); - } else if (MP_OBJ_IS_TYPE(base, &dict_type)) { + } else if (MP_OBJ_IS_TYPE(base, &mp_type_dict)) { // dict store mp_obj_dict_store(base, index, value); } else { diff --git a/stmhal/help.c b/stmhal/help.c index 5cedac9d93..3ab69ec622 100644 --- a/stmhal/help.c +++ b/stmhal/help.c @@ -68,7 +68,7 @@ STATIC mp_obj_t pyb_help(uint n_args, const mp_obj_t *args) { } else { type = mp_obj_get_type(args[0]); } - if (type->locals_dict != MP_OBJ_NULL && MP_OBJ_IS_TYPE(type->locals_dict, &dict_type)) { + if (type->locals_dict != MP_OBJ_NULL && MP_OBJ_IS_TYPE(type->locals_dict, &mp_type_dict)) { map = mp_obj_dict_get_map(type->locals_dict); } } diff --git a/stmhal/i2c.c b/stmhal/i2c.c index 9556e32c9c..ab37f756b8 100644 --- a/stmhal/i2c.c +++ b/stmhal/i2c.c @@ -124,7 +124,7 @@ STATIC mp_obj_t pyb_i2c_mem_read(uint n_args, const mp_obj_t *args) { machine_uint_t n = mp_obj_get_int(args[3]); byte *data; - mp_obj_t o = mp_obj_str_builder_start(&bytes_type, n, &data); + mp_obj_t o = mp_obj_str_builder_start(&mp_type_bytes, n, &data); HAL_StatusTypeDef status = HAL_I2C_Mem_Read(self->i2c_handle, i2c_addr, mem_addr, I2C_MEMADD_SIZE_8BIT, data, n, 200); //printf("Read got %d\n", status); diff --git a/stmhal/modos.c b/stmhal/modos.c index 0ec9fcbb91..606dbe927c 100644 --- a/stmhal/modos.c +++ b/stmhal/modos.c @@ -17,11 +17,11 @@ static char lfn[_MAX_LFN + 1]; /* Buffer to store the LFN */ #endif STATIC mp_obj_t os_listdir(uint n_args, const mp_obj_t *args) { - const mp_obj_type_t *local_str_type = &str_type; + const mp_obj_type_t *local_str_type = &mp_type_str; const char *path; if (n_args == 1) { - if (mp_obj_get_type(args[0]) == &bytes_type) { - local_str_type = &bytes_type; + if (mp_obj_get_type(args[0]) == &mp_type_bytes) { + local_str_type = &mp_type_bytes; } path = mp_obj_str_get_str(args[0]); } else { @@ -138,7 +138,7 @@ MP_DEFINE_CONST_FUN_OBJ_0(os_sync_obj, os_sync); STATIC mp_obj_t os_urandom(mp_obj_t num) { machine_int_t n = mp_obj_get_int(num); byte *data; - mp_obj_t o = mp_obj_str_builder_start(&bytes_type, n, &data); + mp_obj_t o = mp_obj_str_builder_start(&mp_type_bytes, n, &data); for (int i = 0; i < n; i++) { data[i] = rng_get(); } diff --git a/unix/ffi.c b/unix/ffi.c index a25e54b54a..d42e4d0928 100644 --- a/unix/ffi.c +++ b/unix/ffi.c @@ -254,7 +254,7 @@ mp_obj_t ffifunc_call(mp_obj_t self_in, uint n_args, uint n_kw, const mp_obj_t * values[i] = 0; } else if (MP_OBJ_IS_INT(a)) { values[i] = mp_obj_int_get(a); - } else if (MP_OBJ_IS_STR(a) || MP_OBJ_IS_TYPE(a, &bytes_type)) { + } else if (MP_OBJ_IS_STR(a) || MP_OBJ_IS_TYPE(a, &mp_type_bytes)) { const char *s = mp_obj_str_get_str(a); values[i] = (ffi_arg)s; } else if (MP_OBJ_IS_TYPE(a, &fficallback_type)) { diff --git a/unix/mpconfigport.mk b/unix/mpconfigport.mk index d30be8b986..bfb01a71f1 100644 --- a/unix/mpconfigport.mk +++ b/unix/mpconfigport.mk @@ -7,4 +7,4 @@ MICROPY_USE_READLINE = 1 MICROPY_MOD_TIME = 1 # ffi module requires libffi (libffi-dev Debian package) -MICROPY_MOD_FFI = 0 +MICROPY_MOD_FFI = 1 diff --git a/unix/socket.c b/unix/socket.c index 3125544282..04c1d10c73 100644 --- a/unix/socket.c +++ b/unix/socket.c @@ -261,7 +261,7 @@ static mp_obj_t mod_socket_htons(mp_obj_t arg) { static MP_DEFINE_CONST_FUN_OBJ_1(mod_socket_htons_obj, mod_socket_htons); static mp_obj_t mod_socket_inet_aton(mp_obj_t arg) { - assert(MP_OBJ_IS_TYPE(arg, &str_type)); + assert(MP_OBJ_IS_TYPE(arg, &mp_type_str)); const char *s = mp_obj_str_get_str(arg); struct in_addr addr; if (!inet_aton(s, &addr)) { @@ -274,7 +274,7 @@ static MP_DEFINE_CONST_FUN_OBJ_1(mod_socket_inet_aton_obj, mod_socket_inet_aton) #if MICROPY_SOCKET_EXTRA static mp_obj_t mod_socket_gethostbyname(mp_obj_t arg) { - assert(MP_OBJ_IS_TYPE(arg, &str_type)); + assert(MP_OBJ_IS_TYPE(arg, &mp_type_str)); const char *s = mp_obj_str_get_str(arg); struct hostent *h = gethostbyname(s); if (h == NULL) {