From 4ebdb1f2b217410cdc1cee0e0c0da8fceb7627f2 Mon Sep 17 00:00:00 2001 From: Damien George Date: Tue, 18 Oct 2016 11:06:20 +1100 Subject: [PATCH] py: Be more specific with MP_DECLARE_CONST_FUN_OBJ macros. In order to have more fine-grained control over how builtin functions are constructed, the MP_DECLARE_CONST_FUN_OBJ macros are made more specific, with suffix of _0, _1, _2, _3, _VAR, _VAR_BETEEN or _KW. These names now match the MP_DEFINE_CONST_FUN_OBJ macros. --- bare-arm/mpconfigport.h | 1 - cc3200/util/random.h | 2 +- drivers/dht/dht.h | 2 +- esp8266/modpyb.h | 2 +- extmod/fsusermount.h | 6 +-- extmod/machine_pulse.h | 2 +- extmod/machine_spi.h | 8 ++-- extmod/misc.h | 2 +- extmod/modubinascii.h | 10 ++--- extmod/utime_mphal.h | 14 +++--- extmod/vfs_fat_file.h | 2 +- lib/utils/pyexec.h | 2 +- minimal/mpconfigport.h | 1 - pic16bit/mpconfigport.h | 1 - py/builtin.h | 96 ++++++++++++++++++++--------------------- py/obj.h | 10 ++++- py/objstr.h | 54 +++++++++++------------ py/stream.h | 24 +++++------ qemu-arm/mpconfigport.h | 1 - stmhal/irq.h | 8 ++-- stmhal/modmachine.h | 14 +++--- stmhal/modpyb.c | 2 +- stmhal/pin.h | 2 +- stmhal/portmodules.h | 8 ++-- stmhal/rng.h | 2 +- stmhal/servo.h | 4 +- stmhal/usb.h | 6 +-- teensy/modpyb.c | 6 +-- teensy/servo.h | 4 +- unix/main.c | 2 +- unix/modos.c | 6 +-- 31 files changed, 151 insertions(+), 153 deletions(-) diff --git a/bare-arm/mpconfigport.h b/bare-arm/mpconfigport.h index 79b2b73283..912fae66fc 100644 --- a/bare-arm/mpconfigport.h +++ b/bare-arm/mpconfigport.h @@ -61,7 +61,6 @@ typedef long mp_off_t; #define MP_PLAT_PRINT_STRN(str, len) (void)0 // extra built in names to add to the global namespace -extern const struct _mp_obj_fun_builtin_t mp_builtin_open_obj; #define MICROPY_PORT_BUILTINS \ { MP_OBJ_NEW_QSTR(MP_QSTR_open), (mp_obj_t)&mp_builtin_open_obj }, diff --git a/cc3200/util/random.h b/cc3200/util/random.h index 860b46173f..67fd1ff855 100644 --- a/cc3200/util/random.h +++ b/cc3200/util/random.h @@ -30,6 +30,6 @@ void rng_init0 (void); uint32_t rng_get (void); -MP_DECLARE_CONST_FUN_OBJ(machine_rng_get_obj); +MP_DECLARE_CONST_FUN_OBJ_0(machine_rng_get_obj); #endif // __RANDOM_H diff --git a/drivers/dht/dht.h b/drivers/dht/dht.h index 8274228ac6..20954036df 100644 --- a/drivers/dht/dht.h +++ b/drivers/dht/dht.h @@ -1,3 +1,3 @@ #include "py/obj.h" -MP_DECLARE_CONST_FUN_OBJ(dht_readinto_obj); +MP_DECLARE_CONST_FUN_OBJ_2(dht_readinto_obj); diff --git a/esp8266/modpyb.h b/esp8266/modpyb.h index 45d0bb8cfd..c23a119e8d 100644 --- a/esp8266/modpyb.h +++ b/esp8266/modpyb.h @@ -13,7 +13,7 @@ extern const mp_obj_type_t pyb_spi_type; extern const mp_obj_type_t pyb_hspi_type; extern const mp_obj_type_t machine_spi_type; -MP_DECLARE_CONST_FUN_OBJ(pyb_info_obj); +MP_DECLARE_CONST_FUN_OBJ_VAR_BETWEEN(pyb_info_obj); typedef struct _pyb_pin_obj_t { mp_obj_base_t base; diff --git a/extmod/fsusermount.h b/extmod/fsusermount.h index e1f26f2ce8..af6867d23c 100644 --- a/extmod/fsusermount.h +++ b/extmod/fsusermount.h @@ -57,6 +57,6 @@ typedef struct _fs_user_mount_t { fs_user_mount_t *fatfs_mount_mkfs(mp_uint_t n_args, const mp_obj_t *pos_args, mp_map_t *kw_args, bool mkfs); mp_obj_t fatfs_umount(mp_obj_t bdev_or_path_in); -MP_DECLARE_CONST_FUN_OBJ(fsuser_mount_obj); -MP_DECLARE_CONST_FUN_OBJ(fsuser_umount_obj); -MP_DECLARE_CONST_FUN_OBJ(fsuser_mkfs_obj); +MP_DECLARE_CONST_FUN_OBJ_KW(fsuser_mount_obj); +MP_DECLARE_CONST_FUN_OBJ_1(fsuser_umount_obj); +MP_DECLARE_CONST_FUN_OBJ_KW(fsuser_mkfs_obj); diff --git a/extmod/machine_pulse.h b/extmod/machine_pulse.h index 3d5d81c073..cc1c4eda5f 100644 --- a/extmod/machine_pulse.h +++ b/extmod/machine_pulse.h @@ -32,6 +32,6 @@ mp_uint_t machine_time_pulse_us(mp_hal_pin_obj_t pin, int pulse_level, mp_uint_t timeout_us); -MP_DECLARE_CONST_FUN_OBJ(machine_time_pulse_us_obj); +MP_DECLARE_CONST_FUN_OBJ_VAR_BETWEEN(machine_time_pulse_us_obj); #endif // __MICROPY_INCLUDED_EXTMOD_MACHINE_PULSE_H__ diff --git a/extmod/machine_spi.h b/extmod/machine_spi.h index 316d06646e..62f42a8851 100644 --- a/extmod/machine_spi.h +++ b/extmod/machine_spi.h @@ -47,9 +47,9 @@ typedef struct _mp_machine_soft_spi_obj_t { void mp_machine_soft_spi_transfer(mp_obj_base_t *self, size_t len, const uint8_t *src, uint8_t *dest); -MP_DECLARE_CONST_FUN_OBJ(mp_machine_spi_read_obj); -MP_DECLARE_CONST_FUN_OBJ(mp_machine_spi_readinto_obj); -MP_DECLARE_CONST_FUN_OBJ(mp_machine_spi_write_obj); -MP_DECLARE_CONST_FUN_OBJ(mp_machine_spi_write_readinto_obj); +MP_DECLARE_CONST_FUN_OBJ_VAR_BETWEEN(mp_machine_spi_read_obj); +MP_DECLARE_CONST_FUN_OBJ_VAR_BETWEEN(mp_machine_spi_readinto_obj); +MP_DECLARE_CONST_FUN_OBJ_2(mp_machine_spi_write_obj); +MP_DECLARE_CONST_FUN_OBJ_3(mp_machine_spi_write_readinto_obj); #endif // MICROPY_INCLUDED_EXTMOD_MACHINE_SPI_H diff --git a/extmod/misc.h b/extmod/misc.h index 634ea924d0..d7ead06549 100644 --- a/extmod/misc.h +++ b/extmod/misc.h @@ -30,7 +30,7 @@ #include #include "py/runtime.h" -MP_DECLARE_CONST_FUN_OBJ(mp_uos_dupterm_obj); +MP_DECLARE_CONST_FUN_OBJ_VAR_BETWEEN(mp_uos_dupterm_obj); #if MICROPY_PY_OS_DUPTERM void mp_uos_dupterm_tx_strn(const char *str, size_t len); diff --git a/extmod/modubinascii.h b/extmod/modubinascii.h index 71dd8a6936..33d0f1cbd8 100644 --- a/extmod/modubinascii.h +++ b/extmod/modubinascii.h @@ -33,10 +33,10 @@ extern mp_obj_t mod_binascii_a2b_base64(mp_obj_t data); extern mp_obj_t mod_binascii_b2a_base64(mp_obj_t data); extern mp_obj_t mod_binascii_crc32(size_t n_args, const mp_obj_t *args); -MP_DECLARE_CONST_FUN_OBJ(mod_binascii_hexlify_obj); -MP_DECLARE_CONST_FUN_OBJ(mod_binascii_unhexlify_obj); -MP_DECLARE_CONST_FUN_OBJ(mod_binascii_a2b_base64_obj); -MP_DECLARE_CONST_FUN_OBJ(mod_binascii_b2a_base64_obj); -MP_DECLARE_CONST_FUN_OBJ(mod_binascii_crc32_obj); +MP_DECLARE_CONST_FUN_OBJ_VAR_BETWEEN(mod_binascii_hexlify_obj); +MP_DECLARE_CONST_FUN_OBJ_1(mod_binascii_unhexlify_obj); +MP_DECLARE_CONST_FUN_OBJ_1(mod_binascii_a2b_base64_obj); +MP_DECLARE_CONST_FUN_OBJ_1(mod_binascii_b2a_base64_obj); +MP_DECLARE_CONST_FUN_OBJ_VAR_BETWEEN(mod_binascii_crc32_obj); #endif /* MICROPY_EXTMOD_MODUBINASCII */ diff --git a/extmod/utime_mphal.h b/extmod/utime_mphal.h index 4f2395a090..c7611e251b 100644 --- a/extmod/utime_mphal.h +++ b/extmod/utime_mphal.h @@ -27,10 +27,10 @@ #include "py/obj.h" -MP_DECLARE_CONST_FUN_OBJ(mp_utime_sleep_obj); -MP_DECLARE_CONST_FUN_OBJ(mp_utime_sleep_ms_obj); -MP_DECLARE_CONST_FUN_OBJ(mp_utime_sleep_us_obj); -MP_DECLARE_CONST_FUN_OBJ(mp_utime_ticks_ms_obj); -MP_DECLARE_CONST_FUN_OBJ(mp_utime_ticks_us_obj); -MP_DECLARE_CONST_FUN_OBJ(mp_utime_ticks_cpu_obj); -MP_DECLARE_CONST_FUN_OBJ(mp_utime_ticks_diff_obj); +MP_DECLARE_CONST_FUN_OBJ_1(mp_utime_sleep_obj); +MP_DECLARE_CONST_FUN_OBJ_1(mp_utime_sleep_ms_obj); +MP_DECLARE_CONST_FUN_OBJ_1(mp_utime_sleep_us_obj); +MP_DECLARE_CONST_FUN_OBJ_0(mp_utime_ticks_ms_obj); +MP_DECLARE_CONST_FUN_OBJ_0(mp_utime_ticks_us_obj); +MP_DECLARE_CONST_FUN_OBJ_0(mp_utime_ticks_cpu_obj); +MP_DECLARE_CONST_FUN_OBJ_2(mp_utime_ticks_diff_obj); diff --git a/extmod/vfs_fat_file.h b/extmod/vfs_fat_file.h index 6d68889550..5c271b6ee6 100644 --- a/extmod/vfs_fat_file.h +++ b/extmod/vfs_fat_file.h @@ -27,6 +27,6 @@ extern const byte fresult_to_errno_table[20]; mp_obj_t fatfs_builtin_open(mp_uint_t n_args, const mp_obj_t *args, mp_map_t *kwargs); -MP_DECLARE_CONST_FUN_OBJ(mp_builtin_open_obj); +MP_DECLARE_CONST_FUN_OBJ_KW(mp_builtin_open_obj); mp_obj_t fat_vfs_listdir(const char *path, bool is_str_type); diff --git a/lib/utils/pyexec.h b/lib/utils/pyexec.h index ae69a195e7..0c7567e273 100644 --- a/lib/utils/pyexec.h +++ b/lib/utils/pyexec.h @@ -49,6 +49,6 @@ void pyexec_event_repl_init(void); int pyexec_event_repl_process_char(int c); extern uint8_t pyexec_repl_active; -MP_DECLARE_CONST_FUN_OBJ(pyb_set_repl_info_obj); +MP_DECLARE_CONST_FUN_OBJ_1(pyb_set_repl_info_obj); #endif // __MICROPY_INCLUDED_LIB_UTILS_PYEXEC_H__ diff --git a/minimal/mpconfigport.h b/minimal/mpconfigport.h index fc696c77e5..5236babf68 100644 --- a/minimal/mpconfigport.h +++ b/minimal/mpconfigport.h @@ -70,7 +70,6 @@ typedef long mp_off_t; #define MP_PLAT_PRINT_STRN(str, len) mp_hal_stdout_tx_strn_cooked(str, len) // extra built in names to add to the global namespace -extern const struct _mp_obj_fun_builtin_t mp_builtin_open_obj; #define MICROPY_PORT_BUILTINS \ { MP_OBJ_NEW_QSTR(MP_QSTR_open), (mp_obj_t)&mp_builtin_open_obj }, diff --git a/pic16bit/mpconfigport.h b/pic16bit/mpconfigport.h index 24cfe43529..a0371a8ae3 100644 --- a/pic16bit/mpconfigport.h +++ b/pic16bit/mpconfigport.h @@ -88,7 +88,6 @@ typedef int mp_off_t; #define MP_PLAT_PRINT_STRN(str, len) mp_hal_stdout_tx_strn_cooked(str, len) // extra builtin names to add to the global namespace -extern const struct _mp_obj_fun_builtin_t mp_builtin_open_obj; #define MICROPY_PORT_BUILTINS \ { MP_OBJ_NEW_QSTR(MP_QSTR_open), (mp_obj_t)&mp_builtin_open_obj }, diff --git a/py/builtin.h b/py/builtin.h index cd1be3ab88..df33e2b73a 100644 --- a/py/builtin.h +++ b/py/builtin.h @@ -32,56 +32,55 @@ mp_obj_t mp_builtin___import__(size_t n_args, const mp_obj_t *args); mp_obj_t mp_builtin_open(size_t n_args, const mp_obj_t *args, mp_map_t *kwargs); mp_obj_t mp_micropython_mem_info(size_t n_args, const mp_obj_t *args); -MP_DECLARE_CONST_FUN_OBJ(mp_builtin___build_class___obj); -MP_DECLARE_CONST_FUN_OBJ(mp_builtin___import___obj); -MP_DECLARE_CONST_FUN_OBJ(mp_builtin___repl_print___obj); -MP_DECLARE_CONST_FUN_OBJ(mp_builtin_abs_obj); -MP_DECLARE_CONST_FUN_OBJ(mp_builtin_all_obj); -MP_DECLARE_CONST_FUN_OBJ(mp_builtin_any_obj); -MP_DECLARE_CONST_FUN_OBJ(mp_builtin_bin_obj); -MP_DECLARE_CONST_FUN_OBJ(mp_builtin_callable_obj); -MP_DECLARE_CONST_FUN_OBJ(mp_builtin_compile_obj); -MP_DECLARE_CONST_FUN_OBJ(mp_builtin_chr_obj); -MP_DECLARE_CONST_FUN_OBJ(mp_builtin_dir_obj); -MP_DECLARE_CONST_FUN_OBJ(mp_builtin_divmod_obj); -MP_DECLARE_CONST_FUN_OBJ(mp_builtin_eval_obj); -MP_DECLARE_CONST_FUN_OBJ(mp_builtin_exec_obj); -MP_DECLARE_CONST_FUN_OBJ(mp_builtin_execfile_obj); -MP_DECLARE_CONST_FUN_OBJ(mp_builtin_getattr_obj); -MP_DECLARE_CONST_FUN_OBJ(mp_builtin_setattr_obj); -MP_DECLARE_CONST_FUN_OBJ(mp_builtin_globals_obj); -MP_DECLARE_CONST_FUN_OBJ(mp_builtin_hasattr_obj); -MP_DECLARE_CONST_FUN_OBJ(mp_builtin_hash_obj); -MP_DECLARE_CONST_FUN_OBJ(mp_builtin_hex_obj); -MP_DECLARE_CONST_FUN_OBJ(mp_builtin_id_obj); -MP_DECLARE_CONST_FUN_OBJ(mp_builtin_isinstance_obj); -MP_DECLARE_CONST_FUN_OBJ(mp_builtin_issubclass_obj); -MP_DECLARE_CONST_FUN_OBJ(mp_builtin_iter_obj); -MP_DECLARE_CONST_FUN_OBJ(mp_builtin_len_obj); -MP_DECLARE_CONST_FUN_OBJ(mp_builtin_list_obj); -MP_DECLARE_CONST_FUN_OBJ(mp_builtin_locals_obj); -MP_DECLARE_CONST_FUN_OBJ(mp_builtin_max_obj); -MP_DECLARE_CONST_FUN_OBJ(mp_builtin_min_obj); -MP_DECLARE_CONST_FUN_OBJ(mp_builtin_next_obj); -MP_DECLARE_CONST_FUN_OBJ(mp_builtin_oct_obj); -MP_DECLARE_CONST_FUN_OBJ(mp_builtin_ord_obj); -MP_DECLARE_CONST_FUN_OBJ(mp_builtin_pow_obj); -MP_DECLARE_CONST_FUN_OBJ(mp_builtin_print_obj); -MP_DECLARE_CONST_FUN_OBJ(mp_builtin_repr_obj); -MP_DECLARE_CONST_FUN_OBJ(mp_builtin_round_obj); -MP_DECLARE_CONST_FUN_OBJ(mp_builtin_sorted_obj); -MP_DECLARE_CONST_FUN_OBJ(mp_builtin_sum_obj); +MP_DECLARE_CONST_FUN_OBJ_VAR(mp_builtin___build_class___obj); +MP_DECLARE_CONST_FUN_OBJ_VAR_BETWEEN(mp_builtin___import___obj); +MP_DECLARE_CONST_FUN_OBJ_1(mp_builtin___repl_print___obj); +MP_DECLARE_CONST_FUN_OBJ_1(mp_builtin_abs_obj); +MP_DECLARE_CONST_FUN_OBJ_1(mp_builtin_all_obj); +MP_DECLARE_CONST_FUN_OBJ_1(mp_builtin_any_obj); +MP_DECLARE_CONST_FUN_OBJ_1(mp_builtin_bin_obj); +MP_DECLARE_CONST_FUN_OBJ_1(mp_builtin_callable_obj); +MP_DECLARE_CONST_FUN_OBJ_VAR_BETWEEN(mp_builtin_compile_obj); +MP_DECLARE_CONST_FUN_OBJ_1(mp_builtin_chr_obj); +MP_DECLARE_CONST_FUN_OBJ_VAR_BETWEEN(mp_builtin_dir_obj); +MP_DECLARE_CONST_FUN_OBJ_2(mp_builtin_divmod_obj); +MP_DECLARE_CONST_FUN_OBJ_VAR_BETWEEN(mp_builtin_eval_obj); +MP_DECLARE_CONST_FUN_OBJ_VAR_BETWEEN(mp_builtin_exec_obj); +MP_DECLARE_CONST_FUN_OBJ_VAR_BETWEEN(mp_builtin_execfile_obj); +MP_DECLARE_CONST_FUN_OBJ_VAR_BETWEEN(mp_builtin_getattr_obj); +MP_DECLARE_CONST_FUN_OBJ_3(mp_builtin_setattr_obj); +MP_DECLARE_CONST_FUN_OBJ_0(mp_builtin_globals_obj); +MP_DECLARE_CONST_FUN_OBJ_2(mp_builtin_hasattr_obj); +MP_DECLARE_CONST_FUN_OBJ_1(mp_builtin_hash_obj); +MP_DECLARE_CONST_FUN_OBJ_1(mp_builtin_hex_obj); +MP_DECLARE_CONST_FUN_OBJ_1(mp_builtin_id_obj); +MP_DECLARE_CONST_FUN_OBJ_2(mp_builtin_isinstance_obj); +MP_DECLARE_CONST_FUN_OBJ_2(mp_builtin_issubclass_obj); +MP_DECLARE_CONST_FUN_OBJ_1(mp_builtin_iter_obj); +MP_DECLARE_CONST_FUN_OBJ_1(mp_builtin_len_obj); +MP_DECLARE_CONST_FUN_OBJ_0(mp_builtin_locals_obj); +MP_DECLARE_CONST_FUN_OBJ_KW(mp_builtin_max_obj); +MP_DECLARE_CONST_FUN_OBJ_KW(mp_builtin_min_obj); +MP_DECLARE_CONST_FUN_OBJ_1(mp_builtin_next_obj); +MP_DECLARE_CONST_FUN_OBJ_1(mp_builtin_oct_obj); +MP_DECLARE_CONST_FUN_OBJ_1(mp_builtin_ord_obj); +MP_DECLARE_CONST_FUN_OBJ_VAR_BETWEEN(mp_builtin_pow_obj); +MP_DECLARE_CONST_FUN_OBJ_KW(mp_builtin_print_obj); +MP_DECLARE_CONST_FUN_OBJ_1(mp_builtin_repr_obj); +MP_DECLARE_CONST_FUN_OBJ_VAR_BETWEEN(mp_builtin_round_obj); +MP_DECLARE_CONST_FUN_OBJ_KW(mp_builtin_sorted_obj); +MP_DECLARE_CONST_FUN_OBJ_VAR_BETWEEN(mp_builtin_sum_obj); // Defined by a port, but declared here for simplicity -MP_DECLARE_CONST_FUN_OBJ(mp_builtin_help_obj); -MP_DECLARE_CONST_FUN_OBJ(mp_builtin_input_obj); -MP_DECLARE_CONST_FUN_OBJ(mp_builtin_open_obj); +MP_DECLARE_CONST_FUN_OBJ_VAR_BETWEEN(mp_builtin_help_obj); +MP_DECLARE_CONST_FUN_OBJ_VAR_BETWEEN(mp_builtin_input_obj); +MP_DECLARE_CONST_FUN_OBJ_KW(mp_builtin_open_obj); -MP_DECLARE_CONST_FUN_OBJ(mp_namedtuple_obj); +MP_DECLARE_CONST_FUN_OBJ_2(mp_namedtuple_obj); -MP_DECLARE_CONST_FUN_OBJ(mp_op_contains_obj); -MP_DECLARE_CONST_FUN_OBJ(mp_op_getitem_obj); -MP_DECLARE_CONST_FUN_OBJ(mp_op_setitem_obj); -MP_DECLARE_CONST_FUN_OBJ(mp_op_delitem_obj); +MP_DECLARE_CONST_FUN_OBJ_2(mp_op_contains_obj); +MP_DECLARE_CONST_FUN_OBJ_2(mp_op_getitem_obj); +MP_DECLARE_CONST_FUN_OBJ_3(mp_op_setitem_obj); +MP_DECLARE_CONST_FUN_OBJ_2(mp_op_delitem_obj); extern const mp_obj_module_t mp_module___main__; extern const mp_obj_module_t mp_module_builtins; @@ -116,7 +115,4 @@ extern const mp_obj_module_t mp_module_webrepl; extern const mp_obj_module_t mp_module_framebuf; extern const mp_obj_module_t mp_module_btree; -// extmod functions -MP_DECLARE_CONST_FUN_OBJ(pyb_mount_obj); - #endif // __MICROPY_INCLUDED_PY_BUILTIN_H__ diff --git a/py/obj.h b/py/obj.h index 72d79ce14b..e4fa19ac99 100644 --- a/py/obj.h +++ b/py/obj.h @@ -270,7 +270,13 @@ static inline bool mp_obj_is_integer(mp_const_obj_t o) { return MP_OBJ_IS_INT(o) // These macros are used to declare and define constant function objects // You can put "static" in front of the definitions to make them local -#define MP_DECLARE_CONST_FUN_OBJ(obj_name) extern const mp_obj_fun_builtin_t obj_name +#define MP_DECLARE_CONST_FUN_OBJ_0(obj_name) extern const mp_obj_fun_builtin_t obj_name +#define MP_DECLARE_CONST_FUN_OBJ_1(obj_name) extern const mp_obj_fun_builtin_t obj_name +#define MP_DECLARE_CONST_FUN_OBJ_2(obj_name) extern const mp_obj_fun_builtin_t obj_name +#define MP_DECLARE_CONST_FUN_OBJ_3(obj_name) extern const mp_obj_fun_builtin_t obj_name +#define MP_DECLARE_CONST_FUN_OBJ_VAR(obj_name) extern const mp_obj_fun_builtin_t obj_name +#define MP_DECLARE_CONST_FUN_OBJ_VAR_BETWEEN(obj_name) extern const mp_obj_fun_builtin_t obj_name +#define MP_DECLARE_CONST_FUN_OBJ_KW(obj_name) extern const mp_obj_fun_builtin_t obj_name #define MP_DEFINE_CONST_FUN_OBJ_0(obj_name, fun_name) \ const mp_obj_fun_builtin_t obj_name = \ @@ -760,7 +766,7 @@ qstr mp_obj_fun_get_name(mp_const_obj_t fun); qstr mp_obj_code_get_name(const byte *code_info); mp_obj_t mp_identity(mp_obj_t self); -MP_DECLARE_CONST_FUN_OBJ(mp_identity_obj); +MP_DECLARE_CONST_FUN_OBJ_1(mp_identity_obj); // module typedef struct _mp_obj_module_t { diff --git a/py/objstr.h b/py/objstr.h index e14568dac4..ad2777afbc 100644 --- a/py/objstr.h +++ b/py/objstr.h @@ -74,32 +74,32 @@ const byte *str_index_to_ptr(const mp_obj_type_t *type, const byte *self_data, s mp_obj_t index, bool is_slice); const byte *find_subbytes(const byte *haystack, mp_uint_t hlen, const byte *needle, mp_uint_t nlen, mp_int_t direction); -MP_DECLARE_CONST_FUN_OBJ(str_encode_obj); -MP_DECLARE_CONST_FUN_OBJ(str_find_obj); -MP_DECLARE_CONST_FUN_OBJ(str_rfind_obj); -MP_DECLARE_CONST_FUN_OBJ(str_index_obj); -MP_DECLARE_CONST_FUN_OBJ(str_rindex_obj); -MP_DECLARE_CONST_FUN_OBJ(str_join_obj); -MP_DECLARE_CONST_FUN_OBJ(str_split_obj); -MP_DECLARE_CONST_FUN_OBJ(str_splitlines_obj); -MP_DECLARE_CONST_FUN_OBJ(str_rsplit_obj); -MP_DECLARE_CONST_FUN_OBJ(str_startswith_obj); -MP_DECLARE_CONST_FUN_OBJ(str_endswith_obj); -MP_DECLARE_CONST_FUN_OBJ(str_strip_obj); -MP_DECLARE_CONST_FUN_OBJ(str_lstrip_obj); -MP_DECLARE_CONST_FUN_OBJ(str_rstrip_obj); -MP_DECLARE_CONST_FUN_OBJ(str_format_obj); -MP_DECLARE_CONST_FUN_OBJ(str_replace_obj); -MP_DECLARE_CONST_FUN_OBJ(str_count_obj); -MP_DECLARE_CONST_FUN_OBJ(str_partition_obj); -MP_DECLARE_CONST_FUN_OBJ(str_rpartition_obj); -MP_DECLARE_CONST_FUN_OBJ(str_center_obj); -MP_DECLARE_CONST_FUN_OBJ(str_lower_obj); -MP_DECLARE_CONST_FUN_OBJ(str_upper_obj); -MP_DECLARE_CONST_FUN_OBJ(str_isspace_obj); -MP_DECLARE_CONST_FUN_OBJ(str_isalpha_obj); -MP_DECLARE_CONST_FUN_OBJ(str_isdigit_obj); -MP_DECLARE_CONST_FUN_OBJ(str_isupper_obj); -MP_DECLARE_CONST_FUN_OBJ(str_islower_obj); +MP_DECLARE_CONST_FUN_OBJ_VAR_BETWEEN(str_encode_obj); +MP_DECLARE_CONST_FUN_OBJ_VAR_BETWEEN(str_find_obj); +MP_DECLARE_CONST_FUN_OBJ_VAR_BETWEEN(str_rfind_obj); +MP_DECLARE_CONST_FUN_OBJ_VAR_BETWEEN(str_index_obj); +MP_DECLARE_CONST_FUN_OBJ_VAR_BETWEEN(str_rindex_obj); +MP_DECLARE_CONST_FUN_OBJ_2(str_join_obj); +MP_DECLARE_CONST_FUN_OBJ_VAR_BETWEEN(str_split_obj); +MP_DECLARE_CONST_FUN_OBJ_KW(str_splitlines_obj); +MP_DECLARE_CONST_FUN_OBJ_VAR_BETWEEN(str_rsplit_obj); +MP_DECLARE_CONST_FUN_OBJ_VAR_BETWEEN(str_startswith_obj); +MP_DECLARE_CONST_FUN_OBJ_VAR_BETWEEN(str_endswith_obj); +MP_DECLARE_CONST_FUN_OBJ_VAR_BETWEEN(str_strip_obj); +MP_DECLARE_CONST_FUN_OBJ_VAR_BETWEEN(str_lstrip_obj); +MP_DECLARE_CONST_FUN_OBJ_VAR_BETWEEN(str_rstrip_obj); +MP_DECLARE_CONST_FUN_OBJ_KW(str_format_obj); +MP_DECLARE_CONST_FUN_OBJ_VAR_BETWEEN(str_replace_obj); +MP_DECLARE_CONST_FUN_OBJ_VAR_BETWEEN(str_count_obj); +MP_DECLARE_CONST_FUN_OBJ_2(str_partition_obj); +MP_DECLARE_CONST_FUN_OBJ_2(str_rpartition_obj); +MP_DECLARE_CONST_FUN_OBJ_2(str_center_obj); +MP_DECLARE_CONST_FUN_OBJ_1(str_lower_obj); +MP_DECLARE_CONST_FUN_OBJ_1(str_upper_obj); +MP_DECLARE_CONST_FUN_OBJ_1(str_isspace_obj); +MP_DECLARE_CONST_FUN_OBJ_1(str_isalpha_obj); +MP_DECLARE_CONST_FUN_OBJ_1(str_isdigit_obj); +MP_DECLARE_CONST_FUN_OBJ_1(str_isupper_obj); +MP_DECLARE_CONST_FUN_OBJ_1(str_islower_obj); #endif // __MICROPY_INCLUDED_PY_OBJSTR_H__ diff --git a/py/stream.h b/py/stream.h index 33d85e823c..4cdea11eba 100644 --- a/py/stream.h +++ b/py/stream.h @@ -48,18 +48,18 @@ struct mp_stream_seek_t { int whence; }; -MP_DECLARE_CONST_FUN_OBJ(mp_stream_read_obj); -MP_DECLARE_CONST_FUN_OBJ(mp_stream_read1_obj); -MP_DECLARE_CONST_FUN_OBJ(mp_stream_readinto_obj); -MP_DECLARE_CONST_FUN_OBJ(mp_stream_readall_obj); -MP_DECLARE_CONST_FUN_OBJ(mp_stream_unbuffered_readline_obj); -MP_DECLARE_CONST_FUN_OBJ(mp_stream_unbuffered_readlines_obj); -MP_DECLARE_CONST_FUN_OBJ(mp_stream_write_obj); -MP_DECLARE_CONST_FUN_OBJ(mp_stream_write1_obj); -MP_DECLARE_CONST_FUN_OBJ(mp_stream_seek_obj); -MP_DECLARE_CONST_FUN_OBJ(mp_stream_tell_obj); -MP_DECLARE_CONST_FUN_OBJ(mp_stream_flush_obj); -MP_DECLARE_CONST_FUN_OBJ(mp_stream_ioctl_obj); +MP_DECLARE_CONST_FUN_OBJ_VAR_BETWEEN(mp_stream_read_obj); +MP_DECLARE_CONST_FUN_OBJ_VAR_BETWEEN(mp_stream_read1_obj); +MP_DECLARE_CONST_FUN_OBJ_VAR_BETWEEN(mp_stream_readinto_obj); +MP_DECLARE_CONST_FUN_OBJ_1(mp_stream_readall_obj); +MP_DECLARE_CONST_FUN_OBJ_VAR_BETWEEN(mp_stream_unbuffered_readline_obj); +MP_DECLARE_CONST_FUN_OBJ_1(mp_stream_unbuffered_readlines_obj); +MP_DECLARE_CONST_FUN_OBJ_VAR_BETWEEN(mp_stream_write_obj); +MP_DECLARE_CONST_FUN_OBJ_2(mp_stream_write1_obj); +MP_DECLARE_CONST_FUN_OBJ_VAR_BETWEEN(mp_stream_seek_obj); +MP_DECLARE_CONST_FUN_OBJ_1(mp_stream_tell_obj); +MP_DECLARE_CONST_FUN_OBJ_1(mp_stream_flush_obj); +MP_DECLARE_CONST_FUN_OBJ_VAR_BETWEEN(mp_stream_ioctl_obj); // these are for mp_get_stream_raise and can be or'd together #define MP_STREAM_OP_READ (1) diff --git a/qemu-arm/mpconfigport.h b/qemu-arm/mpconfigport.h index b8806405bc..2b8ae855ad 100644 --- a/qemu-arm/mpconfigport.h +++ b/qemu-arm/mpconfigport.h @@ -53,7 +53,6 @@ typedef long mp_off_t; #define MP_PLAT_PRINT_STRN(str, len) write(1, str, len) // extra built in names to add to the global namespace -extern const struct _mp_obj_fun_builtin_t mp_builtin_open_obj; #define MICROPY_PORT_BUILTINS \ { MP_OBJ_NEW_QSTR(MP_QSTR_open), (mp_obj_t)&mp_builtin_open_obj }, diff --git a/stmhal/irq.h b/stmhal/irq.h index 5a08a7d501..bb1749e031 100644 --- a/stmhal/irq.h +++ b/stmhal/irq.h @@ -70,10 +70,10 @@ static inline void restore_irq_pri(uint32_t basepri) { #endif -MP_DECLARE_CONST_FUN_OBJ(pyb_wfi_obj); -MP_DECLARE_CONST_FUN_OBJ(pyb_disable_irq_obj); -MP_DECLARE_CONST_FUN_OBJ(pyb_enable_irq_obj); -MP_DECLARE_CONST_FUN_OBJ(pyb_irq_stats_obj); +MP_DECLARE_CONST_FUN_OBJ_0(pyb_wfi_obj); +MP_DECLARE_CONST_FUN_OBJ_0(pyb_disable_irq_obj); +MP_DECLARE_CONST_FUN_OBJ_VAR_BETWEEN(pyb_enable_irq_obj); +MP_DECLARE_CONST_FUN_OBJ_0(pyb_irq_stats_obj); // IRQ priority definitions. // diff --git a/stmhal/modmachine.h b/stmhal/modmachine.h index 042afb850c..164c5cfda2 100644 --- a/stmhal/modmachine.h +++ b/stmhal/modmachine.h @@ -33,12 +33,12 @@ void machine_init(void); -MP_DECLARE_CONST_FUN_OBJ(machine_info_obj); -MP_DECLARE_CONST_FUN_OBJ(machine_unique_id_obj); -MP_DECLARE_CONST_FUN_OBJ(machine_reset_obj); -MP_DECLARE_CONST_FUN_OBJ(machine_bootloader_obj); -MP_DECLARE_CONST_FUN_OBJ(machine_freq_obj); -MP_DECLARE_CONST_FUN_OBJ(machine_sleep_obj); -MP_DECLARE_CONST_FUN_OBJ(machine_deepsleep_obj); +MP_DECLARE_CONST_FUN_OBJ_VAR_BETWEEN(machine_info_obj); +MP_DECLARE_CONST_FUN_OBJ_0(machine_unique_id_obj); +MP_DECLARE_CONST_FUN_OBJ_0(machine_reset_obj); +MP_DECLARE_CONST_FUN_OBJ_0(machine_bootloader_obj); +MP_DECLARE_CONST_FUN_OBJ_VAR_BETWEEN(machine_freq_obj); +MP_DECLARE_CONST_FUN_OBJ_0(machine_sleep_obj); +MP_DECLARE_CONST_FUN_OBJ_0(machine_deepsleep_obj); #endif // __MICROPY_INCLUDED_STMHAL_MODMACHINE_H__ diff --git a/stmhal/modpyb.c b/stmhal/modpyb.c index 5b2bf7aa99..e602234fc6 100644 --- a/stmhal/modpyb.c +++ b/stmhal/modpyb.c @@ -126,7 +126,7 @@ STATIC mp_obj_t pyb_elapsed_micros(mp_obj_t start) { } STATIC MP_DEFINE_CONST_FUN_OBJ_1(pyb_elapsed_micros_obj, pyb_elapsed_micros); -MP_DECLARE_CONST_FUN_OBJ(pyb_main_obj); // defined in main.c +MP_DECLARE_CONST_FUN_OBJ_KW(pyb_main_obj); // defined in main.c STATIC const mp_map_elem_t pyb_module_globals_table[] = { { MP_OBJ_NEW_QSTR(MP_QSTR___name__), MP_OBJ_NEW_QSTR(MP_QSTR_pyb) }, diff --git a/stmhal/pin.h b/stmhal/pin.h index df7df0ce2e..a11b0a0f8e 100644 --- a/stmhal/pin.h +++ b/stmhal/pin.h @@ -86,7 +86,7 @@ extern const mp_obj_type_t pin_cpu_pins_obj_type; extern const mp_obj_dict_t pin_cpu_pins_locals_dict; extern const mp_obj_dict_t pin_board_pins_locals_dict; -MP_DECLARE_CONST_FUN_OBJ(pin_init_obj); +MP_DECLARE_CONST_FUN_OBJ_KW(pin_init_obj); void pin_init0(void); uint32_t pin_get_mode(const pin_obj_t *pin); diff --git a/stmhal/portmodules.h b/stmhal/portmodules.h index 68ae2f47ce..173d53cc68 100644 --- a/stmhal/portmodules.h +++ b/stmhal/portmodules.h @@ -33,8 +33,8 @@ extern const mp_obj_module_t mp_module_usocket; // additional helper functions exported by the modules -MP_DECLARE_CONST_FUN_OBJ(time_sleep_ms_obj); -MP_DECLARE_CONST_FUN_OBJ(time_sleep_us_obj); +MP_DECLARE_CONST_FUN_OBJ_1(time_sleep_ms_obj); +MP_DECLARE_CONST_FUN_OBJ_1(time_sleep_us_obj); -MP_DECLARE_CONST_FUN_OBJ(mod_os_sync_obj); -MP_DECLARE_CONST_FUN_OBJ(mod_os_dupterm_obj); +MP_DECLARE_CONST_FUN_OBJ_0(mod_os_sync_obj); +MP_DECLARE_CONST_FUN_OBJ_VAR_BETWEEN(mod_os_dupterm_obj); diff --git a/stmhal/rng.h b/stmhal/rng.h index f1e5054ad2..ce1833e80b 100644 --- a/stmhal/rng.h +++ b/stmhal/rng.h @@ -27,4 +27,4 @@ void rng_init0(void); uint32_t rng_get(void); -MP_DECLARE_CONST_FUN_OBJ(pyb_rng_get_obj); +MP_DECLARE_CONST_FUN_OBJ_0(pyb_rng_get_obj); diff --git a/stmhal/servo.h b/stmhal/servo.h index 121ce922df..0fca8fea17 100644 --- a/stmhal/servo.h +++ b/stmhal/servo.h @@ -29,5 +29,5 @@ void servo_timer_irq_callback(void); extern const mp_obj_type_t pyb_servo_type; -MP_DECLARE_CONST_FUN_OBJ(pyb_servo_set_obj); -MP_DECLARE_CONST_FUN_OBJ(pyb_pwm_set_obj); +MP_DECLARE_CONST_FUN_OBJ_2(pyb_servo_set_obj); +MP_DECLARE_CONST_FUN_OBJ_2(pyb_pwm_set_obj); diff --git a/stmhal/usb.h b/stmhal/usb.h index debb4aa7c4..e153f0c6b6 100644 --- a/stmhal/usb.h +++ b/stmhal/usb.h @@ -53,9 +53,9 @@ extern const struct _mp_obj_tuple_t pyb_usb_hid_mouse_obj; extern const struct _mp_obj_tuple_t pyb_usb_hid_keyboard_obj; extern const mp_obj_type_t pyb_usb_vcp_type; extern const mp_obj_type_t pyb_usb_hid_type; -MP_DECLARE_CONST_FUN_OBJ(pyb_usb_mode_obj); -MP_DECLARE_CONST_FUN_OBJ(pyb_have_cdc_obj); // deprecated -MP_DECLARE_CONST_FUN_OBJ(pyb_hid_send_report_obj); // deprecated +MP_DECLARE_CONST_FUN_OBJ_KW(pyb_usb_mode_obj); +MP_DECLARE_CONST_FUN_OBJ_0(pyb_have_cdc_obj); // deprecated +MP_DECLARE_CONST_FUN_OBJ_1(pyb_hid_send_report_obj); // deprecated void pyb_usb_init0(void); bool pyb_usb_dev_init(uint16_t vid, uint16_t pid, usb_device_mode_t mode, USBD_HID_ModeInfoTypeDef *hid_info); diff --git a/teensy/modpyb.c b/teensy/modpyb.c index 0eb2a7b517..9f601e327b 100644 --- a/teensy/modpyb.c +++ b/teensy/modpyb.c @@ -272,9 +272,9 @@ STATIC mp_obj_t pyb_hid_send_report(mp_obj_t arg) { } STATIC MP_DEFINE_CONST_FUN_OBJ_1(pyb_hid_send_report_obj, pyb_hid_send_report); -MP_DECLARE_CONST_FUN_OBJ(pyb_source_dir_obj); // defined in main.c -MP_DECLARE_CONST_FUN_OBJ(pyb_main_obj); // defined in main.c -MP_DECLARE_CONST_FUN_OBJ(pyb_usb_mode_obj); // defined in main.c +MP_DECLARE_CONST_FUN_OBJ_1(pyb_source_dir_obj); // defined in main.c +MP_DECLARE_CONST_FUN_OBJ_1(pyb_main_obj); // defined in main.c +MP_DECLARE_CONST_FUN_OBJ_1(pyb_usb_mode_obj); // defined in main.c STATIC const mp_map_elem_t pyb_module_globals_table[] = { { MP_OBJ_NEW_QSTR(MP_QSTR___name__), MP_OBJ_NEW_QSTR(MP_QSTR_pyb) }, diff --git a/teensy/servo.h b/teensy/servo.h index 5dad041138..5f1c87b693 100644 --- a/teensy/servo.h +++ b/teensy/servo.h @@ -2,6 +2,6 @@ void servo_init(void); extern const mp_obj_type_t pyb_servo_type; -MP_DECLARE_CONST_FUN_OBJ(pyb_servo_set_obj); -MP_DECLARE_CONST_FUN_OBJ(pyb_pwm_set_obj); +MP_DECLARE_CONST_FUN_OBJ_2(pyb_servo_set_obj); +MP_DECLARE_CONST_FUN_OBJ_2(pyb_pwm_set_obj); diff --git a/unix/main.c b/unix/main.c index a1c057400f..482d1944e2 100644 --- a/unix/main.c +++ b/unix/main.c @@ -461,7 +461,7 @@ MP_NOINLINE int main_(int argc, char **argv) { #if defined(MICROPY_UNIX_COVERAGE) { - MP_DECLARE_CONST_FUN_OBJ(extra_coverage_obj); + MP_DECLARE_CONST_FUN_OBJ_0(extra_coverage_obj); mp_store_global(QSTR_FROM_STR_STATIC("extra_coverage"), MP_OBJ_FROM_PTR(&extra_coverage_obj)); } #endif diff --git a/unix/modos.c b/unix/modos.c index 36945720d1..72f5d872e4 100644 --- a/unix/modos.c +++ b/unix/modos.c @@ -43,9 +43,9 @@ // Can't include this, as FATFS structure definition is required, // and FatFs header defining it conflicts with POSIX. //#include "extmod/fsusermount.h" -MP_DECLARE_CONST_FUN_OBJ(fsuser_mount_obj); -MP_DECLARE_CONST_FUN_OBJ(fsuser_umount_obj); -MP_DECLARE_CONST_FUN_OBJ(fsuser_mkfs_obj); +MP_DECLARE_CONST_FUN_OBJ_KW(fsuser_mount_obj); +MP_DECLARE_CONST_FUN_OBJ_1(fsuser_umount_obj); +MP_DECLARE_CONST_FUN_OBJ_KW(fsuser_mkfs_obj); extern const mp_obj_type_t mp_fat_vfs_type; #ifdef __ANDROID__