Commit a71c83a1 authored by Damien George's avatar Damien George
Browse files

Change mp_obj_type_t.name from const char * to qstr.

Ultimately all static strings should be qstr.  This entry in the type
structure is only used for printing error messages (to tell the type of
the bad argument), and printing objects that don't supply a .print method.
parent 8ac72b9d
......@@ -8,6 +8,9 @@ if platform.python_version_tuple()[0] == '2':
elif platform.python_version_tuple()[0] == '3':
from html.entities import codepoint2name
# add some custom names to map characters that aren't in HTML
codepoint2name[ord('.')] = 'dot'
# this must match the equivalent function in qstr.c
def compute_hash(qstr):
hash = 0
......
......@@ -26,7 +26,7 @@ mp_obj_type_t *mp_obj_get_type(mp_obj_t o_in) {
}
const char *mp_obj_get_type_str(mp_obj_t o_in) {
return mp_obj_get_type(o_in)->name;
return qstr_str(mp_obj_get_type(o_in)->name);
}
void printf_wrapper(void *env, const char *fmt, ...) {
......@@ -41,7 +41,7 @@ void mp_obj_print_helper(void (*print)(void *env, const char *fmt, ...), void *e
if (type->print != NULL) {
type->print(print, env, o_in, kind);
} else {
print(env, "<%s>", type->name);
print(env, "<%s>", qstr_str(type->name));
}
}
......@@ -226,11 +226,11 @@ uint mp_get_index(const mp_obj_type_t *type, machine_uint_t len, mp_obj_t index)
i += len;
}
if (i < 0 || i >= len) {
nlr_jump(mp_obj_new_exception_msg_varg(MP_QSTR_IndexError, "%s index out of range", type->name));
nlr_jump(mp_obj_new_exception_msg_varg(MP_QSTR_IndexError, "%s index out of range", qstr_str(type->name)));
}
return i;
} else {
nlr_jump(mp_obj_new_exception_msg_varg(MP_QSTR_TypeError, "%s indices must be integers, not %s", type->name, mp_obj_get_type_str(index)));
nlr_jump(mp_obj_new_exception_msg_varg(MP_QSTR_TypeError, "%s indices must be integers, not %s", qstr_str(type->name), mp_obj_get_type_str(index)));
}
}
......
......@@ -142,7 +142,7 @@ typedef struct _mp_stream_p_t {
struct _mp_obj_type_t {
mp_obj_base_t base;
const char *name;
qstr name;
mp_print_fun_t print;
mp_make_new_fun_t make_new; // to make an instance of the type
......@@ -150,6 +150,12 @@ struct _mp_obj_type_t {
mp_unary_op_fun_t unary_op; // can return NULL if op not supported
mp_binary_op_fun_t binary_op; // can return NULL if op not supported
mp_load_attr_fun_t load_attr;
mp_store_attr_fun_t store_attr;
// Implements container[index] = val; note that load_item is implemented
// by binary_op(RT_BINARY_OP_SUBSCR)
mp_store_item_fun_t store_item;
mp_fun_1_t getiter;
mp_fun_1_t iternext;
......@@ -161,12 +167,6 @@ struct _mp_obj_type_t {
const mp_method_t *methods;
mp_load_attr_fun_t load_attr;
mp_store_attr_fun_t store_attr;
// Implements container[index] = val; note that load_item is implemented
// by binary_op(RT_BINARY_OP_SUBSCR)
mp_store_item_fun_t store_item;
// these are for dynamically created types (classes)
mp_obj_t bases_tuple;
mp_obj_t locals_dict;
......@@ -200,7 +200,7 @@ extern const mp_obj_t mp_const_stop_iteration; // special object indicating end
// General API for objects
mp_obj_t mp_obj_new_type(const char *name, mp_obj_t bases_tuple, mp_obj_t locals_dict);
mp_obj_t mp_obj_new_type(qstr name, mp_obj_t bases_tuple, mp_obj_t locals_dict);
mp_obj_t mp_obj_new_none(void);
mp_obj_t mp_obj_new_bool(bool value);
mp_obj_t mp_obj_new_cell(mp_obj_t obj);
......
......@@ -161,7 +161,7 @@ STATIC const mp_method_t array_type_methods[] = {
const mp_obj_type_t array_type = {
{ &mp_const_type },
"array",
.name = MP_QSTR_array,
.print = array_print,
.make_new = array_make_new,
.getiter = array_iterator_new,
......@@ -223,7 +223,7 @@ mp_obj_t array_it_iternext(mp_obj_t self_in) {
STATIC const mp_obj_type_t array_it_type = {
{ &mp_const_type },
"array_iterator",
.name = MP_QSTR_iterator,
.iternext = array_it_iternext,
};
......
......@@ -47,7 +47,7 @@ STATIC mp_obj_t bool_unary_op(int op, mp_obj_t o_in) {
const mp_obj_type_t bool_type = {
{ &mp_const_type },
"bool",
.name = MP_QSTR_bool,
.print = bool_print,
.make_new = bool_make_new,
.unary_op = bool_unary_op,
......
......@@ -41,7 +41,7 @@ mp_obj_t bound_meth_call(mp_obj_t self_in, uint n_args, uint n_kw, const mp_obj_
const mp_obj_type_t bound_meth_type = {
{ &mp_const_type },
"bound_method",
.name = MP_QSTR_bound_method,
.call = bound_meth_call,
};
......
......@@ -26,7 +26,7 @@ void mp_obj_cell_set(mp_obj_t self_in, mp_obj_t obj) {
const mp_obj_type_t cell_type = {
{ &mp_const_type },
"cell",
.name = MP_QSTR_, // should never need to print cell type
};
mp_obj_t mp_obj_new_cell(mp_obj_t obj) {
......
......@@ -42,7 +42,7 @@ mp_obj_t closure_call(mp_obj_t self_in, uint n_args, uint n_kw, const mp_obj_t *
const mp_obj_type_t closure_type = {
{ &mp_const_type },
"closure",
.name = MP_QSTR_closure,
.call = closure_call,
};
......
......@@ -87,7 +87,7 @@ STATIC mp_obj_t complex_binary_op(int op, mp_obj_t lhs_in, mp_obj_t rhs_in) {
const mp_obj_type_t complex_type = {
{ &mp_const_type },
"complex",
.name = MP_QSTR_complex,
.print = complex_print,
.make_new = complex_make_new,
.unary_op = complex_unary_op,
......
......@@ -113,7 +113,7 @@ mp_obj_t dict_it_iternext(mp_obj_t self_in) {
STATIC const mp_obj_type_t dict_it_type = {
{ &mp_const_type },
"dict_iterator",
.name = MP_QSTR_iterator,
.iternext = dict_it_iternext,
};
......@@ -342,7 +342,7 @@ STATIC mp_obj_t dict_view_it_iternext(mp_obj_t self_in) {
STATIC const mp_obj_type_t dict_view_it_type = {
{ &mp_const_type },
"dict_view_iterator",
.name = MP_QSTR_iterator,
.iternext = dict_view_it_iternext,
.methods = NULL, /* set operations still to come */
};
......@@ -386,7 +386,7 @@ STATIC mp_obj_t dict_view_binary_op(int op, mp_obj_t lhs_in, mp_obj_t rhs_in) {
STATIC const mp_obj_type_t dict_view_type = {
{ &mp_const_type },
"dict_view",
.name = MP_QSTR_dict_view,
.print = dict_view_print,
.binary_op = dict_view_binary_op,
.getiter = dict_view_getiter,
......@@ -441,7 +441,7 @@ STATIC const mp_method_t dict_type_methods[] = {
const mp_obj_type_t dict_type = {
{ &mp_const_type },
"dict",
.name = MP_QSTR_dict,
.print = dict_print,
.make_new = dict_make_new,
.unary_op = dict_unary_op,
......
......@@ -28,7 +28,7 @@ STATIC mp_obj_t enumerate_make_new(mp_obj_t type_in, uint n_args, uint n_kw, con
const mp_obj_type_t enumerate_type = {
{ &mp_const_type },
"enumerate",
.name = MP_QSTR_enumerate,
.make_new = enumerate_make_new,
.iternext = enumerate_iternext,
.getiter = mp_identity,
......
......@@ -63,7 +63,7 @@ STATIC mp_obj_t exception_call(mp_obj_t self_in, uint n_args, uint n_kw, const m
const mp_obj_type_t exception_type = {
{ &mp_const_type },
"exception",
.name = MP_QSTR_, // TODO proper exception names
.print = exception_print,
.call = exception_call,
};
......
......@@ -46,7 +46,7 @@ STATIC mp_obj_t filter_iternext(mp_obj_t self_in) {
const mp_obj_type_t filter_type = {
{ &mp_const_type },
"filter",
.name = MP_QSTR_filter,
.make_new = filter_make_new,
.getiter = mp_identity,
.iternext = filter_iternext,
......
......@@ -65,7 +65,7 @@ STATIC mp_obj_t float_binary_op(int op, mp_obj_t lhs_in, mp_obj_t rhs_in) {
const mp_obj_type_t float_type = {
{ &mp_const_type },
"float",
.name = MP_QSTR_float,
.print = float_print,
.make_new = float_make_new,
.unary_op = float_unary_op,
......
......@@ -90,7 +90,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 = {
{ &mp_const_type },
"function",
.name = MP_QSTR_function,
.call = fun_native_call,
};
......@@ -160,7 +160,7 @@ STATIC mp_obj_t fun_bc_call(mp_obj_t self_in, uint n_args, uint n_kw, const mp_o
const mp_obj_type_t fun_bc_type = {
{ &mp_const_type },
"function",
.name = MP_QSTR_function,
.call = fun_bc_call,
};
......@@ -277,7 +277,7 @@ STATIC mp_obj_t fun_asm_call(mp_obj_t self_in, uint n_args, uint n_kw, const mp_
STATIC const mp_obj_type_t fun_asm_type = {
{ &mp_const_type },
"function",
.name = MP_QSTR_function,
.call = fun_asm_call,
};
......
......@@ -39,7 +39,7 @@ STATIC mp_obj_t gen_wrap_call(mp_obj_t self_in, uint n_args, uint n_kw, const mp
const mp_obj_type_t gen_wrap_type = {
{ &mp_const_type },
"generator",
.name = MP_QSTR_generator,
.call = gen_wrap_call,
};
......@@ -121,7 +121,7 @@ STATIC const mp_method_t gen_type_methods[] = {
const mp_obj_type_t gen_instance_type = {
{ &mp_const_type },
"generator",
.name = MP_QSTR_generator,
.print = gen_instance_print,
.getiter = gen_instance_getiter,
.iternext = gen_instance_iternext,
......
......@@ -38,7 +38,7 @@ STATIC mp_obj_t it_iternext(mp_obj_t self_in) {
STATIC const mp_obj_type_t it_type = {
{ &mp_const_type },
"iterator",
.name = MP_QSTR_iterator,
.iternext = it_iternext
};
......
......@@ -99,7 +99,7 @@ machine_int_t mp_obj_int_get_checked(mp_obj_t self_in) {
const mp_obj_type_t int_type = {
{ &mp_const_type },
"int",
.name = MP_QSTR_int,
.print = int_print,
.make_new = int_make_new,
.unary_op = int_unary_op,
......
......@@ -347,7 +347,7 @@ STATIC const mp_method_t list_type_methods[] = {
const mp_obj_type_t list_type = {
{ &mp_const_type },
"list",
.name = MP_QSTR_list,
.print = list_print,
.make_new = list_make_new,
.unary_op = list_unary_op,
......@@ -409,7 +409,7 @@ mp_obj_t list_it_iternext(mp_obj_t self_in) {
STATIC const mp_obj_type_t list_it_type = {
{ &mp_const_type },
"list_iterator",
.name = MP_QSTR_iterator,
.iternext = list_it_iternext,
};
......
......@@ -52,7 +52,7 @@ STATIC mp_obj_t map_iternext(mp_obj_t self_in) {
const mp_obj_type_t map_type = {
{ &mp_const_type },
"map",
.name = MP_QSTR_map,
.make_new = map_make_new,
.getiter = map_getiter,
.iternext = map_iternext,
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment