From 662b9761b37b054f08fe2f7c00d0fce3a418d0b0 Mon Sep 17 00:00:00 2001 From: Jim Mussared Date: Wed, 14 Jul 2021 14:38:38 +1000 Subject: [PATCH] all: Make all mp_obj_type_t defs use MP_DEFINE_CONST_OBJ_TYPE. In preparation for upcoming rework of mp_obj_type_t layout. Signed-off-by: Jim Mussared --- extmod/machine_i2c.c | 17 +-- extmod/machine_mem.c | 14 ++- extmod/machine_pinbase.c | 13 +- extmod/machine_pwm.c | 15 +-- extmod/machine_signal.c | 17 +-- extmod/machine_spi.c | 17 +-- extmod/modbluetooth.c | 33 ++--- extmod/modbtree.c | 22 ++-- extmod/modframebuf.c | 15 +-- extmod/modlwip.c | 30 ++--- extmod/moduasyncio.c | 30 ++--- extmod/moducryptolib.c | 13 +- extmod/moductypes.c | 21 ++-- extmod/moduhashlib.c | 39 +++--- extmod/modure.c | 28 +++-- extmod/moduselect.c | 16 +-- extmod/modusocket.c | 17 +-- extmod/modussl_axtls.c | 20 ++-- extmod/modussl_mbedtls.c | 20 ++-- extmod/modutimeq.c | 15 +-- extmod/moduwebsocket.c | 15 +-- extmod/moduzlib.c | 15 +-- extmod/modwebrepl.c | 15 +-- extmod/network_cyw43.c | 15 +-- extmod/network_ninaw10.c | 15 ++- extmod/network_wiznet5k.c | 28 +++-- extmod/vfs_fat.c | 15 +-- extmod/vfs_fat_file.c | 40 ++++--- extmod/vfs_lfsx.c | 17 +-- extmod/vfs_lfsx_file.c | 40 ++++--- extmod/vfs_posix.c | 15 +-- extmod/vfs_posix_file.c | 40 ++++--- ports/cc3200/misc/mpirq.c | 14 ++- ports/cc3200/mods/modnetwork.c | 13 +- ports/cc3200/mods/moduhashlib.c | 26 ++-- ports/cc3200/mods/modusocket.c | 15 +-- ports/cc3200/mods/modussl.c | 18 +-- ports/cc3200/mods/modwlan.c | 15 ++- ports/cc3200/mods/pybadc.c | 31 ++--- ports/cc3200/mods/pybflash.c | 13 +- ports/cc3200/mods/pybi2c.c | 15 +-- ports/cc3200/mods/pybpin.c | 31 ++--- ports/cc3200/mods/pybrtc.c | 13 +- ports/cc3200/mods/pybsd.c | 13 +- ports/cc3200/mods/pybsleep.c | 10 +- ports/cc3200/mods/pybspi.c | 15 +-- ports/cc3200/mods/pybtimer.c | 29 +++-- ports/cc3200/mods/pybuart.c | 21 ++-- ports/cc3200/mods/pybwdt.c | 13 +- ports/esp32/esp32_nvs.c | 15 +-- ports/esp32/esp32_partition.c | 15 +-- ports/esp32/esp32_rmt.c | 15 +-- ports/esp32/esp32_ulp.c | 13 +- ports/esp32/machine_adc.c | 15 +-- ports/esp32/machine_adcblock.c | 15 +-- ports/esp32/machine_dac.c | 15 +-- ports/esp32/machine_hw_spi.c | 17 +-- ports/esp32/machine_i2c.c | 17 +-- ports/esp32/machine_i2s.c | 21 ++-- ports/esp32/machine_pin.c | 33 ++--- ports/esp32/machine_rtc.c | 13 +- ports/esp32/machine_sdcard.c | 13 +- ports/esp32/machine_timer.c | 15 +-- ports/esp32/machine_touchpad.c | 13 +- ports/esp32/machine_uart.c | 21 ++-- ports/esp32/machine_wdt.c | 13 +- ports/esp32/modsocket.c | 15 +-- ports/esp32/network_lan.c | 12 +- ports/esp32/network_ppp.c | 12 +- ports/esp32/network_wlan.c | 20 ++-- ports/esp8266/machine_adc.c | 15 +-- ports/esp8266/machine_hspi.c | 17 +-- ports/esp8266/machine_pin.c | 33 ++--- ports/esp8266/machine_rtc.c | 13 +- ports/esp8266/machine_uart.c | 21 ++-- ports/esp8266/machine_wdt.c | 13 +- ports/esp8266/modmachine.c | 15 +-- ports/esp8266/modnetwork.c | 12 +- ports/mimxrt/machine_adc.c | 15 +-- ports/mimxrt/machine_i2c.c | 17 +-- ports/mimxrt/machine_i2s.c | 21 ++-- ports/mimxrt/machine_led.c | 15 +-- ports/mimxrt/machine_pin.c | 59 ++++----- ports/mimxrt/machine_rtc.c | 13 +- ports/mimxrt/machine_sdcard.c | 13 +- ports/mimxrt/machine_spi.c | 17 +-- ports/mimxrt/machine_timer.c | 15 +-- ports/mimxrt/machine_uart.c | 21 ++-- ports/mimxrt/machine_wdt.c | 13 +- ports/mimxrt/mimxrt_flash.c | 13 +- ports/mimxrt/network_lan.c | 16 +-- ports/nrf/boards/microbit/modules/iters.c | 14 ++- .../boards/microbit/modules/microbitdisplay.c | 12 +- .../boards/microbit/modules/microbitimage.c | 73 ++++++----- ports/nrf/modules/board/led.c | 15 +-- ports/nrf/modules/machine/adc.c | 15 +-- ports/nrf/modules/machine/i2c.c | 17 +-- ports/nrf/modules/machine/pin.c | 31 ++--- ports/nrf/modules/machine/pwm.c | 15 +-- ports/nrf/modules/machine/rtcounter.c | 15 +-- ports/nrf/modules/machine/spi.c | 17 +-- ports/nrf/modules/machine/temp.c | 15 +-- ports/nrf/modules/machine/timer.c | 15 +-- ports/nrf/modules/machine/uart.c | 21 ++-- ports/nrf/modules/nrf/flashbdev.c | 15 +-- .../modules/ubluepy/ubluepy_characteristic.c | 15 +-- ports/nrf/modules/ubluepy/ubluepy_constants.c | 24 ++-- ports/nrf/modules/ubluepy/ubluepy_delegate.c | 15 +-- .../nrf/modules/ubluepy/ubluepy_descriptor.c | 15 +-- .../nrf/modules/ubluepy/ubluepy_peripheral.c | 15 +-- .../nrf/modules/ubluepy/ubluepy_scan_entry.c | 14 ++- ports/nrf/modules/ubluepy/ubluepy_scanner.c | 15 +-- ports/nrf/modules/ubluepy/ubluepy_service.c | 15 +-- ports/nrf/modules/ubluepy/ubluepy_uuid.c | 15 +-- ports/nrf/modules/uos/microbitfs.c | 28 +++-- ports/nrf/pin_named_pins.c | 28 +++-- ports/pic16bit/modpybled.c | 15 +-- ports/pic16bit/modpybswitch.c | 17 +-- ports/renesas-ra/extint.c | 15 +-- ports/renesas-ra/led.c | 15 +-- ports/renesas-ra/machine_adc.c | 15 +-- ports/renesas-ra/machine_i2c.c | 17 +-- ports/renesas-ra/machine_pin.c | 43 ++++--- ports/renesas-ra/machine_rtc.c | 13 +- ports/renesas-ra/machine_spi.c | 17 +-- ports/renesas-ra/machine_timer.c | 15 +-- ports/renesas-ra/machine_uart.c | 21 ++-- ports/renesas-ra/storage.c | 15 +-- ports/renesas-ra/timer.c | 29 +++-- ports/renesas-ra/usrsw.c | 17 +-- ports/rp2/machine_adc.c | 15 +-- ports/rp2/machine_i2c.c | 17 +-- ports/rp2/machine_i2s.c | 21 ++-- ports/rp2/machine_pin.c | 19 +-- ports/rp2/machine_rtc.c | 13 +- ports/rp2/machine_spi.c | 17 +-- ports/rp2/machine_timer.c | 15 +-- ports/rp2/machine_uart.c | 21 ++-- ports/rp2/machine_wdt.c | 13 +- ports/rp2/rp2_flash.c | 13 +- ports/rp2/rp2_pio.c | 30 ++--- ports/samd/machine_led.c | 17 +-- ports/samd/machine_pin.c | 19 +-- ports/samd/samd_flash.c | 13 +- ports/stm32/accel.c | 13 +- ports/stm32/adc.c | 28 +++-- ports/stm32/dac.c | 15 +-- ports/stm32/extint.c | 15 +-- ports/stm32/lcd.c | 13 +- ports/stm32/led.c | 15 +-- ports/stm32/machine_adc.c | 15 +-- ports/stm32/machine_i2c.c | 17 +-- ports/stm32/machine_i2s.c | 21 ++-- ports/stm32/machine_spi.c | 17 +-- ports/stm32/machine_timer.c | 15 +-- ports/stm32/machine_uart.c | 21 ++-- ports/stm32/network_lan.c | 15 +-- ports/stm32/pin.c | 33 ++--- ports/stm32/pin_named_pins.c | 24 ++-- ports/stm32/pyb_can.c | 17 +-- ports/stm32/pyb_i2c.c | 15 +-- ports/stm32/pyb_spi.c | 17 +-- ports/stm32/rtc.c | 13 +- ports/stm32/sdcard.c | 26 ++-- ports/stm32/servo.c | 15 +-- ports/stm32/storage.c | 15 +-- ports/stm32/timer.c | 29 +++-- ports/stm32/usb.c | 36 +++--- ports/stm32/usrsw.c | 17 +-- ports/stm32/wdt.c | 13 +- ports/teensy/led.c | 15 +-- ports/teensy/timer.c | 29 +++-- ports/teensy/uart.c | 15 +-- ports/unix/coverage.c | 26 ++-- ports/unix/modffi.c | 69 ++++++----- ports/unix/modjni.c | 58 +++++---- ports/unix/moduselect.c | 16 +-- ports/unix/modusocket.c | 21 ++-- ports/zephyr/machine_i2c.c | 17 +-- ports/zephyr/machine_pin.c | 19 +-- ports/zephyr/machine_spi.c | 17 +-- ports/zephyr/machine_uart.c | 21 ++-- ports/zephyr/modusocket.c | 17 +-- ports/zephyr/modzsensor.c | 13 +- ports/zephyr/zephyr_storage.c | 30 ++--- py/builtinevex.c | 10 +- py/modio.c | 28 +++-- py/modthread.c | 12 +- py/objarray.c | 87 +++++++------- py/objattrtuple.c | 23 ++-- py/objbool.c | 19 +-- py/objboundmeth.c | 16 +-- py/objcell.c | 10 +- py/objclosure.c | 17 +-- py/objcomplex.c | 17 ++- py/objdeque.c | 15 +-- py/objdict.c | 78 ++++++------ py/objenumerate.c | 15 +-- py/objexcept.c | 15 +-- py/objfilter.c | 15 +-- py/objfloat.c | 15 +-- py/objfun.c | 113 ++++++++---------- py/objgenerator.c | 54 +++++---- py/objgetitemiter.c | 14 ++- py/objint.c | 19 +-- py/objlist.c | 24 ++-- py/objmap.c | 15 +-- py/objmodule.c | 14 ++- py/objnone.c | 14 ++- py/objobject.c | 13 +- py/objpolyiter.c | 31 ++--- py/objproperty.c | 13 +- py/objrange.c | 37 +++--- py/objreversed.c | 15 +-- py/objset.c | 43 +++---- py/objsingleton.c | 11 +- py/objslice.c | 16 +-- py/objstr.c | 48 ++++---- py/objstringio.c | 42 +++---- py/objstrunicode.c | 25 ++-- py/objtuple.c | 23 ++-- py/objtype.c | 56 +++++---- py/objzip.c | 15 +-- py/profile.c | 32 ++--- py/runtime.c | 13 +- shared/runtime/mpirq.c | 14 ++- shared/runtime/sys_stdio_mphal.c | 40 ++++--- 227 files changed, 2543 insertions(+), 2184 deletions(-) diff --git a/extmod/machine_i2c.c b/extmod/machine_i2c.c index ff597b58c5..7e597b7910 100644 --- a/extmod/machine_i2c.c +++ b/extmod/machine_i2c.c @@ -730,13 +730,14 @@ STATIC const mp_machine_i2c_p_t mp_machine_soft_i2c_p = { .transfer = mp_machine_soft_i2c_transfer, }; -const mp_obj_type_t mp_machine_soft_i2c_type = { - { &mp_type_type }, - .name = MP_QSTR_SoftI2C, - .print = mp_machine_soft_i2c_print, - .make_new = mp_machine_soft_i2c_make_new, - .protocol = &mp_machine_soft_i2c_p, - .locals_dict = (mp_obj_dict_t *)&mp_machine_i2c_locals_dict, -}; +MP_DEFINE_CONST_OBJ_TYPE( + mp_machine_soft_i2c_type, + MP_QSTR_SoftI2C, + MP_TYPE_FLAG_NONE, + mp_machine_soft_i2c_make_new, + print, mp_machine_soft_i2c_print, + protocol, &mp_machine_soft_i2c_p, + locals_dict, (mp_obj_dict_t *)&mp_machine_i2c_locals_dict + ); #endif // MICROPY_PY_MACHINE_SOFTI2C diff --git a/extmod/machine_mem.c b/extmod/machine_mem.c index 73e2f7fd1f..422e99d3ce 100644 --- a/extmod/machine_mem.c +++ b/extmod/machine_mem.c @@ -101,12 +101,14 @@ STATIC mp_obj_t machine_mem_subscr(mp_obj_t self_in, mp_obj_t index, mp_obj_t va } } -const mp_obj_type_t machine_mem_type = { - { &mp_type_type }, - .name = MP_QSTR_mem, - .print = machine_mem_print, - .subscr = machine_mem_subscr, -}; +MP_DEFINE_CONST_OBJ_TYPE( + machine_mem_type, + MP_QSTR_mem, + MP_TYPE_FLAG_NONE, + MP_TYPE_NULL_MAKE_NEW, + print, machine_mem_print, + subscr, machine_mem_subscr + ); const machine_mem_obj_t machine_mem8_obj = {{&machine_mem_type}, 1}; const machine_mem_obj_t machine_mem16_obj = {{&machine_mem_type}, 2}; diff --git a/extmod/machine_pinbase.c b/extmod/machine_pinbase.c index 070c5cde9d..617dd1280c 100644 --- a/extmod/machine_pinbase.c +++ b/extmod/machine_pinbase.c @@ -77,11 +77,12 @@ STATIC const mp_pin_p_t pinbase_pin_p = { .ioctl = pinbase_ioctl, }; -const mp_obj_type_t machine_pinbase_type = { - { &mp_type_type }, - .name = MP_QSTR_PinBase, - .make_new = pinbase_make_new, - .protocol = &pinbase_pin_p, -}; +MP_DEFINE_CONST_OBJ_TYPE( + machine_pinbase_type, + MP_QSTR_PinBase, + MP_TYPE_FLAG_NONE, + pinbase_make_new, + protocol, &pinbase_pin_p + ); #endif // MICROPY_PY_MACHINE diff --git a/extmod/machine_pwm.c b/extmod/machine_pwm.c index ddf49c1358..f12f70a2d1 100644 --- a/extmod/machine_pwm.c +++ b/extmod/machine_pwm.c @@ -132,12 +132,13 @@ STATIC const mp_rom_map_elem_t machine_pwm_locals_dict_table[] = { }; STATIC MP_DEFINE_CONST_DICT(machine_pwm_locals_dict, machine_pwm_locals_dict_table); -const mp_obj_type_t machine_pwm_type = { - { &mp_type_type }, - .name = MP_QSTR_PWM, - .print = mp_machine_pwm_print, - .make_new = mp_machine_pwm_make_new, - .locals_dict = (mp_obj_dict_t *)&machine_pwm_locals_dict, -}; +MP_DEFINE_CONST_OBJ_TYPE( + machine_pwm_type, + MP_QSTR_PWM, + MP_TYPE_FLAG_NONE, + mp_machine_pwm_make_new, + print, mp_machine_pwm_print, + locals_dict, &machine_pwm_locals_dict + ); #endif // MICROPY_PY_MACHINE_PWM diff --git a/extmod/machine_signal.c b/extmod/machine_signal.c index cf7550a2e0..818bc01c27 100644 --- a/extmod/machine_signal.c +++ b/extmod/machine_signal.c @@ -172,13 +172,14 @@ STATIC const mp_pin_p_t signal_pin_p = { .ioctl = signal_ioctl, }; -const mp_obj_type_t machine_signal_type = { - { &mp_type_type }, - .name = MP_QSTR_Signal, - .make_new = signal_make_new, - .call = signal_call, - .protocol = &signal_pin_p, - .locals_dict = (void *)&signal_locals_dict, -}; +MP_DEFINE_CONST_OBJ_TYPE( + machine_signal_type, + MP_QSTR_Signal, + MP_TYPE_FLAG_NONE, + signal_make_new, + call, signal_call, + protocol, &signal_pin_p, + locals_dict, (void *)&signal_locals_dict + ); #endif // MICROPY_PY_MACHINE diff --git a/extmod/machine_spi.c b/extmod/machine_spi.c index ba533b2a65..43148c9c8d 100644 --- a/extmod/machine_spi.c +++ b/extmod/machine_spi.c @@ -251,13 +251,14 @@ const mp_machine_spi_p_t mp_machine_soft_spi_p = { .transfer = mp_machine_soft_spi_transfer, }; -const mp_obj_type_t mp_machine_soft_spi_type = { - { &mp_type_type }, - .name = MP_QSTR_SoftSPI, - .print = mp_machine_soft_spi_print, - .make_new = mp_machine_soft_spi_make_new, - .protocol = &mp_machine_soft_spi_p, - .locals_dict = (mp_obj_dict_t *)&mp_machine_spi_locals_dict, -}; +MP_DEFINE_CONST_OBJ_TYPE( + mp_machine_soft_spi_type, + MP_QSTR_SoftSPI, + MP_TYPE_FLAG_NONE, + mp_machine_soft_spi_make_new, + print, mp_machine_soft_spi_print, + protocol, &mp_machine_soft_spi_p, + locals_dict, (mp_obj_dict_t *)&mp_machine_spi_locals_dict + ); #endif // MICROPY_PY_MACHINE_SOFTSPI diff --git a/extmod/modbluetooth.c b/extmod/modbluetooth.c index 4cc57b3d55..2b7497e1b6 100644 --- a/extmod/modbluetooth.c +++ b/extmod/modbluetooth.c @@ -240,16 +240,16 @@ STATIC void ringbuf_get_uuid(ringbuf_t *ringbuf, mp_obj_bluetooth_uuid_t *uuid) #endif // !MICROPY_PY_BLUETOOTH_USE_SYNC_EVENTS -const mp_obj_type_t mp_type_bluetooth_uuid = { - { &mp_type_type }, - .name = MP_QSTR_UUID, - .make_new = bluetooth_uuid_make_new, - .unary_op = bluetooth_uuid_unary_op, - .binary_op = bluetooth_uuid_binary_op, - .locals_dict = NULL, - .print = bluetooth_uuid_print, - .buffer = bluetooth_uuid_get_buffer, -}; +MP_DEFINE_CONST_OBJ_TYPE( + mp_type_bluetooth_uuid, + MP_QSTR_UUID, + MP_TYPE_FLAG_NONE, + bluetooth_uuid_make_new, + unary_op, bluetooth_uuid_unary_op, + binary_op, bluetooth_uuid_binary_op, + print, bluetooth_uuid_print, + buffer, bluetooth_uuid_get_buffer + ); // ---------------------------------------------------------------------------- // Bluetooth object: General @@ -976,12 +976,13 @@ STATIC const mp_rom_map_elem_t bluetooth_ble_locals_dict_table[] = { }; STATIC MP_DEFINE_CONST_DICT(bluetooth_ble_locals_dict, bluetooth_ble_locals_dict_table); -STATIC const mp_obj_type_t mp_type_bluetooth_ble = { - { &mp_type_type }, - .name = MP_QSTR_BLE, - .make_new = bluetooth_ble_make_new, - .locals_dict = (void *)&bluetooth_ble_locals_dict, -}; +STATIC MP_DEFINE_CONST_OBJ_TYPE( + mp_type_bluetooth_ble, + MP_QSTR_BLE, + MP_TYPE_FLAG_NONE, + bluetooth_ble_make_new, + locals_dict, (void *)&bluetooth_ble_locals_dict + ); STATIC const mp_rom_map_elem_t mp_module_bluetooth_globals_table[] = { { MP_ROM_QSTR(MP_QSTR___name__), MP_ROM_QSTR(MP_QSTR_ubluetooth) }, diff --git a/extmod/modbtree.c b/extmod/modbtree.c index 7a1daacb41..f115be44fe 100644 --- a/extmod/modbtree.c +++ b/extmod/modbtree.c @@ -319,17 +319,19 @@ STATIC const mp_rom_map_elem_t btree_locals_dict_table[] = { STATIC MP_DEFINE_CONST_DICT(btree_locals_dict, btree_locals_dict_table); -STATIC const mp_obj_type_t btree_type = { - { &mp_type_type }, +STATIC MP_DEFINE_CONST_OBJ_TYPE( + btree_type, + MP_QSTR_btree, + MP_TYPE_FLAG_NONE, + MP_TYPE_NULL_MAKE_NEW, // Save on qstr's, reuse same as for module - .name = MP_QSTR_btree, - .print = btree_print, - .getiter = btree_getiter, - .iternext = btree_iternext, - .binary_op = btree_binary_op, - .subscr = btree_subscr, - .locals_dict = (void *)&btree_locals_dict, -}; + print, btree_print, + getiter, btree_getiter, + iternext, btree_iternext, + binary_op, btree_binary_op, + subscr, btree_subscr, + locals_dict, (void *)&btree_locals_dict + ); #endif STATIC const FILEVTABLE btree_stream_fvtable = { diff --git a/extmod/modframebuf.c b/extmod/modframebuf.c index 9542d4303e..1d44312cf3 100644 --- a/extmod/modframebuf.c +++ b/extmod/modframebuf.c @@ -829,13 +829,14 @@ STATIC const mp_rom_map_elem_t framebuf_locals_dict_table[] = { }; STATIC MP_DEFINE_CONST_DICT(framebuf_locals_dict, framebuf_locals_dict_table); -STATIC const mp_obj_type_t mp_type_framebuf = { - { &mp_type_type }, - .name = MP_QSTR_FrameBuffer, - .make_new = framebuf_make_new, - .buffer = framebuf_get_buffer, - .locals_dict = (mp_obj_dict_t *)&framebuf_locals_dict, -}; +STATIC MP_DEFINE_CONST_OBJ_TYPE( + mp_type_framebuf, + MP_QSTR_FrameBuffer, + MP_TYPE_FLAG_NONE, + framebuf_make_new, + buffer, framebuf_get_buffer, + locals_dict, (mp_obj_dict_t *)&framebuf_locals_dict + ); #endif // this factory function is provided for backwards compatibility with old FrameBuffer1 class diff --git a/extmod/modlwip.c b/extmod/modlwip.c index f9451a0ce4..f9d5b76b2c 100644 --- a/extmod/modlwip.c +++ b/extmod/modlwip.c @@ -177,12 +177,13 @@ STATIC const mp_rom_map_elem_t lwip_slip_locals_dict_table[] = { STATIC MP_DEFINE_CONST_DICT(lwip_slip_locals_dict, lwip_slip_locals_dict_table); -STATIC const mp_obj_type_t lwip_slip_type = { - { &mp_type_type }, - .name = MP_QSTR_slip, - .make_new = lwip_slip_make_new, - .locals_dict = (mp_obj_dict_t *)&lwip_slip_locals_dict, -}; +STATIC MP_DEFINE_CONST_OBJ_TYPE( + lwip_slip_type, + MP_QSTR_slip, + MP_TYPE_FLAG_NONE, + lwip_slip_make_new, + locals_dict, (mp_obj_dict_t *)&lwip_slip_locals_dict + ); #endif // MICROPY_PY_LWIP_SLIP @@ -1594,14 +1595,15 @@ STATIC const mp_stream_p_t lwip_socket_stream_p = { .ioctl = lwip_socket_ioctl, }; -STATIC const mp_obj_type_t lwip_socket_type = { - { &mp_type_type }, - .name = MP_QSTR_socket, - .print = lwip_socket_print, - .make_new = lwip_socket_make_new, - .protocol = &lwip_socket_stream_p, - .locals_dict = (mp_obj_dict_t *)&lwip_socket_locals_dict, -}; +STATIC MP_DEFINE_CONST_OBJ_TYPE( + lwip_socket_type, + MP_QSTR_socket, + MP_TYPE_FLAG_NONE, + lwip_socket_make_new, + print, lwip_socket_print, + protocol, &lwip_socket_stream_p, + locals_dict, (mp_obj_dict_t *)&lwip_socket_locals_dict + ); /******************************************************************************/ // Support functions for memory protection. lwIP has its own memory management diff --git a/extmod/moduasyncio.c b/extmod/moduasyncio.c index 6e3603fa18..500d13c5b8 100644 --- a/extmod/moduasyncio.c +++ b/extmod/moduasyncio.c @@ -144,12 +144,13 @@ STATIC const mp_rom_map_elem_t task_queue_locals_dict_table[] = { }; STATIC MP_DEFINE_CONST_DICT(task_queue_locals_dict, task_queue_locals_dict_table); -STATIC const mp_obj_type_t task_queue_type = { - { &mp_type_type }, - .name = MP_QSTR_TaskQueue, - .make_new = task_queue_make_new, - .locals_dict = (mp_obj_dict_t *)&task_queue_locals_dict, -}; +STATIC MP_DEFINE_CONST_OBJ_TYPE( + task_queue_type, + MP_QSTR_TaskQueue, + MP_TYPE_FLAG_NONE, + task_queue_make_new, + locals_dict, (mp_obj_dict_t *)&task_queue_locals_dict + ); /******************************************************************************/ // Task class @@ -286,14 +287,15 @@ STATIC mp_obj_t task_iternext(mp_obj_t self_in) { return mp_const_none; } -STATIC const mp_obj_type_t task_type = { - { &mp_type_type }, - .name = MP_QSTR_Task, - .make_new = task_make_new, - .attr = task_attr, - .getiter = task_getiter, - .iternext = task_iternext, -}; +STATIC MP_DEFINE_CONST_OBJ_TYPE( + task_type, + MP_QSTR_Task, + MP_TYPE_FLAG_NONE, + task_make_new, + attr, task_attr, + getiter, task_getiter, + iternext, task_iternext + ); /******************************************************************************/ // C-level uasyncio module diff --git a/extmod/moducryptolib.c b/extmod/moducryptolib.c index dc0ecb9b20..236b7edfd7 100644 --- a/extmod/moducryptolib.c +++ b/extmod/moducryptolib.c @@ -348,12 +348,13 @@ STATIC const mp_rom_map_elem_t ucryptolib_aes_locals_dict_table[] = { }; STATIC MP_DEFINE_CONST_DICT(ucryptolib_aes_locals_dict, ucryptolib_aes_locals_dict_table); -STATIC const mp_obj_type_t ucryptolib_aes_type = { - { &mp_type_type }, - .name = MP_QSTR_aes, - .make_new = ucryptolib_aes_make_new, - .locals_dict = (void *)&ucryptolib_aes_locals_dict, -}; +STATIC MP_DEFINE_CONST_OBJ_TYPE( + ucryptolib_aes_type, + MP_QSTR_aes, + MP_TYPE_FLAG_NONE, + ucryptolib_aes_make_new, + locals_dict, (void *)&ucryptolib_aes_locals_dict + ); STATIC const mp_rom_map_elem_t mp_module_ucryptolib_globals_table[] = { { MP_ROM_QSTR(MP_QSTR___name__), MP_ROM_QSTR(MP_QSTR_ucryptolib) }, diff --git a/extmod/moductypes.c b/extmod/moductypes.c index 25578dd6b0..a9ad500c2d 100644 --- a/extmod/moductypes.c +++ b/extmod/moductypes.c @@ -634,16 +634,17 @@ STATIC mp_obj_t uctypes_struct_bytes_at(mp_obj_t ptr, mp_obj_t size) { } MP_DEFINE_CONST_FUN_OBJ_2(uctypes_struct_bytes_at_obj, uctypes_struct_bytes_at); -STATIC const mp_obj_type_t uctypes_struct_type = { - { &mp_type_type }, - .name = MP_QSTR_struct, - .print = uctypes_struct_print, - .make_new = uctypes_struct_make_new, - .attr = uctypes_struct_attr, - .subscr = uctypes_struct_subscr, - .unary_op = uctypes_struct_unary_op, - .buffer = uctypes_get_buffer, -}; +STATIC MP_DEFINE_CONST_OBJ_TYPE( + uctypes_struct_type, + MP_QSTR_struct, + MP_TYPE_FLAG_NONE, + uctypes_struct_make_new, + print, uctypes_struct_print, + attr, uctypes_struct_attr, + subscr, uctypes_struct_subscr, + unary_op, uctypes_struct_unary_op, + buffer, uctypes_get_buffer + ); STATIC const mp_rom_map_elem_t mp_module_uctypes_globals_table[] = { { MP_ROM_QSTR(MP_QSTR___name__), MP_ROM_QSTR(MP_QSTR_uctypes) }, diff --git a/extmod/moduhashlib.c b/extmod/moduhashlib.c index 7eae06b77d..44625ed6da 100644 --- a/extmod/moduhashlib.c +++ b/extmod/moduhashlib.c @@ -157,12 +157,13 @@ STATIC const mp_rom_map_elem_t uhashlib_sha256_locals_dict_table[] = { STATIC MP_DEFINE_CONST_DICT(uhashlib_sha256_locals_dict, uhashlib_sha256_locals_dict_table); -STATIC const mp_obj_type_t uhashlib_sha256_type = { - { &mp_type_type }, - .name = MP_QSTR_sha256, - .make_new = uhashlib_sha256_make_new, - .locals_dict = (void *)&uhashlib_sha256_locals_dict, -}; +STATIC MP_DEFINE_CONST_OBJ_TYPE( + uhashlib_sha256_type, + MP_QSTR_sha256, + MP_TYPE_FLAG_NONE, + uhashlib_sha256_make_new, + locals_dict, (void *)&uhashlib_sha256_locals_dict + ); #endif #if MICROPY_PY_UHASHLIB_SHA1 @@ -250,12 +251,13 @@ STATIC const mp_rom_map_elem_t uhashlib_sha1_locals_dict_table[] = { }; STATIC MP_DEFINE_CONST_DICT(uhashlib_sha1_locals_dict, uhashlib_sha1_locals_dict_table); -STATIC const mp_obj_type_t uhashlib_sha1_type = { - { &mp_type_type }, - .name = MP_QSTR_sha1, - .make_new = uhashlib_sha1_make_new, - .locals_dict = (void *)&uhashlib_sha1_locals_dict, -}; +STATIC MP_DEFINE_CONST_OBJ_TYPE( + uhashlib_sha1_type, + MP_QSTR_sha1, + MP_TYPE_FLAG_NONE, + uhashlib_sha1_make_new, + locals_dict, (void *)&uhashlib_sha1_locals_dict + ); #endif #if MICROPY_PY_UHASHLIB_MD5 @@ -343,12 +345,13 @@ STATIC const mp_rom_map_elem_t uhashlib_md5_locals_dict_table[] = { }; STATIC MP_DEFINE_CONST_DICT(uhashlib_md5_locals_dict, uhashlib_md5_locals_dict_table); -STATIC const mp_obj_type_t uhashlib_md5_type = { - { &mp_type_type }, - .name = MP_QSTR_md5, - .make_new = uhashlib_md5_make_new, - .locals_dict = (void *)&uhashlib_md5_locals_dict, -}; +STATIC MP_DEFINE_CONST_OBJ_TYPE( + uhashlib_md5_type, + MP_QSTR_md5, + MP_TYPE_FLAG_NONE, + uhashlib_md5_make_new, + locals_dict, (void *)&uhashlib_md5_locals_dict + ); #endif // MICROPY_PY_UHASHLIB_MD5 STATIC const mp_rom_map_elem_t mp_module_uhashlib_globals_table[] = { diff --git a/extmod/modure.c b/extmod/modure.c index a674d66499..a27c7ff9fd 100644 --- a/extmod/modure.c +++ b/extmod/modure.c @@ -179,12 +179,14 @@ STATIC const mp_rom_map_elem_t match_locals_dict_table[] = { STATIC MP_DEFINE_CONST_DICT(match_locals_dict, match_locals_dict_table); -STATIC const mp_obj_type_t match_type = { - { &mp_type_type }, - .name = MP_QSTR_match, - .print = match_print, - .locals_dict = (void *)&match_locals_dict, -}; +STATIC MP_DEFINE_CONST_OBJ_TYPE( + match_type, + MP_QSTR_match, + MP_TYPE_FLAG_NONE, + MP_TYPE_NULL_MAKE_NEW, + print, match_print, + locals_dict, (void *)&match_locals_dict + ); #endif STATIC void re_print(const mp_print_t *print, mp_obj_t self_in, mp_print_kind_t kind) { @@ -411,12 +413,14 @@ STATIC const mp_rom_map_elem_t re_locals_dict_table[] = { STATIC MP_DEFINE_CONST_DICT(re_locals_dict, re_locals_dict_table); -STATIC const mp_obj_type_t re_type = { - { &mp_type_type }, - .name = MP_QSTR_ure, - .print = re_print, - .locals_dict = (void *)&re_locals_dict, -}; +STATIC MP_DEFINE_CONST_OBJ_TYPE( + re_type, + MP_QSTR_ure, + MP_TYPE_FLAG_NONE, + MP_TYPE_NULL_MAKE_NEW, + print, re_print, + locals_dict, (void *)&re_locals_dict + ); #endif STATIC mp_obj_t mod_re_compile(size_t n_args, const mp_obj_t *args) { diff --git a/extmod/moduselect.c b/extmod/moduselect.c index 70a1de2e40..1a11ee0eab 100644 --- a/extmod/moduselect.c +++ b/extmod/moduselect.c @@ -336,13 +336,15 @@ STATIC const mp_rom_map_elem_t poll_locals_dict_table[] = { }; STATIC MP_DEFINE_CONST_DICT(poll_locals_dict, poll_locals_dict_table); -STATIC const mp_obj_type_t mp_type_poll = { - { &mp_type_type }, - .name = MP_QSTR_poll, - .getiter = mp_identity_getiter, - .iternext = poll_iternext, - .locals_dict = (void *)&poll_locals_dict, -}; +STATIC MP_DEFINE_CONST_OBJ_TYPE( + mp_type_poll, + MP_QSTR_poll, + MP_TYPE_FLAG_NONE, + MP_TYPE_NULL_MAKE_NEW, + getiter, mp_identity_getiter, + iternext, poll_iternext, + locals_dict, (void *)&poll_locals_dict + ); // poll() STATIC mp_obj_t select_poll(void) { diff --git a/extmod/modusocket.c b/extmod/modusocket.c index 4d72531160..6008edb11c 100644 --- a/extmod/modusocket.c +++ b/extmod/modusocket.c @@ -528,14 +528,15 @@ STATIC const mp_stream_p_t socket_stream_p = { .is_text = false, }; -STATIC const mp_obj_type_t socket_type = { - { &mp_type_type }, - .name = MP_QSTR_socket, - .print = socket_print, - .make_new = socket_make_new, - .protocol = &socket_stream_p, - .locals_dict = (mp_obj_dict_t *)&socket_locals_dict, -}; +STATIC MP_DEFINE_CONST_OBJ_TYPE( + socket_type, + MP_QSTR_socket, + MP_TYPE_FLAG_NONE, + socket_make_new, + protocol, &socket_stream_p, + locals_dict, (mp_obj_dict_t *)&socket_locals_dict, + print, socket_print + ); /******************************************************************************/ // usocket module diff --git a/extmod/modussl_axtls.c b/extmod/modussl_axtls.c index 9ba613a3e8..72eb0e214f 100644 --- a/extmod/modussl_axtls.c +++ b/extmod/modussl_axtls.c @@ -314,16 +314,18 @@ STATIC const mp_stream_p_t ussl_socket_stream_p = { .ioctl = ussl_socket_ioctl, }; -STATIC const mp_obj_type_t ussl_socket_type = { - { &mp_type_type }, +STATIC MP_DEFINE_CONST_OBJ_TYPE( + ussl_socket_type, + MP_QSTR_ussl, + MP_TYPE_FLAG_NONE, + MP_TYPE_NULL_MAKE_NEW, // Save on qstr's, reuse same as for module - .name = MP_QSTR_ussl, - .print = ussl_socket_print, - .getiter = NULL, - .iternext = NULL, - .protocol = &ussl_socket_stream_p, - .locals_dict = (void *)&ussl_socket_locals_dict, -}; + print, ussl_socket_print, + getiter, NULL, + iternext, NULL, + protocol, &ussl_socket_stream_p, + locals_dict, (void *)&ussl_socket_locals_dict + ); STATIC mp_obj_t mod_ssl_wrap_socket(size_t n_args, const mp_obj_t *pos_args, mp_map_t *kw_args) { // TODO: Implement more args diff --git a/extmod/modussl_mbedtls.c b/extmod/modussl_mbedtls.c index b14ed9ad0e..0fab915f3f 100644 --- a/extmod/modussl_mbedtls.c +++ b/extmod/modussl_mbedtls.c @@ -392,16 +392,18 @@ STATIC const mp_stream_p_t ussl_socket_stream_p = { .ioctl = socket_ioctl, }; -STATIC const mp_obj_type_t ussl_socket_type = { - { &mp_type_type }, +STATIC MP_DEFINE_CONST_OBJ_TYPE( + ussl_socket_type, + MP_QSTR_ussl, + MP_TYPE_FLAG_NONE, + MP_TYPE_NULL_MAKE_NEW, // Save on qstr's, reuse same as for module - .name = MP_QSTR_ussl, - .print = socket_print, - .getiter = NULL, - .iternext = NULL, - .protocol = &ussl_socket_stream_p, - .locals_dict = (void *)&ussl_socket_locals_dict, -}; + print, socket_print, + getiter, NULL, + iternext, NULL, + protocol, &ussl_socket_stream_p, + locals_dict, (void *)&ussl_socket_locals_dict + ); STATIC mp_obj_t mod_ssl_wrap_socket(size_t n_args, const mp_obj_t *pos_args, mp_map_t *kw_args) { // TODO: Implement more args diff --git a/extmod/modutimeq.c b/extmod/modutimeq.c index 1dde90bd1b..bf4e031895 100644 --- a/extmod/modutimeq.c +++ b/extmod/modutimeq.c @@ -209,13 +209,14 @@ STATIC const mp_rom_map_elem_t utimeq_locals_dict_table[] = { STATIC MP_DEFINE_CONST_DICT(utimeq_locals_dict, utimeq_locals_dict_table); -STATIC const mp_obj_type_t utimeq_type = { - { &mp_type_type }, - .name = MP_QSTR_utimeq, - .make_new = utimeq_make_new, - .unary_op = utimeq_unary_op, - .locals_dict = (void *)&utimeq_locals_dict, -}; +STATIC MP_DEFINE_CONST_OBJ_TYPE( + utimeq_type, + MP_QSTR_utimeq, + MP_TYPE_FLAG_NONE, + utimeq_make_new, + unary_op, utimeq_unary_op, + locals_dict, (void *)&utimeq_locals_dict + ); STATIC const mp_rom_map_elem_t mp_module_utimeq_globals_table[] = { { MP_ROM_QSTR(MP_QSTR___name__), MP_ROM_QSTR(MP_QSTR_utimeq) }, diff --git a/extmod/moduwebsocket.c b/extmod/moduwebsocket.c index a9ad0c22e3..2895978f3d 100644 --- a/extmod/moduwebsocket.c +++ b/extmod/moduwebsocket.c @@ -290,13 +290,14 @@ STATIC const mp_stream_p_t websocket_stream_p = { .ioctl = websocket_ioctl, }; -STATIC const mp_obj_type_t websocket_type = { - { &mp_type_type }, - .name = MP_QSTR_websocket, - .make_new = websocket_make_new, - .protocol = &websocket_stream_p, - .locals_dict = (void *)&websocket_locals_dict, -}; +STATIC MP_DEFINE_CONST_OBJ_TYPE( + websocket_type, + MP_QSTR_websocket, + MP_TYPE_FLAG_NONE, + websocket_make_new, + protocol, &websocket_stream_p, + locals_dict, (void *)&websocket_locals_dict + ); STATIC const mp_rom_map_elem_t uwebsocket_module_globals_table[] = { { MP_ROM_QSTR(MP_QSTR___name__), MP_ROM_QSTR(MP_QSTR_uwebsocket) }, diff --git a/extmod/moduzlib.c b/extmod/moduzlib.c index 0161b9f49c..93c939129e 100644 --- a/extmod/moduzlib.c +++ b/extmod/moduzlib.c @@ -140,13 +140,14 @@ STATIC const mp_stream_p_t decompio_stream_p = { }; #if !MICROPY_ENABLE_DYNRUNTIME -STATIC const mp_obj_type_t decompio_type = { - { &mp_type_type }, - .name = MP_QSTR_DecompIO, - .make_new = decompio_make_new, - .protocol = &decompio_stream_p, - .locals_dict = (void *)&decompio_locals_dict, -}; +STATIC MP_DEFINE_CONST_OBJ_TYPE( + decompio_type, + MP_QSTR_DecompIO, + MP_TYPE_FLAG_NONE, + decompio_make_new, + protocol, &decompio_stream_p, + locals_dict, (void *)&decompio_locals_dict + ); #endif STATIC mp_obj_t mod_uzlib_decompress(size_t n_args, const mp_obj_t *args) { diff --git a/extmod/modwebrepl.c b/extmod/modwebrepl.c index 1a2a718acf..cb893b38dc 100644 --- a/extmod/modwebrepl.c +++ b/extmod/modwebrepl.c @@ -342,13 +342,14 @@ STATIC const mp_stream_p_t webrepl_stream_p = { .ioctl = webrepl_ioctl, }; -STATIC const mp_obj_type_t webrepl_type = { - { &mp_type_type }, - .name = MP_QSTR__webrepl, - .make_new = webrepl_make_new, - .protocol = &webrepl_stream_p, - .locals_dict = (mp_obj_dict_t *)&webrepl_locals_dict, -}; +STATIC MP_DEFINE_CONST_OBJ_TYPE( + webrepl_type, + MP_QSTR__webrepl, + MP_TYPE_FLAG_NONE, + webrepl_make_new, + protocol, &webrepl_stream_p, + locals_dict, (mp_obj_dict_t *)&webrepl_locals_dict + ); STATIC const mp_rom_map_elem_t webrepl_module_globals_table[] = { { MP_ROM_QSTR(MP_QSTR___name__), MP_ROM_QSTR(MP_QSTR__webrepl) }, diff --git a/extmod/network_cyw43.c b/extmod/network_cyw43.c index 9df799119f..fbd0a750b8 100644 --- a/extmod/network_cyw43.c +++ b/extmod/network_cyw43.c @@ -496,12 +496,13 @@ STATIC const mp_rom_map_elem_t network_cyw43_locals_dict_table[] = { }; STATIC MP_DEFINE_CONST_DICT(network_cyw43_locals_dict, network_cyw43_locals_dict_table); -const mp_obj_type_t mp_network_cyw43_type = { - { &mp_type_type }, - .name = MP_QSTR_CYW43, - .print = network_cyw43_print, - .make_new = network_cyw43_make_new, - .locals_dict = (mp_obj_dict_t *)&network_cyw43_locals_dict, -}; +MP_DEFINE_CONST_OBJ_TYPE( + mp_network_cyw43_type, + MP_QSTR_CYW43, + MP_TYPE_FLAG_NONE, + network_cyw43_make_new, + print, network_cyw43_print, + locals_dict, (mp_obj_dict_t *)&network_cyw43_locals_dict + ); #endif // MICROPY_PY_NETWORK_CYW43 diff --git a/extmod/network_ninaw10.c b/extmod/network_ninaw10.c index 4014a71c1a..0906176d20 100644 --- a/extmod/network_ninaw10.c +++ b/extmod/network_ninaw10.c @@ -774,13 +774,16 @@ static const mp_rom_map_elem_t nina_locals_dict_table[] = { static MP_DEFINE_CONST_DICT(nina_locals_dict, nina_locals_dict_table); +STATIC MP_DEFINE_CONST_OBJ_TYPE( + mod_network_nic_type_nina_base, + MP_QSTR_nina, + MP_TYPE_FLAG_NONE, + network_ninaw10_make_new, + locals_dict, &nina_locals_dict + ); + const mod_network_nic_type_t mod_network_nic_type_nina = { - .base = { - { &mp_type_type }, - .name = MP_QSTR_nina, - .make_new = network_ninaw10_make_new, - .locals_dict = (mp_obj_t)&nina_locals_dict, - }, + .base = mod_network_nic_type_nina_base, .gethostbyname = network_ninaw10_gethostbyname, .socket = network_ninaw10_socket_socket, .close = network_ninaw10_socket_close, diff --git a/extmod/network_wiznet5k.c b/extmod/network_wiznet5k.c index 95c852d7f7..951a2966c9 100644 --- a/extmod/network_wiznet5k.c +++ b/extmod/network_wiznet5k.c @@ -1016,20 +1016,24 @@ STATIC const mp_rom_map_elem_t wiznet5k_locals_dict_table[] = { STATIC MP_DEFINE_CONST_DICT(wiznet5k_locals_dict, wiznet5k_locals_dict_table); #if WIZNET5K_WITH_LWIP_STACK -const mp_obj_type_t mod_network_nic_type_wiznet5k = { - { &mp_type_type }, - .name = MP_QSTR_WIZNET5K, - .make_new = wiznet5k_make_new, - .locals_dict = (mp_obj_dict_t *)&wiznet5k_locals_dict, -}; +MP_DEFINE_CONST_OBJ_TYPE( + mod_network_nic_type_wiznet5k, + MP_QSTR_WIZNET5K, + MP_TYPE_FLAG_NONE, + wiznet5k_make_new, + locals_dict, &wiznet5k_locals_dict + ); #else // WIZNET5K_PROVIDED_STACK +STATIC MP_DEFINE_CONST_OBJ_TYPE( + mod_network_nic_type_wiznet5k_base, + MP_QSTR_WIZNET5K, + MP_TYPE_FLAG_NONE, + wiznet5k_make_new, + locals_dict, &wiznet5k_locals_dict + ); + const mod_network_nic_type_t mod_network_nic_type_wiznet5k = { - .base = { - { &mp_type_type }, - .name = MP_QSTR_WIZNET5K, - .make_new = wiznet5k_make_new, - .locals_dict = (mp_obj_dict_t *)&wiznet5k_locals_dict, - }, + .base = mod_network_nic_type_wiznet5k_base, .gethostbyname = wiznet5k_gethostbyname, .socket = wiznet5k_socket_socket, .close = wiznet5k_socket_close, diff --git a/extmod/vfs_fat.c b/extmod/vfs_fat.c index 8d2f13be47..4a2ef883c2 100644 --- a/extmod/vfs_fat.c +++ b/extmod/vfs_fat.c @@ -431,12 +431,13 @@ STATIC const mp_vfs_proto_t fat_vfs_proto = { .import_stat = fat_vfs_import_stat, }; -const mp_obj_type_t mp_fat_vfs_type = { - { &mp_type_type }, - .name = MP_QSTR_VfsFat, - .make_new = fat_vfs_make_new, - .protocol = &fat_vfs_proto, - .locals_dict = (mp_obj_dict_t *)&fat_vfs_locals_dict, -}; +MP_DEFINE_CONST_OBJ_TYPE( + mp_fat_vfs_type, + MP_QSTR_VfsFat, + MP_TYPE_FLAG_NONE, + fat_vfs_make_new, + protocol, &fat_vfs_proto, + locals_dict, (mp_obj_dict_t *)&fat_vfs_locals_dict + ); #endif // MICROPY_VFS_FAT diff --git a/extmod/vfs_fat_file.c b/extmod/vfs_fat_file.c index 874f10c500..0d4af09b45 100644 --- a/extmod/vfs_fat_file.c +++ b/extmod/vfs_fat_file.c @@ -176,15 +176,17 @@ STATIC const mp_stream_p_t vfs_fat_fileio_stream_p = { .ioctl = file_obj_ioctl, }; -const mp_obj_type_t mp_type_vfs_fat_fileio = { - { &mp_type_type }, - .name = MP_QSTR_FileIO, - .print = file_obj_print, - .getiter = mp_identity_getiter, - .iternext = mp_stream_unbuffered_iter, - .protocol = &vfs_fat_fileio_stream_p, - .locals_dict = (mp_obj_dict_t *)&vfs_fat_rawfile_locals_dict, -}; +MP_DEFINE_CONST_OBJ_TYPE( + mp_type_vfs_fat_fileio, + MP_QSTR_FileIO, + MP_TYPE_FLAG_NONE, + MP_TYPE_NULL_MAKE_NEW, + print, file_obj_print, + getiter, mp_identity_getiter, + iternext, mp_stream_unbuffered_iter, + protocol, &vfs_fat_fileio_stream_p, + locals_dict, (mp_obj_dict_t *)&vfs_fat_rawfile_locals_dict + ); STATIC const mp_stream_p_t vfs_fat_textio_stream_p = { .read = file_obj_read, @@ -193,15 +195,17 @@ STATIC const mp_stream_p_t vfs_fat_textio_stream_p = { .is_text = true, }; -const mp_obj_type_t mp_type_vfs_fat_textio = { - { &mp_type_type }, - .name = MP_QSTR_TextIOWrapper, - .print = file_obj_print, - .getiter = mp_identity_getiter, - .iternext = mp_stream_unbuffered_iter, - .protocol = &vfs_fat_textio_stream_p, - .locals_dict = (mp_obj_dict_t *)&vfs_fat_rawfile_locals_dict, -}; +MP_DEFINE_CONST_OBJ_TYPE( + mp_type_vfs_fat_textio, + MP_QSTR_TextIOWrapper, + MP_TYPE_FLAG_NONE, + MP_TYPE_NULL_MAKE_NEW, + print, file_obj_print, + getiter, mp_identity_getiter, + iternext, mp_stream_unbuffered_iter, + protocol, &vfs_fat_textio_stream_p, + locals_dict, (mp_obj_dict_t *)&vfs_fat_rawfile_locals_dict + ); // Factory function for I/O stream classes STATIC mp_obj_t fat_vfs_open(mp_obj_t self_in, mp_obj_t path_in, mp_obj_t mode_in) { diff --git a/extmod/vfs_lfsx.c b/extmod/vfs_lfsx.c index fbfeaa5ccf..72c6696105 100644 --- a/extmod/vfs_lfsx.c +++ b/extmod/vfs_lfsx.c @@ -502,14 +502,15 @@ STATIC const mp_vfs_proto_t MP_VFS_LFSx(proto) = { .import_stat = MP_VFS_LFSx(import_stat), }; -const mp_obj_type_t MP_TYPE_VFS_LFSx = { - { &mp_type_type }, +MP_DEFINE_CONST_OBJ_TYPE( + MP_TYPE_VFS_LFSx, #if LFS_BUILD_VERSION == 1 - .name = MP_QSTR_VfsLfs1, + MP_QSTR_VfsLfs1, #else - .name = MP_QSTR_VfsLfs2, + MP_QSTR_VfsLfs2, #endif - .make_new = MP_VFS_LFSx(make_new), - .protocol = &MP_VFS_LFSx(proto), - .locals_dict = (mp_obj_dict_t *)&MP_VFS_LFSx(locals_dict), -}; + MP_TYPE_FLAG_NONE, + MP_VFS_LFSx(make_new), + protocol, &MP_VFS_LFSx(proto), + locals_dict, (mp_obj_dict_t *)&MP_VFS_LFSx(locals_dict) + ); diff --git a/extmod/vfs_lfsx_file.c b/extmod/vfs_lfsx_file.c index 124361feb9..ba90cc6084 100644 --- a/extmod/vfs_lfsx_file.c +++ b/extmod/vfs_lfsx_file.c @@ -220,15 +220,17 @@ STATIC const mp_stream_p_t MP_VFS_LFSx(fileio_stream_p) = { .ioctl = MP_VFS_LFSx(file_ioctl), }; -const mp_obj_type_t MP_TYPE_VFS_LFSx_(_fileio) = { - { &mp_type_type }, - .name = MP_QSTR_FileIO, - .print = MP_VFS_LFSx(file_print), - .getiter = mp_identity_getiter, - .iternext = mp_stream_unbuffered_iter, - .protocol = &MP_VFS_LFSx(fileio_stream_p), - .locals_dict = (mp_obj_dict_t *)&MP_VFS_LFSx(file_locals_dict), -}; +MP_DEFINE_CONST_OBJ_TYPE( + MP_TYPE_VFS_LFSx_(_fileio), + MP_QSTR_FileIO, + MP_TYPE_FLAG_NONE, + MP_TYPE_NULL_MAKE_NEW, + print, MP_VFS_LFSx(file_print), + getiter, mp_identity_getiter, + iternext, mp_stream_unbuffered_iter, + protocol, &MP_VFS_LFSx(fileio_stream_p), + locals_dict, (mp_obj_dict_t *)&MP_VFS_LFSx(file_locals_dict) + ); STATIC const mp_stream_p_t MP_VFS_LFSx(textio_stream_p) = { .read = MP_VFS_LFSx(file_read), @@ -237,12 +239,14 @@ STATIC const mp_stream_p_t MP_VFS_LFSx(textio_stream_p) = { .is_text = true, }; -const mp_obj_type_t MP_TYPE_VFS_LFSx_(_textio) = { - { &mp_type_type }, - .name = MP_QSTR_TextIOWrapper, - .print = MP_VFS_LFSx(file_print), - .getiter = mp_identity_getiter, - .iternext = mp_stream_unbuffered_iter, - .protocol = &MP_VFS_LFSx(textio_stream_p), - .locals_dict = (mp_obj_dict_t *)&MP_VFS_LFSx(file_locals_dict), -}; +MP_DEFINE_CONST_OBJ_TYPE( + MP_TYPE_VFS_LFSx_(_textio), + MP_QSTR_TextIOWrapper, + MP_TYPE_FLAG_NONE, + MP_TYPE_NULL_MAKE_NEW, + print, MP_VFS_LFSx(file_print), + getiter, mp_identity_getiter, + iternext, mp_stream_unbuffered_iter, + protocol, &MP_VFS_LFSx(textio_stream_p), + locals_dict, (mp_obj_dict_t *)&MP_VFS_LFSx(file_locals_dict) + ); diff --git a/extmod/vfs_posix.c b/extmod/vfs_posix.c index 36b211b84d..79126c0070 100644 --- a/extmod/vfs_posix.c +++ b/extmod/vfs_posix.c @@ -398,12 +398,13 @@ STATIC const mp_vfs_proto_t vfs_posix_proto = { .import_stat = mp_vfs_posix_import_stat, }; -const mp_obj_type_t mp_type_vfs_posix = { - { &mp_type_type }, - .name = MP_QSTR_VfsPosix, - .make_new = vfs_posix_make_new, - .protocol = &vfs_posix_proto, - .locals_dict = (mp_obj_dict_t *)&vfs_posix_locals_dict, -}; +MP_DEFINE_CONST_OBJ_TYPE( + mp_type_vfs_posix, + MP_QSTR_VfsPosix, + MP_TYPE_FLAG_NONE, + vfs_posix_make_new, + protocol, &vfs_posix_proto, + locals_dict, (mp_obj_dict_t *)&vfs_posix_locals_dict + ); #endif // MICROPY_VFS_POSIX diff --git a/extmod/vfs_posix_file.c b/extmod/vfs_posix_file.c index c550842cd4..85aef1617b 100644 --- a/extmod/vfs_posix_file.c +++ b/extmod/vfs_posix_file.c @@ -249,15 +249,17 @@ STATIC const mp_stream_p_t vfs_posix_fileio_stream_p = { .ioctl = vfs_posix_file_ioctl, }; -const mp_obj_type_t mp_type_vfs_posix_fileio = { - { &mp_type_type }, - .name = MP_QSTR_FileIO, - .print = vfs_posix_file_print, - .getiter = mp_identity_getiter, - .iternext = mp_stream_unbuffered_iter, - .protocol = &vfs_posix_fileio_stream_p, - .locals_dict = (mp_obj_dict_t *)&vfs_posix_rawfile_locals_dict, -}; +MP_DEFINE_CONST_OBJ_TYPE( + mp_type_vfs_posix_fileio, + MP_QSTR_FileIO, + MP_TYPE_FLAG_NONE, + MP_TYPE_NULL_MAKE_NEW, + print, vfs_posix_file_print, + getiter, mp_identity_getiter, + iternext, mp_stream_unbuffered_iter, + protocol, &vfs_posix_fileio_stream_p, + locals_dict, (mp_obj_dict_t *)&vfs_posix_rawfile_locals_dict + ); STATIC const mp_stream_p_t vfs_posix_textio_stream_p = { .read = vfs_posix_file_read, @@ -266,15 +268,17 @@ STATIC const mp_stream_p_t vfs_posix_textio_stream_p = { .is_text = true, }; -const mp_obj_type_t mp_type_vfs_posix_textio = { - { &mp_type_type }, - .name = MP_QSTR_TextIOWrapper, - .print = vfs_posix_file_print, - .getiter = mp_identity_getiter, - .iternext = mp_stream_unbuffered_iter, - .protocol = &vfs_posix_textio_stream_p, - .locals_dict = (mp_obj_dict_t *)&vfs_posix_rawfile_locals_dict, -}; +MP_DEFINE_CONST_OBJ_TYPE( + mp_type_vfs_posix_textio, + MP_QSTR_TextIOWrapper, + MP_TYPE_FLAG_NONE, + MP_TYPE_NULL_MAKE_NEW, + print, vfs_posix_file_print, + getiter, mp_identity_getiter, + iternext, mp_stream_unbuffered_iter, + protocol, &vfs_posix_textio_stream_p, + locals_dict, (mp_obj_dict_t *)&vfs_posix_rawfile_locals_dict + ); const mp_obj_vfs_posix_file_t mp_sys_stdin_obj = {{&mp_type_vfs_posix_textio}, STDIN_FILENO}; const mp_obj_vfs_posix_file_t mp_sys_stdout_obj = {{&mp_type_vfs_posix_textio}, STDOUT_FILENO}; diff --git a/ports/cc3200/misc/mpirq.c b/ports/cc3200/misc/mpirq.c index eb93e5eef0..e9cae92a32 100644 --- a/ports/cc3200/misc/mpirq.c +++ b/ports/cc3200/misc/mpirq.c @@ -190,11 +190,13 @@ STATIC const mp_rom_map_elem_t mp_irq_locals_dict_table[] = { STATIC MP_DEFINE_CONST_DICT(mp_irq_locals_dict, mp_irq_locals_dict_table); -const mp_obj_type_t mp_irq_type = { - { &mp_type_type }, - .name = MP_QSTR_irq, - .call = mp_irq_call, - .locals_dict = (mp_obj_t)&mp_irq_locals_dict, -}; +MP_DEFINE_CONST_OBJ_TYPE( + mp_irq_type, + MP_QSTR_irq, + MP_TYPE_FLAG_NONE, + MP_TYPE_NULL_MAKE_NEW, + call, mp_irq_call, + locals_dict, (mp_obj_t)&mp_irq_locals_dict + ); MP_REGISTER_ROOT_POINTER(mp_obj_list_t mp_irq_obj_list); diff --git a/ports/cc3200/mods/modnetwork.c b/ports/cc3200/mods/modnetwork.c index d6ccc7c6a0..a741893007 100644 --- a/ports/cc3200/mods/modnetwork.c +++ b/ports/cc3200/mods/modnetwork.c @@ -171,10 +171,11 @@ STATIC const mp_rom_map_elem_t network_server_locals_dict_table[] = { STATIC MP_DEFINE_CONST_DICT(network_server_locals_dict, network_server_locals_dict_table); -STATIC const mp_obj_type_t network_server_type = { - { &mp_type_type }, - .name = MP_QSTR_Server, - .make_new = network_server_make_new, - .locals_dict = (mp_obj_t)&network_server_locals_dict, -}; +STATIC MP_DEFINE_CONST_OBJ_TYPE( + network_server_type, + MP_QSTR_Server, + MP_TYPE_FLAG_NONE, + network_server_make_new, + locals_dict, (mp_obj_t)&network_server_locals_dict + ); #endif diff --git a/ports/cc3200/mods/moduhashlib.c b/ports/cc3200/mods/moduhashlib.c index fc11569b7f..5437cfb264 100644 --- a/ports/cc3200/mods/moduhashlib.c +++ b/ports/cc3200/mods/moduhashlib.c @@ -177,19 +177,21 @@ STATIC MP_DEFINE_CONST_DICT(hash_locals_dict, hash_locals_dict_table); // .locals_dict = (mp_obj_t)&hash_locals_dict, //}; -STATIC const mp_obj_type_t sha1_type = { - { &mp_type_type }, - .name = MP_QSTR_sha1, - .make_new = hash_make_new, - .locals_dict = (mp_obj_t)&hash_locals_dict, -}; +STATIC MP_DEFINE_CONST_OBJ_TYPE( + sha1_type, + MP_QSTR_sha1, + MP_TYPE_FLAG_NONE, + hash_make_new, + locals_dict, (mp_obj_t)&hash_locals_dict + ); -STATIC const mp_obj_type_t sha256_type = { - { &mp_type_type }, - .name = MP_QSTR_sha256, - .make_new = hash_make_new, - .locals_dict = (mp_obj_t)&hash_locals_dict, -}; +STATIC MP_DEFINE_CONST_OBJ_TYPE( + sha256_type, + MP_QSTR_sha256, + MP_TYPE_FLAG_NONE, + hash_make_new, + locals_dict, (mp_obj_t)&hash_locals_dict + ); STATIC const mp_rom_map_elem_t mp_module_hashlib_globals_table[] = { { MP_ROM_QSTR(MP_QSTR___name__), MP_ROM_QSTR(MP_QSTR_uhashlib) }, diff --git a/ports/cc3200/mods/modusocket.c b/ports/cc3200/mods/modusocket.c index 23982eb966..11199de146 100644 --- a/ports/cc3200/mods/modusocket.c +++ b/ports/cc3200/mods/modusocket.c @@ -759,13 +759,14 @@ const mp_stream_p_t socket_stream_p = { .is_text = false, }; -STATIC const mp_obj_type_t socket_type = { - { &mp_type_type }, - .name = MP_QSTR_socket, - .make_new = socket_make_new, - .protocol = &socket_stream_p, - .locals_dict = (mp_obj_t)&socket_locals_dict, -}; +STATIC MP_DEFINE_CONST_OBJ_TYPE( + socket_type, + MP_QSTR_socket, + MP_TYPE_FLAG_NONE, + socket_make_new, + protocol, &socket_stream_p, + locals_dict, (mp_obj_t)&socket_locals_dict + ); /******************************************************************************/ // usocket module diff --git a/ports/cc3200/mods/modussl.c b/ports/cc3200/mods/modussl.c index cd2c62dcb8..d0909e7c29 100644 --- a/ports/cc3200/mods/modussl.c +++ b/ports/cc3200/mods/modussl.c @@ -60,14 +60,16 @@ STATIC const mp_obj_type_t ssl_socket_type; // ssl sockets inherit from normal socket, so we take its // locals and stream methods -STATIC const mp_obj_type_t ssl_socket_type = { - { &mp_type_type }, - .name = MP_QSTR_ussl, - .getiter = NULL, - .iternext = NULL, - .protocol = &socket_stream_p, - .locals_dict = (mp_obj_t)&socket_locals_dict, -}; +STATIC MP_DEFINE_CONST_OBJ_TYPE( + ssl_socket_type, + MP_QSTR_ussl, + MP_TYPE_FLAG_NONE, + MP_TYPE_NULL_MAKE_NEW, + getiter, NULL, + iternext, NULL, + protocol, &socket_stream_p, + locals_dict, (mp_obj_t)&socket_locals_dict + ); STATIC mp_obj_t mod_ssl_wrap_socket(size_t n_args, const mp_obj_t *pos_args, mp_map_t *kw_args) { STATIC const mp_arg_t allowed_args[] = { diff --git a/ports/cc3200/mods/modwlan.c b/ports/cc3200/mods/modwlan.c index 3b686932e8..24f5d196d2 100644 --- a/ports/cc3200/mods/modwlan.c +++ b/ports/cc3200/mods/modwlan.c @@ -1285,13 +1285,16 @@ STATIC const mp_rom_map_elem_t wlan_locals_dict_table[] = { }; STATIC MP_DEFINE_CONST_DICT(wlan_locals_dict, wlan_locals_dict_table); +STATIC MP_DEFINE_CONST_OBJ_TYPE( + mod_network_nic_type_wlan_base, + MP_QSTR_WLAN, + MP_TYPE_FLAG_NONE, + wlan_make_new, + locals_dict, (mp_obj_t)&wlan_locals_dict + ); + const mod_network_nic_type_t mod_network_nic_type_wlan = { - .base = { - { &mp_type_type }, - .name = MP_QSTR_WLAN, - .make_new = wlan_make_new, - .locals_dict = (mp_obj_t)&wlan_locals_dict, - }, + .base = mod_network_nic_type_wlan_base, }; STATIC const mp_irq_methods_t wlan_irq_methods = { diff --git a/ports/cc3200/mods/pybadc.c b/ports/cc3200/mods/pybadc.c index fbdd393cd2..a114eeda16 100644 --- a/ports/cc3200/mods/pybadc.c +++ b/ports/cc3200/mods/pybadc.c @@ -233,13 +233,14 @@ STATIC const mp_rom_map_elem_t adc_locals_dict_table[] = { STATIC MP_DEFINE_CONST_DICT(adc_locals_dict, adc_locals_dict_table); -const mp_obj_type_t pyb_adc_type = { - { &mp_type_type }, - .name = MP_QSTR_ADC, - .print = adc_print, - .make_new = adc_make_new, - .locals_dict = (mp_obj_t)&adc_locals_dict, -}; +MP_DEFINE_CONST_OBJ_TYPE( + pyb_adc_type, + MP_QSTR_ADC, + MP_TYPE_FLAG_NONE, + adc_make_new, + print, adc_print, + locals_dict, (mp_obj_t)&adc_locals_dict + ); STATIC void adc_channel_print(const mp_print_t *print, mp_obj_t self_in, mp_print_kind_t kind) { pyb_adc_channel_obj_t *self = self_in; @@ -300,10 +301,12 @@ STATIC const mp_rom_map_elem_t adc_channel_locals_dict_table[] = { STATIC MP_DEFINE_CONST_DICT(adc_channel_locals_dict, adc_channel_locals_dict_table); -STATIC const mp_obj_type_t pyb_adc_channel_type = { - { &mp_type_type }, - .name = MP_QSTR_ADCChannel, - .print = adc_channel_print, - .call = adc_channel_call, - .locals_dict = (mp_obj_t)&adc_channel_locals_dict, -}; +STATIC MP_DEFINE_CONST_OBJ_TYPE( + pyb_adc_channel_type, + MP_QSTR_ADCChannel, + MP_TYPE_FLAG_NONE, + MP_TYPE_NULL_MAKE_NEW, + print, adc_channel_print, + call, adc_channel_call, + locals_dict, (mp_obj_t)&adc_channel_locals_dict + ); diff --git a/ports/cc3200/mods/pybflash.c b/ports/cc3200/mods/pybflash.c index 9d534608be..4cfafb7abf 100644 --- a/ports/cc3200/mods/pybflash.c +++ b/ports/cc3200/mods/pybflash.c @@ -84,12 +84,13 @@ STATIC const mp_rom_map_elem_t pyb_flash_locals_dict_table[] = { STATIC MP_DEFINE_CONST_DICT(pyb_flash_locals_dict, pyb_flash_locals_dict_table); -const mp_obj_type_t pyb_flash_type = { - { &mp_type_type }, - .name = MP_QSTR_Flash, - .make_new = pyb_flash_make_new, - .locals_dict = (mp_obj_t)&pyb_flash_locals_dict, -}; +MP_DEFINE_CONST_OBJ_TYPE( + pyb_flash_type, + MP_QSTR_Flash, + MP_TYPE_FLAG_NONE, + pyb_flash_make_new, + locals_dict, (mp_obj_t)&pyb_flash_locals_dict + ); void pyb_flash_init_vfs(fs_user_mount_t *vfs) { vfs->base.type = &mp_fat_vfs_type; diff --git a/ports/cc3200/mods/pybi2c.c b/ports/cc3200/mods/pybi2c.c index 40b3e2a207..91a0b9b9f9 100644 --- a/ports/cc3200/mods/pybi2c.c +++ b/ports/cc3200/mods/pybi2c.c @@ -521,10 +521,11 @@ STATIC const mp_rom_map_elem_t pyb_i2c_locals_dict_table[] = { STATIC MP_DEFINE_CONST_DICT(pyb_i2c_locals_dict, pyb_i2c_locals_dict_table); -const mp_obj_type_t pyb_i2c_type = { - { &mp_type_type }, - .name = MP_QSTR_I2C, - .print = pyb_i2c_print, - .make_new = pyb_i2c_make_new, - .locals_dict = (mp_obj_t)&pyb_i2c_locals_dict, -}; +MP_DEFINE_CONST_OBJ_TYPE( + pyb_i2c_type, + MP_QSTR_I2C, + MP_TYPE_FLAG_NONE, + pyb_i2c_make_new, + print, pyb_i2c_print, + locals_dict, (mp_obj_t)&pyb_i2c_locals_dict + ); diff --git a/ports/cc3200/mods/pybpin.c b/ports/cc3200/mods/pybpin.c index fd2f032e8d..948cda70d4 100644 --- a/ports/cc3200/mods/pybpin.c +++ b/ports/cc3200/mods/pybpin.c @@ -931,14 +931,15 @@ STATIC const mp_rom_map_elem_t pin_locals_dict_table[] = { STATIC MP_DEFINE_CONST_DICT(pin_locals_dict, pin_locals_dict_table); -const mp_obj_type_t pin_type = { - { &mp_type_type }, - .name = MP_QSTR_Pin, - .print = pin_print, - .make_new = pin_make_new, - .call = pin_call, - .locals_dict = (mp_obj_t)&pin_locals_dict, -}; +MP_DEFINE_CONST_OBJ_TYPE( + pin_type, + MP_QSTR_Pin, + MP_TYPE_FLAG_NONE, + pin_make_new, + print, pin_print, + call, pin_call, + locals_dict, (mp_obj_t)&pin_locals_dict + ); STATIC const mp_irq_methods_t pin_irq_methods = { .init = pin_irq, @@ -952,10 +953,12 @@ STATIC void pin_named_pins_obj_print(const mp_print_t *print, mp_obj_t self_in, mp_printf(print, "", self->name); } -const mp_obj_type_t pin_board_pins_obj_type = { - { &mp_type_type }, - .name = MP_QSTR_board, - .print = pin_named_pins_obj_print, - .locals_dict = (mp_obj_t)&pin_board_pins_locals_dict, -}; +MP_DEFINE_CONST_OBJ_TYPE( + pin_board_pins_obj_type, + MP_QSTR_board, + MP_TYPE_FLAG_NONE, + MP_TYPE_NULL_MAKE_NEW, + print, pin_named_pins_obj_print, + locals_dict, (mp_obj_t)&pin_board_pins_locals_dict + ); diff --git a/ports/cc3200/mods/pybrtc.c b/ports/cc3200/mods/pybrtc.c index 6c1918831c..2761cb3c64 100644 --- a/ports/cc3200/mods/pybrtc.c +++ b/ports/cc3200/mods/pybrtc.c @@ -469,12 +469,13 @@ STATIC const mp_rom_map_elem_t pyb_rtc_locals_dict_table[] = { }; STATIC MP_DEFINE_CONST_DICT(pyb_rtc_locals_dict, pyb_rtc_locals_dict_table); -const mp_obj_type_t pyb_rtc_type = { - { &mp_type_type }, - .name = MP_QSTR_RTC, - .make_new = pyb_rtc_make_new, - .locals_dict = (mp_obj_t)&pyb_rtc_locals_dict, -}; +MP_DEFINE_CONST_OBJ_TYPE( + pyb_rtc_type, + MP_QSTR_RTC, + MP_TYPE_FLAG_NONE, + pyb_rtc_make_new, + locals_dict, (mp_obj_t)&pyb_rtc_locals_dict + ); STATIC const mp_irq_methods_t pyb_rtc_irq_methods = { .init = pyb_rtc_irq, diff --git a/ports/cc3200/mods/pybsd.c b/ports/cc3200/mods/pybsd.c index 817127634d..d8834e36f7 100644 --- a/ports/cc3200/mods/pybsd.c +++ b/ports/cc3200/mods/pybsd.c @@ -212,9 +212,10 @@ STATIC const mp_rom_map_elem_t pyb_sd_locals_dict_table[] = { STATIC MP_DEFINE_CONST_DICT(pyb_sd_locals_dict, pyb_sd_locals_dict_table); -const mp_obj_type_t pyb_sd_type = { - { &mp_type_type }, - .name = MP_QSTR_SD, - .make_new = pyb_sd_make_new, - .locals_dict = (mp_obj_t)&pyb_sd_locals_dict, -}; +MP_DEFINE_CONST_OBJ_TYPE( + pyb_sd_type, + MP_QSTR_SD, + MP_TYPE_FLAG_NONE, + pyb_sd_make_new, + locals_dict, (mp_obj_t)&pyb_sd_locals_dict + ); diff --git a/ports/cc3200/mods/pybsleep.c b/ports/cc3200/mods/pybsleep.c index 76fe0849a4..423099991f 100644 --- a/ports/cc3200/mods/pybsleep.c +++ b/ports/cc3200/mods/pybsleep.c @@ -125,10 +125,12 @@ STATIC pybsleep_data_t pybsleep_data = {NULL, NULL, NULL}; volatile arm_cm4_core_regs_t vault_arm_registers; STATIC pybsleep_reset_cause_t pybsleep_reset_cause = PYB_SLP_PWRON_RESET; STATIC pybsleep_wake_reason_t pybsleep_wake_reason = PYB_SLP_WAKED_PWRON; -STATIC const mp_obj_type_t pyb_sleep_type = { - { &mp_type_type }, - .name = MP_QSTR_sleep, -}; +STATIC MP_DEFINE_CONST_OBJ_TYPE( + pyb_sleep_type, + MP_QSTR_sleep, + MP_TYPE_FLAG_NONE, + MP_TYPE_NULL_MAKE_NEW + ); /****************************************************************************** DECLARE PRIVATE FUNCTIONS diff --git a/ports/cc3200/mods/pybspi.c b/ports/cc3200/mods/pybspi.c index ed03b09060..50d897633e 100644 --- a/ports/cc3200/mods/pybspi.c +++ b/ports/cc3200/mods/pybspi.c @@ -377,10 +377,11 @@ STATIC const mp_rom_map_elem_t pyb_spi_locals_dict_table[] = { STATIC MP_DEFINE_CONST_DICT(pyb_spi_locals_dict, pyb_spi_locals_dict_table); -const mp_obj_type_t pyb_spi_type = { - { &mp_type_type }, - .name = MP_QSTR_SPI, - .print = pyb_spi_print, - .make_new = pyb_spi_make_new, - .locals_dict = (mp_obj_t)&pyb_spi_locals_dict, -}; +MP_DEFINE_CONST_OBJ_TYPE( + pyb_spi_type, + MP_QSTR_SPI, + MP_TYPE_FLAG_NONE, + pyb_spi_make_new, + print, pyb_spi_print, + locals_dict, (mp_obj_t)&pyb_spi_locals_dict + ); diff --git a/ports/cc3200/mods/pybtimer.c b/ports/cc3200/mods/pybtimer.c index b2725ae166..a8bc7821e0 100644 --- a/ports/cc3200/mods/pybtimer.c +++ b/ports/cc3200/mods/pybtimer.c @@ -459,13 +459,14 @@ STATIC const mp_rom_map_elem_t pyb_timer_locals_dict_table[] = { }; STATIC MP_DEFINE_CONST_DICT(pyb_timer_locals_dict, pyb_timer_locals_dict_table); -const mp_obj_type_t pyb_timer_type = { - { &mp_type_type }, - .name = MP_QSTR_Timer, - .print = pyb_timer_print, - .make_new = pyb_timer_make_new, - .locals_dict = (mp_obj_t)&pyb_timer_locals_dict, -}; +MP_DEFINE_CONST_OBJ_TYPE( + pyb_timer_type, + MP_QSTR_Timer, + MP_TYPE_FLAG_NONE, + pyb_timer_make_new, + print, pyb_timer_print, + locals_dict, (mp_obj_t)&pyb_timer_locals_dict + ); STATIC const mp_irq_methods_t pyb_timer_channel_irq_methods = { .init = pyb_timer_channel_irq, @@ -721,11 +722,13 @@ STATIC const mp_rom_map_elem_t pyb_timer_channel_locals_dict_table[] = { }; STATIC MP_DEFINE_CONST_DICT(pyb_timer_channel_locals_dict, pyb_timer_channel_locals_dict_table); -STATIC const mp_obj_type_t pyb_timer_channel_type = { - { &mp_type_type }, - .name = MP_QSTR_TimerChannel, - .print = pyb_timer_channel_print, - .locals_dict = (mp_obj_t)&pyb_timer_channel_locals_dict, -}; +STATIC MP_DEFINE_CONST_OBJ_TYPE( + pyb_timer_channel_type, + MP_QSTR_TimerChannel, + MP_TYPE_FLAG_NONE, + MP_TYPE_NULL_MAKE_NEW, + print, pyb_timer_channel_print, + locals_dict, (mp_obj_t)&pyb_timer_channel_locals_dict + ); MP_REGISTER_ROOT_POINTER(mp_obj_list_t pyb_timer_channel_obj_list); diff --git a/ports/cc3200/mods/pybuart.c b/ports/cc3200/mods/pybuart.c index a81954abb8..059101f4f2 100644 --- a/ports/cc3200/mods/pybuart.c +++ b/ports/cc3200/mods/pybuart.c @@ -685,15 +685,16 @@ STATIC const mp_irq_methods_t uart_irq_methods = { .flags = uart_irq_flags }; -const mp_obj_type_t pyb_uart_type = { - { &mp_type_type }, - .name = MP_QSTR_UART, - .print = pyb_uart_print, - .make_new = pyb_uart_make_new, - .getiter = mp_identity_getiter, - .iternext = mp_stream_unbuffered_iter, - .protocol = &uart_stream_p, - .locals_dict = (mp_obj_t)&pyb_uart_locals_dict, -}; +MP_DEFINE_CONST_OBJ_TYPE( + pyb_uart_type, + MP_QSTR_UART, + MP_TYPE_FLAG_NONE, + pyb_uart_make_new, + print, pyb_uart_print, + getiter, mp_identity_getiter, + iternext, mp_stream_unbuffered_iter, + protocol, &uart_stream_p, + locals_dict, (mp_obj_t)&pyb_uart_locals_dict + ); MP_REGISTER_ROOT_POINTER(struct _pyb_uart_obj_t *pyb_uart_objs[2]); diff --git a/ports/cc3200/mods/pybwdt.c b/ports/cc3200/mods/pybwdt.c index 8db096d6b5..cde1abe59d 100644 --- a/ports/cc3200/mods/pybwdt.c +++ b/ports/cc3200/mods/pybwdt.c @@ -150,10 +150,11 @@ STATIC const mp_rom_map_elem_t pybwdt_locals_dict_table[] = { }; STATIC MP_DEFINE_CONST_DICT(pybwdt_locals_dict, pybwdt_locals_dict_table); -const mp_obj_type_t pyb_wdt_type = { - { &mp_type_type }, - .name = MP_QSTR_WDT, - .make_new = pyb_wdt_make_new, - .locals_dict = (mp_obj_t)&pybwdt_locals_dict, -}; +MP_DEFINE_CONST_OBJ_TYPE( + pyb_wdt_type, + MP_QSTR_WDT, + MP_TYPE_FLAG_NONE, + pyb_wdt_make_new, + locals_dict, (mp_obj_t)&pybwdt_locals_dict + ); diff --git a/ports/esp32/esp32_nvs.c b/ports/esp32/esp32_nvs.c index 42d65be4a6..1f96ad129d 100644 --- a/ports/esp32/esp32_nvs.c +++ b/ports/esp32/esp32_nvs.c @@ -141,10 +141,11 @@ STATIC const mp_rom_map_elem_t esp32_nvs_locals_dict_table[] = { }; STATIC MP_DEFINE_CONST_DICT(esp32_nvs_locals_dict, esp32_nvs_locals_dict_table); -const mp_obj_type_t esp32_nvs_type = { - { &mp_type_type }, - .name = MP_QSTR_NVS, - .print = esp32_nvs_print, - .make_new = esp32_nvs_make_new, - .locals_dict = (mp_obj_dict_t *)&esp32_nvs_locals_dict, -}; +MP_DEFINE_CONST_OBJ_TYPE( + esp32_nvs_type, + MP_QSTR_NVS, + MP_TYPE_FLAG_NONE, + esp32_nvs_make_new, + print, esp32_nvs_print, + locals_dict, (mp_obj_dict_t *)&esp32_nvs_locals_dict + ); diff --git a/ports/esp32/esp32_partition.c b/ports/esp32/esp32_partition.c index 47e769486c..2e42e7a819 100644 --- a/ports/esp32/esp32_partition.c +++ b/ports/esp32/esp32_partition.c @@ -284,10 +284,11 @@ STATIC const mp_rom_map_elem_t esp32_partition_locals_dict_table[] = { }; STATIC MP_DEFINE_CONST_DICT(esp32_partition_locals_dict, esp32_partition_locals_dict_table); -const mp_obj_type_t esp32_partition_type = { - { &mp_type_type }, - .name = MP_QSTR_Partition, - .print = esp32_partition_print, - .make_new = esp32_partition_make_new, - .locals_dict = (mp_obj_dict_t *)&esp32_partition_locals_dict, -}; +MP_DEFINE_CONST_OBJ_TYPE( + esp32_partition_type, + MP_QSTR_Partition, + MP_TYPE_FLAG_NONE, + esp32_partition_make_new, + print, esp32_partition_print, + locals_dict, (mp_obj_dict_t *)&esp32_partition_locals_dict + ); diff --git a/ports/esp32/esp32_rmt.c b/ports/esp32/esp32_rmt.c index ac897e3336..36f33df3f5 100644 --- a/ports/esp32/esp32_rmt.c +++ b/ports/esp32/esp32_rmt.c @@ -372,10 +372,11 @@ STATIC const mp_rom_map_elem_t esp32_rmt_locals_dict_table[] = { }; STATIC MP_DEFINE_CONST_DICT(esp32_rmt_locals_dict, esp32_rmt_locals_dict_table); -const mp_obj_type_t esp32_rmt_type = { - { &mp_type_type }, - .name = MP_QSTR_RMT, - .print = esp32_rmt_print, - .make_new = esp32_rmt_make_new, - .locals_dict = (mp_obj_dict_t *)&esp32_rmt_locals_dict, -}; +MP_DEFINE_CONST_OBJ_TYPE( + esp32_rmt_type, + MP_QSTR_RMT, + MP_TYPE_FLAG_NONE, + esp32_rmt_make_new, + print, esp32_rmt_print, + locals_dict, (mp_obj_dict_t *)&esp32_rmt_locals_dict + ); diff --git a/ports/esp32/esp32_ulp.c b/ports/esp32/esp32_ulp.c index 8e4ce9c5a4..5eb0e5591e 100644 --- a/ports/esp32/esp32_ulp.c +++ b/ports/esp32/esp32_ulp.c @@ -91,11 +91,12 @@ STATIC const mp_rom_map_elem_t esp32_ulp_locals_dict_table[] = { }; STATIC MP_DEFINE_CONST_DICT(esp32_ulp_locals_dict, esp32_ulp_locals_dict_table); -const mp_obj_type_t esp32_ulp_type = { - { &mp_type_type }, - .name = MP_QSTR_ULP, - .make_new = esp32_ulp_make_new, - .locals_dict = (mp_obj_t)&esp32_ulp_locals_dict, -}; +MP_DEFINE_CONST_OBJ_TYPE( + esp32_ulp_type, + MP_QSTR_ULP, + MP_TYPE_FLAG_NONE, + esp32_ulp_make_new, + locals_dict, (mp_obj_t)&esp32_ulp_locals_dict + ); #endif // CONFIG_IDF_TARGET_ESP32 diff --git a/ports/esp32/machine_adc.c b/ports/esp32/machine_adc.c index cb45aab339..5cc2d80384 100644 --- a/ports/esp32/machine_adc.c +++ b/ports/esp32/machine_adc.c @@ -256,10 +256,11 @@ STATIC const mp_rom_map_elem_t madc_locals_dict_table[] = { }; STATIC MP_DEFINE_CONST_DICT(madc_locals_dict, madc_locals_dict_table); -const mp_obj_type_t machine_adc_type = { - { &mp_type_type }, - .name = MP_QSTR_ADC, - .print = madc_print, - .make_new = madc_make_new, - .locals_dict = (mp_obj_t)&madc_locals_dict, -}; +MP_DEFINE_CONST_OBJ_TYPE( + machine_adc_type, + MP_QSTR_ADC, + MP_TYPE_FLAG_NONE, + madc_make_new, + print, madc_print, + locals_dict, (mp_obj_t)&madc_locals_dict + ); diff --git a/ports/esp32/machine_adcblock.c b/ports/esp32/machine_adcblock.c index 06c215f8ae..770839e93e 100644 --- a/ports/esp32/machine_adcblock.c +++ b/ports/esp32/machine_adcblock.c @@ -194,10 +194,11 @@ STATIC const mp_rom_map_elem_t madcblock_locals_dict_table[] = { }; STATIC MP_DEFINE_CONST_DICT(madcblock_locals_dict, madcblock_locals_dict_table); -const mp_obj_type_t machine_adcblock_type = { - { &mp_type_type }, - .name = MP_QSTR_ADCBlock, - .print = madcblock_print, - .make_new = madcblock_make_new, - .locals_dict = (mp_obj_t)&madcblock_locals_dict, -}; +MP_DEFINE_CONST_OBJ_TYPE( + machine_adcblock_type, + MP_QSTR_ADCBlock, + MP_TYPE_FLAG_NONE, + madcblock_make_new, + print, madcblock_print, + locals_dict, (mp_obj_dict_t *)&madcblock_locals_dict + ); diff --git a/ports/esp32/machine_dac.c b/ports/esp32/machine_dac.c index 35826d4a99..c9b9c14e01 100644 --- a/ports/esp32/machine_dac.c +++ b/ports/esp32/machine_dac.c @@ -104,12 +104,13 @@ STATIC const mp_rom_map_elem_t mdac_locals_dict_table[] = { STATIC MP_DEFINE_CONST_DICT(mdac_locals_dict, mdac_locals_dict_table); -const mp_obj_type_t machine_dac_type = { - { &mp_type_type }, - .name = MP_QSTR_DAC, - .print = mdac_print, - .make_new = mdac_make_new, - .locals_dict = (mp_obj_t)&mdac_locals_dict, -}; +MP_DEFINE_CONST_OBJ_TYPE( + machine_dac_type, + MP_QSTR_DAC, + MP_TYPE_FLAG_NONE, + mdac_make_new, + print, mdac_print, + locals_dict, (mp_obj_t)&mdac_locals_dict + ); #endif // MICROPY_PY_MACHINE_DAC diff --git a/ports/esp32/machine_hw_spi.c b/ports/esp32/machine_hw_spi.c index 3e720adb1a..71583ef60e 100644 --- a/ports/esp32/machine_hw_spi.c +++ b/ports/esp32/machine_hw_spi.c @@ -545,11 +545,12 @@ STATIC const mp_machine_spi_p_t machine_hw_spi_p = { .transfer = machine_hw_spi_transfer, }; -const mp_obj_type_t machine_hw_spi_type = { - { &mp_type_type }, - .name = MP_QSTR_SPI, - .print = machine_hw_spi_print, - .make_new = machine_hw_spi_make_new, - .protocol = &machine_hw_spi_p, - .locals_dict = (mp_obj_dict_t *)&mp_machine_spi_locals_dict, -}; +MP_DEFINE_CONST_OBJ_TYPE( + machine_hw_spi_type, + MP_QSTR_SPI, + MP_TYPE_FLAG_NONE, + machine_hw_spi_make_new, + print, machine_hw_spi_print, + protocol, &machine_hw_spi_p, + locals_dict, (mp_obj_dict_t *)&mp_machine_spi_locals_dict + ); diff --git a/ports/esp32/machine_i2c.c b/ports/esp32/machine_i2c.c index e25cad0b60..9e5be606db 100644 --- a/ports/esp32/machine_i2c.c +++ b/ports/esp32/machine_i2c.c @@ -192,11 +192,12 @@ STATIC const mp_machine_i2c_p_t machine_hw_i2c_p = { .transfer = machine_hw_i2c_transfer, }; -const mp_obj_type_t machine_hw_i2c_type = { - { &mp_type_type }, - .name = MP_QSTR_I2C, - .print = machine_hw_i2c_print, - .make_new = machine_hw_i2c_make_new, - .protocol = &machine_hw_i2c_p, - .locals_dict = (mp_obj_dict_t *)&mp_machine_i2c_locals_dict, -}; +MP_DEFINE_CONST_OBJ_TYPE( + machine_hw_i2c_type, + MP_QSTR_I2C, + MP_TYPE_FLAG_NONE, + machine_hw_i2c_make_new, + print, machine_hw_i2c_print, + protocol, &machine_hw_i2c_p, + locals_dict, (mp_obj_dict_t *)&mp_machine_i2c_locals_dict + ); diff --git a/ports/esp32/machine_i2s.c b/ports/esp32/machine_i2s.c index 933e68684b..d30fb5d836 100644 --- a/ports/esp32/machine_i2s.c +++ b/ports/esp32/machine_i2s.c @@ -829,16 +829,17 @@ STATIC const mp_stream_p_t i2s_stream_p = { .is_text = false, }; -const mp_obj_type_t machine_i2s_type = { - { &mp_type_type }, - .name = MP_QSTR_I2S, - .print = machine_i2s_print, - .getiter = mp_identity_getiter, - .iternext = mp_stream_unbuffered_iter, - .protocol = &i2s_stream_p, - .make_new = machine_i2s_make_new, - .locals_dict = (mp_obj_dict_t *)&machine_i2s_locals_dict, -}; +MP_DEFINE_CONST_OBJ_TYPE( + machine_i2s_type, + MP_QSTR_I2S, + MP_TYPE_FLAG_NONE, + machine_i2s_make_new, + print, machine_i2s_print, + getiter, mp_identity_getiter, + iternext, mp_stream_unbuffered_iter, + protocol, &i2s_stream_p, + locals_dict, (mp_obj_dict_t *)&machine_i2s_locals_dict + ); MP_REGISTER_ROOT_POINTER(struct _machine_i2s_obj_t *machine_i2s_obj[I2S_NUM_MAX]); diff --git a/ports/esp32/machine_pin.c b/ports/esp32/machine_pin.c index b575626338..1a1a3a0f8d 100644 --- a/ports/esp32/machine_pin.c +++ b/ports/esp32/machine_pin.c @@ -529,15 +529,16 @@ STATIC const mp_pin_p_t pin_pin_p = { .ioctl = pin_ioctl, }; -const mp_obj_type_t machine_pin_type = { - { &mp_type_type }, - .name = MP_QSTR_Pin, - .print = machine_pin_print, - .make_new = mp_pin_make_new, - .call = machine_pin_call, - .protocol = &pin_pin_p, - .locals_dict = (mp_obj_t)&machine_pin_locals_dict, -}; +MP_DEFINE_CONST_OBJ_TYPE( + machine_pin_type, + MP_QSTR_Pin, + MP_TYPE_FLAG_NONE, + mp_pin_make_new, + print, machine_pin_print, + call, machine_pin_call, + protocol, &pin_pin_p, + locals_dict, (mp_obj_t)&machine_pin_locals_dict + ); /******************************************************************************/ // Pin IRQ object @@ -723,11 +724,13 @@ STATIC const mp_rom_map_elem_t machine_pin_irq_locals_dict_table[] = { }; STATIC MP_DEFINE_CONST_DICT(machine_pin_irq_locals_dict, machine_pin_irq_locals_dict_table); -STATIC const mp_obj_type_t machine_pin_irq_type = { - { &mp_type_type }, - .name = MP_QSTR_IRQ, - .call = machine_pin_irq_call, - .locals_dict = (mp_obj_dict_t *)&machine_pin_irq_locals_dict, -}; +STATIC MP_DEFINE_CONST_OBJ_TYPE( + machine_pin_irq_type, + MP_QSTR_IRQ, + MP_TYPE_FLAG_NONE, + MP_TYPE_NULL_MAKE_NEW, + call, machine_pin_irq_call, + locals_dict, (mp_obj_dict_t *)&machine_pin_irq_locals_dict + ); MP_REGISTER_ROOT_POINTER(mp_obj_t machine_pin_irq_handler[40]); diff --git a/ports/esp32/machine_rtc.c b/ports/esp32/machine_rtc.c index 72d7b5c828..6634bf5b03 100644 --- a/ports/esp32/machine_rtc.c +++ b/ports/esp32/machine_rtc.c @@ -173,9 +173,10 @@ STATIC const mp_rom_map_elem_t machine_rtc_locals_dict_table[] = { }; STATIC MP_DEFINE_CONST_DICT(machine_rtc_locals_dict, machine_rtc_locals_dict_table); -const mp_obj_type_t machine_rtc_type = { - { &mp_type_type }, - .name = MP_QSTR_RTC, - .make_new = machine_rtc_make_new, - .locals_dict = (mp_obj_t)&machine_rtc_locals_dict, -}; +MP_DEFINE_CONST_OBJ_TYPE( + machine_rtc_type, + MP_QSTR_RTC, + MP_TYPE_FLAG_NONE, + machine_rtc_make_new, + locals_dict, (mp_obj_t)&machine_rtc_locals_dict + ); diff --git a/ports/esp32/machine_sdcard.c b/ports/esp32/machine_sdcard.c index 3f94356adb..2d5663d476 100644 --- a/ports/esp32/machine_sdcard.c +++ b/ports/esp32/machine_sdcard.c @@ -399,11 +399,12 @@ STATIC const mp_rom_map_elem_t machine_sdcard_locals_dict_table[] = { STATIC MP_DEFINE_CONST_DICT(machine_sdcard_locals_dict, machine_sdcard_locals_dict_table); -const mp_obj_type_t machine_sdcard_type = { - { &mp_type_type }, - .name = MP_QSTR_SDCard, - .make_new = machine_sdcard_make_new, - .locals_dict = (mp_obj_dict_t *)&machine_sdcard_locals_dict, -}; +MP_DEFINE_CONST_OBJ_TYPE( + machine_sdcard_type, + MP_QSTR_SDCard, + MP_TYPE_FLAG_NONE, + machine_sdcard_make_new, + locals_dict, (mp_obj_dict_t *)&machine_sdcard_locals_dict + ); #endif // MICROPY_HW_ENABLE_SDCARD diff --git a/ports/esp32/machine_timer.c b/ports/esp32/machine_timer.c index 66969b3a95..3b12950955 100644 --- a/ports/esp32/machine_timer.c +++ b/ports/esp32/machine_timer.c @@ -277,12 +277,13 @@ STATIC const mp_rom_map_elem_t machine_timer_locals_dict_table[] = { }; STATIC MP_DEFINE_CONST_DICT(machine_timer_locals_dict, machine_timer_locals_dict_table); -const mp_obj_type_t machine_timer_type = { - { &mp_type_type }, - .name = MP_QSTR_Timer, - .print = machine_timer_print, - .make_new = machine_timer_make_new, - .locals_dict = (mp_obj_t)&machine_timer_locals_dict, -}; +MP_DEFINE_CONST_OBJ_TYPE( + machine_timer_type, + MP_QSTR_Timer, + MP_TYPE_FLAG_NONE, + machine_timer_make_new, + print, machine_timer_print, + locals_dict, (mp_obj_t)&machine_timer_locals_dict + ); MP_REGISTER_ROOT_POINTER(struct _machine_timer_obj_t *machine_timer_obj_head); diff --git a/ports/esp32/machine_touchpad.c b/ports/esp32/machine_touchpad.c index 168ac16d0e..c5e3483b74 100644 --- a/ports/esp32/machine_touchpad.c +++ b/ports/esp32/machine_touchpad.c @@ -134,11 +134,12 @@ STATIC const mp_rom_map_elem_t mtp_locals_dict_table[] = { STATIC MP_DEFINE_CONST_DICT(mtp_locals_dict, mtp_locals_dict_table); -const mp_obj_type_t machine_touchpad_type = { - { &mp_type_type }, - .name = MP_QSTR_TouchPad, - .make_new = mtp_make_new, - .locals_dict = (mp_obj_t)&mtp_locals_dict, -}; +MP_DEFINE_CONST_OBJ_TYPE( + machine_touchpad_type, + MP_QSTR_TouchPad, + MP_TYPE_FLAG_NONE, + mtp_make_new, + locals_dict, (mp_obj_t)&mtp_locals_dict + ); #endif // CONFIG_IDF_TARGET_ESP32 diff --git a/ports/esp32/machine_uart.c b/ports/esp32/machine_uart.c index 7244591289..9df16ae419 100644 --- a/ports/esp32/machine_uart.c +++ b/ports/esp32/machine_uart.c @@ -530,13 +530,14 @@ STATIC const mp_stream_p_t uart_stream_p = { .is_text = false, }; -const mp_obj_type_t machine_uart_type = { - { &mp_type_type }, - .name = MP_QSTR_UART, - .print = machine_uart_print, - .make_new = machine_uart_make_new, - .getiter = mp_identity_getiter, - .iternext = mp_stream_unbuffered_iter, - .protocol = &uart_stream_p, - .locals_dict = (mp_obj_dict_t *)&machine_uart_locals_dict, -}; +MP_DEFINE_CONST_OBJ_TYPE( + machine_uart_type, + MP_QSTR_UART, + MP_TYPE_FLAG_NONE, + machine_uart_make_new, + print, machine_uart_print, + getiter, mp_identity_getiter, + iternext, mp_stream_unbuffered_iter, + protocol, &uart_stream_p, + locals_dict, (mp_obj_dict_t *)&machine_uart_locals_dict + ); diff --git a/ports/esp32/machine_wdt.c b/ports/esp32/machine_wdt.c index f0ec6928e0..c2898c7fe1 100644 --- a/ports/esp32/machine_wdt.c +++ b/ports/esp32/machine_wdt.c @@ -83,9 +83,10 @@ STATIC const mp_rom_map_elem_t machine_wdt_locals_dict_table[] = { }; STATIC MP_DEFINE_CONST_DICT(machine_wdt_locals_dict, machine_wdt_locals_dict_table); -const mp_obj_type_t machine_wdt_type = { - { &mp_type_type }, - .name = MP_QSTR_WDT, - .make_new = machine_wdt_make_new, - .locals_dict = (mp_obj_t)&machine_wdt_locals_dict, -}; +MP_DEFINE_CONST_OBJ_TYPE( + machine_wdt_type, + MP_QSTR_WDT, + MP_TYPE_FLAG_NONE, + machine_wdt_make_new, + locals_dict, (mp_obj_t)&machine_wdt_locals_dict + ); diff --git a/ports/esp32/modsocket.c b/ports/esp32/modsocket.c index a281558241..a2dcb3946c 100644 --- a/ports/esp32/modsocket.c +++ b/ports/esp32/modsocket.c @@ -785,13 +785,14 @@ STATIC const mp_stream_p_t socket_stream_p = { .ioctl = socket_stream_ioctl }; -STATIC const mp_obj_type_t socket_type = { - { &mp_type_type }, - .name = MP_QSTR_socket, - .make_new = socket_make_new, - .protocol = &socket_stream_p, - .locals_dict = (mp_obj_t)&socket_locals_dict, -}; +STATIC MP_DEFINE_CONST_OBJ_TYPE( + socket_type, + MP_QSTR_socket, + MP_TYPE_FLAG_NONE, + socket_make_new, + protocol, &socket_stream_p, + locals_dict, (mp_obj_t)&socket_locals_dict + ); STATIC mp_obj_t esp_socket_getaddrinfo(size_t n_args, const mp_obj_t *args) { // TODO support additional args beyond the first two diff --git a/ports/esp32/network_lan.c b/ports/esp32/network_lan.c index f302d70fec..fc50e13c48 100644 --- a/ports/esp32/network_lan.c +++ b/ports/esp32/network_lan.c @@ -302,10 +302,12 @@ STATIC const mp_rom_map_elem_t lan_if_locals_dict_table[] = { STATIC MP_DEFINE_CONST_DICT(lan_if_locals_dict, lan_if_locals_dict_table); -const mp_obj_type_t lan_if_type = { - { &mp_type_type }, - .name = MP_QSTR_LAN, - .locals_dict = (mp_obj_dict_t *)&lan_if_locals_dict, -}; +MP_DEFINE_CONST_OBJ_TYPE( + lan_if_type, + MP_QSTR_LAN, + MP_TYPE_FLAG_NONE, + MP_TYPE_NULL_MAKE_NEW, + locals_dict, (mp_obj_dict_t *)&lan_if_locals_dict + ); #endif diff --git a/ports/esp32/network_ppp.c b/ports/esp32/network_ppp.c index d74283c19c..d6368d9f20 100644 --- a/ports/esp32/network_ppp.c +++ b/ports/esp32/network_ppp.c @@ -278,8 +278,10 @@ STATIC const mp_rom_map_elem_t ppp_if_locals_dict_table[] = { }; STATIC MP_DEFINE_CONST_DICT(ppp_if_locals_dict, ppp_if_locals_dict_table); -const mp_obj_type_t ppp_if_type = { - { &mp_type_type }, - .name = MP_QSTR_PPP, - .locals_dict = (mp_obj_dict_t *)&ppp_if_locals_dict, -}; +MP_DEFINE_CONST_OBJ_TYPE( + ppp_if_type, + MP_QSTR_PPP, + MP_TYPE_FLAG_NONE, + MP_TYPE_NULL_MAKE_NEW, + locals_dict, (mp_obj_dict_t *)&ppp_if_locals_dict + ); diff --git a/ports/esp32/network_wlan.c b/ports/esp32/network_wlan.c index 4f74262afc..6ca5f9a9ba 100644 --- a/ports/esp32/network_wlan.c +++ b/ports/esp32/network_wlan.c @@ -47,9 +47,8 @@ #error WIFI_MODE_STA and WIFI_MODE_AP are supposed to be bitfields! #endif -STATIC const mp_obj_type_t wlan_if_type; -STATIC const wlan_if_obj_t wlan_sta_obj = {{&wlan_if_type}, WIFI_IF_STA}; -STATIC const wlan_if_obj_t wlan_ap_obj = {{&wlan_if_type}, WIFI_IF_AP}; +STATIC const wlan_if_obj_t wlan_sta_obj; +STATIC const wlan_if_obj_t wlan_ap_obj; // Set to "true" if esp_wifi_start() was called static bool wifi_started = false; @@ -616,10 +615,15 @@ STATIC const mp_rom_map_elem_t wlan_if_locals_dict_table[] = { }; STATIC MP_DEFINE_CONST_DICT(wlan_if_locals_dict, wlan_if_locals_dict_table); -STATIC const mp_obj_type_t wlan_if_type = { - { &mp_type_type }, - .name = MP_QSTR_WLAN, - .locals_dict = (mp_obj_t)&wlan_if_locals_dict, -}; +MP_DEFINE_CONST_OBJ_TYPE( + wlan_if_type, + MP_QSTR_WLAN, + MP_TYPE_FLAG_NONE, + MP_TYPE_NULL_MAKE_NEW, + locals_dict, (mp_obj_dict_t *)&wlan_if_locals_dict + ); + +STATIC const wlan_if_obj_t wlan_sta_obj = {{&wlan_if_type}, WIFI_IF_STA}; +STATIC const wlan_if_obj_t wlan_ap_obj = {{&wlan_if_type}, WIFI_IF_AP}; #endif // MICROPY_PY_NETWORK_WLAN diff --git a/ports/esp8266/machine_adc.c b/ports/esp8266/machine_adc.c index 471e14d8df..bface7f7e1 100644 --- a/ports/esp8266/machine_adc.c +++ b/ports/esp8266/machine_adc.c @@ -89,10 +89,11 @@ STATIC const mp_rom_map_elem_t machine_adc_locals_dict_table[] = { }; STATIC MP_DEFINE_CONST_DICT(machine_adc_locals_dict, machine_adc_locals_dict_table); -const mp_obj_type_t machine_adc_type = { - { &mp_type_type }, - .name = MP_QSTR_ADC, - .print = machine_adc_print, - .make_new = machine_adc_make_new, - .locals_dict = (mp_obj_dict_t *)&machine_adc_locals_dict, -}; +MP_DEFINE_CONST_OBJ_TYPE( + machine_adc_type, + MP_QSTR_ADC, + MP_TYPE_FLAG_NONE, + machine_adc_make_new, + print, machine_adc_print, + locals_dict, (mp_obj_dict_t *)&machine_adc_locals_dict + ); diff --git a/ports/esp8266/machine_hspi.c b/ports/esp8266/machine_hspi.c index 3ff76f5a02..c0d4a677e3 100644 --- a/ports/esp8266/machine_hspi.c +++ b/ports/esp8266/machine_hspi.c @@ -175,13 +175,14 @@ STATIC const mp_machine_spi_p_t machine_hspi_p = { .transfer = machine_hspi_transfer, }; -const mp_obj_type_t machine_hspi_type = { - { &mp_type_type }, - .name = MP_QSTR_HSPI, - .print = machine_hspi_print, - .make_new = machine_hspi_make_new, - .protocol = &machine_hspi_p, - .locals_dict = (mp_obj_dict_t *)&mp_machine_spi_locals_dict, -}; +MP_DEFINE_CONST_OBJ_TYPE( + machine_hspi_type, + MP_QSTR_HSPI, + MP_TYPE_FLAG_NONE, + machine_hspi_make_new, + print, machine_hspi_print, + protocol, &machine_hspi_p, + locals_dict, (mp_obj_dict_t *)&mp_machine_spi_locals_dict + ); #endif // MICROPY_PY_MACHINE_SPI diff --git a/ports/esp8266/machine_pin.c b/ports/esp8266/machine_pin.c index 8171b8a8a3..8b759766cd 100644 --- a/ports/esp8266/machine_pin.c +++ b/ports/esp8266/machine_pin.c @@ -450,15 +450,16 @@ STATIC const mp_pin_p_t pin_pin_p = { .ioctl = pin_ioctl, }; -const mp_obj_type_t pyb_pin_type = { - { &mp_type_type }, - .name = MP_QSTR_Pin, - .print = pyb_pin_print, - .make_new = mp_pin_make_new, - .call = pyb_pin_call, - .protocol = &pin_pin_p, - .locals_dict = (mp_obj_dict_t *)&pyb_pin_locals_dict, -}; +MP_DEFINE_CONST_OBJ_TYPE( + pyb_pin_type, + MP_QSTR_Pin, + MP_TYPE_FLAG_NONE, + mp_pin_make_new, + print, pyb_pin_print, + call, pyb_pin_call, + protocol, &pin_pin_p, + locals_dict, (mp_obj_dict_t *)&pyb_pin_locals_dict + ); /******************************************************************************/ // Pin IRQ object @@ -509,11 +510,13 @@ STATIC const mp_rom_map_elem_t pin_irq_locals_dict_table[] = { STATIC MP_DEFINE_CONST_DICT(pin_irq_locals_dict, pin_irq_locals_dict_table); -STATIC const mp_obj_type_t pin_irq_type = { - { &mp_type_type }, - .name = MP_QSTR_IRQ, - .call = pin_irq_call, - .locals_dict = (mp_obj_dict_t *)&pin_irq_locals_dict, -}; +STATIC MP_DEFINE_CONST_OBJ_TYPE( + pin_irq_type, + MP_QSTR_IRQ, + MP_TYPE_FLAG_NONE, + MP_TYPE_NULL_MAKE_NEW, + call, pin_irq_call, + locals_dict, (mp_obj_dict_t *)&pin_irq_locals_dict + ); MP_REGISTER_ROOT_POINTER(mp_obj_t pin_irq_handler[16]); diff --git a/ports/esp8266/machine_rtc.c b/ports/esp8266/machine_rtc.c index 38049ce724..4235b325ef 100644 --- a/ports/esp8266/machine_rtc.c +++ b/ports/esp8266/machine_rtc.c @@ -262,9 +262,10 @@ STATIC const mp_rom_map_elem_t pyb_rtc_locals_dict_table[] = { }; STATIC MP_DEFINE_CONST_DICT(pyb_rtc_locals_dict, pyb_rtc_locals_dict_table); -const mp_obj_type_t pyb_rtc_type = { - { &mp_type_type }, - .name = MP_QSTR_RTC, - .make_new = pyb_rtc_make_new, - .locals_dict = (mp_obj_dict_t *)&pyb_rtc_locals_dict, -}; +MP_DEFINE_CONST_OBJ_TYPE( + pyb_rtc_type, + MP_QSTR_RTC, + MP_TYPE_FLAG_NONE, + pyb_rtc_make_new, + locals_dict, (mp_obj_dict_t *)&pyb_rtc_locals_dict + ); diff --git a/ports/esp8266/machine_uart.c b/ports/esp8266/machine_uart.c index 2fe6516dc7..82f5189388 100644 --- a/ports/esp8266/machine_uart.c +++ b/ports/esp8266/machine_uart.c @@ -343,15 +343,16 @@ STATIC const mp_stream_p_t uart_stream_p = { .is_text = false, }; -const mp_obj_type_t pyb_uart_type = { - { &mp_type_type }, - .name = MP_QSTR_UART, - .print = pyb_uart_print, - .make_new = pyb_uart_make_new, - .getiter = mp_identity_getiter, - .iternext = mp_stream_unbuffered_iter, - .protocol = &uart_stream_p, - .locals_dict = (mp_obj_dict_t *)&pyb_uart_locals_dict, -}; +MP_DEFINE_CONST_OBJ_TYPE( + pyb_uart_type, + MP_QSTR_UART, + MP_TYPE_FLAG_NONE, + pyb_uart_make_new, + print, pyb_uart_print, + getiter, mp_identity_getiter, + iternext, mp_stream_unbuffered_iter, + protocol, &uart_stream_p, + locals_dict, (mp_obj_dict_t *)&pyb_uart_locals_dict + ); MP_REGISTER_ROOT_POINTER(byte * uart0_rxbuf); diff --git a/ports/esp8266/machine_wdt.c b/ports/esp8266/machine_wdt.c index b06e752277..d8c32ddd1a 100644 --- a/ports/esp8266/machine_wdt.c +++ b/ports/esp8266/machine_wdt.c @@ -69,9 +69,10 @@ STATIC const mp_rom_map_elem_t machine_wdt_locals_dict_table[] = { }; STATIC MP_DEFINE_CONST_DICT(machine_wdt_locals_dict, machine_wdt_locals_dict_table); -const mp_obj_type_t esp_wdt_type = { - { &mp_type_type }, - .name = MP_QSTR_WDT, - .make_new = machine_wdt_make_new, - .locals_dict = (mp_obj_dict_t *)&machine_wdt_locals_dict, -}; +MP_DEFINE_CONST_OBJ_TYPE( + esp_wdt_type, + MP_QSTR_WDT, + MP_TYPE_FLAG_NONE, + machine_wdt_make_new, + locals_dict, (mp_obj_dict_t *)&machine_wdt_locals_dict + ); diff --git a/ports/esp8266/modmachine.c b/ports/esp8266/modmachine.c index 1dd87b9af8..2bb2c7bd76 100644 --- a/ports/esp8266/modmachine.c +++ b/ports/esp8266/modmachine.c @@ -337,13 +337,14 @@ STATIC const mp_rom_map_elem_t esp_timer_locals_dict_table[] = { }; STATIC MP_DEFINE_CONST_DICT(esp_timer_locals_dict, esp_timer_locals_dict_table); -const mp_obj_type_t esp_timer_type = { - { &mp_type_type }, - .name = MP_QSTR_Timer, - .print = esp_timer_print, - .make_new = esp_timer_make_new, - .locals_dict = (mp_obj_dict_t *)&esp_timer_locals_dict, -}; +MP_DEFINE_CONST_OBJ_TYPE( + esp_timer_type, + MP_QSTR_Timer, + MP_TYPE_FLAG_NONE, + esp_timer_make_new, + print, esp_timer_print, + locals_dict, (mp_obj_dict_t *)&esp_timer_locals_dict + ); // this bit is unused in the Xtensa PS register #define ETS_LOOP_ITER_BIT (12) diff --git a/ports/esp8266/modnetwork.c b/ports/esp8266/modnetwork.c index 5240d3b320..f78bf5da52 100644 --- a/ports/esp8266/modnetwork.c +++ b/ports/esp8266/modnetwork.c @@ -510,11 +510,13 @@ STATIC const mp_rom_map_elem_t wlan_if_locals_dict_table[] = { STATIC MP_DEFINE_CONST_DICT(wlan_if_locals_dict, wlan_if_locals_dict_table); -const mp_obj_type_t wlan_if_type = { - { &mp_type_type }, - .name = MP_QSTR_WLAN, - .locals_dict = (mp_obj_dict_t *)&wlan_if_locals_dict, -}; +MP_DEFINE_CONST_OBJ_TYPE( + wlan_if_type, + MP_QSTR_WLAN, + MP_TYPE_FLAG_NONE, + MP_TYPE_NULL_MAKE_NEW, + locals_dict, (mp_obj_dict_t *)&wlan_if_locals_dict + ); STATIC mp_obj_t esp_phy_mode(size_t n_args, const mp_obj_t *args) { if (n_args == 0) { diff --git a/ports/mimxrt/machine_adc.c b/ports/mimxrt/machine_adc.c index aa4cc831e5..cbac6b5734 100644 --- a/ports/mimxrt/machine_adc.c +++ b/ports/mimxrt/machine_adc.c @@ -117,13 +117,14 @@ STATIC const mp_rom_map_elem_t adc_locals_dict_table[] = { STATIC MP_DEFINE_CONST_DICT(adc_locals_dict, adc_locals_dict_table); -const mp_obj_type_t machine_adc_type = { - {&mp_type_type}, - .name = MP_QSTR_ADC, - .print = adc_obj_print, - .make_new = adc_obj_make_new, - .locals_dict = (mp_obj_dict_t *)&adc_locals_dict, -}; +MP_DEFINE_CONST_OBJ_TYPE( + machine_adc_type, + MP_QSTR_ADC, + MP_TYPE_FLAG_NONE, + adc_obj_make_new, + print, adc_obj_print, + locals_dict, (mp_obj_dict_t *)&adc_locals_dict + ); void machine_adc_init(void) { for (int i = 1; i < sizeof(adc_bases) / sizeof(ADC_Type *); ++i) { diff --git a/ports/mimxrt/machine_i2c.c b/ports/mimxrt/machine_i2c.c index c10fcaddbe..b8b6b7bc63 100644 --- a/ports/mimxrt/machine_i2c.c +++ b/ports/mimxrt/machine_i2c.c @@ -197,11 +197,12 @@ STATIC const mp_machine_i2c_p_t machine_i2c_p = { .transfer_single = machine_i2c_transfer_single, }; -const mp_obj_type_t machine_i2c_type = { - { &mp_type_type }, - .name = MP_QSTR_I2C, - .print = machine_i2c_print, - .make_new = machine_i2c_make_new, - .protocol = &machine_i2c_p, - .locals_dict = (mp_obj_dict_t *)&mp_machine_i2c_locals_dict, -}; +MP_DEFINE_CONST_OBJ_TYPE( + machine_i2c_type, + MP_QSTR_I2C, + MP_TYPE_FLAG_NONE, + machine_i2c_make_new, + print, machine_i2c_print, + protocol, &machine_i2c_p, + locals_dict, (mp_obj_dict_t *)&mp_machine_i2c_locals_dict + ); diff --git a/ports/mimxrt/machine_i2s.c b/ports/mimxrt/machine_i2s.c index a5446c7ac3..68bf3a820f 100644 --- a/ports/mimxrt/machine_i2s.c +++ b/ports/mimxrt/machine_i2s.c @@ -1213,16 +1213,17 @@ STATIC const mp_stream_p_t i2s_stream_p = { .is_text = false, }; -const mp_obj_type_t machine_i2s_type = { - { &mp_type_type }, - .name = MP_QSTR_I2S, - .print = machine_i2s_print, - .getiter = mp_identity_getiter, - .iternext = mp_stream_unbuffered_iter, - .protocol = &i2s_stream_p, - .make_new = machine_i2s_make_new, - .locals_dict = (mp_obj_dict_t *)&machine_i2s_locals_dict, -}; +MP_DEFINE_CONST_OBJ_TYPE( + machine_i2s_type, + MP_QSTR_I2S, + MP_TYPE_FLAG_NONE, + machine_i2s_make_new, + print, machine_i2s_print, + getiter, mp_identity_getiter, + iternext, mp_stream_unbuffered_iter, + protocol, &i2s_stream_p, + locals_dict, (mp_obj_dict_t *)&machine_i2s_locals_dict + ); MP_REGISTER_ROOT_POINTER(struct _machine_i2s_obj_t *machine_i2s_obj[MICROPY_HW_I2S_NUM]); diff --git a/ports/mimxrt/machine_led.c b/ports/mimxrt/machine_led.c index 4082eb34bb..d766c8f323 100644 --- a/ports/mimxrt/machine_led.c +++ b/ports/mimxrt/machine_led.c @@ -80,12 +80,13 @@ STATIC const mp_rom_map_elem_t led_locals_dict_table[] = { STATIC MP_DEFINE_CONST_DICT(led_locals_dict, led_locals_dict_table); -const mp_obj_type_t machine_led_type = { - {&mp_type_type}, - .name = MP_QSTR_LED, - .print = led_obj_print, - .make_new = led_obj_make_new, - .locals_dict = (mp_obj_dict_t *)&led_locals_dict, -}; +MP_DEFINE_CONST_OBJ_TYPE( + machine_led_type, + MP_QSTR_LED, + MP_TYPE_FLAG_NONE, + led_obj_make_new, + print, led_obj_print, + locals_dict, (mp_obj_dict_t *)&led_locals_dict + ); #endif diff --git a/ports/mimxrt/machine_pin.c b/ports/mimxrt/machine_pin.c index 64066af0e1..7ec66d0eac 100644 --- a/ports/mimxrt/machine_pin.c +++ b/ports/mimxrt/machine_pin.c @@ -58,17 +58,21 @@ enum { }; // Pin mapping dictionaries -const mp_obj_type_t machine_pin_cpu_pins_obj_type = { - { &mp_type_type }, - .name = MP_QSTR_cpu, - .locals_dict = (mp_obj_t)&machine_pin_cpu_pins_locals_dict, -}; +MP_DEFINE_CONST_OBJ_TYPE( + machine_pin_cpu_pins_obj_type, + MP_QSTR_cpu, + MP_TYPE_FLAG_NONE, + MP_TYPE_NULL_MAKE_NEW, + locals_dict, (mp_obj_t)&machine_pin_cpu_pins_locals_dict + ); -const mp_obj_type_t machine_pin_board_pins_obj_type = { - { &mp_type_type }, - .name = MP_QSTR_board, - .locals_dict = (mp_obj_t)&machine_pin_board_pins_locals_dict, -}; +MP_DEFINE_CONST_OBJ_TYPE( + machine_pin_board_pins_obj_type, + MP_QSTR_board, + MP_TYPE_FLAG_NONE, + MP_TYPE_NULL_MAKE_NEW, + locals_dict, (mp_obj_t)&machine_pin_board_pins_locals_dict + ); STATIC const mp_irq_methods_t machine_pin_irq_methods; @@ -396,7 +400,6 @@ STATIC const mp_rom_map_elem_t machine_pin_locals_dict_table[] = { }; STATIC MP_DEFINE_CONST_DICT(machine_pin_locals_dict, machine_pin_locals_dict_table); - STATIC mp_uint_t machine_pin_ioctl(mp_obj_t self_in, mp_uint_t request, uintptr_t arg, int *errcode) { (void)errcode; machine_pin_obj_t *self = self_in; @@ -417,24 +420,26 @@ STATIC const mp_pin_p_t machine_pin_obj_protocol = { .ioctl = machine_pin_ioctl, }; -const mp_obj_type_t machine_pin_type = { - {&mp_type_type}, - .name = MP_QSTR_Pin, - .print = machine_pin_obj_print, - .call = machine_pin_obj_call, - .make_new = mp_pin_make_new, - .protocol = &machine_pin_obj_protocol, - .locals_dict = (mp_obj_dict_t *)&machine_pin_locals_dict, -}; +MP_DEFINE_CONST_OBJ_TYPE( + machine_pin_type, + MP_QSTR_Pin, + MP_TYPE_FLAG_NONE, + mp_pin_make_new, + print, machine_pin_obj_print, + call, machine_pin_obj_call, + protocol, &machine_pin_obj_protocol, + locals_dict, (mp_obj_dict_t *)&machine_pin_locals_dict + ); // FIXME: Create actual pin_af type!!! -const mp_obj_type_t machine_pin_af_type = { - {&mp_type_type}, - .name = MP_QSTR_PinAF, - .print = machine_pin_obj_print, - .make_new = mp_pin_make_new, - .locals_dict = (mp_obj_dict_t *)&machine_pin_locals_dict, -}; +MP_DEFINE_CONST_OBJ_TYPE( + machine_pin_af_type, + MP_QSTR_PinAF, + MP_TYPE_FLAG_NONE, + mp_pin_make_new, + print, machine_pin_obj_print, + locals_dict, (mp_obj_dict_t *)&machine_pin_locals_dict + ); STATIC mp_uint_t machine_pin_irq_trigger(mp_obj_t self_in, mp_uint_t new_trigger) { machine_pin_obj_t *self = MP_OBJ_TO_PTR(self_in); diff --git a/ports/mimxrt/machine_rtc.c b/ports/mimxrt/machine_rtc.c index e0d33554b5..5211027bdf 100644 --- a/ports/mimxrt/machine_rtc.c +++ b/ports/mimxrt/machine_rtc.c @@ -166,9 +166,10 @@ STATIC const mp_rom_map_elem_t machine_rtc_locals_dict_table[] = { }; STATIC MP_DEFINE_CONST_DICT(machine_rtc_locals_dict, machine_rtc_locals_dict_table); -const mp_obj_type_t machine_rtc_type = { - { &mp_type_type }, - .name = MP_QSTR_RTC, - .make_new = machine_rtc_make_new, - .locals_dict = (mp_obj_t)&machine_rtc_locals_dict, -}; +MP_DEFINE_CONST_OBJ_TYPE( + machine_rtc_type, + MP_QSTR_RTC, + MP_TYPE_FLAG_NONE, + machine_rtc_make_new, + locals_dict, (mp_obj_t)&machine_rtc_locals_dict + ); diff --git a/ports/mimxrt/machine_sdcard.c b/ports/mimxrt/machine_sdcard.c index 4a92aae00c..b7bdceef47 100644 --- a/ports/mimxrt/machine_sdcard.c +++ b/ports/mimxrt/machine_sdcard.c @@ -208,12 +208,13 @@ STATIC const mp_rom_map_elem_t sdcard_locals_dict_table[] = { }; STATIC MP_DEFINE_CONST_DICT(sdcard_locals_dict, sdcard_locals_dict_table); -const mp_obj_type_t machine_sdcard_type = { - { &mp_type_type }, - .name = MP_QSTR_SDCard, - .make_new = sdcard_obj_make_new, - .locals_dict = (mp_obj_dict_t *)&sdcard_locals_dict, -}; +MP_DEFINE_CONST_OBJ_TYPE( + machine_sdcard_type, + MP_QSTR_SDCard, + MP_TYPE_FLAG_NONE, + sdcard_obj_make_new, + locals_dict, (mp_obj_dict_t *)&sdcard_locals_dict + ); void machine_sdcard_init0(void) { return; diff --git a/ports/mimxrt/machine_spi.c b/ports/mimxrt/machine_spi.c index 32bc77c34d..ff3cf4fb25 100644 --- a/ports/mimxrt/machine_spi.c +++ b/ports/mimxrt/machine_spi.c @@ -251,11 +251,12 @@ STATIC const mp_machine_spi_p_t machine_spi_p = { .transfer = machine_spi_transfer, }; -const mp_obj_type_t machine_spi_type = { - { &mp_type_type }, - .name = MP_QSTR_SPI, - .print = machine_spi_print, - .make_new = machine_spi_make_new, - .protocol = &machine_spi_p, - .locals_dict = (mp_obj_dict_t *)&mp_machine_spi_locals_dict, -}; +MP_DEFINE_CONST_OBJ_TYPE( + machine_spi_type, + MP_QSTR_SPI, + MP_TYPE_FLAG_NONE, + machine_spi_make_new, + print, machine_spi_print, + protocol, &machine_spi_p, + locals_dict, (mp_obj_dict_t *)&mp_machine_spi_locals_dict + ); diff --git a/ports/mimxrt/machine_timer.c b/ports/mimxrt/machine_timer.c index 62a560ebbf..9612388486 100644 --- a/ports/mimxrt/machine_timer.c +++ b/ports/mimxrt/machine_timer.c @@ -211,12 +211,13 @@ STATIC const mp_rom_map_elem_t machine_timer_locals_dict_table[] = { }; STATIC MP_DEFINE_CONST_DICT(machine_timer_locals_dict, machine_timer_locals_dict_table); -const mp_obj_type_t machine_timer_type = { - { &mp_type_type }, - .name = MP_QSTR_Timer, - .print = machine_timer_print, - .make_new = machine_timer_make_new, - .locals_dict = (mp_obj_dict_t *)&machine_timer_locals_dict, -}; +MP_DEFINE_CONST_OBJ_TYPE( + machine_timer_type, + MP_QSTR_Timer, + MP_TYPE_FLAG_NONE, + machine_timer_make_new, + print, machine_timer_print, + locals_dict, (mp_obj_dict_t *)&machine_timer_locals_dict + ); MP_REGISTER_ROOT_POINTER(struct _machine_timer_obj_t *timer_table[MICROPY_HW_PIT_NUM_CHANNELS]); diff --git a/ports/mimxrt/machine_uart.c b/ports/mimxrt/machine_uart.c index 83382a6cf2..4bb518eab2 100644 --- a/ports/mimxrt/machine_uart.c +++ b/ports/mimxrt/machine_uart.c @@ -469,13 +469,14 @@ STATIC const mp_stream_p_t uart_stream_p = { .is_text = false, }; -const mp_obj_type_t machine_uart_type = { - { &mp_type_type }, - .name = MP_QSTR_UART, - .print = machine_uart_print, - .make_new = machine_uart_make_new, - .getiter = mp_identity_getiter, - .iternext = mp_stream_unbuffered_iter, - .protocol = &uart_stream_p, - .locals_dict = (mp_obj_dict_t *)&machine_uart_locals_dict, -}; +MP_DEFINE_CONST_OBJ_TYPE( + machine_uart_type, + MP_QSTR_UART, + MP_TYPE_FLAG_NONE, + machine_uart_make_new, + print, machine_uart_print, + getiter, mp_identity_getiter, + iternext, mp_stream_unbuffered_iter, + protocol, &uart_stream_p, + locals_dict, (mp_obj_dict_t *)&machine_uart_locals_dict + ); diff --git a/ports/mimxrt/machine_wdt.c b/ports/mimxrt/machine_wdt.c index d09c464f69..cde80f085b 100644 --- a/ports/mimxrt/machine_wdt.c +++ b/ports/mimxrt/machine_wdt.c @@ -99,9 +99,10 @@ STATIC const mp_rom_map_elem_t machine_wdt_locals_dict_table[] = { }; STATIC MP_DEFINE_CONST_DICT(machine_wdt_locals_dict, machine_wdt_locals_dict_table); -const mp_obj_type_t machine_wdt_type = { - { &mp_type_type }, - .name = MP_QSTR_WDT, - .make_new = machine_wdt_make_new, - .locals_dict = (mp_obj_dict_t *)&machine_wdt_locals_dict, -}; +MP_DEFINE_CONST_OBJ_TYPE( + machine_wdt_type, + MP_QSTR_WDT, + MP_TYPE_FLAG_NONE, + machine_wdt_make_new, + locals_dict, (mp_obj_dict_t *)&machine_wdt_locals_dict + ); diff --git a/ports/mimxrt/mimxrt_flash.c b/ports/mimxrt/mimxrt_flash.c index 27ab987ed1..1a7d6cca8d 100644 --- a/ports/mimxrt/mimxrt_flash.c +++ b/ports/mimxrt/mimxrt_flash.c @@ -215,9 +215,10 @@ STATIC const mp_rom_map_elem_t mimxrt_flash_locals_dict_table[] = { }; STATIC MP_DEFINE_CONST_DICT(mimxrt_flash_locals_dict, mimxrt_flash_locals_dict_table); -const mp_obj_type_t mimxrt_flash_type = { - { &mp_type_type }, - .name = MP_QSTR_Flash, - .make_new = mimxrt_flash_make_new, - .locals_dict = (mp_obj_dict_t *)&mimxrt_flash_locals_dict, -}; +MP_DEFINE_CONST_OBJ_TYPE( + mimxrt_flash_type, + MP_QSTR_Flash, + MP_TYPE_FLAG_NONE, + mimxrt_flash_make_new, + locals_dict, (mp_obj_dict_t *)&mimxrt_flash_locals_dict + ); diff --git a/ports/mimxrt/network_lan.c b/ports/mimxrt/network_lan.c index 5517b54bd0..08c3c9e729 100644 --- a/ports/mimxrt/network_lan.c +++ b/ports/mimxrt/network_lan.c @@ -220,12 +220,14 @@ STATIC const mp_rom_map_elem_t network_lan_locals_dict_table[] = { }; STATIC MP_DEFINE_CONST_DICT(network_lan_locals_dict, network_lan_locals_dict_table); -const mp_obj_type_t network_lan_type = { - { &mp_type_type }, - .name = MP_QSTR_LAN, - .print = network_lan_print, - .make_new = network_lan_make_new, - .locals_dict = (mp_obj_dict_t *)&network_lan_locals_dict, -}; +MP_DEFINE_CONST_OBJ_TYPE( + network_lan_type, + MP_QSTR_LAN, + MP_TYPE_FLAG_NONE, + network_lan_make_new, + print, network_lan_print, + locals_dict, (mp_obj_dict_t *)&network_lan_locals_dict + ); + #endif // defined(MICROPY_HW_ETH_MDC) diff --git a/ports/nrf/boards/microbit/modules/iters.c b/ports/nrf/boards/microbit/modules/iters.c index 66f9f6c7f3..296fc1f51c 100644 --- a/ports/nrf/boards/microbit/modules/iters.c +++ b/ports/nrf/boards/microbit/modules/iters.c @@ -43,12 +43,14 @@ static mp_obj_t microbit_repeat_iter_next(mp_obj_t iter_in) { return mp_obj_subscr(iter->iterable, MP_OBJ_NEW_SMALL_INT(iter->index), MP_OBJ_SENTINEL); } -const mp_obj_type_t microbit_repeat_iterator_type = { - { &mp_type_type }, - .name = MP_QSTR_iterator, - .getiter = mp_identity_getiter, - .iternext = microbit_repeat_iter_next, -}; +MP_DEFINE_CONST_OBJ_TYPE( + microbit_repeat_iterator_type, + MP_QSTR_iterator, + MP_TYPE_FLAG_NONE, + MP_TYPE_NULL_MAKE_NEW, + getiter, mp_identity_getiter, + iternext, microbit_repeat_iter_next + ); mp_obj_t microbit_repeat_iterator(mp_obj_t iterable) { repeat_iterator_t *result = mp_obj_malloc(repeat_iterator_t, µbit_repeat_iterator_type); diff --git a/ports/nrf/boards/microbit/modules/microbitdisplay.c b/ports/nrf/boards/microbit/modules/microbitdisplay.c index 93ba9772fe..084cb09524 100644 --- a/ports/nrf/boards/microbit/modules/microbitdisplay.c +++ b/ports/nrf/boards/microbit/modules/microbitdisplay.c @@ -542,11 +542,13 @@ STATIC const mp_rom_map_elem_t microbit_display_locals_dict_table[] = { STATIC MP_DEFINE_CONST_DICT(microbit_display_locals_dict, microbit_display_locals_dict_table); -const mp_obj_type_t microbit_display_type = { - { &mp_type_type }, - .name = MP_QSTR_MicroBitDisplay, - .locals_dict = (mp_obj_dict_t*)µbit_display_locals_dict, -}; +MP_DEFINE_CONST_OBJ_TYPE( + microbit_display_type, + MP_QSTR_MicroBitDisplay, + MP_TYPE_FLAG_NONE, + MP_TYPE_NULL_MAKE_NEW, + locals_dict, (mp_obj_dict_t*)µbit_display_locals_dict + ); microbit_display_obj_t microbit_display_obj = { {µbit_display_type}, diff --git a/ports/nrf/boards/microbit/modules/microbitimage.c b/ports/nrf/boards/microbit/modules/microbitimage.c index eb44660b97..95b17bb6d3 100644 --- a/ports/nrf/boards/microbit/modules/microbitimage.c +++ b/ports/nrf/boards/microbit/modules/microbitimage.c @@ -678,14 +678,15 @@ STATIC mp_obj_t image_binary_op(mp_binary_op_t op, mp_obj_t lhs_in, mp_obj_t rhs } -const mp_obj_type_t microbit_image_type = { - { &mp_type_type }, - .name = MP_QSTR_MicroBitImage, - .print = microbit_image_print, - .make_new = microbit_image_make_new, - .binary_op = image_binary_op, - .locals_dict = (mp_obj_dict_t*)µbit_image_locals_dict, -}; +MP_DEFINE_CONST_OBJ_TYPE( + microbit_image_type, + MP_QSTR_MicroBitImage, + MP_TYPE_FLAG_NONE, + microbit_image_make_new, + print, microbit_image_print, + binary_op, image_binary_op, + locals_dict, (mp_obj_dict_t*)µbit_image_locals_dict + ); typedef struct _scrolling_string_t { mp_obj_base_t base; @@ -820,18 +821,22 @@ STATIC mp_obj_t microbit_scrolling_string_iter_next(mp_obj_t o_in) { return iter->img; } -const mp_obj_type_t microbit_scrolling_string_type = { - { &mp_type_type }, - .name = MP_QSTR_ScrollingString, - .getiter = get_microbit_scrolling_string_iter, -}; +MP_DEFINE_CONST_OBJ_TYPE( + microbit_scrolling_string_type, + MP_QSTR_ScrollingString, + MP_TYPE_FLAG_NONE, + MP_TYPE_NULL_MAKE_NEW, + getiter, get_microbit_scrolling_string_iter + ); -const mp_obj_type_t microbit_scrolling_string_iterator_type = { - { &mp_type_type }, - .name = MP_QSTR_iterator, - .getiter = mp_identity_getiter, - .iternext = microbit_scrolling_string_iter_next, -}; +MP_DEFINE_CONST_OBJ_TYPE( + microbit_scrolling_string_iterator_type, + MP_QSTR_iterator, + MP_TYPE_FLAG_NONE, + MP_TYPE_NULL_MAKE_NEW, + getiter, mp_identity_getiter, + iternext, microbit_scrolling_string_iter_next + ); /** Facade types to present a string as a sequence of images. * These are necessary to avoid allocation during iteration, @@ -869,13 +874,15 @@ static mp_obj_t facade_unary_op(mp_unary_op_t op, mp_obj_t self_in) { static mp_obj_t microbit_facade_iterator(mp_obj_t iterable_in, mp_obj_iter_buf_t *iter_buf); -const mp_obj_type_t string_image_facade_type = { - { &mp_type_type }, - .name = MP_QSTR_Facade, - .unary_op = facade_unary_op, - .subscr = string_image_facade_subscr, - .getiter = microbit_facade_iterator, -}; +MP_DEFINE_CONST_OBJ_TYPE( + string_image_facade_type, + MP_QSTR_Facade, + MP_TYPE_FLAG_NONE, + MP_TYPE_NULL_MAKE_NEW, + unary_op, facade_unary_op, + subscr, string_image_facade_subscr, + getiter, microbit_facade_iterator + ); typedef struct _facade_iterator_t { @@ -904,12 +911,14 @@ static mp_obj_t microbit_facade_iter_next(mp_obj_t iter_in) { return iter->image; } -const mp_obj_type_t microbit_facade_iterator_type = { - { &mp_type_type }, - .name = MP_QSTR_iterator, - .getiter = mp_identity_getiter, - .iternext = microbit_facade_iter_next, -}; +MP_DEFINE_CONST_OBJ_TYPE( + microbit_facade_iterator_type, + MP_QSTR_iterator, + MP_TYPE_FLAG_NONE, + MP_TYPE_NULL_MAKE_NEW, + getiter, mp_identity_getiter, + iternext, microbit_facade_iter_next + ); mp_obj_t microbit_facade_iterator(mp_obj_t iterable_in, mp_obj_iter_buf_t *iter_buf) { (void)iter_buf; diff --git a/ports/nrf/modules/board/led.c b/ports/nrf/modules/board/led.c index cbfc330d63..5eef8f0464 100644 --- a/ports/nrf/modules/board/led.c +++ b/ports/nrf/modules/board/led.c @@ -194,13 +194,14 @@ STATIC const mp_rom_map_elem_t led_locals_dict_table[] = { STATIC MP_DEFINE_CONST_DICT(led_locals_dict, led_locals_dict_table); -const mp_obj_type_t board_led_type = { - { &mp_type_type }, - .name = MP_QSTR_LED, - .print = led_obj_print, - .make_new = led_obj_make_new, - .locals_dict = (mp_obj_dict_t*)&led_locals_dict, -}; +MP_DEFINE_CONST_OBJ_TYPE( + board_led_type, + MP_QSTR_LED, + MP_TYPE_FLAG_NONE, + led_obj_make_new, + print, led_obj_print, + locals_dict, (mp_obj_dict_t*)&led_locals_dict + ); #else // For boards with no LEDs, we leave an empty function here so that we don't diff --git a/ports/nrf/modules/machine/adc.c b/ports/nrf/modules/machine/adc.c index 54870d2c18..5814dcaa39 100644 --- a/ports/nrf/modules/machine/adc.c +++ b/ports/nrf/modules/machine/adc.c @@ -294,12 +294,13 @@ STATIC const mp_rom_map_elem_t machine_adc_locals_dict_table[] = { STATIC MP_DEFINE_CONST_DICT(machine_adc_locals_dict, machine_adc_locals_dict_table); -const mp_obj_type_t machine_adc_type = { - { &mp_type_type }, - .name = MP_QSTR_ADC, - .make_new = machine_adc_make_new, - .locals_dict = (mp_obj_dict_t*)&machine_adc_locals_dict, - .print = machine_adc_print, -}; +MP_DEFINE_CONST_OBJ_TYPE( + machine_adc_type, + MP_QSTR_ADC, + MP_TYPE_FLAG_NONE, + machine_adc_make_new, + locals_dict, (mp_obj_dict_t*)&machine_adc_locals_dict, + print, machine_adc_print + ); #endif // MICROPY_PY_MACHINE_ADC diff --git a/ports/nrf/modules/machine/i2c.c b/ports/nrf/modules/machine/i2c.c index aac9320873..8468684428 100644 --- a/ports/nrf/modules/machine/i2c.c +++ b/ports/nrf/modules/machine/i2c.c @@ -161,13 +161,14 @@ STATIC const mp_machine_i2c_p_t machine_hard_i2c_p = { .transfer_single = machine_hard_i2c_transfer_single, }; -const mp_obj_type_t machine_hard_i2c_type = { - { &mp_type_type }, - .name = MP_QSTR_I2C, - .print = machine_hard_i2c_print, - .make_new = machine_hard_i2c_make_new, - .protocol = &machine_hard_i2c_p, - .locals_dict = (mp_obj_dict_t*)&mp_machine_i2c_locals_dict, -}; +MP_DEFINE_CONST_OBJ_TYPE( + machine_hard_i2c_type, + MP_QSTR_I2C, + MP_TYPE_FLAG_NONE, + machine_hard_i2c_make_new, + print, machine_hard_i2c_print, + protocol, &machine_hard_i2c_p, + locals_dict, (mp_obj_dict_t*)&mp_machine_i2c_locals_dict + ); #endif // MICROPY_PY_MACHINE_I2C diff --git a/ports/nrf/modules/machine/pin.c b/ports/nrf/modules/machine/pin.c index 3a45c22d18..835f6cf2bd 100644 --- a/ports/nrf/modules/machine/pin.c +++ b/ports/nrf/modules/machine/pin.c @@ -596,14 +596,15 @@ STATIC const mp_rom_map_elem_t pin_locals_dict_table[] = { STATIC MP_DEFINE_CONST_DICT(pin_locals_dict, pin_locals_dict_table); -const mp_obj_type_t pin_type = { - { &mp_type_type }, - .name = MP_QSTR_Pin, - .print = pin_print, - .make_new = pin_make_new, - .call = pin_call, - .locals_dict = (mp_obj_dict_t*)&pin_locals_dict, -}; +MP_DEFINE_CONST_OBJ_TYPE( + pin_type, + MP_QSTR_Pin, + MP_TYPE_FLAG_NONE, + pin_make_new, + print, pin_print, + call, pin_call, + locals_dict, (mp_obj_dict_t*)&pin_locals_dict + ); /// \moduleref machine /// \class PinAF - Pin Alternate Functions @@ -671,12 +672,14 @@ STATIC const mp_rom_map_elem_t pin_af_locals_dict_table[] = { }; STATIC MP_DEFINE_CONST_DICT(pin_af_locals_dict, pin_af_locals_dict_table); -const mp_obj_type_t pin_af_type = { - { &mp_type_type }, - .name = MP_QSTR_PinAF, - .print = pin_af_obj_print, - .locals_dict = (mp_obj_dict_t*)&pin_af_locals_dict, -}; +MP_DEFINE_CONST_OBJ_TYPE( + pin_af_type, + MP_QSTR_PinAF, + MP_TYPE_FLAG_NONE, + MP_TYPE_NULL_MAKE_NEW, + print, pin_af_obj_print, + locals_dict, (mp_obj_dict_t*)&pin_af_locals_dict + ); MP_REGISTER_ROOT_POINTER(mp_obj_t pin_class_mapper); MP_REGISTER_ROOT_POINTER(mp_obj_t pin_class_map_dict); diff --git a/ports/nrf/modules/machine/pwm.c b/ports/nrf/modules/machine/pwm.c index a750285841..d0ac0e9450 100644 --- a/ports/nrf/modules/machine/pwm.c +++ b/ports/nrf/modules/machine/pwm.c @@ -339,12 +339,13 @@ STATIC mp_obj_t machine_hard_pwm_freq(mp_obj_t self_in, mp_arg_val_t *args) { return mp_const_none; } -const mp_obj_type_t machine_hard_pwm_type = { - { &mp_type_type }, - .name = MP_QSTR_PWM, - .print = machine_pwm_print, - .make_new = machine_pwm_make_new, - .locals_dict = (mp_obj_dict_t*)&machine_pwm_locals_dict, -}; +MP_DEFINE_CONST_OBJ_TYPE( + machine_hard_pwm_type, + MP_QSTR_PWM, + MP_TYPE_FLAG_NONE, + machine_pwm_make_new, + print, machine_pwm_print, + locals_dict, (mp_obj_dict_t*)&machine_pwm_locals_dict + ); #endif // MICROPY_PY_MACHINE_HW_PWM diff --git a/ports/nrf/modules/machine/rtcounter.c b/ports/nrf/modules/machine/rtcounter.c index c9f907774e..3c48c4bb1f 100644 --- a/ports/nrf/modules/machine/rtcounter.c +++ b/ports/nrf/modules/machine/rtcounter.c @@ -262,12 +262,13 @@ STATIC const mp_rom_map_elem_t machine_rtc_locals_dict_table[] = { STATIC MP_DEFINE_CONST_DICT(machine_rtc_locals_dict, machine_rtc_locals_dict_table); -const mp_obj_type_t machine_rtcounter_type = { - { &mp_type_type }, - .name = MP_QSTR_RTCounter, - .print = rtc_print, - .make_new = machine_rtc_make_new, - .locals_dict = (mp_obj_dict_t*)&machine_rtc_locals_dict -}; +MP_DEFINE_CONST_OBJ_TYPE( + machine_rtcounter_type, + MP_QSTR_RTCounter, + MP_TYPE_FLAG_NONE, + machine_rtc_make_new, + print, rtc_print, + locals_dict, (mp_obj_dict_t*)&machine_rtc_locals_dict + ); #endif // MICROPY_PY_MACHINE_RTCOUNTER diff --git a/ports/nrf/modules/machine/spi.c b/ports/nrf/modules/machine/spi.c index 81bc151beb..22b0ff56e5 100644 --- a/ports/nrf/modules/machine/spi.c +++ b/ports/nrf/modules/machine/spi.c @@ -427,13 +427,14 @@ STATIC const mp_machine_spi_p_t machine_hard_spi_p = { .transfer = machine_hard_spi_transfer, }; -const mp_obj_type_t machine_hard_spi_type = { - { &mp_type_type }, - .name = MP_QSTR_SPI, - .print = machine_hard_spi_print, - .make_new = machine_spi_make_new, - .protocol = &machine_hard_spi_p, - .locals_dict = (mp_obj_dict_t*)&machine_spi_locals_dict, -}; +MP_DEFINE_CONST_OBJ_TYPE( + machine_hard_spi_type, + MP_QSTR_SPI, + MP_TYPE_FLAG_NONE, + machine_spi_make_new, + print, machine_hard_spi_print, + protocol, &machine_hard_spi_p, + locals_dict, (mp_obj_dict_t*)&machine_spi_locals_dict + ); #endif // MICROPY_PY_MACHINE_HW_SPI diff --git a/ports/nrf/modules/machine/temp.c b/ports/nrf/modules/machine/temp.c index 1eb38c08d0..1e21f11253 100644 --- a/ports/nrf/modules/machine/temp.c +++ b/ports/nrf/modules/machine/temp.c @@ -112,12 +112,13 @@ STATIC const mp_rom_map_elem_t machine_temp_locals_dict_table[] = { STATIC MP_DEFINE_CONST_DICT(machine_temp_locals_dict, machine_temp_locals_dict_table); -const mp_obj_type_t machine_temp_type = { - { &mp_type_type }, - .name = MP_QSTR_Temp, - .make_new = machine_temp_make_new, - .locals_dict = (mp_obj_dict_t*)&machine_temp_locals_dict, - .print = machine_temp_print, -}; +MP_DEFINE_CONST_OBJ_TYPE( + machine_temp_type, + MP_QSTR_Temp, + MP_TYPE_FLAG_NONE, + machine_temp_make_new, + locals_dict, (mp_obj_dict_t*)&machine_temp_locals_dict, + print, machine_temp_print + ); #endif // MICROPY_PY_MACHINE_TEMP diff --git a/ports/nrf/modules/machine/timer.c b/ports/nrf/modules/machine/timer.c index c99713ef52..3724881aa8 100644 --- a/ports/nrf/modules/machine/timer.c +++ b/ports/nrf/modules/machine/timer.c @@ -234,12 +234,13 @@ STATIC const mp_rom_map_elem_t machine_timer_locals_dict_table[] = { STATIC MP_DEFINE_CONST_DICT(machine_timer_locals_dict, machine_timer_locals_dict_table); -const mp_obj_type_t machine_timer_type = { - { &mp_type_type }, - .name = MP_QSTR_Timer, - .print = timer_print, - .make_new = machine_timer_make_new, - .locals_dict = (mp_obj_dict_t*)&machine_timer_locals_dict -}; +MP_DEFINE_CONST_OBJ_TYPE( + machine_timer_type, + MP_QSTR_Timer, + MP_TYPE_FLAG_NONE, + machine_timer_make_new, + print, timer_print, + locals_dict, (mp_obj_dict_t*)&machine_timer_locals_dict + ); #endif // MICROPY_PY_MACHINE_TIMER diff --git a/ports/nrf/modules/machine/uart.c b/ports/nrf/modules/machine/uart.c index 1fd2ccc06c..5c9ba83ab6 100644 --- a/ports/nrf/modules/machine/uart.c +++ b/ports/nrf/modules/machine/uart.c @@ -370,15 +370,16 @@ STATIC const mp_stream_p_t uart_stream_p = { .is_text = false, }; -const mp_obj_type_t machine_hard_uart_type = { - { &mp_type_type }, - .name = MP_QSTR_UART, - .print = machine_hard_uart_print, - .make_new = machine_hard_uart_make_new, - .getiter = mp_identity_getiter, - .iternext = mp_stream_unbuffered_iter, - .protocol = &uart_stream_p, - .locals_dict = (mp_obj_dict_t*)&machine_hard_uart_locals_dict, -}; +MP_DEFINE_CONST_OBJ_TYPE( + machine_hard_uart_type, + MP_QSTR_UART, + MP_TYPE_FLAG_NONE, + machine_hard_uart_make_new, + print, machine_hard_uart_print, + getiter, mp_identity_getiter, + iternext, mp_stream_unbuffered_iter, + protocol, &uart_stream_p, + locals_dict, (mp_obj_dict_t*)&machine_hard_uart_locals_dict + ); #endif // MICROPY_PY_MACHINE_UART diff --git a/ports/nrf/modules/nrf/flashbdev.c b/ports/nrf/modules/nrf/flashbdev.c index f63a9b46b2..b67e86d0d0 100644 --- a/ports/nrf/modules/nrf/flashbdev.c +++ b/ports/nrf/modules/nrf/flashbdev.c @@ -183,13 +183,14 @@ STATIC mp_obj_t nrf_flashbdev_make_new(const mp_obj_type_t *type, size_t n_args, return MP_OBJ_FROM_PTR(self); } -const mp_obj_type_t nrf_flashbdev_type = { - { &mp_type_type }, - .name = MP_QSTR_Flash, - .print = nrf_flashbdev_print, - .make_new = nrf_flashbdev_make_new, - .locals_dict = (mp_obj_dict_t *)&nrf_flashbdev_locals_dict, -}; +MP_DEFINE_CONST_OBJ_TYPE( + nrf_flashbdev_type, + MP_QSTR_Flash, + MP_TYPE_FLAG_NONE, + nrf_flashbdev_make_new, + print, nrf_flashbdev_print, + locals_dict, (mp_obj_dict_t *)&nrf_flashbdev_locals_dict + ); void flashbdev_init(void) { // Set start to first aligned page from _fs_start. diff --git a/ports/nrf/modules/ubluepy/ubluepy_characteristic.c b/ports/nrf/modules/ubluepy/ubluepy_characteristic.c index a66483f60d..5544ac6aef 100644 --- a/ports/nrf/modules/ubluepy/ubluepy_characteristic.c +++ b/ports/nrf/modules/ubluepy/ubluepy_characteristic.c @@ -209,12 +209,13 @@ STATIC const mp_rom_map_elem_t ubluepy_characteristic_locals_dict_table[] = { STATIC MP_DEFINE_CONST_DICT(ubluepy_characteristic_locals_dict, ubluepy_characteristic_locals_dict_table); -const mp_obj_type_t ubluepy_characteristic_type = { - { &mp_type_type }, - .name = MP_QSTR_Characteristic, - .print = ubluepy_characteristic_print, - .make_new = ubluepy_characteristic_make_new, - .locals_dict = (mp_obj_dict_t*)&ubluepy_characteristic_locals_dict -}; +MP_DEFINE_CONST_OBJ_TYPE( + ubluepy_characteristic_type, + MP_QSTR_Characteristic, + MP_TYPE_FLAG_NONE, + ubluepy_characteristic_make_new, + print, ubluepy_characteristic_print, + locals_dict, (mp_obj_dict_t*)&ubluepy_characteristic_locals_dict + ); #endif // MICROPY_PY_UBLUEPY_PERIPHERAL || MICROPY_PY_UBLUEPY_CENTRAL diff --git a/ports/nrf/modules/ubluepy/ubluepy_constants.c b/ports/nrf/modules/ubluepy/ubluepy_constants.c index 14e433e6eb..e4637c8cbc 100644 --- a/ports/nrf/modules/ubluepy/ubluepy_constants.c +++ b/ports/nrf/modules/ubluepy/ubluepy_constants.c @@ -69,11 +69,13 @@ STATIC const mp_rom_map_elem_t ubluepy_constants_ad_types_locals_dict_table[] = STATIC MP_DEFINE_CONST_DICT(ubluepy_constants_ad_types_locals_dict, ubluepy_constants_ad_types_locals_dict_table); -const mp_obj_type_t ubluepy_constants_ad_types_type = { - { &mp_type_type }, - .name = MP_QSTR_ad_types, - .locals_dict = (mp_obj_dict_t*)&ubluepy_constants_ad_types_locals_dict -}; +MP_DEFINE_CONST_OBJ_TYPE( + ubluepy_constants_ad_types_type, + MP_QSTR_ad_types, + MP_TYPE_FLAG_NONE, + MP_TYPE_NULL_MAKE_NEW, + locals_dict, (mp_obj_dict_t*)&ubluepy_constants_ad_types_locals_dict + ); STATIC const mp_rom_map_elem_t ubluepy_constants_locals_dict_table[] = { // GAP events @@ -90,10 +92,12 @@ STATIC const mp_rom_map_elem_t ubluepy_constants_locals_dict_table[] = { STATIC MP_DEFINE_CONST_DICT(ubluepy_constants_locals_dict, ubluepy_constants_locals_dict_table); -const mp_obj_type_t ubluepy_constants_type = { - { &mp_type_type }, - .name = MP_QSTR_constants, - .locals_dict = (mp_obj_dict_t*)&ubluepy_constants_locals_dict -}; +MP_DEFINE_CONST_OBJ_TYPE( + ubluepy_constants_type, + MP_QSTR_constants, + MP_TYPE_FLAG_NONE, + MP_TYPE_NULL_MAKE_NEW, + locals_dict, (mp_obj_dict_t*)&ubluepy_constants_locals_dict + ); #endif // MICROPY_PY_UBLUEPY diff --git a/ports/nrf/modules/ubluepy/ubluepy_delegate.c b/ports/nrf/modules/ubluepy/ubluepy_delegate.c index 736bfbc9dd..71648767e6 100644 --- a/ports/nrf/modules/ubluepy/ubluepy_delegate.c +++ b/ports/nrf/modules/ubluepy/ubluepy_delegate.c @@ -77,12 +77,13 @@ STATIC const mp_rom_map_elem_t ubluepy_delegate_locals_dict_table[] = { STATIC MP_DEFINE_CONST_DICT(ubluepy_delegate_locals_dict, ubluepy_delegate_locals_dict_table); -const mp_obj_type_t ubluepy_delegate_type = { - { &mp_type_type }, - .name = MP_QSTR_DefaultDelegate, - .print = ubluepy_delegate_print, - .make_new = ubluepy_delegate_make_new, - .locals_dict = (mp_obj_dict_t*)&ubluepy_delegate_locals_dict -}; +MP_DEFINE_CONST_OBJ_TYPE( + ubluepy_delegate_type, + MP_QSTR_DefaultDelegate, + MP_TYPE_FLAG_NONE, + ubluepy_delegate_make_new, + print, ubluepy_delegate_print, + locals_dict, (mp_obj_dict_t*)&ubluepy_delegate_locals_dict + ); #endif // MICROPY_PY_UBLUEPY_PERIPHERAL || MICROPY_PY_UBLUEPY_CENTRAL diff --git a/ports/nrf/modules/ubluepy/ubluepy_descriptor.c b/ports/nrf/modules/ubluepy/ubluepy_descriptor.c index 370188f7fc..07035460ae 100644 --- a/ports/nrf/modules/ubluepy/ubluepy_descriptor.c +++ b/ports/nrf/modules/ubluepy/ubluepy_descriptor.c @@ -70,12 +70,13 @@ STATIC const mp_rom_map_elem_t ubluepy_descriptor_locals_dict_table[] = { STATIC MP_DEFINE_CONST_DICT(ubluepy_descriptor_locals_dict, ubluepy_descriptor_locals_dict_table); -const mp_obj_type_t ubluepy_descriptor_type = { - { &mp_type_type }, - .name = MP_QSTR_Descriptor, - .print = ubluepy_descriptor_print, - .make_new = ubluepy_descriptor_make_new, - .locals_dict = (mp_obj_dict_t*)&ubluepy_descriptor_locals_dict -}; +MP_DEFINE_CONST_OBJ_TYPE( + ubluepy_descriptor_type, + MP_QSTR_Descriptor, + MP_TYPE_FLAG_NONE, + ubluepy_descriptor_make_new, + print, ubluepy_descriptor_print, + locals_dict, (mp_obj_dict_t*)&ubluepy_descriptor_locals_dict + ); #endif // MICROPY_PY_UBLUEPY diff --git a/ports/nrf/modules/ubluepy/ubluepy_peripheral.c b/ports/nrf/modules/ubluepy/ubluepy_peripheral.c index acfe316c0c..9c346a885b 100644 --- a/ports/nrf/modules/ubluepy/ubluepy_peripheral.c +++ b/ports/nrf/modules/ubluepy/ubluepy_peripheral.c @@ -482,12 +482,13 @@ STATIC const mp_rom_map_elem_t ubluepy_peripheral_locals_dict_table[] = { STATIC MP_DEFINE_CONST_DICT(ubluepy_peripheral_locals_dict, ubluepy_peripheral_locals_dict_table); -const mp_obj_type_t ubluepy_peripheral_type = { - { &mp_type_type }, - .name = MP_QSTR_Peripheral, - .print = ubluepy_peripheral_print, - .make_new = ubluepy_peripheral_make_new, - .locals_dict = (mp_obj_dict_t*)&ubluepy_peripheral_locals_dict -}; +MP_DEFINE_CONST_OBJ_TYPE( + ubluepy_peripheral_type, + MP_QSTR_Peripheral, + MP_TYPE_FLAG_NONE, + ubluepy_peripheral_make_new, + print, ubluepy_peripheral_print, + locals_dict, (mp_obj_dict_t*)&ubluepy_peripheral_locals_dict + ); #endif // MICROPY_PY_UBLUEPY diff --git a/ports/nrf/modules/ubluepy/ubluepy_scan_entry.c b/ports/nrf/modules/ubluepy/ubluepy_scan_entry.c index 773070b089..64a81d215d 100644 --- a/ports/nrf/modules/ubluepy/ubluepy_scan_entry.c +++ b/ports/nrf/modules/ubluepy/ubluepy_scan_entry.c @@ -136,11 +136,13 @@ STATIC const mp_rom_map_elem_t ubluepy_scan_entry_locals_dict_table[] = { STATIC MP_DEFINE_CONST_DICT(ubluepy_scan_entry_locals_dict, ubluepy_scan_entry_locals_dict_table); -const mp_obj_type_t ubluepy_scan_entry_type = { - { &mp_type_type }, - .name = MP_QSTR_ScanEntry, - .print = ubluepy_scan_entry_print, - .locals_dict = (mp_obj_dict_t*)&ubluepy_scan_entry_locals_dict -}; +MP_DEFINE_CONST_OBJ_TYPE( + ubluepy_scan_entry_type, + MP_QSTR_ScanEntry, + MP_TYPE_FLAG_NONE, + MP_TYPE_NULL_MAKE_NEW, + print, ubluepy_scan_entry_print, + locals_dict, (mp_obj_dict_t*)&ubluepy_scan_entry_locals_dict + ); #endif // MICROPY_PY_UBLUEPY_CENTRAL diff --git a/ports/nrf/modules/ubluepy/ubluepy_scanner.c b/ports/nrf/modules/ubluepy/ubluepy_scanner.c index 60895a3da9..c47044cf0c 100644 --- a/ports/nrf/modules/ubluepy/ubluepy_scanner.c +++ b/ports/nrf/modules/ubluepy/ubluepy_scanner.c @@ -114,12 +114,13 @@ STATIC const mp_rom_map_elem_t ubluepy_scanner_locals_dict_table[] = { STATIC MP_DEFINE_CONST_DICT(ubluepy_scanner_locals_dict, ubluepy_scanner_locals_dict_table); -const mp_obj_type_t ubluepy_scanner_type = { - { &mp_type_type }, - .name = MP_QSTR_Scanner, - .print = ubluepy_scanner_print, - .make_new = ubluepy_scanner_make_new, - .locals_dict = (mp_obj_dict_t*)&ubluepy_scanner_locals_dict -}; +MP_DEFINE_CONST_OBJ_TYPE( + ubluepy_scanner_type, + MP_QSTR_Scanner, + MP_TYPE_FLAG_NONE, + ubluepy_scanner_make_new, + print, ubluepy_scanner_print, + locals_dict, (mp_obj_dict_t*)&ubluepy_scanner_locals_dict + ); #endif // MICROPY_PY_UBLUEPY_CENTRAL diff --git a/ports/nrf/modules/ubluepy/ubluepy_service.c b/ports/nrf/modules/ubluepy/ubluepy_service.c index 6dac231779..9d0d6e5b95 100644 --- a/ports/nrf/modules/ubluepy/ubluepy_service.c +++ b/ports/nrf/modules/ubluepy/ubluepy_service.c @@ -171,12 +171,13 @@ STATIC const mp_rom_map_elem_t ubluepy_service_locals_dict_table[] = { STATIC MP_DEFINE_CONST_DICT(ubluepy_service_locals_dict, ubluepy_service_locals_dict_table); -const mp_obj_type_t ubluepy_service_type = { - { &mp_type_type }, - .name = MP_QSTR_Service, - .print = ubluepy_service_print, - .make_new = ubluepy_service_make_new, - .locals_dict = (mp_obj_dict_t*)&ubluepy_service_locals_dict -}; +MP_DEFINE_CONST_OBJ_TYPE( + ubluepy_service_type, + MP_QSTR_Service, + MP_TYPE_FLAG_NONE, + ubluepy_service_make_new, + print, ubluepy_service_print, + locals_dict, (mp_obj_dict_t*)&ubluepy_service_locals_dict + ); #endif // MICROPY_PY_UBLUEPY_PERIPHERAL || MICROPY_PY_UBLUEPY_CENTRAL diff --git a/ports/nrf/modules/ubluepy/ubluepy_uuid.c b/ports/nrf/modules/ubluepy/ubluepy_uuid.c index aee7b9a1a8..0414a2a286 100644 --- a/ports/nrf/modules/ubluepy/ubluepy_uuid.c +++ b/ports/nrf/modules/ubluepy/ubluepy_uuid.c @@ -160,12 +160,13 @@ STATIC const mp_rom_map_elem_t ubluepy_uuid_locals_dict_table[] = { STATIC MP_DEFINE_CONST_DICT(ubluepy_uuid_locals_dict, ubluepy_uuid_locals_dict_table); -const mp_obj_type_t ubluepy_uuid_type = { - { &mp_type_type }, - .name = MP_QSTR_UUID, - .print = ubluepy_uuid_print, - .make_new = ubluepy_uuid_make_new, - .locals_dict = (mp_obj_dict_t*)&ubluepy_uuid_locals_dict -}; +MP_DEFINE_CONST_OBJ_TYPE( + ubluepy_uuid_type, + MP_QSTR_UUID, + MP_TYPE_FLAG_NONE, + ubluepy_uuid_make_new, + print, ubluepy_uuid_print, + locals_dict, (mp_obj_dict_t*)&ubluepy_uuid_locals_dict + ); #endif // MICROPY_PY_UBLUEPY diff --git a/ports/nrf/modules/uos/microbitfs.c b/ports/nrf/modules/uos/microbitfs.c index 6c8ffb0925..63ac8c9321 100644 --- a/ports/nrf/modules/uos/microbitfs.c +++ b/ports/nrf/modules/uos/microbitfs.c @@ -626,12 +626,14 @@ STATIC const mp_stream_p_t textio_stream_p = { .is_text = true, }; -const mp_obj_type_t uos_mbfs_textio_type = { - { &mp_type_type }, - .name = MP_QSTR_TextIO, - .protocol = &textio_stream_p, - .locals_dict = (mp_obj_dict_t*)&uos_mbfs_file_locals_dict, -}; +MP_DEFINE_CONST_OBJ_TYPE( + uos_mbfs_textio_type, + MP_QSTR_TextIO, + MP_TYPE_FLAG_NONE, + MP_TYPE_NULL_MAKE_NEW, + protocol, &textio_stream_p, + locals_dict, (mp_obj_dict_t*)&uos_mbfs_file_locals_dict + ); STATIC const mp_stream_p_t fileio_stream_p = { @@ -639,12 +641,14 @@ STATIC const mp_stream_p_t fileio_stream_p = { .write = microbit_file_write, }; -const mp_obj_type_t uos_mbfs_fileio_type = { - { &mp_type_type }, - .name = MP_QSTR_FileIO, - .protocol = &fileio_stream_p, - .locals_dict = (mp_obj_dict_t*)&uos_mbfs_file_locals_dict, -}; +MP_DEFINE_CONST_OBJ_TYPE( + uos_mbfs_fileio_type, + MP_QSTR_FileIO, + MP_TYPE_FLAG_NONE, + MP_TYPE_NULL_MAKE_NEW, + protocol, &fileio_stream_p, + locals_dict, (mp_obj_dict_t*)&uos_mbfs_file_locals_dict + ); // From micro:bit fileobj.c mp_obj_t uos_mbfs_open(size_t n_args, const mp_obj_t *args) { diff --git a/ports/nrf/pin_named_pins.c b/ports/nrf/pin_named_pins.c index e1d8736b9c..87fed746e6 100644 --- a/ports/nrf/pin_named_pins.c +++ b/ports/nrf/pin_named_pins.c @@ -36,19 +36,23 @@ STATIC void pin_named_pins_obj_print(const mp_print_t *print, mp_obj_t self_in, mp_printf(print, "", self->name); } -const mp_obj_type_t pin_cpu_pins_obj_type = { - { &mp_type_type }, - .name = MP_QSTR_cpu, - .print = pin_named_pins_obj_print, - .locals_dict = (mp_obj_t)&pin_cpu_pins_locals_dict, -}; +MP_DEFINE_CONST_OBJ_TYPE( + pin_cpu_pins_obj_type, + MP_QSTR_cpu, + MP_TYPE_FLAG_NONE, + MP_TYPE_NULL_MAKE_NEW, + print, pin_named_pins_obj_print, + locals_dict, (mp_obj_t)&pin_cpu_pins_locals_dict + ); -const mp_obj_type_t pin_board_pins_obj_type = { - { &mp_type_type }, - .name = MP_QSTR_board, - .print = pin_named_pins_obj_print, - .locals_dict = (mp_obj_t)&pin_board_pins_locals_dict, -}; +MP_DEFINE_CONST_OBJ_TYPE( + pin_board_pins_obj_type, + MP_QSTR_board, + MP_TYPE_FLAG_NONE, + MP_TYPE_NULL_MAKE_NEW, + print, pin_named_pins_obj_print, + locals_dict, (mp_obj_t)&pin_board_pins_locals_dict + ); const pin_obj_t *pin_find_named_pin(const mp_obj_dict_t *named_pins, mp_obj_t name) { mp_map_t *named_map = mp_obj_dict_get_map((mp_obj_t)named_pins); diff --git a/ports/pic16bit/modpybled.c b/ports/pic16bit/modpybled.c index 6adb2fda31..fd4e8cce9c 100644 --- a/ports/pic16bit/modpybled.c +++ b/ports/pic16bit/modpybled.c @@ -84,10 +84,11 @@ STATIC const mp_rom_map_elem_t pyb_led_locals_dict_table[] = { STATIC MP_DEFINE_CONST_DICT(pyb_led_locals_dict, pyb_led_locals_dict_table); -const mp_obj_type_t pyb_led_type = { - { &mp_type_type }, - .name = MP_QSTR_LED, - .print = pyb_led_print, - .make_new = pyb_led_make_new, - .locals_dict = (mp_obj_t)&pyb_led_locals_dict, -}; +MP_DEFINE_CONST_OBJ_TYPE( + pyb_led_type, + MP_QSTR_LED, + MP_TYPE_FLAG_NONE, + pyb_led_make_new, + print, pyb_led_print, + locals_dict, (mp_obj_t)&pyb_led_locals_dict + ); diff --git a/ports/pic16bit/modpybswitch.c b/ports/pic16bit/modpybswitch.c index 7b3d0f5f52..e1096b1daa 100644 --- a/ports/pic16bit/modpybswitch.c +++ b/ports/pic16bit/modpybswitch.c @@ -71,11 +71,12 @@ STATIC const mp_rom_map_elem_t pyb_switch_locals_dict_table[] = { STATIC MP_DEFINE_CONST_DICT(pyb_switch_locals_dict, pyb_switch_locals_dict_table); -const mp_obj_type_t pyb_switch_type = { - { &mp_type_type }, - .name = MP_QSTR_Switch, - .print = pyb_switch_print, - .make_new = pyb_switch_make_new, - .call = pyb_switch_call, - .locals_dict = (mp_obj_t)&pyb_switch_locals_dict, -}; +MP_DEFINE_CONST_OBJ_TYPE( + pyb_switch_type, + MP_QSTR_Switch, + MP_TYPE_FLAG_NONE, + pyb_switch_make_new, + print, pyb_switch_print, + call, pyb_switch_call, + locals_dict, (mp_obj_t)&pyb_switch_locals_dict + ); diff --git a/ports/renesas-ra/extint.c b/ports/renesas-ra/extint.c index 59f9ecfa37..496a50c3e8 100644 --- a/ports/renesas-ra/extint.c +++ b/ports/renesas-ra/extint.c @@ -374,13 +374,14 @@ STATIC const mp_rom_map_elem_t extint_locals_dict_table[] = { STATIC MP_DEFINE_CONST_DICT(extint_locals_dict, extint_locals_dict_table); -const mp_obj_type_t extint_type = { - { &mp_type_type }, - .name = MP_QSTR_ExtInt, - .print = extint_obj_print, - .make_new = extint_make_new, - .locals_dict = (mp_obj_dict_t *)&extint_locals_dict, -}; +MP_DEFINE_CONST_OBJ_TYPE( + extint_type, + MP_QSTR_ExtInt, + MP_TYPE_FLAG_NONE, + extint_make_new, + locals_dict, &extint_locals_dict, + print, extint_obj_print + ); void extint_init0(void) { ra_icu_init(); diff --git a/ports/renesas-ra/led.c b/ports/renesas-ra/led.c index efc09d9de1..9a3f1d40e9 100644 --- a/ports/renesas-ra/led.c +++ b/ports/renesas-ra/led.c @@ -170,13 +170,14 @@ STATIC const mp_rom_map_elem_t led_locals_dict_table[] = { STATIC MP_DEFINE_CONST_DICT(led_locals_dict, led_locals_dict_table); -const mp_obj_type_t ra_led_type = { - { &mp_type_type }, - .name = MP_QSTR_LED, - .print = led_obj_print, - .make_new = led_obj_make_new, - .locals_dict = (mp_obj_dict_t *)&led_locals_dict, -}; +MP_DEFINE_CONST_OBJ_TYPE( + ra_led_type, + MP_QSTR_LED, + MP_TYPE_FLAG_NONE, + led_obj_make_new, + locals_dict, &led_locals_dict, + print, led_obj_print + ); #else // For boards with no LEDs, we leave an empty function here so that we don't diff --git a/ports/renesas-ra/machine_adc.c b/ports/renesas-ra/machine_adc.c index adeebeb4c4..99e35f48d9 100644 --- a/ports/renesas-ra/machine_adc.c +++ b/ports/renesas-ra/machine_adc.c @@ -126,10 +126,11 @@ STATIC const mp_rom_map_elem_t machine_adc_locals_dict_table[] = { }; STATIC MP_DEFINE_CONST_DICT(machine_adc_locals_dict, machine_adc_locals_dict_table); -const mp_obj_type_t machine_adc_type = { - { &mp_type_type }, - .name = MP_QSTR_ADC, - .print = machine_adc_print, - .make_new = machine_adc_make_new, - .locals_dict = (mp_obj_dict_t *)&machine_adc_locals_dict, -}; +MP_DEFINE_CONST_OBJ_TYPE( + machine_adc_type, + MP_QSTR_ADC, + MP_TYPE_FLAG_NONE, + machine_adc_make_new, + locals_dict, &machine_adc_locals_dict, + print, machine_adc_print + ); diff --git a/ports/renesas-ra/machine_i2c.c b/ports/renesas-ra/machine_i2c.c index bc1cea0cd9..eaca5ff4a8 100644 --- a/ports/renesas-ra/machine_i2c.c +++ b/ports/renesas-ra/machine_i2c.c @@ -156,13 +156,14 @@ STATIC const mp_machine_i2c_p_t machine_i2c_p = { .transfer_single = machine_i2c_transfer_single, }; -const mp_obj_type_t machine_i2c_type = { - { &mp_type_type }, - .name = MP_QSTR_I2C, - .print = machine_i2c_print, - .make_new = machine_i2c_make_new, - .protocol = &machine_i2c_p, - .locals_dict = (mp_obj_dict_t *)&mp_machine_i2c_locals_dict, -}; +MP_DEFINE_CONST_OBJ_TYPE( + machine_i2c_type, + MP_QSTR_I2C, + MP_TYPE_FLAG_NONE, + machine_i2c_make_new, + locals_dict, (void *)&mp_machine_i2c_locals_dict, + print, machine_i2c_print, + protocol, &machine_i2c_p + ); #endif // MICROPY_HW_ENABLE_HW_I2C diff --git a/ports/renesas-ra/machine_pin.c b/ports/renesas-ra/machine_pin.c index f940b55547..17ef1e19a4 100644 --- a/ports/renesas-ra/machine_pin.c +++ b/ports/renesas-ra/machine_pin.c @@ -349,15 +349,16 @@ STATIC const mp_pin_p_t machine_pin_pin_p = { .ioctl = machine_pin_ioctl, }; -const mp_obj_type_t machine_pin_type = { - { &mp_type_type }, - .name = MP_QSTR_Pin, - .print = machine_pin_print, - .make_new = mp_pin_make_new, - .call = machine_pin_call, - .protocol = &machine_pin_pin_p, - .locals_dict = (mp_obj_t)&machine_pin_locals_dict, -}; +MP_DEFINE_CONST_OBJ_TYPE( + machine_pin_type, + MP_QSTR_Pin, + MP_TYPE_FLAG_NONE, + mp_pin_make_new, + locals_dict, &machine_pin_locals_dict, + print, machine_pin_print, + call, machine_pin_call, + protocol, &machine_pin_pin_p + ); // Returns the pin mode. This value returned by this macro should be one of: // GPIO_MODE_INPUT, GPIO_MODE_OUTPUT_PP, GPIO_MODE_OUTPUT_OD, @@ -388,17 +389,21 @@ uint32_t pin_get_af(const machine_pin_obj_t *pin) { return (uint32_t)ra_gpio_get_af(pin->pin); } -const mp_obj_type_t pin_cpu_pins_obj_type = { - { &mp_type_type }, - .name = MP_QSTR_cpu, - .locals_dict = (mp_obj_dict_t *)&pin_cpu_pins_locals_dict, -}; +MP_DEFINE_CONST_OBJ_TYPE( + pin_cpu_pins_obj_type, + MP_QSTR_cpu, + MP_TYPE_FLAG_NONE, + MP_TYPE_NULL_MAKE_NEW, + locals_dict, &pin_cpu_pins_locals_dict + ); -const mp_obj_type_t pin_board_pins_obj_type = { - { &mp_type_type }, - .name = MP_QSTR_board, - .locals_dict = (mp_obj_dict_t *)&pin_board_pins_locals_dict, -}; +MP_DEFINE_CONST_OBJ_TYPE( + pin_board_pins_obj_type, + MP_QSTR_board, + MP_TYPE_FLAG_NONE, + MP_TYPE_NULL_MAKE_NEW, + locals_dict, &pin_board_pins_locals_dict + ); const machine_pin_obj_t *pin_find_named_pin(const mp_obj_dict_t *named_pins, mp_obj_t name) { const mp_map_t *named_map = &named_pins->map; diff --git a/ports/renesas-ra/machine_rtc.c b/ports/renesas-ra/machine_rtc.c index 9ddc902137..c3f64c6971 100644 --- a/ports/renesas-ra/machine_rtc.c +++ b/ports/renesas-ra/machine_rtc.c @@ -341,9 +341,10 @@ STATIC const mp_rom_map_elem_t machine_rtc_locals_dict_table[] = { }; STATIC MP_DEFINE_CONST_DICT(machine_rtc_locals_dict, machine_rtc_locals_dict_table); -const mp_obj_type_t machine_rtc_type = { - { &mp_type_type }, - .name = MP_QSTR_RTC, - .make_new = machine_rtc_make_new, - .locals_dict = (mp_obj_dict_t *)&machine_rtc_locals_dict, -}; +MP_DEFINE_CONST_OBJ_TYPE( + machine_rtc_type, + MP_QSTR_RTC, + MP_TYPE_FLAG_NONE, + machine_rtc_make_new, + locals_dict, &machine_rtc_locals_dict + ); diff --git a/ports/renesas-ra/machine_spi.c b/ports/renesas-ra/machine_spi.c index 01972ad457..d0e8b03bd1 100644 --- a/ports/renesas-ra/machine_spi.c +++ b/ports/renesas-ra/machine_spi.c @@ -297,14 +297,15 @@ STATIC const mp_machine_spi_p_t machine_hard_spi_p = { .transfer = machine_hard_spi_transfer, }; -const mp_obj_type_t machine_hard_spi_type = { - { &mp_type_type }, - .name = MP_QSTR_SPI, - .print = machine_hard_spi_print, - .make_new = machine_hard_spi_make_new, - .protocol = &machine_hard_spi_p, - .locals_dict = (mp_obj_dict_t *)&mp_machine_spi_locals_dict, -}; +MP_DEFINE_CONST_OBJ_TYPE( + machine_hard_spi_type, + MP_QSTR_SPI, + MP_TYPE_FLAG_NONE, + machine_hard_spi_make_new, + locals_dict, &mp_machine_spi_locals_dict, + print, machine_hard_spi_print, + protocol, &machine_hard_spi_p + ); void spi_init0(void) { } diff --git a/ports/renesas-ra/machine_timer.c b/ports/renesas-ra/machine_timer.c index c387d35117..f3e5aafb7c 100644 --- a/ports/renesas-ra/machine_timer.c +++ b/ports/renesas-ra/machine_timer.c @@ -136,10 +136,11 @@ STATIC const mp_rom_map_elem_t machine_timer_locals_dict_table[] = { }; STATIC MP_DEFINE_CONST_DICT(machine_timer_locals_dict, machine_timer_locals_dict_table); -const mp_obj_type_t machine_timer_type = { - { &mp_type_type }, - .name = MP_QSTR_Timer, - .print = machine_timer_print, - .make_new = machine_timer_make_new, - .locals_dict = (mp_obj_dict_t *)&machine_timer_locals_dict, -}; +MP_DEFINE_CONST_OBJ_TYPE( + machine_timer_type, + MP_QSTR_Timer, + MP_TYPE_FLAG_NONE, + machine_timer_make_new, + locals_dict, &machine_timer_locals_dict, + print, machine_timer_print + ); diff --git a/ports/renesas-ra/machine_uart.c b/ports/renesas-ra/machine_uart.c index 4b4aa3396b..11f5d6825e 100644 --- a/ports/renesas-ra/machine_uart.c +++ b/ports/renesas-ra/machine_uart.c @@ -571,15 +571,16 @@ STATIC const mp_stream_p_t uart_stream_p = { .is_text = false, }; -const mp_obj_type_t machine_uart_type = { - { &mp_type_type }, - .name = MP_QSTR_UART, - .print = machine_uart_print, - .make_new = machine_uart_make_new, - .getiter = mp_identity_getiter, - .iternext = mp_stream_unbuffered_iter, - .protocol = &uart_stream_p, - .locals_dict = (mp_obj_dict_t *)&machine_uart_locals_dict, -}; +MP_DEFINE_CONST_OBJ_TYPE( + machine_uart_type, + MP_QSTR_UART, + MP_TYPE_FLAG_NONE, + machine_uart_make_new, + locals_dict, &machine_uart_locals_dict, + print, machine_uart_print, + getiter, mp_identity_getiter, + iternext, mp_stream_unbuffered_iter, + protocol, &uart_stream_p + ); MP_REGISTER_ROOT_POINTER(struct _machine_uart_obj_t *machine_uart_obj_all[MICROPY_HW_MAX_UART + MICROPY_HW_MAX_LPUART]); diff --git a/ports/renesas-ra/storage.c b/ports/renesas-ra/storage.c index 8d94f6fb9c..f573894a50 100644 --- a/ports/renesas-ra/storage.c +++ b/ports/renesas-ra/storage.c @@ -400,13 +400,14 @@ STATIC const mp_rom_map_elem_t pyb_flash_locals_dict_table[] = { STATIC MP_DEFINE_CONST_DICT(pyb_flash_locals_dict, pyb_flash_locals_dict_table); -const mp_obj_type_t pyb_flash_type = { - { &mp_type_type }, - .name = MP_QSTR_Flash, - .print = pyb_flash_print, - .make_new = pyb_flash_make_new, - .locals_dict = (mp_obj_dict_t *)&pyb_flash_locals_dict, -}; +MP_DEFINE_CONST_OBJ_TYPE( + pyb_flash_type, + MP_QSTR_Flash, + MP_TYPE_FLAG_NONE, + pyb_flash_make_new, + locals_dict, &pyb_flash_locals_dict, + print, pyb_flash_print + ); void pyb_flash_init_vfs(fs_user_mount_t *vfs) { vfs->base.type = &mp_fat_vfs_type; diff --git a/ports/renesas-ra/timer.c b/ports/renesas-ra/timer.c index 1ae936525e..8f7acbcdaa 100644 --- a/ports/renesas-ra/timer.c +++ b/ports/renesas-ra/timer.c @@ -410,13 +410,14 @@ STATIC const mp_rom_map_elem_t pyb_timer_locals_dict_table[] = { }; STATIC MP_DEFINE_CONST_DICT(pyb_timer_locals_dict, pyb_timer_locals_dict_table); -const mp_obj_type_t pyb_timer_type = { - { &mp_type_type }, - .name = MP_QSTR_Timer, - .print = pyb_timer_print, - .make_new = pyb_timer_make_new, - .locals_dict = (mp_obj_dict_t *)&pyb_timer_locals_dict, -}; +MP_DEFINE_CONST_OBJ_TYPE( + pyb_timer_type, + MP_QSTR_Timer, + MP_TYPE_FLAG_NONE, + pyb_timer_make_new, + locals_dict, &pyb_timer_locals_dict, + print, pyb_timer_print + ); #if defined(TIMER_CHANNEL) /* @@ -502,12 +503,14 @@ STATIC const mp_rom_map_elem_t pyb_timer_channel_locals_dict_table[] = { }; STATIC MP_DEFINE_CONST_DICT(pyb_timer_channel_locals_dict, pyb_timer_channel_locals_dict_table); -STATIC const mp_obj_type_t pyb_timer_channel_type = { - { &mp_type_type }, - .name = MP_QSTR_TimerChannel, - .print = pyb_timer_channel_print, - .locals_dict = (mp_obj_dict_t *)&pyb_timer_channel_locals_dict, -}; +STATIC MP_DEFINE_CONST_OBJ_TYPE( + pyb_timer_channel_type, + MP_QSTR_TimerChannel, + MP_TYPE_FLAG_NONE, + MP_TYPE_NULL_MAKE_NEW, + locals_dict, &pyb_timer_channel_locals_dict, + print, pyb_timer_channel_print + ); #endif STATIC void timer_handle_irq_channel(pyb_timer_obj_t *tim, uint8_t channel, mp_obj_t callback) { diff --git a/ports/renesas-ra/usrsw.c b/ports/renesas-ra/usrsw.c index 572510816b..4107d7850d 100644 --- a/ports/renesas-ra/usrsw.c +++ b/ports/renesas-ra/usrsw.c @@ -135,14 +135,15 @@ STATIC const mp_rom_map_elem_t pyb_switch_locals_dict_table[] = { STATIC MP_DEFINE_CONST_DICT(pyb_switch_locals_dict, pyb_switch_locals_dict_table); -const mp_obj_type_t pyb_switch_type = { - { &mp_type_type }, - .name = MP_QSTR_Switch, - .print = pyb_switch_print, - .make_new = pyb_switch_make_new, - .call = pyb_switch_call, - .locals_dict = (mp_obj_dict_t *)&pyb_switch_locals_dict, -}; +MP_DEFINE_CONST_OBJ_TYPE( + pyb_switch_type, + MP_QSTR_Switch, + MP_TYPE_FLAG_NONE, + pyb_switch_make_new, + locals_dict, &pyb_switch_locals_dict, + print, pyb_switch_print, + call, pyb_switch_call + ); MP_REGISTER_ROOT_POINTER(mp_obj_t pyb_switch_callback); diff --git a/ports/rp2/machine_adc.c b/ports/rp2/machine_adc.c index 5f91392e14..549f8d5ecd 100644 --- a/ports/rp2/machine_adc.c +++ b/ports/rp2/machine_adc.c @@ -113,10 +113,11 @@ STATIC const mp_rom_map_elem_t machine_adc_locals_dict_table[] = { }; STATIC MP_DEFINE_CONST_DICT(machine_adc_locals_dict, machine_adc_locals_dict_table); -const mp_obj_type_t machine_adc_type = { - { &mp_type_type }, - .name = MP_QSTR_ADC, - .print = machine_adc_print, - .make_new = machine_adc_make_new, - .locals_dict = (mp_obj_dict_t *)&machine_adc_locals_dict, -}; +MP_DEFINE_CONST_OBJ_TYPE( + machine_adc_type, + MP_QSTR_ADC, + MP_TYPE_FLAG_NONE, + machine_adc_make_new, + print, machine_adc_print, + locals_dict, (mp_obj_dict_t *)&machine_adc_locals_dict + ); diff --git a/ports/rp2/machine_i2c.c b/ports/rp2/machine_i2c.c index 3390cc4210..91d8bb59b7 100644 --- a/ports/rp2/machine_i2c.c +++ b/ports/rp2/machine_i2c.c @@ -176,11 +176,12 @@ STATIC const mp_machine_i2c_p_t machine_i2c_p = { .transfer_single = machine_i2c_transfer_single, }; -const mp_obj_type_t machine_hw_i2c_type = { - { &mp_type_type }, - .name = MP_QSTR_I2C, - .print = machine_i2c_print, - .make_new = machine_i2c_make_new, - .protocol = &machine_i2c_p, - .locals_dict = (mp_obj_dict_t *)&mp_machine_i2c_locals_dict, -}; +MP_DEFINE_CONST_OBJ_TYPE( + machine_hw_i2c_type, + MP_QSTR_I2C, + MP_TYPE_FLAG_NONE, + machine_i2c_make_new, + print, machine_i2c_print, + protocol, &machine_i2c_p, + locals_dict, (mp_obj_dict_t *)&mp_machine_i2c_locals_dict + ); diff --git a/ports/rp2/machine_i2s.c b/ports/rp2/machine_i2s.c index 1015ba1017..8446a59781 100644 --- a/ports/rp2/machine_i2s.c +++ b/ports/rp2/machine_i2s.c @@ -1137,15 +1137,16 @@ STATIC const mp_stream_p_t i2s_stream_p = { .is_text = false, }; -const mp_obj_type_t machine_i2s_type = { - { &mp_type_type }, - .name = MP_QSTR_I2S, - .print = machine_i2s_print, - .getiter = mp_identity_getiter, - .iternext = mp_stream_unbuffered_iter, - .protocol = &i2s_stream_p, - .make_new = machine_i2s_make_new, - .locals_dict = (mp_obj_dict_t *)&machine_i2s_locals_dict, -}; +MP_DEFINE_CONST_OBJ_TYPE( + machine_i2s_type, + MP_QSTR_I2S, + MP_TYPE_FLAG_NONE, + machine_i2s_make_new, + print, machine_i2s_print, + getiter, mp_identity_getiter, + iternext, mp_stream_unbuffered_iter, + protocol, &i2s_stream_p, + locals_dict, (mp_obj_dict_t *)&machine_i2s_locals_dict + ); MP_REGISTER_ROOT_POINTER(void *machine_i2s_obj[2]); diff --git a/ports/rp2/machine_pin.c b/ports/rp2/machine_pin.c index 705f61242c..38670f09ab 100644 --- a/ports/rp2/machine_pin.c +++ b/ports/rp2/machine_pin.c @@ -641,15 +641,16 @@ STATIC const mp_pin_p_t pin_pin_p = { .ioctl = pin_ioctl, }; -const mp_obj_type_t machine_pin_type = { - { &mp_type_type }, - .name = MP_QSTR_Pin, - .print = machine_pin_print, - .make_new = mp_pin_make_new, - .call = machine_pin_call, - .protocol = &pin_pin_p, - .locals_dict = (mp_obj_t)&machine_pin_locals_dict, -}; +MP_DEFINE_CONST_OBJ_TYPE( + machine_pin_type, + MP_QSTR_Pin, + MP_TYPE_FLAG_NONE, + mp_pin_make_new, + print, machine_pin_print, + call, machine_pin_call, + protocol, &pin_pin_p, + locals_dict, (mp_obj_t)&machine_pin_locals_dict + ); STATIC mp_uint_t machine_pin_irq_trigger(mp_obj_t self_in, mp_uint_t new_trigger) { machine_pin_obj_t *self = MP_OBJ_TO_PTR(self_in); diff --git a/ports/rp2/machine_rtc.c b/ports/rp2/machine_rtc.c index 9d59124a66..73bdaee6c7 100644 --- a/ports/rp2/machine_rtc.c +++ b/ports/rp2/machine_rtc.c @@ -115,9 +115,10 @@ STATIC const mp_rom_map_elem_t machine_rtc_locals_dict_table[] = { }; STATIC MP_DEFINE_CONST_DICT(machine_rtc_locals_dict, machine_rtc_locals_dict_table); -const mp_obj_type_t machine_rtc_type = { - { &mp_type_type }, - .name = MP_QSTR_RTC, - .make_new = machine_rtc_make_new, - .locals_dict = (mp_obj_t)&machine_rtc_locals_dict, -}; +MP_DEFINE_CONST_OBJ_TYPE( + machine_rtc_type, + MP_QSTR_RTC, + MP_TYPE_FLAG_NONE, + machine_rtc_make_new, + locals_dict, (mp_obj_t)&machine_rtc_locals_dict + ); diff --git a/ports/rp2/machine_spi.c b/ports/rp2/machine_spi.c index 104bd1fd53..f3ac8d7cf8 100644 --- a/ports/rp2/machine_spi.c +++ b/ports/rp2/machine_spi.c @@ -290,14 +290,15 @@ STATIC const mp_machine_spi_p_t machine_spi_p = { .transfer = machine_spi_transfer, }; -const mp_obj_type_t machine_spi_type = { - { &mp_type_type }, - .name = MP_QSTR_SPI, - .print = machine_spi_print, - .make_new = machine_spi_make_new, - .protocol = &machine_spi_p, - .locals_dict = (mp_obj_dict_t *)&mp_machine_spi_locals_dict, -}; +MP_DEFINE_CONST_OBJ_TYPE( + machine_spi_type, + MP_QSTR_SPI, + MP_TYPE_FLAG_NONE, + machine_spi_make_new, + print, machine_spi_print, + protocol, &machine_spi_p, + locals_dict, (mp_obj_dict_t *)&mp_machine_spi_locals_dict + ); mp_obj_base_t *mp_hal_get_spi_obj(mp_obj_t o) { if (mp_obj_is_type(o, &machine_spi_type)) { diff --git a/ports/rp2/machine_timer.c b/ports/rp2/machine_timer.c index e7e8f02d55..d3b6015529 100644 --- a/ports/rp2/machine_timer.c +++ b/ports/rp2/machine_timer.c @@ -156,10 +156,11 @@ STATIC const mp_rom_map_elem_t machine_timer_locals_dict_table[] = { }; STATIC MP_DEFINE_CONST_DICT(machine_timer_locals_dict, machine_timer_locals_dict_table); -const mp_obj_type_t machine_timer_type = { - { &mp_type_type }, - .name = MP_QSTR_Timer, - .print = machine_timer_print, - .make_new = machine_timer_make_new, - .locals_dict = (mp_obj_dict_t *)&machine_timer_locals_dict, -}; +MP_DEFINE_CONST_OBJ_TYPE( + machine_timer_type, + MP_QSTR_Timer, + MP_TYPE_FLAG_NONE, + machine_timer_make_new, + print, machine_timer_print, + locals_dict, (mp_obj_dict_t *)&machine_timer_locals_dict + ); diff --git a/ports/rp2/machine_uart.c b/ports/rp2/machine_uart.c index f7e44b6b25..df6228058b 100644 --- a/ports/rp2/machine_uart.c +++ b/ports/rp2/machine_uart.c @@ -579,16 +579,17 @@ STATIC const mp_stream_p_t uart_stream_p = { .is_text = false, }; -const mp_obj_type_t machine_uart_type = { - { &mp_type_type }, - .name = MP_QSTR_UART, - .print = machine_uart_print, - .make_new = machine_uart_make_new, - .getiter = mp_identity_getiter, - .iternext = mp_stream_unbuffered_iter, - .protocol = &uart_stream_p, - .locals_dict = (mp_obj_dict_t *)&machine_uart_locals_dict, -}; +MP_DEFINE_CONST_OBJ_TYPE( + machine_uart_type, + MP_QSTR_UART, + MP_TYPE_FLAG_NONE, + machine_uart_make_new, + print, machine_uart_print, + getiter, mp_identity_getiter, + iternext, mp_stream_unbuffered_iter, + protocol, &uart_stream_p, + locals_dict, (mp_obj_dict_t *)&machine_uart_locals_dict + ); MP_REGISTER_ROOT_POINTER(void *rp2_uart_rx_buffer[2]); MP_REGISTER_ROOT_POINTER(void *rp2_uart_tx_buffer[2]); diff --git a/ports/rp2/machine_wdt.c b/ports/rp2/machine_wdt.c index d6914a4f26..e8c4333069 100644 --- a/ports/rp2/machine_wdt.c +++ b/ports/rp2/machine_wdt.c @@ -77,9 +77,10 @@ STATIC const mp_rom_map_elem_t machine_wdt_locals_dict_table[] = { }; STATIC MP_DEFINE_CONST_DICT(machine_wdt_locals_dict, machine_wdt_locals_dict_table); -const mp_obj_type_t machine_wdt_type = { - { &mp_type_type }, - .name = MP_QSTR_WDT, - .make_new = machine_wdt_make_new, - .locals_dict = (mp_obj_dict_t *)&machine_wdt_locals_dict, -}; +MP_DEFINE_CONST_OBJ_TYPE( + machine_wdt_type, + MP_QSTR_WDT, + MP_TYPE_FLAG_NONE, + machine_wdt_make_new, + locals_dict, (mp_obj_dict_t *)&machine_wdt_locals_dict + ); diff --git a/ports/rp2/rp2_flash.c b/ports/rp2/rp2_flash.c index 47c95ea5c8..37a3412db5 100644 --- a/ports/rp2/rp2_flash.c +++ b/ports/rp2/rp2_flash.c @@ -185,9 +185,10 @@ STATIC const mp_rom_map_elem_t rp2_flash_locals_dict_table[] = { }; STATIC MP_DEFINE_CONST_DICT(rp2_flash_locals_dict, rp2_flash_locals_dict_table); -const mp_obj_type_t rp2_flash_type = { - { &mp_type_type }, - .name = MP_QSTR_Flash, - .make_new = rp2_flash_make_new, - .locals_dict = (mp_obj_dict_t *)&rp2_flash_locals_dict, -}; +MP_DEFINE_CONST_OBJ_TYPE( + rp2_flash_type, + MP_QSTR_Flash, + MP_TYPE_FLAG_NONE, + rp2_flash_make_new, + locals_dict, (mp_obj_dict_t *)&rp2_flash_locals_dict + ); diff --git a/ports/rp2/rp2_pio.c b/ports/rp2/rp2_pio.c index eb85eb2248..9a195bdd8a 100644 --- a/ports/rp2/rp2_pio.c +++ b/ports/rp2/rp2_pio.c @@ -376,13 +376,14 @@ STATIC const mp_rom_map_elem_t rp2_pio_locals_dict_table[] = { }; STATIC MP_DEFINE_CONST_DICT(rp2_pio_locals_dict, rp2_pio_locals_dict_table); -const mp_obj_type_t rp2_pio_type = { - { &mp_type_type }, - .name = MP_QSTR_PIO, - .print = rp2_pio_print, - .make_new = rp2_pio_make_new, - .locals_dict = (mp_obj_dict_t *)&rp2_pio_locals_dict, -}; +MP_DEFINE_CONST_OBJ_TYPE( + rp2_pio_type, + MP_QSTR_PIO, + MP_TYPE_FLAG_NONE, + rp2_pio_make_new, + print, rp2_pio_print, + locals_dict, (mp_obj_dict_t *)&rp2_pio_locals_dict + ); STATIC mp_uint_t rp2_pio_irq_trigger(mp_obj_t self_in, mp_uint_t new_trigger) { rp2_pio_obj_t *self = MP_OBJ_TO_PTR(self_in); @@ -806,13 +807,14 @@ STATIC const mp_rom_map_elem_t rp2_state_machine_locals_dict_table[] = { }; STATIC MP_DEFINE_CONST_DICT(rp2_state_machine_locals_dict, rp2_state_machine_locals_dict_table); -const mp_obj_type_t rp2_state_machine_type = { - { &mp_type_type }, - .name = MP_QSTR_StateMachine, - .print = rp2_state_machine_print, - .make_new = rp2_state_machine_make_new, - .locals_dict = (mp_obj_dict_t *)&rp2_state_machine_locals_dict, -}; +MP_DEFINE_CONST_OBJ_TYPE( + rp2_state_machine_type, + MP_QSTR_StateMachine, + MP_TYPE_FLAG_NONE, + rp2_state_machine_make_new, + print, rp2_state_machine_print, + locals_dict, (mp_obj_dict_t *)&rp2_state_machine_locals_dict + ); STATIC mp_uint_t rp2_state_machine_irq_trigger(mp_obj_t self_in, mp_uint_t new_trigger) { rp2_state_machine_obj_t *self = MP_OBJ_TO_PTR(self_in); diff --git a/ports/samd/machine_led.c b/ports/samd/machine_led.c index f4dd1aeb3c..76aae8ffc5 100644 --- a/ports/samd/machine_led.c +++ b/ports/samd/machine_led.c @@ -162,11 +162,12 @@ STATIC const mp_rom_map_elem_t machine_led_locals_dict_table[] = { }; STATIC MP_DEFINE_CONST_DICT(machine_led_locals_dict, machine_led_locals_dict_table); -const mp_obj_type_t machine_led_type = { - { &mp_type_type }, - .name = MP_QSTR_LED, - .print = machine_led_print, - .make_new = mp_led_make_new, - .call = machine_led_call, - .locals_dict = (mp_obj_t)&machine_led_locals_dict, -}; +MP_DEFINE_CONST_OBJ_TYPE( + machine_led_type, + MP_QSTR_LED, + MP_TYPE_FLAG_NONE, + mp_led_make_new, + print, machine_led_print, + call, machine_led_call, + locals_dict, (mp_obj_t)&machine_led_locals_dict + ); diff --git a/ports/samd/machine_pin.c b/ports/samd/machine_pin.c index 161a3ccddd..d47982e0e1 100644 --- a/ports/samd/machine_pin.c +++ b/ports/samd/machine_pin.c @@ -287,15 +287,16 @@ STATIC const mp_pin_p_t pin_pin_p = { .ioctl = pin_ioctl, }; -const mp_obj_type_t machine_pin_type = { - { &mp_type_type }, - .name = MP_QSTR_Pin, - .print = machine_pin_print, - .make_new = mp_pin_make_new, - .call = machine_pin_call, - .protocol = &pin_pin_p, - .locals_dict = (mp_obj_t)&machine_pin_locals_dict, -}; +MP_DEFINE_CONST_OBJ_TYPE( + machine_pin_type, + MP_QSTR_Pin, + MP_TYPE_FLAG_NONE, + mp_pin_make_new, + print, machine_pin_print, + call, machine_pin_call, + protocol, &pin_pin_p, + locals_dict, (mp_obj_t)&machine_pin_locals_dict + ); /* STATIC mp_uint_t machine_pin_irq_trigger(mp_obj_t self_in, mp_uint_t new_trigger) { diff --git a/ports/samd/samd_flash.c b/ports/samd/samd_flash.c index 530e3d9c8e..6c74b59a26 100644 --- a/ports/samd/samd_flash.c +++ b/ports/samd/samd_flash.c @@ -181,9 +181,10 @@ STATIC const mp_rom_map_elem_t samd_flash_locals_dict_table[] = { }; STATIC MP_DEFINE_CONST_DICT(samd_flash_locals_dict, samd_flash_locals_dict_table); -const mp_obj_type_t samd_flash_type = { - { &mp_type_type }, - .name = MP_QSTR_Flash, - .make_new = samd_flash_make_new, - .locals_dict = (mp_obj_dict_t *)&samd_flash_locals_dict, -}; +MP_DEFINE_CONST_OBJ_TYPE( + samd_flash_type, + MP_QSTR_Flash, + MP_TYPE_FLAG_NONE, + samd_flash_make_new, + locals_dict, (mp_obj_dict_t *)&samd_flash_locals_dict + ); diff --git a/ports/stm32/accel.c b/ports/stm32/accel.c index b07791a9a0..276ce37d3a 100644 --- a/ports/stm32/accel.c +++ b/ports/stm32/accel.c @@ -281,11 +281,12 @@ STATIC const mp_rom_map_elem_t pyb_accel_locals_dict_table[] = { STATIC MP_DEFINE_CONST_DICT(pyb_accel_locals_dict, pyb_accel_locals_dict_table); -const mp_obj_type_t pyb_accel_type = { - { &mp_type_type }, - .name = MP_QSTR_Accel, - .make_new = pyb_accel_make_new, - .locals_dict = (mp_obj_dict_t *)&pyb_accel_locals_dict, -}; +MP_DEFINE_CONST_OBJ_TYPE( + pyb_accel_type, + MP_QSTR_Accel, + MP_TYPE_FLAG_NONE, + pyb_accel_make_new, + locals_dict, (mp_obj_dict_t *)&pyb_accel_locals_dict + ); #endif // MICROPY_HW_HAS_MMA7660 || MICROPY_HW_HAS_KXTJ3 diff --git a/ports/stm32/adc.c b/ports/stm32/adc.c index 9d58cf2e7c..7e627d088f 100644 --- a/ports/stm32/adc.c +++ b/ports/stm32/adc.c @@ -703,13 +703,14 @@ STATIC const mp_rom_map_elem_t adc_locals_dict_table[] = { STATIC MP_DEFINE_CONST_DICT(adc_locals_dict, adc_locals_dict_table); -const mp_obj_type_t pyb_adc_type = { - { &mp_type_type }, - .name = MP_QSTR_ADC, - .print = adc_print, - .make_new = adc_make_new, - .locals_dict = (mp_obj_dict_t *)&adc_locals_dict, -}; +MP_DEFINE_CONST_OBJ_TYPE( + pyb_adc_type, + MP_QSTR_ADC, + MP_TYPE_FLAG_NONE, + adc_make_new, + print, adc_print, + locals_dict, (mp_obj_dict_t *)&adc_locals_dict + ); /******************************************************************************/ /* adc all object */ @@ -911,11 +912,12 @@ STATIC const mp_rom_map_elem_t adc_all_locals_dict_table[] = { STATIC MP_DEFINE_CONST_DICT(adc_all_locals_dict, adc_all_locals_dict_table); -const mp_obj_type_t pyb_adc_all_type = { - { &mp_type_type }, - .name = MP_QSTR_ADCAll, - .make_new = adc_all_make_new, - .locals_dict = (mp_obj_dict_t *)&adc_all_locals_dict, -}; +MP_DEFINE_CONST_OBJ_TYPE( + pyb_adc_all_type, + MP_QSTR_ADCAll, + MP_TYPE_FLAG_NONE, + adc_all_make_new, + locals_dict, (mp_obj_dict_t *)&adc_all_locals_dict + ); #endif // MICROPY_HW_ENABLE_ADC diff --git a/ports/stm32/dac.c b/ports/stm32/dac.c index c41bf858a7..da50b30fef 100644 --- a/ports/stm32/dac.c +++ b/ports/stm32/dac.c @@ -502,12 +502,13 @@ STATIC const mp_rom_map_elem_t pyb_dac_locals_dict_table[] = { STATIC MP_DEFINE_CONST_DICT(pyb_dac_locals_dict, pyb_dac_locals_dict_table); -const mp_obj_type_t pyb_dac_type = { - { &mp_type_type }, - .name = MP_QSTR_DAC, - .print = pyb_dac_print, - .make_new = pyb_dac_make_new, - .locals_dict = (mp_obj_dict_t *)&pyb_dac_locals_dict, -}; +MP_DEFINE_CONST_OBJ_TYPE( + pyb_dac_type, + MP_QSTR_DAC, + MP_TYPE_FLAG_NONE, + pyb_dac_make_new, + print, pyb_dac_print, + locals_dict, (mp_obj_dict_t *)&pyb_dac_locals_dict + ); #endif // MICROPY_HW_ENABLE_DAC diff --git a/ports/stm32/extint.c b/ports/stm32/extint.c index d68275bf19..4d2dc5d23b 100644 --- a/ports/stm32/extint.c +++ b/ports/stm32/extint.c @@ -659,13 +659,14 @@ STATIC const mp_rom_map_elem_t extint_locals_dict_table[] = { STATIC MP_DEFINE_CONST_DICT(extint_locals_dict, extint_locals_dict_table); -const mp_obj_type_t extint_type = { - { &mp_type_type }, - .name = MP_QSTR_ExtInt, - .print = extint_obj_print, - .make_new = extint_make_new, - .locals_dict = (mp_obj_dict_t *)&extint_locals_dict, -}; +MP_DEFINE_CONST_OBJ_TYPE( + extint_type, + MP_QSTR_ExtInt, + MP_TYPE_FLAG_NONE, + extint_make_new, + print, extint_obj_print, + locals_dict, (mp_obj_dict_t *)&extint_locals_dict + ); void extint_init0(void) { for (int i = 0; i < PYB_EXTI_NUM_VECTORS; i++) { diff --git a/ports/stm32/lcd.c b/ports/stm32/lcd.c index a0e001d1fd..a951ea7668 100644 --- a/ports/stm32/lcd.c +++ b/ports/stm32/lcd.c @@ -525,11 +525,12 @@ STATIC const mp_rom_map_elem_t pyb_lcd_locals_dict_table[] = { STATIC MP_DEFINE_CONST_DICT(pyb_lcd_locals_dict, pyb_lcd_locals_dict_table); -const mp_obj_type_t pyb_lcd_type = { - { &mp_type_type }, - .name = MP_QSTR_LCD, - .make_new = pyb_lcd_make_new, - .locals_dict = (mp_obj_dict_t *)&pyb_lcd_locals_dict, -}; +MP_DEFINE_CONST_OBJ_TYPE( + pyb_lcd_type, + MP_QSTR_LCD, + MP_TYPE_FLAG_NONE, + pyb_lcd_make_new, + locals_dict, (mp_obj_dict_t *)&pyb_lcd_locals_dict + ); #endif // MICROPY_HW_HAS_LCD diff --git a/ports/stm32/led.c b/ports/stm32/led.c index 078327462a..6745ef60b8 100644 --- a/ports/stm32/led.c +++ b/ports/stm32/led.c @@ -381,13 +381,14 @@ STATIC const mp_rom_map_elem_t led_locals_dict_table[] = { STATIC MP_DEFINE_CONST_DICT(led_locals_dict, led_locals_dict_table); -const mp_obj_type_t pyb_led_type = { - { &mp_type_type }, - .name = MP_QSTR_LED, - .print = led_obj_print, - .make_new = led_obj_make_new, - .locals_dict = (mp_obj_dict_t *)&led_locals_dict, -}; +MP_DEFINE_CONST_OBJ_TYPE( + pyb_led_type, + MP_QSTR_LED, + MP_TYPE_FLAG_NONE, + led_obj_make_new, + print, led_obj_print, + locals_dict, (mp_obj_dict_t *)&led_locals_dict + ); #else // For boards with no LEDs, we leave an empty function here so that we don't diff --git a/ports/stm32/machine_adc.c b/ports/stm32/machine_adc.c index ad7c994ba1..682bae3a6d 100644 --- a/ports/stm32/machine_adc.c +++ b/ports/stm32/machine_adc.c @@ -492,12 +492,13 @@ STATIC const mp_rom_map_elem_t machine_adc_locals_dict_table[] = { }; STATIC MP_DEFINE_CONST_DICT(machine_adc_locals_dict, machine_adc_locals_dict_table); -const mp_obj_type_t machine_adc_type = { - { &mp_type_type }, - .name = MP_QSTR_ADC, - .print = machine_adc_print, - .make_new = machine_adc_make_new, - .locals_dict = (mp_obj_dict_t *)&machine_adc_locals_dict, -}; +MP_DEFINE_CONST_OBJ_TYPE( + machine_adc_type, + MP_QSTR_ADC, + MP_TYPE_FLAG_NONE, + machine_adc_make_new, + print, machine_adc_print, + locals_dict, (mp_obj_dict_t *)&machine_adc_locals_dict + ); #endif diff --git a/ports/stm32/machine_i2c.c b/ports/stm32/machine_i2c.c index 262944585a..89970f234d 100644 --- a/ports/stm32/machine_i2c.c +++ b/ports/stm32/machine_i2c.c @@ -236,13 +236,14 @@ STATIC const mp_machine_i2c_p_t machine_hard_i2c_p = { .transfer = machine_hard_i2c_transfer, }; -const mp_obj_type_t machine_hard_i2c_type = { - { &mp_type_type }, - .name = MP_QSTR_I2C, - .print = machine_hard_i2c_print, - .make_new = machine_hard_i2c_make_new, - .protocol = &machine_hard_i2c_p, - .locals_dict = (mp_obj_dict_t *)&mp_machine_i2c_locals_dict, -}; +MP_DEFINE_CONST_OBJ_TYPE( + machine_hard_i2c_type, + MP_QSTR_I2C, + MP_TYPE_FLAG_NONE, + machine_hard_i2c_make_new, + print, machine_hard_i2c_print, + protocol, &machine_hard_i2c_p, + locals_dict, (mp_obj_dict_t *)&mp_machine_i2c_locals_dict + ); #endif // MICROPY_HW_ENABLE_HW_I2C diff --git a/ports/stm32/machine_i2s.c b/ports/stm32/machine_i2s.c index 4f583a53e8..7dc6439f25 100644 --- a/ports/stm32/machine_i2s.c +++ b/ports/stm32/machine_i2s.c @@ -1114,16 +1114,17 @@ STATIC const mp_stream_p_t i2s_stream_p = { .is_text = false, }; -const mp_obj_type_t machine_i2s_type = { - { &mp_type_type }, - .name = MP_QSTR_I2S, - .print = machine_i2s_print, - .getiter = mp_identity_getiter, - .iternext = mp_stream_unbuffered_iter, - .protocol = &i2s_stream_p, - .make_new = machine_i2s_make_new, - .locals_dict = (mp_obj_dict_t *)&machine_i2s_locals_dict, -}; +MP_DEFINE_CONST_OBJ_TYPE( + machine_i2s_type, + MP_QSTR_I2S, + MP_TYPE_FLAG_NONE, + machine_i2s_make_new, + print, machine_i2s_print, + getiter, mp_identity_getiter, + iternext, mp_stream_unbuffered_iter, + protocol, &i2s_stream_p, + locals_dict, (mp_obj_dict_t *)&machine_i2s_locals_dict + ); MP_REGISTER_ROOT_POINTER(struct _machine_i2s_obj_t *machine_i2s_obj[MICROPY_HW_MAX_I2S]); diff --git a/ports/stm32/machine_spi.c b/ports/stm32/machine_spi.c index 37c026cefc..87561c2b7b 100644 --- a/ports/stm32/machine_spi.c +++ b/ports/stm32/machine_spi.c @@ -135,11 +135,12 @@ STATIC const mp_machine_spi_p_t machine_hard_spi_p = { .transfer = machine_hard_spi_transfer, }; -const mp_obj_type_t machine_hard_spi_type = { - { &mp_type_type }, - .name = MP_QSTR_SPI, - .print = machine_hard_spi_print, - .make_new = machine_hard_spi_make_new, - .protocol = &machine_hard_spi_p, - .locals_dict = (mp_obj_dict_t *)&mp_machine_spi_locals_dict, -}; +MP_DEFINE_CONST_OBJ_TYPE( + machine_hard_spi_type, + MP_QSTR_SPI, + MP_TYPE_FLAG_NONE, + machine_hard_spi_make_new, + print, machine_hard_spi_print, + protocol, &machine_hard_spi_p, + locals_dict, (mp_obj_dict_t *)&mp_machine_spi_locals_dict + ); diff --git a/ports/stm32/machine_timer.c b/ports/stm32/machine_timer.c index c387d35117..bd9dbe6098 100644 --- a/ports/stm32/machine_timer.c +++ b/ports/stm32/machine_timer.c @@ -136,10 +136,11 @@ STATIC const mp_rom_map_elem_t machine_timer_locals_dict_table[] = { }; STATIC MP_DEFINE_CONST_DICT(machine_timer_locals_dict, machine_timer_locals_dict_table); -const mp_obj_type_t machine_timer_type = { - { &mp_type_type }, - .name = MP_QSTR_Timer, - .print = machine_timer_print, - .make_new = machine_timer_make_new, - .locals_dict = (mp_obj_dict_t *)&machine_timer_locals_dict, -}; +MP_DEFINE_CONST_OBJ_TYPE( + machine_timer_type, + MP_QSTR_Timer, + MP_TYPE_FLAG_NONE, + machine_timer_make_new, + print, machine_timer_print, + locals_dict, (mp_obj_dict_t *)&machine_timer_locals_dict + ); diff --git a/ports/stm32/machine_uart.c b/ports/stm32/machine_uart.c index 1bb1d2a1a7..4d25a0274c 100644 --- a/ports/stm32/machine_uart.c +++ b/ports/stm32/machine_uart.c @@ -660,13 +660,14 @@ STATIC const mp_stream_p_t uart_stream_p = { .is_text = false, }; -const mp_obj_type_t pyb_uart_type = { - { &mp_type_type }, - .name = MP_QSTR_UART, - .print = pyb_uart_print, - .make_new = pyb_uart_make_new, - .getiter = mp_identity_getiter, - .iternext = mp_stream_unbuffered_iter, - .protocol = &uart_stream_p, - .locals_dict = (mp_obj_dict_t *)&pyb_uart_locals_dict, -}; +MP_DEFINE_CONST_OBJ_TYPE( + pyb_uart_type, + MP_QSTR_UART, + MP_TYPE_FLAG_NONE, + pyb_uart_make_new, + print, pyb_uart_print, + getiter, mp_identity_getiter, + iternext, mp_stream_unbuffered_iter, + protocol, &uart_stream_p, + locals_dict, (mp_obj_dict_t *)&pyb_uart_locals_dict + ); diff --git a/ports/stm32/network_lan.c b/ports/stm32/network_lan.c index f19916a1df..f9c7d80b78 100644 --- a/ports/stm32/network_lan.c +++ b/ports/stm32/network_lan.c @@ -158,12 +158,13 @@ STATIC const mp_rom_map_elem_t network_lan_locals_dict_table[] = { }; STATIC MP_DEFINE_CONST_DICT(network_lan_locals_dict, network_lan_locals_dict_table); -const mp_obj_type_t network_lan_type = { - { &mp_type_type }, - .name = MP_QSTR_LAN, - .print = network_lan_print, - .make_new = network_lan_make_new, - .locals_dict = (mp_obj_dict_t *)&network_lan_locals_dict, -}; +MP_DEFINE_CONST_OBJ_TYPE( + network_lan_type, + MP_QSTR_LAN, + MP_TYPE_FLAG_NONE, + network_lan_make_new, + print, network_lan_print, + locals_dict, (mp_obj_dict_t *)&network_lan_locals_dict + ); #endif // defined(MICROPY_HW_ETH_MDC) diff --git a/ports/stm32/pin.c b/ports/stm32/pin.c index af6bafc43f..992046cd17 100644 --- a/ports/stm32/pin.c +++ b/ports/stm32/pin.c @@ -592,15 +592,16 @@ STATIC const mp_pin_p_t pin_pin_p = { .ioctl = pin_ioctl, }; -const mp_obj_type_t pin_type = { - { &mp_type_type }, - .name = MP_QSTR_Pin, - .print = pin_print, - .make_new = mp_pin_make_new, - .call = pin_call, - .protocol = &pin_pin_p, - .locals_dict = (mp_obj_dict_t *)&pin_locals_dict, -}; +MP_DEFINE_CONST_OBJ_TYPE( + pin_type, + MP_QSTR_Pin, + MP_TYPE_FLAG_NONE, + mp_pin_make_new, + print, pin_print, + call, pin_call, + protocol, &pin_pin_p, + locals_dict, (mp_obj_dict_t *)&pin_locals_dict + ); /// \moduleref pyb /// \class PinAF - Pin Alternate Functions @@ -669,12 +670,14 @@ STATIC const mp_rom_map_elem_t pin_af_locals_dict_table[] = { }; STATIC MP_DEFINE_CONST_DICT(pin_af_locals_dict, pin_af_locals_dict_table); -const mp_obj_type_t pin_af_type = { - { &mp_type_type }, - .name = MP_QSTR_PinAF, - .print = pin_af_obj_print, - .locals_dict = (mp_obj_dict_t *)&pin_af_locals_dict, -}; +MP_DEFINE_CONST_OBJ_TYPE( + pin_af_type, + MP_QSTR_PinAF, + MP_TYPE_FLAG_NONE, + MP_TYPE_NULL_MAKE_NEW, + print, pin_af_obj_print, + locals_dict, (mp_obj_dict_t *)&pin_af_locals_dict + ); MP_REGISTER_ROOT_POINTER(mp_obj_t pin_class_mapper); MP_REGISTER_ROOT_POINTER(mp_obj_t pin_class_map_dict); diff --git a/ports/stm32/pin_named_pins.c b/ports/stm32/pin_named_pins.c index 3a8e0f9fce..620888878c 100644 --- a/ports/stm32/pin_named_pins.c +++ b/ports/stm32/pin_named_pins.c @@ -31,17 +31,21 @@ #include "py/mphal.h" #include "pin.h" -const mp_obj_type_t pin_cpu_pins_obj_type = { - { &mp_type_type }, - .name = MP_QSTR_cpu, - .locals_dict = (mp_obj_dict_t *)&pin_cpu_pins_locals_dict, -}; +MP_DEFINE_CONST_OBJ_TYPE( + pin_cpu_pins_obj_type, + MP_QSTR_cpu, + MP_TYPE_FLAG_NONE, + MP_TYPE_NULL_MAKE_NEW, + locals_dict, (mp_obj_dict_t *)&pin_cpu_pins_locals_dict + ); -const mp_obj_type_t pin_board_pins_obj_type = { - { &mp_type_type }, - .name = MP_QSTR_board, - .locals_dict = (mp_obj_dict_t *)&pin_board_pins_locals_dict, -}; +MP_DEFINE_CONST_OBJ_TYPE( + pin_board_pins_obj_type, + MP_QSTR_board, + MP_TYPE_FLAG_NONE, + MP_TYPE_NULL_MAKE_NEW, + locals_dict, (mp_obj_dict_t *)&pin_board_pins_locals_dict + ); const pin_obj_t *pin_find_named_pin(const mp_obj_dict_t *named_pins, mp_obj_t name) { const mp_map_t *named_map = &named_pins->map; diff --git a/ports/stm32/pyb_can.c b/ports/stm32/pyb_can.c index ff41de3186..6fdfd2c854 100644 --- a/ports/stm32/pyb_can.c +++ b/ports/stm32/pyb_can.c @@ -1072,14 +1072,15 @@ STATIC const mp_stream_p_t can_stream_p = { .is_text = false, }; -const mp_obj_type_t pyb_can_type = { - { &mp_type_type }, - .name = MP_QSTR_CAN, - .print = pyb_can_print, - .make_new = pyb_can_make_new, - .protocol = &can_stream_p, - .locals_dict = (mp_obj_dict_t *)&pyb_can_locals_dict, -}; +MP_DEFINE_CONST_OBJ_TYPE( + pyb_can_type, + MP_QSTR_CAN, + MP_TYPE_FLAG_NONE, + pyb_can_make_new, + print, pyb_can_print, + protocol, &can_stream_p, + locals_dict, (mp_obj_dict_t *)&pyb_can_locals_dict + ); MP_REGISTER_ROOT_POINTER(struct _pyb_can_obj_t *pyb_can_obj_all[MICROPY_HW_MAX_CAN]); diff --git a/ports/stm32/pyb_i2c.c b/ports/stm32/pyb_i2c.c index e9877422ca..ee6983a143 100644 --- a/ports/stm32/pyb_i2c.c +++ b/ports/stm32/pyb_i2c.c @@ -1104,12 +1104,13 @@ STATIC const mp_rom_map_elem_t pyb_i2c_locals_dict_table[] = { STATIC MP_DEFINE_CONST_DICT(pyb_i2c_locals_dict, pyb_i2c_locals_dict_table); -const mp_obj_type_t pyb_i2c_type = { - { &mp_type_type }, - .name = MP_QSTR_I2C, - .print = pyb_i2c_print, - .make_new = pyb_i2c_make_new, - .locals_dict = (mp_obj_dict_t *)&pyb_i2c_locals_dict, -}; +MP_DEFINE_CONST_OBJ_TYPE( + pyb_i2c_type, + MP_QSTR_I2C, + MP_TYPE_FLAG_NONE, + pyb_i2c_make_new, + print, pyb_i2c_print, + locals_dict, (mp_obj_dict_t *)&pyb_i2c_locals_dict + ); #endif // MICROPY_PY_PYB_LEGACY && MICROPY_HW_ENABLE_HW_I2C diff --git a/ports/stm32/pyb_spi.c b/ports/stm32/pyb_spi.c index f2cdcebf2a..b1425272fe 100644 --- a/ports/stm32/pyb_spi.c +++ b/ports/stm32/pyb_spi.c @@ -350,11 +350,12 @@ STATIC const mp_machine_spi_p_t pyb_spi_p = { .transfer = spi_transfer_machine, }; -const mp_obj_type_t pyb_spi_type = { - { &mp_type_type }, - .name = MP_QSTR_SPI, - .print = pyb_spi_print, - .make_new = pyb_spi_make_new, - .protocol = &pyb_spi_p, - .locals_dict = (mp_obj_dict_t *)&pyb_spi_locals_dict, -}; +MP_DEFINE_CONST_OBJ_TYPE( + pyb_spi_type, + MP_QSTR_SPI, + MP_TYPE_FLAG_NONE, + pyb_spi_make_new, + print, pyb_spi_print, + protocol, &pyb_spi_p, + locals_dict, (mp_obj_dict_t *)&pyb_spi_locals_dict + ); diff --git a/ports/stm32/rtc.c b/ports/stm32/rtc.c index 55977791b8..c7698db143 100644 --- a/ports/stm32/rtc.c +++ b/ports/stm32/rtc.c @@ -837,9 +837,10 @@ STATIC const mp_rom_map_elem_t pyb_rtc_locals_dict_table[] = { }; STATIC MP_DEFINE_CONST_DICT(pyb_rtc_locals_dict, pyb_rtc_locals_dict_table); -const mp_obj_type_t pyb_rtc_type = { - { &mp_type_type }, - .name = MP_QSTR_RTC, - .make_new = pyb_rtc_make_new, - .locals_dict = (mp_obj_dict_t *)&pyb_rtc_locals_dict, -}; +MP_DEFINE_CONST_OBJ_TYPE( + pyb_rtc_type, + MP_QSTR_RTC, + MP_TYPE_FLAG_NONE, + pyb_rtc_make_new, + locals_dict, (mp_obj_dict_t *)&pyb_rtc_locals_dict + ); diff --git a/ports/stm32/sdcard.c b/ports/stm32/sdcard.c index 6f5892570b..b9cc051e7f 100644 --- a/ports/stm32/sdcard.c +++ b/ports/stm32/sdcard.c @@ -872,21 +872,23 @@ STATIC const mp_rom_map_elem_t pyb_sdcard_locals_dict_table[] = { STATIC MP_DEFINE_CONST_DICT(pyb_sdcard_locals_dict, pyb_sdcard_locals_dict_table); #if MICROPY_HW_ENABLE_SDCARD -const mp_obj_type_t pyb_sdcard_type = { - { &mp_type_type }, - .name = MP_QSTR_SDCard, - .make_new = pyb_sdcard_make_new, - .locals_dict = (mp_obj_dict_t *)&pyb_sdcard_locals_dict, -}; +MP_DEFINE_CONST_OBJ_TYPE( + pyb_sdcard_type, + MP_QSTR_SDCard, + MP_TYPE_FLAG_NONE, + pyb_sdcard_make_new, + locals_dict, (mp_obj_dict_t *)&pyb_sdcard_locals_dict + ); #endif #if MICROPY_HW_ENABLE_MMCARD -const mp_obj_type_t pyb_mmcard_type = { - { &mp_type_type }, - .name = MP_QSTR_MMCard, - .make_new = pyb_mmcard_make_new, - .locals_dict = (mp_obj_dict_t *)&pyb_sdcard_locals_dict, -}; +MP_DEFINE_CONST_OBJ_TYPE( + pyb_mmcard_type, + MP_QSTR_MMCard, + MP_TYPE_FLAG_NONE, + pyb_mmcard_make_new, + locals_dict, (mp_obj_dict_t *)&pyb_sdcard_locals_dict + ); #endif void sdcard_init_vfs(fs_user_mount_t *vfs, int part) { diff --git a/ports/stm32/servo.c b/ports/stm32/servo.c index 1708422463..d552f5e6b5 100644 --- a/ports/stm32/servo.c +++ b/ports/stm32/servo.c @@ -336,12 +336,13 @@ STATIC const mp_rom_map_elem_t pyb_servo_locals_dict_table[] = { STATIC MP_DEFINE_CONST_DICT(pyb_servo_locals_dict, pyb_servo_locals_dict_table); -const mp_obj_type_t pyb_servo_type = { - { &mp_type_type }, - .name = MP_QSTR_Servo, - .print = pyb_servo_print, - .make_new = pyb_servo_make_new, - .locals_dict = (mp_obj_dict_t *)&pyb_servo_locals_dict, -}; +MP_DEFINE_CONST_OBJ_TYPE( + pyb_servo_type, + MP_QSTR_Servo, + MP_TYPE_FLAG_NONE, + pyb_servo_make_new, + print, pyb_servo_print, + locals_dict, (mp_obj_dict_t *)&pyb_servo_locals_dict + ); #endif // MICROPY_HW_ENABLE_SERVO diff --git a/ports/stm32/storage.c b/ports/stm32/storage.c index c33a75f671..92f7059493 100644 --- a/ports/stm32/storage.c +++ b/ports/stm32/storage.c @@ -453,13 +453,14 @@ STATIC const mp_rom_map_elem_t pyb_flash_locals_dict_table[] = { STATIC MP_DEFINE_CONST_DICT(pyb_flash_locals_dict, pyb_flash_locals_dict_table); -const mp_obj_type_t pyb_flash_type = { - { &mp_type_type }, - .name = MP_QSTR_Flash, - .print = pyb_flash_print, - .make_new = pyb_flash_make_new, - .locals_dict = (mp_obj_dict_t *)&pyb_flash_locals_dict, -}; +MP_DEFINE_CONST_OBJ_TYPE( + pyb_flash_type, + MP_QSTR_Flash, + MP_TYPE_FLAG_NONE, + pyb_flash_make_new, + print, pyb_flash_print, + locals_dict, (mp_obj_dict_t *)&pyb_flash_locals_dict + ); void pyb_flash_init_vfs(fs_user_mount_t *vfs) { vfs->base.type = &mp_fat_vfs_type; diff --git a/ports/stm32/timer.c b/ports/stm32/timer.c index 518a2e23b4..abf4c1f3fc 100644 --- a/ports/stm32/timer.c +++ b/ports/stm32/timer.c @@ -1471,13 +1471,14 @@ STATIC const mp_rom_map_elem_t pyb_timer_locals_dict_table[] = { }; STATIC MP_DEFINE_CONST_DICT(pyb_timer_locals_dict, pyb_timer_locals_dict_table); -const mp_obj_type_t pyb_timer_type = { - { &mp_type_type }, - .name = MP_QSTR_Timer, - .print = pyb_timer_print, - .make_new = pyb_timer_make_new, - .locals_dict = (mp_obj_dict_t *)&pyb_timer_locals_dict, -}; +MP_DEFINE_CONST_OBJ_TYPE( + pyb_timer_type, + MP_QSTR_Timer, + MP_TYPE_FLAG_NONE, + pyb_timer_make_new, + print, pyb_timer_print, + locals_dict, (mp_obj_dict_t *)&pyb_timer_locals_dict + ); /// \moduleref pyb /// \class TimerChannel - setup a channel for a timer. @@ -1610,12 +1611,14 @@ STATIC const mp_rom_map_elem_t pyb_timer_channel_locals_dict_table[] = { }; STATIC MP_DEFINE_CONST_DICT(pyb_timer_channel_locals_dict, pyb_timer_channel_locals_dict_table); -STATIC const mp_obj_type_t pyb_timer_channel_type = { - { &mp_type_type }, - .name = MP_QSTR_TimerChannel, - .print = pyb_timer_channel_print, - .locals_dict = (mp_obj_dict_t *)&pyb_timer_channel_locals_dict, -}; +STATIC MP_DEFINE_CONST_OBJ_TYPE( + pyb_timer_channel_type, + MP_QSTR_TimerChannel, + MP_TYPE_FLAG_NONE, + MP_TYPE_NULL_MAKE_NEW, + print, pyb_timer_channel_print, + locals_dict, (mp_obj_dict_t *)&pyb_timer_channel_locals_dict + ); STATIC void timer_handle_irq_channel(pyb_timer_obj_t *tim, uint8_t channel, mp_obj_t callback) { uint32_t irq_mask = TIMER_IRQ_MASK(channel); diff --git a/ports/stm32/usb.c b/ports/stm32/usb.c index c5fdd88acf..7c36765c28 100644 --- a/ports/stm32/usb.c +++ b/ports/stm32/usb.c @@ -936,16 +936,17 @@ STATIC const mp_stream_p_t pyb_usb_vcp_stream_p = { .ioctl = pyb_usb_vcp_ioctl, }; -const mp_obj_type_t pyb_usb_vcp_type = { - { &mp_type_type }, - .name = MP_QSTR_USB_VCP, - .print = pyb_usb_vcp_print, - .make_new = pyb_usb_vcp_make_new, - .getiter = mp_identity_getiter, - .iternext = mp_stream_unbuffered_iter, - .protocol = &pyb_usb_vcp_stream_p, - .locals_dict = (mp_obj_dict_t *)&pyb_usb_vcp_locals_dict, -}; +MP_DEFINE_CONST_OBJ_TYPE( + pyb_usb_vcp_type, + MP_QSTR_USB_VCP, + MP_TYPE_FLAG_NONE, + pyb_usb_vcp_make_new, + print, pyb_usb_vcp_print, + getiter, mp_identity_getiter, + iternext, mp_stream_unbuffered_iter, + protocol, &pyb_usb_vcp_stream_p, + locals_dict, (mp_obj_dict_t *)&pyb_usb_vcp_locals_dict + ); /******************************************************************************/ // MicroPython bindings for USB HID @@ -1077,13 +1078,14 @@ STATIC const mp_stream_p_t pyb_usb_hid_stream_p = { .ioctl = pyb_usb_hid_ioctl, }; -const mp_obj_type_t pyb_usb_hid_type = { - { &mp_type_type }, - .name = MP_QSTR_USB_HID, - .make_new = pyb_usb_hid_make_new, - .protocol = &pyb_usb_hid_stream_p, - .locals_dict = (mp_obj_dict_t *)&pyb_usb_hid_locals_dict, -}; +MP_DEFINE_CONST_OBJ_TYPE( + pyb_usb_hid_type, + MP_QSTR_USB_HID, + MP_TYPE_FLAG_NONE, + pyb_usb_hid_make_new, + protocol, &pyb_usb_hid_stream_p, + locals_dict, (mp_obj_dict_t *)&pyb_usb_hid_locals_dict + ); #endif // MICROPY_HW_USB_HID diff --git a/ports/stm32/usrsw.c b/ports/stm32/usrsw.c index 60aae1c883..137f4dabfa 100644 --- a/ports/stm32/usrsw.c +++ b/ports/stm32/usrsw.c @@ -134,14 +134,15 @@ STATIC const mp_rom_map_elem_t pyb_switch_locals_dict_table[] = { STATIC MP_DEFINE_CONST_DICT(pyb_switch_locals_dict, pyb_switch_locals_dict_table); -const mp_obj_type_t pyb_switch_type = { - { &mp_type_type }, - .name = MP_QSTR_Switch, - .print = pyb_switch_print, - .make_new = pyb_switch_make_new, - .call = pyb_switch_call, - .locals_dict = (mp_obj_dict_t *)&pyb_switch_locals_dict, -}; +MP_DEFINE_CONST_OBJ_TYPE( + pyb_switch_type, + MP_QSTR_Switch, + MP_TYPE_FLAG_NONE, + pyb_switch_make_new, + print, pyb_switch_print, + call, pyb_switch_call, + locals_dict, (mp_obj_dict_t *)&pyb_switch_locals_dict + ); MP_REGISTER_ROOT_POINTER(mp_obj_t pyb_switch_callback); diff --git a/ports/stm32/wdt.c b/ports/stm32/wdt.c index d794607bc0..e3b8e2e0ae 100644 --- a/ports/stm32/wdt.c +++ b/ports/stm32/wdt.c @@ -102,9 +102,10 @@ STATIC const mp_rom_map_elem_t pyb_wdt_locals_dict_table[] = { STATIC MP_DEFINE_CONST_DICT(pyb_wdt_locals_dict, pyb_wdt_locals_dict_table); -const mp_obj_type_t pyb_wdt_type = { - { &mp_type_type }, - .name = MP_QSTR_WDT, - .make_new = pyb_wdt_make_new, - .locals_dict = (mp_obj_dict_t *)&pyb_wdt_locals_dict, -}; +MP_DEFINE_CONST_OBJ_TYPE( + pyb_wdt_type, + MP_QSTR_WDT, + MP_TYPE_FLAG_NONE, + pyb_wdt_make_new, + locals_dict, (mp_obj_dict_t *)&pyb_wdt_locals_dict + ); diff --git a/ports/teensy/led.c b/ports/teensy/led.c index d79e63cf71..ca548431fe 100644 --- a/ports/teensy/led.c +++ b/ports/teensy/led.c @@ -134,10 +134,11 @@ STATIC const mp_rom_map_elem_t led_locals_dict_table[] = { STATIC MP_DEFINE_CONST_DICT(led_locals_dict, led_locals_dict_table); -const mp_obj_type_t pyb_led_type = { - { &mp_type_type }, - .name = MP_QSTR_LED, - .print = led_obj_print, - .make_new = led_obj_make_new, - .locals_dict = (mp_obj_t)&led_locals_dict, -}; +MP_DEFINE_CONST_OBJ_TYPE( + pyb_led_type, + MP_QSTR_LED, + MP_TYPE_FLAG_NONE, + led_obj_make_new, + print, led_obj_print, + locals_dict, (mp_obj_t)&led_locals_dict + ); diff --git a/ports/teensy/timer.c b/ports/teensy/timer.c index 68dc965eb8..4df2474335 100644 --- a/ports/teensy/timer.c +++ b/ports/teensy/timer.c @@ -746,13 +746,14 @@ STATIC const mp_rom_map_elem_t pyb_timer_locals_dict_table[] = { }; STATIC MP_DEFINE_CONST_DICT(pyb_timer_locals_dict, pyb_timer_locals_dict_table); -const mp_obj_type_t pyb_timer_type = { - { &mp_type_type }, - .name = MP_QSTR_Timer, - .print = pyb_timer_print, - .make_new = pyb_timer_make_new, - .locals_dict = (mp_obj_t)&pyb_timer_locals_dict, -}; +MP_DEFINE_CONST_OBJ_TYPE( + pyb_timer_type, + MP_QSTR_Timer, + MP_TYPE_FLAG_NONE, + pyb_timer_make_new, + print, pyb_timer_print, + locals_dict, (mp_obj_t)&pyb_timer_locals_dict + ); /// \moduleref pyb /// \class TimerChannel - setup a channel for a timer. @@ -889,12 +890,14 @@ STATIC const mp_rom_map_elem_t pyb_timer_channel_locals_dict_table[] = { }; STATIC MP_DEFINE_CONST_DICT(pyb_timer_channel_locals_dict, pyb_timer_channel_locals_dict_table); -STATIC const mp_obj_type_t pyb_timer_channel_type = { - { &mp_type_type }, - .name = MP_QSTR_TimerChannel, - .print = pyb_timer_channel_print, - .locals_dict = (mp_obj_t)&pyb_timer_channel_locals_dict, -}; +STATIC MP_DEFINE_CONST_OBJ_TYPE( + pyb_timer_channel_type, + MP_QSTR_TimerChannel, + MP_TYPE_FLAG_NONE, + MP_TYPE_NULL_MAKE_NEW, + print, pyb_timer_channel_print, + locals_dict, (mp_obj_t)&pyb_timer_channel_locals_dict + ); STATIC bool ftm_handle_irq_callback(pyb_timer_obj_t *self, mp_uint_t channel, mp_obj_t callback) { // execute callback if it's set diff --git a/ports/teensy/uart.c b/ports/teensy/uart.c index 5b63fcb3cd..8957d92709 100644 --- a/ports/teensy/uart.c +++ b/ports/teensy/uart.c @@ -483,10 +483,11 @@ STATIC const mp_rom_map_elem_t pyb_uart_locals_dict_table[] = { STATIC MP_DEFINE_CONST_DICT(pyb_uart_locals_dict, pyb_uart_locals_dict_table); -const mp_obj_type_t pyb_uart_type = { - { &mp_type_type }, - .name = MP_QSTR_UART, - .print = pyb_uart_print, - .make_new = pyb_uart_make_new, - .locals_dict = (mp_obj_t)&pyb_uart_locals_dict, -}; +MP_DEFINE_CONST_OBJ_TYPE( + pyb_uart_type, + MP_QSTR_UART, + MP_TYPE_FLAG_NONE, + pyb_uart_make_new, + print, pyb_uart_print, + locals_dict, (mp_obj_t)&pyb_uart_locals_dict + ); diff --git a/ports/unix/coverage.c b/ports/unix/coverage.c index cf425ac433..b4567417a2 100644 --- a/ports/unix/coverage.c +++ b/ports/unix/coverage.c @@ -106,11 +106,14 @@ STATIC const mp_stream_p_t fileio_stream_p = { .ioctl = stest_ioctl, }; -STATIC const mp_obj_type_t mp_type_stest_fileio = { - { &mp_type_type }, - .protocol = &fileio_stream_p, - .locals_dict = (mp_obj_dict_t *)&rawfile_locals_dict, -}; +STATIC MP_DEFINE_CONST_OBJ_TYPE( + mp_type_stest_fileio, + MP_QSTR_stest_fileio, + MP_TYPE_FLAG_NONE, + MP_TYPE_NULL_MAKE_NEW, + protocol, &fileio_stream_p, + locals_dict, (mp_obj_dict_t *)&rawfile_locals_dict + ); // stream read returns non-blocking error STATIC mp_uint_t stest_read2(mp_obj_t o_in, void *buf, mp_uint_t size, int *errcode) { @@ -133,11 +136,14 @@ STATIC const mp_stream_p_t textio_stream_p2 = { .is_text = true, }; -STATIC const mp_obj_type_t mp_type_stest_textio2 = { - { &mp_type_type }, - .protocol = &textio_stream_p2, - .locals_dict = (mp_obj_dict_t *)&rawfile_locals_dict2, -}; +STATIC MP_DEFINE_CONST_OBJ_TYPE( + mp_type_stest_textio2, + MP_QSTR_stest_textio2, + MP_TYPE_FLAG_NONE, + MP_TYPE_NULL_MAKE_NEW, + protocol, &textio_stream_p2, + locals_dict, (mp_obj_dict_t *)&rawfile_locals_dict2 + ); // str/bytes objects without a valid hash STATIC const mp_obj_str_t str_no_hash_obj = {{&mp_type_str}, 0, 10, (const byte *)"0123456789"}; diff --git a/ports/unix/modffi.c b/ports/unix/modffi.c index 6417b5d3b3..98f0a1aa0f 100644 --- a/ports/unix/modffi.c +++ b/ports/unix/modffi.c @@ -421,13 +421,14 @@ STATIC const mp_rom_map_elem_t ffimod_locals_dict_table[] = { STATIC MP_DEFINE_CONST_DICT(ffimod_locals_dict, ffimod_locals_dict_table); -STATIC const mp_obj_type_t ffimod_type = { - { &mp_type_type }, - .name = MP_QSTR_ffimod, - .print = ffimod_print, - .make_new = ffimod_make_new, - .locals_dict = (mp_obj_dict_t *)&ffimod_locals_dict, -}; +STATIC MP_DEFINE_CONST_OBJ_TYPE( + ffimod_type, + MP_QSTR_ffimod, + MP_TYPE_FLAG_NONE, + ffimod_make_new, + print, ffimod_print, + locals_dict, (mp_obj_dict_t *)&ffimod_locals_dict + ); // FFI function @@ -530,12 +531,14 @@ error: mp_raise_TypeError(MP_ERROR_TEXT("don't know how to pass object to native function")); } -STATIC const mp_obj_type_t ffifunc_type = { - { &mp_type_type }, - .name = MP_QSTR_ffifunc, - .print = ffifunc_print, - .call = ffifunc_call, -}; +STATIC MP_DEFINE_CONST_OBJ_TYPE( + ffifunc_type, + MP_QSTR_ffifunc, + MP_TYPE_FLAG_NONE, + MP_TYPE_NULL_MAKE_NEW, + print, ffifunc_print, + call, ffifunc_call + ); // FFI callback for Python function @@ -556,12 +559,14 @@ STATIC const mp_rom_map_elem_t fficallback_locals_dict_table[] = { }; STATIC MP_DEFINE_CONST_DICT(fficallback_locals_dict, fficallback_locals_dict_table); -STATIC const mp_obj_type_t fficallback_type = { - { &mp_type_type }, - .name = MP_QSTR_fficallback, - .print = fficallback_print, - .locals_dict = (mp_obj_dict_t *)&fficallback_locals_dict -}; +STATIC MP_DEFINE_CONST_OBJ_TYPE( + fficallback_type, + MP_QSTR_fficallback, + MP_TYPE_FLAG_NONE, + MP_TYPE_NULL_MAKE_NEW, + print, fficallback_print, + locals_dict, (mp_obj_dict_t *)&fficallback_locals_dict + ); // FFI variable @@ -592,21 +597,25 @@ STATIC const mp_rom_map_elem_t ffivar_locals_dict_table[] = { STATIC MP_DEFINE_CONST_DICT(ffivar_locals_dict, ffivar_locals_dict_table); -STATIC const mp_obj_type_t ffivar_type = { - { &mp_type_type }, - .name = MP_QSTR_ffivar, - .print = ffivar_print, - .locals_dict = (mp_obj_dict_t *)&ffivar_locals_dict, -}; +STATIC MP_DEFINE_CONST_OBJ_TYPE( + ffivar_type, + MP_QSTR_ffivar, + MP_TYPE_FLAG_NONE, + MP_TYPE_NULL_MAKE_NEW, + print, ffivar_print, + locals_dict, (mp_obj_dict_t *)&ffivar_locals_dict + ); // Generic opaque storage object (unused) /* -STATIC const mp_obj_type_t opaque_type = { - { &mp_type_type }, - .name = MP_QSTR_opaqueval, -// .print = opaque_print, -}; +STATIC MP_DEFINE_CONST_OBJ_TYPE( + opaque_type, + MP_QSTR_opaqueval, + MP_TYPE_FLAG_NONE, + MP_TYPE_NULL_MAKE_NEW, + // .print = opaque_print, + ); */ STATIC mp_obj_t mod_ffi_open(size_t n_args, const mp_obj_t *args) { diff --git a/ports/unix/modjni.c b/ports/unix/modjni.c index 6fa00731fb..72f95b645b 100644 --- a/ports/unix/modjni.c +++ b/ports/unix/modjni.c @@ -174,14 +174,16 @@ STATIC const mp_rom_map_elem_t jclass_locals_dict_table[] = { STATIC MP_DEFINE_CONST_DICT(jclass_locals_dict, jclass_locals_dict_table); -STATIC const mp_obj_type_t jclass_type = { - { &mp_type_type }, - .name = MP_QSTR_jclass, - .print = jclass_print, - .attr = jclass_attr, - .call = jclass_call, - .locals_dict = (mp_obj_dict_t *)&jclass_locals_dict, -}; +STATIC MP_DEFINE_CONST_OBJ_TYPE( + jclass_type, + MP_QSTR_jclass, + MP_TYPE_FLAG_NONE, + MP_TYPE_NULL_MAKE_NEW, + print, jclass_print, + attr, jclass_attr, + call, jclass_call, + locals_dict, (mp_obj_dict_t *)&jclass_locals_dict + ); STATIC mp_obj_t new_jclass(jclass jc) { mp_obj_jclass_t *o = mp_obj_malloc(mp_obj_jclass_t, &jclass_type); @@ -320,16 +322,18 @@ STATIC mp_obj_t subscr_getiter(mp_obj_t self_in, mp_obj_iter_buf_t *iter_buf) { return mp_obj_new_getitem_iter(dest, iter_buf); } -STATIC const mp_obj_type_t jobject_type = { - { &mp_type_type }, - .name = MP_QSTR_jobject, - .print = jobject_print, - .unary_op = jobject_unary_op, - .attr = jobject_attr, - .subscr = jobject_subscr, - .getiter = subscr_getiter, -// .locals_dict = (mp_obj_dict_t*)&jobject_locals_dict, -}; +STATIC MP_DEFINE_CONST_OBJ_TYPE( + jobject_type, + MP_QSTR_jobject, + MP_TYPE_FLAG_NONE, + MP_TYPE_NULL_MAKE_NEW, + print, jobject_print, + unary_op, jobject_unary_op, + attr, jobject_attr, + subscr, jobject_subscr, + getiter, subscr_getiter, + // .locals_dict = (mp_obj_dict_t*)&jobject_locals_dict, + ); STATIC mp_obj_t new_jobject(jobject jo) { if (jo == NULL) { @@ -567,14 +571,16 @@ STATIC mp_obj_t jmethod_call(mp_obj_t self_in, size_t n_args, size_t n_kw, const return call_method(self->obj, name, methods, false, n_args, args); } -STATIC const mp_obj_type_t jmethod_type = { - { &mp_type_type }, - .name = MP_QSTR_jmethod, - .print = jmethod_print, - .call = jmethod_call, -// .attr = jobject_attr, -// .locals_dict = (mp_obj_dict_t*)&jobject_locals_dict, -}; +STATIC MP_DEFINE_CONST_OBJ_TYPE( + jmethod_type, + MP_QSTR_jmethod, + MP_TYPE_FLAG_NONE, + MP_TYPE_NULL_MAKE_NEW, + print, jmethod_print, + call, jmethod_call, + // .attr = jobject_attr, + // .locals_dict = (mp_obj_dict_t*)&jobject_locals_dict, + ); #ifdef __ANDROID__ #define LIBJVM_SO "libdvm.so" diff --git a/ports/unix/moduselect.c b/ports/unix/moduselect.c index 2de4a316ed..d8a8d1d8c3 100644 --- a/ports/unix/moduselect.c +++ b/ports/unix/moduselect.c @@ -311,13 +311,15 @@ STATIC const mp_rom_map_elem_t poll_locals_dict_table[] = { }; STATIC MP_DEFINE_CONST_DICT(poll_locals_dict, poll_locals_dict_table); -STATIC const mp_obj_type_t mp_type_poll = { - { &mp_type_type }, - .name = MP_QSTR_poll, - .getiter = mp_identity_getiter, - .iternext = poll_iternext, - .locals_dict = (void *)&poll_locals_dict, -}; +STATIC MP_DEFINE_CONST_OBJ_TYPE( + mp_type_poll, + MP_QSTR_poll, + MP_TYPE_FLAG_NONE, + MP_TYPE_NULL_MAKE_NEW, + getiter, mp_identity_getiter, + iternext, poll_iternext, + locals_dict, (void *)&poll_locals_dict + ); STATIC mp_obj_t select_poll(size_t n_args, const mp_obj_t *args) { int alloc = 4; diff --git a/ports/unix/modusocket.c b/ports/unix/modusocket.c index 72c70d1750..7e4476cbd0 100644 --- a/ports/unix/modusocket.c +++ b/ports/unix/modusocket.c @@ -516,16 +516,17 @@ STATIC const mp_stream_p_t usocket_stream_p = { .ioctl = socket_ioctl, }; -const mp_obj_type_t mp_type_socket = { - { &mp_type_type }, - .name = MP_QSTR_socket, - .print = socket_print, - .make_new = socket_make_new, - .getiter = NULL, - .iternext = NULL, - .protocol = &usocket_stream_p, - .locals_dict = (mp_obj_dict_t *)&usocket_locals_dict, -}; +MP_DEFINE_CONST_OBJ_TYPE( + mp_type_socket, + MP_QSTR_socket, + MP_TYPE_FLAG_NONE, + socket_make_new, + print, socket_print, + getiter, NULL, + iternext, NULL, + protocol, &usocket_stream_p, + locals_dict, (mp_obj_dict_t *)&usocket_locals_dict + ); #define BINADDR_MAX_LEN sizeof(struct in6_addr) STATIC mp_obj_t mod_socket_inet_pton(mp_obj_t family_in, mp_obj_t addr_in) { diff --git a/ports/zephyr/machine_i2c.c b/ports/zephyr/machine_i2c.c index 9bb63229dd..60a1924d80 100644 --- a/ports/zephyr/machine_i2c.c +++ b/ports/zephyr/machine_i2c.c @@ -126,13 +126,14 @@ STATIC const mp_machine_i2c_p_t machine_hard_i2c_p = { .transfer_single = machine_hard_i2c_transfer_single, }; -const mp_obj_type_t machine_hard_i2c_type = { - { &mp_type_type }, - .name = MP_QSTR_I2C, - .print = machine_hard_i2c_print, - .make_new = machine_hard_i2c_make_new, - .protocol = &machine_hard_i2c_p, - .locals_dict = (mp_obj_dict_t *)&mp_machine_i2c_locals_dict, -}; +MP_DEFINE_CONST_OBJ_TYPE( + machine_hard_i2c_type, + MP_QSTR_I2C, + MP_TYPE_FLAG_NONE, + machine_hard_i2c_make_new, + print, machine_hard_i2c_print, + protocol, &machine_hard_i2c_p, + locals_dict, (mp_obj_dict_t *)&mp_machine_i2c_locals_dict + ); #endif // MICROPY_PY_MACHINE_I2C diff --git a/ports/zephyr/machine_pin.c b/ports/zephyr/machine_pin.c index aa55c04104..48303edd81 100644 --- a/ports/zephyr/machine_pin.c +++ b/ports/zephyr/machine_pin.c @@ -285,15 +285,16 @@ STATIC const mp_pin_p_t machine_pin_pin_p = { .ioctl = machine_pin_ioctl, }; -const mp_obj_type_t machine_pin_type = { - { &mp_type_type }, - .name = MP_QSTR_Pin, - .print = machine_pin_print, - .make_new = mp_pin_make_new, - .call = machine_pin_call, - .protocol = &machine_pin_pin_p, - .locals_dict = (mp_obj_t)&machine_pin_locals_dict, -}; +MP_DEFINE_CONST_OBJ_TYPE( + machine_pin_type, + MP_QSTR_Pin, + MP_TYPE_FLAG_NONE, + mp_pin_make_new, + print, machine_pin_print, + call, machine_pin_call, + protocol, &machine_pin_pin_p, + locals_dict, (mp_obj_t)&machine_pin_locals_dict + ); STATIC mp_uint_t machine_pin_irq_trigger(mp_obj_t self_in, mp_uint_t new_trigger) { machine_pin_obj_t *self = MP_OBJ_TO_PTR(self_in); diff --git a/ports/zephyr/machine_spi.c b/ports/zephyr/machine_spi.c index 2b0911c591..6d9bf896b0 100644 --- a/ports/zephyr/machine_spi.c +++ b/ports/zephyr/machine_spi.c @@ -197,13 +197,14 @@ STATIC const mp_machine_spi_p_t machine_hard_spi_p = { .transfer = machine_hard_spi_transfer, }; -const mp_obj_type_t machine_hard_spi_type = { - { &mp_type_type }, - .name = MP_QSTR_SPI, - .print = machine_hard_spi_print, - .make_new = machine_hard_spi_make_new, - .protocol = &machine_hard_spi_p, - .locals_dict = (mp_obj_dict_t *)&mp_machine_spi_locals_dict, -}; +MP_DEFINE_CONST_OBJ_TYPE( + machine_hard_spi_type, + MP_QSTR_SPI, + MP_TYPE_FLAG_NONE, + machine_hard_spi_make_new, + print, machine_hard_spi_print, + protocol, &machine_hard_spi_p, + locals_dict, (mp_obj_dict_t *)&mp_machine_spi_locals_dict + ); #endif // MICROPY_PY_MACHINE_SPI diff --git a/ports/zephyr/machine_uart.c b/ports/zephyr/machine_uart.c index 3520795c5a..3f5df74657 100644 --- a/ports/zephyr/machine_uart.c +++ b/ports/zephyr/machine_uart.c @@ -154,13 +154,14 @@ STATIC const mp_stream_p_t uart_stream_p = { .is_text = false, }; -const mp_obj_type_t machine_uart_type = { - { &mp_type_type }, - .name = MP_QSTR_UART, - .print = machine_uart_print, - .make_new = machine_uart_make_new, - .getiter = mp_identity_getiter, - .iternext = mp_stream_unbuffered_iter, - .protocol = &uart_stream_p, - .locals_dict = (mp_obj_dict_t *)&machine_uart_locals_dict, -}; +MP_DEFINE_CONST_OBJ_TYPE( + machine_uart_type, + MP_QSTR_UART, + MP_TYPE_FLAG_NONE, + machine_uart_make_new, + print, machine_uart_print, + getiter, mp_identity_getiter, + iternext, mp_stream_unbuffered_iter, + protocol, &uart_stream_p, + locals_dict, (mp_obj_dict_t *)&machine_uart_locals_dict + ); diff --git a/ports/zephyr/modusocket.c b/ports/zephyr/modusocket.c index 17cf9babd3..a7bef74ca6 100644 --- a/ports/zephyr/modusocket.c +++ b/ports/zephyr/modusocket.c @@ -353,14 +353,15 @@ STATIC const mp_stream_p_t socket_stream_p = { .ioctl = sock_ioctl, }; -STATIC const mp_obj_type_t socket_type = { - { &mp_type_type }, - .name = MP_QSTR_socket, - .print = socket_print, - .make_new = socket_make_new, - .protocol = &socket_stream_p, - .locals_dict = (mp_obj_t)&socket_locals_dict, -}; +STATIC MP_DEFINE_CONST_OBJ_TYPE( + socket_type, + MP_QSTR_socket, + MP_TYPE_FLAG_NONE, + socket_make_new, + print, socket_print, + protocol, &socket_stream_p, + locals_dict, (mp_obj_t)&socket_locals_dict + ); // // getaddrinfo() implementation diff --git a/ports/zephyr/modzsensor.c b/ports/zephyr/modzsensor.c index ba6717046f..7c0b0193d3 100644 --- a/ports/zephyr/modzsensor.c +++ b/ports/zephyr/modzsensor.c @@ -105,12 +105,13 @@ STATIC const mp_rom_map_elem_t sensor_locals_dict_table[] = { STATIC MP_DEFINE_CONST_DICT(sensor_locals_dict, sensor_locals_dict_table); -STATIC const mp_obj_type_t sensor_type = { - { &mp_type_type }, - .name = MP_QSTR_Sensor, - .make_new = sensor_make_new, - .locals_dict = (void *)&sensor_locals_dict, -}; +STATIC MP_DEFINE_CONST_OBJ_TYPE( + sensor_type, + MP_QSTR_Sensor, + MP_TYPE_FLAG_NONE, + sensor_make_new, + locals_dict, (void *)&sensor_locals_dict + ); STATIC const mp_rom_map_elem_t mp_module_zsensor_globals_table[] = { { MP_ROM_QSTR(MP_QSTR___name__), MP_ROM_QSTR(MP_QSTR_zsensor) }, diff --git a/ports/zephyr/zephyr_storage.c b/ports/zephyr/zephyr_storage.c index 1179c3fda8..ded7caa657 100644 --- a/ports/zephyr/zephyr_storage.c +++ b/ports/zephyr/zephyr_storage.c @@ -128,13 +128,14 @@ STATIC const mp_rom_map_elem_t zephyr_disk_access_locals_dict_table[] = { }; STATIC MP_DEFINE_CONST_DICT(zephyr_disk_access_locals_dict, zephyr_disk_access_locals_dict_table); -const mp_obj_type_t zephyr_disk_access_type = { - { &mp_type_type }, - .name = MP_QSTR_DiskAccess, - .print = zephyr_disk_access_print, - .make_new = zephyr_disk_access_make_new, - .locals_dict = (mp_obj_dict_t *)&zephyr_disk_access_locals_dict, -}; +MP_DEFINE_CONST_OBJ_TYPE( + zephyr_disk_access_type, + MP_QSTR_DiskAccess, + MP_TYPE_FLAG_NONE, + zephyr_disk_access_make_new, + print, zephyr_disk_access_print, + locals_dict, (mp_obj_dict_t *)&zephyr_disk_access_locals_dict + ); #endif // CONFIG_DISK_ACCESS #ifdef CONFIG_FLASH_MAP @@ -249,11 +250,12 @@ STATIC const mp_rom_map_elem_t zephyr_flash_area_locals_dict_table[] = { }; STATIC MP_DEFINE_CONST_DICT(zephyr_flash_area_locals_dict, zephyr_flash_area_locals_dict_table); -const mp_obj_type_t zephyr_flash_area_type = { - { &mp_type_type }, - .name = MP_QSTR_FlashArea, - .print = zephyr_flash_area_print, - .make_new = zephyr_flash_area_make_new, - .locals_dict = (mp_obj_dict_t *)&zephyr_flash_area_locals_dict, -}; +MP_DEFINE_CONST_OBJ_TYPE( + zephyr_flash_area_type, + MP_QSTR_FlashArea, + MP_TYPE_FLAG_NONE, + zephyr_flash_area_make_new, + print, zephyr_flash_area_print, + locals_dict, (mp_obj_dict_t *)&zephyr_flash_area_locals_dict + ); #endif // CONFIG_FLASH_MAP diff --git a/py/builtinevex.c b/py/builtinevex.c index 73b77b40b7..403cd95a9d 100644 --- a/py/builtinevex.c +++ b/py/builtinevex.c @@ -38,10 +38,12 @@ typedef struct _mp_obj_code_t { mp_obj_t module_fun; } mp_obj_code_t; -STATIC const mp_obj_type_t mp_type_code = { - { &mp_type_type }, - .name = MP_QSTR_code, -}; +STATIC MP_DEFINE_CONST_OBJ_TYPE( + mp_type_code, + MP_QSTR_code, + MP_TYPE_FLAG_NONE, + MP_TYPE_NULL_MAKE_NEW + ); STATIC mp_obj_t code_execute(mp_obj_code_t *self, mp_obj_dict_t *globals, mp_obj_dict_t *locals) { // save context and set new context diff --git a/py/modio.c b/py/modio.c index d44c1948ab..093cb1f7e7 100644 --- a/py/modio.c +++ b/py/modio.c @@ -97,12 +97,13 @@ STATIC const mp_stream_p_t iobase_p = { .ioctl = iobase_ioctl, }; -STATIC const mp_obj_type_t mp_type_iobase = { - { &mp_type_type }, - .name = MP_QSTR_IOBase, - .make_new = iobase_make_new, - .protocol = &iobase_p, -}; +STATIC MP_DEFINE_CONST_OBJ_TYPE( + mp_type_iobase, + MP_QSTR_IOBase, + MP_TYPE_FLAG_NONE, + iobase_make_new, + protocol, &iobase_p + ); #endif // MICROPY_PY_IO_IOBASE @@ -191,13 +192,14 @@ STATIC const mp_stream_p_t bufwriter_stream_p = { .write = bufwriter_write, }; -STATIC const mp_obj_type_t mp_type_bufwriter = { - { &mp_type_type }, - .name = MP_QSTR_BufferedWriter, - .make_new = bufwriter_make_new, - .protocol = &bufwriter_stream_p, - .locals_dict = (mp_obj_dict_t *)&bufwriter_locals_dict, -}; +STATIC MP_DEFINE_CONST_OBJ_TYPE( + mp_type_bufwriter, + MP_QSTR_BufferedWriter, + MP_TYPE_FLAG_NONE, + bufwriter_make_new, + protocol, &bufwriter_stream_p, + locals_dict, (mp_obj_dict_t *)&bufwriter_locals_dict + ); #endif // MICROPY_PY_IO_BUFFEREDWRITER STATIC const mp_rom_map_elem_t mp_module_io_globals_table[] = { diff --git a/py/modthread.c b/py/modthread.c index bad94fbf2f..0a15447425 100644 --- a/py/modthread.c +++ b/py/modthread.c @@ -116,11 +116,13 @@ STATIC const mp_rom_map_elem_t thread_lock_locals_dict_table[] = { STATIC MP_DEFINE_CONST_DICT(thread_lock_locals_dict, thread_lock_locals_dict_table); -STATIC const mp_obj_type_t mp_type_thread_lock = { - { &mp_type_type }, - .name = MP_QSTR_lock, - .locals_dict = (mp_obj_dict_t *)&thread_lock_locals_dict, -}; +STATIC MP_DEFINE_CONST_OBJ_TYPE( + mp_type_thread_lock, + MP_QSTR_lock, + MP_TYPE_FLAG_NONE, + MP_TYPE_NULL_MAKE_NEW, + locals_dict, (mp_obj_dict_t *)&thread_lock_locals_dict + ); /****************************************************************/ // _thread module diff --git a/py/objarray.c b/py/objarray.c index dca41c2931..d93cce29ee 100644 --- a/py/objarray.c +++ b/py/objarray.c @@ -571,54 +571,55 @@ STATIC mp_int_t array_get_buffer(mp_obj_t o_in, mp_buffer_info_t *bufinfo, mp_ui } #if MICROPY_PY_ARRAY -const mp_obj_type_t mp_type_array = { - { &mp_type_type }, - .name = MP_QSTR_array, - .print = array_print, - .make_new = array_make_new, - .getiter = array_iterator_new, - .unary_op = array_unary_op, - .binary_op = array_binary_op, - .subscr = array_subscr, - .buffer_p = array_get_buffer, - .locals_dict = (mp_obj_dict_t *)&mp_obj_array_locals_dict, -}; +MP_DEFINE_CONST_OBJ_TYPE( + mp_type_array, + MP_QSTR_array, + MP_TYPE_FLAG_NONE, + array_make_new, + print, array_print, + getiter, array_iterator_new, + unary_op, array_unary_op, + binary_op, array_binary_op, + subscr, array_subscr, + buffer, array_get_buffer, + locals_dict, (mp_obj_dict_t *)&mp_obj_array_locals_dict + ); #endif #if MICROPY_PY_BUILTINS_BYTEARRAY -const mp_obj_type_t mp_type_bytearray = { - { &mp_type_type }, - .flags = MP_TYPE_FLAG_EQ_CHECKS_OTHER_TYPE, - .name = MP_QSTR_bytearray, - .print = array_print, - .make_new = bytearray_make_new, - .getiter = array_iterator_new, - .unary_op = array_unary_op, - .binary_op = array_binary_op, - .subscr = array_subscr, - .buffer = array_get_buffer, - .locals_dict = (mp_obj_dict_t *)&mp_obj_bytearray_locals_dict, -}; +MP_DEFINE_CONST_OBJ_TYPE( + mp_type_bytearray, + MP_QSTR_bytearray, + MP_TYPE_FLAG_EQ_CHECKS_OTHER_TYPE, + bytearray_make_new, + print, array_print, + getiter, array_iterator_new, + unary_op, array_unary_op, + binary_op, array_binary_op, + subscr, array_subscr, + buffer, array_get_buffer, + locals_dict, (mp_obj_dict_t *)&mp_obj_bytearray_locals_dict + ); #endif #if MICROPY_PY_BUILTINS_MEMORYVIEW -const mp_obj_type_t mp_type_memoryview = { - { &mp_type_type }, - .flags = MP_TYPE_FLAG_EQ_CHECKS_OTHER_TYPE, - .name = MP_QSTR_memoryview, - .make_new = memoryview_make_new, - .getiter = array_iterator_new, - .unary_op = array_unary_op, - .binary_op = array_binary_op, +MP_DEFINE_CONST_OBJ_TYPE( + mp_type_memoryview, + MP_QSTR_memoryview, + MP_TYPE_FLAG_EQ_CHECKS_OTHER_TYPE, + memoryview_make_new, + getiter, array_iterator_new, + unary_op, array_unary_op, + binary_op, array_binary_op, #if MICROPY_PY_BUILTINS_MEMORYVIEW_ITEMSIZE - .attr = memoryview_attr, + attr, memoryview_attr, #endif #if MICROPY_PY_BUILTINS_BYTES_HEX - .locals_dict = (mp_obj_dict_t *)&mp_obj_memoryview_locals_dict, + locals_dict, (mp_obj_dict_t *)&mp_obj_memoryview_locals_dict, #endif .subscr = array_subscr, .buffer = array_get_buffer, -}; + ); #endif /* unused @@ -664,12 +665,14 @@ STATIC mp_obj_t array_it_iternext(mp_obj_t self_in) { } } -STATIC const mp_obj_type_t mp_type_array_it = { - { &mp_type_type }, - .name = MP_QSTR_iterator, - .getiter = mp_identity_getiter, - .iternext = array_it_iternext, -}; +STATIC MP_DEFINE_CONST_OBJ_TYPE( + mp_type_array_it, + MP_QSTR_iterator, + MP_TYPE_FLAG_NONE, + MP_TYPE_NULL_MAKE_NEW, + getiter, mp_identity_getiter, + iternext, array_it_iternext + ); STATIC mp_obj_t array_iterator_new(mp_obj_t array_in, mp_obj_iter_buf_t *iter_buf) { assert(sizeof(mp_obj_array_t) <= sizeof(mp_obj_iter_buf_t)); diff --git a/py/objattrtuple.c b/py/objattrtuple.c index 13c281aa1c..0d41ee5235 100644 --- a/py/objattrtuple.c +++ b/py/objattrtuple.c @@ -80,15 +80,18 @@ mp_obj_t mp_obj_new_attrtuple(const qstr *fields, size_t n, const mp_obj_t *item return MP_OBJ_FROM_PTR(o); } -const mp_obj_type_t mp_type_attrtuple = { - { &mp_type_type }, - .name = MP_QSTR_tuple, // reuse tuple to save on a qstr - .print = mp_obj_attrtuple_print, - .unary_op = mp_obj_tuple_unary_op, - .binary_op = mp_obj_tuple_binary_op, - .attr = mp_obj_attrtuple_attr, - .subscr = mp_obj_tuple_subscr, - .getiter = mp_obj_tuple_getiter, -}; +MP_DEFINE_CONST_OBJ_TYPE( + mp_type_attrtuple, + MP_QSTR_tuple, + MP_TYPE_FLAG_NONE, + MP_TYPE_NULL_MAKE_NEW, + // reuse tuple to save on a qstr + print, mp_obj_attrtuple_print, + unary_op, mp_obj_tuple_unary_op, + binary_op, mp_obj_tuple_binary_op, + attr, mp_obj_attrtuple_attr, + subscr, mp_obj_tuple_subscr, + getiter, mp_obj_tuple_getiter + ); #endif // MICROPY_PY_ATTRTUPLE diff --git a/py/objbool.c b/py/objbool.c index 23e023d8cb..5d014bbb8e 100644 --- a/py/objbool.c +++ b/py/objbool.c @@ -84,15 +84,16 @@ STATIC mp_obj_t bool_binary_op(mp_binary_op_t op, mp_obj_t lhs_in, mp_obj_t rhs_ return mp_binary_op(op, MP_OBJ_NEW_SMALL_INT(value), rhs_in); } -const mp_obj_type_t mp_type_bool = { - { &mp_type_type }, - .flags = MP_TYPE_FLAG_EQ_CHECKS_OTHER_TYPE, // can match all numeric types - .name = MP_QSTR_bool, - .print = bool_print, - .make_new = bool_make_new, - .unary_op = bool_unary_op, - .binary_op = bool_binary_op, -}; +MP_DEFINE_CONST_OBJ_TYPE( + // can match all numeric types + mp_type_bool, + MP_QSTR_bool, + MP_TYPE_FLAG_EQ_CHECKS_OTHER_TYPE, + bool_make_new, + print, bool_print, + unary_op, bool_unary_op, + binary_op, bool_binary_op + ); #if !MICROPY_OBJ_IMMEDIATE_OBJS const mp_obj_bool_t mp_const_false_obj = {{&mp_type_bool}, false}; diff --git a/py/objboundmeth.c b/py/objboundmeth.c index 9936c06e49..353364cdc7 100644 --- a/py/objboundmeth.c +++ b/py/objboundmeth.c @@ -95,17 +95,19 @@ STATIC void bound_meth_attr(mp_obj_t self_in, qstr attr, mp_obj_t *dest) { } #endif -STATIC const mp_obj_type_t mp_type_bound_meth = { - { &mp_type_type }, - .name = MP_QSTR_bound_method, +STATIC MP_DEFINE_CONST_OBJ_TYPE( + mp_type_bound_meth, + MP_QSTR_bound_method, + MP_TYPE_FLAG_NONE, + MP_TYPE_NULL_MAKE_NEW, #if MICROPY_ERROR_REPORTING == MICROPY_ERROR_REPORTING_DETAILED - .print = bound_meth_print, + print, bound_meth_print, #endif - .call = bound_meth_call, + call, bound_meth_call #if MICROPY_PY_FUNCTION_ATTRS - .attr = bound_meth_attr, + , attr, bound_meth_attr #endif -}; + ); mp_obj_t mp_obj_new_bound_meth(mp_obj_t meth, mp_obj_t self) { mp_obj_bound_meth_t *o = mp_obj_malloc(mp_obj_bound_meth_t, &mp_type_bound_meth); diff --git a/py/objcell.c b/py/objcell.c index cab0d0b030..a17a94b9b7 100644 --- a/py/objcell.c +++ b/py/objcell.c @@ -40,13 +40,13 @@ STATIC void cell_print(const mp_print_t *print, mp_obj_t o_in, mp_print_kind_t k } #endif -STATIC const mp_obj_type_t mp_type_cell = { - { &mp_type_type }, - .name = MP_QSTR_, // cell representation is just value in < > +STATIC MP_DEFINE_CONST_OBJ_TYPE( + // cell representation is just value in < > + mp_type_cell, MP_QSTR_, MP_TYPE_FLAG_NONE, MP_TYPE_NULL_MAKE_NEW #if MICROPY_ERROR_REPORTING == MICROPY_ERROR_REPORTING_DETAILED - .print = cell_print, + , print, cell_print #endif -}; + ); mp_obj_t mp_obj_new_cell(mp_obj_t obj) { mp_obj_cell_t *o = mp_obj_malloc(mp_obj_cell_t, &mp_type_cell); diff --git a/py/objclosure.c b/py/objclosure.c index 5b9923a44b..15ed994d37 100644 --- a/py/objclosure.c +++ b/py/objclosure.c @@ -86,18 +86,19 @@ STATIC void mp_obj_closure_attr(mp_obj_t self_in, qstr attr, mp_obj_t *dest) { } #endif -const mp_obj_type_t mp_type_closure = { - { &mp_type_type }, - .flags = MP_TYPE_FLAG_BINDS_SELF, - .name = MP_QSTR_closure, +MP_DEFINE_CONST_OBJ_TYPE( + mp_type_closure, + MP_QSTR_closure, + MP_TYPE_FLAG_BINDS_SELF, + MP_TYPE_NULL_MAKE_NEW, #if MICROPY_ERROR_REPORTING == MICROPY_ERROR_REPORTING_DETAILED - .print = closure_print, + print, closure_print, #endif - .call = closure_call, #if MICROPY_PY_FUNCTION_ATTRS - .attr = mp_obj_closure_attr, + attr, mp_obj_closure_attr, #endif -}; + call, closure_call + ); mp_obj_t mp_obj_new_closure(mp_obj_t fun, size_t n_closed_over, const mp_obj_t *closed) { mp_obj_closure_t *o = mp_obj_malloc_var(mp_obj_closure_t, mp_obj_t, n_closed_over, &mp_type_closure); diff --git a/py/objcomplex.c b/py/objcomplex.c index 4aa598a0bc..cf213d718a 100644 --- a/py/objcomplex.c +++ b/py/objcomplex.c @@ -151,16 +151,13 @@ STATIC void complex_attr(mp_obj_t self_in, qstr attr, mp_obj_t *dest) { } } -const mp_obj_type_t mp_type_complex = { - { &mp_type_type }, - .flags = MP_TYPE_FLAG_EQ_NOT_REFLEXIVE | MP_TYPE_FLAG_EQ_CHECKS_OTHER_TYPE, - .name = MP_QSTR_complex, - .print = complex_print, - .make_new = complex_make_new, - .unary_op = complex_unary_op, - .binary_op = complex_binary_op, - .attr = complex_attr, -}; +MP_DEFINE_CONST_OBJ_TYPE( + mp_type_complex, MP_QSTR_complex, MP_TYPE_FLAG_EQ_NOT_REFLEXIVE | MP_TYPE_FLAG_EQ_CHECKS_OTHER_TYPE, complex_make_new, + print, complex_print, + unary_op, complex_unary_op, + binary_op, complex_binary_op, + attr, complex_attr + ); mp_obj_t mp_obj_new_complex(mp_float_t real, mp_float_t imag) { mp_obj_complex_t *o = mp_obj_malloc(mp_obj_complex_t, &mp_type_complex); diff --git a/py/objdeque.c b/py/objdeque.c index b1c59a81e9..22770317ab 100644 --- a/py/objdeque.c +++ b/py/objdeque.c @@ -155,12 +155,13 @@ STATIC const mp_rom_map_elem_t deque_locals_dict_table[] = { STATIC MP_DEFINE_CONST_DICT(deque_locals_dict, deque_locals_dict_table); -const mp_obj_type_t mp_type_deque = { - { &mp_type_type }, - .name = MP_QSTR_deque, - .make_new = deque_make_new, - .unary_op = deque_unary_op, - .locals_dict = (mp_obj_dict_t *)&deque_locals_dict, -}; +MP_DEFINE_CONST_OBJ_TYPE( + mp_type_deque, + MP_QSTR_deque, + MP_TYPE_FLAG_NONE, + deque_make_new, + unary_op, deque_unary_op, + locals_dict, (mp_obj_dict_t *)&deque_locals_dict + ); #endif // MICROPY_PY_COLLECTIONS_DEQUE diff --git a/py/objdict.c b/py/objdict.c index 1d8e9059a1..6e217d5c9a 100644 --- a/py/objdict.c +++ b/py/objdict.c @@ -461,12 +461,14 @@ STATIC mp_obj_t dict_view_it_iternext(mp_obj_t self_in) { } } -STATIC const mp_obj_type_t mp_type_dict_view_it = { - { &mp_type_type }, - .name = MP_QSTR_iterator, - .getiter = mp_identity_getiter, - .iternext = dict_view_it_iternext, -}; +STATIC MP_DEFINE_CONST_OBJ_TYPE( + mp_type_dict_view_it, + MP_QSTR_iterator, + MP_TYPE_FLAG_NONE, + MP_TYPE_NULL_MAKE_NEW, + getiter, mp_identity_getiter, + iternext, dict_view_it_iternext + ); STATIC mp_obj_t dict_view_getiter(mp_obj_t view_in, mp_obj_iter_buf_t *iter_buf) { assert(sizeof(mp_obj_dict_view_it_t) <= sizeof(mp_obj_iter_buf_t)); @@ -512,13 +514,15 @@ STATIC mp_obj_t dict_view_binary_op(mp_binary_op_t op, mp_obj_t lhs_in, mp_obj_t return dict_binary_op(op, o->dict, rhs_in); } -STATIC const mp_obj_type_t mp_type_dict_view = { - { &mp_type_type }, - .name = MP_QSTR_dict_view, - .print = dict_view_print, - .binary_op = dict_view_binary_op, - .getiter = dict_view_getiter, -}; +STATIC MP_DEFINE_CONST_OBJ_TYPE( + mp_type_dict_view, + MP_QSTR_dict_view, + MP_TYPE_FLAG_NONE, + MP_TYPE_NULL_MAKE_NEW, + print, dict_view_print, + binary_op, dict_view_binary_op, + getiter, dict_view_getiter + ); STATIC mp_obj_t mp_obj_new_dict_view(mp_obj_t dict, mp_dict_view_kind_t kind) { mp_obj_dict_view_t *o = mp_obj_malloc(mp_obj_dict_view_t, &mp_type_dict_view); @@ -585,31 +589,33 @@ STATIC const mp_rom_map_elem_t dict_locals_dict_table[] = { STATIC MP_DEFINE_CONST_DICT(dict_locals_dict, dict_locals_dict_table); -const mp_obj_type_t mp_type_dict = { - { &mp_type_type }, - .name = MP_QSTR_dict, - .print = dict_print, - .make_new = mp_obj_dict_make_new, - .unary_op = dict_unary_op, - .binary_op = dict_binary_op, - .subscr = dict_subscr, - .getiter = dict_getiter, - .locals_dict = (mp_obj_dict_t *)&dict_locals_dict, -}; +MP_DEFINE_CONST_OBJ_TYPE( + mp_type_dict, + MP_QSTR_dict, + MP_TYPE_FLAG_NONE, + mp_obj_dict_make_new, + print, dict_print, + unary_op, dict_unary_op, + binary_op, dict_binary_op, + subscr, dict_subscr, + getiter, dict_getiter, + locals_dict, (mp_obj_dict_t *)&dict_locals_dict + ); #if MICROPY_PY_COLLECTIONS_ORDEREDDICT -const mp_obj_type_t mp_type_ordereddict = { - { &mp_type_type }, - .name = MP_QSTR_OrderedDict, - .print = dict_print, - .make_new = mp_obj_dict_make_new, - .unary_op = dict_unary_op, - .binary_op = dict_binary_op, - .subscr = dict_subscr, - .getiter = dict_getiter, - .parent = &mp_type_dict, - .locals_dict = (mp_obj_dict_t *)&dict_locals_dict, -}; +MP_DEFINE_CONST_OBJ_TYPE( + mp_type_ordereddict, + MP_QSTR_OrderedDict, + MP_TYPE_FLAG_NONE, + mp_obj_dict_make_new, + print, dict_print, + unary_op, dict_unary_op, + binary_op, dict_binary_op, + subscr, dict_subscr, + getiter, dict_getiter, + parent, &mp_type_dict, + locals_dict, (mp_obj_dict_t *)&dict_locals_dict + ); #endif void mp_obj_dict_init(mp_obj_dict_t *dict, size_t n_args) { diff --git a/py/objenumerate.c b/py/objenumerate.c index 241aef3023..f4f4ff6ae1 100644 --- a/py/objenumerate.c +++ b/py/objenumerate.c @@ -67,13 +67,14 @@ STATIC mp_obj_t enumerate_make_new(const mp_obj_type_t *type, size_t n_args, siz return MP_OBJ_FROM_PTR(o); } -const mp_obj_type_t mp_type_enumerate = { - { &mp_type_type }, - .name = MP_QSTR_enumerate, - .make_new = enumerate_make_new, - .iternext = enumerate_iternext, - .getiter = mp_identity_getiter, -}; +MP_DEFINE_CONST_OBJ_TYPE( + mp_type_enumerate, + MP_QSTR_enumerate, + MP_TYPE_FLAG_NONE, + enumerate_make_new, + iternext, enumerate_iternext, + getiter, mp_identity_getiter + ); STATIC mp_obj_t enumerate_iternext(mp_obj_t self_in) { assert(mp_obj_is_type(self_in, &mp_type_enumerate)); diff --git a/py/objexcept.c b/py/objexcept.c index 028b73fd8b..190213e12f 100644 --- a/py/objexcept.c +++ b/py/objexcept.c @@ -284,13 +284,14 @@ void mp_obj_exception_attr(mp_obj_t self_in, qstr attr, mp_obj_t *dest) { } } -const mp_obj_type_t mp_type_BaseException = { - { &mp_type_type }, - .name = MP_QSTR_BaseException, - .print = mp_obj_exception_print, - .make_new = mp_obj_exception_make_new, - .attr = mp_obj_exception_attr, -}; +MP_DEFINE_CONST_OBJ_TYPE( + mp_type_BaseException, + MP_QSTR_BaseException, + MP_TYPE_FLAG_NONE, + mp_obj_exception_make_new, + print, mp_obj_exception_print, + attr, mp_obj_exception_attr + ); // *FORMAT-OFF* diff --git a/py/objfilter.c b/py/objfilter.c index a402d8c648..2b57300af3 100644 --- a/py/objfilter.c +++ b/py/objfilter.c @@ -60,12 +60,13 @@ STATIC mp_obj_t filter_iternext(mp_obj_t self_in) { return MP_OBJ_STOP_ITERATION; } -const mp_obj_type_t mp_type_filter = { - { &mp_type_type }, - .name = MP_QSTR_filter, - .make_new = filter_make_new, - .getiter = mp_identity_getiter, - .iternext = filter_iternext, -}; +MP_DEFINE_CONST_OBJ_TYPE( + mp_type_filter, + MP_QSTR_filter, + MP_TYPE_FLAG_NONE, + filter_make_new, + getiter, mp_identity_getiter, + iternext, filter_iternext + ); #endif // MICROPY_PY_BUILTINS_FILTER diff --git a/py/objfloat.c b/py/objfloat.c index 8e89b3da37..9ecbab7a4d 100644 --- a/py/objfloat.c +++ b/py/objfloat.c @@ -182,15 +182,12 @@ STATIC mp_obj_t float_binary_op(mp_binary_op_t op, mp_obj_t lhs_in, mp_obj_t rhs return mp_obj_float_binary_op(op, lhs_val, rhs_in); } -const mp_obj_type_t mp_type_float = { - { &mp_type_type }, - .flags = MP_TYPE_FLAG_EQ_NOT_REFLEXIVE | MP_TYPE_FLAG_EQ_CHECKS_OTHER_TYPE, - .name = MP_QSTR_float, - .print = float_print, - .make_new = float_make_new, - .unary_op = float_unary_op, - .binary_op = float_binary_op, -}; +MP_DEFINE_CONST_OBJ_TYPE( + mp_type_float, MP_QSTR_float, MP_TYPE_FLAG_EQ_NOT_REFLEXIVE | MP_TYPE_FLAG_EQ_CHECKS_OTHER_TYPE, float_make_new, + print, float_print, + unary_op, float_unary_op, + binary_op, float_binary_op + ); #if MICROPY_OBJ_REPR != MICROPY_OBJ_REPR_C && MICROPY_OBJ_REPR != MICROPY_OBJ_REPR_D diff --git a/py/objfun.c b/py/objfun.c index 5fa9d71dda..30de8670a1 100644 --- a/py/objfun.c +++ b/py/objfun.c @@ -56,13 +56,11 @@ STATIC mp_obj_t fun_builtin_0_call(mp_obj_t self_in, size_t n_args, size_t n_kw, return self->fun._0(); } -const mp_obj_type_t mp_type_fun_builtin_0 = { - { &mp_type_type }, - .flags = MP_TYPE_FLAG_BINDS_SELF | MP_TYPE_FLAG_BUILTIN_FUN, - .name = MP_QSTR_function, - .call = fun_builtin_0_call, - .unary_op = mp_generic_unary_op, -}; +MP_DEFINE_CONST_OBJ_TYPE( + mp_type_fun_builtin_0, MP_QSTR_function, MP_TYPE_FLAG_BINDS_SELF | MP_TYPE_FLAG_BUILTIN_FUN, MP_TYPE_NULL_MAKE_NEW, + call, fun_builtin_0_call, + unary_op, mp_generic_unary_op + ); STATIC mp_obj_t fun_builtin_1_call(mp_obj_t self_in, size_t n_args, size_t n_kw, const mp_obj_t *args) { assert(mp_obj_is_type(self_in, &mp_type_fun_builtin_1)); @@ -71,13 +69,11 @@ STATIC mp_obj_t fun_builtin_1_call(mp_obj_t self_in, size_t n_args, size_t n_kw, return self->fun._1(args[0]); } -const mp_obj_type_t mp_type_fun_builtin_1 = { - { &mp_type_type }, - .flags = MP_TYPE_FLAG_BINDS_SELF | MP_TYPE_FLAG_BUILTIN_FUN, - .name = MP_QSTR_function, - .call = fun_builtin_1_call, - .unary_op = mp_generic_unary_op, -}; +MP_DEFINE_CONST_OBJ_TYPE( + mp_type_fun_builtin_1, MP_QSTR_function, MP_TYPE_FLAG_BINDS_SELF | MP_TYPE_FLAG_BUILTIN_FUN, MP_TYPE_NULL_MAKE_NEW, + call, fun_builtin_1_call, + unary_op, mp_generic_unary_op + ); STATIC mp_obj_t fun_builtin_2_call(mp_obj_t self_in, size_t n_args, size_t n_kw, const mp_obj_t *args) { assert(mp_obj_is_type(self_in, &mp_type_fun_builtin_2)); @@ -86,13 +82,11 @@ STATIC mp_obj_t fun_builtin_2_call(mp_obj_t self_in, size_t n_args, size_t n_kw, return self->fun._2(args[0], args[1]); } -const mp_obj_type_t mp_type_fun_builtin_2 = { - { &mp_type_type }, - .flags = MP_TYPE_FLAG_BINDS_SELF | MP_TYPE_FLAG_BUILTIN_FUN, - .name = MP_QSTR_function, - .call = fun_builtin_2_call, - .unary_op = mp_generic_unary_op, -}; +MP_DEFINE_CONST_OBJ_TYPE( + mp_type_fun_builtin_2, MP_QSTR_function, MP_TYPE_FLAG_BINDS_SELF | MP_TYPE_FLAG_BUILTIN_FUN, MP_TYPE_NULL_MAKE_NEW, + call, fun_builtin_2_call, + unary_op, mp_generic_unary_op + ); STATIC mp_obj_t fun_builtin_3_call(mp_obj_t self_in, size_t n_args, size_t n_kw, const mp_obj_t *args) { assert(mp_obj_is_type(self_in, &mp_type_fun_builtin_3)); @@ -101,13 +95,11 @@ STATIC mp_obj_t fun_builtin_3_call(mp_obj_t self_in, size_t n_args, size_t n_kw, return self->fun._3(args[0], args[1], args[2]); } -const mp_obj_type_t mp_type_fun_builtin_3 = { - { &mp_type_type }, - .flags = MP_TYPE_FLAG_BINDS_SELF | MP_TYPE_FLAG_BUILTIN_FUN, - .name = MP_QSTR_function, - .call = fun_builtin_3_call, - .unary_op = mp_generic_unary_op, -}; +MP_DEFINE_CONST_OBJ_TYPE( + mp_type_fun_builtin_3, MP_QSTR_function, MP_TYPE_FLAG_BINDS_SELF | MP_TYPE_FLAG_BUILTIN_FUN, MP_TYPE_NULL_MAKE_NEW, + call, fun_builtin_3_call, + unary_op, mp_generic_unary_op + ); STATIC mp_obj_t fun_builtin_var_call(mp_obj_t self_in, size_t n_args, size_t n_kw, const mp_obj_t *args) { assert(mp_obj_is_type(self_in, &mp_type_fun_builtin_var)); @@ -132,13 +124,11 @@ STATIC mp_obj_t fun_builtin_var_call(mp_obj_t self_in, size_t n_args, size_t n_k } } -const mp_obj_type_t mp_type_fun_builtin_var = { - { &mp_type_type }, - .flags = MP_TYPE_FLAG_BINDS_SELF | MP_TYPE_FLAG_BUILTIN_FUN, - .name = MP_QSTR_function, - .call = fun_builtin_var_call, - .unary_op = mp_generic_unary_op, -}; +MP_DEFINE_CONST_OBJ_TYPE( + mp_type_fun_builtin_var, MP_QSTR_function, MP_TYPE_FLAG_BINDS_SELF | MP_TYPE_FLAG_BUILTIN_FUN, MP_TYPE_NULL_MAKE_NEW, + call, fun_builtin_var_call, + unary_op, mp_generic_unary_op + ); /******************************************************************************/ /* byte code functions */ @@ -362,19 +352,20 @@ void mp_obj_fun_bc_attr(mp_obj_t self_in, qstr attr, mp_obj_t *dest) { } #endif -const mp_obj_type_t mp_type_fun_bc = { - { &mp_type_type }, - .flags = MP_TYPE_FLAG_BINDS_SELF, - .name = MP_QSTR_function, +MP_DEFINE_CONST_OBJ_TYPE( + mp_type_fun_bc, + MP_QSTR_function, + MP_TYPE_FLAG_BINDS_SELF, + MP_TYPE_NULL_MAKE_NEW, #if MICROPY_CPYTHON_COMPAT - .print = fun_bc_print, + print, fun_bc_print, #endif - .call = fun_bc_call, - .unary_op = mp_generic_unary_op, + call, fun_bc_call, + unary_op, mp_generic_unary_op #if MICROPY_PY_FUNCTION_ATTRS - .attr = mp_obj_fun_bc_attr, + , attr, mp_obj_fun_bc_attr #endif -}; + ); mp_obj_t mp_obj_new_fun_bc(const mp_obj_t *def_args, const byte *code, const mp_module_context_t *context, struct _mp_raw_code_t *const *child_table) { size_t n_def_args = 0; @@ -417,19 +408,20 @@ STATIC mp_obj_t fun_native_call(mp_obj_t self_in, size_t n_args, size_t n_kw, co return fun(self_in, n_args, n_kw, args); } -STATIC const mp_obj_type_t mp_type_fun_native = { - { &mp_type_type }, - .flags = MP_TYPE_FLAG_BINDS_SELF, - .name = MP_QSTR_function, +STATIC MP_DEFINE_CONST_OBJ_TYPE( + mp_type_fun_native, + MP_QSTR_function, + MP_TYPE_FLAG_BINDS_SELF, + MP_TYPE_NULL_MAKE_NEW, #if MICROPY_CPYTHON_COMPAT - .print = fun_bc_print, + print, fun_bc_print, #endif - .call = fun_native_call, - .unary_op = mp_generic_unary_op, #if MICROPY_PY_FUNCTION_ATTRS - .attr = mp_obj_fun_bc_attr, + attr, mp_obj_fun_bc_attr, #endif -}; + call, fun_native_call, + unary_op, mp_generic_unary_op + ); mp_obj_t mp_obj_new_fun_native(const mp_obj_t *def_args, const void *fun_data, const mp_module_context_t *mc, struct _mp_raw_code_t *const *child_table) { mp_obj_fun_bc_t *o = MP_OBJ_TO_PTR(mp_obj_new_fun_bc(def_args, (const byte *)fun_data, mc, child_table)); @@ -531,13 +523,14 @@ STATIC mp_obj_t fun_asm_call(mp_obj_t self_in, size_t n_args, size_t n_kw, const return mp_native_to_obj(ret, self->type_sig); } -STATIC const mp_obj_type_t mp_type_fun_asm = { - { &mp_type_type }, - .flags = MP_TYPE_FLAG_BINDS_SELF, - .name = MP_QSTR_function, - .call = fun_asm_call, - .unary_op = mp_generic_unary_op, -}; +STATIC MP_DEFINE_CONST_OBJ_TYPE( + mp_type_fun_asm, + MP_QSTR_function, + MP_TYPE_FLAG_BINDS_SELF, + MP_TYPE_NULL_MAKE_NEW, + call, fun_asm_call, + unary_op, mp_generic_unary_op + ); mp_obj_t mp_obj_new_fun_asm(size_t n_args, const void *fun_data, mp_uint_t type_sig) { mp_obj_fun_asm_t *o = mp_obj_malloc(mp_obj_fun_asm_t, &mp_type_fun_asm); diff --git a/py/objgenerator.c b/py/objgenerator.c index 802fd45bbd..0ab80ca118 100644 --- a/py/objgenerator.c +++ b/py/objgenerator.c @@ -70,16 +70,17 @@ STATIC mp_obj_t gen_wrap_call(mp_obj_t self_in, size_t n_args, size_t n_kw, cons return MP_OBJ_FROM_PTR(o); } -const mp_obj_type_t mp_type_gen_wrap = { - { &mp_type_type }, - .flags = MP_TYPE_FLAG_BINDS_SELF, - .name = MP_QSTR_generator, - .call = gen_wrap_call, - .unary_op = mp_generic_unary_op, +MP_DEFINE_CONST_OBJ_TYPE( + mp_type_gen_wrap, + MP_QSTR_generator, + MP_TYPE_FLAG_BINDS_SELF, + MP_TYPE_NULL_MAKE_NEW, + call, gen_wrap_call, + unary_op, mp_generic_unary_op #if MICROPY_PY_FUNCTION_ATTRS - .attr = mp_obj_fun_bc_attr, + , attr, mp_obj_fun_bc_attr #endif -}; + ); /******************************************************************************/ // native generator wrapper @@ -131,16 +132,17 @@ STATIC mp_obj_t native_gen_wrap_call(mp_obj_t self_in, size_t n_args, size_t n_k return MP_OBJ_FROM_PTR(o); } -const mp_obj_type_t mp_type_native_gen_wrap = { - { &mp_type_type }, - .flags = MP_TYPE_FLAG_BINDS_SELF, - .name = MP_QSTR_generator, - .call = native_gen_wrap_call, - .unary_op = mp_generic_unary_op, +MP_DEFINE_CONST_OBJ_TYPE( + mp_type_native_gen_wrap, + MP_QSTR_generator, + MP_TYPE_FLAG_BINDS_SELF, + MP_TYPE_NULL_MAKE_NEW, + call, native_gen_wrap_call, + unary_op, mp_generic_unary_op #if MICROPY_PY_FUNCTION_ATTRS - .attr = mp_obj_fun_bc_attr, + , attr, mp_obj_fun_bc_attr #endif -}; + ); #endif // MICROPY_EMIT_NATIVE @@ -357,12 +359,14 @@ STATIC const mp_rom_map_elem_t gen_instance_locals_dict_table[] = { STATIC MP_DEFINE_CONST_DICT(gen_instance_locals_dict, gen_instance_locals_dict_table); -const mp_obj_type_t mp_type_gen_instance = { - { &mp_type_type }, - .name = MP_QSTR_generator, - .print = gen_instance_print, - .unary_op = mp_generic_unary_op, - .getiter = mp_identity_getiter, - .iternext = gen_instance_iternext, - .locals_dict = (mp_obj_dict_t *)&gen_instance_locals_dict, -}; +MP_DEFINE_CONST_OBJ_TYPE( + mp_type_gen_instance, + MP_QSTR_generator, + MP_TYPE_FLAG_NONE, + MP_TYPE_NULL_MAKE_NEW, + print, gen_instance_print, + unary_op, mp_generic_unary_op, + getiter, mp_identity_getiter, + iternext, gen_instance_iternext, + locals_dict, (mp_obj_dict_t *)&gen_instance_locals_dict + ); diff --git a/py/objgetitemiter.c b/py/objgetitemiter.c index 31ed4a9228..ed2dfbbe1f 100644 --- a/py/objgetitemiter.c +++ b/py/objgetitemiter.c @@ -56,12 +56,14 @@ STATIC mp_obj_t it_iternext(mp_obj_t self_in) { } } -STATIC const mp_obj_type_t mp_type_it = { - { &mp_type_type }, - .name = MP_QSTR_iterator, - .getiter = mp_identity_getiter, - .iternext = it_iternext, -}; +STATIC MP_DEFINE_CONST_OBJ_TYPE( + mp_type_it, + MP_QSTR_iterator, + MP_TYPE_FLAG_NONE, + MP_TYPE_NULL_MAKE_NEW, + getiter, mp_identity_getiter, + iternext, it_iternext + ); // args are those returned from mp_load_method_maybe (ie either an attribute or a method) mp_obj_t mp_obj_new_getitem_iter(mp_obj_t *args, mp_obj_iter_buf_t *iter_buf) { diff --git a/py/objint.c b/py/objint.c index 645b269966..d7a3f9eb9d 100644 --- a/py/objint.c +++ b/py/objint.c @@ -457,12 +457,13 @@ STATIC const mp_rom_map_elem_t int_locals_dict_table[] = { STATIC MP_DEFINE_CONST_DICT(int_locals_dict, int_locals_dict_table); -const mp_obj_type_t mp_type_int = { - { &mp_type_type }, - .name = MP_QSTR_int, - .print = mp_obj_int_print, - .make_new = mp_obj_int_make_new, - .unary_op = mp_obj_int_unary_op, - .binary_op = mp_obj_int_binary_op, - .locals_dict = (mp_obj_dict_t *)&int_locals_dict, -}; +MP_DEFINE_CONST_OBJ_TYPE( + mp_type_int, + MP_QSTR_int, + MP_TYPE_FLAG_NONE, + mp_obj_int_make_new, + print, mp_obj_int_print, + unary_op, mp_obj_int_unary_op, + binary_op, mp_obj_int_binary_op, + locals_dict, (mp_obj_dict_t *)&int_locals_dict + ); diff --git a/py/objlist.c b/py/objlist.c index f431e273df..8c7921b989 100644 --- a/py/objlist.c +++ b/py/objlist.c @@ -452,17 +452,19 @@ STATIC const mp_rom_map_elem_t list_locals_dict_table[] = { STATIC MP_DEFINE_CONST_DICT(list_locals_dict, list_locals_dict_table); -const mp_obj_type_t mp_type_list = { - { &mp_type_type }, - .name = MP_QSTR_list, - .print = list_print, - .make_new = list_make_new, - .unary_op = list_unary_op, - .binary_op = list_binary_op, - .subscr = list_subscr, - .getiter = list_getiter, - .locals_dict = (mp_obj_dict_t *)&list_locals_dict, -}; +MP_DEFINE_CONST_OBJ_TYPE( + mp_type_list, + MP_QSTR_list, + MP_TYPE_FLAG_NONE, + list_make_new, + print, list_print, + unary_op, list_unary_op, + binary_op, list_binary_op, + subscr, list_subscr, + getiter, list_getiter, + locals_dict, (mp_obj_dict_t *)&list_locals_dict + ); + void mp_obj_list_init(mp_obj_list_t *o, size_t n) { o->base.type = &mp_type_list; diff --git a/py/objmap.c b/py/objmap.c index 1f9275854f..dc305e21b5 100644 --- a/py/objmap.c +++ b/py/objmap.c @@ -63,10 +63,11 @@ STATIC mp_obj_t map_iternext(mp_obj_t self_in) { return mp_call_function_n_kw(self->fun, self->n_iters, 0, nextses); } -const mp_obj_type_t mp_type_map = { - { &mp_type_type }, - .name = MP_QSTR_map, - .make_new = map_make_new, - .getiter = mp_identity_getiter, - .iternext = map_iternext, -}; +MP_DEFINE_CONST_OBJ_TYPE( + mp_type_map, + MP_QSTR_map, + MP_TYPE_FLAG_NONE, + map_make_new, + getiter, mp_identity_getiter, + iternext, map_iternext + ); diff --git a/py/objmodule.c b/py/objmodule.c index 783d6b0508..6fc3653e6a 100644 --- a/py/objmodule.c +++ b/py/objmodule.c @@ -130,12 +130,14 @@ STATIC void module_attr(mp_obj_t self_in, qstr attr, mp_obj_t *dest) { } } -const mp_obj_type_t mp_type_module = { - { &mp_type_type }, - .name = MP_QSTR_module, - .print = module_print, - .attr = module_attr, -}; +MP_DEFINE_CONST_OBJ_TYPE( + mp_type_module, + MP_QSTR_module, + MP_TYPE_FLAG_NONE, + MP_TYPE_NULL_MAKE_NEW, + print, module_print, + attr, module_attr + ); mp_obj_t mp_obj_new_module(qstr module_name) { mp_map_t *mp_loaded_modules_map = &MP_STATE_VM(mp_loaded_modules_dict).map; diff --git a/py/objnone.c b/py/objnone.c index 271a8543f9..4fffbc997e 100644 --- a/py/objnone.c +++ b/py/objnone.c @@ -43,12 +43,14 @@ STATIC void none_print(const mp_print_t *print, mp_obj_t self_in, mp_print_kind_ } } -const mp_obj_type_t mp_type_NoneType = { - { &mp_type_type }, - .name = MP_QSTR_NoneType, - .print = none_print, - .unary_op = mp_generic_unary_op, -}; +MP_DEFINE_CONST_OBJ_TYPE( + mp_type_NoneType, + MP_QSTR_NoneType, + MP_TYPE_FLAG_NONE, + MP_TYPE_NULL_MAKE_NEW, + print, none_print, + unary_op, mp_generic_unary_op + ); #if !MICROPY_OBJ_IMMEDIATE_OBJS const mp_obj_none_t mp_const_none_obj = {{&mp_type_NoneType}}; diff --git a/py/objobject.c b/py/objobject.c index 1652802805..617b40fbbf 100644 --- a/py/objobject.c +++ b/py/objobject.c @@ -111,11 +111,12 @@ STATIC const mp_rom_map_elem_t object_locals_dict_table[] = { STATIC MP_DEFINE_CONST_DICT(object_locals_dict, object_locals_dict_table); #endif -const mp_obj_type_t mp_type_object = { - { &mp_type_type }, - .name = MP_QSTR_object, - .make_new = object_make_new, +MP_DEFINE_CONST_OBJ_TYPE( + mp_type_object, + MP_QSTR_object, + MP_TYPE_FLAG_NONE, + object_make_new #if MICROPY_CPYTHON_COMPAT - .locals_dict = (mp_obj_dict_t *)&object_locals_dict, + , locals_dict, (mp_obj_dict_t *)&object_locals_dict #endif -}; + ); diff --git a/py/objpolyiter.c b/py/objpolyiter.c index dac6a25455..326153182b 100644 --- a/py/objpolyiter.c +++ b/py/objpolyiter.c @@ -45,12 +45,14 @@ STATIC mp_obj_t polymorph_it_iternext(mp_obj_t self_in) { return self->iternext(self_in); } -const mp_obj_type_t mp_type_polymorph_iter = { - { &mp_type_type }, - .name = MP_QSTR_iterator, - .getiter = mp_identity_getiter, - .iternext = polymorph_it_iternext, -}; +MP_DEFINE_CONST_OBJ_TYPE( + mp_type_polymorph_iter, + MP_QSTR_iterator, + MP_TYPE_FLAG_NONE, + MP_TYPE_NULL_MAKE_NEW, + getiter, mp_identity_getiter, + iternext, polymorph_it_iternext + ); #if MICROPY_ENABLE_FINALISER // mp_type_polymorph_iter_with_finaliser is a variant of the universal iterator @@ -76,12 +78,13 @@ STATIC const mp_rom_map_elem_t mp_obj_polymorph_iter_locals_dict_table[] = { }; STATIC MP_DEFINE_CONST_DICT(mp_obj_polymorph_iter_locals_dict, mp_obj_polymorph_iter_locals_dict_table); -const mp_obj_type_t mp_type_polymorph_iter_with_finaliser = { - { &mp_type_type }, - .name = MP_QSTR_iterator, - .getiter = mp_identity_getiter, - .iternext = polymorph_it_iternext, - .locals_dict = (mp_obj_dict_t *)&mp_obj_polymorph_iter_locals_dict, -}; - +MP_DEFINE_CONST_OBJ_TYPE( + mp_type_polymorph_iter_with_finaliser, + MP_QSTR_iterator, + MP_TYPE_FLAG_NONE, + MP_TYPE_NULL_MAKE_NEW, + getiter, mp_identity_getiter, + iternext, polymorph_it_iternext, + locals_dict, (mp_obj_dict_t *)&mp_obj_polymorph_iter_locals_dict + ); #endif diff --git a/py/objproperty.c b/py/objproperty.c index 49327c981e..42c357f330 100644 --- a/py/objproperty.c +++ b/py/objproperty.c @@ -90,12 +90,13 @@ STATIC const mp_rom_map_elem_t property_locals_dict_table[] = { STATIC MP_DEFINE_CONST_DICT(property_locals_dict, property_locals_dict_table); -const mp_obj_type_t mp_type_property = { - { &mp_type_type }, - .name = MP_QSTR_property, - .make_new = property_make_new, - .locals_dict = (mp_obj_dict_t *)&property_locals_dict, -}; +MP_DEFINE_CONST_OBJ_TYPE( + mp_type_property, + MP_QSTR_property, + MP_TYPE_FLAG_NONE, + property_make_new, + locals_dict, (mp_obj_dict_t *)&property_locals_dict + ); const mp_obj_t *mp_obj_property_get(mp_obj_t self_in) { mp_check_self(mp_obj_is_type(self_in, &mp_type_property)); diff --git a/py/objrange.c b/py/objrange.c index 5496021892..adf4b17466 100644 --- a/py/objrange.c +++ b/py/objrange.c @@ -50,12 +50,14 @@ STATIC mp_obj_t range_it_iternext(mp_obj_t o_in) { } } -STATIC const mp_obj_type_t mp_type_range_it = { - { &mp_type_type }, - .name = MP_QSTR_iterator, - .getiter = mp_identity_getiter, - .iternext = range_it_iternext, -}; +STATIC MP_DEFINE_CONST_OBJ_TYPE( + mp_type_range_it, + MP_QSTR_iterator, + MP_TYPE_FLAG_NONE, + MP_TYPE_NULL_MAKE_NEW, + getiter, mp_identity_getiter, + iternext, range_it_iternext + ); STATIC mp_obj_t mp_obj_new_range_iterator(mp_int_t cur, mp_int_t stop, mp_int_t step, mp_obj_iter_buf_t *iter_buf) { assert(sizeof(mp_obj_range_it_t) <= sizeof(mp_obj_iter_buf_t)); @@ -208,18 +210,19 @@ STATIC void range_attr(mp_obj_t o_in, qstr attr, mp_obj_t *dest) { } #endif -const mp_obj_type_t mp_type_range = { - { &mp_type_type }, - .name = MP_QSTR_range, - .print = range_print, - .make_new = range_make_new, - .unary_op = range_unary_op, +MP_DEFINE_CONST_OBJ_TYPE( + mp_type_range, + MP_QSTR_range, + MP_TYPE_FLAG_NONE, + range_make_new, + print, range_print, + unary_op, range_unary_op, #if MICROPY_PY_BUILTINS_RANGE_BINOP - .binary_op = range_binary_op, + binary_op, range_binary_op, #endif - .subscr = range_subscr, - .getiter = range_getiter, + subscr, range_subscr, + getiter, range_getiter #if MICROPY_PY_BUILTINS_RANGE_ATTRS - .attr = range_attr, + , attr, range_attr #endif -}; + ); diff --git a/py/objreversed.c b/py/objreversed.c index 08961c0d2d..bc1f07ddec 100644 --- a/py/objreversed.c +++ b/py/objreversed.c @@ -68,12 +68,13 @@ STATIC mp_obj_t reversed_iternext(mp_obj_t self_in) { return mp_obj_subscr(self->seq, MP_OBJ_NEW_SMALL_INT(self->cur_index), MP_OBJ_SENTINEL); } -const mp_obj_type_t mp_type_reversed = { - { &mp_type_type }, - .name = MP_QSTR_reversed, - .make_new = reversed_make_new, - .getiter = mp_identity_getiter, - .iternext = reversed_iternext, -}; +MP_DEFINE_CONST_OBJ_TYPE( + mp_type_reversed, + MP_QSTR_reversed, + MP_TYPE_FLAG_NONE, + reversed_make_new, + getiter, mp_identity_getiter, + iternext, reversed_iternext + ); #endif // MICROPY_PY_BUILTINS_REVERSED diff --git a/py/objset.c b/py/objset.c index 26fd74398b..8fc744a140 100644 --- a/py/objset.c +++ b/py/objset.c @@ -539,16 +539,17 @@ STATIC const mp_rom_map_elem_t set_locals_dict_table[] = { }; STATIC MP_DEFINE_CONST_DICT(set_locals_dict, set_locals_dict_table); -const mp_obj_type_t mp_type_set = { - { &mp_type_type }, - .name = MP_QSTR_set, - .print = set_print, - .make_new = set_make_new, - .unary_op = set_unary_op, - .binary_op = set_binary_op, - .getiter = set_getiter, - .locals_dict = (mp_obj_dict_t *)&set_locals_dict, -}; +MP_DEFINE_CONST_OBJ_TYPE( + mp_type_set, + MP_QSTR_set, + MP_TYPE_FLAG_NONE, + set_make_new, + print, set_print, + unary_op, set_unary_op, + binary_op, set_binary_op, + getiter, set_getiter, + locals_dict, (mp_obj_dict_t *)&set_locals_dict + ); #if MICROPY_PY_BUILTINS_FROZENSET STATIC const mp_rom_map_elem_t frozenset_locals_dict_table[] = { @@ -564,17 +565,17 @@ STATIC const mp_rom_map_elem_t frozenset_locals_dict_table[] = { }; STATIC MP_DEFINE_CONST_DICT(frozenset_locals_dict, frozenset_locals_dict_table); -const mp_obj_type_t mp_type_frozenset = { - { &mp_type_type }, - .flags = MP_TYPE_FLAG_EQ_CHECKS_OTHER_TYPE, - .name = MP_QSTR_frozenset, - .print = set_print, - .make_new = set_make_new, - .unary_op = set_unary_op, - .binary_op = set_binary_op, - .getiter = set_getiter, - .locals_dict = (mp_obj_dict_t *)&frozenset_locals_dict, -}; +MP_DEFINE_CONST_OBJ_TYPE( + mp_type_frozenset, + MP_QSTR_frozenset, + MP_TYPE_FLAG_EQ_CHECKS_OTHER_TYPE, + set_make_new, + print, set_print, + unary_op, set_unary_op, + binary_op, set_binary_op, + getiter, set_getiter, + locals_dict, (mp_obj_dict_t *)&frozenset_locals_dict + ); #endif mp_obj_t mp_obj_new_set(size_t n_args, mp_obj_t *items) { diff --git a/py/objsingleton.c b/py/objsingleton.c index 2b896305cf..4a099657d4 100644 --- a/py/objsingleton.c +++ b/py/objsingleton.c @@ -43,12 +43,11 @@ STATIC void singleton_print(const mp_print_t *print, mp_obj_t self_in, mp_print_ mp_printf(print, "%q", self->name); } -const mp_obj_type_t mp_type_singleton = { - { &mp_type_type }, - .name = MP_QSTR_, - .print = singleton_print, - .unary_op = mp_generic_unary_op, -}; +MP_DEFINE_CONST_OBJ_TYPE( + mp_type_singleton, MP_QSTR_, MP_TYPE_FLAG_NONE, MP_TYPE_NULL_MAKE_NEW, + print, singleton_print, + unary_op, mp_generic_unary_op + ); const mp_obj_singleton_t mp_const_ellipsis_obj = {{&mp_type_singleton}, MP_QSTR_Ellipsis}; #if MICROPY_PY_BUILTINS_NOTIMPLEMENTED diff --git a/py/objslice.c b/py/objslice.c index 0b34516c18..98c03485ff 100644 --- a/py/objslice.c +++ b/py/objslice.c @@ -92,16 +92,18 @@ STATIC const mp_rom_map_elem_t slice_locals_dict_table[] = { STATIC MP_DEFINE_CONST_DICT(slice_locals_dict, slice_locals_dict_table); #endif -const mp_obj_type_t mp_type_slice = { - { &mp_type_type }, - .name = MP_QSTR_slice, - .print = slice_print, +MP_DEFINE_CONST_OBJ_TYPE( + mp_type_slice, + MP_QSTR_slice, + MP_TYPE_FLAG_NONE, + MP_TYPE_NULL_MAKE_NEW, + print, slice_print #if MICROPY_PY_BUILTINS_SLICE_ATTRS - .attr = slice_attr, + , attr, slice_attr #elif MICROPY_PY_BUILTINS_SLICE_INDICES - .locals_dict = (mp_obj_dict_t *)&slice_locals_dict, + , locals_dict, (mp_obj_dict_t *)&slice_locals_dict #endif -}; + ); mp_obj_t mp_obj_new_slice(mp_obj_t ostart, mp_obj_t ostop, mp_obj_t ostep) { mp_obj_slice_t *o = mp_obj_malloc(mp_obj_slice_t, &mp_type_slice); diff --git a/py/objstr.c b/py/objstr.c index 9dd7f65e66..77ca269d42 100644 --- a/py/objstr.c +++ b/py/objstr.c @@ -2143,31 +2143,33 @@ MP_DEFINE_CONST_DICT_WITH_SIZE(mp_obj_memoryview_locals_dict, #if !MICROPY_PY_BUILTINS_STR_UNICODE STATIC mp_obj_t mp_obj_new_str_iterator(mp_obj_t str, mp_obj_iter_buf_t *iter_buf); -const mp_obj_type_t mp_type_str = { - { &mp_type_type }, - .name = MP_QSTR_str, - .print = str_print, - .make_new = mp_obj_str_make_new, - .binary_op = mp_obj_str_binary_op, - .subscr = bytes_subscr, - .getiter = mp_obj_new_str_iterator, - .buffer = mp_obj_str_get_buffer, - .locals_dict = (mp_obj_dict_t *)&mp_obj_str_locals_dict, -}; +MP_DEFINE_CONST_OBJ_TYPE( + mp_type_str, + MP_QSTR_str, + MP_TYPE_FLAG_NONE, + mp_obj_str_make_new, + print, str_print, + binary_op, mp_obj_str_binary_op, + subscr, bytes_subscr, + getiter, mp_obj_new_str_iterator, + buffer, mp_obj_str_get_buffer, + locals_dict, (mp_obj_dict_t *)&mp_obj_str_locals_dict + ); #endif // !MICROPY_PY_BUILTINS_STR_UNICODE -// Reuses most of methods from str -const mp_obj_type_t mp_type_bytes = { - { &mp_type_type }, - .name = MP_QSTR_bytes, - .print = str_print, - .make_new = bytes_make_new, - .binary_op = mp_obj_str_binary_op, - .subscr = bytes_subscr, - .getiter = mp_obj_new_bytes_iterator, - .buffer = mp_obj_str_get_buffer, - .locals_dict = (mp_obj_dict_t *)&mp_obj_bytes_locals_dict, -}; +// Reuses most methods from str +MP_DEFINE_CONST_OBJ_TYPE( + mp_type_bytes, + MP_QSTR_bytes, + MP_TYPE_FLAG_NONE, + bytes_make_new, + print, str_print, + binary_op, mp_obj_str_binary_op, + subscr, bytes_subscr, + getiter, mp_obj_new_bytes_iterator, + buffer, mp_obj_str_get_buffer, + locals_dict, (mp_obj_dict_t *)&mp_obj_bytes_locals_dict + ); // The zero-length bytes object, with data that includes a null-terminating byte const mp_obj_str_t mp_const_empty_bytes_obj = {{&mp_type_bytes}, 0, 0, (const byte *)""}; diff --git a/py/objstringio.c b/py/objstringio.c index 8b6c7531d7..d781ccc789 100644 --- a/py/objstringio.c +++ b/py/objstringio.c @@ -244,16 +244,17 @@ STATIC const mp_stream_p_t stringio_stream_p = { .is_text = true, }; -const mp_obj_type_t mp_type_stringio = { - { &mp_type_type }, - .name = MP_QSTR_StringIO, - .print = stringio_print, - .make_new = stringio_make_new, - .getiter = mp_identity_getiter, - .iternext = mp_stream_unbuffered_iter, - .protocol = &stringio_stream_p, - .locals_dict = (mp_obj_dict_t *)&stringio_locals_dict, -}; +MP_DEFINE_CONST_OBJ_TYPE( + mp_type_stringio, + MP_QSTR_StringIO, + MP_TYPE_FLAG_NONE, + stringio_make_new, + print, stringio_print, + getiter, mp_identity_getiter, + iternext, mp_stream_unbuffered_iter, + protocol, &stringio_stream_p, + locals_dict, (mp_obj_dict_t *)&stringio_locals_dict + ); #if MICROPY_PY_IO_BYTESIO STATIC const mp_stream_p_t bytesio_stream_p = { @@ -262,16 +263,17 @@ STATIC const mp_stream_p_t bytesio_stream_p = { .ioctl = stringio_ioctl, }; -const mp_obj_type_t mp_type_bytesio = { - { &mp_type_type }, - .name = MP_QSTR_BytesIO, - .print = stringio_print, - .make_new = stringio_make_new, - .getiter = mp_identity_getiter, - .iternext = mp_stream_unbuffered_iter, - .protocol = &bytesio_stream_p, - .locals_dict = (mp_obj_dict_t *)&stringio_locals_dict, -}; +MP_DEFINE_CONST_OBJ_TYPE( + mp_type_bytesio, + MP_QSTR_BytesIO, + MP_TYPE_FLAG_NONE, + stringio_make_new, + print, stringio_print, + getiter, mp_identity_getiter, + iternext, mp_stream_unbuffered_iter, + protocol, &bytesio_stream_p, + locals_dict, (mp_obj_dict_t *)&stringio_locals_dict + ); #endif #endif diff --git a/py/objstrunicode.c b/py/objstrunicode.c index fef0353683..afef1498e9 100644 --- a/py/objstrunicode.c +++ b/py/objstrunicode.c @@ -229,18 +229,19 @@ STATIC mp_obj_t str_subscr(mp_obj_t self_in, mp_obj_t index, mp_obj_t value) { } } -const mp_obj_type_t mp_type_str = { - { &mp_type_type }, - .name = MP_QSTR_str, - .print = uni_print, - .make_new = mp_obj_str_make_new, - .unary_op = uni_unary_op, - .binary_op = mp_obj_str_binary_op, - .subscr = str_subscr, - .getiter = mp_obj_new_str_iterator, - .buffer = mp_obj_str_get_buffer, - .locals_dict = (mp_obj_dict_t *)&mp_obj_str_locals_dict, -}; +MP_DEFINE_CONST_OBJ_TYPE( + mp_type_str, + MP_QSTR_str, + MP_TYPE_FLAG_NONE, + mp_obj_str_make_new, + print, uni_print, + unary_op, uni_unary_op, + binary_op, mp_obj_str_binary_op, + subscr, str_subscr, + getiter, mp_obj_new_str_iterator, + buffer, mp_obj_str_get_buffer, + locals_dict, (mp_obj_dict_t *)&mp_obj_str_locals_dict + ); /******************************************************************************/ /* str iterator */ diff --git a/py/objtuple.c b/py/objtuple.c index e0cec84473..b2ea6e380e 100644 --- a/py/objtuple.c +++ b/py/objtuple.c @@ -224,17 +224,18 @@ STATIC const mp_rom_map_elem_t tuple_locals_dict_table[] = { STATIC MP_DEFINE_CONST_DICT(tuple_locals_dict, tuple_locals_dict_table); -const mp_obj_type_t mp_type_tuple = { - { &mp_type_type }, - .name = MP_QSTR_tuple, - .print = mp_obj_tuple_print, - .make_new = mp_obj_tuple_make_new, - .unary_op = mp_obj_tuple_unary_op, - .binary_op = mp_obj_tuple_binary_op, - .subscr = mp_obj_tuple_subscr, - .getiter = mp_obj_tuple_getiter, - .locals_dict = (mp_obj_dict_t *)&tuple_locals_dict, -}; +MP_DEFINE_CONST_OBJ_TYPE( + mp_type_tuple, + MP_QSTR_tuple, + MP_TYPE_FLAG_NONE, + mp_obj_tuple_make_new, + print, mp_obj_tuple_print, + unary_op, mp_obj_tuple_unary_op, + binary_op, mp_obj_tuple_binary_op, + subscr, mp_obj_tuple_subscr, + getiter, mp_obj_tuple_getiter, + locals_dict, (mp_obj_dict_t *)&tuple_locals_dict + ); // the zero-length tuple const mp_obj_tuple_t mp_const_empty_tuple_obj = {{&mp_type_tuple}, 0}; diff --git a/py/objtype.c b/py/objtype.c index c0f6857809..77fe8e22e3 100644 --- a/py/objtype.c +++ b/py/objtype.c @@ -1098,15 +1098,16 @@ STATIC void type_attr(mp_obj_t self_in, qstr attr, mp_obj_t *dest) { } } -const mp_obj_type_t mp_type_type = { - { &mp_type_type }, - .name = MP_QSTR_type, - .print = type_print, - .make_new = type_make_new, - .call = type_call, - .unary_op = mp_generic_unary_op, - .attr = type_attr, -}; +MP_DEFINE_CONST_OBJ_TYPE( + mp_type_type, + MP_QSTR_type, + MP_TYPE_FLAG_NONE, + type_make_new, + print, type_print, + call, type_call, + unary_op, mp_generic_unary_op, + attr, type_attr + ); mp_obj_t mp_obj_new_type(qstr name, mp_obj_t bases_tuple, mp_obj_t locals_dict) { // Verify input objects have expected type @@ -1314,13 +1315,14 @@ STATIC void super_attr(mp_obj_t self_in, qstr attr, mp_obj_t *dest) { mp_obj_class_lookup(&lookup, &mp_type_object); } -const mp_obj_type_t mp_type_super = { - { &mp_type_type }, - .name = MP_QSTR_super, - .print = super_print, - .make_new = super_make_new, - .attr = super_attr, -}; +MP_DEFINE_CONST_OBJ_TYPE( + mp_type_super, + MP_QSTR_super, + MP_TYPE_FLAG_NONE, + super_make_new, + print, super_print, + attr, super_attr + ); void mp_load_super_method(qstr attr, mp_obj_t *dest) { mp_obj_super_t super = {{&mp_type_super}, dest[1], dest[2]}; @@ -1436,14 +1438,16 @@ STATIC mp_obj_t static_class_method_make_new(const mp_obj_type_t *self, size_t n return MP_OBJ_FROM_PTR(o); } -const mp_obj_type_t mp_type_staticmethod = { - { &mp_type_type }, - .name = MP_QSTR_staticmethod, - .make_new = static_class_method_make_new, -}; +MP_DEFINE_CONST_OBJ_TYPE( + mp_type_staticmethod, + MP_QSTR_staticmethod, + MP_TYPE_FLAG_NONE, + static_class_method_make_new + ); -const mp_obj_type_t mp_type_classmethod = { - { &mp_type_type }, - .name = MP_QSTR_classmethod, - .make_new = static_class_method_make_new, -}; +MP_DEFINE_CONST_OBJ_TYPE( + mp_type_classmethod, + MP_QSTR_classmethod, + MP_TYPE_FLAG_NONE, + static_class_method_make_new + ); diff --git a/py/objzip.c b/py/objzip.c index 81fa1d587e..0ceafd97f2 100644 --- a/py/objzip.c +++ b/py/objzip.c @@ -66,10 +66,11 @@ STATIC mp_obj_t zip_iternext(mp_obj_t self_in) { return MP_OBJ_FROM_PTR(tuple); } -const mp_obj_type_t mp_type_zip = { - { &mp_type_type }, - .name = MP_QSTR_zip, - .make_new = zip_make_new, - .getiter = mp_identity_getiter, - .iternext = zip_iternext, -}; +MP_DEFINE_CONST_OBJ_TYPE( + mp_type_zip, + MP_QSTR_zip, + MP_TYPE_FLAG_NONE, + zip_make_new, + getiter, mp_identity_getiter, + iternext, zip_iternext + ); diff --git a/py/profile.c b/py/profile.c index 4e23e9eac4..2b9531e245 100644 --- a/py/profile.c +++ b/py/profile.c @@ -172,13 +172,15 @@ STATIC void code_attr(mp_obj_t self_in, qstr attr, mp_obj_t *dest) { } } -const mp_obj_type_t mp_type_settrace_codeobj = { - { &mp_type_type }, - .name = MP_QSTR_code, - .print = code_print, - .unary_op = mp_generic_unary_op, - .attr = code_attr, -}; +MP_DEFINE_CONST_OBJ_TYPE( + mp_type_settrace_codeobj, + MP_QSTR_code, + MP_TYPE_FLAG_NONE, + MP_TYPE_NULL_MAKE_NEW, + print, code_print, + unary_op, mp_generic_unary_op, + attr, code_attr + ); mp_obj_t mp_obj_new_code(const mp_module_context_t *context, const mp_raw_code_t *rc) { mp_obj_code_t *o = m_new_obj_maybe(mp_obj_code_t); @@ -241,13 +243,15 @@ STATIC void frame_attr(mp_obj_t self_in, qstr attr, mp_obj_t *dest) { } } -const mp_obj_type_t mp_type_frame = { - { &mp_type_type }, - .name = MP_QSTR_frame, - .print = frame_print, - .unary_op = mp_generic_unary_op, - .attr = frame_attr, -}; +MP_DEFINE_CONST_OBJ_TYPE( + mp_type_frame, + MP_QSTR_frame, + MP_TYPE_FLAG_NONE, + MP_TYPE_NULL_MAKE_NEW, + print, frame_print, + unary_op, mp_generic_unary_op, + attr, frame_attr + ); mp_obj_t mp_obj_new_frame(const mp_code_state_t *code_state) { if (gc_is_locked()) { diff --git a/py/runtime.c b/py/runtime.c index ea3553db72..27b4f05f04 100644 --- a/py/runtime.c +++ b/py/runtime.c @@ -1070,12 +1070,13 @@ STATIC mp_obj_t checked_fun_call(mp_obj_t self_in, size_t n_args, size_t n_kw, c return mp_call_function_n_kw(self->fun, n_args, n_kw, args); } -STATIC const mp_obj_type_t mp_type_checked_fun = { - { &mp_type_type }, - .flags = MP_TYPE_FLAG_BINDS_SELF, - .name = MP_QSTR_function, - .call = checked_fun_call, -}; +STATIC MP_DEFINE_CONST_OBJ_TYPE( + mp_type_checked_fun, + MP_QSTR_function, + MP_TYPE_FLAG_BINDS_SELF, + MP_TYPE_NULL_MAKE_NEW, + call, checked_fun_call + ); STATIC mp_obj_t mp_obj_new_checked_fun(const mp_obj_type_t *type, mp_obj_t fun) { mp_obj_checked_fun_t *o = mp_obj_malloc(mp_obj_checked_fun_t, &mp_type_checked_fun); diff --git a/shared/runtime/mpirq.c b/shared/runtime/mpirq.c index 8e474bf5a2..763da6e0e4 100644 --- a/shared/runtime/mpirq.c +++ b/shared/runtime/mpirq.c @@ -125,11 +125,13 @@ STATIC const mp_rom_map_elem_t mp_irq_locals_dict_table[] = { }; STATIC MP_DEFINE_CONST_DICT(mp_irq_locals_dict, mp_irq_locals_dict_table); -const mp_obj_type_t mp_irq_type = { - { &mp_type_type }, - .name = MP_QSTR_irq, - .call = mp_irq_call, - .locals_dict = (mp_obj_dict_t *)&mp_irq_locals_dict, -}; +MP_DEFINE_CONST_OBJ_TYPE( + mp_irq_type, + MP_QSTR_irq, + MP_TYPE_FLAG_NONE, + MP_TYPE_NULL_MAKE_NEW, + call, mp_irq_call, + locals_dict, (mp_obj_dict_t *)&mp_irq_locals_dict + ); #endif // MICROPY_ENABLE_SCHEDULER diff --git a/shared/runtime/sys_stdio_mphal.c b/shared/runtime/sys_stdio_mphal.c index 24f528b0c4..f1290853da 100644 --- a/shared/runtime/sys_stdio_mphal.c +++ b/shared/runtime/sys_stdio_mphal.c @@ -123,15 +123,17 @@ STATIC const mp_stream_p_t stdio_obj_stream_p = { .is_text = true, }; -STATIC const mp_obj_type_t stdio_obj_type = { - { &mp_type_type }, - .name = MP_QSTR_FileIO, - .print = stdio_obj_print, - .getiter = mp_identity_getiter, - .iternext = mp_stream_unbuffered_iter, - .protocol = &stdio_obj_stream_p, - .locals_dict = (mp_obj_dict_t *)&stdio_locals_dict, -}; +MP_DEFINE_CONST_OBJ_TYPE( + stdio_obj_type, + MP_QSTR_FileIO, + MP_TYPE_FLAG_NONE, + MP_TYPE_NULL_MAKE_NEW, + print, stdio_obj_print, + getiter, mp_identity_getiter, + iternext, mp_stream_unbuffered_iter, + protocol, &stdio_obj_stream_p, + locals_dict, (mp_obj_dict_t *)&stdio_locals_dict + ); const sys_stdio_obj_t mp_sys_stdin_obj = {{&stdio_obj_type}, .fd = STDIO_FD_IN}; const sys_stdio_obj_t mp_sys_stdout_obj = {{&stdio_obj_type}, .fd = STDIO_FD_OUT}; @@ -157,15 +159,17 @@ STATIC const mp_stream_p_t stdio_buffer_obj_stream_p = { .is_text = false, }; -STATIC const mp_obj_type_t stdio_buffer_obj_type = { - { &mp_type_type }, - .name = MP_QSTR_FileIO, - .print = stdio_obj_print, - .getiter = mp_identity_getiter, - .iternext = mp_stream_unbuffered_iter, - .protocol = &stdio_buffer_obj_stream_p, - .locals_dict = (mp_obj_dict_t *)&stdio_locals_dict, -}; +STATIC MP_DEFINE_CONST_OBJ_TYPE( + stdio_buffer_obj_type, + MP_QSTR_FileIO, + MP_TYPE_FLAG_NONE, + MP_TYPE_NULL_MAKE_NEW, + print, stdio_obj_print, + getiter, mp_identity_getiter, + iternext, mp_stream_unbuffered_iter, + protocol, &stdio_buffer_obj_stream_p, + locals_dict, (mp_obj_dict_t *)&stdio_locals_dict + ); STATIC const sys_stdio_obj_t stdio_buffer_obj = {{&stdio_buffer_obj_type}, .fd = 0}; // fd unused #endif