Commit 3e1a5c10 authored by Damien George's avatar Damien George
Browse files

py: Rename old const type objects to mp_type_* for consistency.

parent 07ddab52
...@@ -166,7 +166,7 @@ STATIC mp_obj_t mp_builtin_dir(uint n_args, const mp_obj_t *args) { ...@@ -166,7 +166,7 @@ STATIC mp_obj_t mp_builtin_dir(uint n_args, const mp_obj_t *args) {
} else { } else {
type = mp_obj_get_type(args[0]); 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); 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 ...@@ -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, nlr_jump(mp_obj_new_exception_msg(&mp_type_TypeError,
"must use keyword argument for key function")); "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); mp_obj_list_sort(1, &self, kwargs);
return self; return self;
......
...@@ -26,26 +26,26 @@ STATIC const mp_builtin_elem_t builtin_object_table[] = { ...@@ -26,26 +26,26 @@ STATIC const mp_builtin_elem_t builtin_object_table[] = {
// built-in types // built-in types
{ MP_QSTR_bool, (mp_obj_t)&mp_type_bool }, { 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 #if MICROPY_ENABLE_FLOAT
{ MP_QSTR_complex, (mp_obj_t)&mp_type_complex }, { MP_QSTR_complex, (mp_obj_t)&mp_type_complex },
#endif #endif
{ MP_QSTR_dict, (mp_obj_t)&dict_type }, { MP_QSTR_dict, (mp_obj_t)&mp_type_dict },
{ MP_QSTR_enumerate, (mp_obj_t)&enumerate_type }, { MP_QSTR_enumerate, (mp_obj_t)&mp_type_enumerate },
{ MP_QSTR_filter, (mp_obj_t)&filter_type }, { MP_QSTR_filter, (mp_obj_t)&mp_type_filter },
#if MICROPY_ENABLE_FLOAT #if MICROPY_ENABLE_FLOAT
{ MP_QSTR_float, (mp_obj_t)&mp_type_float }, { MP_QSTR_float, (mp_obj_t)&mp_type_float },
#endif #endif
{ MP_QSTR_int, (mp_obj_t)&int_type }, { MP_QSTR_int, (mp_obj_t)&mp_type_int },
{ MP_QSTR_list, (mp_obj_t)&list_type }, { MP_QSTR_list, (mp_obj_t)&mp_type_list },
{ MP_QSTR_map, (mp_obj_t)&map_type }, { MP_QSTR_map, (mp_obj_t)&mp_type_map },
{ MP_QSTR_object, (mp_obj_t)&mp_type_object }, { MP_QSTR_object, (mp_obj_t)&mp_type_object },
{ MP_QSTR_set, (mp_obj_t)&set_type }, { MP_QSTR_set, (mp_obj_t)&mp_type_set },
{ MP_QSTR_str, (mp_obj_t)&str_type }, { MP_QSTR_str, (mp_obj_t)&mp_type_str },
{ MP_QSTR_super, (mp_obj_t)&super_type }, { MP_QSTR_super, (mp_obj_t)&mp_type_super },
{ MP_QSTR_tuple, (mp_obj_t)&mp_type_tuple }, { MP_QSTR_tuple, (mp_obj_t)&mp_type_tuple },
{ MP_QSTR_type, (mp_obj_t)&mp_type_type }, { 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_classmethod, (mp_obj_t)&mp_type_classmethod },
{ MP_QSTR_staticmethod, (mp_obj_t)&mp_type_staticmethod }, { MP_QSTR_staticmethod, (mp_obj_t)&mp_type_staticmethod },
......
...@@ -13,9 +13,9 @@ ...@@ -13,9 +13,9 @@
mp_obj_type_t *mp_obj_get_type(mp_obj_t o_in) { mp_obj_type_t *mp_obj_get_type(mp_obj_t o_in) {
if (MP_OBJ_IS_SMALL_INT(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)) { } else if (MP_OBJ_IS_QSTR(o_in)) {
return (mp_obj_t)&str_type; return (mp_obj_t)&mp_type_str;
} else { } else {
mp_obj_base_t *o = o_in; mp_obj_base_t *o = o_in;
return (mp_obj_t)o->type; return (mp_obj_t)o->type;
...@@ -81,7 +81,7 @@ machine_int_t mp_obj_hash(mp_obj_t o_in) { ...@@ -81,7 +81,7 @@ machine_int_t mp_obj_hash(mp_obj_t o_in) {
return mp_obj_str_get_hash(o_in); return mp_obj_str_get_hash(o_in);
} else if (MP_OBJ_IS_TYPE(o_in, &mp_type_NoneType)) { } else if (MP_OBJ_IS_TYPE(o_in, &mp_type_NoneType)) {
return (machine_int_t)o_in; 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; return (machine_int_t)o_in;
} else if (MP_OBJ_IS_TYPE(o_in, &mp_type_tuple)) { } else if (MP_OBJ_IS_TYPE(o_in, &mp_type_tuple)) {
return mp_obj_tuple_hash(o_in); return mp_obj_tuple_hash(o_in);
...@@ -116,7 +116,7 @@ bool mp_obj_equal(mp_obj_t o1, mp_obj_t o2) { ...@@ -116,7 +116,7 @@ bool mp_obj_equal(mp_obj_t o1, mp_obj_t o2) {
return val == 0; return val == 0;
} else if (o2 == mp_const_true) { } else if (o2 == mp_const_true) {
return val == 1; 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 // If o2 is long int, dispatch to its virtual methods
mp_obj_base_t *o = o2; mp_obj_base_t *o = o2;
if (o->type->binary_op != NULL) { if (o->type->binary_op != NULL) {
...@@ -161,7 +161,7 @@ machine_int_t mp_obj_get_int(mp_obj_t arg) { ...@@ -161,7 +161,7 @@ machine_int_t mp_obj_get_int(mp_obj_t arg) {
return 1; return 1;
} else if (MP_OBJ_IS_SMALL_INT(arg)) { } else if (MP_OBJ_IS_SMALL_INT(arg)) {
return MP_OBJ_SMALL_INT_VALUE(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); return mp_obj_int_get_checked(arg);
} else { } else {
nlr_jump(mp_obj_new_exception_msg_varg(&mp_type_TypeError, "can't convert %s to int", mp_obj_get_type_str(arg))); 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) { ...@@ -176,7 +176,7 @@ mp_float_t mp_obj_get_float(mp_obj_t arg) {
return 1; return 1;
} else if (MP_OBJ_IS_SMALL_INT(arg)) { } else if (MP_OBJ_IS_SMALL_INT(arg)) {
return MP_OBJ_SMALL_INT_VALUE(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); return mp_obj_int_as_float(arg);
} else if (MP_OBJ_IS_TYPE(arg, &mp_type_float)) { } else if (MP_OBJ_IS_TYPE(arg, &mp_type_float)) {
return mp_obj_float_get(arg); 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) { ...@@ -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) { void mp_obj_get_array(mp_obj_t o, uint *len, mp_obj_t **items) {
if (MP_OBJ_IS_TYPE(o, &mp_type_tuple)) { if (MP_OBJ_IS_TYPE(o, &mp_type_tuple)) {
mp_obj_tuple_get(o, len, items); 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); mp_obj_list_get(o, len, items);
} else { } 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))); 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) { ...@@ -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) { 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; uint seq_len;
if (MP_OBJ_IS_TYPE(o, &mp_type_tuple)) { if (MP_OBJ_IS_TYPE(o, &mp_type_tuple)) {
mp_obj_tuple_get(o, &seq_len, items); mp_obj_tuple_get(o, &seq_len, items);
......
...@@ -36,8 +36,8 @@ typedef struct _mp_obj_base_t mp_obj_base_t; ...@@ -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_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_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_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_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, &str_type)) #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_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)) #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; ...@@ -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_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_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_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) #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; ...@@ -64,7 +64,7 @@ typedef struct _mp_obj_base_t mp_obj_base_t;
#define MP_DEFINE_CONST_DICT(dict_name, table_name) \ #define MP_DEFINE_CONST_DICT(dict_name, table_name) \
const mp_obj_dict_t dict_name = { \ const mp_obj_dict_t dict_name = { \
.base = {&dict_type}, \ .base = {&mp_type_dict}, \
.map = { \ .map = { \
.all_keys_are_qstrs = 1, \ .all_keys_are_qstrs = 1, \
.table_is_fixed_array = 1, \ .table_is_fixed_array = 1, \
...@@ -197,6 +197,31 @@ typedef struct _mp_obj_type_t mp_obj_type_t; ...@@ -197,6 +197,31 @@ typedef struct _mp_obj_type_t mp_obj_type_t;
// Constant types, globally accessible // Constant types, globally accessible
extern const mp_obj_type_t mp_type_type; 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 // Exceptions
extern const mp_obj_type_t mp_type_BaseException; 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); ...@@ -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); 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 */ 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 // bool
extern const mp_obj_type_t mp_type_bool;
#define MP_BOOL(x) (x ? mp_const_true : mp_const_false) #define MP_BOOL(x) (x ? mp_const_true : mp_const_false)
// cell // cell
...@@ -314,7 +332,6 @@ mp_obj_t mp_obj_cell_get(mp_obj_t self_in); ...@@ -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); void mp_obj_cell_set(mp_obj_t self_in, mp_obj_t obj);
// int // int
extern const mp_obj_type_t int_type;
// For long int, returns value truncated to machine_int_t // For long int, returns value truncated to machine_int_t
machine_int_t mp_obj_int_get(mp_obj_t self_in); machine_int_t mp_obj_int_get(mp_obj_t self_in);
#if MICROPY_ENABLE_FLOAT #if MICROPY_ENABLE_FLOAT
...@@ -333,7 +350,6 @@ void mp_obj_exception_get_traceback(mp_obj_t self_in, machine_uint_t *n, machine ...@@ -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); mp_obj_t mp_obj_exception_get_value(mp_obj_t self_in);
// str // 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_start(const mp_obj_type_t *type, uint len, byte **data);
mp_obj_t mp_obj_str_builder_end(mp_obj_t o_in); 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); 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 ...@@ -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); 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); 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 #if MICROPY_ENABLE_FLOAT
// float // float
typedef struct _mp_obj_float_t { typedef struct _mp_obj_float_t {
mp_obj_base_t base; mp_obj_base_t base;
mp_float_t value; mp_float_t value;
} mp_obj_float_t; } 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_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); mp_obj_t mp_obj_float_binary_op(int op, mp_float_t lhs_val, mp_obj_t rhs);
// complex // 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); 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); 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 #endif
// tuple // 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_get(mp_obj_t self_in, uint *len, mp_obj_t **items);
void mp_obj_tuple_del(mp_obj_t self_in); void mp_obj_tuple_del(mp_obj_t self_in);
machine_int_t mp_obj_tuple_hash(mp_obj_t self_in); machine_int_t mp_obj_tuple_hash(mp_obj_t self_in);
// list // 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); 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_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); 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); 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 // dict
extern const mp_obj_type_t dict_type;
uint mp_obj_dict_len(mp_obj_t self_in); 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); 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); struct _mp_map_t *mp_obj_dict_get_map(mp_obj_t self_in);
// set // set
extern const mp_obj_type_t set_type;
void mp_obj_set_store(mp_obj_t self_in, mp_obj_t item); void mp_obj_set_store(mp_obj_t self_in, mp_obj_t item);
// slice // 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); 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 // array
extern const mp_obj_type_t mp_type_array;
uint mp_obj_array_len(mp_obj_t self_in); uint mp_obj_array_len(mp_obj_t self_in);
mp_obj_t mp_obj_new_bytearray_by_ref(uint n, void *items); 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 ...@@ -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 // such functions won't be able to access the global scope, but that's probably okay
} mp_obj_fun_native_t; } 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); 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_obj_t mp_identity(mp_obj_t self);
MP_DECLARE_CONST_FUN_OBJ(mp_identity_obj); 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 // module
typedef struct _mp_obj_module_t { typedef struct _mp_obj_module_t {
mp_obj_base_t base; mp_obj_base_t base;
qstr name; qstr name;
struct _mp_map_t *globals; struct _mp_map_t *globals;
} mp_obj_module_t; } 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); 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 // 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 // this structure is used for instances of both staticmethod and classmethod
typedef struct _mp_obj_static_class_method_t { typedef struct _mp_obj_static_class_method_t {
mp_obj_base_t base; mp_obj_base_t base;
......
...@@ -105,7 +105,7 @@ mp_obj_t dict_it_iternext(mp_obj_t self_in) { ...@@ -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 }, { &mp_type_type },
.name = MP_QSTR_iterator, .name = MP_QSTR_iterator,
.iternext = dict_it_iternext, .iternext = dict_it_iternext,
...@@ -113,7 +113,7 @@ STATIC const mp_obj_type_t dict_it_type = { ...@@ -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) { 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); 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->dict = dict;
o->cur = cur; o->cur = cur;
return o; return o;
...@@ -127,7 +127,7 @@ STATIC mp_obj_t dict_getiter(mp_obj_t o_in) { ...@@ -127,7 +127,7 @@ STATIC mp_obj_t dict_getiter(mp_obj_t o_in) {
/* dict methods */ /* dict methods */
STATIC mp_obj_t dict_clear(mp_obj_t self_in) { 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_obj_dict_t *self = self_in;
mp_map_clear(&self->map); mp_map_clear(&self->map);
...@@ -137,7 +137,7 @@ STATIC mp_obj_t dict_clear(mp_obj_t self_in) { ...@@ -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_DEFINE_CONST_FUN_OBJ_1(dict_clear_obj, dict_clear);
STATIC mp_obj_t dict_copy(mp_obj_t self_in) { 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 *self = self_in;
mp_obj_dict_t *other = mp_obj_new_dict(self->map.alloc); mp_obj_dict_t *other = mp_obj_new_dict(self->map.alloc);
other->map.used = self->map.used; 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 ...@@ -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) { STATIC mp_obj_t dict_get(uint n_args, const mp_obj_t *args) {
assert(2 <= n_args && n_args <= 3); 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, return dict_get_helper(&((mp_obj_dict_t *)args[0])->map,
args[1], args[1],
...@@ -214,7 +214,7 @@ STATIC MP_DEFINE_CONST_FUN_OBJ_VAR_BETWEEN(dict_get_obj, 2, 3, dict_get); ...@@ -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) { STATIC mp_obj_t dict_pop(uint n_args, const mp_obj_t *args) {
assert(2 <= n_args && n_args <= 3); 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, return dict_get_helper(&((mp_obj_dict_t *)args[0])->map,
args[1], args[1],
...@@ -226,7 +226,7 @@ STATIC MP_DEFINE_CONST_FUN_OBJ_VAR_BETWEEN(dict_pop_obj, 2, 3, dict_pop); ...@@ -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) { STATIC mp_obj_t dict_setdefault(uint n_args, const mp_obj_t *args) {
assert(2 <= n_args && n_args <= 3); 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, return dict_get_helper(&((mp_obj_dict_t *)args[0])->map,
args[1], args[1],
...@@ -237,7 +237,7 @@ STATIC MP_DEFINE_CONST_FUN_OBJ_VAR_BETWEEN(dict_setdefault_obj, 2, 3, dict_setde ...@@ -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) { 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; mp_obj_dict_t *self = self_in;
if (self->map.used == 0) { if (self->map.used == 0) {
nlr_jump(mp_obj_new_exception_msg(&mp_type_KeyError, "popitem(): dictionary is empty")); 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) { ...@@ -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_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) { 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; mp_obj_dict_t *self = self_in;
/* TODO: check for the "keys" method */ /* TODO: check for the "keys" method */
mp_obj_t iter = rt_getiter(iterable); 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) { ...@@ -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) { 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; mp_obj_dict_t *self = self_in;
return mp_obj_new_dict_view(self, kind); return mp_obj_new_dict_view(self, kind);
} }
...@@ -433,7 +433,7 @@ STATIC const mp_map_elem_t dict_locals_dict_table[] = { ...@@ -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); 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 }, { &mp_type_type },
.name = MP_QSTR_dict, .name = MP_QSTR_dict,
.print = dict_print, .print = dict_print,
...@@ -446,7 +446,7 @@ const mp_obj_type_t dict_type = { ...@@ -446,7 +446,7 @@ const mp_obj_type_t dict_type = {
mp_obj_t mp_obj_new_dict(int n_args) { mp_obj_t mp_obj_new_dict(int n_args) {
mp_obj_dict_t *o = m_new_obj(mp_obj_dict_t); 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); mp_map_init(&o->map, n_args);
return o; return o;
} }
...@@ -456,14 +456,14 @@ uint mp_obj_dict_len(mp_obj_t self_in) { ...@@ -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) { 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));