Skip to content

Commit 3e1a5c1

Browse files
committed
py: Rename old const type objects to mp_type_* for consistency.
1 parent 07ddab5 commit 3e1a5c1

27 files changed

+197
-217
lines changed

py/builtin.c

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -166,7 +166,7 @@ STATIC mp_obj_t mp_builtin_dir(uint n_args, const mp_obj_t *args) {
166166
} else {
167167
type = mp_obj_get_type(args[0]);
168168
}
169-
if (type->locals_dict != MP_OBJ_NULL && MP_OBJ_IS_TYPE(type->locals_dict, &dict_type)) {
169+
if (type->locals_dict != MP_OBJ_NULL && MP_OBJ_IS_TYPE(type->locals_dict, &mp_type_dict)) {
170170
map = mp_obj_dict_get_map(type->locals_dict);
171171
}
172172
}
@@ -375,7 +375,7 @@ STATIC mp_obj_t mp_builtin_sorted(uint n_args, const mp_obj_t *args, mp_map_t *k
375375
nlr_jump(mp_obj_new_exception_msg(&mp_type_TypeError,
376376
"must use keyword argument for key function"));
377377
}
378-
mp_obj_t self = list_type.make_new((mp_obj_t)&list_type, 1, 0, args);
378+
mp_obj_t self = mp_type_list.make_new((mp_obj_t)&mp_type_list, 1, 0, args);
379379
mp_obj_list_sort(1, &self, kwargs);
380380

381381
return self;

py/builtintables.c

Lines changed: 11 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -26,26 +26,26 @@ STATIC const mp_builtin_elem_t builtin_object_table[] = {
2626

2727
// built-in types
2828
{ MP_QSTR_bool, (mp_obj_t)&mp_type_bool },
29-
{ MP_QSTR_bytes, (mp_obj_t)&bytes_type },
29+
{ MP_QSTR_bytes, (mp_obj_t)&mp_type_bytes },
3030
#if MICROPY_ENABLE_FLOAT
3131
{ MP_QSTR_complex, (mp_obj_t)&mp_type_complex },
3232
#endif
33-
{ MP_QSTR_dict, (mp_obj_t)&dict_type },
34-
{ MP_QSTR_enumerate, (mp_obj_t)&enumerate_type },
35-
{ MP_QSTR_filter, (mp_obj_t)&filter_type },
33+
{ MP_QSTR_dict, (mp_obj_t)&mp_type_dict },
34+
{ MP_QSTR_enumerate, (mp_obj_t)&mp_type_enumerate },
35+
{ MP_QSTR_filter, (mp_obj_t)&mp_type_filter },
3636
#if MICROPY_ENABLE_FLOAT
3737
{ MP_QSTR_float, (mp_obj_t)&mp_type_float },
3838
#endif
39-
{ MP_QSTR_int, (mp_obj_t)&int_type },
40-
{ MP_QSTR_list, (mp_obj_t)&list_type },
41-
{ MP_QSTR_map, (mp_obj_t)&map_type },
39+
{ MP_QSTR_int, (mp_obj_t)&mp_type_int },
40+
{ MP_QSTR_list, (mp_obj_t)&mp_type_list },
41+
{ MP_QSTR_map, (mp_obj_t)&mp_type_map },
4242
{ MP_QSTR_object, (mp_obj_t)&mp_type_object },
43-
{ MP_QSTR_set, (mp_obj_t)&set_type },
44-
{ MP_QSTR_str, (mp_obj_t)&str_type },
45-
{ MP_QSTR_super, (mp_obj_t)&super_type },
43+
{ MP_QSTR_set, (mp_obj_t)&mp_type_set },
44+
{ MP_QSTR_str, (mp_obj_t)&mp_type_str },
45+
{ MP_QSTR_super, (mp_obj_t)&mp_type_super },
4646
{ MP_QSTR_tuple, (mp_obj_t)&mp_type_tuple },
4747
{ MP_QSTR_type, (mp_obj_t)&mp_type_type },
48-
{ MP_QSTR_zip, (mp_obj_t)&zip_type },
48+
{ MP_QSTR_zip, (mp_obj_t)&mp_type_zip },
4949

5050
{ MP_QSTR_classmethod, (mp_obj_t)&mp_type_classmethod },
5151
{ MP_QSTR_staticmethod, (mp_obj_t)&mp_type_staticmethod },

py/obj.c

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -13,9 +13,9 @@
1313

1414
mp_obj_type_t *mp_obj_get_type(mp_obj_t o_in) {
1515
if (MP_OBJ_IS_SMALL_INT(o_in)) {
16-
return (mp_obj_t)&int_type;
16+
return (mp_obj_t)&mp_type_int;
1717
} else if (MP_OBJ_IS_QSTR(o_in)) {
18-
return (mp_obj_t)&str_type;
18+
return (mp_obj_t)&mp_type_str;
1919
} else {
2020
mp_obj_base_t *o = o_in;
2121
return (mp_obj_t)o->type;
@@ -81,7 +81,7 @@ machine_int_t mp_obj_hash(mp_obj_t o_in) {
8181
return mp_obj_str_get_hash(o_in);
8282
} else if (MP_OBJ_IS_TYPE(o_in, &mp_type_NoneType)) {
8383
return (machine_int_t)o_in;
84-
} else if (MP_OBJ_IS_TYPE(o_in, &fun_native_type) || MP_OBJ_IS_TYPE(o_in, &fun_bc_type)) {
84+
} else if (MP_OBJ_IS_TYPE(o_in, &mp_type_fun_native) || MP_OBJ_IS_TYPE(o_in, &mp_type_fun_bc)) {
8585
return (machine_int_t)o_in;
8686
} else if (MP_OBJ_IS_TYPE(o_in, &mp_type_tuple)) {
8787
return mp_obj_tuple_hash(o_in);
@@ -116,7 +116,7 @@ bool mp_obj_equal(mp_obj_t o1, mp_obj_t o2) {
116116
return val == 0;
117117
} else if (o2 == mp_const_true) {
118118
return val == 1;
119-
} else if (MP_OBJ_IS_TYPE(o2, &int_type)) {
119+
} else if (MP_OBJ_IS_TYPE(o2, &mp_type_int)) {
120120
// If o2 is long int, dispatch to its virtual methods
121121
mp_obj_base_t *o = o2;
122122
if (o->type->binary_op != NULL) {
@@ -161,7 +161,7 @@ machine_int_t mp_obj_get_int(mp_obj_t arg) {
161161
return 1;
162162
} else if (MP_OBJ_IS_SMALL_INT(arg)) {
163163
return MP_OBJ_SMALL_INT_VALUE(arg);
164-
} else if (MP_OBJ_IS_TYPE(arg, &int_type)) {
164+
} else if (MP_OBJ_IS_TYPE(arg, &mp_type_int)) {
165165
return mp_obj_int_get_checked(arg);
166166
} else {
167167
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) {
176176
return 1;
177177
} else if (MP_OBJ_IS_SMALL_INT(arg)) {
178178
return MP_OBJ_SMALL_INT_VALUE(arg);
179-
} else if (MP_OBJ_IS_TYPE(arg, &int_type)) {
179+
} else if (MP_OBJ_IS_TYPE(arg, &mp_type_int)) {
180180
return mp_obj_int_as_float(arg);
181181
} else if (MP_OBJ_IS_TYPE(arg, &mp_type_float)) {
182182
return mp_obj_float_get(arg);
@@ -209,15 +209,15 @@ void mp_obj_get_complex(mp_obj_t arg, mp_float_t *real, mp_float_t *imag) {
209209
void mp_obj_get_array(mp_obj_t o, uint *len, mp_obj_t **items) {
210210
if (MP_OBJ_IS_TYPE(o, &mp_type_tuple)) {
211211
mp_obj_tuple_get(o, len, items);
212-
} else if (MP_OBJ_IS_TYPE(o, &list_type)) {
212+
} else if (MP_OBJ_IS_TYPE(o, &mp_type_list)) {
213213
mp_obj_list_get(o, len, items);
214214
} else {
215215
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)));
216216
}
217217
}
218218

219219
void mp_obj_get_array_fixed_n(mp_obj_t o, uint len, mp_obj_t **items) {
220-
if (MP_OBJ_IS_TYPE(o, &mp_type_tuple) || MP_OBJ_IS_TYPE(o, &list_type)) {
220+
if (MP_OBJ_IS_TYPE(o, &mp_type_tuple) || MP_OBJ_IS_TYPE(o, &mp_type_list)) {
221221
uint seq_len;
222222
if (MP_OBJ_IS_TYPE(o, &mp_type_tuple)) {
223223
mp_obj_tuple_get(o, &seq_len, items);

py/obj.h

Lines changed: 29 additions & 49 deletions
Original file line numberDiff line numberDiff line change
@@ -36,8 +36,8 @@ typedef struct _mp_obj_base_t mp_obj_base_t;
3636
#define MP_OBJ_IS_QSTR(o) ((((mp_small_int_t)(o)) & 3) == 2)
3737
#define MP_OBJ_IS_OBJ(o) ((((mp_small_int_t)(o)) & 3) == 0)
3838
#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
39-
#define MP_OBJ_IS_INT(o) (MP_OBJ_IS_SMALL_INT(o) || MP_OBJ_IS_TYPE(o, &int_type))
40-
#define MP_OBJ_IS_STR(o) (MP_OBJ_IS_QSTR(o) || MP_OBJ_IS_TYPE(o, &str_type))
39+
#define MP_OBJ_IS_INT(o) (MP_OBJ_IS_SMALL_INT(o) || MP_OBJ_IS_TYPE(o, &mp_type_int))
40+
#define MP_OBJ_IS_STR(o) (MP_OBJ_IS_QSTR(o) || MP_OBJ_IS_TYPE(o, &mp_type_str))
4141

4242
#define MP_OBJ_SMALL_INT_VALUE(o) (((mp_small_int_t)(o)) >> 1)
4343
#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;
5050

5151
#define MP_DECLARE_CONST_FUN_OBJ(obj_name) extern const mp_obj_fun_native_t obj_name
5252

53-
#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}
53+
#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}
5454
#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)
5555
#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)
5656
#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;
6464

6565
#define MP_DEFINE_CONST_DICT(dict_name, table_name) \
6666
const mp_obj_dict_t dict_name = { \
67-
.base = {&dict_type}, \
67+
.base = {&mp_type_dict}, \
6868
.map = { \
6969
.all_keys_are_qstrs = 1, \
7070
.table_is_fixed_array = 1, \
@@ -197,6 +197,31 @@ typedef struct _mp_obj_type_t mp_obj_type_t;
197197

198198
// Constant types, globally accessible
199199
extern const mp_obj_type_t mp_type_type;
200+
extern const mp_obj_type_t mp_type_object;
201+
extern const mp_obj_type_t mp_type_NoneType;
202+
extern const mp_obj_type_t mp_type_bool;
203+
extern const mp_obj_type_t mp_type_int;
204+
extern const mp_obj_type_t mp_type_str;
205+
extern const mp_obj_type_t mp_type_bytes;
206+
extern const mp_obj_type_t mp_type_float;
207+
extern const mp_obj_type_t mp_type_complex;
208+
extern const mp_obj_type_t mp_type_tuple;
209+
extern const mp_obj_type_t mp_type_list;
210+
extern const mp_obj_type_t mp_type_map; // map (the python builtin, not the dict implementation detail)
211+
extern const mp_obj_type_t mp_type_enumerate;
212+
extern const mp_obj_type_t mp_type_filter;
213+
extern const mp_obj_type_t mp_type_dict;
214+
extern const mp_obj_type_t mp_type_set;
215+
extern const mp_obj_type_t mp_type_slice;
216+
extern const mp_obj_type_t mp_type_zip;
217+
extern const mp_obj_type_t mp_type_array;
218+
extern const mp_obj_type_t mp_type_super;
219+
extern const mp_obj_type_t mp_type_gen_instance;
220+
extern const mp_obj_type_t mp_type_fun_native;
221+
extern const mp_obj_type_t mp_type_fun_bc;
222+
extern const mp_obj_type_t mp_type_module;
223+
extern const mp_obj_type_t mp_type_staticmethod;
224+
extern const mp_obj_type_t mp_type_classmethod;
200225

201226
// Exceptions
202227
extern const mp_obj_type_t mp_type_BaseException;
@@ -299,22 +324,14 @@ void mp_obj_get_array_fixed_n(mp_obj_t o, uint len, mp_obj_t **items);
299324
uint mp_get_index(const mp_obj_type_t *type, machine_uint_t len, mp_obj_t index, bool is_slice);
300325
mp_obj_t mp_obj_len_maybe(mp_obj_t o_in); /* may return NULL */
301326

302-
// object
303-
extern const mp_obj_type_t mp_type_object;
304-
305-
// none
306-
extern const mp_obj_type_t mp_type_NoneType;
307-
308327
// bool
309-
extern const mp_obj_type_t mp_type_bool;
310328
#define MP_BOOL(x) (x ? mp_const_true : mp_const_false)
311329

312330
// cell
313331
mp_obj_t mp_obj_cell_get(mp_obj_t self_in);
314332
void mp_obj_cell_set(mp_obj_t self_in, mp_obj_t obj);
315333

316334
// int
317-
extern const mp_obj_type_t int_type;
318335
// For long int, returns value truncated to machine_int_t
319336
machine_int_t mp_obj_int_get(mp_obj_t self_in);
320337
#if MICROPY_ENABLE_FLOAT
@@ -333,7 +350,6 @@ void mp_obj_exception_get_traceback(mp_obj_t self_in, machine_uint_t *n, machine
333350
mp_obj_t mp_obj_exception_get_value(mp_obj_t self_in);
334351

335352
// str
336-
extern const mp_obj_type_t str_type;
337353
mp_obj_t mp_obj_str_builder_start(const mp_obj_type_t *type, uint len, byte **data);
338354
mp_obj_t mp_obj_str_builder_end(mp_obj_t o_in);
339355
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
344360
const char *mp_obj_str_get_data(mp_obj_t self_in, uint *len);
345361
void mp_str_print_quoted(void (*print)(void *env, const char *fmt, ...), void *env, const byte *str_data, uint str_len);
346362

347-
// bytes
348-
extern const mp_obj_type_t bytes_type;
349-
350363
#if MICROPY_ENABLE_FLOAT
351364
// float
352365
typedef struct _mp_obj_float_t {
353366
mp_obj_base_t base;
354367
mp_float_t value;
355368
} mp_obj_float_t;
356-
extern const mp_obj_type_t mp_type_float;
357369
mp_float_t mp_obj_float_get(mp_obj_t self_in);
358370
mp_obj_t mp_obj_float_binary_op(int op, mp_float_t lhs_val, mp_obj_t rhs);
359371

360372
// complex
361-
extern const mp_obj_type_t mp_type_complex;
362373
void mp_obj_complex_get(mp_obj_t self_in, mp_float_t *real, mp_float_t *imag);
363374
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);
364375
#endif
365376

366377
// tuple
367-
extern const mp_obj_type_t mp_type_tuple;
368378
void mp_obj_tuple_get(mp_obj_t self_in, uint *len, mp_obj_t **items);
369379
void mp_obj_tuple_del(mp_obj_t self_in);
370380
machine_int_t mp_obj_tuple_hash(mp_obj_t self_in);
371381

372382
// list
373-
extern const mp_obj_type_t list_type;
374383
mp_obj_t mp_obj_list_append(mp_obj_t self_in, mp_obj_t arg);
375384
void mp_obj_list_get(mp_obj_t self_in, uint *len, mp_obj_t **items);
376385
void mp_obj_list_store(mp_obj_t self_in, mp_obj_t index, mp_obj_t value);
377386
mp_obj_t mp_obj_list_sort(uint n_args, const mp_obj_t *args, struct _mp_map_t *kwargs);
378387

379-
// map (the python builtin, not the dict implementation detail)
380-
extern const mp_obj_type_t map_type;
381-
382-
// enumerate
383-
extern const mp_obj_type_t enumerate_type;
384-
385-
// filter
386-
extern const mp_obj_type_t filter_type;
387-
388388
// dict
389-
extern const mp_obj_type_t dict_type;
390389
uint mp_obj_dict_len(mp_obj_t self_in);
391390
mp_obj_t mp_obj_dict_store(mp_obj_t self_in, mp_obj_t key, mp_obj_t value);
392391
struct _mp_map_t *mp_obj_dict_get_map(mp_obj_t self_in);
393392

394393
// set
395-
extern const mp_obj_type_t set_type;
396394
void mp_obj_set_store(mp_obj_t self_in, mp_obj_t item);
397395

398396
// slice
399-
extern const mp_obj_type_t slice_type;
400397
void mp_obj_slice_get(mp_obj_t self_in, machine_int_t *start, machine_int_t *stop, machine_int_t *step);
401398

402-
// zip
403-
extern const mp_obj_type_t zip_type;
404-
405399
// array
406-
extern const mp_obj_type_t mp_type_array;
407400
uint mp_obj_array_len(mp_obj_t self_in);
408401
mp_obj_t mp_obj_new_bytearray_by_ref(uint n, void *items);
409402

@@ -420,33 +413,20 @@ typedef struct _mp_obj_fun_native_t { // need this so we can define const object
420413
// such functions won't be able to access the global scope, but that's probably okay
421414
} mp_obj_fun_native_t;
422415

423-
extern const mp_obj_type_t fun_native_type;
424-
extern const mp_obj_type_t fun_bc_type;
425416
void mp_obj_fun_bc_get(mp_obj_t self_in, int *n_args, const byte **code);
426417

427418
mp_obj_t mp_identity(mp_obj_t self);
428419
MP_DECLARE_CONST_FUN_OBJ(mp_identity_obj);
429420

430-
// super
431-
extern const mp_obj_type_t super_type;
432-
433-
// generator
434-
extern const mp_obj_type_t gen_instance_type;
435-
436421
// module
437422
typedef struct _mp_obj_module_t {
438423
mp_obj_base_t base;
439424
qstr name;
440425
struct _mp_map_t *globals;
441426
} mp_obj_module_t;
442-
extern const mp_obj_type_t mp_type_module;
443427
struct _mp_map_t *mp_obj_module_get_globals(mp_obj_t self_in);
444428

445429
// staticmethod and classmethod types; defined here so we can make const versions
446-
447-
extern const mp_obj_type_t mp_type_staticmethod;
448-
extern const mp_obj_type_t mp_type_classmethod;
449-
450430
// this structure is used for instances of both staticmethod and classmethod
451431
typedef struct _mp_obj_static_class_method_t {
452432
mp_obj_base_t base;

0 commit comments

Comments
 (0)