Convert many object types structs to use C99 tagged initializer syntax.

This commit is contained in:
Paul Sokolovsky 2014-01-05 22:34:09 +02:00
parent 12e2656472
commit 860ffb0a43
27 changed files with 73 additions and 147 deletions

View File

@ -41,7 +41,7 @@ const mp_obj_type_t bool_type = {
NULL, // binary_op NULL, // binary_op
NULL, // getiter NULL, // getiter
NULL, // iternext NULL, // iternext
{{NULL, NULL},}, // method list .methods = {{NULL, NULL},},
}; };
static const mp_obj_bool_t false_obj = {{&bool_type}, false}; static const mp_obj_bool_t false_obj = {{&bool_type}, false};

View File

@ -43,7 +43,7 @@ const mp_obj_type_t bound_meth_type = {
NULL, // binary_op NULL, // binary_op
NULL, // getiter NULL, // getiter
NULL, // iternext NULL, // iternext
{{NULL, NULL},}, // method list .methods = {{NULL, NULL},},
}; };
mp_obj_t mp_obj_new_bound_meth(mp_obj_t self, mp_obj_t meth) { mp_obj_t mp_obj_new_bound_meth(mp_obj_t self, mp_obj_t meth) {

View File

@ -33,7 +33,7 @@ const mp_obj_type_t cell_type = {
NULL, // binary_op NULL, // binary_op
NULL, // getiter NULL, // getiter
NULL, // iternext NULL, // iternext
{{NULL, NULL},}, // method list .methods = {{NULL, NULL},},
}; };
mp_obj_t mp_obj_new_cell(mp_obj_t obj) { mp_obj_t mp_obj_new_cell(mp_obj_t obj) {

View File

@ -70,7 +70,7 @@ const mp_obj_type_t class_type = {
NULL, // binary_op NULL, // binary_op
NULL, // getiter NULL, // getiter
NULL, // iternext NULL, // iternext
{{NULL, NULL},}, // method list .methods = {{NULL, NULL},},
}; };
mp_obj_t mp_obj_new_class(mp_map_t *class_locals) { mp_obj_t mp_obj_new_class(mp_map_t *class_locals) {

View File

@ -42,7 +42,7 @@ const mp_obj_type_t closure_type = {
NULL, // binary_op NULL, // binary_op
NULL, // getiter NULL, // getiter
NULL, // iternext NULL, // iternext
{{NULL, NULL},}, // method list .methods = {{NULL, NULL},},
}; };
mp_obj_t mp_obj_new_closure(mp_obj_t fun, mp_obj_t closure_tuple) { mp_obj_t mp_obj_new_closure(mp_obj_t fun, mp_obj_t closure_tuple) {

View File

@ -125,7 +125,7 @@ const mp_obj_type_t complex_type = {
complex_binary_op, // binary_op complex_binary_op, // binary_op
NULL, // getiter NULL, // getiter
NULL, // iternext NULL, // iternext
{ { NULL, NULL }, }, // method list .methods = { { NULL, NULL }, },
}; };
mp_obj_t mp_obj_new_complex(mp_float_t real, mp_float_t imag) { mp_obj_t mp_obj_new_complex(mp_float_t real, mp_float_t imag) {

View File

@ -63,14 +63,11 @@ static mp_obj_t dict_binary_op(int op, mp_obj_t lhs_in, mp_obj_t rhs_in) {
const mp_obj_type_t dict_type = { const mp_obj_type_t dict_type = {
{ &mp_const_type }, { &mp_const_type },
"dict", "dict",
dict_print, // print .print = dict_print,
dict_make_new, // make_new .make_new = dict_make_new,
NULL, // call_n .binary_op = dict_binary_op,
NULL, // unary_op .getiter = NULL,
dict_binary_op, // binary_op .methods = {{NULL, NULL},},
NULL, // getiter
NULL, // iternext
{{NULL, NULL},}, // method list
}; };
mp_obj_t mp_obj_new_dict(int n_args) { mp_obj_t mp_obj_new_dict(int n_args) {

View File

@ -45,7 +45,7 @@ const mp_obj_type_t exception_type = {
NULL, // binary_op NULL, // binary_op
NULL, // getiter NULL, // getiter
NULL, // iternext NULL, // iternext
{{NULL, NULL},}, // method list .methods = {{NULL, NULL},},
}; };
mp_obj_t mp_obj_new_exception(qstr id) { mp_obj_t mp_obj_new_exception(qstr id) {

View File

@ -79,14 +79,11 @@ 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 = { const mp_obj_type_t float_type = {
{ &mp_const_type }, { &mp_const_type },
"float", "float",
float_print, .print = float_print,
float_make_new, // make_new .make_new = float_make_new,
NULL, // call_n .unary_op = float_unary_op,
float_unary_op, .binary_op = float_binary_op,
float_binary_op, .methods = { { NULL, NULL }, },
NULL, // getiter
NULL, // iternext
{ { NULL, NULL }, }, // method list
}; };
mp_obj_t mp_obj_new_float(mp_float_t value) { mp_obj_t mp_obj_new_float(mp_float_t value) {

View File

@ -76,7 +76,7 @@ const mp_obj_type_t fun_native_type = {
NULL, // binary_op NULL, // binary_op
NULL, // getiter NULL, // getiter
NULL, // iternext NULL, // iternext
{ // method list .methods = {
{NULL, NULL}, // end-of-list sentinel {NULL, NULL}, // end-of-list sentinel
}, },
}; };
@ -169,7 +169,7 @@ const mp_obj_type_t fun_bc_type = {
NULL, // binary_op NULL, // binary_op
NULL, // getiter NULL, // getiter
NULL, // iternext NULL, // iternext
{ // method list .methods = {
{NULL, NULL}, // end-of-list sentinel {NULL, NULL}, // end-of-list sentinel
}, },
}; };
@ -283,7 +283,7 @@ static const mp_obj_type_t fun_asm_type = {
NULL, // binary_op NULL, // binary_op
NULL, // getiter NULL, // getiter
NULL, // iternext NULL, // iternext
{ // method list .methods = {
{NULL, NULL}, // end-of-list sentinel {NULL, NULL}, // end-of-list sentinel
}, },
}; };

View File

@ -46,7 +46,7 @@ const mp_obj_type_t gen_wrap_type = {
NULL, // binary_op NULL, // binary_op
NULL, // getiter NULL, // getiter
NULL, // iternext NULL, // iternext
{{NULL, NULL},}, // method list .methods = {{NULL, NULL},},
}; };
mp_obj_t mp_obj_new_gen_wrap(uint n_locals, uint n_stack, mp_obj_t fun) { mp_obj_t mp_obj_new_gen_wrap(uint n_locals, uint n_stack, mp_obj_t fun) {
@ -101,7 +101,7 @@ const mp_obj_type_t gen_instance_type = {
NULL, // binary_op NULL, // binary_op
gen_instance_getiter, // getiter gen_instance_getiter, // getiter
gen_instance_iternext, // iternext gen_instance_iternext, // iternext
{{NULL, NULL},}, // method list .methods = {{NULL, NULL},},
}; };
// args are in reverse order in the array // args are in reverse order in the array

View File

@ -99,7 +99,7 @@ const mp_obj_type_t instance_type = {
NULL, // binary_op NULL, // binary_op
NULL, // getiter NULL, // getiter
NULL, // iternext NULL, // iternext
{{NULL, NULL},}, // method list .methods = {{NULL, NULL},},
}; };
mp_obj_t mp_obj_new_instance(mp_obj_t class) { mp_obj_t mp_obj_new_instance(mp_obj_t class) {

View File

@ -33,14 +33,8 @@ static mp_obj_t int_make_new(mp_obj_t type_in, int n_args, const mp_obj_t *args)
const mp_obj_type_t int_type = { const mp_obj_type_t int_type = {
{ &mp_const_type }, { &mp_const_type },
"int", "int",
NULL, .make_new = int_make_new,
int_make_new, // make_new .methods = { { NULL, NULL }, },
NULL, // call_n
NULL, // unary_op
NULL, // binary_op
NULL, // getiter
NULL, // iternext
{ { NULL, NULL }, }, // method list
}; };
mp_obj_t mp_obj_new_int(machine_int_t value) { mp_obj_t mp_obj_new_int(machine_int_t value) {

View File

@ -208,14 +208,12 @@ static MP_DEFINE_CONST_FUN_OBJ_2(list_sort_obj, list_sort);
const mp_obj_type_t list_type = { const mp_obj_type_t list_type = {
{ &mp_const_type }, { &mp_const_type },
"list", "list",
list_print, // print .print = list_print,
list_make_new, // make_new .make_new = list_make_new,
NULL, // call_n .unary_op = NULL,
NULL, // unary_op .binary_op = list_binary_op,
list_binary_op, // binary_op .getiter = list_getiter,
list_getiter, // getiter .methods = {
NULL, // iternext
{ // method list
{ "append", &list_append_obj }, { "append", &list_append_obj },
{ "clear", &list_clear_obj }, { "clear", &list_clear_obj },
{ "copy", &list_copy_obj }, { "copy", &list_copy_obj },
@ -287,14 +285,8 @@ mp_obj_t list_it_iternext(mp_obj_t self_in) {
static const mp_obj_type_t list_it_type = { static const mp_obj_type_t list_it_type = {
{ &mp_const_type }, { &mp_const_type },
"list_iterator", "list_iterator",
NULL, // print .iternext = list_it_iternext,
NULL, // make_new .methods = { { NULL, NULL }, },
NULL, // call_n
NULL, // unary_op
NULL, // binary_op
NULL, // getiter
list_it_iternext, // iternext
{ { NULL, NULL }, }, // method list
}; };
mp_obj_t mp_obj_new_list_iterator(mp_obj_list_t *list, int cur) { mp_obj_t mp_obj_new_list_iterator(mp_obj_list_t *list, int cur) {

View File

@ -31,7 +31,7 @@ const mp_obj_type_t module_type = {
NULL, // binary_op NULL, // binary_op
NULL, // getiter NULL, // getiter
NULL, // iternext NULL, // iternext
{{NULL, NULL},}, // method list .methods = {{NULL, NULL},},
}; };
mp_obj_t mp_obj_new_module(qstr module_name) { mp_obj_t mp_obj_new_module(qstr module_name) {

View File

@ -17,14 +17,8 @@ void none_print(void (*print)(void *env, const char *fmt, ...), void *env, mp_ob
const mp_obj_type_t none_type = { const mp_obj_type_t none_type = {
{ &mp_const_type }, { &mp_const_type },
"NoneType", "NoneType",
none_print, // print .print = none_print,
NULL, // make_new .methods = {{NULL, NULL},},
NULL, // call_n
NULL, // unary_op
NULL, // binary_op
NULL, // getiter
NULL, // iternext
{{NULL, NULL},}, // method list
}; };
static const mp_obj_none_t none_obj = {{&none_type}}; static const mp_obj_none_t none_obj = {{&none_type}};

View File

@ -32,7 +32,7 @@ static const mp_obj_type_t range_type = {
NULL, // binary_op NULL, // binary_op
range_getiter, range_getiter,
NULL, // iternext NULL, // iternext
{{NULL, NULL},}, // method list .methods = {{NULL, NULL},},
}; };
// range is a class and instances are immutable sequence objects // range is a class and instances are immutable sequence objects
@ -77,7 +77,7 @@ static const mp_obj_type_t range_it_type = {
NULL, // binary_op NULL, // binary_op
NULL, // getiter NULL, // getiter
range_it_iternext, range_it_iternext,
{{NULL, NULL},}, // method list .methods = {{NULL, NULL},},
}; };
mp_obj_t mp_obj_new_range_iterator(int cur, int stop, int step) { mp_obj_t mp_obj_new_range_iterator(int cur, int stop, int step) {

View File

@ -64,7 +64,7 @@ const mp_obj_type_t set_type = {
NULL, // binary_op NULL, // binary_op
NULL, // getiter NULL, // getiter
NULL, // iternext NULL, // iternext
{ { NULL, NULL }, }, // method list .methods = { { NULL, NULL }, },
}; };
mp_obj_t mp_obj_new_set(int n_args, mp_obj_t *items) { mp_obj_t mp_obj_new_set(int n_args, mp_obj_t *items) {

View File

@ -30,7 +30,7 @@ const mp_obj_type_t ellipsis_type = {
NULL, // binary_op NULL, // binary_op
NULL, // getiter NULL, // getiter
NULL, // iternext NULL, // iternext
{{NULL, NULL},}, // method list .methods = {{NULL, NULL},},
}; };
static const mp_obj_ellipsis_t ellipsis_obj = {{&ellipsis_type}}; static const mp_obj_ellipsis_t ellipsis_obj = {{&ellipsis_type}};
@ -57,14 +57,8 @@ void slice_print(void (*print)(void *env, const char *fmt, ...), void *env, mp_o
const mp_obj_type_t slice_type = { const mp_obj_type_t slice_type = {
{ &mp_const_type }, { &mp_const_type },
"slice", "slice",
slice_print, .print = slice_print,
NULL, // call_n .methods = { { NULL, NULL }, },
NULL, // make_new
NULL, // unary_op
NULL, // binary_op
NULL, // getiter
NULL, // iternext
{ { NULL, NULL }, }, // method list
}; };
// TODO: Make sure to handle "empty" values, which are signified by None in CPython // TODO: Make sure to handle "empty" values, which are signified by None in CPython

View File

@ -187,14 +187,10 @@ static MP_DEFINE_CONST_FUN_OBJ_VAR(str_format_obj, 1, str_format);
const mp_obj_type_t str_type = { const mp_obj_type_t str_type = {
{ &mp_const_type }, { &mp_const_type },
"str", "str",
str_print, // print .print = str_print,
NULL, // make_new .binary_op = str_binary_op,
NULL, // call_n .getiter = str_getiter,
NULL, // unary_op .methods = {
str_binary_op, // binary_op
str_getiter, // getiter
NULL, // iternext
{ // method list
{ "join", &str_join_obj }, { "join", &str_join_obj },
{ "format", &str_format_obj }, { "format", &str_format_obj },
{ NULL, NULL }, // end-of-list sentinel { NULL, NULL }, // end-of-list sentinel
@ -238,14 +234,8 @@ mp_obj_t str_it_iternext(mp_obj_t self_in) {
static const mp_obj_type_t str_it_type = { static const mp_obj_type_t str_it_type = {
{ &mp_const_type }, { &mp_const_type },
"str_iterator", "str_iterator",
NULL, // print .iternext = str_it_iternext,
NULL, // make_new .methods = { { NULL, NULL }, },
NULL, // call_n
NULL, // unary_op
NULL, // binary_op
NULL, // getiter
str_it_iternext, // iternext
{ { NULL, NULL }, }, // method str
}; };
mp_obj_t mp_obj_new_str_iterator(mp_obj_str_t *str, int cur) { mp_obj_t mp_obj_new_str_iterator(mp_obj_str_t *str, int cur) {

View File

@ -99,14 +99,11 @@ static mp_obj_t tuple_getiter(mp_obj_t o_in) {
const mp_obj_type_t tuple_type = { const mp_obj_type_t tuple_type = {
{ &mp_const_type }, { &mp_const_type },
"tuple", "tuple",
tuple_print, // print .print = tuple_print,
tuple_make_new, // make_new .make_new = tuple_make_new,
NULL, // call_n .binary_op = tuple_binary_op,
NULL, // unary_op .getiter = tuple_getiter,
tuple_binary_op, // binary_op .methods = {{NULL, NULL},},
tuple_getiter, // getiter
NULL, // iternext
{{NULL, NULL},}, // method list
}; };
// the zero-length tuple // the zero-length tuple
@ -168,14 +165,8 @@ static mp_obj_t tuple_it_iternext(mp_obj_t self_in) {
static const mp_obj_type_t tuple_it_type = { static const mp_obj_type_t tuple_it_type = {
{ &mp_const_type }, { &mp_const_type },
"tuple_iterator", "tuple_iterator",
NULL, // print .iternext = tuple_it_iternext,
NULL, // make_new .methods = {{NULL, NULL},},
NULL, // call_n
NULL, // unary_op
NULL, // binary_op
NULL, // getiter
tuple_it_iternext,
{{NULL, NULL},}, // method list
}; };
static mp_obj_t mp_obj_new_tuple_iterator(mp_obj_tuple_t *tuple, int cur) { static mp_obj_t mp_obj_new_tuple_iterator(mp_obj_tuple_t *tuple, int cur) {

View File

@ -25,12 +25,7 @@ static mp_obj_t type_call_n(mp_obj_t self_in, int n_args, const mp_obj_t *args)
const mp_obj_type_t mp_const_type = { const mp_obj_type_t mp_const_type = {
{ &mp_const_type }, { &mp_const_type },
"type", "type",
type_print, // print .print = type_print,
NULL, // make_new .call_n = type_call_n,
type_call_n, // call_n .methods = {{NULL, NULL},},
NULL, // unary_op
NULL, // binary_op
NULL, // getiter
NULL, // iternext
{{NULL, NULL},}, // method list
}; };

View File

@ -329,14 +329,8 @@ static MP_DEFINE_CONST_FUN_OBJ_1(i2c_obj_stop_obj, i2c_obj_stop);
static const mp_obj_type_t i2c_obj_type = { static const mp_obj_type_t i2c_obj_type = {
{ &mp_const_type }, { &mp_const_type },
"I2C", "I2C",
i2c_obj_print, // print .print = i2c_obj_print,
NULL, // make_new .methods = {
NULL, // call_n
NULL, // unary_op
NULL, // binary_op
NULL, // getiter
NULL, // iternext
{ // method list
{ "start", &i2c_obj_start_obj }, { "start", &i2c_obj_start_obj },
{ "write", &i2c_obj_write_obj }, { "write", &i2c_obj_write_obj },
{ "read", &i2c_obj_read_obj }, { "read", &i2c_obj_read_obj },

View File

@ -107,14 +107,8 @@ static MP_DEFINE_CONST_FUN_OBJ_1(led_obj_off_obj, led_obj_off);
static const mp_obj_type_t led_obj_type = { static const mp_obj_type_t led_obj_type = {
{ &mp_const_type }, { &mp_const_type },
"Led", "Led",
led_obj_print, // print .print = led_obj_print,
NULL, // make_new .methods = {
NULL, // call_n
NULL, // unary_op
NULL, // binary_op
NULL, // getiter
NULL, // iternext
{ // method list
{ "on", &led_obj_on_obj }, { "on", &led_obj_on_obj },
{ "off", &led_obj_off_obj }, { "off", &led_obj_off_obj },
{ NULL, NULL }, { NULL, NULL },

View File

@ -699,7 +699,7 @@ static const mp_obj_type_t file_obj_type = {
NULL, // binary_op NULL, // binary_op
NULL, // getiter NULL, // getiter
NULL, // iternext NULL, // iternext
{ // method list .methods = {
{ "read", &file_obj_read_obj }, { "read", &file_obj_read_obj },
{ "write", &file_obj_write_obj }, { "write", &file_obj_write_obj },
{ "close", &file_obj_close_obj }, { "close", &file_obj_close_obj },

View File

@ -140,14 +140,8 @@ static MP_DEFINE_CONST_FUN_OBJ_2(servo_obj_angle_obj, servo_obj_angle);
static const mp_obj_type_t servo_obj_type = { static const mp_obj_type_t servo_obj_type = {
{ &mp_const_type }, { &mp_const_type },
"Servo", "Servo",
servo_obj_print, // print .print = servo_obj_print,
NULL, // make_new .methods = {
NULL, // call_n
NULL, // unary_op
NULL, // binary_op
NULL, // getiter
NULL, // iternext
{ // method list
{ "angle", &servo_obj_angle_obj }, { "angle", &servo_obj_angle_obj },
{ NULL, NULL }, { NULL, NULL },
} }

View File

@ -191,14 +191,14 @@ static MP_DEFINE_CONST_FUN_OBJ_2(test_set_obj, test_set);
static const mp_obj_type_t test_type = { static const mp_obj_type_t test_type = {
{ &mp_const_type }, { &mp_const_type },
"Test", "Test",
test_print, // print .print = test_print,
NULL, // make_new .make_new = NULL,
NULL, // call_n .call_n = NULL,
NULL, // unary_op .unary_op = NULL,
NULL, // binary_op .binary_op = NULL,
NULL, // getiter .getiter = NULL,
NULL, // iternext .iternext = NULL,
{ // method list .methods = {
{ "get", &test_get_obj }, { "get", &test_get_obj },
{ "set", &test_set_obj }, { "set", &test_set_obj },
{ NULL, NULL }, { NULL, NULL },