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
......@@ -39,7 +39,7 @@ STATIC bool module_store_attr(mp_obj_t self_in, qstr attr, mp_obj_t value) {
const mp_obj_type_t module_type = {
{ &mp_const_type },
"module",
.name = MP_QSTR_module,
.print = module_print,
.load_attr = module_load_attr,
.store_attr = module_store_attr,
......
......@@ -25,7 +25,7 @@ STATIC mp_obj_t none_unary_op(int op, mp_obj_t o_in) {
const mp_obj_type_t none_type = {
{ &mp_const_type },
"NoneType",
.name = MP_QSTR_NoneType,
.print = none_print,
.unary_op = none_unary_op,
};
......
......@@ -25,7 +25,7 @@ STATIC mp_obj_t range_getiter(mp_obj_t o_in) {
STATIC const mp_obj_type_t range_type = {
{ &mp_const_type} ,
"range",
.name = MP_QSTR_range,
.getiter = range_getiter,
};
......@@ -63,7 +63,7 @@ STATIC mp_obj_t range_it_iternext(mp_obj_t o_in) {
STATIC const mp_obj_type_t range_it_type = {
{ &mp_const_type },
"range_iterator",
.name = MP_QSTR_iterator,
.iternext = range_it_iternext,
};
......
......@@ -73,7 +73,7 @@ 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 = {
{ &mp_const_type },
"set_iterator",
.name = MP_QSTR_iterator,
.iternext = set_it_iternext,
};
......@@ -447,7 +447,7 @@ STATIC const mp_method_t set_type_methods[] = {
const mp_obj_type_t set_type = {
{ &mp_const_type },
"set",
.name = MP_QSTR_set,
.print = set_print,
.make_new = set_make_new,
.binary_op = set_binary_op,
......
......@@ -23,7 +23,7 @@ void ellipsis_print(void (*print)(void *env, const char *fmt, ...), void *env, m
const mp_obj_type_t ellipsis_type = {
{ &mp_const_type },
"ellipsis",
.name = MP_QSTR_Ellipsis,
.print = ellipsis_print,
};
......@@ -50,7 +50,7 @@ void slice_print(void (*print)(void *env, const char *fmt, ...), void *env, mp_o
const mp_obj_type_t slice_type = {
{ &mp_const_type },
"slice",
.name = MP_QSTR_slice,
.print = slice_print,
};
......
......@@ -508,7 +508,7 @@ STATIC const mp_method_t str_type_methods[] = {
const mp_obj_type_t str_type = {
{ &mp_const_type },
"str",
.name = MP_QSTR_str,
.print = str_print,
.binary_op = str_binary_op,
.getiter = mp_obj_new_str_iterator,
......@@ -518,7 +518,7 @@ const mp_obj_type_t str_type = {
// Reuses most of methods from str
const mp_obj_type_t bytes_type = {
{ &mp_const_type },
"bytes",
.name = MP_QSTR_bytes,
.print = str_print,
.binary_op = str_binary_op,
.getiter = mp_obj_new_bytes_iterator,
......@@ -668,7 +668,7 @@ STATIC mp_obj_t str_it_iternext(mp_obj_t self_in) {
STATIC const mp_obj_type_t str_it_type = {
{ &mp_const_type },
"str_iterator",
.name = MP_QSTR_iterator,
.iternext = str_it_iternext,
};
......@@ -686,7 +686,7 @@ STATIC mp_obj_t bytes_it_iternext(mp_obj_t self_in) {
STATIC const mp_obj_type_t bytes_it_type = {
{ &mp_const_type },
"bytes_iterator",
.name = MP_QSTR_iterator,
.iternext = bytes_it_iternext,
};
......
......@@ -175,7 +175,7 @@ STATIC const mp_method_t tuple_type_methods[] = {
const mp_obj_type_t tuple_type = {
{ &mp_const_type },
"tuple",
.name = MP_QSTR_tuple,
.print = tuple_print,
.make_new = tuple_make_new,
.unary_op = tuple_unary_op,
......@@ -242,7 +242,7 @@ STATIC mp_obj_t tuple_it_iternext(mp_obj_t self_in) {
STATIC const mp_obj_type_t tuple_it_type = {
{ &mp_const_type },
"tuple_iterator",
.name = MP_QSTR_iterator,
.iternext = tuple_it_iternext,
};
......
......@@ -257,7 +257,7 @@ bool class_store_item(mp_obj_t self_in, mp_obj_t index, mp_obj_t value) {
STATIC void type_print(void (*print)(void *env, const char *fmt, ...), void *env, mp_obj_t self_in, mp_print_kind_t kind) {
mp_obj_type_t *self = self_in;
print(env, "<class '%s'>", self->name);
print(env, "<class '%s'>", qstr_str(self->name));
}
STATIC mp_obj_t type_make_new(mp_obj_t type_in, uint n_args, uint n_kw, const mp_obj_t *args) {
......@@ -271,7 +271,7 @@ STATIC mp_obj_t type_make_new(mp_obj_t type_in, uint n_args, uint n_kw, const mp
// args[0] = name
// args[1] = bases tuple
// args[2] = locals dict
return mp_obj_new_type(mp_obj_str_get_str(args[0]), args[1], args[2]);
return mp_obj_new_type(mp_obj_str_get_qstr(args[0]), args[1], args[2]);
default:
nlr_jump(mp_obj_new_exception_msg(MP_QSTR_TypeError, "type takes 1 or 3 arguments"));
......@@ -284,7 +284,7 @@ STATIC mp_obj_t type_call(mp_obj_t self_in, uint n_args, uint n_kw, const mp_obj
mp_obj_type_t *self = self_in;
if (self->make_new == NULL) {
nlr_jump(mp_obj_new_exception_msg_varg(MP_QSTR_TypeError, "cannot create '%s' instances", self->name));
nlr_jump(mp_obj_new_exception_msg_varg(MP_QSTR_TypeError, "cannot create '%s' instances", qstr_str(self->name)));
}
// make new instance
......@@ -335,7 +335,7 @@ STATIC bool type_store_attr(mp_obj_t self_in, qstr attr, mp_obj_t value) {
const mp_obj_type_t mp_const_type = {
{ &mp_const_type },
"type",
.name = MP_QSTR_type,
.print = type_print,
.make_new = type_make_new,
.call = type_call,
......@@ -343,7 +343,7 @@ const mp_obj_type_t mp_const_type = {
.store_attr = type_store_attr,
};
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) {
assert(MP_OBJ_IS_TYPE(bases_tuple, &tuple_type)); // Micro Python restriction, for now
assert(MP_OBJ_IS_TYPE(locals_dict, &dict_type)); // Micro Python restriction, for now
mp_obj_type_t *o = m_new0(mp_obj_type_t, 1);
......@@ -439,7 +439,7 @@ STATIC void super_load_attr(mp_obj_t self_in, qstr attr, mp_obj_t *dest) {
const mp_obj_type_t super_type = {
{ &mp_const_type },
"super",
.name = MP_QSTR_super,
.print = super_print,
.make_new = super_make_new,
.load_attr = super_load_attr,
......@@ -521,12 +521,12 @@ STATIC mp_obj_t static_class_method_make_new(mp_obj_t self_in, uint n_args, uint
const mp_obj_type_t mp_type_staticmethod = {
{ &mp_const_type },
"staticmethod",
.name = MP_QSTR_staticmethod,
.make_new = static_class_method_make_new
};
const mp_obj_type_t mp_type_classmethod = {
{ &mp_const_type },
"classmethod",
.name = MP_QSTR_classmethod,
.make_new = static_class_method_make_new
};
......@@ -52,7 +52,7 @@ STATIC mp_obj_t zip_iternext(mp_obj_t self_in) {
const mp_obj_type_t zip_type = {
{ &mp_const_type },
"zip",
.name = MP_QSTR_zip,
.make_new = zip_make_new,
.getiter = zip_getiter,
.iternext = zip_iternext,
......
......@@ -44,6 +44,8 @@ Q(TypeError)
Q(ValueError)
Q(OverflowError)
Q(NoneType)
Q(abs)
Q(all)
Q(any)
......@@ -101,6 +103,15 @@ Q(format)
Q(key)
Q(reverse)
Q(bound_method)
Q(closure)
Q(dict_view)
Q(function)
Q(generator)
Q(iterator)
Q(module)
Q(slice)
Q(<module>)
Q(<lambda>)
Q(<listcomp>)
......
......@@ -18,7 +18,7 @@ DFU=../tools/dfu.py
CROSS_COMPILE = arm-none-eabi-
CFLAGS_CORTEX_M4 = -mthumb -mtune=cortex-m4 -mabi=aapcs-linux -mcpu=cortex-m4 -mfpu=fpv4-sp-d16 -mfloat-abi=hard -fsingle-precision-constant -Wdouble-promotion
CFLAGS = -I. -I$(PY_SRC) -I$(CMSIS_DIR) -I$(STMPERIPH_DIR) -I$(STMUSB_DIR) -Wall -ansi -std=gnu99 $(CFLAGS_CORTEX_M4) $(COPT)
CFLAGS = -I. -I$(PY_SRC) -I$(CMSIS_DIR) -I$(STMPERIPH_DIR) -I$(STMUSB_DIR) -Wall -Werror -ansi -std=gnu99 $(CFLAGS_CORTEX_M4) $(COPT)
CFLAGS += -I$(STMUSBD_DIR)
CFLAGS += -I$(STMUSBH_DIR)
CFLAGS += -I$(FATFS_DIR)
......
......@@ -333,7 +333,7 @@ static const mp_method_t adc_all_methods[] = {
static const mp_obj_type_t adc_all_type = {
{ &mp_const_type },
"ADC_all",
.name = MP_QSTR_ADC,
.print = adc_all_print,
.methods = adc_all_methods,
};
......@@ -387,7 +387,7 @@ static const mp_method_t adc_methods[] = {
static const mp_obj_type_t adc_type = {
{ &mp_const_type },
"ADC",
.name = MP_QSTR_ADC,
.print = adc_print,
.methods = adc_methods,
};
......
......@@ -61,7 +61,7 @@ static const mp_method_t file_methods[] = {
static const mp_obj_type_t file_obj_type = {
{ &mp_const_type },
"File",
.name = MP_QSTR_File,
.print = file_obj_print,
.methods = file_methods,
};
......
......@@ -336,7 +336,7 @@ static const mp_method_t i2c_methods[] = {
static const mp_obj_type_t i2c_obj_type = {
{ &mp_const_type },
"I2C",
.name = MP_QSTR_I2C,
.print = i2c_obj_print,
.methods = i2c_methods,
};
......
......@@ -287,7 +287,7 @@ static mp_obj_t pyb_lcd_init(void) {
lcd_next_line = 0;
// Micro Python interface
mp_obj_t o = mp_obj_new_type("LCD", mp_const_empty_tuple, mp_obj_new_dict(0));
mp_obj_t o = mp_obj_new_type(MP_QSTR_LCD, mp_const_empty_tuple, mp_obj_new_dict(0));
rt_store_attr(o, qstr_from_str("lcd8"), rt_make_function_n(2, lcd_draw_pixel_8));
rt_store_attr(o, qstr_from_str("clear"), rt_make_function_n(0, lcd_pix_clear));
rt_store_attr(o, qstr_from_str("get"), rt_make_function_n(2, lcd_pix_get));
......
......@@ -149,7 +149,7 @@ static const mp_method_t led_methods[] = {
static const mp_obj_type_t led_obj_type = {
{ &mp_const_type },
"Led",
.name = MP_QSTR_Led,
.print = led_obj_print,
.methods = led_methods,
};
......
......@@ -21,9 +21,12 @@ Q(hid)
Q(time)
Q(rand)
Q(Led)
Q(LCD)
Q(Servo)
Q(SDcard)
Q(I2C)
Q(gpio)
Q(Usart)
Q(ADC)
Q(open)
Q(File)
......@@ -203,7 +203,7 @@ static const mp_method_t sdcard_methods[] = {
static const mp_obj_type_t sdcard_type = {
{ &mp_const_type },
"SDcard",
.name = MP_QSTR_SDcard,
.methods = sdcard_methods,
};
......
......@@ -145,7 +145,7 @@ static const mp_method_t servo_methods[] = {
static const mp_obj_type_t servo_obj_type = {
{ &mp_const_type },
"Servo",
.name = MP_QSTR_Servo,
.print = servo_obj_print,
.methods = servo_methods,
};
......
......@@ -243,7 +243,7 @@ static const mp_method_t usart_methods[] = {
static const mp_obj_type_t usart_obj_type = {
{ &mp_const_type },
"Usart",
.name = MP_QSTR_Usart,
.print = usart_obj_print,
.methods = usart_methods,
};
......
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