@@ -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
199199extern 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
202227extern 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);
299324uint mp_get_index (const mp_obj_type_t * type , machine_uint_t len , mp_obj_t index , bool is_slice );
300325mp_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
313331mp_obj_t mp_obj_cell_get (mp_obj_t self_in );
314332void 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
319336machine_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
333350mp_obj_t mp_obj_exception_get_value (mp_obj_t self_in );
334351
335352// str
336- extern const mp_obj_type_t str_type ;
337353mp_obj_t mp_obj_str_builder_start (const mp_obj_type_t * type , uint len , byte * * data );
338354mp_obj_t mp_obj_str_builder_end (mp_obj_t o_in );
339355bool 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
344360const char * mp_obj_str_get_data (mp_obj_t self_in , uint * len );
345361void 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
352365typedef 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 ;
357369mp_float_t mp_obj_float_get (mp_obj_t self_in );
358370mp_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 ;
362373void mp_obj_complex_get (mp_obj_t self_in , mp_float_t * real , mp_float_t * imag );
363374mp_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 ;
368378void mp_obj_tuple_get (mp_obj_t self_in , uint * len , mp_obj_t * * items );
369379void mp_obj_tuple_del (mp_obj_t self_in );
370380machine_int_t mp_obj_tuple_hash (mp_obj_t self_in );
371381
372382// list
373- extern const mp_obj_type_t list_type ;
374383mp_obj_t mp_obj_list_append (mp_obj_t self_in , mp_obj_t arg );
375384void mp_obj_list_get (mp_obj_t self_in , uint * len , mp_obj_t * * items );
376385void mp_obj_list_store (mp_obj_t self_in , mp_obj_t index , mp_obj_t value );
377386mp_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 ;
390389uint mp_obj_dict_len (mp_obj_t self_in );
391390mp_obj_t mp_obj_dict_store (mp_obj_t self_in , mp_obj_t key , mp_obj_t value );
392391struct _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 ;
396394void 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 ;
400397void 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 ;
407400uint mp_obj_array_len (mp_obj_t self_in );
408401mp_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 ;
425416void mp_obj_fun_bc_get (mp_obj_t self_in , int * n_args , const byte * * code );
426417
427418mp_obj_t mp_identity (mp_obj_t self );
428419MP_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
437422typedef 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 ;
443427struct _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
451431typedef struct _mp_obj_static_class_method_t {
452432 mp_obj_base_t base ;
0 commit comments