diff --git a/.github/workflows/build.yml b/.github/workflows/build.yml index 2f2b08154..67d13acf1 100644 --- a/.github/workflows/build.yml +++ b/.github/workflows/build.yml @@ -31,7 +31,7 @@ jobs: uses: actions/upload-artifact@v3 with: name: mpy-cross - path: micropython/mpy-cross/mpy-cross + path: micropython/mpy-cross/build/mpy-cross unix_coverage: name: unix coverage @@ -48,9 +48,9 @@ jobs: uses: actions/download-artifact@v3 with: name: mpy-cross - path: micropython/mpy-cross + path: micropython/mpy-cross/build - name: Fix file permission - run: chmod +x micropython/mpy-cross/mpy-cross + run: chmod +x micropython/mpy-cross/build/mpy-cross - name: Build run: | cd micropython @@ -62,7 +62,7 @@ jobs: run: | cd micropython make -C ports/unix VARIANT=coverage test_full - (cd tests && MICROPY_CPYTHON3=python3 MICROPY_MICROPYTHON=../ports/unix/micropython-coverage ./run-multitests.py multi_net/*.py) + (cd tests && MICROPY_CPYTHON3=python3 MICROPY_MICROPYTHON=../ports/unix/build-coverage/micropython ./run-multitests.py multi_net/*.py) - name: List failed tests if: failure() run: micropython/tests/run-tests.py --print-failures @@ -104,7 +104,7 @@ jobs: uses: actions/upload-artifact@v3 with: name: pybricks-micropython-build-${{ github.run_number }} - path: bricks/ev3dev/pybricks-micropython + path: bricks/ev3dev/build-armel/pybricks-micropython ev3dev_ubuntu_lts: name: ev3dev-ubuntu-lts @@ -138,9 +138,9 @@ jobs: uses: actions/download-artifact@v3 with: name: mpy-cross - path: micropython/mpy-cross + path: micropython/mpy-cross/build - name: Fix file permission - run: chmod +x micropython/mpy-cross/mpy-cross + run: chmod +x micropython/mpy-cross/build/mpy-cross - name: Build run: make $MAKEOPTS -C bricks/ev3dev - name: Test @@ -172,9 +172,9 @@ jobs: uses: actions/download-artifact@v3 with: name: mpy-cross - path: micropython/mpy-cross + path: micropython/mpy-cross/build - name: Fix file permission - run: chmod +x micropython/mpy-cross/mpy-cross + run: chmod +x micropython/mpy-cross/build/mpy-cross - name: Install python uses: actions/setup-python@v4 with: @@ -227,9 +227,9 @@ jobs: uses: actions/download-artifact@v3 with: name: mpy-cross - path: micropython/mpy-cross + path: micropython/mpy-cross/build - name: Fix file permission - run: chmod +x micropython/mpy-cross/mpy-cross + run: chmod +x micropython/mpy-cross/build/mpy-cross - name: Build and test run: COVERAGE=1 ./test-virtualhub.sh - name: Coveralls @@ -256,9 +256,9 @@ jobs: uses: actions/download-artifact@v3 with: name: mpy-cross - path: micropython/mpy-cross + path: micropython/mpy-cross/build - name: Fix file permission - run: chmod +x micropython/mpy-cross/mpy-cross + run: chmod +x micropython/mpy-cross/build/mpy-cross - name: Build run: make $MAKEOPTS -C bricks/ev3rt @@ -278,9 +278,9 @@ jobs: uses: actions/download-artifact@v3 with: name: mpy-cross - path: micropython/mpy-cross + path: micropython/mpy-cross/build - name: Fix file permission - run: chmod +x micropython/mpy-cross/mpy-cross + run: chmod +x micropython/mpy-cross/build/mpy-cross - name: Build run: make $MAKEOPTS -C bricks/debug build/firmware.dfu diff --git a/.vscode/launch.json b/.vscode/launch.json index 1a3d686a7..dd30a9c98 100644 --- a/.vscode/launch.json +++ b/.vscode/launch.json @@ -66,7 +66,7 @@ "type": "cppdbg", "request": "launch", "cwd": "${workspaceFolder}/micropython/tests", - "program": "${workspaceFolder}/bricks/ev3dev/pybricks-micropython", + "program": "${workspaceFolder}/bricks/ev3dev/build-test/pybricks-micropython", "args": [ "../../tests/ev3dev/brick/battery.py" ], @@ -187,7 +187,7 @@ "name": "(gdb) Attach", "type": "cppdbg", "request": "attach", - "program": "${workspaceFolder}/bricks/ev3dev/pybricks-micropython", + "program": "${workspaceFolder}/bricks/ev3dev/built-test/pybricks-micropython", "processId": "${command:pickProcess}", "MIMode": "gdb", "setupCommands": [ diff --git a/.vscode/tasks.json b/.vscode/tasks.json index 7cfa80ac2..2321af2db 100644 --- a/.vscode/tasks.json +++ b/.vscode/tasks.json @@ -6,12 +6,12 @@ { "label": "build ev3dev-test", "type": "shell", - "command": "poetry run make -C bricks/ev3dev pybricks-micropython build-test/libgrx-3.0-vdriver-test.so DEBUG=1 COPT=-O0 BUILD=build-test CROSS_COMPILE= -j" + "command": "poetry run make -C bricks/ev3dev build-test/pybricks-micropython build-test/libgrx-3.0-vdriver-test.so DEBUG=1 COPT=-O0 BUILD=build-test CROSS_COMPILE= -j" }, { "label": "build ev3dev deploy", "type": "shell", - "command": "make ev3dev-armel -j && cp bricks/ev3dev/pybricks-micropython /run/user/1000/gvfs/sftp:host=*/home/robot" + "command": "make ev3dev-armel -j && cp bricks/ev3dev/build-armel/pybricks-micropython /run/user/1000/gvfs/sftp:host=*/home/robot" }, { "label": "build virtualhub", diff --git a/CHANGELOG.md b/CHANGELOG.md index 788a7e152..0e268156a 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -4,6 +4,9 @@ ## [Unreleased] +### Changed +- Updated MicroPython to v1.20.0. + ## [3.3.0b4] - 2023-04-21 ### Fixed diff --git a/Makefile b/Makefile index a444ff3e4..794d53ab6 100644 --- a/Makefile +++ b/Makefile @@ -1,5 +1,5 @@ # SPDX-License-Identifier: MIT -# Copyright (c) 2019-2022 The Pybricks Authors +# Copyright (c) 2019-2023 The Pybricks Authors # ensure micropython submodule is checked out for building mpy-cross ifeq ("$(wildcard micropython/README.md)","") @@ -30,7 +30,7 @@ clean-doc: all: movehub cityhub technichub primehub essentialhub virtualhub nxt debug ev3rt doc -clean-all: clean-movehub clean-cityhub clean-technichub clean-primehub clean-essentialhub clean-virtualhub clean-nxt clean-debug clean-doc +clean-all: clean-movehub clean-cityhub clean-technichub clean-primehub clean-essentialhub clean-virtualhub clean-nxt clean-debug clean-ev3rt clean-doc ifeq ($(HOST_OS),Linux) diff --git a/bricks/_common/arm_none_eabi.mk b/bricks/_common/arm_none_eabi.mk index e5101ce6e..2a7f05dbc 100644 --- a/bricks/_common/arm_none_eabi.mk +++ b/bricks/_common/arm_none_eabi.mk @@ -175,8 +175,6 @@ CFLAGS += -DSTM32_H='' CFLAGS += -DSTM32_HAL_H='' endif -MPY_CROSS = $(PBTOP)/micropython/mpy-cross/mpy-cross - LIBS = "$(shell $(CC) $(CFLAGS) -print-libgcc-file-name)" # Sources and libraries common to all pybricks bricks @@ -192,6 +190,7 @@ include $(PBTOP)/bricks/_common/sources.mk # between the top level directory and the micropython/ subdirectory. PY_EXTRA_SRC_C = $(addprefix shared/,\ + libc/printf.c \ libc/string0.c \ readline/readline.c \ runtime/gchelper_native.c \ diff --git a/bricks/_common/micropython.c b/bricks/_common/micropython.c index c392bc2aa..2ef2c045b 100644 --- a/bricks/_common/micropython.c +++ b/bricks/_common/micropython.c @@ -48,7 +48,19 @@ void pb_event_poll_hook(void) { // callback for when stop button is pressed in IDE or on hub void pbsys_main_stop_program(bool force_stop) { - mp_sched_system_exit_or_abort(force_stop); + if (force_stop) { + mp_sched_vm_abort(); + } else { + pyexec_system_exit = PYEXEC_FORCED_EXIT; + + static mp_obj_exception_t system_exit; + system_exit.base.type = &mp_type_SystemExit; + system_exit.traceback_alloc = system_exit.traceback_len = 0; + system_exit.traceback_data = NULL; + system_exit.args = (mp_obj_tuple_t *)&mp_const_empty_tuple_obj; + + mp_sched_exception(MP_OBJ_FROM_PTR(&system_exit)); + } } bool pbsys_main_stdin_event(uint8_t c) { @@ -91,8 +103,8 @@ static void mp_vfs_map_minimal_new_reader(mp_reader_t *reader, mp_vfs_map_minima // Prints the exception that ended the program. static void print_final_exception(mp_obj_t exc) { - // Handle graceful stop with button or shutdown. - if (mp_obj_exception_match(exc, MP_OBJ_FROM_PTR(&mp_type_SystemAbort)) || + // Handle graceful stop with button. + if (pyexec_system_exit == PYEXEC_FORCED_EXIT && mp_obj_exception_match(exc, MP_OBJ_FROM_PTR(&mp_type_SystemExit))) { mp_printf(&mp_plat_print, "The program was stopped (%q).\n", ((mp_obj_exception_t *)MP_OBJ_TO_PTR(exc))->base.type->name); @@ -105,19 +117,31 @@ static void print_final_exception(mp_obj_t exc) { #if PYBRICKS_OPT_COMPILER static void run_repl(void) { - // Reset REPL history. readline_init0(); + pyexec_system_exit = 0; + nlr_buf_t nlr; + nlr.ret_val = NULL; + if (nlr_push(&nlr) == 0) { + nlr_set_abort(&nlr); // Run the REPL. pyexec_friendly_repl(); nlr_pop(); } else { + // if vm abort + if (nlr.ret_val == NULL) { + // we are shutting down, so don't bother with cleanup + return; + } + // clear any pending exceptions (and run any callbacks). mp_handle_pending(false); // Print which exception triggered this. print_final_exception(MP_OBJ_FROM_PTR(nlr.ret_val)); } + + nlr_set_abort(NULL); } #endif @@ -203,9 +227,14 @@ static mpy_info_t *mpy_data_find(qstr name) { * Runs the __main__ module from user RAM. */ static void run_user_program(void) { + pyexec_system_exit = 0; nlr_buf_t nlr; + nlr.ret_val = NULL; + if (nlr_push(&nlr) == 0) { + nlr_set_abort(&nlr); + mpy_info_t *info = mpy_data_find(MP_QSTR___main__); if (!info) { @@ -218,7 +247,9 @@ static void run_user_program(void) { mp_vfs_map_minimal_new_reader(&reader, &data, mpy_data_get_buf(info), pbio_get_uint32_le(info->mpy_size)); mp_module_context_t *context = m_new_obj(mp_module_context_t); context->module.globals = mp_globals_get(); - mp_compiled_module_t compiled_module = mp_raw_code_load(&reader, context); + mp_compiled_module_t compiled_module; + compiled_module.context = context; + mp_raw_code_load(&reader, &compiled_module); mp_obj_t module_fun = mp_make_function_from_raw_code(compiled_module.rc, context, NULL); // Run the script while letting CTRL-C interrupt it. @@ -231,8 +262,15 @@ static void run_user_program(void) { nlr_pop(); } else { - // Clear any pending exceptions (and run any callbacks). mp_hal_set_interrupt_char(-1); + + // if vm abort + if (nlr.ret_val == NULL) { + // we are shutting down, so don't bother with cleanup + return; + } + + // Clear any pending exceptions (and run any callbacks). mp_handle_pending(false); print_final_exception(MP_OBJ_FROM_PTR(nlr.ret_val)); @@ -251,6 +289,8 @@ static void run_user_program(void) { } #endif } + + nlr_set_abort(NULL); } // Runs MicroPython with the given program data. @@ -340,7 +380,9 @@ mp_obj_t pb_builtin_import(size_t n_args, const mp_obj_t *args) { // Create new module and execute in its own context. mp_obj_t module_obj = mp_obj_new_module(module_name_qstr); mp_module_context_t *context = MP_OBJ_TO_PTR(module_obj); - mp_compiled_module_t compiled_module = mp_raw_code_load(&reader, context); + mp_compiled_module_t compiled_module; + compiled_module.context = context; + mp_raw_code_load(&reader, &compiled_module); do_execute_raw_code(context, compiled_module.rc, compiled_module.context); // Return the newly imported module. diff --git a/bricks/_common/mpconfigport.h b/bricks/_common/mpconfigport.h index 96595205c..0a0b2a4b5 100644 --- a/bricks/_common/mpconfigport.h +++ b/bricks/_common/mpconfigport.h @@ -1,5 +1,5 @@ // SPDX-License-Identifier: MIT -// Copyright (c) 2019-2022 The Pybricks Authors +// Copyright (c) 2019-2023 The Pybricks Authors // Common configuration of Pybricks MicroPython ports. @@ -106,6 +106,7 @@ #define MICROPY_FLOAT_IMPL (MICROPY_FLOAT_IMPL_NONE) #endif #define MICROPY_KBD_EXCEPTION (1) +#define MICROPY_ENABLE_VM_ABORT (1) #define MICROPY_ENABLE_SCHEDULER (0) #define MICROPY_PY_INSTANCE_ATTRS (1) diff --git a/bricks/_common_stm32/mpconfigport.h b/bricks/_common_stm32/mpconfigport.h index 893580784..bd4a3a5e1 100644 --- a/bricks/_common_stm32/mpconfigport.h +++ b/bricks/_common_stm32/mpconfigport.h @@ -1,6 +1,6 @@ // SPDX-License-Identifier: MIT // Copyright (c) 2013, 2014 Damien P. George -// Copyright (c) 2018-2022 The Pybricks Authors +// Copyright (c) 2018-2023 The Pybricks Authors // Contains the MicroPython configuration for all STM32-based Pybricks ports. @@ -67,7 +67,3 @@ static inline mp_uint_t disable_irq(void) { #include #define MP_STATE_PORT MP_STATE_VM - -#define MICROPY_PORT_ROOT_POINTERS \ - mp_obj_dict_t *pb_type_Color_dict; \ - const char *readline_hist[8]; diff --git a/bricks/ev3dev/Makefile b/bricks/ev3dev/Makefile index dd8b88116..895ff0b8a 100644 --- a/bricks/ev3dev/Makefile +++ b/bricks/ev3dev/Makefile @@ -1,6 +1,6 @@ # SPDX-License-Identifier: MIT # Copyright (c) 2013, 2014 Damien P. George -# Copyright (c) 2019-2022 The Pybricks Authors +# Copyright (c) 2019-2023 The Pybricks Authors # ensure required git submodules checked out ifeq ("$(wildcard ../../micropython/README.md)","") @@ -24,6 +24,13 @@ ifeq ("$(wildcard ../../micropython/lib/berkeley-db-1.xx/README)","") $(error failed) endif endif +ifeq ("$(wildcard ../../micropython/lib/micropython-lib/README.md)","") +$(info GIT cloning micropython-lib submodule) +$(info $(shell cd ../../micropython && git submodule update --init lib/micropython-lib)) +ifeq ("$(wildcard ../../micropython/lib/micropython-lib/README.md)","") +$(error failed) +endif +endif # lets micropython make files work with external files USER_C_MODULES = ../.. @@ -47,6 +54,7 @@ UNAME_S := $(shell uname -s) # include py core make definitions include $(TOP)/py/py.mk +include $(TOP)/extmod/extmod.mk INC += -I. INC += -I$(TOP) @@ -213,11 +221,12 @@ SRC_C += $(SRC_MOD) SHARED_SRC_C += $(addprefix shared/,\ runtime/gchelper_generic.c \ - runtime/pyexec.c \ timeutils/timeutils.c \ $(SHARED_SRC_C_EXTRA) \ ) +SRC_CXX += \ + # Pybricks port core source files PYBRICKS_SRC_C += \ ev3dev_mphal.c \ @@ -242,17 +251,18 @@ EV3DEV_LIB_SRC_C = $(addprefix lib/,\ OBJ = $(PY_O) OBJ += $(addprefix $(BUILD)/, $(SRC_C:.c=.o)) +OBJ += $(addprefix $(BUILD)/, $(SRC_CXX:.cpp=.o)) OBJ += $(addprefix $(BUILD)/, $(SHARED_SRC_C:.c=.o)) OBJ += $(addprefix $(BUILD)/, $(CONTIKI_SRC_C:.c=.o)) OBJ += $(addprefix $(BUILD)/, $(EV3DEV_LIB_SRC_C:.c=.o)) -OBJ += $(addprefix $(BUILD)/, $(EXTMOD_SRC_C:.c=.o)) +OBJ += $(addprefix $(BUILD)/, $(SRC_EXTMOD_C:.c=.o)) OBJ += $(addprefix $(BUILD)/, $(PBIO_SRC_C:.c=.o)) OBJ += $(addprefix $(BUILD)/, $(PY_EXTRA_SRC_C:.c=.o)) OBJ += $(addprefix $(BUILD)/, $(PYBRICKS_PYBRICKS_SRC_C:.c=.o)) OBJ += $(addprefix $(BUILD)/, $(PYBRICKS_SRC_C:.c=.o)) # List of sources for qstr extraction -SRC_QSTR += $(SRC_C) $(SHARED_SRC_C) $(PY_EXTRA_SRC_C) $(EXTMOD_SRC_C) $(PYBRICKS_SRC_C) $(PYBRICKS_PYBRICKS_SRC_C) +SRC_QSTR += $(SRC_C) $(SHARED_SRC_C) $(PY_EXTRA_SRC_C) $(SRC_EXTMOD_C) $(PYBRICKS_SRC_C) $(PYBRICKS_PYBRICKS_SRC_C) # Append any auto-generated sources that are needed by sources listed in # SRC_QSTR SRC_QSTR_AUTO_DEPS += @@ -263,9 +273,6 @@ ifneq ($(FROZEN_MANIFEST),) CFLAGS += -DMICROPY_QSTR_EXTRA_POOL=mp_qstr_frozen_const_pool CFLAGS += -DMICROPY_MODULE_FROZEN_MPY CFLAGS += -DMPZ_DIG_SIZE=16 # force 16 bits to work on both 32 and 64 bit archs -endif - -ifneq ($(FROZEN_MANIFEST),) CFLAGS += -DMICROPY_MODULE_FROZEN_STR endif @@ -292,14 +299,14 @@ $(GRX_TEST_PLUGIN_OBJ): ../../tests/ev3dev/grx-plugin.c $(GRX_TEST_PLUGIN_LIB): $(GRX_TEST_PLUGIN_OBJ) $(Q)$(CC) -shared -o $@ $^ $(LDFLAGS) -test-ev3dev: $(PROG) $(TOP)/tests/run-tests.py $(GRX_TEST_PLUGIN_LIB) - cd $(TOP)/tests && MICROPY_MICROPYTHON="../../tests/ev3dev/test-wrapper.sh" \ +test-ev3dev: $(BUILD)/$(PROG) $(TOP)/tests/run-tests.py $(GRX_TEST_PLUGIN_LIB) + cd $(TOP)/tests && PYBRICKS_MICROPYTHON="$(realpath $<)" MICROPY_MICROPYTHON="../../tests/ev3dev/test-wrapper.sh" \ GRX_PLUGIN_PATH=$(realpath $(BUILD)) GRX_DRIVER=test \ ./run-tests.py --test-dirs $(EV3DEV_TEST_DIRS) -test: $(PROG) $(TOP)/tests/run-tests.py $(GRX_TEST_PLUGIN_LIB) +test: $(BUILD)/$(PROG) $(TOP)/tests/run-tests.py $(GRX_TEST_PLUGIN_LIB) $(eval DIRNAME=../bricks/$(notdir $(CURDIR))) - cd $(TOP)/tests && MICROPY_MICROPYTHON="../../tests/ev3dev/test-wrapper.sh" \ + cd $(TOP)/tests && PYBRICKS_MICROPYTHON="$(realpath $<)" MICROPY_MICROPYTHON="../../tests/ev3dev/test-wrapper.sh" \ GRX_PLUGIN_PATH=$(realpath $(BUILD)) GRX_DRIVER=test \ ./run-tests.py @@ -314,9 +321,9 @@ endif PREFIX = /usr/local BINDIR = $(DESTDIR)$(PREFIX)/bin -install: $(PROG) +install: $(BUILD)/$(PROG) install -d $(BINDIR) - install $(PROG) $(BINDIR)/$(PROG) + install $(BUILD)/$(PROG) $(BINDIR)/$(PROG) uninstall: -rm $(BINDIR)/$(PROG) diff --git a/bricks/ev3dev/README.md b/bricks/ev3dev/README.md index 4f00c419b..e85b0d224 100644 --- a/bricks/ev3dev/README.md +++ b/bricks/ev3dev/README.md @@ -27,7 +27,7 @@ sudo ln -s /home/robot/pybricks-micropython /usr/bin/pybricks-micropython Once you've followed the steps above, you can build and deploy using: ``` -make ev3dev-armel && cp bricks/ev3dev/pybricks-micropython /run/user/1000/gvfs/sftp:host=*,user=robot/home/robot +make ev3dev-armel && cp bricks/ev3dev/build-armel/pybricks-micropython /run/user/1000/gvfs/sftp:host=*,user=robot/home/robot ``` Then all pybricks-micropython tools and projects will use the new build without diff --git a/bricks/ev3dev/docker/README.md b/bricks/ev3dev/docker/README.md index b11d947e7..608853d2b 100644 --- a/bricks/ev3dev/docker/README.md +++ b/bricks/ev3dev/docker/README.md @@ -15,7 +15,7 @@ submodules and have built `mpy-cross` for the host OS (`make -C mpy-cross`). 3. Transfer the generated `pybricks-micropython` to the EV3 Brick. - scp bricks/ev3dev/pybricks-micropython robot@ev3dev:~ + scp bricks/ev3dev/build-armel/pybricks-micropython robot@ev3dev:~ 4. Run it on the EV3. diff --git a/bricks/ev3dev/docker/setup.sh b/bricks/ev3dev/docker/setup.sh index 1aa10ac79..efa9a2693 100755 --- a/bricks/ev3dev/docker/setup.sh +++ b/bricks/ev3dev/docker/setup.sh @@ -73,6 +73,7 @@ docker run \ --name ${container_name} \ --env "TERM=${TERM}" \ --env "DESTDIR=/build/dist" \ + --env "MICROPY_MPYCROSS=/src/micropython/mpy-cross/build-armel/mpy-cross" \ --user $(id -u):$(id -g) \ --tty \ --detach \ diff --git a/bricks/ev3dev/manifest.py b/bricks/ev3dev/manifest.py index f36556e58..8dd552435 100644 --- a/bricks/ev3dev/manifest.py +++ b/bricks/ev3dev/manifest.py @@ -1,3 +1 @@ freeze_as_mpy("./modules") -freeze_as_mpy("$(MPY_DIR)/tools", "upip.py") -freeze_as_mpy("$(MPY_DIR)/tools", "upip_utarfile.py", opt=3) diff --git a/bricks/ev3dev/mpconfigport.h b/bricks/ev3dev/mpconfigport.h index 21c68d27e..557fb5c85 100644 --- a/bricks/ev3dev/mpconfigport.h +++ b/bricks/ev3dev/mpconfigport.h @@ -1,6 +1,6 @@ // SPDX-License-Identifier: MIT // Copyright (c) 2013, 2014 Damien P. George -// Copyright (c) 2018-2022 The Pybricks Authors +// Copyright (c) 2018-2023 The Pybricks Authors // Pybricks brick specific definitions #include "brickconfig.h" @@ -143,6 +143,7 @@ static const char pybricks_ev3dev_help_text[] = #define MICROPY_MODULE_GETATTR (1) #define MICROPY_PY_DELATTR_SETATTR (1) #define MICROPY_PY_REVERSE_SPECIAL_METHODS (1) +#define MICROPY_PY_BUILTINS_BYTES_HEX (1) #define MICROPY_PY_BUILTINS_MEMORYVIEW_ITEMSIZE (1) #define MICROPY_PY_BUILTINS_NEXT2 (1) #define MICROPY_PY_BUILTINS_RANGE_BINOP (1) @@ -363,12 +364,6 @@ struct _mp_bluetooth_nimble_malloc_t; #define MICROPY_BLUETOOTH_ROOT_POINTERS #endif -#define MICROPY_PORT_ROOT_POINTERS \ - mp_obj_dict_t *pb_type_Color_dict; \ - const char *readline_hist[50]; \ - void *mmap_region_head; \ - MICROPY_BLUETOOTH_ROOT_POINTERS \ - // We need to provide a declaration/definition of alloca() // unless support for it is disabled. #if !defined(MICROPY_NO_ALLOCA) || MICROPY_NO_ALLOCA == 0 diff --git a/bricks/ev3dev/pb_type_ev3dev_font.c b/bricks/ev3dev/pb_type_ev3dev_font.c index a5161158d..bc1304f76 100644 --- a/bricks/ev3dev/pb_type_ev3dev_font.c +++ b/bricks/ev3dev/pb_type_ev3dev_font.c @@ -1,6 +1,6 @@ // SPDX-License-Identifier: MIT // Copyright (c) 2013, 2014 Damien P. George -// Copyright (c) 2019-2021 The Pybricks Authors +// Copyright (c) 2019-2023 The Pybricks Authors // class Screen @@ -151,14 +151,13 @@ STATIC const mp_rom_map_elem_t ev3dev_Font_locals_dict_table[] = { }; STATIC MP_DEFINE_CONST_DICT(ev3dev_Font_locals_dict, ev3dev_Font_locals_dict_table); -const mp_obj_type_t pb_type_ev3dev_Font = { - { &mp_type_type }, - .name = MP_QSTR_Font, - .make_new = ev3dev_Font_make_new, - .attr = pb_attribute_handler, - .protocol = ev3dev_Font_attr_dict, - .locals_dict = (mp_obj_dict_t *)&ev3dev_Font_locals_dict, -}; +MP_DEFINE_CONST_OBJ_TYPE(pb_type_ev3dev_Font, + MP_QSTR_Font, + MP_TYPE_FLAG_NONE, + make_new, ev3dev_Font_make_new, + attr, pb_attribute_handler, + protocol, ev3dev_Font_attr_dict, + locals_dict, &ev3dev_Font_locals_dict); GrxFont *pb_ev3dev_Font_obj_get_font(mp_const_obj_t obj) { if (!mp_obj_is_type(obj, &pb_type_ev3dev_Font)) { diff --git a/bricks/ev3dev/pb_type_ev3dev_image.c b/bricks/ev3dev/pb_type_ev3dev_image.c index 4e5ee5ddb..74f3324db 100644 --- a/bricks/ev3dev/pb_type_ev3dev_image.c +++ b/bricks/ev3dev/pb_type_ev3dev_image.c @@ -1,6 +1,6 @@ // SPDX-License-Identifier: MIT // Copyright (c) 2013, 2014 Damien P. George -// Copyright (c) 2019-2021 The Pybricks Authors +// Copyright (c) 2019-2023 The Pybricks Authors // class Image // @@ -408,13 +408,15 @@ STATIC mp_obj_t ev3dev_Image_draw_text(size_t n_args, const mp_obj_t *pos_args, mp_int_t x = pb_obj_get_int(x_in); mp_int_t y = pb_obj_get_int(y_in); + if (!mp_obj_is_str_or_bytes(text_in)) { vstr_t vstr; mp_print_t print; vstr_init_print(&vstr, 16, &print); mp_obj_print_helper(&print, text_in, PRINT_STR); - text_in = mp_obj_new_str_from_vstr(&mp_type_str, &vstr); + text_in = mp_obj_new_str_from_vstr(&vstr); } + const char *text = mp_obj_str_get_str(text_in); GrxColor text_color = map_color(text_color_in); GrxColor background_color = map_color(background_color_in); @@ -570,11 +572,10 @@ STATIC const mp_rom_map_elem_t ev3dev_Image_locals_dict_table[] = { }; STATIC MP_DEFINE_CONST_DICT(ev3dev_Image_locals_dict, ev3dev_Image_locals_dict_table); -const mp_obj_type_t pb_type_ev3dev_Image = { - { &mp_type_type }, - .name = MP_QSTR_Image, - .make_new = ev3dev_Image_make_new, - .attr = pb_attribute_handler, - .protocol = ev3dev_Image_attr_dict, - .locals_dict = (mp_obj_dict_t *)&ev3dev_Image_locals_dict, -}; +MP_DEFINE_CONST_OBJ_TYPE(pb_type_ev3dev_Image, + MP_QSTR_Image, + MP_TYPE_FLAG_NONE, + make_new, ev3dev_Image_make_new, + attr, pb_attribute_handler, + protocol, ev3dev_Image_attr_dict, + locals_dict, &ev3dev_Image_locals_dict); diff --git a/bricks/ev3dev/pb_type_ev3dev_speaker.c b/bricks/ev3dev/pb_type_ev3dev_speaker.c index dbfd08291..ade1b37bd 100644 --- a/bricks/ev3dev/pb_type_ev3dev_speaker.c +++ b/bricks/ev3dev/pb_type_ev3dev_speaker.c @@ -1,5 +1,5 @@ // SPDX-License-Identifier: MIT -// Copyright (c) 2018-2020 The Pybricks Authors +// Copyright (c) 2018-2023 The Pybricks Authors // class Speaker // @@ -657,9 +657,8 @@ STATIC const mp_rom_map_elem_t ev3dev_Speaker_locals_dict_table[] = { }; STATIC MP_DEFINE_CONST_DICT(ev3dev_Speaker_locals_dict, ev3dev_Speaker_locals_dict_table); -const mp_obj_type_t pb_type_ev3dev_Speaker = { - { &mp_type_type }, - .name = MP_QSTR_Speaker, - .make_new = ev3dev_Speaker_make_new, - .locals_dict = (mp_obj_dict_t *)&ev3dev_Speaker_locals_dict, -}; +MP_DEFINE_CONST_OBJ_TYPE(pb_type_ev3dev_Speaker, + MP_QSTR_Speaker, + MP_TYPE_FLAG_NONE, + make_new, ev3dev_Speaker_make_new, + locals_dict, &ev3dev_Speaker_locals_dict); diff --git a/bricks/ev3rt/Makefile b/bricks/ev3rt/Makefile index 3e3452517..eb4e3b442 100644 --- a/bricks/ev3rt/Makefile +++ b/bricks/ev3rt/Makefile @@ -108,6 +108,7 @@ PY_EMBEDDED_SRC_C = $(addprefix bricks/,\ # between the top level directory and the micropython/ subdirectory. PY_EXTRA_SRC_C += $(addprefix shared/,\ + libc/printf.c \ libc/string0.c \ readline/readline.c \ runtime/gchelper_native.c \ diff --git a/bricks/ev3rt/mpconfigport.h b/bricks/ev3rt/mpconfigport.h index 74f350f7e..d8e684620 100644 --- a/bricks/ev3rt/mpconfigport.h +++ b/bricks/ev3rt/mpconfigport.h @@ -1,6 +1,6 @@ // SPDX-License-Identifier: MIT // Copyright (c) 2013, 2014 Damien P. George -// Copyright (c) 2018-2022 The Pybricks Authors +// Copyright (c) 2018-2023 The Pybricks Authors #include #include @@ -114,7 +114,3 @@ static inline mp_uint_t disable_irq(void) { #include #define MP_STATE_PORT MP_STATE_VM - -#define MICROPY_PORT_ROOT_POINTERS \ - mp_obj_dict_t *pb_type_Color_dict; \ - const char *readline_hist[8]; diff --git a/bricks/nxt/mpconfigport.h b/bricks/nxt/mpconfigport.h index 7b076ba8b..8c401d621 100644 --- a/bricks/nxt/mpconfigport.h +++ b/bricks/nxt/mpconfigport.h @@ -91,7 +91,3 @@ void nx_interrupts_enable(uint32_t); } while (0); #define MP_STATE_PORT MP_STATE_VM - -#define MICROPY_PORT_ROOT_POINTERS \ - mp_obj_dict_t *pb_type_Color_dict; \ - const char *readline_hist[8]; diff --git a/bricks/virtualhub/mpconfigvariant.h b/bricks/virtualhub/mpconfigvariant.h index 378ee4b93..2c87a115e 100644 --- a/bricks/virtualhub/mpconfigvariant.h +++ b/bricks/virtualhub/mpconfigvariant.h @@ -1,5 +1,5 @@ // SPDX-License-Identifier: MIT -// Copyright (c) 2022 The Pybricks Authors +// Copyright (c) 2022-2023 The Pybricks Authors #define PYBRICKS_HUB_CLASS_NAME (MP_QSTR_VirtualHub) @@ -42,14 +42,23 @@ #define PYBRICKS_OPT_CUSTOM_IMPORT (1) // Upstream MicroPython options +#define MICROPY_FLOAT_IMPL (MICROPY_FLOAT_IMPL_FLOAT) +#define MICROPY_LONGINT_IMPL (MICROPY_LONGINT_IMPL_LONGLONG) #define MICROPY_MODULE_ATTR_DELEGATION (1) #define MICROPY_MODULE_BUILTIN_INIT (1) #define MICROPY_PY_BUILTINS_HELP (1) #define MICROPY_PY_BUILTINS_HELP_MODULES (1) #define MICROPY_PY_SYS_SETTRACE (1) -#define MICROPY_PERSISTENT_CODE_SAVE (1) +#define MICROPY_PY_UERRNO (1) +#define MICROPY_PY_UOS (1) +#define MICROPY_PY_UOS_GETENV_PUTENV_UNSETENV (1) +#define MICROPY_PY_UOS_INCLUDEFILE "ports/unix/moduos.c" #define MICROPY_PY_URANDOM_EXTRA_FUNCS (1) #define MICROPY_PY_BUILTINS_SLICE_INDICES (1) +#define MICROPY_PERSISTENT_CODE_SAVE (1) +#define MICROPY_STREAMS_POSIX_API (1) +#define MICROPY_HELPER_REPL (1) +#define MICROPY_KBD_EXCEPTION (1) // REVISIT: This list currently matches the stm32 builds. We may consider // adding more like the ev3dev build. @@ -77,9 +86,6 @@ pb_virtualhub_port_deinit(); \ } while (0) -#define MICROPY_VARIANT_ROOT_POINTERS \ - mp_obj_dict_t *pb_type_Color_dict; - #define MICROPY_VM_HOOK_LOOP do { \ extern void pb_virtualhub_poll(void); \ pb_virtualhub_poll(); \ diff --git a/bricks/virtualhub/mpconfigvariant.mk b/bricks/virtualhub/mpconfigvariant.mk index 0ccf3bb07..c62c464b7 100644 --- a/bricks/virtualhub/mpconfigvariant.mk +++ b/bricks/virtualhub/mpconfigvariant.mk @@ -1,5 +1,5 @@ # SPDX-License-Identifier: MIT -# Copyright (c) 2022 The Pybricks Authors +# Copyright (c) 2022-2023 The Pybricks Authors ############################### # Standard MicroPython config # @@ -31,10 +31,10 @@ MICROPY_PY_SOCKET = 1 MICROPY_PY_FFI = 1 # ussl module requires one of the TLS libraries below -MICROPY_PY_USSL = 1 +MICROPY_PY_USSL = 0 # axTLS has minimal size but implements only a subset of modern TLS # functionality, so may have problems with some servers. -MICROPY_SSL_AXTLS = 1 +MICROPY_SSL_AXTLS = 0 # mbedTLS is more up to date and complete implementation, but also # more bloated. MICROPY_SSL_MBEDTLS = 0 @@ -46,6 +46,10 @@ MICROPY_PY_JNI = 0 # as submodules (currently affects only libffi). MICROPY_STANDALONE = 0 +MICROPY_VFS_FAT = 0 +MICROPY_VFS_LFS1 = 0 +MICROPY_VFS_LFS2 = 0 + ###################### # Pybricks additions # ###################### @@ -62,9 +66,8 @@ INC += -I../../../lib/pbio/platform/virtual_hub PBIO_PLATFORM = virtual_hub include ../../../bricks/_common/sources.mk -EXTMOD_SRC_C += $(PYBRICKS_PYBRICKS_SRC_C) -LIB_SRC_C += $(CONTIKI_SRC_C) -LIB_SRC_C += $(PBIO_SRC_C) +SRC_EXTMOD_C += $(PYBRICKS_PYBRICKS_SRC_C) +SRC_THIRDPARTY_C += $(CONTIKI_SRC_C) $(PBIO_SRC_C) # realtime library for timer signals LIB += -lrt diff --git a/micropython b/micropython index 70b94d726..6c633a8dd 160000 --- a/micropython +++ b/micropython @@ -1 +1 @@ -Subproject commit 70b94d72648a1365f11058b9312d668d2fd0fe3e +Subproject commit 6c633a8dd9f7dd933dae709e9c697330a5d56cca diff --git a/pybricks/common/pb_type_charger.c b/pybricks/common/pb_type_charger.c index aed40b712..9ef7629ca 100644 --- a/pybricks/common/pb_type_charger.c +++ b/pybricks/common/pb_type_charger.c @@ -1,5 +1,5 @@ // SPDX-License-Identifier: MIT -// Copyright (c) 2021-2022 The Pybricks Authors +// Copyright (c) 2021-2023 The Pybricks Authors #include "py/mpconfig.h" @@ -43,11 +43,10 @@ STATIC const mp_rom_map_elem_t Charger_locals_dict_table[] = { }; STATIC MP_DEFINE_CONST_DICT(Charger_locals_dict, Charger_locals_dict_table); -const mp_obj_type_t pb_type_Charger = { - .base = { .type = &mp_type_type }, - .name = MP_QSTR_Charger, - .locals_dict = (mp_obj_dict_t *)&Charger_locals_dict, -}; +MP_DEFINE_CONST_OBJ_TYPE(pb_type_Charger, + MP_QSTR_Charger, + MP_TYPE_FLAG_NONE, + locals_dict, &Charger_locals_dict); mp_obj_t pb_type_Charger_obj_new(void) { pb_obj_Charger_t *self = mp_obj_malloc(pb_obj_Charger_t, &pb_type_Charger); diff --git a/pybricks/common/pb_type_colorlight_external.c b/pybricks/common/pb_type_colorlight_external.c index 8c3b03d57..3e9e5a974 100644 --- a/pybricks/common/pb_type_colorlight_external.c +++ b/pybricks/common/pb_type_colorlight_external.c @@ -1,5 +1,5 @@ // SPDX-License-Identifier: MIT -// Copyright (c) 2018-2021 The Pybricks Authors +// Copyright (c) 2018-2023 The Pybricks Authors #include "py/mpconfig.h" @@ -55,11 +55,10 @@ STATIC const mp_rom_map_elem_t common_ColorLight_external_locals_dict_table[] = STATIC MP_DEFINE_CONST_DICT(common_ColorLight_external_locals_dict, common_ColorLight_external_locals_dict_table); // type(pybricks.builtins.ColorLight) -STATIC const mp_obj_type_t pb_type_ColorLight_external = { - { &mp_type_type }, - .name = MP_QSTR_ColorLight, - .locals_dict = (mp_obj_dict_t *)&common_ColorLight_external_locals_dict, -}; +STATIC MP_DEFINE_CONST_OBJ_TYPE(pb_type_ColorLight_external, + MP_QSTR_ColorLight, + MP_TYPE_FLAG_NONE, + locals_dict, &common_ColorLight_external_locals_dict); // pybricks._common.ColorLight.__init__ mp_obj_t pb_type_ColorLight_external_obj_new(void *context, pb_type_ColorLight_on_t on) { diff --git a/pybricks/common/pb_type_colorlight_internal.c b/pybricks/common/pb_type_colorlight_internal.c index 1e03859fb..d6a0e573a 100644 --- a/pybricks/common/pb_type_colorlight_internal.c +++ b/pybricks/common/pb_type_colorlight_internal.c @@ -1,5 +1,5 @@ // SPDX-License-Identifier: MIT -// Copyright (c) 2018-2020 The Pybricks Authors +// Copyright (c) 2018-2023 The Pybricks Authors #include "py/mpconfig.h" @@ -136,11 +136,10 @@ STATIC const mp_rom_map_elem_t common_ColorLight_internal_locals_dict_table[] = STATIC MP_DEFINE_CONST_DICT(common_ColorLight_internal_locals_dict, common_ColorLight_internal_locals_dict_table); // type(pybricks.builtins.ColorLight) -STATIC const mp_obj_type_t pb_type_ColorLight_internal = { - { &mp_type_type }, - .name = MP_QSTR_ColorLight, - .locals_dict = (mp_obj_dict_t *)&common_ColorLight_internal_locals_dict, -}; +STATIC MP_DEFINE_CONST_OBJ_TYPE(pb_type_ColorLight_internal, + MP_QSTR_ColorLight, + MP_TYPE_FLAG_NONE, + locals_dict, &common_ColorLight_internal_locals_dict); // pybricks._common.ColorLight.__init__ mp_obj_t common_ColorLight_internal_obj_new(pbio_color_light_t *light) { diff --git a/pybricks/common/pb_type_control.c b/pybricks/common/pb_type_control.c index 8ecd0b5e8..d0aff56ea 100644 --- a/pybricks/common/pb_type_control.c +++ b/pybricks/common/pb_type_control.c @@ -1,5 +1,5 @@ // SPDX-License-Identifier: MIT -// Copyright (c) 2018-2022 The Pybricks Authors +// Copyright (c) 2018-2023 The Pybricks Authors #include @@ -302,12 +302,11 @@ STATIC const mp_rom_map_elem_t pb_type_Control_locals_dict_table[] = { STATIC MP_DEFINE_CONST_DICT(pb_type_Control_locals_dict, pb_type_Control_locals_dict_table); // type(pybricks.common.Control) -const mp_obj_type_t pb_type_Control = { - { &mp_type_type }, - .name = MP_QSTR_Control, - .attr = pb_attribute_handler, - .protocol = pb_type_Control_attr_dict, - .locals_dict = (mp_obj_dict_t *)&pb_type_Control_locals_dict, -}; +MP_DEFINE_CONST_OBJ_TYPE(pb_type_Control, + MP_QSTR_Control, + MP_TYPE_FLAG_NONE, + attr, pb_attribute_handler, + protocol, pb_type_Control_attr_dict, + locals_dict, &pb_type_Control_locals_dict); #endif // PYBRICKS_PY_COMMON_CONTROL diff --git a/pybricks/common/pb_type_dcmotor.c b/pybricks/common/pb_type_dcmotor.c index 2fcd143b9..6c8900186 100644 --- a/pybricks/common/pb_type_dcmotor.c +++ b/pybricks/common/pb_type_dcmotor.c @@ -1,5 +1,5 @@ // SPDX-License-Identifier: MIT -// Copyright (c) 2018-2022 The Pybricks Authors +// Copyright (c) 2018-2023 The Pybricks Authors #include "py/mpconfig.h" @@ -143,12 +143,11 @@ STATIC const mp_rom_map_elem_t common_DCMotor_locals_dict_table[] = { MP_DEFINE_CONST_DICT(common_DCMotor_locals_dict, common_DCMotor_locals_dict_table); // type(pybricks.builtins.DCMotor) -const mp_obj_type_t pb_type_DCMotor = { - { &mp_type_type }, - .name = MP_QSTR_DCMotor, - .print = common_DCMotor_print, - .make_new = common_DCMotor_make_new, - .locals_dict = (mp_obj_dict_t *)&common_DCMotor_locals_dict, -}; +MP_DEFINE_CONST_OBJ_TYPE(pb_type_DCMotor, + MP_QSTR_DCMotor, + MP_TYPE_FLAG_NONE, + print, common_DCMotor_print, + make_new, common_DCMotor_make_new, + locals_dict, &common_DCMotor_locals_dict); #endif // PYBRICKS_PY_COMMON_MOTORS diff --git a/pybricks/common/pb_type_imu.c b/pybricks/common/pb_type_imu.c index f13d9185a..935c5907e 100644 --- a/pybricks/common/pb_type_imu.c +++ b/pybricks/common/pb_type_imu.c @@ -1,5 +1,5 @@ // SPDX-License-Identifier: MIT -// Copyright (c) 2020-2022 The Pybricks Authors +// Copyright (c) 2020-2023 The Pybricks Authors #include "py/mpconfig.h" @@ -227,11 +227,10 @@ STATIC const mp_rom_map_elem_t common_IMU_locals_dict_table[] = { STATIC MP_DEFINE_CONST_DICT(common_IMU_locals_dict, common_IMU_locals_dict_table); // type(pybricks.common.IMU) -STATIC const mp_obj_type_t pb_type_IMU = { - { &mp_type_type }, - .name = MP_QSTR_IMU, - .locals_dict = (mp_obj_dict_t *)&common_IMU_locals_dict, -}; +STATIC MP_DEFINE_CONST_OBJ_TYPE(pb_type_IMU, + MP_QSTR_IMU, + MP_TYPE_FLAG_NONE, + locals_dict, &common_IMU_locals_dict); STATIC common_IMU_obj_t singleton_imu_obj = { .base.type = &pb_type_IMU, diff --git a/pybricks/common/pb_type_keypad.c b/pybricks/common/pb_type_keypad.c index 97b38c45d..e3e889c7c 100644 --- a/pybricks/common/pb_type_keypad.c +++ b/pybricks/common/pb_type_keypad.c @@ -1,5 +1,5 @@ // SPDX-License-Identifier: MIT -// Copyright (c) 2018-2021 The Pybricks Authors +// Copyright (c) 2018-2023 The Pybricks Authors #include "py/mpconfig.h" @@ -50,11 +50,10 @@ STATIC const mp_rom_map_elem_t common_Keypad_locals_dict_table[] = { STATIC MP_DEFINE_CONST_DICT(common_Keypad_locals_dict, common_Keypad_locals_dict_table); // type(pybricks.common.Keypad) -STATIC const mp_obj_type_t pb_type_Keypad = { - { &mp_type_type }, - .name = MP_QSTR_Keypad, - .locals_dict = (mp_obj_dict_t *)&common_Keypad_locals_dict, -}; +STATIC MP_DEFINE_CONST_OBJ_TYPE(pb_type_Keypad, + MP_QSTR_Keypad, + MP_TYPE_FLAG_NONE, + locals_dict, &common_Keypad_locals_dict); // pybricks._common.Keypad.__init__ mp_obj_t pb_type_Keypad_obj_new(uint8_t number_of_buttons, const pb_obj_enum_member_t **buttons, pbio_button_is_pressed_func_t is_pressed) { diff --git a/pybricks/common/pb_type_lightarray.c b/pybricks/common/pb_type_lightarray.c index 516f7b839..b81f15124 100644 --- a/pybricks/common/pb_type_lightarray.c +++ b/pybricks/common/pb_type_lightarray.c @@ -1,5 +1,5 @@ // SPDX-License-Identifier: MIT -// Copyright (c) 2018-2020 The Pybricks Authors +// Copyright (c) 2018-2023 The Pybricks Authors #include "py/mpconfig.h" @@ -76,11 +76,10 @@ STATIC const mp_rom_map_elem_t common_LightArray_locals_dict_table[] = { STATIC MP_DEFINE_CONST_DICT(common_LightArray_locals_dict, common_LightArray_locals_dict_table); // type(pybricks.builtins.LightArray) -STATIC const mp_obj_type_t pb_type_LightArray = { - { &mp_type_type }, - .name = MP_QSTR_LightArray, - .locals_dict = (mp_obj_dict_t *)&common_LightArray_locals_dict, -}; +STATIC MP_DEFINE_CONST_OBJ_TYPE(pb_type_LightArray, + MP_QSTR_LightArray, + MP_TYPE_FLAG_NONE, + locals_dict, &common_LightArray_locals_dict); // pybricks._common.LightArray.__init__ mp_obj_t common_LightArray_obj_make_new(pb_device_t *pbdev, uint8_t light_mode, uint8_t number_of_lights) { diff --git a/pybricks/common/pb_type_lightmatrix.c b/pybricks/common/pb_type_lightmatrix.c index 5631caee0..73ac88810 100644 --- a/pybricks/common/pb_type_lightmatrix.c +++ b/pybricks/common/pb_type_lightmatrix.c @@ -1,5 +1,5 @@ // SPDX-License-Identifier: MIT -// Copyright (c) 2018-2020 The Pybricks Authors +// Copyright (c) 2020-2023 The Pybricks Authors #include "py/mpconfig.h" @@ -316,11 +316,10 @@ STATIC const mp_rom_map_elem_t common_LightMatrix_locals_dict_table[] = { STATIC MP_DEFINE_CONST_DICT(common_LightMatrix_locals_dict, common_LightMatrix_locals_dict_table); // type(pybricks.builtins.LightMatrix) -STATIC const mp_obj_type_t pb_type_LightMatrix = { - { &mp_type_type }, - .name = MP_QSTR_LightMatrix, - .locals_dict = (mp_obj_dict_t *)&common_LightMatrix_locals_dict, -}; +STATIC MP_DEFINE_CONST_OBJ_TYPE(pb_type_LightMatrix, + MP_QSTR_LightMatrix, + MP_TYPE_FLAG_NONE, + locals_dict, &common_LightMatrix_locals_dict); // pybricks._common.LightMatrix.__init__ mp_obj_t pb_type_LightMatrix_obj_new(pbio_light_matrix_t *light_matrix) { diff --git a/pybricks/common/pb_type_logger.c b/pybricks/common/pb_type_logger.c index 9fab6cb1a..981d34f92 100644 --- a/pybricks/common/pb_type_logger.c +++ b/pybricks/common/pb_type_logger.c @@ -1,5 +1,5 @@ // SPDX-License-Identifier: MIT -// Copyright (c) 2018-2020 The Pybricks Authors +// Copyright (c) 2018-2023 The Pybricks Authors #include "py/mpconfig.h" @@ -152,10 +152,10 @@ STATIC const mp_rom_map_elem_t tools_Logger_locals_dict_table[] = { STATIC MP_DEFINE_CONST_DICT(tools_Logger_locals_dict, tools_Logger_locals_dict_table); // type(pybricks.tools.Logger) -STATIC const mp_obj_type_t tools_Logger_type = { - { &mp_type_type }, - .locals_dict = (mp_obj_dict_t *)&tools_Logger_locals_dict, -}; +STATIC MP_DEFINE_CONST_OBJ_TYPE(tools_Logger_type, + MP_QSTR_Logger, + MP_TYPE_FLAG_NONE, + locals_dict, &tools_Logger_locals_dict); mp_obj_t common_Logger_obj_make_new(pbio_log_t *log, uint8_t num_values) { tools_Logger_obj_t *logger = mp_obj_malloc(tools_Logger_obj_t, &tools_Logger_type); diff --git a/pybricks/common/pb_type_motor.c b/pybricks/common/pb_type_motor.c index 072f0b487..0cc689c68 100644 --- a/pybricks/common/pb_type_motor.c +++ b/pybricks/common/pb_type_motor.c @@ -1,5 +1,5 @@ // SPDX-License-Identifier: MIT -// Copyright (c) 2018-2022 The Pybricks Authors +// Copyright (c) 2018-2023 The Pybricks Authors #include "py/mpconfig.h" @@ -426,16 +426,15 @@ STATIC const mp_rom_map_elem_t common_Motor_locals_dict_table[] = { MP_DEFINE_CONST_DICT(common_Motor_locals_dict, common_Motor_locals_dict_table); // type(pybricks.builtins.Motor) -const mp_obj_type_t pb_type_Motor = { - { &mp_type_type }, - .name = MP_QSTR_Motor, - .print = common_DCMotor_print, - .make_new = common_Motor_make_new, +MP_DEFINE_CONST_OBJ_TYPE(pb_type_Motor, + MP_QSTR_Motor, + MP_TYPE_FLAG_NONE, + print, common_DCMotor_print, + make_new, common_Motor_make_new, #if PYBRICKS_PY_COMMON_CONTROL | PYBRICKS_PY_COMMON_LOGGER - .attr = pb_attribute_handler, - .protocol = common_Motor_attr_dict, + attr, pb_attribute_handler, + protocol, common_Motor_attr_dict, #endif - .locals_dict = (mp_obj_dict_t *)&common_Motor_locals_dict, -}; + locals_dict, &common_Motor_locals_dict); #endif // PYBRICKS_PY_COMMON_MOTORS diff --git a/pybricks/common/pb_type_motor_model.c b/pybricks/common/pb_type_motor_model.c index ec68d8e48..ed6bdc145 100644 --- a/pybricks/common/pb_type_motor_model.c +++ b/pybricks/common/pb_type_motor_model.c @@ -1,5 +1,5 @@ // SPDX-License-Identifier: MIT -// Copyright (c) 2018-2022 The Pybricks Authors +// Copyright (c) 2018-2023 The Pybricks Authors #include "py/mpconfig.h" @@ -94,10 +94,9 @@ STATIC const mp_rom_map_elem_t pb_type_MotorModel_locals_dict_table[] = { STATIC MP_DEFINE_CONST_DICT(pb_type_MotorModel_locals_dict, pb_type_MotorModel_locals_dict_table); // type(pybricks.common.MotorModel) -const mp_obj_type_t pb_type_MotorModel = { - { &mp_type_type }, - .name = MP_QSTR_MotorModel, - .locals_dict = (mp_obj_dict_t *)&pb_type_MotorModel_locals_dict, -}; +MP_DEFINE_CONST_OBJ_TYPE(pb_type_MotorModel, + MP_QSTR_MotorModel, + MP_TYPE_FLAG_NONE, + locals_dict, &pb_type_MotorModel_locals_dict); #endif // PYBRICKS_PY_COMMON_MOTOR_MODEL diff --git a/pybricks/common/pb_type_speaker.c b/pybricks/common/pb_type_speaker.c index 7e570d64e..bd358c1b1 100644 --- a/pybricks/common/pb_type_speaker.c +++ b/pybricks/common/pb_type_speaker.c @@ -1,5 +1,5 @@ // SPDX-License-Identifier: MIT -// Copyright (c) 2018-2020 The Pybricks Authors +// Copyright (c) 2018-2023 The Pybricks Authors // Speaker class for playing sounds. @@ -355,11 +355,10 @@ STATIC const mp_rom_map_elem_t pb_type_Speaker_locals_dict_table[] = { }; STATIC MP_DEFINE_CONST_DICT(pb_type_Speaker_locals_dict, pb_type_Speaker_locals_dict_table); -const mp_obj_type_t pb_type_Speaker = { - { &mp_type_type }, - .name = MP_QSTR_Speaker, - .make_new = pb_type_Speaker_make_new, - .locals_dict = (mp_obj_dict_t *)&pb_type_Speaker_locals_dict, -}; +MP_DEFINE_CONST_OBJ_TYPE(pb_type_Speaker, + MP_QSTR_Speaker, + MP_TYPE_FLAG_NONE, + make_new, pb_type_Speaker_make_new, + locals_dict, &pb_type_Speaker_locals_dict); #endif // PYBRICKS_PY_COMMON_SPEAKER diff --git a/pybricks/ev3devices/pb_type_ev3devices_colorsensor.c b/pybricks/ev3devices/pb_type_ev3devices_colorsensor.c index e0eaad01a..bb4d2f072 100644 --- a/pybricks/ev3devices/pb_type_ev3devices_colorsensor.c +++ b/pybricks/ev3devices/pb_type_ev3devices_colorsensor.c @@ -1,5 +1,5 @@ // SPDX-License-Identifier: MIT -// Copyright (c) 2018-2020 The Pybricks Authors +// Copyright (c) 2018-2023 The Pybricks Authors #include "py/mpconfig.h" @@ -107,11 +107,10 @@ STATIC const mp_rom_map_elem_t ev3devices_ColorSensor_locals_dict_table[] = { STATIC MP_DEFINE_CONST_DICT(ev3devices_ColorSensor_locals_dict, ev3devices_ColorSensor_locals_dict_table); // type(pybricks.ev3devices.ColorSensor) -const mp_obj_type_t pb_type_ev3devices_ColorSensor = { - { &mp_type_type }, - .name = MP_QSTR_ColorSensor, - .make_new = ev3devices_ColorSensor_make_new, - .locals_dict = (mp_obj_dict_t *)&ev3devices_ColorSensor_locals_dict, -}; +MP_DEFINE_CONST_OBJ_TYPE(pb_type_ev3devices_ColorSensor, + MP_QSTR_ColorSensor, + MP_TYPE_FLAG_NONE, + make_new, ev3devices_ColorSensor_make_new, + locals_dict, &ev3devices_ColorSensor_locals_dict); #endif // PYBRICKS_PY_EV3DEVICES diff --git a/pybricks/ev3devices/pb_type_ev3devices_gyrosensor.c b/pybricks/ev3devices/pb_type_ev3devices_gyrosensor.c index 95e71248a..5ddcee714 100644 --- a/pybricks/ev3devices/pb_type_ev3devices_gyrosensor.c +++ b/pybricks/ev3devices/pb_type_ev3devices_gyrosensor.c @@ -1,5 +1,5 @@ // SPDX-License-Identifier: MIT -// Copyright (c) 2018-2020 The Pybricks Authors +// Copyright (c) 2018-2023 The Pybricks Authors #include "py/mpconfig.h" @@ -103,11 +103,10 @@ STATIC const mp_rom_map_elem_t ev3devices_GyroSensor_locals_dict_table[] = { STATIC MP_DEFINE_CONST_DICT(ev3devices_GyroSensor_locals_dict, ev3devices_GyroSensor_locals_dict_table); // type(pybricks.ev3devices.GyroSensor) -const mp_obj_type_t pb_type_ev3devices_GyroSensor = { - { &mp_type_type }, - .name = MP_QSTR_GyroSensor, - .make_new = ev3devices_GyroSensor_make_new, - .locals_dict = (mp_obj_dict_t *)&ev3devices_GyroSensor_locals_dict, -}; +MP_DEFINE_CONST_OBJ_TYPE(pb_type_ev3devices_GyroSensor, + MP_QSTR_GyroSensor, + MP_TYPE_FLAG_NONE, + make_new, ev3devices_GyroSensor_make_new, + locals_dict, &ev3devices_GyroSensor_locals_dict); #endif // PYBRICKS_PY_EV3DEVICES diff --git a/pybricks/ev3devices/pb_type_ev3devices_infraredsensor.c b/pybricks/ev3devices/pb_type_ev3devices_infraredsensor.c index ae05c46e1..530aba1fe 100644 --- a/pybricks/ev3devices/pb_type_ev3devices_infraredsensor.c +++ b/pybricks/ev3devices/pb_type_ev3devices_infraredsensor.c @@ -1,5 +1,5 @@ // SPDX-License-Identifier: MIT -// Copyright (c) 2018-2020 The Pybricks Authors +// Copyright (c) 2018-2023 The Pybricks Authors #include "py/mpconfig.h" @@ -187,11 +187,10 @@ STATIC const mp_rom_map_elem_t ev3devices_InfraredSensor_locals_dict_table[] = { STATIC MP_DEFINE_CONST_DICT(ev3devices_InfraredSensor_locals_dict, ev3devices_InfraredSensor_locals_dict_table); // type(pybricks.ev3devices.InfraredSensor) -const mp_obj_type_t pb_type_ev3devices_InfraredSensor = { - { &mp_type_type }, - .name = MP_QSTR_InfraredSensor, - .make_new = ev3devices_InfraredSensor_make_new, - .locals_dict = (mp_obj_dict_t *)&ev3devices_InfraredSensor_locals_dict, -}; +MP_DEFINE_CONST_OBJ_TYPE(pb_type_ev3devices_InfraredSensor, + MP_QSTR_InfraredSensor, + MP_TYPE_FLAG_NONE, + make_new, ev3devices_InfraredSensor_make_new, + locals_dict, &ev3devices_InfraredSensor_locals_dict); #endif // PYBRICKS_PY_EV3DEVICES diff --git a/pybricks/ev3devices/pb_type_ev3devices_touchsensor.c b/pybricks/ev3devices/pb_type_ev3devices_touchsensor.c index 47a50282a..fa11083cc 100644 --- a/pybricks/ev3devices/pb_type_ev3devices_touchsensor.c +++ b/pybricks/ev3devices/pb_type_ev3devices_touchsensor.c @@ -1,5 +1,5 @@ // SPDX-License-Identifier: MIT -// Copyright (c) 2018-2020 The Pybricks Authors +// Copyright (c) 2018-2023 The Pybricks Authors #include "py/mpconfig.h" @@ -50,11 +50,10 @@ STATIC const mp_rom_map_elem_t ev3devices_TouchSensor_locals_dict_table[] = { STATIC MP_DEFINE_CONST_DICT(ev3devices_TouchSensor_locals_dict, ev3devices_TouchSensor_locals_dict_table); // type(pybricks.ev3devices.TouchSensor) -const mp_obj_type_t pb_type_ev3devices_TouchSensor = { - { &mp_type_type }, - .name = MP_QSTR_TouchSensor, - .make_new = ev3devices_TouchSensor_make_new, - .locals_dict = (mp_obj_dict_t *)&ev3devices_TouchSensor_locals_dict, -}; +MP_DEFINE_CONST_OBJ_TYPE(pb_type_ev3devices_TouchSensor, + MP_QSTR_TouchSensor, + MP_TYPE_FLAG_NONE, + make_new, ev3devices_TouchSensor_make_new, + locals_dict, &ev3devices_TouchSensor_locals_dict); #endif // PYBRICKS_PY_EV3DEVICES diff --git a/pybricks/ev3devices/pb_type_ev3devices_ultrasonicsensor.c b/pybricks/ev3devices/pb_type_ev3devices_ultrasonicsensor.c index fc9996210..89a564a91 100644 --- a/pybricks/ev3devices/pb_type_ev3devices_ultrasonicsensor.c +++ b/pybricks/ev3devices/pb_type_ev3devices_ultrasonicsensor.c @@ -1,5 +1,5 @@ // SPDX-License-Identifier: MIT -// Copyright (c) 2018-2020 The Pybricks Authors +// Copyright (c) 2018-2023 The Pybricks Authors #include "py/mpconfig.h" @@ -68,11 +68,10 @@ STATIC const mp_rom_map_elem_t ev3devices_UltrasonicSensor_locals_dict_table[] = STATIC MP_DEFINE_CONST_DICT(ev3devices_UltrasonicSensor_locals_dict, ev3devices_UltrasonicSensor_locals_dict_table); // type(pybricks.ev3devices.UltrasonicSensor) -const mp_obj_type_t pb_type_ev3devices_UltrasonicSensor = { - { &mp_type_type }, - .name = MP_QSTR_UltrasonicSensor, - .make_new = ev3devices_UltrasonicSensor_make_new, - .locals_dict = (mp_obj_dict_t *)&ev3devices_UltrasonicSensor_locals_dict, -}; +MP_DEFINE_CONST_OBJ_TYPE(pb_type_ev3devices_UltrasonicSensor, + MP_QSTR_UltrasonicSensor, + MP_TYPE_FLAG_NONE, + make_new, ev3devices_UltrasonicSensor_make_new, + locals_dict, &ev3devices_UltrasonicSensor_locals_dict); #endif // PYBRICKS_PY_EV3DEVICES diff --git a/pybricks/hubs/pb_type_cityhub.c b/pybricks/hubs/pb_type_cityhub.c index e635f0069..036fdb789 100644 --- a/pybricks/hubs/pb_type_cityhub.c +++ b/pybricks/hubs/pb_type_cityhub.c @@ -1,5 +1,5 @@ // SPDX-License-Identifier: MIT -// Copyright (c) 2018-2021 The Pybricks Authors +// Copyright (c) 2018-2023 The Pybricks Authors #include "py/mpconfig.h" @@ -42,12 +42,11 @@ STATIC const pb_attr_dict_entry_t hubs_CityHub_attr_dict[] = { PB_ATTR_DICT_SENTINEL }; -const mp_obj_type_t pb_type_ThisHub = { - { &mp_type_type }, - .name = MP_QSTR_CityHub, - .make_new = hubs_CityHub_make_new, - .attr = pb_attribute_handler, - .protocol = hubs_CityHub_attr_dict, -}; +MP_DEFINE_CONST_OBJ_TYPE(pb_type_ThisHub, + MP_QSTR_CityHub, + MP_TYPE_FLAG_NONE, + make_new, hubs_CityHub_make_new, + attr, pb_attribute_handler, + protocol, hubs_CityHub_attr_dict); #endif // PYBRICKS_PY_HUBS && PYBRICKS_HUB_CITYHUB diff --git a/pybricks/hubs/pb_type_essentialhub.c b/pybricks/hubs/pb_type_essentialhub.c index 3b6888076..ddba61ad8 100644 --- a/pybricks/hubs/pb_type_essentialhub.c +++ b/pybricks/hubs/pb_type_essentialhub.c @@ -1,5 +1,5 @@ // SPDX-License-Identifier: MIT -// Copyright (c) 2018-2021 The Pybricks Authors +// Copyright (c) 2018-2023 The Pybricks Authors #include "py/mpconfig.h" @@ -63,12 +63,11 @@ STATIC const pb_attr_dict_entry_t hubs_EssentialHub_attr_dict[] = { PB_ATTR_DICT_SENTINEL }; -const mp_obj_type_t pb_type_ThisHub = { - { &mp_type_type }, - .name = PYBRICKS_HUB_CLASS_NAME, - .make_new = hubs_EssentialHub_make_new, - .attr = pb_attribute_handler, - .protocol = hubs_EssentialHub_attr_dict, -}; +MP_DEFINE_CONST_OBJ_TYPE(pb_type_ThisHub, + PYBRICKS_HUB_CLASS_NAME, + MP_TYPE_FLAG_NONE, + make_new, hubs_EssentialHub_make_new, + attr, pb_attribute_handler, + protocol, hubs_EssentialHub_attr_dict); #endif // PYBRICKS_PY_HUBS && PYBRICKS_HUB_ESSENTIALHUB diff --git a/pybricks/hubs/pb_type_ev3brick.c b/pybricks/hubs/pb_type_ev3brick.c index e1330d4f6..62d9ff95c 100644 --- a/pybricks/hubs/pb_type_ev3brick.c +++ b/pybricks/hubs/pb_type_ev3brick.c @@ -1,5 +1,5 @@ // SPDX-License-Identifier: MIT -// Copyright (c) 2018-2021 The Pybricks Authors +// Copyright (c) 2018-2023 The Pybricks Authors #include "py/mpconfig.h" @@ -41,8 +41,8 @@ STATIC mp_obj_t hubs_EV3Brick_make_new(const mp_obj_type_t *type, size_t n_args, self->buttons = pb_type_Keypad_obj_new(MP_ARRAY_SIZE(ev3brick_buttons), ev3brick_buttons, pbio_button_is_pressed); self->light = common_ColorLight_internal_obj_new(ev3dev_status_light); mp_obj_t screen_args[] = { MP_ROM_QSTR(MP_QSTR__screen_) }; - self->screen = pb_type_ev3dev_Image.make_new(&pb_type_ev3dev_Image, 1, 0, screen_args); - self->speaker = pb_type_ev3dev_Speaker.make_new(&pb_type_ev3dev_Speaker, 0, 0, NULL); + self->screen = MP_OBJ_TYPE_GET_SLOT(&pb_type_ev3dev_Image, make_new)(&pb_type_ev3dev_Image, 1, 0, screen_args); + self->speaker = MP_OBJ_TYPE_GET_SLOT(&pb_type_ev3dev_Speaker, make_new)(&pb_type_ev3dev_Speaker, 0, 0, NULL); self->system = MP_OBJ_FROM_PTR(&pb_type_System); return MP_OBJ_FROM_PTR(self); @@ -58,12 +58,11 @@ STATIC const pb_attr_dict_entry_t hubs_EV3Brick_attr_dict[] = { PB_ATTR_DICT_SENTINEL }; -const mp_obj_type_t pb_type_ThisHub = { - { &mp_type_type }, - .name = PYBRICKS_HUB_CLASS_NAME, - .make_new = hubs_EV3Brick_make_new, - .attr = pb_attribute_handler, - .protocol = hubs_EV3Brick_attr_dict, -}; +MP_DEFINE_CONST_OBJ_TYPE(pb_type_ThisHub, + PYBRICKS_HUB_CLASS_NAME, + MP_TYPE_FLAG_NONE, + make_new, hubs_EV3Brick_make_new, + attr, pb_attribute_handler, + protocol, hubs_EV3Brick_attr_dict); #endif // PYBRICKS_PY_HUBS && PYBRICKS_HUB_EV3BRICK diff --git a/pybricks/hubs/pb_type_movehub.c b/pybricks/hubs/pb_type_movehub.c index b984bc542..5d32fefd2 100644 --- a/pybricks/hubs/pb_type_movehub.c +++ b/pybricks/hubs/pb_type_movehub.c @@ -1,5 +1,5 @@ // SPDX-License-Identifier: MIT -// Copyright (c) 2018-2021 The Pybricks Authors +// Copyright (c) 2018-2023 The Pybricks Authors #include "py/mpconfig.h" @@ -197,12 +197,11 @@ STATIC const mp_rom_map_elem_t hubs_MoveHub_IMU_locals_dict_table[] = { }; STATIC MP_DEFINE_CONST_DICT(hubs_MoveHub_IMU_locals_dict, hubs_MoveHub_IMU_locals_dict_table); -STATIC const mp_obj_type_t hubs_MoveHub_IMU_type = { - { &mp_type_type }, - .name = MP_QSTR_Motion, - .attr = pb_attribute_handler, - .locals_dict = (mp_obj_dict_t *)&hubs_MoveHub_IMU_locals_dict, -}; +STATIC MP_DEFINE_CONST_OBJ_TYPE(hubs_MoveHub_IMU_type, + MP_QSTR_IMU, + MP_TYPE_FLAG_NONE, + attr, pb_attribute_handler, + locals_dict, &hubs_MoveHub_IMU_locals_dict); STATIC mp_obj_t hubs_MoveHub_IMU_make_new(void) { hubs_MoveHub_IMU_obj_t *self = mp_obj_malloc(hubs_MoveHub_IMU_obj_t, &hubs_MoveHub_IMU_type); @@ -273,12 +272,11 @@ STATIC const pb_attr_dict_entry_t hubs_MoveHub_attr_dict[] = { PB_ATTR_DICT_SENTINEL }; -const mp_obj_type_t pb_type_ThisHub = { - { &mp_type_type }, - .name = PYBRICKS_HUB_CLASS_NAME, - .make_new = hubs_MoveHub_make_new, - .attr = pb_attribute_handler, - .protocol = hubs_MoveHub_attr_dict, -}; +MP_DEFINE_CONST_OBJ_TYPE(pb_type_ThisHub, + PYBRICKS_HUB_CLASS_NAME, + MP_TYPE_FLAG_NONE, + make_new, hubs_MoveHub_make_new, + attr, pb_attribute_handler, + protocol, hubs_MoveHub_attr_dict); #endif // PYBRICKS_PY_HUBS && PYBRICKS_HUB_MOVEHUB diff --git a/pybricks/hubs/pb_type_nxtbrick.c b/pybricks/hubs/pb_type_nxtbrick.c index 15fa2f346..6f2e658dc 100644 --- a/pybricks/hubs/pb_type_nxtbrick.c +++ b/pybricks/hubs/pb_type_nxtbrick.c @@ -47,12 +47,11 @@ STATIC const pb_attr_dict_entry_t hubs_NXTBrick_attr_dict[] = { PB_ATTR_DICT_SENTINEL }; -const mp_obj_type_t pb_type_ThisHub = { - { &mp_type_type }, - .name = PYBRICKS_HUB_CLASS_NAME, - .make_new = hubs_NXTBrick_make_new, - .attr = pb_attribute_handler, - .protocol = hubs_NXTBrick_attr_dict, -}; +MP_DEFINE_CONST_OBJ_TYPE(pb_type_ThisHub, + PYBRICKS_HUB_CLASS_NAME, + MP_TYPE_FLAG_NONE, + make_new, hubs_NXTBrick_make_new, + attr, pb_attribute_handler, + protocol, hubs_NXTBrick_attr_dict); #endif // PYBRICKS_PY_HUBS && PYBRICKS_HUB_NXTBRICK diff --git a/pybricks/hubs/pb_type_primehub.c b/pybricks/hubs/pb_type_primehub.c index cf823fa93..bd325bbe5 100644 --- a/pybricks/hubs/pb_type_primehub.c +++ b/pybricks/hubs/pb_type_primehub.c @@ -1,5 +1,5 @@ // SPDX-License-Identifier: MIT -// Copyright (c) 2018-2021 The Pybricks Authors +// Copyright (c) 2018-2023 The Pybricks Authors #include "py/mpconfig.h" @@ -72,12 +72,11 @@ STATIC const pb_attr_dict_entry_t hubs_PrimeHub_attr_dict[] = { PB_ATTR_DICT_SENTINEL }; -const mp_obj_type_t pb_type_ThisHub = { - { &mp_type_type }, - .name = PYBRICKS_HUB_CLASS_NAME, - .make_new = hubs_PrimeHub_make_new, - .attr = pb_attribute_handler, - .protocol = hubs_PrimeHub_attr_dict, -}; +MP_DEFINE_CONST_OBJ_TYPE(pb_type_ThisHub, + PYBRICKS_HUB_CLASS_NAME, + MP_TYPE_FLAG_NONE, + make_new, hubs_PrimeHub_make_new, + attr, pb_attribute_handler, + protocol, hubs_PrimeHub_attr_dict); #endif // PYBRICKS_PY_HUBS && PYBRICKS_HUB_PRIMEHUB diff --git a/pybricks/hubs/pb_type_technichub.c b/pybricks/hubs/pb_type_technichub.c index 3fb073044..09af37ac0 100644 --- a/pybricks/hubs/pb_type_technichub.c +++ b/pybricks/hubs/pb_type_technichub.c @@ -1,5 +1,5 @@ // SPDX-License-Identifier: MIT -// Copyright (c) 2018-2021 The Pybricks Authors +// Copyright (c) 2018-2023 The Pybricks Authors #include "py/mpconfig.h" @@ -51,12 +51,11 @@ STATIC const pb_attr_dict_entry_t hubs_TechnicHub_attr_dict[] = { PB_ATTR_DICT_SENTINEL }; -const mp_obj_type_t pb_type_ThisHub = { - { &mp_type_type }, - .name = PYBRICKS_HUB_CLASS_NAME, - .make_new = hubs_TechnicHub_make_new, - .attr = pb_attribute_handler, - .protocol = hubs_TechnicHub_attr_dict, -}; +MP_DEFINE_CONST_OBJ_TYPE(pb_type_ThisHub, + PYBRICKS_HUB_CLASS_NAME, + MP_TYPE_FLAG_NONE, + make_new, hubs_TechnicHub_make_new, + attr, pb_attribute_handler, + protocol, hubs_TechnicHub_attr_dict); #endif // PYBRICKS_PY_HUBS && PYBRICKS_HUB_TECHNICHUB diff --git a/pybricks/hubs/pb_type_virtualhub.c b/pybricks/hubs/pb_type_virtualhub.c index 135a83ebb..c4bcb87b9 100644 --- a/pybricks/hubs/pb_type_virtualhub.c +++ b/pybricks/hubs/pb_type_virtualhub.c @@ -1,5 +1,5 @@ // SPDX-License-Identifier: MIT -// Copyright (c) 2022 The Pybricks Authors +// Copyright (c) 2022-2023 The Pybricks Authors #include "py/mpconfig.h" @@ -48,12 +48,11 @@ STATIC const pb_attr_dict_entry_t hubs_VirtualHub_attr_dict[] = { PB_ATTR_DICT_SENTINEL }; -const mp_obj_type_t pb_type_ThisHub = { - { &mp_type_type }, - .name = PYBRICKS_HUB_CLASS_NAME, - .make_new = hubs_VirtualHub_make_new, - .attr = pb_attribute_handler, - .protocol = hubs_VirtualHub_attr_dict, -}; +MP_DEFINE_CONST_OBJ_TYPE(pb_type_ThisHub, + PYBRICKS_HUB_CLASS_NAME, + MP_TYPE_FLAG_NONE, + make_new, hubs_VirtualHub_make_new, + attr, pb_attribute_handler, + protocol, hubs_VirtualHub_attr_dict); #endif // PYBRICKS_PY_HUBS && PYBRICKS_HUB_VIRTUALHUB diff --git a/pybricks/iodevices/pb_type_iodevices_analogsensor.c b/pybricks/iodevices/pb_type_iodevices_analogsensor.c index e57d2b452..11e12dbaa 100644 --- a/pybricks/iodevices/pb_type_iodevices_analogsensor.c +++ b/pybricks/iodevices/pb_type_iodevices_analogsensor.c @@ -1,5 +1,5 @@ // SPDX-License-Identifier: MIT -// Copyright (c) 2018-2020 The Pybricks Authors +// Copyright (c) 2018-2023 The Pybricks Authors #include "py/mpconfig.h" @@ -96,11 +96,10 @@ STATIC const mp_rom_map_elem_t iodevices_AnalogSensor_locals_dict_table[] = { STATIC MP_DEFINE_CONST_DICT(iodevices_AnalogSensor_locals_dict, iodevices_AnalogSensor_locals_dict_table); // type(pybricks.iodevices.AnalogSensor) -const mp_obj_type_t pb_type_iodevices_AnalogSensor = { - { &mp_type_type }, - .name = MP_QSTR_AnalogSensor, - .make_new = iodevices_AnalogSensor_make_new, - .locals_dict = (mp_obj_dict_t *)&iodevices_AnalogSensor_locals_dict, -}; +MP_DEFINE_CONST_OBJ_TYPE(pb_type_iodevices_AnalogSensor, + MP_QSTR_AnalogSensor, + MP_TYPE_FLAG_NONE, + make_new, iodevices_AnalogSensor_make_new, + locals_dict, &iodevices_AnalogSensor_locals_dict); #endif // PYBRICKS_PY_IODEVICES && PYBRICKS_PY_EV3DEVICES diff --git a/pybricks/iodevices/pb_type_iodevices_ev3devsensor.c b/pybricks/iodevices/pb_type_iodevices_ev3devsensor.c index 0bf9d1f45..bc90dbdeb 100644 --- a/pybricks/iodevices/pb_type_iodevices_ev3devsensor.c +++ b/pybricks/iodevices/pb_type_iodevices_ev3devsensor.c @@ -1,5 +1,5 @@ // SPDX-License-Identifier: MIT -// Copyright (c) 2018-2021 The Pybricks Authors +// Copyright (c) 2018-2023 The Pybricks Authors #include "py/mpconfig.h" @@ -85,12 +85,12 @@ STATIC const mp_rom_map_elem_t iodevices_Ev3devSensor_locals_dict_table[] = { STATIC MP_DEFINE_CONST_DICT(iodevices_Ev3devSensor_locals_dict, iodevices_Ev3devSensor_locals_dict_table); // type(pybricks.iodevices.Ev3devSensor) -const mp_obj_type_t pb_type_iodevices_Ev3devSensor = { - { &mp_type_type }, - .make_new = iodevices_Ev3devSensor_make_new, - .attr = pb_attribute_handler, - .protocol = iodevices_Ev3devSensor_attr_dict, - .locals_dict = (mp_obj_dict_t *)&iodevices_Ev3devSensor_locals_dict, -}; +MP_DEFINE_CONST_OBJ_TYPE(pb_type_iodevices_Ev3devSensor, + MP_QSTR_Ev3devSensor, + MP_TYPE_FLAG_NONE, + make_new, iodevices_Ev3devSensor_make_new, + attr, pb_attribute_handler, + protocol, iodevices_Ev3devSensor_attr_dict, + locals_dict, &iodevices_Ev3devSensor_locals_dict); #endif // PYBRICKS_PY_IODEVICES && PYBRICKS_PY_EV3DEVICES diff --git a/pybricks/iodevices/pb_type_iodevices_i2cdevice.c b/pybricks/iodevices/pb_type_iodevices_i2cdevice.c index c099deaf8..5adb8abe1 100644 --- a/pybricks/iodevices/pb_type_iodevices_i2cdevice.c +++ b/pybricks/iodevices/pb_type_iodevices_i2cdevice.c @@ -1,5 +1,5 @@ // SPDX-License-Identifier: MIT -// Copyright (c) 2018-2020 The Pybricks Authors +// Copyright (c) 2018-2023 The Pybricks Authors #include "py/mpconfig.h" @@ -160,11 +160,10 @@ STATIC const mp_rom_map_elem_t iodevices_I2CDevice_locals_dict_table[] = { STATIC MP_DEFINE_CONST_DICT(iodevices_I2CDevice_locals_dict, iodevices_I2CDevice_locals_dict_table); // type(pybricks.iodevices.I2CDevice) -const mp_obj_type_t pb_type_iodevices_I2CDevice = { - { &mp_type_type }, - .name = MP_QSTR_I2CDevice, - .make_new = iodevices_I2CDevice_make_new, - .locals_dict = (mp_obj_dict_t *)&iodevices_I2CDevice_locals_dict, -}; +MP_DEFINE_CONST_OBJ_TYPE(pb_type_iodevices_I2CDevice, + MP_QSTR_I2CDevice, + MP_TYPE_FLAG_NONE, + make_new, iodevices_I2CDevice_make_new, + locals_dict, &iodevices_I2CDevice_locals_dict); #endif // PYBRICKS_PY_IODEVICES && PYBRICKS_PY_EV3DEVICES diff --git a/pybricks/iodevices/pb_type_iodevices_lumpdevice.c b/pybricks/iodevices/pb_type_iodevices_lumpdevice.c index 89b406c8c..9e73059d1 100644 --- a/pybricks/iodevices/pb_type_iodevices_lumpdevice.c +++ b/pybricks/iodevices/pb_type_iodevices_lumpdevice.c @@ -1,5 +1,5 @@ // SPDX-License-Identifier: MIT -// Copyright (c) 2018-2021 The Pybricks Authors +// Copyright (c) 2018-2023 The Pybricks Authors #include "py/mpconfig.h" @@ -105,12 +105,12 @@ STATIC const mp_rom_map_elem_t iodevices_LUMPDevice_locals_dict_table[] = { STATIC MP_DEFINE_CONST_DICT(iodevices_LUMPDevice_locals_dict, iodevices_LUMPDevice_locals_dict_table); // type(pybricks.iodevices.LUMPDevice) -const mp_obj_type_t pb_type_iodevices_LUMPDevice = { - { &mp_type_type }, - .make_new = iodevices_LUMPDevice_make_new, - .attr = pb_attribute_handler, - .protocol = iodevices_LUMPDevice_attr_dict, - .locals_dict = (mp_obj_dict_t *)&iodevices_LUMPDevice_locals_dict, -}; +MP_DEFINE_CONST_OBJ_TYPE(pb_type_iodevices_LUMPDevice, + MP_QSTR_LUMPDevice, + MP_TYPE_FLAG_NONE, + make_new, iodevices_LUMPDevice_make_new, + attr, pb_attribute_handler, + protocol, iodevices_LUMPDevice_attr_dict, + locals_dict, &iodevices_LUMPDevice_locals_dict); #endif // PYBRICKS_PY_IODEVICES && PYBRICKS_PY_EV3DEVICES diff --git a/pybricks/iodevices/pb_type_iodevices_lwp3device.c b/pybricks/iodevices/pb_type_iodevices_lwp3device.c index 7fbc9b3c4..9a88f64e7 100644 --- a/pybricks/iodevices/pb_type_iodevices_lwp3device.c +++ b/pybricks/iodevices/pb_type_iodevices_lwp3device.c @@ -1,5 +1,5 @@ // SPDX-License-Identifier: MIT -// Copyright (c) 2021 The Pybricks Authors +// Copyright (c) 2021-2023 The Pybricks Authors #include "py/mpconfig.h" @@ -219,11 +219,10 @@ STATIC const mp_rom_map_elem_t pb_type_iodevices_LWP3Device_locals_dict_table[] }; STATIC MP_DEFINE_CONST_DICT(pb_type_iodevices_LWP3Device_locals_dict, pb_type_iodevices_LWP3Device_locals_dict_table); -const mp_obj_type_t pb_type_iodevices_LWP3Device = { - { &mp_type_type }, - .name = MP_QSTR_LWP3Device, - .make_new = pb_type_iodevices_LWP3Device_make_new, - .locals_dict = (mp_obj_dict_t *)&pb_type_iodevices_LWP3Device_locals_dict, -}; +MP_DEFINE_CONST_OBJ_TYPE(pb_type_iodevices_LWP3Device, + MP_QSTR_LWP3Device, + MP_TYPE_FLAG_NONE, + make_new, pb_type_iodevices_LWP3Device_make_new, + locals_dict, &pb_type_iodevices_LWP3Device_locals_dict); #endif // PYBRICKS_PY_IODEVICES && PYBRICKS_PY_PUPDEVICES diff --git a/pybricks/iodevices/pb_type_iodevices_pupdevice.c b/pybricks/iodevices/pb_type_iodevices_pupdevice.c index 62363258f..1105dd11e 100644 --- a/pybricks/iodevices/pb_type_iodevices_pupdevice.c +++ b/pybricks/iodevices/pb_type_iodevices_pupdevice.c @@ -1,5 +1,5 @@ // SPDX-License-Identifier: MIT -// Copyright (c) 2018-2020 The Pybricks Authors +// Copyright (c) 2018-2023 The Pybricks Authors #include "py/mpconfig.h" @@ -109,10 +109,10 @@ STATIC const mp_rom_map_elem_t iodevices_PUPDevice_locals_dict_table[] = { STATIC MP_DEFINE_CONST_DICT(iodevices_PUPDevice_locals_dict, iodevices_PUPDevice_locals_dict_table); // type(pybricks.iodevices.PUPDevice) -const mp_obj_type_t pb_type_iodevices_PUPDevice = { - { &mp_type_type }, - .make_new = iodevices_PUPDevice_make_new, - .locals_dict = (mp_obj_dict_t *)&iodevices_PUPDevice_locals_dict, -}; +MP_DEFINE_CONST_OBJ_TYPE(pb_type_iodevices_PUPDevice, + MP_QSTR_PUPDevice, + MP_TYPE_FLAG_NONE, + make_new, iodevices_PUPDevice_make_new, + locals_dict, &iodevices_PUPDevice_locals_dict); #endif // PYBRICKS_PY_IODEVICES && PYBRICKS_PY_PUPDEVICES diff --git a/pybricks/iodevices/pb_type_iodevices_uartdevice.c b/pybricks/iodevices/pb_type_iodevices_uartdevice.c index 3c99fe4bc..68e997999 100644 --- a/pybricks/iodevices/pb_type_iodevices_uartdevice.c +++ b/pybricks/iodevices/pb_type_iodevices_uartdevice.c @@ -1,5 +1,5 @@ // SPDX-License-Identifier: MIT -// Copyright (c) 2018-2020 The Pybricks Authors +// Copyright (c) 2018-2023 The Pybricks Authors #include "py/mpconfig.h" @@ -180,11 +180,10 @@ STATIC const mp_rom_map_elem_t iodevices_UARTDevice_locals_dict_table[] = { STATIC MP_DEFINE_CONST_DICT(iodevices_UARTDevice_locals_dict, iodevices_UARTDevice_locals_dict_table); // type(pybricks.iodevices.UARTDevice) -const mp_obj_type_t pb_type_iodevices_UARTDevice = { - { &mp_type_type }, - .name = MP_QSTR_UARTDevice, - .make_new = iodevices_UARTDevice_make_new, - .locals_dict = (mp_obj_dict_t *)&iodevices_UARTDevice_locals_dict, -}; +MP_DEFINE_CONST_OBJ_TYPE(pb_type_iodevices_UARTDevice, + MP_QSTR_UARTDevice, + MP_TYPE_FLAG_NONE, + make_new, iodevices_UARTDevice_make_new, + locals_dict, &iodevices_UARTDevice_locals_dict); #endif // PYBRICKS_PY_IODEVICES && PYBRICKS_PY_EV3DEVICES diff --git a/pybricks/nxtdevices/pb_type_nxtdevices_colorsensor.c b/pybricks/nxtdevices/pb_type_nxtdevices_colorsensor.c index 302668ef6..e41c9c58c 100644 --- a/pybricks/nxtdevices/pb_type_nxtdevices_colorsensor.c +++ b/pybricks/nxtdevices/pb_type_nxtdevices_colorsensor.c @@ -1,5 +1,5 @@ // SPDX-License-Identifier: MIT -// Copyright (c) 2018-2021 The Pybricks Authors +// Copyright (c) 2018-2023 The Pybricks Authors #include "py/mpconfig.h" @@ -157,13 +157,12 @@ STATIC const mp_rom_map_elem_t nxtdevices_ColorSensor_locals_dict_table[] = { STATIC MP_DEFINE_CONST_DICT(nxtdevices_ColorSensor_locals_dict, nxtdevices_ColorSensor_locals_dict_table); // type(pybricks.nxtdevices.ColorSensor) -const mp_obj_type_t pb_type_nxtdevices_ColorSensor = { - { &mp_type_type }, - .name = MP_QSTR_ColorSensor, - .make_new = nxtdevices_ColorSensor_make_new, - .attr = pb_attribute_handler, - .protocol = nxtdevices_ColorSensor_attr_dict, - .locals_dict = (mp_obj_dict_t *)&nxtdevices_ColorSensor_locals_dict, -}; +MP_DEFINE_CONST_OBJ_TYPE(pb_type_nxtdevices_ColorSensor, + MP_QSTR_ColorSensor, + MP_TYPE_FLAG_NONE, + make_new, nxtdevices_ColorSensor_make_new, + attr, pb_attribute_handler, + protocol, nxtdevices_ColorSensor_attr_dict, + locals_dict, &nxtdevices_ColorSensor_locals_dict); #endif // PYBRICKS_PY_NXTDEVICES && PYBRICKS_PY_EV3DEVICES diff --git a/pybricks/nxtdevices/pb_type_nxtdevices_energymeter.c b/pybricks/nxtdevices/pb_type_nxtdevices_energymeter.c index e64ab696f..604d79739 100644 --- a/pybricks/nxtdevices/pb_type_nxtdevices_energymeter.c +++ b/pybricks/nxtdevices/pb_type_nxtdevices_energymeter.c @@ -1,5 +1,5 @@ // SPDX-License-Identifier: MIT -// Copyright (c) 2018-2020 The Pybricks Authors +// Copyright (c) 2018-2023 The Pybricks Authors #include "py/mpconfig.h" @@ -80,12 +80,11 @@ STATIC const mp_rom_map_elem_t nxtdevices_EnergyMeter_locals_dict_table[] = { STATIC MP_DEFINE_CONST_DICT(nxtdevices_EnergyMeter_locals_dict, nxtdevices_EnergyMeter_locals_dict_table); // type(pybricks.nxtdevices.EnergyMeter) -const mp_obj_type_t pb_type_nxtdevices_EnergyMeter = { - { &mp_type_type }, - .name = MP_QSTR_EnergyMeter, - .make_new = nxtdevices_EnergyMeter_make_new, - .locals_dict = (mp_obj_dict_t *)&nxtdevices_EnergyMeter_locals_dict, -}; +MP_DEFINE_CONST_OBJ_TYPE(pb_type_nxtdevices_EnergyMeter, + MP_QSTR_EnergyMeter, + MP_TYPE_FLAG_NONE, + make_new, nxtdevices_EnergyMeter_make_new, + locals_dict, &nxtdevices_EnergyMeter_locals_dict); #endif // PYBRICKS_PY_NXTDEVICES && PYBRICKS_PY_EV3DEVICES diff --git a/pybricks/nxtdevices/pb_type_nxtdevices_lightsensor.c b/pybricks/nxtdevices/pb_type_nxtdevices_lightsensor.c index 8a26c32c0..8e1df2ba2 100644 --- a/pybricks/nxtdevices/pb_type_nxtdevices_lightsensor.c +++ b/pybricks/nxtdevices/pb_type_nxtdevices_lightsensor.c @@ -1,5 +1,5 @@ // SPDX-License-Identifier: MIT -// Copyright (c) 2018-2020 The Pybricks Authors +// Copyright (c) 2018-2023 The Pybricks Authors #include "py/mpconfig.h" @@ -77,11 +77,10 @@ STATIC const mp_rom_map_elem_t nxtdevices_LightSensor_locals_dict_table[] = { STATIC MP_DEFINE_CONST_DICT(nxtdevices_LightSensor_locals_dict, nxtdevices_LightSensor_locals_dict_table); // type(pybricks.ev3devices.LightSensor) -const mp_obj_type_t pb_type_nxtdevices_LightSensor = { - { &mp_type_type }, - .name = MP_QSTR_LightSensor, - .make_new = nxtdevices_LightSensor_make_new, - .locals_dict = (mp_obj_dict_t *)&nxtdevices_LightSensor_locals_dict, -}; +MP_DEFINE_CONST_OBJ_TYPE(pb_type_nxtdevices_LightSensor, + MP_QSTR_LightSensor, + MP_TYPE_FLAG_NONE, + make_new, nxtdevices_LightSensor_make_new, + locals_dict, &nxtdevices_LightSensor_locals_dict); #endif // PYBRICKS_PY_NXTDEVICES && PYBRICKS_PY_EV3DEVICES diff --git a/pybricks/nxtdevices/pb_type_nxtdevices_soundsensor.c b/pybricks/nxtdevices/pb_type_nxtdevices_soundsensor.c index f9fd1f119..9e3d88a10 100644 --- a/pybricks/nxtdevices/pb_type_nxtdevices_soundsensor.c +++ b/pybricks/nxtdevices/pb_type_nxtdevices_soundsensor.c @@ -1,5 +1,5 @@ // SPDX-License-Identifier: MIT -// Copyright (c) 2018-2020 The Pybricks Authors +// Copyright (c) 2018-2023 The Pybricks Authors #include "py/mpconfig.h" @@ -61,11 +61,10 @@ STATIC const mp_rom_map_elem_t nxtdevices_SoundSensor_locals_dict_table[] = { STATIC MP_DEFINE_CONST_DICT(nxtdevices_SoundSensor_locals_dict, nxtdevices_SoundSensor_locals_dict_table); // type(pybricks.ev3devices.SoundSensor) -const mp_obj_type_t pb_type_nxtdevices_SoundSensor = { - { &mp_type_type }, - .name = MP_QSTR_SoundSensor, - .make_new = nxtdevices_SoundSensor_make_new, - .locals_dict = (mp_obj_dict_t *)&nxtdevices_SoundSensor_locals_dict, -}; +MP_DEFINE_CONST_OBJ_TYPE(pb_type_nxtdevices_SoundSensor, + MP_QSTR_SoundSensor, + MP_TYPE_FLAG_NONE, + make_new, nxtdevices_SoundSensor_make_new, + locals_dict, &nxtdevices_SoundSensor_locals_dict); #endif // PYBRICKS_PY_NXTDEVICES && PYBRICKS_PY_EV3DEVICES diff --git a/pybricks/nxtdevices/pb_type_nxtdevices_temperaturesensor.c b/pybricks/nxtdevices/pb_type_nxtdevices_temperaturesensor.c index f08d1428b..2a7106ff5 100644 --- a/pybricks/nxtdevices/pb_type_nxtdevices_temperaturesensor.c +++ b/pybricks/nxtdevices/pb_type_nxtdevices_temperaturesensor.c @@ -1,5 +1,5 @@ // SPDX-License-Identifier: MIT -// Copyright (c) 2018-2020 The Pybricks Authors +// Copyright (c) 2018-2023 The Pybricks Authors #include "py/mpconfig.h" @@ -49,11 +49,10 @@ STATIC const mp_rom_map_elem_t nxtdevices_TemperatureSensor_locals_dict_table[] STATIC MP_DEFINE_CONST_DICT(nxtdevices_TemperatureSensor_locals_dict, nxtdevices_TemperatureSensor_locals_dict_table); // type(pybricks.nxtdevices.TemperatureSensor) -const mp_obj_type_t pb_type_nxtdevices_TemperatureSensor = { - { &mp_type_type }, - .name = MP_QSTR_TemperatureSensor, - .make_new = nxtdevices_TemperatureSensor_make_new, - .locals_dict = (mp_obj_dict_t *)&nxtdevices_TemperatureSensor_locals_dict, -}; +MP_DEFINE_CONST_OBJ_TYPE(pb_type_nxtdevices_TemperatureSensor, + MP_QSTR_TemperatureSensor, + MP_TYPE_FLAG_NONE, + make_new, nxtdevices_TemperatureSensor_make_new, + locals_dict, &nxtdevices_TemperatureSensor_locals_dict); #endif // PYBRICKS_PY_NXTDEVICES && PYBRICKS_PY_EV3DEVICES diff --git a/pybricks/nxtdevices/pb_type_nxtdevices_touchsensor.c b/pybricks/nxtdevices/pb_type_nxtdevices_touchsensor.c index ba04be73e..cabaf0aca 100644 --- a/pybricks/nxtdevices/pb_type_nxtdevices_touchsensor.c +++ b/pybricks/nxtdevices/pb_type_nxtdevices_touchsensor.c @@ -1,5 +1,5 @@ // SPDX-License-Identifier: MIT -// Copyright (c) 2018-2020 The Pybricks Authors +// Copyright (c) 2018-2023 The Pybricks Authors #include "py/mpconfig.h" @@ -49,11 +49,10 @@ STATIC const mp_rom_map_elem_t nxtdevices_TouchSensor_locals_dict_table[] = { STATIC MP_DEFINE_CONST_DICT(nxtdevices_TouchSensor_locals_dict, nxtdevices_TouchSensor_locals_dict_table); // type(pybricks.ev3devices.TouchSensor) -const mp_obj_type_t pb_type_nxtdevices_TouchSensor = { - { &mp_type_type }, - .name = MP_QSTR_TouchSensor, - .make_new = nxtdevices_TouchSensor_make_new, - .locals_dict = (mp_obj_dict_t *)&nxtdevices_TouchSensor_locals_dict, -}; +MP_DEFINE_CONST_OBJ_TYPE(pb_type_nxtdevices_TouchSensor, + MP_QSTR_TouchSensor, + MP_TYPE_FLAG_NONE, + make_new, nxtdevices_TouchSensor_make_new, + locals_dict, &nxtdevices_TouchSensor_locals_dict); #endif // PYBRICKS_PY_NXTDEVICES && PYBRICKS_PY_EV3DEVICES diff --git a/pybricks/nxtdevices/pb_type_nxtdevices_ultrasonicsensor.c b/pybricks/nxtdevices/pb_type_nxtdevices_ultrasonicsensor.c index d498581f9..7b0a16225 100644 --- a/pybricks/nxtdevices/pb_type_nxtdevices_ultrasonicsensor.c +++ b/pybricks/nxtdevices/pb_type_nxtdevices_ultrasonicsensor.c @@ -1,5 +1,5 @@ // SPDX-License-Identifier: MIT -// Copyright (c) 2018-2020 The Pybricks Authors +// Copyright (c) 2018-2023 The Pybricks Authors #include "py/mpconfig.h" @@ -49,11 +49,10 @@ STATIC const mp_rom_map_elem_t nxtdevices_UltrasonicSensor_locals_dict_table[] = STATIC MP_DEFINE_CONST_DICT(nxtdevices_UltrasonicSensor_locals_dict, nxtdevices_UltrasonicSensor_locals_dict_table); // type(pybricks.nxtdevices.UltrasonicSensor) -const mp_obj_type_t pb_type_nxtdevices_UltrasonicSensor = { - { &mp_type_type }, - .name = MP_QSTR_UltrasonicSensor, - .make_new = nxtdevices_UltrasonicSensor_make_new, - .locals_dict = (mp_obj_dict_t *)&nxtdevices_UltrasonicSensor_locals_dict, -}; +MP_DEFINE_CONST_OBJ_TYPE(pb_type_nxtdevices_UltrasonicSensor, + MP_QSTR_UltrasonicSensor, + MP_TYPE_FLAG_NONE, + make_new, nxtdevices_UltrasonicSensor_make_new, + locals_dict, &nxtdevices_UltrasonicSensor_locals_dict); #endif // PYBRICKS_PY_NXTDEVICES && PYBRICKS_PY_EV3DEVICES diff --git a/pybricks/parameters/pb_type_axis.c b/pybricks/parameters/pb_type_axis.c index bbda6a5d2..cabf689c9 100644 --- a/pybricks/parameters/pb_type_axis.c +++ b/pybricks/parameters/pb_type_axis.c @@ -49,10 +49,9 @@ STATIC const mp_rom_map_elem_t pb_type_Axis_table[] = { }; STATIC MP_DEFINE_CONST_DICT(pb_type_Axis_locals_dict, pb_type_Axis_table); -const mp_obj_type_t pb_enum_type_Axis = { - { &mp_type_type }, - .name = MP_QSTR_Axis, - .locals_dict = (mp_obj_dict_t *)&(pb_type_Axis_locals_dict), -}; +MP_DEFINE_CONST_OBJ_TYPE(pb_enum_type_Axis, + MP_QSTR_Axis, + MP_TYPE_FLAG_NONE, + locals_dict, &(pb_type_Axis_locals_dict)); #endif // PYBRICKS_PY_PARAMETERS && MICROPY_PY_BUILTINS_FLOAT diff --git a/pybricks/parameters/pb_type_button.c b/pybricks/parameters/pb_type_button.c index 4f5a60617..09625dec0 100644 --- a/pybricks/parameters/pb_type_button.c +++ b/pybricks/parameters/pb_type_button.c @@ -1,5 +1,5 @@ // SPDX-License-Identifier: MIT -// Copyright (c) 2018-2020 The Pybricks Authors +// Copyright (c) 2018-2023 The Pybricks Authors #include "py/mpconfig.h" @@ -126,13 +126,12 @@ STATIC const mp_rom_map_elem_t pb_enum_Button_table[] = { }; STATIC MP_DEFINE_CONST_DICT(pb_enum_type_Button_locals_dict, pb_enum_Button_table); -const mp_obj_type_t pb_enum_type_Button = { - { &mp_type_type }, - .name = MP_QSTR_Button, - .print = pb_type_enum_print, - .unary_op = mp_generic_unary_op, - .locals_dict = (mp_obj_dict_t *)&(pb_enum_type_Button_locals_dict), -}; +MP_DEFINE_CONST_OBJ_TYPE(pb_enum_type_Button, + MP_QSTR_Button, + MP_TYPE_FLAG_NONE, + print, pb_type_enum_print, + unary_op, mp_generic_unary_op, + locals_dict, &(pb_enum_type_Button_locals_dict)); #endif // PYBRICKS_PY_PARAMETERS_BUTTON diff --git a/pybricks/parameters/pb_type_color.c b/pybricks/parameters/pb_type_color.c index ba70ae167..3bf9dd2e5 100644 --- a/pybricks/parameters/pb_type_color.c +++ b/pybricks/parameters/pb_type_color.c @@ -1,5 +1,5 @@ // SPDX-License-Identifier: MIT -// Copyright (c) 2018-2020 The Pybricks Authors +// Copyright (c) 2018-2023 The Pybricks Authors #include "py/mpconfig.h" @@ -145,7 +145,7 @@ void pb_type_Color_print(const mp_print_t *print, mp_obj_t self_in, mp_print_kin // If we're the class itself, use dict printer if (MP_OBJ_TO_PTR(self_in) == &pb_type_Color_obj) { - mp_type_dict.print(print, MP_OBJ_FROM_PTR(MP_STATE_VM(pb_type_Color_dict)), kind); + MP_OBJ_TYPE_GET_SLOT(&mp_type_dict, print)(print, MP_OBJ_FROM_PTR(MP_STATE_VM(pb_type_Color_dict)), kind); return; } @@ -177,7 +177,7 @@ STATIC mp_obj_t pb_type_Color_subscr(mp_obj_t self_in, mp_obj_t index, mp_obj_t } // Treat it like a dictionary - return mp_type_dict.subscr(MP_OBJ_FROM_PTR(MP_STATE_VM(pb_type_Color_dict)), index, value); + return MP_OBJ_TYPE_GET_SLOT(&mp_type_dict, subscr)(MP_OBJ_FROM_PTR(MP_STATE_VM(pb_type_Color_dict)), index, value); } STATIC mp_obj_t pb_type_Color_getiter(mp_obj_t self_in, mp_obj_iter_buf_t *iter_buf) { @@ -188,7 +188,7 @@ STATIC mp_obj_t pb_type_Color_getiter(mp_obj_t self_in, mp_obj_iter_buf_t *iter_ } // Treat it like a dictionary - return mp_type_dict.getiter(MP_OBJ_FROM_PTR(MP_STATE_VM(pb_type_Color_dict)), iter_buf); + return ((mp_getiter_fun_t)MP_OBJ_TYPE_GET_SLOT(&mp_type_dict, iter))(MP_OBJ_FROM_PTR(MP_STATE_VM(pb_type_Color_dict)), iter_buf); } STATIC void pb_type_Color_attr(mp_obj_t self_in, qstr attr, mp_obj_t *dest) { @@ -308,17 +308,16 @@ STATIC mp_obj_t pb_type_Color_call(mp_obj_t self_in, size_t n_args, size_t n_kw, return pb_type_Color_make_new_helper(pb_obj_get_int(h_in), pb_obj_get_int(s_in), pb_obj_get_int(v_in)); } -const mp_obj_type_t pb_type_Color = { - { &mp_type_type }, - .name = MP_QSTR_Color, - .call = pb_type_Color_call, - .attr = pb_type_Color_attr, - .print = pb_type_Color_print, - .unary_op = mp_generic_unary_op, - .binary_op = pb_type_Color_binary_op, - .subscr = pb_type_Color_subscr, - .getiter = pb_type_Color_getiter, -}; +MP_DEFINE_CONST_OBJ_TYPE(pb_type_Color, + MP_QSTR_Color, + MP_TYPE_FLAG_ITER_IS_GETITER, + call, pb_type_Color_call, + attr, pb_type_Color_attr, + print, pb_type_Color_print, + unary_op, mp_generic_unary_op, + binary_op, pb_type_Color_binary_op, + subscr, pb_type_Color_subscr, + iter, pb_type_Color_getiter); // We expose an instance instead of the type. This lets us provide class // attributes via the attribute handler for more flexibility. @@ -326,4 +325,6 @@ const mp_obj_base_t pb_type_Color_obj = { &pb_type_Color }; +MP_REGISTER_ROOT_POINTER(mp_obj_dict_t * pb_type_Color_dict); + #endif // PYBRICKS_PY_PARAMETERS diff --git a/pybricks/parameters/pb_type_direction.c b/pybricks/parameters/pb_type_direction.c index 46cf0dfd6..261704cd2 100644 --- a/pybricks/parameters/pb_type_direction.c +++ b/pybricks/parameters/pb_type_direction.c @@ -1,5 +1,5 @@ // SPDX-License-Identifier: MIT -// Copyright (c) 2018-2020 The Pybricks Authors +// Copyright (c) 2018-2023 The Pybricks Authors #include "py/mpconfig.h" @@ -29,12 +29,11 @@ STATIC const mp_rom_map_elem_t pb_enum_Direction_table[] = { }; STATIC MP_DEFINE_CONST_DICT(pb_enum_type_Direction_locals_dict, pb_enum_Direction_table); -const mp_obj_type_t pb_enum_type_Direction = { - { &mp_type_type }, - .name = MP_QSTR_Direction, - .print = pb_type_enum_print, - .unary_op = mp_generic_unary_op, - .locals_dict = (mp_obj_dict_t *)&(pb_enum_type_Direction_locals_dict), -}; +MP_DEFINE_CONST_OBJ_TYPE(pb_enum_type_Direction, + MP_QSTR_Direction, + MP_TYPE_FLAG_NONE, + print, pb_type_enum_print, + unary_op, mp_generic_unary_op, + locals_dict, &(pb_enum_type_Direction_locals_dict)); #endif // PYBRICKS_PY_PARAMETERS diff --git a/pybricks/parameters/pb_type_icon.c b/pybricks/parameters/pb_type_icon.c index 169cf4c45..43cf36803 100644 --- a/pybricks/parameters/pb_type_icon.c +++ b/pybricks/parameters/pb_type_icon.c @@ -1,5 +1,5 @@ // SPDX-License-Identifier: MIT -// Copyright (c) 2018-2020 The Pybricks Authors +// Copyright (c) 2021-2023 The Pybricks Authors #include "py/mpconfig.h" @@ -260,12 +260,11 @@ STATIC mp_obj_t pb_type_Icon_call(mp_obj_t self_in, size_t n_args, size_t n_kw, return pb_type_Matrix_make_bitmap(5, 5, 100, mp_obj_get_int(args[0])); } -STATIC const mp_obj_type_t pb_type_Icon = { - { &mp_type_type }, - .name = MP_QSTR_Icon, - .call = pb_type_Icon_call, - .attr = pb_type_Icon_attr, -}; +STATIC MP_DEFINE_CONST_OBJ_TYPE(pb_type_Icon, + MP_QSTR_Icon, + MP_TYPE_FLAG_NONE, + call, pb_type_Icon_call, + attr, pb_type_Icon_attr); // We expose an instance instead of the type. This workaround allows // us to provide class attributes via the attribute handler, generating diff --git a/pybricks/parameters/pb_type_port.c b/pybricks/parameters/pb_type_port.c index 673615cc8..33680272d 100644 --- a/pybricks/parameters/pb_type_port.c +++ b/pybricks/parameters/pb_type_port.c @@ -1,5 +1,5 @@ // SPDX-License-Identifier: MIT -// Copyright (c) 2018-2020 The Pybricks Authors +// Copyright (c) 2018-2023 The Pybricks Authors #include "py/mpconfig.h" @@ -127,12 +127,11 @@ STATIC const mp_rom_map_elem_t pb_enum_Port_table[] = { }; STATIC MP_DEFINE_CONST_DICT(pb_enum_type_Port_locals_dict, pb_enum_Port_table); -const mp_obj_type_t pb_enum_type_Port = { - { &mp_type_type }, - .name = MP_QSTR_Port, - .print = pb_type_enum_print, - .unary_op = mp_generic_unary_op, - .locals_dict = (mp_obj_dict_t *)&(pb_enum_type_Port_locals_dict), -}; +MP_DEFINE_CONST_OBJ_TYPE(pb_enum_type_Port, + MP_QSTR_Port, + MP_TYPE_FLAG_NONE, + print, pb_type_enum_print, + unary_op, mp_generic_unary_op, + locals_dict, &(pb_enum_type_Port_locals_dict)); #endif // PYBRICKS_PY_PARAMETERS diff --git a/pybricks/parameters/pb_type_side.c b/pybricks/parameters/pb_type_side.c index d9f591ca5..f1b5ea2df 100644 --- a/pybricks/parameters/pb_type_side.c +++ b/pybricks/parameters/pb_type_side.c @@ -1,5 +1,5 @@ // SPDX-License-Identifier: MIT -// Copyright (c) 2018-2020 The Pybricks Authors +// Copyright (c) 2018-2023 The Pybricks Authors #include "py/mpconfig.h" @@ -57,12 +57,11 @@ STATIC const mp_rom_map_elem_t pb_enum_Side_table[] = { }; STATIC MP_DEFINE_CONST_DICT(pb_enum_type_Side_locals_dict, pb_enum_Side_table); -const mp_obj_type_t pb_enum_type_Side = { - { &mp_type_type }, - .name = MP_QSTR_Side, - .print = pb_type_enum_print, - .unary_op = mp_generic_unary_op, - .locals_dict = (mp_obj_dict_t *)&(pb_enum_type_Side_locals_dict), -}; +MP_DEFINE_CONST_OBJ_TYPE(pb_enum_type_Side, + MP_QSTR_Side, + MP_TYPE_FLAG_NONE, + print, pb_type_enum_print, + unary_op, mp_generic_unary_op, + locals_dict, &(pb_enum_type_Side_locals_dict)); #endif // PYBRICKS_PY_PARAMETERS diff --git a/pybricks/parameters/pb_type_stop.c b/pybricks/parameters/pb_type_stop.c index d2bbdfe4c..756b98262 100644 --- a/pybricks/parameters/pb_type_stop.c +++ b/pybricks/parameters/pb_type_stop.c @@ -1,5 +1,5 @@ // SPDX-License-Identifier: MIT -// Copyright (c) 2018-2020 The Pybricks Authors +// Copyright (c) 2018-2023 The Pybricks Authors #include "py/mpconfig.h" @@ -57,11 +57,11 @@ STATIC const mp_rom_map_elem_t pb_enum_Stop_table[] = { }; STATIC MP_DEFINE_CONST_DICT(pb_enum_type_Stop_locals_dict, pb_enum_Stop_table); -const mp_obj_type_t pb_enum_type_Stop = { - { &mp_type_type }, - .name = MP_QSTR_Stop, - .print = pb_type_enum_print, - .unary_op = mp_generic_unary_op, - .locals_dict = (mp_obj_dict_t *)&(pb_enum_type_Stop_locals_dict), -}; +MP_DEFINE_CONST_OBJ_TYPE(pb_enum_type_Stop, + MP_QSTR_Stop, + MP_TYPE_FLAG_NONE, + print, pb_type_enum_print, + unary_op, mp_generic_unary_op, + locals_dict, &(pb_enum_type_Stop_locals_dict)); + #endif // PYBRICKS_PY_PARAMETERS diff --git a/pybricks/pupdevices/pb_type_pupdevices_colordistancesensor.c b/pybricks/pupdevices/pb_type_pupdevices_colordistancesensor.c index a3e0b9596..5fdb28c40 100644 --- a/pybricks/pupdevices/pb_type_pupdevices_colordistancesensor.c +++ b/pybricks/pupdevices/pb_type_pupdevices_colordistancesensor.c @@ -1,5 +1,5 @@ // SPDX-License-Identifier: MIT -// Copyright (c) 2018-2021 The Pybricks Authors +// Copyright (c) 2018-2023 The Pybricks Authors #include "py/mpconfig.h" @@ -165,13 +165,12 @@ STATIC const mp_rom_map_elem_t pupdevices_ColorDistanceSensor_locals_dict_table[ STATIC MP_DEFINE_CONST_DICT(pupdevices_ColorDistanceSensor_locals_dict, pupdevices_ColorDistanceSensor_locals_dict_table); // type(pybricks.pupdevices.ColorDistanceSensor) -const mp_obj_type_t pb_type_pupdevices_ColorDistanceSensor = { - { &mp_type_type }, - .name = MP_QSTR_ColorDistanceSensor, - .make_new = pupdevices_ColorDistanceSensor_make_new, - .attr = pb_attribute_handler, - .protocol = pupdevices_ColorDistanceSensor_attr_dict, - .locals_dict = (mp_obj_dict_t *)&pupdevices_ColorDistanceSensor_locals_dict, -}; +MP_DEFINE_CONST_OBJ_TYPE(pb_type_pupdevices_ColorDistanceSensor, + MP_QSTR_ColorDistanceSensor, + MP_TYPE_FLAG_NONE, + make_new, pupdevices_ColorDistanceSensor_make_new, + attr, pb_attribute_handler, + protocol, pupdevices_ColorDistanceSensor_attr_dict, + locals_dict, &pupdevices_ColorDistanceSensor_locals_dict); #endif // PYBRICKS_PY_PUPDEVICES diff --git a/pybricks/pupdevices/pb_type_pupdevices_colorlightmatrix.c b/pybricks/pupdevices/pb_type_pupdevices_colorlightmatrix.c index 137e9444e..fe8b5c2a1 100644 --- a/pybricks/pupdevices/pb_type_pupdevices_colorlightmatrix.c +++ b/pybricks/pupdevices/pb_type_pupdevices_colorlightmatrix.c @@ -1,5 +1,5 @@ // SPDX-License-Identifier: MIT -// Copyright (c) 2018-2020 The Pybricks Authors +// Copyright (c) 2018-2023 The Pybricks Authors #include "py/mpconfig.h" @@ -112,11 +112,10 @@ STATIC const mp_rom_map_elem_t pupdevices_ColorLightMatrix_locals_dict_table[] = STATIC MP_DEFINE_CONST_DICT(pupdevices_ColorLightMatrix_locals_dict, pupdevices_ColorLightMatrix_locals_dict_table); // type(pybricks.pupdevices.ColorLightMatrix) -const mp_obj_type_t pb_type_pupdevices_ColorLightMatrix = { - { &mp_type_type }, - .name = MP_QSTR_ColorLightMatrix, - .make_new = pupdevices_ColorLightMatrix_make_new, - .locals_dict = (mp_obj_dict_t *)&pupdevices_ColorLightMatrix_locals_dict, -}; +MP_DEFINE_CONST_OBJ_TYPE(pb_type_pupdevices_ColorLightMatrix, + MP_QSTR_ColorLightMatrix, + MP_TYPE_FLAG_NONE, + make_new, pupdevices_ColorLightMatrix_make_new, + locals_dict, &pupdevices_ColorLightMatrix_locals_dict); #endif // PYBRICKS_PY_PUPDEVICES diff --git a/pybricks/pupdevices/pb_type_pupdevices_colorsensor.c b/pybricks/pupdevices/pb_type_pupdevices_colorsensor.c index 62452b2a8..e874a4a9f 100644 --- a/pybricks/pupdevices/pb_type_pupdevices_colorsensor.c +++ b/pybricks/pupdevices/pb_type_pupdevices_colorsensor.c @@ -1,5 +1,5 @@ // SPDX-License-Identifier: MIT -// Copyright (c) 2018-2021 The Pybricks Authors +// Copyright (c) 2018-2023 The Pybricks Authors #include "py/mpconfig.h" @@ -167,13 +167,12 @@ STATIC const mp_rom_map_elem_t pupdevices_ColorSensor_locals_dict_table[] = { STATIC MP_DEFINE_CONST_DICT(pupdevices_ColorSensor_locals_dict, pupdevices_ColorSensor_locals_dict_table); // type(pybricks.pupdevices.ColorSensor) -const mp_obj_type_t pb_type_pupdevices_ColorSensor = { - { &mp_type_type }, - .name = MP_QSTR_ColorSensor, - .make_new = pupdevices_ColorSensor_make_new, - .attr = pb_attribute_handler, - .protocol = pupdevices_ColorSensor_attr_dict, - .locals_dict = (mp_obj_dict_t *)&pupdevices_ColorSensor_locals_dict, -}; +MP_DEFINE_CONST_OBJ_TYPE(pb_type_pupdevices_ColorSensor, + MP_QSTR_ColorSensor, + MP_TYPE_FLAG_NONE, + make_new, pupdevices_ColorSensor_make_new, + attr, pb_attribute_handler, + protocol, pupdevices_ColorSensor_attr_dict, + locals_dict, &pupdevices_ColorSensor_locals_dict); #endif // PYBRICKS_PY_PUPDEVICES diff --git a/pybricks/pupdevices/pb_type_pupdevices_forcesensor.c b/pybricks/pupdevices/pb_type_pupdevices_forcesensor.c index f3d37d452..055e7836e 100644 --- a/pybricks/pupdevices/pb_type_pupdevices_forcesensor.c +++ b/pybricks/pupdevices/pb_type_pupdevices_forcesensor.c @@ -1,5 +1,5 @@ // SPDX-License-Identifier: MIT -// Copyright (c) 2018-2020 The Pybricks Authors +// Copyright (c) 2018-2023 The Pybricks Authors #include "py/mpconfig.h" @@ -138,11 +138,10 @@ STATIC const mp_rom_map_elem_t pupdevices_ForceSensor_locals_dict_table[] = { STATIC MP_DEFINE_CONST_DICT(pupdevices_ForceSensor_locals_dict, pupdevices_ForceSensor_locals_dict_table); // type(pybricks.pupdevices.ForceSensor) -const mp_obj_type_t pb_type_pupdevices_ForceSensor = { - { &mp_type_type }, - .name = MP_QSTR_ForceSensor, - .make_new = pupdevices_ForceSensor_make_new, - .locals_dict = (mp_obj_dict_t *)&pupdevices_ForceSensor_locals_dict, -}; +MP_DEFINE_CONST_OBJ_TYPE(pb_type_pupdevices_ForceSensor, + MP_QSTR_ForceSensor, + MP_TYPE_FLAG_NONE, + make_new, pupdevices_ForceSensor_make_new, + locals_dict, &pupdevices_ForceSensor_locals_dict); #endif // PYBRICKS_PY_PUPDEVICES diff --git a/pybricks/pupdevices/pb_type_pupdevices_infraredsensor.c b/pybricks/pupdevices/pb_type_pupdevices_infraredsensor.c index 192cc1445..976e67628 100644 --- a/pybricks/pupdevices/pb_type_pupdevices_infraredsensor.c +++ b/pybricks/pupdevices/pb_type_pupdevices_infraredsensor.c @@ -1,5 +1,5 @@ // SPDX-License-Identifier: MIT -// Copyright (c) 2018-2020 The Pybricks Authors +// Copyright (c) 2018-2023 The Pybricks Authors #include "py/mpconfig.h" @@ -80,11 +80,10 @@ STATIC const mp_rom_map_elem_t pupdevices_InfraredSensor_locals_dict_table[] = { STATIC MP_DEFINE_CONST_DICT(pupdevices_InfraredSensor_locals_dict, pupdevices_InfraredSensor_locals_dict_table); // type(pybricks.pupdevices.InfraredSensor) -const mp_obj_type_t pb_type_pupdevices_InfraredSensor = { - { &mp_type_type }, - .name = MP_QSTR_InfraredSensor, - .make_new = pupdevices_InfraredSensor_make_new, - .locals_dict = (mp_obj_dict_t *)&pupdevices_InfraredSensor_locals_dict, -}; +MP_DEFINE_CONST_OBJ_TYPE(pb_type_pupdevices_InfraredSensor, + MP_QSTR_InfraredSensor, + MP_TYPE_FLAG_NONE, + make_new, pupdevices_InfraredSensor_make_new, + locals_dict, &pupdevices_InfraredSensor_locals_dict); #endif // PYBRICKS_PY_PUPDEVICES diff --git a/pybricks/pupdevices/pb_type_pupdevices_light.c b/pybricks/pupdevices/pb_type_pupdevices_light.c index 5412b16ef..f6d5a83f8 100644 --- a/pybricks/pupdevices/pb_type_pupdevices_light.c +++ b/pybricks/pupdevices/pb_type_pupdevices_light.c @@ -1,5 +1,5 @@ // SPDX-License-Identifier: MIT -// Copyright (c) 2018-2020 The Pybricks Authors +// Copyright (c) 2018-2023 The Pybricks Authors #include "py/mpconfig.h" @@ -63,11 +63,10 @@ STATIC const mp_rom_map_elem_t pupdevices_Light_locals_dict_table[] = { STATIC MP_DEFINE_CONST_DICT(pupdevices_Light_locals_dict, pupdevices_Light_locals_dict_table); // type(pybricks.pupdevices.Light) -const mp_obj_type_t pb_type_pupdevices_Light = { - { &mp_type_type }, - .name = MP_QSTR_Light, - .make_new = pupdevices_Light_make_new, - .locals_dict = (mp_obj_dict_t *)&pupdevices_Light_locals_dict, -}; +MP_DEFINE_CONST_OBJ_TYPE(pb_type_pupdevices_Light, + MP_QSTR_Light, + MP_TYPE_FLAG_NONE, + make_new, pupdevices_Light_make_new, + locals_dict, &pupdevices_Light_locals_dict); #endif // PYBRICKS_PY_PUPDEVICES diff --git a/pybricks/pupdevices/pb_type_pupdevices_pfmotor.c b/pybricks/pupdevices/pb_type_pupdevices_pfmotor.c index d86cf8827..74fc12c68 100644 --- a/pybricks/pupdevices/pb_type_pupdevices_pfmotor.c +++ b/pybricks/pupdevices/pb_type_pupdevices_pfmotor.c @@ -1,5 +1,5 @@ // SPDX-License-Identifier: MIT -// Copyright (c) 2018-2020 The Pybricks Authors +// Copyright (c) 2018-2023 The Pybricks Authors #include "py/mpconfig.h" @@ -155,11 +155,10 @@ STATIC const mp_rom_map_elem_t pupdevices_PFMotor_locals_dict_table[] = { STATIC MP_DEFINE_CONST_DICT(pupdevices_PFMotor_locals_dict, pupdevices_PFMotor_locals_dict_table); // type(pybricks.pupdevices.PFMotor) -const mp_obj_type_t pb_type_pupdevices_PFMotor = { - { &mp_type_type }, - .name = MP_QSTR_PFMotor, - .make_new = pupdevices_PFMotor_make_new, - .locals_dict = (mp_obj_dict_t *)&pupdevices_PFMotor_locals_dict, -}; +MP_DEFINE_CONST_OBJ_TYPE(pb_type_pupdevices_PFMotor, + MP_QSTR_PFMotor, + MP_TYPE_FLAG_NONE, + make_new, pupdevices_PFMotor_make_new, + locals_dict, &pupdevices_PFMotor_locals_dict); #endif // PYBRICKS_PY_PUPDEVICES diff --git a/pybricks/pupdevices/pb_type_pupdevices_remote.c b/pybricks/pupdevices/pb_type_pupdevices_remote.c index 4fcce0d63..985c902a5 100644 --- a/pybricks/pupdevices/pb_type_pupdevices_remote.c +++ b/pybricks/pupdevices/pb_type_pupdevices_remote.c @@ -333,13 +333,12 @@ STATIC const mp_rom_map_elem_t pb_type_pupdevices_Remote_locals_dict_table[] = { }; STATIC MP_DEFINE_CONST_DICT(pb_type_pupdevices_Remote_locals_dict, pb_type_pupdevices_Remote_locals_dict_table); -const mp_obj_type_t pb_type_pupdevices_Remote = { - { &mp_type_type }, - .name = MP_QSTR_Remote, - .make_new = pb_type_pupdevices_Remote_make_new, - .attr = pb_attribute_handler, - .protocol = pb_type_pupdevices_Remote_attr_dict, - .locals_dict = (mp_obj_dict_t *)&pb_type_pupdevices_Remote_locals_dict, -}; +MP_DEFINE_CONST_OBJ_TYPE(pb_type_pupdevices_Remote, + MP_QSTR_Remote, + MP_TYPE_FLAG_NONE, + make_new, pb_type_pupdevices_Remote_make_new, + attr, pb_attribute_handler, + protocol, pb_type_pupdevices_Remote_attr_dict, + locals_dict, &pb_type_pupdevices_Remote_locals_dict); #endif // PYBRICKS_PY_PUPDEVICES diff --git a/pybricks/pupdevices/pb_type_pupdevices_tiltsensor.c b/pybricks/pupdevices/pb_type_pupdevices_tiltsensor.c index abc1d6551..9ab83f644 100644 --- a/pybricks/pupdevices/pb_type_pupdevices_tiltsensor.c +++ b/pybricks/pupdevices/pb_type_pupdevices_tiltsensor.c @@ -1,5 +1,5 @@ // SPDX-License-Identifier: MIT -// Copyright (c) 2018-2020 The Pybricks Authors +// Copyright (c) 2018-2023 The Pybricks Authors #include "py/mpconfig.h" @@ -53,11 +53,10 @@ STATIC const mp_rom_map_elem_t pupdevices_TiltSensor_locals_dict_table[] = { STATIC MP_DEFINE_CONST_DICT(pupdevices_TiltSensor_locals_dict, pupdevices_TiltSensor_locals_dict_table); // type(pybricks.pupdevices.TiltSensor) -const mp_obj_type_t pb_type_pupdevices_TiltSensor = { - { &mp_type_type }, - .name = MP_QSTR_TiltSensor, - .make_new = pupdevices_TiltSensor_make_new, - .locals_dict = (mp_obj_dict_t *)&pupdevices_TiltSensor_locals_dict, -}; +MP_DEFINE_CONST_OBJ_TYPE(pb_type_pupdevices_TiltSensor, + MP_QSTR_TiltSensor, + MP_TYPE_FLAG_NONE, + make_new, pupdevices_TiltSensor_make_new, + locals_dict, &pupdevices_TiltSensor_locals_dict); #endif // PYBRICKS_PY_PUPDEVICES diff --git a/pybricks/pupdevices/pb_type_pupdevices_ultrasonicsensor.c b/pybricks/pupdevices/pb_type_pupdevices_ultrasonicsensor.c index b4d35caf4..f25ad000f 100644 --- a/pybricks/pupdevices/pb_type_pupdevices_ultrasonicsensor.c +++ b/pybricks/pupdevices/pb_type_pupdevices_ultrasonicsensor.c @@ -1,5 +1,5 @@ // SPDX-License-Identifier: MIT -// Copyright (c) 2018-2021 The Pybricks Authors +// Copyright (c) 2018-2023 The Pybricks Authors #include "py/mpconfig.h" @@ -69,13 +69,12 @@ STATIC const mp_rom_map_elem_t pupdevices_UltrasonicSensor_locals_dict_table[] = STATIC MP_DEFINE_CONST_DICT(pupdevices_UltrasonicSensor_locals_dict, pupdevices_UltrasonicSensor_locals_dict_table); // type(pybricks.pupdevices.UltrasonicSensor) -const mp_obj_type_t pb_type_pupdevices_UltrasonicSensor = { - { &mp_type_type }, - .name = MP_QSTR_UltrasonicSensor, - .make_new = pupdevices_UltrasonicSensor_make_new, - .attr = pb_attribute_handler, - .protocol = pupdevices_UltrasonicSensor_attr_dict, - .locals_dict = (mp_obj_dict_t *)&pupdevices_UltrasonicSensor_locals_dict, -}; +MP_DEFINE_CONST_OBJ_TYPE(pb_type_pupdevices_UltrasonicSensor, + MP_QSTR_UltrasonicSensor, + MP_TYPE_FLAG_NONE, + make_new, pupdevices_UltrasonicSensor_make_new, + attr, pb_attribute_handler, + protocol, pupdevices_UltrasonicSensor_attr_dict, + locals_dict, &pupdevices_UltrasonicSensor_locals_dict); #endif // PYBRICKS_PY_PUPDEVICES diff --git a/pybricks/pybricks.c b/pybricks/pybricks.c index 8952fa771..646019538 100644 --- a/pybricks/pybricks.c +++ b/pybricks/pybricks.c @@ -1,5 +1,5 @@ // SPDX-License-Identifier: MIT -// Copyright (c) 2018-2022 The Pybricks Authors +// Copyright (c) 2018-2023 The Pybricks Authors #include @@ -87,7 +87,7 @@ static void pb_package_import_all(void) { #if PYBRICKS_PY_HUBS // Initialize hub instance const mp_obj_t args; - mp_store_name(MP_QSTR_hub, pb_type_ThisHub.make_new(&pb_type_ThisHub, 0, 0, &args)); + mp_store_name(MP_QSTR_hub, MP_OBJ_TYPE_GET_SLOT(&pb_type_ThisHub, make_new)(&pb_type_ThisHub, 0, 0, &args)); #endif } diff --git a/pybricks/robotics/pb_type_drivebase.c b/pybricks/robotics/pb_type_drivebase.c index 8d16c5547..b20daac69 100644 --- a/pybricks/robotics/pb_type_drivebase.c +++ b/pybricks/robotics/pb_type_drivebase.c @@ -315,29 +315,27 @@ STATIC const mp_rom_map_elem_t pb_type_DriveBase_locals_dict_table[] = { STATIC MP_DEFINE_CONST_DICT(pb_type_DriveBase_locals_dict, pb_type_DriveBase_locals_dict_table); // type(pybricks.robotics.DriveBase) -const mp_obj_type_t pb_type_drivebase = { - { &mp_type_type }, - .name = MP_QSTR_DriveBase, - .make_new = pb_type_DriveBase_make_new, +MP_DEFINE_CONST_OBJ_TYPE(pb_type_drivebase, + MP_QSTR_DriveBase, + MP_TYPE_FLAG_NONE, + make_new, pb_type_DriveBase_make_new, #if PYBRICKS_PY_COMMON_CONTROL - .attr = pb_attribute_handler, - .protocol = pb_type_DriveBase_attr_dict, + attr, pb_attribute_handler, + protocol, pb_type_DriveBase_attr_dict, #endif - .locals_dict = (mp_obj_dict_t *)&pb_type_DriveBase_locals_dict, -}; + locals_dict, &pb_type_DriveBase_locals_dict); #if PYBRICKS_PY_ROBOTICS_DRIVEBASE_GYRO // type(pybricks.robotics.GyroDriveBase) -const mp_obj_type_t pb_type_gyrodrivebase = { - { &mp_type_type }, - .name = MP_QSTR_GyroDriveBase, - .make_new = pb_type_DriveBase_make_new, +MP_DEFINE_CONST_OBJ_TYPE(pb_type_gyrodrivebase, + MP_QSTR_GyroDriveBase, + MP_TYPE_FLAG_NONE, + make_new, pb_type_DriveBase_make_new, #if PYBRICKS_PY_COMMON_CONTROL - .attr = pb_attribute_handler, - .protocol = pb_type_DriveBase_attr_dict, + attr, pb_attribute_handler, + protocol, pb_type_DriveBase_attr_dict, #endif - .locals_dict = (mp_obj_dict_t *)&pb_type_DriveBase_locals_dict, -}; + locals_dict, &pb_type_DriveBase_locals_dict); #endif // PYBRICKS_PY_ROBOTICS_DRIVEBASE_GYRO #endif // PYBRICKS_PY_ROBOTICS && PYBRICKS_PY_COMMON_MOTORS diff --git a/pybricks/robotics/pb_type_spikebase.c b/pybricks/robotics/pb_type_spikebase.c index b1797fbad..a61e6a949 100644 --- a/pybricks/robotics/pb_type_spikebase.c +++ b/pybricks/robotics/pb_type_spikebase.c @@ -1,5 +1,5 @@ // SPDX-License-Identifier: MIT -// Copyright (c) 2021 The Pybricks Authors +// Copyright (c) 2021-2023 The Pybricks Authors #include "py/mpconfig.h" @@ -243,13 +243,12 @@ STATIC const mp_rom_map_elem_t robotics_SpikeBase_locals_dict_table[] = { STATIC MP_DEFINE_CONST_DICT(robotics_SpikeBase_locals_dict, robotics_SpikeBase_locals_dict_table); // type(pybricks.robotics.SpikeBase) -const mp_obj_type_t pb_type_spikebase = { - { &mp_type_type }, - .name = MP_QSTR_SpikeBase, - .make_new = robotics_SpikeBase_make_new, - .attr = pb_attribute_handler, - .protocol = robotics_SpikeBase_attr_dict, - .locals_dict = (mp_obj_dict_t *)&robotics_SpikeBase_locals_dict, -}; +MP_DEFINE_CONST_OBJ_TYPE(pb_type_spikebase, + MP_QSTR_SpikeBase, + MP_TYPE_FLAG_NONE, + make_new, robotics_SpikeBase_make_new, + attr, pb_attribute_handler, + protocol, robotics_SpikeBase_attr_dict, + locals_dict, &robotics_SpikeBase_locals_dict); #endif // PYBRICKS_PY_ROBOTICS && PYBRICKS_PY_ROBOTICS_DRIVEBASE_SPIKE diff --git a/pybricks/tools/pb_type_matrix.c b/pybricks/tools/pb_type_matrix.c index 53e9aa0e0..ab6be00e4 100644 --- a/pybricks/tools/pb_type_matrix.c +++ b/pybricks/tools/pb_type_matrix.c @@ -514,17 +514,16 @@ STATIC mp_obj_t pb_type_Matrix_getiter(mp_obj_t o_in, mp_obj_iter_buf_t *iter_bu } // type(pybricks.tools.Matrix) -const mp_obj_type_t pb_type_Matrix = { - { &mp_type_type }, - .name = MP_QSTR_Matrix, - .print = pb_type_Matrix_print, - .make_new = pb_type_Matrix_make_new, - .attr = pb_type_Matrix_attr, - .unary_op = pb_type_Matrix_unary_op, - .binary_op = pb_type_Matrix_binary_op, - .subscr = pb_type_Matrix_subscr, - .getiter = pb_type_Matrix_getiter, -}; +MP_DEFINE_CONST_OBJ_TYPE(pb_type_Matrix, + MP_QSTR_Matrix, + MP_TYPE_FLAG_ITER_IS_GETITER, + print, pb_type_Matrix_print, + make_new, pb_type_Matrix_make_new, + attr, pb_type_Matrix_attr, + unary_op, pb_type_Matrix_unary_op, + binary_op, pb_type_Matrix_binary_op, + subscr, pb_type_Matrix_subscr, + iter, pb_type_Matrix_getiter); // pybricks.tools._make_vector mp_obj_t pb_type_Matrix_make_vector(size_t m, float *data, bool normalize) { diff --git a/pybricks/tools/pb_type_stopwatch.c b/pybricks/tools/pb_type_stopwatch.c index 668bac7e6..c20d8bc29 100644 --- a/pybricks/tools/pb_type_stopwatch.c +++ b/pybricks/tools/pb_type_stopwatch.c @@ -1,5 +1,5 @@ // SPDX-License-Identifier: MIT -// Copyright (c) 2018-2020 The Pybricks Authors +// Copyright (c) 2018-2023 The Pybricks Authors #include "py/mpconfig.h" @@ -75,11 +75,10 @@ STATIC const mp_rom_map_elem_t tools_StopWatch_locals_dict_table[] = { }; STATIC MP_DEFINE_CONST_DICT(tools_StopWatch_locals_dict, tools_StopWatch_locals_dict_table); -const mp_obj_type_t pb_type_StopWatch = { - { &mp_type_type }, - .name = MP_QSTR_StopWatch, - .make_new = tools_StopWatch_make_new, - .locals_dict = (mp_obj_dict_t *)&tools_StopWatch_locals_dict, -}; +MP_DEFINE_CONST_OBJ_TYPE(pb_type_StopWatch, + MP_QSTR_StopWatch, + MP_TYPE_FLAG_NONE, + make_new, tools_StopWatch_make_new, + locals_dict, &tools_StopWatch_locals_dict); #endif // PYBRICKS_PY_TOOLS diff --git a/pybricks/util_mp/pb_obj_helper.c b/pybricks/util_mp/pb_obj_helper.c index f927b82f4..a8c5c12f4 100644 --- a/pybricks/util_mp/pb_obj_helper.c +++ b/pybricks/util_mp/pb_obj_helper.c @@ -1,5 +1,5 @@ // SPDX-License-Identifier: MIT -// Copyright (c) 2019-2021 The Pybricks Authors +// Copyright (c) 2019-2023 The Pybricks Authors #include #include @@ -156,7 +156,7 @@ void pb_attribute_handler(mp_obj_t self_in, qstr attr, mp_obj_t *dest) { const mp_obj_type_t *type = mp_obj_get_type(self_in); // type may have been subclassed - while (type->attr != pb_attribute_handler) { + while (MP_OBJ_TYPE_GET_SLOT_OR_NULL(type, attr) != pb_attribute_handler) { type = type->base.type; if (type == &mp_type_type) { @@ -168,7 +168,7 @@ void pb_attribute_handler(mp_obj_t self_in, qstr attr, mp_obj_t *dest) { } // Get number of attributes and reference to attributes array. - const pb_attr_dict_entry_t *attr_dict = type->protocol; + const pb_attr_dict_entry_t *attr_dict = MP_OBJ_TYPE_GET_SLOT(type, protocol); const pb_attr_dict_entry_t *entry = NULL; // Look up the attribute offset. attr_dict is zero-terminated. diff --git a/test-ev3dev.sh b/test-ev3dev.sh index 33110bfd2..a4ba79199 100755 --- a/test-ev3dev.sh +++ b/test-ev3dev.sh @@ -13,9 +13,9 @@ MP_TEST_DIR="$SCRIPT_DIR/micropython/tests" PB_TEST_DIR=$(readlink -f "$SCRIPT_DIR/tests") BUILD_DIR=$(readlink -f "$BRICK_DIR/build-test") -rm -f "$BRICK_DIR/pybricks-micropython" -make -s -j $(nproc --all) -C "$BRICK_DIR" pybricks-micropython build-test/libgrx-3.0-vdriver-test.so CROSS_COMPILE= DEBUG=1 COPT=-O0 BUILD=build-test +make -s -j $(nproc --all) -C "$BRICK_DIR" build-test/pybricks-micropython build-test/libgrx-3.0-vdriver-test.so CROSS_COMPILE= DEBUG=1 COPT=-O0 BUILD=build-test +export PYBRICKS_MICROPYTHON="$BUILD_DIR/pybricks-micropython" export MICROPY_MICROPYTHON="$PB_TEST_DIR/ev3dev/test-wrapper.sh" export GRX_PLUGIN_PATH="$BUILD_DIR" export GRX_DRIVER=test diff --git a/tests/ev3dev/test-wrapper.sh b/tests/ev3dev/test-wrapper.sh index df2c0f092..e2e4ee9c6 100755 --- a/tests/ev3dev/test-wrapper.sh +++ b/tests/ev3dev/test-wrapper.sh @@ -6,4 +6,4 @@ DIR=$(dirname "$(readlink -f $0)") export EV3DEV_MOCKS_UMOCKDEV_RUN_ARGS="-d $DIR/lego-ev3-large-motor-port-a.umockdev" -exec ev3dev-mocks-run "$DIR/../../bricks/ev3dev/pybricks-micropython" "$@" +exec ev3dev-mocks-run "$PYBRICKS_MICROPYTHON" "$@" diff --git a/tests/virtualhub/motor/test_1.py b/tests/virtualhub/motor/test_1.py index 9eb1ee1f9..376e7654b 100644 --- a/tests/virtualhub/motor/test_1.py +++ b/tests/virtualhub/motor/test_1.py @@ -2,8 +2,8 @@ from pybricks.parameters import Port from pybricks.tools import wait, StopWatch -from errno import ETIMEDOUT -from os import getenv +from uerrno import ETIMEDOUT +from uos import getenv # environment variables allow running one-off tests TARGET_ANGLE = int(getenv("TARGET_ANGLE", 1000))