From 860ffb0a4365bba62cbd692392375df9fd4a72e7 Mon Sep 17 00:00:00 2001 From: Paul Sokolovsky Date: Sun, 5 Jan 2014 22:34:09 +0200 Subject: [PATCH] Convert many object types structs to use C99 tagged initializer syntax. --- py/objbool.c | 2 +- py/objboundmeth.c | 2 +- py/objcell.c | 2 +- py/objclass.c | 2 +- py/objclosure.c | 2 +- py/objcomplex.c | 2 +- py/objdict.c | 13 +++++-------- py/objexcept.c | 2 +- py/objfloat.c | 13 +++++-------- py/objfun.c | 6 +++--- py/objgenerator.c | 4 ++-- py/objinstance.c | 2 +- py/objint.c | 10 ++-------- py/objlist.c | 24 ++++++++---------------- py/objmodule.c | 2 +- py/objnone.c | 10 ++-------- py/objrange.c | 4 ++-- py/objset.c | 2 +- py/objslice.c | 12 +++--------- py/objstr.c | 22 ++++++---------------- py/objtuple.c | 23 +++++++---------------- py/objtype.c | 11 +++-------- stm/i2c.c | 10 ++-------- stm/led.c | 10 ++-------- stm/main.c | 2 +- stm/servo.c | 10 ++-------- unix/main.c | 16 ++++++++-------- 27 files changed, 73 insertions(+), 147 deletions(-) diff --git a/py/objbool.c b/py/objbool.c index 1d94ee03be..77394dab99 100644 --- a/py/objbool.c +++ b/py/objbool.c @@ -41,7 +41,7 @@ const mp_obj_type_t bool_type = { NULL, // binary_op NULL, // getiter NULL, // iternext - {{NULL, NULL},}, // method list + .methods = {{NULL, NULL},}, }; static const mp_obj_bool_t false_obj = {{&bool_type}, false}; diff --git a/py/objboundmeth.c b/py/objboundmeth.c index 264c2effd4..4e6d2e0103 100644 --- a/py/objboundmeth.c +++ b/py/objboundmeth.c @@ -43,7 +43,7 @@ const mp_obj_type_t bound_meth_type = { NULL, // binary_op NULL, // getiter 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) { diff --git a/py/objcell.c b/py/objcell.c index daaa340a7f..3465f99198 100644 --- a/py/objcell.c +++ b/py/objcell.c @@ -33,7 +33,7 @@ const mp_obj_type_t cell_type = { NULL, // binary_op NULL, // getiter NULL, // iternext - {{NULL, NULL},}, // method list + .methods = {{NULL, NULL},}, }; mp_obj_t mp_obj_new_cell(mp_obj_t obj) { diff --git a/py/objclass.c b/py/objclass.c index 197dfa7268..536abdf7e3 100644 --- a/py/objclass.c +++ b/py/objclass.c @@ -70,7 +70,7 @@ const mp_obj_type_t class_type = { NULL, // binary_op NULL, // getiter NULL, // iternext - {{NULL, NULL},}, // method list + .methods = {{NULL, NULL},}, }; mp_obj_t mp_obj_new_class(mp_map_t *class_locals) { diff --git a/py/objclosure.c b/py/objclosure.c index 550bb5067f..3317eb86f4 100644 --- a/py/objclosure.c +++ b/py/objclosure.c @@ -42,7 +42,7 @@ const mp_obj_type_t closure_type = { NULL, // binary_op NULL, // getiter 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) { diff --git a/py/objcomplex.c b/py/objcomplex.c index 5408d71cf2..fc32f96674 100644 --- a/py/objcomplex.c +++ b/py/objcomplex.c @@ -125,7 +125,7 @@ const mp_obj_type_t complex_type = { complex_binary_op, // binary_op NULL, // getiter NULL, // iternext - { { NULL, NULL }, }, // method list + .methods = { { NULL, NULL }, }, }; mp_obj_t mp_obj_new_complex(mp_float_t real, mp_float_t imag) { diff --git a/py/objdict.c b/py/objdict.c index 3737f5eab0..b3e21aedd2 100644 --- a/py/objdict.c +++ b/py/objdict.c @@ -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 = { { &mp_const_type }, "dict", - dict_print, // print - dict_make_new, // make_new - NULL, // call_n - NULL, // unary_op - dict_binary_op, // binary_op - NULL, // getiter - NULL, // iternext - {{NULL, NULL},}, // method list + .print = dict_print, + .make_new = dict_make_new, + .binary_op = dict_binary_op, + .getiter = NULL, + .methods = {{NULL, NULL},}, }; mp_obj_t mp_obj_new_dict(int n_args) { diff --git a/py/objexcept.c b/py/objexcept.c index ec03b9bf1a..22b8c58126 100644 --- a/py/objexcept.c +++ b/py/objexcept.c @@ -45,7 +45,7 @@ const mp_obj_type_t exception_type = { NULL, // binary_op NULL, // getiter NULL, // iternext - {{NULL, NULL},}, // method list + .methods = {{NULL, NULL},}, }; mp_obj_t mp_obj_new_exception(qstr id) { diff --git a/py/objfloat.c b/py/objfloat.c index 8fc925e0b6..0250172ad3 100644 --- a/py/objfloat.c +++ b/py/objfloat.c @@ -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 = { { &mp_const_type }, "float", - float_print, - float_make_new, // make_new - NULL, // call_n - float_unary_op, - float_binary_op, - NULL, // getiter - NULL, // iternext - { { NULL, NULL }, }, // method list + .print = float_print, + .make_new = float_make_new, + .unary_op = float_unary_op, + .binary_op = float_binary_op, + .methods = { { NULL, NULL }, }, }; mp_obj_t mp_obj_new_float(mp_float_t value) { diff --git a/py/objfun.c b/py/objfun.c index 22b82a9ca0..2d81f8f5c1 100644 --- a/py/objfun.c +++ b/py/objfun.c @@ -76,7 +76,7 @@ const mp_obj_type_t fun_native_type = { NULL, // binary_op NULL, // getiter NULL, // iternext - { // method list + .methods = { {NULL, NULL}, // end-of-list sentinel }, }; @@ -169,7 +169,7 @@ const mp_obj_type_t fun_bc_type = { NULL, // binary_op NULL, // getiter NULL, // iternext - { // method list + .methods = { {NULL, NULL}, // end-of-list sentinel }, }; @@ -283,7 +283,7 @@ static const mp_obj_type_t fun_asm_type = { NULL, // binary_op NULL, // getiter NULL, // iternext - { // method list + .methods = { {NULL, NULL}, // end-of-list sentinel }, }; diff --git a/py/objgenerator.c b/py/objgenerator.c index 7fbca075e2..a91b0d6fc6 100644 --- a/py/objgenerator.c +++ b/py/objgenerator.c @@ -46,7 +46,7 @@ const mp_obj_type_t gen_wrap_type = { NULL, // binary_op NULL, // getiter 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) { @@ -101,7 +101,7 @@ const mp_obj_type_t gen_instance_type = { NULL, // binary_op gen_instance_getiter, // getiter gen_instance_iternext, // iternext - {{NULL, NULL},}, // method list + .methods = {{NULL, NULL},}, }; // args are in reverse order in the array diff --git a/py/objinstance.c b/py/objinstance.c index fd8cada7cb..8ef2773fd9 100644 --- a/py/objinstance.c +++ b/py/objinstance.c @@ -99,7 +99,7 @@ const mp_obj_type_t instance_type = { NULL, // binary_op NULL, // getiter NULL, // iternext - {{NULL, NULL},}, // method list + .methods = {{NULL, NULL},}, }; mp_obj_t mp_obj_new_instance(mp_obj_t class) { diff --git a/py/objint.c b/py/objint.c index 5bc747e8f0..8d69c4e7a7 100644 --- a/py/objint.c +++ b/py/objint.c @@ -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 = { { &mp_const_type }, "int", - NULL, - int_make_new, // make_new - NULL, // call_n - NULL, // unary_op - NULL, // binary_op - NULL, // getiter - NULL, // iternext - { { NULL, NULL }, }, // method list + .make_new = int_make_new, + .methods = { { NULL, NULL }, }, }; mp_obj_t mp_obj_new_int(machine_int_t value) { diff --git a/py/objlist.c b/py/objlist.c index 6c0de405fe..a656a4aeb6 100644 --- a/py/objlist.c +++ b/py/objlist.c @@ -208,14 +208,12 @@ static MP_DEFINE_CONST_FUN_OBJ_2(list_sort_obj, list_sort); const mp_obj_type_t list_type = { { &mp_const_type }, "list", - list_print, // print - list_make_new, // make_new - NULL, // call_n - NULL, // unary_op - list_binary_op, // binary_op - list_getiter, // getiter - NULL, // iternext - { // method list + .print = list_print, + .make_new = list_make_new, + .unary_op = NULL, + .binary_op = list_binary_op, + .getiter = list_getiter, + .methods = { { "append", &list_append_obj }, { "clear", &list_clear_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 = { { &mp_const_type }, "list_iterator", - NULL, // print - NULL, // make_new - NULL, // call_n - NULL, // unary_op - NULL, // binary_op - NULL, // getiter - list_it_iternext, // iternext - { { NULL, NULL }, }, // method list + .iternext = list_it_iternext, + .methods = { { NULL, NULL }, }, }; mp_obj_t mp_obj_new_list_iterator(mp_obj_list_t *list, int cur) { diff --git a/py/objmodule.c b/py/objmodule.c index 9263eb44f0..2d6f9555e8 100644 --- a/py/objmodule.c +++ b/py/objmodule.c @@ -31,7 +31,7 @@ const mp_obj_type_t module_type = { NULL, // binary_op NULL, // getiter NULL, // iternext - {{NULL, NULL},}, // method list + .methods = {{NULL, NULL},}, }; mp_obj_t mp_obj_new_module(qstr module_name) { diff --git a/py/objnone.c b/py/objnone.c index 11dd4939b1..877e61fe5c 100644 --- a/py/objnone.c +++ b/py/objnone.c @@ -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 = { { &mp_const_type }, "NoneType", - none_print, // print - NULL, // make_new - NULL, // call_n - NULL, // unary_op - NULL, // binary_op - NULL, // getiter - NULL, // iternext - {{NULL, NULL},}, // method list + .print = none_print, + .methods = {{NULL, NULL},}, }; static const mp_obj_none_t none_obj = {{&none_type}}; diff --git a/py/objrange.c b/py/objrange.c index b163f779b8..1ef42673f4 100644 --- a/py/objrange.c +++ b/py/objrange.c @@ -32,7 +32,7 @@ static const mp_obj_type_t range_type = { NULL, // binary_op range_getiter, NULL, // iternext - {{NULL, NULL},}, // method list + .methods = {{NULL, NULL},}, }; // 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, // getiter range_it_iternext, - {{NULL, NULL},}, // method list + .methods = {{NULL, NULL},}, }; mp_obj_t mp_obj_new_range_iterator(int cur, int stop, int step) { diff --git a/py/objset.c b/py/objset.c index 826f8bdc86..dd9a4d1e1d 100644 --- a/py/objset.c +++ b/py/objset.c @@ -64,7 +64,7 @@ const mp_obj_type_t set_type = { NULL, // binary_op NULL, // getiter NULL, // iternext - { { NULL, NULL }, }, // method list + .methods = { { NULL, NULL }, }, }; mp_obj_t mp_obj_new_set(int n_args, mp_obj_t *items) { diff --git a/py/objslice.c b/py/objslice.c index a624be9631..da69b92af2 100644 --- a/py/objslice.c +++ b/py/objslice.c @@ -30,7 +30,7 @@ const mp_obj_type_t ellipsis_type = { NULL, // binary_op NULL, // getiter NULL, // iternext - {{NULL, NULL},}, // method list + .methods = {{NULL, NULL},}, }; 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 = { { &mp_const_type }, "slice", - slice_print, - NULL, // call_n - NULL, // make_new - NULL, // unary_op - NULL, // binary_op - NULL, // getiter - NULL, // iternext - { { NULL, NULL }, }, // method list + .print = slice_print, + .methods = { { NULL, NULL }, }, }; // TODO: Make sure to handle "empty" values, which are signified by None in CPython diff --git a/py/objstr.c b/py/objstr.c index a1d139e83a..db3e0beca0 100644 --- a/py/objstr.c +++ b/py/objstr.c @@ -187,14 +187,10 @@ static MP_DEFINE_CONST_FUN_OBJ_VAR(str_format_obj, 1, str_format); const mp_obj_type_t str_type = { { &mp_const_type }, "str", - str_print, // print - NULL, // make_new - NULL, // call_n - NULL, // unary_op - str_binary_op, // binary_op - str_getiter, // getiter - NULL, // iternext - { // method list + .print = str_print, + .binary_op = str_binary_op, + .getiter = str_getiter, + .methods = { { "join", &str_join_obj }, { "format", &str_format_obj }, { 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 = { { &mp_const_type }, "str_iterator", - NULL, // print - NULL, // make_new - NULL, // call_n - NULL, // unary_op - NULL, // binary_op - NULL, // getiter - str_it_iternext, // iternext - { { NULL, NULL }, }, // method str + .iternext = str_it_iternext, + .methods = { { NULL, NULL }, }, }; mp_obj_t mp_obj_new_str_iterator(mp_obj_str_t *str, int cur) { diff --git a/py/objtuple.c b/py/objtuple.c index d55259d1a6..ceca4200e4 100644 --- a/py/objtuple.c +++ b/py/objtuple.c @@ -99,14 +99,11 @@ static mp_obj_t tuple_getiter(mp_obj_t o_in) { const mp_obj_type_t tuple_type = { { &mp_const_type }, "tuple", - tuple_print, // print - tuple_make_new, // make_new - NULL, // call_n - NULL, // unary_op - tuple_binary_op, // binary_op - tuple_getiter, // getiter - NULL, // iternext - {{NULL, NULL},}, // method list + .print = tuple_print, + .make_new = tuple_make_new, + .binary_op = tuple_binary_op, + .getiter = tuple_getiter, + .methods = {{NULL, NULL},}, }; // 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 = { { &mp_const_type }, "tuple_iterator", - NULL, // print - NULL, // make_new - NULL, // call_n - NULL, // unary_op - NULL, // binary_op - NULL, // getiter - tuple_it_iternext, - {{NULL, NULL},}, // method list + .iternext = tuple_it_iternext, + .methods = {{NULL, NULL},}, }; static mp_obj_t mp_obj_new_tuple_iterator(mp_obj_tuple_t *tuple, int cur) { diff --git a/py/objtype.c b/py/objtype.c index aeeaebb95d..37d40b38f4 100644 --- a/py/objtype.c +++ b/py/objtype.c @@ -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 = { { &mp_const_type }, "type", - type_print, // print - NULL, // make_new - type_call_n, // call_n - NULL, // unary_op - NULL, // binary_op - NULL, // getiter - NULL, // iternext - {{NULL, NULL},}, // method list + .print = type_print, + .call_n = type_call_n, + .methods = {{NULL, NULL},}, }; diff --git a/stm/i2c.c b/stm/i2c.c index 3f29f02c0c..9e25ff9839 100644 --- a/stm/i2c.c +++ b/stm/i2c.c @@ -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 = { { &mp_const_type }, "I2C", - i2c_obj_print, // print - NULL, // make_new - NULL, // call_n - NULL, // unary_op - NULL, // binary_op - NULL, // getiter - NULL, // iternext - { // method list + .print = i2c_obj_print, + .methods = { { "start", &i2c_obj_start_obj }, { "write", &i2c_obj_write_obj }, { "read", &i2c_obj_read_obj }, diff --git a/stm/led.c b/stm/led.c index 9305716be9..ef6fea0ce2 100644 --- a/stm/led.c +++ b/stm/led.c @@ -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 = { { &mp_const_type }, "Led", - led_obj_print, // print - NULL, // make_new - NULL, // call_n - NULL, // unary_op - NULL, // binary_op - NULL, // getiter - NULL, // iternext - { // method list + .print = led_obj_print, + .methods = { { "on", &led_obj_on_obj }, { "off", &led_obj_off_obj }, { NULL, NULL }, diff --git a/stm/main.c b/stm/main.c index 2121742fd8..07c974eff8 100644 --- a/stm/main.c +++ b/stm/main.c @@ -699,7 +699,7 @@ static const mp_obj_type_t file_obj_type = { NULL, // binary_op NULL, // getiter NULL, // iternext - { // method list + .methods = { { "read", &file_obj_read_obj }, { "write", &file_obj_write_obj }, { "close", &file_obj_close_obj }, diff --git a/stm/servo.c b/stm/servo.c index 1e31db5140..31190ce795 100644 --- a/stm/servo.c +++ b/stm/servo.c @@ -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 = { { &mp_const_type }, "Servo", - servo_obj_print, // print - NULL, // make_new - NULL, // call_n - NULL, // unary_op - NULL, // binary_op - NULL, // getiter - NULL, // iternext - { // method list + .print = servo_obj_print, + .methods = { { "angle", &servo_obj_angle_obj }, { NULL, NULL }, } diff --git a/unix/main.c b/unix/main.c index 16fcf6ef8d..a06dc36791 100644 --- a/unix/main.c +++ b/unix/main.c @@ -191,14 +191,14 @@ static MP_DEFINE_CONST_FUN_OBJ_2(test_set_obj, test_set); static const mp_obj_type_t test_type = { { &mp_const_type }, "Test", - test_print, // print - NULL, // make_new - NULL, // call_n - NULL, // unary_op - NULL, // binary_op - NULL, // getiter - NULL, // iternext - { // method list + .print = test_print, + .make_new = NULL, + .call_n = NULL, + .unary_op = NULL, + .binary_op = NULL, + .getiter = NULL, + .iternext = NULL, + .methods = { { "get", &test_get_obj }, { "set", &test_set_obj }, { NULL, NULL },