py: Change first arg of type.make_new from mp_obj_t to mp_obj_type_t*.
The first argument to the type.make_new method is naturally a uPy type, and all uses of this argument cast it directly to a pointer to a type structure. So it makes sense to just have it a pointer to a type from the very beginning (and a const pointer at that). This patch makes such a change, and removes all unnecessary casting to/from mp_obj_t.
This commit is contained in:
parent
4b72b3a133
commit
5b3f0b7f39
@ -91,7 +91,7 @@ STATIC const mp_arg_t network_server_args[] = {
|
||||
{ MP_QSTR_login, MP_ARG_KW_ONLY | MP_ARG_OBJ, {.u_obj = MP_OBJ_NULL} },
|
||||
{ MP_QSTR_timeout, MP_ARG_KW_ONLY | MP_ARG_OBJ, {.u_obj = MP_OBJ_NULL} },
|
||||
};
|
||||
STATIC mp_obj_t network_server_make_new(mp_obj_t type_in, mp_uint_t n_args, mp_uint_t n_kw, const mp_obj_t *all_args) {
|
||||
STATIC mp_obj_t network_server_make_new(const mp_obj_type_t *type, mp_uint_t n_args, mp_uint_t n_kw, const mp_obj_t *all_args) {
|
||||
// parse args
|
||||
mp_map_t kw_args;
|
||||
mp_map_init_fixed_table(&kw_args, n_kw, all_args + n_args);
|
||||
|
@ -125,7 +125,7 @@ void modusocket_close_all_user_sockets (void) {
|
||||
// socket class
|
||||
|
||||
// constructor socket(family=AF_INET, type=SOCK_STREAM, proto=IPPROTO_TCP, fileno=None)
|
||||
STATIC mp_obj_t socket_make_new(mp_obj_t type_in, mp_uint_t n_args, mp_uint_t n_kw, const mp_obj_t *args) {
|
||||
STATIC mp_obj_t socket_make_new(const mp_obj_type_t *type, mp_uint_t n_args, mp_uint_t n_kw, const mp_obj_t *args) {
|
||||
mp_arg_check_num(n_args, n_kw, 0, 4, false);
|
||||
|
||||
// create socket object
|
||||
|
@ -821,7 +821,7 @@ STATIC const mp_arg_t wlan_init_args[] = {
|
||||
{ MP_QSTR_channel, MP_ARG_KW_ONLY | MP_ARG_INT, {.u_int = 1} },
|
||||
{ MP_QSTR_antenna, MP_ARG_KW_ONLY | MP_ARG_INT, {.u_int = ANTENNA_TYPE_INTERNAL} },
|
||||
};
|
||||
STATIC mp_obj_t wlan_make_new (mp_obj_t type_in, mp_uint_t n_args, mp_uint_t n_kw, const mp_obj_t *all_args) {
|
||||
STATIC mp_obj_t wlan_make_new(const mp_obj_type_t *type, mp_uint_t n_args, mp_uint_t n_kw, const mp_obj_t *all_args) {
|
||||
// parse args
|
||||
mp_map_t kw_args;
|
||||
mp_map_init_fixed_table(&kw_args, n_kw, all_args + n_args);
|
||||
|
@ -140,7 +140,7 @@ STATIC const mp_arg_t pyb_adc_init_args[] = {
|
||||
{ MP_QSTR_id, MP_ARG_INT, {.u_int = 0} },
|
||||
{ MP_QSTR_bits, MP_ARG_KW_ONLY | MP_ARG_INT, {.u_int = 12} },
|
||||
};
|
||||
STATIC mp_obj_t adc_make_new(mp_obj_t type_in, mp_uint_t n_args, mp_uint_t n_kw, const mp_obj_t *all_args) {
|
||||
STATIC mp_obj_t adc_make_new(const mp_obj_type_t *type, mp_uint_t n_args, mp_uint_t n_kw, const mp_obj_t *all_args) {
|
||||
// parse args
|
||||
mp_map_t kw_args;
|
||||
mp_map_init_fixed_table(&kw_args, n_kw, all_args + n_args);
|
||||
|
@ -319,7 +319,7 @@ STATIC const mp_arg_t pyb_i2c_init_args[] = {
|
||||
{ MP_QSTR_baudrate, MP_ARG_KW_ONLY | MP_ARG_INT, {.u_int = 100000} },
|
||||
{ MP_QSTR_pins, MP_ARG_KW_ONLY | MP_ARG_OBJ, {.u_obj = MP_OBJ_NULL} },
|
||||
};
|
||||
STATIC mp_obj_t pyb_i2c_make_new(mp_obj_t type_in, mp_uint_t n_args, mp_uint_t n_kw, const mp_obj_t *all_args) {
|
||||
STATIC mp_obj_t pyb_i2c_make_new(const mp_obj_type_t *type, mp_uint_t n_args, mp_uint_t n_kw, const mp_obj_t *all_args) {
|
||||
// parse args
|
||||
mp_map_t kw_args;
|
||||
mp_map_init_fixed_table(&kw_args, n_kw, all_args + n_args);
|
||||
|
@ -648,7 +648,7 @@ STATIC void pin_print(const mp_print_t *print, mp_obj_t self_in, mp_print_kind_t
|
||||
mp_printf(print, ", alt=%d)", alt);
|
||||
}
|
||||
|
||||
STATIC mp_obj_t pin_make_new(mp_obj_t self_in, mp_uint_t n_args, mp_uint_t n_kw, const mp_obj_t *args) {
|
||||
STATIC mp_obj_t pin_make_new(const mp_obj_type_t *type, mp_uint_t n_args, mp_uint_t n_kw, const mp_obj_t *args) {
|
||||
mp_arg_check_num(n_args, n_kw, 1, MP_OBJ_FUN_ARGS_MAX, true);
|
||||
|
||||
// Run an argument through the mapper and return the result.
|
||||
|
@ -285,7 +285,7 @@ STATIC const mp_arg_t pyb_rtc_init_args[] = {
|
||||
{ MP_QSTR_id, MP_ARG_INT, {.u_int = 0} },
|
||||
{ MP_QSTR_datetime, MP_ARG_OBJ, {.u_obj = MP_OBJ_NULL} },
|
||||
};
|
||||
STATIC mp_obj_t pyb_rtc_make_new(mp_obj_t type_in, mp_uint_t n_args, mp_uint_t n_kw, const mp_obj_t *all_args) {
|
||||
STATIC mp_obj_t pyb_rtc_make_new(const mp_obj_type_t *type, mp_uint_t n_args, mp_uint_t n_kw, const mp_obj_t *all_args) {
|
||||
// parse args
|
||||
mp_map_t kw_args;
|
||||
mp_map_init_fixed_table(&kw_args, n_kw, all_args + n_args);
|
||||
|
@ -64,7 +64,7 @@ STATIC const mp_obj_t pyb_sd_def_pin[3] = {&pin_GP10, &pin_GP11, &pin_GP15};
|
||||
DECLARE PRIVATE FUNCTIONS
|
||||
******************************************************************************/
|
||||
STATIC void pyb_sd_hw_init (pybsd_obj_t *self);
|
||||
STATIC mp_obj_t pyb_sd_make_new (mp_obj_t type_in, mp_uint_t n_args, mp_uint_t n_kw, const mp_obj_t *args);
|
||||
STATIC mp_obj_t pyb_sd_make_new (const mp_obj_type_t *type, mp_uint_t n_args, mp_uint_t n_kw, const mp_obj_t *args);
|
||||
STATIC mp_obj_t pyb_sd_deinit (mp_obj_t self_in);
|
||||
|
||||
/******************************************************************************
|
||||
@ -123,7 +123,7 @@ STATIC const mp_arg_t pyb_sd_init_args[] = {
|
||||
{ MP_QSTR_id, MP_ARG_INT, {.u_int = 0} },
|
||||
{ MP_QSTR_pins, MP_ARG_OBJ, {.u_obj = MP_OBJ_NULL} },
|
||||
};
|
||||
STATIC mp_obj_t pyb_sd_make_new (mp_obj_t type_in, mp_uint_t n_args, mp_uint_t n_kw, const mp_obj_t *all_args) {
|
||||
STATIC mp_obj_t pyb_sd_make_new (const mp_obj_type_t *type, mp_uint_t n_args, mp_uint_t n_kw, const mp_obj_t *all_args) {
|
||||
// parse args
|
||||
mp_map_t kw_args;
|
||||
mp_map_init_fixed_table(&kw_args, n_kw, all_args + n_args);
|
||||
|
@ -231,7 +231,7 @@ static const mp_arg_t pyb_spi_init_args[] = {
|
||||
{ MP_QSTR_firstbit, MP_ARG_KW_ONLY | MP_ARG_INT, {.u_int = PYBSPI_FIRST_BIT_MSB} },
|
||||
{ MP_QSTR_pins, MP_ARG_KW_ONLY | MP_ARG_OBJ, {.u_obj = MP_OBJ_NULL} },
|
||||
};
|
||||
STATIC mp_obj_t pyb_spi_make_new(mp_obj_t type_in, mp_uint_t n_args, mp_uint_t n_kw, const mp_obj_t *all_args) {
|
||||
STATIC mp_obj_t pyb_spi_make_new(const mp_obj_type_t *type, mp_uint_t n_args, mp_uint_t n_kw, const mp_obj_t *all_args) {
|
||||
// parse args
|
||||
mp_map_t kw_args;
|
||||
mp_map_init_fixed_table(&kw_args, n_kw, all_args + n_args);
|
||||
|
@ -356,7 +356,7 @@ error:
|
||||
/// Construct a new timer object of the given id. If additional
|
||||
/// arguments are given, then the timer is initialised by `init(...)`.
|
||||
/// `id` can be 1 to 4
|
||||
STATIC mp_obj_t pyb_timer_make_new(mp_obj_t type_in, mp_uint_t n_args, mp_uint_t n_kw, const mp_obj_t *args) {
|
||||
STATIC mp_obj_t pyb_timer_make_new(const mp_obj_type_t *type, mp_uint_t n_args, mp_uint_t n_kw, const mp_obj_t *args) {
|
||||
// check arguments
|
||||
mp_arg_check_num(n_args, n_kw, 1, MP_OBJ_FUN_ARGS_MAX, true);
|
||||
|
||||
|
@ -443,7 +443,7 @@ STATIC const mp_arg_t pyb_uart_init_args[] = {
|
||||
{ MP_QSTR_stop, MP_ARG_INT, {.u_int = 1} },
|
||||
{ MP_QSTR_pins, MP_ARG_KW_ONLY | MP_ARG_OBJ, {.u_obj = MP_OBJ_NULL} },
|
||||
};
|
||||
STATIC mp_obj_t pyb_uart_make_new(mp_obj_t type_in, mp_uint_t n_args, mp_uint_t n_kw, const mp_obj_t *all_args) {
|
||||
STATIC mp_obj_t pyb_uart_make_new(const mp_obj_type_t *type, mp_uint_t n_args, mp_uint_t n_kw, const mp_obj_t *all_args) {
|
||||
// parse args
|
||||
mp_map_t kw_args;
|
||||
mp_map_init_fixed_table(&kw_args, n_kw, all_args + n_args);
|
||||
|
@ -92,7 +92,7 @@ STATIC const mp_arg_t pyb_wdt_init_args[] = {
|
||||
{ MP_QSTR_id, MP_ARG_OBJ, {.u_obj = mp_const_none} },
|
||||
{ MP_QSTR_timeout, MP_ARG_INT, {.u_int = 5000} }, // 5 s
|
||||
};
|
||||
STATIC mp_obj_t pyb_wdt_make_new (mp_obj_t type_in, mp_uint_t n_args, mp_uint_t n_kw, const mp_obj_t *all_args) {
|
||||
STATIC mp_obj_t pyb_wdt_make_new(const mp_obj_type_t *type, mp_uint_t n_args, mp_uint_t n_kw, const mp_obj_t *all_args) {
|
||||
// check the arguments
|
||||
mp_map_t kw_args;
|
||||
mp_map_init_fixed_table(&kw_args, n_kw, all_args + n_args);
|
||||
|
@ -82,7 +82,7 @@ STATIC mp_obj_t esp_socket_make_new_base() {
|
||||
|
||||
// constructor esp_socket(family=AF_INET, type=SOCK_STREAM, proto=IPPROTO_TCP, fileno=None)
|
||||
// Arguments ignored as we do not support UDP (yet)
|
||||
STATIC mp_obj_t esp_socket_make_new(mp_obj_t type_in, mp_uint_t n_args,
|
||||
STATIC mp_obj_t esp_socket_make_new(const mp_obj_type_t *type_in, mp_uint_t n_args,
|
||||
mp_uint_t n_kw, const mp_obj_t *args) {
|
||||
mp_arg_check_num(n_args, n_kw, 0, 4, false);
|
||||
|
||||
|
@ -42,7 +42,7 @@ typedef struct _pyb_adc_obj_t {
|
||||
STATIC pyb_adc_obj_t pyb_adc_vdd3 = {{&pyb_adc_type}, true};
|
||||
STATIC pyb_adc_obj_t pyb_adc_adc = {{&pyb_adc_type}, false};
|
||||
|
||||
STATIC mp_obj_t pyb_adc_make_new(mp_obj_t type_in, mp_uint_t n_args, mp_uint_t n_kw,
|
||||
STATIC mp_obj_t pyb_adc_make_new(const mp_obj_type_t *type_in, mp_uint_t n_args, mp_uint_t n_kw,
|
||||
const mp_obj_t *args) {
|
||||
mp_arg_check_num(n_args, n_kw, 1, 1, false);
|
||||
|
||||
|
@ -119,7 +119,7 @@ STATIC mp_obj_t pyb_pin_obj_init_helper(pyb_pin_obj_t *self, mp_uint_t n_args, c
|
||||
}
|
||||
|
||||
// constructor(id, ...)
|
||||
STATIC mp_obj_t pyb_pin_make_new(mp_obj_t self_in, mp_uint_t n_args, mp_uint_t n_kw, const mp_obj_t *args) {
|
||||
STATIC mp_obj_t pyb_pin_make_new(const mp_obj_type_t *type, mp_uint_t n_args, mp_uint_t n_kw, const mp_obj_t *args) {
|
||||
mp_arg_check_num(n_args, n_kw, 1, MP_OBJ_FUN_ARGS_MAX, true);
|
||||
|
||||
// Run an argument through the mapper and return the result.
|
||||
|
@ -49,7 +49,7 @@ typedef struct _pyb_rtc_obj_t {
|
||||
// singleton RTC object
|
||||
STATIC const pyb_rtc_obj_t pyb_rtc_obj = {{&pyb_rtc_type}};
|
||||
|
||||
STATIC mp_obj_t pyb_rtc_make_new(mp_obj_t type_in, mp_uint_t n_args, mp_uint_t n_kw, const mp_obj_t *args) {
|
||||
STATIC mp_obj_t pyb_rtc_make_new(const mp_obj_type_t *type, mp_uint_t n_args, mp_uint_t n_kw, const mp_obj_t *args) {
|
||||
// check arguments
|
||||
mp_arg_check_num(n_args, n_kw, 0, 0, false);
|
||||
|
||||
|
@ -121,10 +121,10 @@ STATIC NORETURN void syntax_error(void) {
|
||||
nlr_raise(mp_obj_new_exception_msg(&mp_type_TypeError, "syntax error in uctypes descriptor"));
|
||||
}
|
||||
|
||||
STATIC mp_obj_t uctypes_struct_make_new(mp_obj_t type_in, size_t n_args, size_t n_kw, const mp_obj_t *args) {
|
||||
STATIC mp_obj_t uctypes_struct_make_new(const mp_obj_type_t *type, size_t n_args, size_t n_kw, const mp_obj_t *args) {
|
||||
mp_arg_check_num(n_args, n_kw, 2, 3, false);
|
||||
mp_obj_uctypes_struct_t *o = m_new_obj(mp_obj_uctypes_struct_t);
|
||||
o->base.type = MP_OBJ_TO_PTR(type_in);
|
||||
o->base.type = type;
|
||||
o->addr = (void*)(uintptr_t)mp_obj_get_int(args[0]);
|
||||
o->desc = args[1];
|
||||
o->flags = LAYOUT_NATIVE;
|
||||
|
@ -41,10 +41,10 @@ typedef struct _mp_obj_hash_t {
|
||||
|
||||
STATIC mp_obj_t hash_update(mp_obj_t self_in, mp_obj_t arg);
|
||||
|
||||
STATIC mp_obj_t hash_make_new(mp_obj_t type_in, size_t n_args, size_t n_kw, const mp_obj_t *args) {
|
||||
STATIC mp_obj_t hash_make_new(const mp_obj_type_t *type, size_t n_args, size_t n_kw, const mp_obj_t *args) {
|
||||
mp_arg_check_num(n_args, n_kw, 0, 1, false);
|
||||
mp_obj_hash_t *o = m_new_obj_var(mp_obj_hash_t, char, sizeof(CRYAL_SHA256_CTX));
|
||||
o->base.type = MP_OBJ_TO_PTR(type_in);
|
||||
o->base.type = type;
|
||||
sha256_init((CRYAL_SHA256_CTX*)o->state);
|
||||
if (n_args == 1) {
|
||||
hash_update(MP_OBJ_FROM_PTR(o), args[0]);
|
||||
|
@ -512,7 +512,7 @@ STATIC mp_obj_t mp_builtin_sorted(size_t n_args, const mp_obj_t *args, mp_map_t
|
||||
nlr_raise(mp_obj_new_exception_msg(&mp_type_TypeError,
|
||||
"must use keyword argument for key function"));
|
||||
}
|
||||
mp_obj_t self = mp_type_list.make_new(MP_OBJ_FROM_PTR(&mp_type_list), 1, 0, args);
|
||||
mp_obj_t self = mp_type_list.make_new(&mp_type_list, 1, 0, args);
|
||||
mp_obj_list_sort(1, &self, kwargs);
|
||||
|
||||
return self;
|
||||
|
20
py/obj.h
20
py/obj.h
@ -42,12 +42,14 @@ typedef machine_ptr_t mp_obj_t;
|
||||
typedef machine_const_ptr_t mp_const_obj_t;
|
||||
#endif
|
||||
|
||||
// Anything that wants to be a Micro Python object must have
|
||||
// mp_obj_base_t as its first member (except small ints and qstrs)
|
||||
// This mp_obj_type_t struct is a concrete MicroPython object which holds info
|
||||
// about a type. See below for actual definition of the struct.
|
||||
typedef struct _mp_obj_type_t mp_obj_type_t;
|
||||
|
||||
struct _mp_obj_type_t;
|
||||
// Anything that wants to be a concrete MicroPython object must have mp_obj_base_t
|
||||
// as its first member (small ints, qstr objs and inline floats are not concrete).
|
||||
struct _mp_obj_base_t {
|
||||
const struct _mp_obj_type_t *type MICROPY_OBJ_BASE_ALIGNMENT;
|
||||
const mp_obj_type_t *type MICROPY_OBJ_BASE_ALIGNMENT;
|
||||
};
|
||||
typedef struct _mp_obj_base_t mp_obj_base_t;
|
||||
|
||||
@ -259,8 +261,8 @@ typedef struct _mp_rom_obj_t { mp_const_obj_t o; } mp_rom_obj_t;
|
||||
//static inline bool MP_OBJ_IS_TYPE(mp_const_obj_t o, const mp_obj_type_t *t) { return (MP_OBJ_IS_OBJ(o) && (((mp_obj_base_t*)(o))->type == (t))); } // this does not work for checking a string, use below macro for that
|
||||
//static inline bool MP_OBJ_IS_INT(mp_const_obj_t o) { return (MP_OBJ_IS_SMALL_INT(o) || MP_OBJ_IS_TYPE(o, &mp_type_int)); } // returns true if o is a small int or long int
|
||||
// Need to forward declare these for the inline function to compile.
|
||||
extern const struct _mp_obj_type_t mp_type_int;
|
||||
extern const struct _mp_obj_type_t mp_type_bool;
|
||||
extern const mp_obj_type_t mp_type_int;
|
||||
extern const mp_obj_type_t mp_type_bool;
|
||||
static inline bool mp_obj_is_integer(mp_const_obj_t o) { return MP_OBJ_IS_INT(o) || MP_OBJ_IS_TYPE(o, &mp_type_bool); } // returns true if o is bool, small int or long int
|
||||
//static inline bool MP_OBJ_IS_STR(mp_const_obj_t o) { return (MP_OBJ_IS_QSTR(o) || MP_OBJ_IS_TYPE(o, &mp_type_str)); }
|
||||
|
||||
@ -408,7 +410,7 @@ typedef enum {
|
||||
} mp_print_kind_t;
|
||||
|
||||
typedef void (*mp_print_fun_t)(const mp_print_t *print, mp_obj_t o, mp_print_kind_t kind);
|
||||
typedef mp_obj_t (*mp_make_new_fun_t)(mp_obj_t type_in, size_t n_args, size_t n_kw, const mp_obj_t *args);
|
||||
typedef mp_obj_t (*mp_make_new_fun_t)(const mp_obj_type_t *type, size_t n_args, size_t n_kw, const mp_obj_t *args);
|
||||
typedef mp_obj_t (*mp_call_fun_t)(mp_obj_t fun, size_t n_args, size_t n_kw, const mp_obj_t *args);
|
||||
typedef mp_obj_t (*mp_unary_op_fun_t)(mp_uint_t op, mp_obj_t);
|
||||
typedef mp_obj_t (*mp_binary_op_fun_t)(mp_uint_t op, mp_obj_t, mp_obj_t);
|
||||
@ -510,8 +512,6 @@ struct _mp_obj_type_t {
|
||||
*/
|
||||
};
|
||||
|
||||
typedef struct _mp_obj_type_t mp_obj_type_t;
|
||||
|
||||
// Constant types, globally accessible
|
||||
extern const mp_obj_type_t mp_type_type;
|
||||
extern const mp_obj_type_t mp_type_object;
|
||||
@ -691,7 +691,7 @@ void mp_obj_exception_clear_traceback(mp_obj_t self_in);
|
||||
void mp_obj_exception_add_traceback(mp_obj_t self_in, qstr file, size_t line, qstr block);
|
||||
void mp_obj_exception_get_traceback(mp_obj_t self_in, size_t *n, size_t **values);
|
||||
mp_obj_t mp_obj_exception_get_value(mp_obj_t self_in);
|
||||
mp_obj_t mp_obj_exception_make_new(mp_obj_t type_in, size_t n_args, size_t n_kw, const mp_obj_t *args);
|
||||
mp_obj_t mp_obj_exception_make_new(const mp_obj_type_t *type_in, size_t n_args, size_t n_kw, const mp_obj_t *args);
|
||||
mp_obj_t mp_alloc_emergency_exception_buf(mp_obj_t size_in);
|
||||
void mp_init_emergency_exception_buf(void);
|
||||
|
||||
|
@ -168,7 +168,7 @@ STATIC mp_obj_t array_construct(char typecode, mp_obj_t initializer) {
|
||||
#endif
|
||||
|
||||
#if MICROPY_PY_ARRAY
|
||||
STATIC mp_obj_t array_make_new(mp_obj_t type_in, size_t n_args, size_t n_kw, const mp_obj_t *args) {
|
||||
STATIC mp_obj_t array_make_new(const mp_obj_type_t *type_in, size_t n_args, size_t n_kw, const mp_obj_t *args) {
|
||||
(void)type_in;
|
||||
mp_arg_check_num(n_args, n_kw, 1, 2, false);
|
||||
|
||||
@ -187,7 +187,7 @@ STATIC mp_obj_t array_make_new(mp_obj_t type_in, size_t n_args, size_t n_kw, con
|
||||
#endif
|
||||
|
||||
#if MICROPY_PY_BUILTINS_BYTEARRAY
|
||||
STATIC mp_obj_t bytearray_make_new(mp_obj_t type_in, size_t n_args, size_t n_kw, const mp_obj_t *args) {
|
||||
STATIC mp_obj_t bytearray_make_new(const mp_obj_type_t *type_in, size_t n_args, size_t n_kw, const mp_obj_t *args) {
|
||||
(void)type_in;
|
||||
mp_arg_check_num(n_args, n_kw, 0, 1, false);
|
||||
|
||||
@ -219,7 +219,7 @@ mp_obj_t mp_obj_new_memoryview(byte typecode, mp_uint_t nitems, void *items) {
|
||||
return MP_OBJ_FROM_PTR(self);
|
||||
}
|
||||
|
||||
STATIC mp_obj_t memoryview_make_new(mp_obj_t type_in, size_t n_args, size_t n_kw, const mp_obj_t *args) {
|
||||
STATIC mp_obj_t memoryview_make_new(const mp_obj_type_t *type_in, size_t n_args, size_t n_kw, const mp_obj_t *args) {
|
||||
(void)type_in;
|
||||
|
||||
// TODO possibly allow memoryview constructor to take start/stop so that one
|
||||
|
@ -52,7 +52,7 @@ STATIC void bool_print(const mp_print_t *print, mp_obj_t self_in, mp_print_kind_
|
||||
}
|
||||
}
|
||||
|
||||
STATIC mp_obj_t bool_make_new(mp_obj_t type_in, size_t n_args, size_t n_kw, const mp_obj_t *args) {
|
||||
STATIC mp_obj_t bool_make_new(const mp_obj_type_t *type_in, size_t n_args, size_t n_kw, const mp_obj_t *args) {
|
||||
(void)type_in;
|
||||
mp_arg_check_num(n_args, n_kw, 0, 1, false);
|
||||
|
||||
|
@ -69,7 +69,7 @@ STATIC void complex_print(const mp_print_t *print, mp_obj_t o_in, mp_print_kind_
|
||||
}
|
||||
}
|
||||
|
||||
STATIC mp_obj_t complex_make_new(mp_obj_t type_in, size_t n_args, size_t n_kw, const mp_obj_t *args) {
|
||||
STATIC mp_obj_t complex_make_new(const mp_obj_type_t *type_in, size_t n_args, size_t n_kw, const mp_obj_t *args) {
|
||||
(void)type_in;
|
||||
mp_arg_check_num(n_args, n_kw, 0, 2, false);
|
||||
|
||||
|
@ -82,12 +82,12 @@ STATIC void dict_print(const mp_print_t *print, mp_obj_t self_in, mp_print_kind_
|
||||
}
|
||||
}
|
||||
|
||||
STATIC mp_obj_t dict_make_new(mp_obj_t type_in, size_t n_args, size_t n_kw, const mp_obj_t *args) {
|
||||
STATIC mp_obj_t dict_make_new(const mp_obj_type_t *type, size_t n_args, size_t n_kw, const mp_obj_t *args) {
|
||||
mp_obj_t dict_out = mp_obj_new_dict(0);
|
||||
mp_obj_dict_t *dict = MP_OBJ_TO_PTR(dict_out);
|
||||
dict->base.type = MP_OBJ_TO_PTR(type_in);
|
||||
dict->base.type = type;
|
||||
#if MICROPY_PY_COLLECTIONS_ORDEREDDICT
|
||||
if (MP_OBJ_TO_PTR(type_in) == &mp_type_ordereddict) {
|
||||
if (type == &mp_type_ordereddict) {
|
||||
dict->map.is_ordered = 1;
|
||||
}
|
||||
#endif
|
||||
|
@ -45,7 +45,7 @@ STATIC const mp_arg_t enumerate_make_new_args[] = {
|
||||
};
|
||||
#define ENUMERATE_MAKE_NEW_NUM_ARGS MP_ARRAY_SIZE(enumerate_make_new_args)
|
||||
|
||||
STATIC mp_obj_t enumerate_make_new(mp_obj_t type_in, size_t n_args, size_t n_kw, const mp_obj_t *args) {
|
||||
STATIC mp_obj_t enumerate_make_new(const mp_obj_type_t *type, size_t n_args, size_t n_kw, const mp_obj_t *args) {
|
||||
#if MICROPY_CPYTHON_COMPAT
|
||||
// parse args
|
||||
mp_arg_val_t vals[ENUMERATE_MAKE_NEW_NUM_ARGS];
|
||||
@ -53,13 +53,13 @@ STATIC mp_obj_t enumerate_make_new(mp_obj_t type_in, size_t n_args, size_t n_kw,
|
||||
|
||||
// create enumerate object
|
||||
mp_obj_enumerate_t *o = m_new_obj(mp_obj_enumerate_t);
|
||||
o->base.type = MP_OBJ_TO_PTR(type_in);
|
||||
o->base.type = type;
|
||||
o->iter = mp_getiter(vals[0].u_obj);
|
||||
o->cur = vals[1].u_int;
|
||||
#else
|
||||
(void)n_kw;
|
||||
mp_obj_enumerate_t *o = m_new_obj(mp_obj_enumerate_t);
|
||||
o->base.type = type_in;
|
||||
o->base.type = type;
|
||||
o->iter = mp_getiter(args[0]);
|
||||
o->cur = n_args > 1 ? mp_obj_get_int(args[1]) : 0;
|
||||
#endif
|
||||
|
@ -114,7 +114,7 @@ STATIC void mp_obj_exception_print(const mp_print_t *print, mp_obj_t o_in, mp_pr
|
||||
mp_obj_tuple_print(print, MP_OBJ_FROM_PTR(o->args), kind);
|
||||
}
|
||||
|
||||
mp_obj_t mp_obj_exception_make_new(mp_obj_t type_in, size_t n_args, size_t n_kw, const mp_obj_t *args) {
|
||||
mp_obj_t mp_obj_exception_make_new(const mp_obj_type_t *type, size_t n_args, size_t n_kw, const mp_obj_t *args) {
|
||||
mp_arg_check_num(n_args, n_kw, 0, MP_OBJ_FUN_ARGS_MAX, false);
|
||||
mp_obj_exception_t *o = m_new_obj_var_maybe(mp_obj_exception_t, mp_obj_t, 0);
|
||||
if (o == NULL) {
|
||||
@ -125,7 +125,7 @@ mp_obj_t mp_obj_exception_make_new(mp_obj_t type_in, size_t n_args, size_t n_kw,
|
||||
} else {
|
||||
o->args = MP_OBJ_TO_PTR(mp_obj_new_tuple(n_args, args));
|
||||
}
|
||||
o->base.type = MP_OBJ_TO_PTR(type_in);
|
||||
o->base.type = type;
|
||||
o->traceback_data = NULL;
|
||||
return MP_OBJ_FROM_PTR(o);
|
||||
}
|
||||
@ -290,7 +290,7 @@ mp_obj_t mp_obj_new_exception_arg1(const mp_obj_type_t *exc_type, mp_obj_t arg)
|
||||
|
||||
mp_obj_t mp_obj_new_exception_args(const mp_obj_type_t *exc_type, mp_uint_t n_args, const mp_obj_t *args) {
|
||||
assert(exc_type->make_new == mp_obj_exception_make_new);
|
||||
return exc_type->make_new(MP_OBJ_FROM_PTR(exc_type), n_args, 0, args);
|
||||
return exc_type->make_new(exc_type, n_args, 0, args);
|
||||
}
|
||||
|
||||
mp_obj_t mp_obj_new_exception_msg(const mp_obj_type_t *exc_type, const char *msg) {
|
||||
|
@ -34,10 +34,10 @@ typedef struct _mp_obj_filter_t {
|
||||
mp_obj_t iter;
|
||||
} mp_obj_filter_t;
|
||||
|
||||
STATIC mp_obj_t filter_make_new(mp_obj_t type_in, size_t n_args, size_t n_kw, const mp_obj_t *args) {
|
||||
STATIC mp_obj_t filter_make_new(const mp_obj_type_t *type, size_t n_args, size_t n_kw, const mp_obj_t *args) {
|
||||
mp_arg_check_num(n_args, n_kw, 2, 2, false);
|
||||
mp_obj_filter_t *o = m_new_obj(mp_obj_filter_t);
|
||||
o->base.type = MP_OBJ_TO_PTR(type_in);
|
||||
o->base.type = type;
|
||||
o->fun = args[0];
|
||||
o->iter = mp_getiter(args[1]);
|
||||
return MP_OBJ_FROM_PTR(o);
|
||||
|
@ -69,7 +69,7 @@ STATIC void float_print(const mp_print_t *print, mp_obj_t o_in, mp_print_kind_t
|
||||
}
|
||||
}
|
||||
|
||||
STATIC mp_obj_t float_make_new(mp_obj_t type_in, size_t n_args, size_t n_kw, const mp_obj_t *args) {
|
||||
STATIC mp_obj_t float_make_new(const mp_obj_type_t *type_in, size_t n_args, size_t n_kw, const mp_obj_t *args) {
|
||||
(void)type_in;
|
||||
mp_arg_check_num(n_args, n_kw, 0, 1, false);
|
||||
|
||||
|
@ -42,7 +42,7 @@
|
||||
#endif
|
||||
|
||||
// This dispatcher function is expected to be independent of the implementation of long int
|
||||
STATIC mp_obj_t mp_obj_int_make_new(mp_obj_t type_in, size_t n_args, size_t n_kw, const mp_obj_t *args) {
|
||||
STATIC mp_obj_t mp_obj_int_make_new(const mp_obj_type_t *type_in, size_t n_args, size_t n_kw, const mp_obj_t *args) {
|
||||
(void)type_in;
|
||||
mp_arg_check_num(n_args, n_kw, 0, 2, false);
|
||||
|
||||
|
@ -68,7 +68,7 @@ STATIC mp_obj_t list_extend_from_iter(mp_obj_t list, mp_obj_t iterable) {
|
||||
return list;
|
||||
}
|
||||
|
||||
STATIC mp_obj_t list_make_new(mp_obj_t type_in, size_t n_args, size_t n_kw, const mp_obj_t *args) {
|
||||
STATIC mp_obj_t list_make_new(const mp_obj_type_t *type_in, size_t n_args, size_t n_kw, const mp_obj_t *args) {
|
||||
(void)type_in;
|
||||
mp_arg_check_num(n_args, n_kw, 0, 1, false);
|
||||
|
||||
|
@ -36,10 +36,10 @@ typedef struct _mp_obj_map_t {
|
||||
mp_obj_t iters[];
|
||||
} mp_obj_map_t;
|
||||
|
||||
STATIC mp_obj_t map_make_new(mp_obj_t type_in, size_t n_args, size_t n_kw, const mp_obj_t *args) {
|
||||
STATIC mp_obj_t map_make_new(const mp_obj_type_t *type, size_t n_args, size_t n_kw, const mp_obj_t *args) {
|
||||
mp_arg_check_num(n_args, n_kw, 2, MP_OBJ_FUN_ARGS_MAX, false);
|
||||
mp_obj_map_t *o = m_new_obj_var(mp_obj_map_t, mp_obj_t, n_args - 1);
|
||||
o->base.type = MP_OBJ_TO_PTR(type_in);
|
||||
o->base.type = type;
|
||||
o->n_iters = n_args - 1;
|
||||
o->fun = args[0];
|
||||
for (mp_uint_t i = 0; i < n_args - 1; i++) {
|
||||
|
@ -44,7 +44,7 @@ typedef struct _mp_obj_namedtuple_t {
|
||||
mp_obj_tuple_t tuple;
|
||||
} mp_obj_namedtuple_t;
|
||||
|
||||
STATIC mp_uint_t namedtuple_find_field(mp_obj_namedtuple_type_t *type, qstr name) {
|
||||
STATIC mp_uint_t namedtuple_find_field(const mp_obj_namedtuple_type_t *type, qstr name) {
|
||||
for (mp_uint_t i = 0; i < type->n_fields; i++) {
|
||||
if (type->fields[i] == name) {
|
||||
return i;
|
||||
@ -77,8 +77,8 @@ STATIC void namedtuple_attr(mp_obj_t self_in, qstr attr, mp_obj_t *dest) {
|
||||
}
|
||||
}
|
||||
|
||||
STATIC mp_obj_t namedtuple_make_new(mp_obj_t type_in, size_t n_args, size_t n_kw, const mp_obj_t *args) {
|
||||
mp_obj_namedtuple_type_t *type = MP_OBJ_TO_PTR(type_in);
|
||||
STATIC mp_obj_t namedtuple_make_new(const mp_obj_type_t *type_in, size_t n_args, size_t n_kw, const mp_obj_t *args) {
|
||||
const mp_obj_namedtuple_type_t *type = (const mp_obj_namedtuple_type_t*)type_in;
|
||||
mp_uint_t num_fields = type->n_fields;
|
||||
if (n_args + n_kw != num_fields) {
|
||||
if (MICROPY_ERROR_REPORTING == MICROPY_ERROR_REPORTING_TERSE) {
|
||||
@ -130,7 +130,7 @@ STATIC mp_obj_t namedtuple_make_new(mp_obj_t type_in, size_t n_args, size_t n_kw
|
||||
}
|
||||
|
||||
mp_obj_tuple_t *tuple = MP_OBJ_TO_PTR(mp_obj_new_tuple(num_fields, arg_objects));
|
||||
tuple->base.type = MP_OBJ_TO_PTR(type_in);
|
||||
tuple->base.type = type_in;
|
||||
return MP_OBJ_FROM_PTR(tuple);
|
||||
}
|
||||
|
||||
|
@ -33,11 +33,11 @@ typedef struct _mp_obj_object_t {
|
||||
mp_obj_base_t base;
|
||||
} mp_obj_object_t;
|
||||
|
||||
STATIC mp_obj_t object_make_new(mp_obj_t type_in, size_t n_args, size_t n_kw, const mp_obj_t *args) {
|
||||
STATIC mp_obj_t object_make_new(const mp_obj_type_t *type, size_t n_args, size_t n_kw, const mp_obj_t *args) {
|
||||
(void)args;
|
||||
mp_arg_check_num(n_args, n_kw, 0, 0, false);
|
||||
mp_obj_object_t *o = m_new_obj(mp_obj_object_t);
|
||||
o->base.type = MP_OBJ_TO_PTR(type_in);
|
||||
o->base.type = type;
|
||||
return MP_OBJ_FROM_PTR(o);
|
||||
}
|
||||
|
||||
@ -54,7 +54,7 @@ STATIC mp_obj_t object___new__(mp_obj_t cls) {
|
||||
"__new__ arg must be a user-type"));
|
||||
}
|
||||
mp_obj_t o = MP_OBJ_SENTINEL;
|
||||
mp_obj_t res = mp_obj_instance_make_new(cls, 1, 0, &o);
|
||||
mp_obj_t res = mp_obj_instance_make_new(MP_OBJ_TO_PTR(cls), 1, 0, &o);
|
||||
return res;
|
||||
}
|
||||
STATIC MP_DEFINE_CONST_FUN_OBJ_1(object___new___fun_obj, object___new__);
|
||||
|
@ -37,11 +37,11 @@ typedef struct _mp_obj_property_t {
|
||||
mp_obj_t proxy[3]; // getter, setter, deleter
|
||||
} mp_obj_property_t;
|
||||
|
||||
STATIC mp_obj_t property_make_new(mp_obj_t type_in, size_t n_args, size_t n_kw, const mp_obj_t *args) {
|
||||
STATIC mp_obj_t property_make_new(const mp_obj_type_t *type, size_t n_args, size_t n_kw, const mp_obj_t *args) {
|
||||
mp_arg_check_num(n_args, n_kw, 0, 4, false);
|
||||
|
||||
mp_obj_property_t *o = m_new_obj(mp_obj_property_t);
|
||||
o->base.type = MP_OBJ_TO_PTR(type_in);
|
||||
o->base.type = type;
|
||||
if (n_args >= 4) {
|
||||
// doc ignored
|
||||
}
|
||||
|
@ -90,11 +90,11 @@ STATIC void range_print(const mp_print_t *print, mp_obj_t self_in, mp_print_kind
|
||||
}
|
||||
}
|
||||
|
||||
STATIC mp_obj_t range_make_new(mp_obj_t type_in, size_t n_args, size_t n_kw, const mp_obj_t *args) {
|
||||
STATIC mp_obj_t range_make_new(const mp_obj_type_t *type, size_t n_args, size_t n_kw, const mp_obj_t *args) {
|
||||
mp_arg_check_num(n_args, n_kw, 1, 3, false);
|
||||
|
||||
mp_obj_range_t *o = m_new_obj(mp_obj_range_t);
|
||||
o->base.type = MP_OBJ_TO_PTR(type_in);
|
||||
o->base.type = type;
|
||||
o->start = 0;
|
||||
o->step = 1;
|
||||
|
||||
|
@ -38,7 +38,7 @@ typedef struct _mp_obj_reversed_t {
|
||||
mp_uint_t cur_index; // current index, plus 1; 0=no more, 1=last one (index 0)
|
||||
} mp_obj_reversed_t;
|
||||
|
||||
STATIC mp_obj_t reversed_make_new(mp_obj_t type_in, size_t n_args, size_t n_kw, const mp_obj_t *args) {
|
||||
STATIC mp_obj_t reversed_make_new(const mp_obj_type_t *type, size_t n_args, size_t n_kw, const mp_obj_t *args) {
|
||||
mp_arg_check_num(n_args, n_kw, 1, 1, false);
|
||||
|
||||
// check if __reversed__ exists, and if so delegate to it
|
||||
@ -49,7 +49,7 @@ STATIC mp_obj_t reversed_make_new(mp_obj_t type_in, size_t n_args, size_t n_kw,
|
||||
}
|
||||
|
||||
mp_obj_reversed_t *o = m_new_obj(mp_obj_reversed_t);
|
||||
o->base.type = MP_OBJ_TO_PTR(type_in);
|
||||
o->base.type = type;
|
||||
o->seq = args[0];
|
||||
o->cur_index = mp_obj_get_int(mp_obj_len(args[0])); // start at the end of the sequence
|
||||
|
||||
|
10
py/objset.c
10
py/objset.c
@ -119,7 +119,7 @@ STATIC void set_print(const mp_print_t *print, mp_obj_t self_in, mp_print_kind_t
|
||||
#endif
|
||||
}
|
||||
|
||||
STATIC mp_obj_t set_make_new(mp_obj_t type_in, size_t n_args, size_t n_kw, const mp_obj_t *args) {
|
||||
STATIC mp_obj_t set_make_new(const mp_obj_type_t *type, size_t n_args, size_t n_kw, const mp_obj_t *args) {
|
||||
mp_arg_check_num(n_args, n_kw, 0, 1, false);
|
||||
|
||||
switch (n_args) {
|
||||
@ -127,7 +127,7 @@ STATIC mp_obj_t set_make_new(mp_obj_t type_in, size_t n_args, size_t n_kw, const
|
||||
// create a new, empty set
|
||||
mp_obj_set_t *set = MP_OBJ_TO_PTR(mp_obj_new_set(0, NULL));
|
||||
// set actual set/frozenset type
|
||||
set->base.type = MP_OBJ_TO_PTR(type_in);
|
||||
set->base.type = type;
|
||||
return MP_OBJ_FROM_PTR(set);
|
||||
}
|
||||
|
||||
@ -141,7 +141,7 @@ STATIC mp_obj_t set_make_new(mp_obj_t type_in, size_t n_args, size_t n_kw, const
|
||||
mp_obj_set_store(set, item);
|
||||
}
|
||||
// Set actual set/frozenset type
|
||||
((mp_obj_set_t*)MP_OBJ_TO_PTR(set))->base.type = MP_OBJ_TO_PTR(type_in);
|
||||
((mp_obj_set_t*)MP_OBJ_TO_PTR(set))->base.type = type;
|
||||
return set;
|
||||
}
|
||||
}
|
||||
@ -327,7 +327,7 @@ STATIC mp_obj_t set_issubset_internal(mp_obj_t self_in, mp_obj_t other_in, bool
|
||||
if (is_set_or_frozenset(self_in)) {
|
||||
self = MP_OBJ_TO_PTR(self_in);
|
||||
} else {
|
||||
self = MP_OBJ_TO_PTR(set_make_new(MP_OBJ_FROM_PTR(&mp_type_set), 1, 0, &self_in));
|
||||
self = MP_OBJ_TO_PTR(set_make_new(&mp_type_set, 1, 0, &self_in));
|
||||
cleanup_self = true;
|
||||
}
|
||||
|
||||
@ -336,7 +336,7 @@ STATIC mp_obj_t set_issubset_internal(mp_obj_t self_in, mp_obj_t other_in, bool
|
||||
if (is_set_or_frozenset(other_in)) {
|
||||
other = MP_OBJ_TO_PTR(other_in);
|
||||
} else {
|
||||
other = MP_OBJ_TO_PTR(set_make_new(MP_OBJ_FROM_PTR(&mp_type_set), 1, 0, &other_in));
|
||||
other = MP_OBJ_TO_PTR(set_make_new(&mp_type_set, 1, 0, &other_in));
|
||||
cleanup_other = true;
|
||||
}
|
||||
bool out = true;
|
||||
|
14
py/objstr.c
14
py/objstr.c
@ -131,7 +131,7 @@ STATIC void str_print(const mp_print_t *print, mp_obj_t self_in, mp_print_kind_t
|
||||
}
|
||||
}
|
||||
|
||||
mp_obj_t mp_obj_str_make_new(mp_obj_t type_in, size_t n_args, size_t n_kw, const mp_obj_t *args) {
|
||||
mp_obj_t mp_obj_str_make_new(const mp_obj_type_t *type, size_t n_args, size_t n_kw, const mp_obj_t *args) {
|
||||
#if MICROPY_CPYTHON_COMPAT
|
||||
if (n_kw != 0) {
|
||||
mp_arg_error_unimpl_kw();
|
||||
@ -149,7 +149,7 @@ mp_obj_t mp_obj_str_make_new(mp_obj_t type_in, size_t n_args, size_t n_kw, const
|
||||
mp_print_t print;
|
||||
vstr_init_print(&vstr, 16, &print);
|
||||
mp_obj_print_helper(&print, args[0], PRINT_STR);
|
||||
return mp_obj_new_str_from_vstr(MP_OBJ_TO_PTR(type_in), &vstr);
|
||||
return mp_obj_new_str_from_vstr(type, &vstr);
|
||||
}
|
||||
|
||||
default: // 2 or 3 args
|
||||
@ -157,7 +157,7 @@ mp_obj_t mp_obj_str_make_new(mp_obj_t type_in, size_t n_args, size_t n_kw, const
|
||||
if (MP_OBJ_IS_TYPE(args[0], &mp_type_bytes)) {
|
||||
GET_STR_DATA_LEN(args[0], str_data, str_len);
|
||||
GET_STR_HASH(args[0], str_hash);
|
||||
mp_obj_str_t *o = MP_OBJ_TO_PTR(mp_obj_new_str_of_type(MP_OBJ_TO_PTR(type_in), NULL, str_len));
|
||||
mp_obj_str_t *o = MP_OBJ_TO_PTR(mp_obj_new_str_of_type(type, NULL, str_len));
|
||||
o->data = str_data;
|
||||
o->hash = str_hash;
|
||||
return MP_OBJ_FROM_PTR(o);
|
||||
@ -169,7 +169,7 @@ mp_obj_t mp_obj_str_make_new(mp_obj_t type_in, size_t n_args, size_t n_kw, const
|
||||
}
|
||||
}
|
||||
|
||||
STATIC mp_obj_t bytes_make_new(mp_obj_t type_in, size_t n_args, size_t n_kw, const mp_obj_t *args) {
|
||||
STATIC mp_obj_t bytes_make_new(const mp_obj_type_t *type_in, size_t n_args, size_t n_kw, const mp_obj_t *args) {
|
||||
(void)type_in;
|
||||
|
||||
#if MICROPY_CPYTHON_COMPAT
|
||||
@ -426,7 +426,7 @@ STATIC mp_obj_t str_join(mp_obj_t self_in, mp_obj_t arg) {
|
||||
if (!MP_OBJ_IS_TYPE(arg, &mp_type_list)) {
|
||||
// arg is not a list, try to convert it to one
|
||||
// TODO: Try to optimize?
|
||||
arg = mp_type_list.make_new(MP_OBJ_FROM_PTR(&mp_type_list), 1, 0, &arg);
|
||||
arg = mp_type_list.make_new(&mp_type_list, 1, 0, &arg);
|
||||
}
|
||||
mp_obj_list_get(arg, &seq_len, &seq_items);
|
||||
}
|
||||
@ -1767,7 +1767,7 @@ STATIC mp_obj_t bytes_decode(size_t n_args, const mp_obj_t *args) {
|
||||
args = new_args;
|
||||
n_args++;
|
||||
}
|
||||
return mp_obj_str_make_new(MP_OBJ_FROM_PTR(&mp_type_str), n_args, 0, args);
|
||||
return mp_obj_str_make_new(&mp_type_str, n_args, 0, args);
|
||||
}
|
||||
|
||||
// TODO: should accept kwargs too
|
||||
@ -1779,7 +1779,7 @@ STATIC mp_obj_t str_encode(size_t n_args, const mp_obj_t *args) {
|
||||
args = new_args;
|
||||
n_args++;
|
||||
}
|
||||
return bytes_make_new(MP_OBJ_NULL, n_args, 0, args);
|
||||
return bytes_make_new(NULL, n_args, 0, args);
|
||||
}
|
||||
#endif
|
||||
|
||||
|
@ -60,7 +60,7 @@ const byte *mp_obj_str_get_data_no_check(mp_obj_t self_in, size_t *len);
|
||||
else { str_len = ((mp_obj_str_t*)MP_OBJ_TO_PTR(str_obj_in))->len; str_data = ((mp_obj_str_t*)MP_OBJ_TO_PTR(str_obj_in))->data; }
|
||||
#endif
|
||||
|
||||
mp_obj_t mp_obj_str_make_new(mp_obj_t type_in, size_t n_args, size_t n_kw, const mp_obj_t *args);
|
||||
mp_obj_t mp_obj_str_make_new(const mp_obj_type_t *type_in, size_t n_args, size_t n_kw, const mp_obj_t *args);
|
||||
void mp_str_print_json(const mp_print_t *print, const byte *str_data, size_t str_len);
|
||||
mp_obj_t mp_obj_str_format(size_t n_args, const mp_obj_t *args, mp_map_t *kwargs);
|
||||
mp_obj_t mp_obj_str_split(size_t n_args, const mp_obj_t *args);
|
||||
|
@ -120,15 +120,15 @@ STATIC mp_obj_t stringio___exit__(size_t n_args, const mp_obj_t *args) {
|
||||
}
|
||||
STATIC MP_DEFINE_CONST_FUN_OBJ_VAR_BETWEEN(stringio___exit___obj, 4, 4, stringio___exit__);
|
||||
|
||||
STATIC mp_obj_stringio_t *stringio_new(mp_obj_t type_in) {
|
||||
STATIC mp_obj_stringio_t *stringio_new(const mp_obj_type_t *type) {
|
||||
mp_obj_stringio_t *o = m_new_obj(mp_obj_stringio_t);
|
||||
o->base.type = MP_OBJ_TO_PTR(type_in);
|
||||
o->base.type = type;
|
||||
o->vstr = vstr_new();
|
||||
o->pos = 0;
|
||||
return o;
|
||||
}
|
||||
|
||||
STATIC mp_obj_t stringio_make_new(mp_obj_t type_in, size_t n_args, size_t n_kw, const mp_obj_t *args) {
|
||||
STATIC mp_obj_t stringio_make_new(const mp_obj_type_t *type_in, size_t n_args, size_t n_kw, const mp_obj_t *args) {
|
||||
(void)n_kw; // TODO check n_kw==0
|
||||
mp_obj_stringio_t *o = stringio_new(type_in);
|
||||
|
||||
|
@ -61,7 +61,7 @@ void mp_obj_tuple_print(const mp_print_t *print, mp_obj_t o_in, mp_print_kind_t
|
||||
}
|
||||
}
|
||||
|
||||
STATIC mp_obj_t mp_obj_tuple_make_new(mp_obj_t type_in, size_t n_args, size_t n_kw, const mp_obj_t *args) {
|
||||
STATIC mp_obj_t mp_obj_tuple_make_new(const mp_obj_type_t *type_in, size_t n_args, size_t n_kw, const mp_obj_t *args) {
|
||||
(void)type_in;
|
||||
|
||||
mp_arg_check_num(n_args, n_kw, 0, 1, false);
|
||||
|
30
py/objtype.c
30
py/objtype.c
@ -43,14 +43,14 @@
|
||||
#define DEBUG_printf(...) (void)0
|
||||
#endif
|
||||
|
||||
STATIC mp_obj_t static_class_method_make_new(mp_obj_t self_in, size_t n_args, size_t n_kw, const mp_obj_t *args);
|
||||
STATIC mp_obj_t static_class_method_make_new(const mp_obj_type_t *self_in, size_t n_args, size_t n_kw, const mp_obj_t *args);
|
||||
|
||||
/******************************************************************************/
|
||||
// instance object
|
||||
|
||||
STATIC mp_obj_t mp_obj_new_instance(mp_obj_t class, uint subobjs) {
|
||||
STATIC mp_obj_t mp_obj_new_instance(const mp_obj_type_t *class, uint subobjs) {
|
||||
mp_obj_instance_t *o = m_new_obj_var(mp_obj_instance_t, mp_obj_t, subobjs);
|
||||
o->base.type = MP_OBJ_TO_PTR(class);
|
||||
o->base.type = class;
|
||||
mp_map_init(&o->members, 0);
|
||||
mp_seq_clear(o->subobj, 0, subobjs, sizeof(*o->subobj));
|
||||
return MP_OBJ_FROM_PTR(o);
|
||||
@ -235,16 +235,14 @@ STATIC void instance_print(const mp_print_t *print, mp_obj_t self_in, mp_print_k
|
||||
mp_printf(print, "<%s object at %p>", mp_obj_get_type_str(self_in), self_in);
|
||||
}
|
||||
|
||||
mp_obj_t mp_obj_instance_make_new(mp_obj_t self_in, size_t n_args, size_t n_kw, const mp_obj_t *args) {
|
||||
assert(MP_OBJ_IS_TYPE(self_in, &mp_type_type));
|
||||
mp_obj_type_t *self = MP_OBJ_TO_PTR(self_in);
|
||||
mp_obj_t mp_obj_instance_make_new(const mp_obj_type_t *self, size_t n_args, size_t n_kw, const mp_obj_t *args) {
|
||||
assert(mp_obj_is_instance_type(self));
|
||||
|
||||
const mp_obj_type_t *native_base;
|
||||
uint num_native_bases = instance_count_native_bases(self, &native_base);
|
||||
assert(num_native_bases < 2);
|
||||
|
||||
mp_obj_instance_t *o = MP_OBJ_TO_PTR(mp_obj_new_instance(self_in, num_native_bases));
|
||||
mp_obj_instance_t *o = MP_OBJ_TO_PTR(mp_obj_new_instance(self, num_native_bases));
|
||||
|
||||
// This executes only "__new__" part of obejection creation.
|
||||
// TODO: This won't work will for classes with native bases.
|
||||
@ -269,14 +267,15 @@ mp_obj_t mp_obj_instance_make_new(mp_obj_t self_in, size_t n_args, size_t n_kw,
|
||||
if (init_fn[0] == MP_OBJ_SENTINEL) {
|
||||
// Native type's constructor is what wins - it gets all our arguments,
|
||||
// and none Python classes are initialized at all.
|
||||
o->subobj[0] = native_base->make_new(MP_OBJ_FROM_PTR(native_base), n_args, n_kw, args);
|
||||
o->subobj[0] = native_base->make_new(native_base, n_args, n_kw, args);
|
||||
} else if (init_fn[0] != MP_OBJ_NULL) {
|
||||
// now call Python class __new__ function with all args
|
||||
if (n_args == 0 && n_kw == 0) {
|
||||
new_ret = mp_call_function_n_kw(init_fn[0], 1, 0, (mp_obj_t*)(void*)&self_in);
|
||||
mp_obj_t args2[1] = {MP_OBJ_FROM_PTR(self)};
|
||||
new_ret = mp_call_function_n_kw(init_fn[0], 1, 0, args2);
|
||||
} else {
|
||||
mp_obj_t *args2 = m_new(mp_obj_t, 1 + n_args + 2 * n_kw);
|
||||
args2[0] = self_in;
|
||||
args2[0] = MP_OBJ_FROM_PTR(self);
|
||||
memcpy(args2 + 1, args, (n_args + 2 * n_kw) * sizeof(mp_obj_t));
|
||||
new_ret = mp_call_function_n_kw(init_fn[0], n_args + 1, n_kw, args2);
|
||||
m_del(mp_obj_t, args2, 1 + n_args + 2 * n_kw);
|
||||
@ -778,7 +777,7 @@ STATIC void type_print(const mp_print_t *print, mp_obj_t self_in, mp_print_kind_
|
||||
mp_printf(print, "<class '%q'>", self->name);
|
||||
}
|
||||
|
||||
STATIC mp_obj_t type_make_new(mp_obj_t type_in, size_t n_args, size_t n_kw, const mp_obj_t *args) {
|
||||
STATIC mp_obj_t type_make_new(const mp_obj_type_t *type_in, size_t n_args, size_t n_kw, const mp_obj_t *args) {
|
||||
(void)type_in;
|
||||
|
||||
mp_arg_check_num(n_args, n_kw, 1, 3, false);
|
||||
@ -813,7 +812,7 @@ STATIC mp_obj_t type_call(mp_obj_t self_in, size_t n_args, size_t n_kw, const mp
|
||||
}
|
||||
|
||||
// make new instance
|
||||
mp_obj_t o = self->make_new(self_in, n_args, n_kw, args);
|
||||
mp_obj_t o = self->make_new(self, n_args, n_kw, args);
|
||||
|
||||
// return new instance
|
||||
return o;
|
||||
@ -931,7 +930,7 @@ mp_obj_t mp_obj_new_type(qstr name, mp_obj_t bases_tuple, mp_obj_t locals_dict)
|
||||
// __new__ slot exists; check if it is a function
|
||||
if (MP_OBJ_IS_FUN(elem->value)) {
|
||||
// __new__ is a function, wrap it in a staticmethod decorator
|
||||
elem->value = static_class_method_make_new(MP_OBJ_FROM_PTR(&mp_type_staticmethod), 1, 0, &elem->value);
|
||||
elem->value = static_class_method_make_new(&mp_type_staticmethod, 1, 0, &elem->value);
|
||||
}
|
||||
}
|
||||
|
||||
@ -957,7 +956,7 @@ STATIC void super_print(const mp_print_t *print, mp_obj_t self_in, mp_print_kind
|
||||
mp_print_str(print, ">");
|
||||
}
|
||||
|
||||
STATIC mp_obj_t super_make_new(mp_obj_t type_in, size_t n_args, size_t n_kw, const mp_obj_t *args) {
|
||||
STATIC mp_obj_t super_make_new(const mp_obj_type_t *type_in, size_t n_args, size_t n_kw, const mp_obj_t *args) {
|
||||
(void)type_in;
|
||||
// 0 arguments are turned into 2 in the compiler
|
||||
// 1 argument is not yet implemented
|
||||
@ -1108,8 +1107,7 @@ mp_obj_t mp_instance_cast_to_native_base(mp_const_obj_t self_in, mp_const_obj_t
|
||||
/******************************************************************************/
|
||||
// staticmethod and classmethod types (probably should go in a different file)
|
||||
|
||||
STATIC mp_obj_t static_class_method_make_new(mp_obj_t self_in, size_t n_args, size_t n_kw, const mp_obj_t *args) {
|
||||
mp_obj_type_t *self = MP_OBJ_TO_PTR(self_in);
|
||||
STATIC mp_obj_t static_class_method_make_new(const mp_obj_type_t *self, size_t n_args, size_t n_kw, const mp_obj_t *args) {
|
||||
assert(self == &mp_type_staticmethod || self == &mp_type_classmethod);
|
||||
|
||||
mp_arg_check_num(n_args, n_kw, 1, 1, false);
|
||||
|
@ -47,6 +47,6 @@ mp_obj_t mp_obj_instance_call(mp_obj_t self_in, size_t n_args, size_t n_kw, cons
|
||||
#define mp_obj_is_instance_type(type) ((type)->make_new == mp_obj_instance_make_new)
|
||||
#define mp_obj_is_native_type(type) ((type)->make_new != mp_obj_instance_make_new)
|
||||
// this needs to be exposed for the above macros to work correctly
|
||||
mp_obj_t mp_obj_instance_make_new(mp_obj_t self_in, size_t n_args, size_t n_kw, const mp_obj_t *args);
|
||||
mp_obj_t mp_obj_instance_make_new(const mp_obj_type_t *self_in, size_t n_args, size_t n_kw, const mp_obj_t *args);
|
||||
|
||||
#endif // __MICROPY_INCLUDED_PY_OBJTYPE_H__
|
||||
|
@ -36,11 +36,11 @@ typedef struct _mp_obj_zip_t {
|
||||
mp_obj_t iters[];
|
||||
} mp_obj_zip_t;
|
||||
|
||||
STATIC mp_obj_t zip_make_new(mp_obj_t type_in, size_t n_args, size_t n_kw, const mp_obj_t *args) {
|
||||
STATIC mp_obj_t zip_make_new(const mp_obj_type_t *type, size_t n_args, size_t n_kw, const mp_obj_t *args) {
|
||||
mp_arg_check_num(n_args, n_kw, 0, MP_OBJ_FUN_ARGS_MAX, false);
|
||||
|
||||
mp_obj_zip_t *o = m_new_obj_var(mp_obj_zip_t, mp_obj_t, n_args);
|
||||
o->base.type = MP_OBJ_TO_PTR(type_in);
|
||||
o->base.type = type;
|
||||
o->n_iters = n_args;
|
||||
for (mp_uint_t i = 0; i < n_args; i++) {
|
||||
o->iters[i] = mp_getiter(args[i]);
|
||||
|
@ -130,7 +130,7 @@ STATIC pyb_accel_obj_t pyb_accel_obj;
|
||||
/// accel = pyb.Accel()
|
||||
/// pyb.delay(20)
|
||||
/// print(accel.x())
|
||||
STATIC mp_obj_t pyb_accel_make_new(mp_obj_t type_in, mp_uint_t n_args, mp_uint_t n_kw, const mp_obj_t *args) {
|
||||
STATIC mp_obj_t pyb_accel_make_new(const mp_obj_type_t *type, mp_uint_t n_args, mp_uint_t n_kw, const mp_obj_t *args) {
|
||||
// check arguments
|
||||
mp_arg_check_num(n_args, n_kw, 0, 0, false);
|
||||
|
||||
|
@ -153,7 +153,7 @@ STATIC void adc_print(const mp_print_t *print, mp_obj_t self_in, mp_print_kind_t
|
||||
/// \classmethod \constructor(pin)
|
||||
/// Create an ADC object associated with the given pin.
|
||||
/// This allows you to then read analog values on that pin.
|
||||
STATIC mp_obj_t adc_make_new(mp_obj_t type_in, mp_uint_t n_args, mp_uint_t n_kw, const mp_obj_t *args) {
|
||||
STATIC mp_obj_t adc_make_new(const mp_obj_type_t *type, mp_uint_t n_args, mp_uint_t n_kw, const mp_obj_t *args) {
|
||||
// check number of arguments
|
||||
mp_arg_check_num(n_args, n_kw, 1, 1, false);
|
||||
|
||||
@ -436,7 +436,7 @@ float adc_read_core_vref(ADC_HandleTypeDef *adcHandle) {
|
||||
/******************************************************************************/
|
||||
/* Micro Python bindings : adc_all object */
|
||||
|
||||
STATIC mp_obj_t adc_all_make_new(mp_obj_t type_in, mp_uint_t n_args, mp_uint_t n_kw, const mp_obj_t *args) {
|
||||
STATIC mp_obj_t adc_all_make_new(const mp_obj_type_t *type, mp_uint_t n_args, mp_uint_t n_kw, const mp_obj_t *args) {
|
||||
// check number of arguments
|
||||
mp_arg_check_num(n_args, n_kw, 1, 1, false);
|
||||
|
||||
|
@ -339,7 +339,7 @@ STATIC mp_obj_t pyb_can_init_helper(pyb_can_obj_t *self, mp_uint_t n_args, const
|
||||
///
|
||||
/// - `CAN(1)` is on `YA`: `(RX, TX) = (Y3, Y4) = (PB8, PB9)`
|
||||
/// - `CAN(2)` is on `YB`: `(RX, TX) = (Y5, Y6) = (PB12, PB13)`
|
||||
STATIC mp_obj_t pyb_can_make_new(mp_obj_t type_in, mp_uint_t n_args, mp_uint_t n_kw, const mp_obj_t *args) {
|
||||
STATIC mp_obj_t pyb_can_make_new(const mp_obj_type_t *type, mp_uint_t n_args, mp_uint_t n_kw, const mp_obj_t *args) {
|
||||
// check arguments
|
||||
mp_arg_check_num(n_args, n_kw, 1, MP_OBJ_FUN_ARGS_MAX, true);
|
||||
|
||||
|
@ -192,7 +192,7 @@ STATIC mp_obj_t pyb_dac_init_helper(pyb_dac_obj_t *self, mp_uint_t n_args, const
|
||||
///
|
||||
/// `port` can be a pin object, or an integer (1 or 2).
|
||||
/// DAC(1) is on pin X5 and DAC(2) is on pin X6.
|
||||
STATIC mp_obj_t pyb_dac_make_new(mp_obj_t type_in, mp_uint_t n_args, mp_uint_t n_kw, const mp_obj_t *args) {
|
||||
STATIC mp_obj_t pyb_dac_make_new(const mp_obj_type_t *type, mp_uint_t n_args, mp_uint_t n_kw, const mp_obj_t *args) {
|
||||
// check arguments
|
||||
mp_arg_check_num(n_args, n_kw, 1, MP_OBJ_FUN_ARGS_MAX, true);
|
||||
|
||||
|
@ -307,7 +307,7 @@ STATIC const mp_arg_t pyb_extint_make_new_args[] = {
|
||||
};
|
||||
#define PYB_EXTINT_MAKE_NEW_NUM_ARGS MP_ARRAY_SIZE(pyb_extint_make_new_args)
|
||||
|
||||
STATIC mp_obj_t extint_make_new(mp_obj_t type_in, mp_uint_t n_args, mp_uint_t n_kw, const mp_obj_t *args) {
|
||||
STATIC mp_obj_t extint_make_new(const mp_obj_type_t *type, mp_uint_t n_args, mp_uint_t n_kw, const mp_obj_t *args) {
|
||||
// type_in == extint_obj_type
|
||||
|
||||
// parse args
|
||||
@ -315,7 +315,7 @@ STATIC mp_obj_t extint_make_new(mp_obj_t type_in, mp_uint_t n_args, mp_uint_t n_
|
||||
mp_arg_parse_all_kw_array(n_args, n_kw, args, PYB_EXTINT_MAKE_NEW_NUM_ARGS, pyb_extint_make_new_args, vals);
|
||||
|
||||
extint_obj_t *self = m_new_obj(extint_obj_t);
|
||||
self->base.type = type_in;
|
||||
self->base.type = type;
|
||||
self->line = extint_register(vals[0].u_obj, vals[1].u_int, vals[2].u_int, vals[3].u_obj, false);
|
||||
|
||||
return self;
|
||||
|
@ -157,7 +157,7 @@ STATIC const mp_arg_t file_open_args[] = {
|
||||
};
|
||||
#define FILE_OPEN_NUM_ARGS MP_ARRAY_SIZE(file_open_args)
|
||||
|
||||
STATIC mp_obj_t file_open(mp_obj_t type, mp_arg_val_t *args) {
|
||||
STATIC mp_obj_t file_open(const mp_obj_type_t *type, mp_arg_val_t *args) {
|
||||
int mode = 0;
|
||||
const char *mode_s = mp_obj_str_get_str(args[1].u_obj);
|
||||
// TODO make sure only one of r, w, x, a, and b, t are specified
|
||||
@ -180,11 +180,11 @@ STATIC mp_obj_t file_open(mp_obj_t type, mp_arg_val_t *args) {
|
||||
break;
|
||||
#if MICROPY_PY_IO_FILEIO
|
||||
case 'b':
|
||||
type = (mp_obj_t)&mp_type_fileio;
|
||||
type = &mp_type_fileio;
|
||||
break;
|
||||
#endif
|
||||
case 't':
|
||||
type = (mp_obj_t)&mp_type_textio;
|
||||
type = &mp_type_textio;
|
||||
break;
|
||||
}
|
||||
}
|
||||
@ -207,10 +207,10 @@ STATIC mp_obj_t file_open(mp_obj_t type, mp_arg_val_t *args) {
|
||||
return o;
|
||||
}
|
||||
|
||||
STATIC mp_obj_t file_obj_make_new(mp_obj_t type_in, mp_uint_t n_args, mp_uint_t n_kw, const mp_obj_t *args) {
|
||||
STATIC mp_obj_t file_obj_make_new(const mp_obj_type_t *type, mp_uint_t n_args, mp_uint_t n_kw, const mp_obj_t *args) {
|
||||
mp_arg_val_t arg_vals[FILE_OPEN_NUM_ARGS];
|
||||
mp_arg_parse_all_kw_array(n_args, n_kw, args, FILE_OPEN_NUM_ARGS, file_open_args, arg_vals);
|
||||
return file_open(type_in, arg_vals);
|
||||
return file_open(type, arg_vals);
|
||||
}
|
||||
|
||||
// TODO gc hook to close the file if not already closed
|
||||
@ -275,6 +275,6 @@ mp_obj_t mp_builtin_open(mp_uint_t n_args, const mp_obj_t *args, mp_map_t *kwarg
|
||||
// TODO: analyze buffering args and instantiate appropriate type
|
||||
mp_arg_val_t arg_vals[FILE_OPEN_NUM_ARGS];
|
||||
mp_arg_parse_all(n_args, args, kwargs, FILE_OPEN_NUM_ARGS, file_open_args, arg_vals);
|
||||
return file_open((mp_obj_t)&mp_type_textio, arg_vals);
|
||||
return file_open(&mp_type_textio, arg_vals);
|
||||
}
|
||||
MP_DEFINE_CONST_FUN_OBJ_KW(mp_builtin_open_obj, 1, mp_builtin_open);
|
||||
|
@ -395,7 +395,7 @@ STATIC mp_obj_t pyb_i2c_init_helper(const pyb_i2c_obj_t *self, mp_uint_t n_args,
|
||||
///
|
||||
/// - `I2C(1)` is on the X position: `(SCL, SDA) = (X9, X10) = (PB6, PB7)`
|
||||
/// - `I2C(2)` is on the Y position: `(SCL, SDA) = (Y9, Y10) = (PB10, PB11)`
|
||||
STATIC mp_obj_t pyb_i2c_make_new(mp_obj_t type_in, mp_uint_t n_args, mp_uint_t n_kw, const mp_obj_t *args) {
|
||||
STATIC mp_obj_t pyb_i2c_make_new(const mp_obj_type_t *type, mp_uint_t n_args, mp_uint_t n_kw, const mp_obj_t *args) {
|
||||
// check arguments
|
||||
mp_arg_check_num(n_args, n_kw, 1, MP_OBJ_FUN_ARGS_MAX, true);
|
||||
|
||||
|
@ -192,7 +192,7 @@ STATIC void lcd_write_strn(pyb_lcd_obj_t *lcd, const char *str, unsigned int len
|
||||
///
|
||||
/// Construct an LCD object in the given skin position. `skin_position` can be 'X' or 'Y', and
|
||||
/// should match the position where the LCD pyskin is plugged in.
|
||||
STATIC mp_obj_t pyb_lcd_make_new(mp_obj_t type_in, mp_uint_t n_args, mp_uint_t n_kw, const mp_obj_t *args) {
|
||||
STATIC mp_obj_t pyb_lcd_make_new(const mp_obj_type_t *type, mp_uint_t n_args, mp_uint_t n_kw, const mp_obj_t *args) {
|
||||
// check arguments
|
||||
mp_arg_check_num(n_args, n_kw, 1, 1, false);
|
||||
|
||||
|
@ -217,7 +217,7 @@ void led_obj_print(const mp_print_t *print, mp_obj_t self_in, mp_print_kind_t ki
|
||||
/// Create an LED object associated with the given LED:
|
||||
///
|
||||
/// - `id` is the LED number, 1-4.
|
||||
STATIC mp_obj_t led_obj_make_new(mp_obj_t type_in, mp_uint_t n_args, mp_uint_t n_kw, const mp_obj_t *args) {
|
||||
STATIC mp_obj_t led_obj_make_new(const mp_obj_type_t *type, mp_uint_t n_args, mp_uint_t n_kw, const mp_obj_t *args) {
|
||||
// check arguments
|
||||
mp_arg_check_num(n_args, n_kw, 1, 1, false);
|
||||
|
||||
|
@ -428,7 +428,7 @@ STATIC const cc3k_obj_t cc3k_obj = {{(mp_obj_type_t*)&mod_network_nic_type_cc3k}
|
||||
// [SPI on Y position; Y6=B13=SCK, Y7=B14=MISO, Y8=B15=MOSI]
|
||||
//
|
||||
// STM32F4DISC: init(pyb.SPI(2), pyb.Pin.cpu.A15, pyb.Pin.cpu.B10, pyb.Pin.cpu.B11)
|
||||
STATIC mp_obj_t cc3k_make_new(mp_obj_t type_in, mp_uint_t n_args, mp_uint_t n_kw, const mp_obj_t *args) {
|
||||
STATIC mp_obj_t cc3k_make_new(const mp_obj_type_t *type, mp_uint_t n_args, mp_uint_t n_kw, const mp_obj_t *args) {
|
||||
// check arguments
|
||||
mp_arg_check_num(n_args, n_kw, 4, 4, false);
|
||||
|
||||
|
@ -318,7 +318,7 @@ STATIC mp_obj_t wiznet5k_socket_disconnect(mp_obj_t self_in) {
|
||||
|
||||
/// \classmethod \constructor(spi, pin_cs, pin_rst)
|
||||
/// Create and return a WIZNET5K object.
|
||||
STATIC mp_obj_t wiznet5k_make_new(mp_obj_t type_in, mp_uint_t n_args, mp_uint_t n_kw, const mp_obj_t *args) {
|
||||
STATIC mp_obj_t wiznet5k_make_new(const mp_obj_type_t *type, mp_uint_t n_args, mp_uint_t n_kw, const mp_obj_t *args) {
|
||||
// check arguments
|
||||
mp_arg_check_num(n_args, n_kw, 3, 3, false);
|
||||
|
||||
|
@ -41,7 +41,7 @@
|
||||
STATIC const mp_obj_type_t socket_type;
|
||||
|
||||
// constructor socket(family=AF_INET, type=SOCK_STREAM, proto=0, fileno=None)
|
||||
STATIC mp_obj_t socket_make_new(mp_obj_t type_in, mp_uint_t n_args, mp_uint_t n_kw, const mp_obj_t *args) {
|
||||
STATIC mp_obj_t socket_make_new(const mp_obj_type_t *type, mp_uint_t n_args, mp_uint_t n_kw, const mp_obj_t *args) {
|
||||
mp_arg_check_num(n_args, n_kw, 0, 4, false);
|
||||
|
||||
// create socket object (not bound to any NIC yet)
|
||||
|
@ -244,7 +244,7 @@ STATIC mp_obj_t pin_obj_init_helper(const pin_obj_t *pin, mp_uint_t n_args, cons
|
||||
/// \classmethod \constructor(id, ...)
|
||||
/// Create a new Pin object associated with the id. If additional arguments are given,
|
||||
/// they are used to initialise the pin. See `init`.
|
||||
STATIC mp_obj_t pin_make_new(mp_obj_t self_in, mp_uint_t n_args, mp_uint_t n_kw, const mp_obj_t *args) {
|
||||
STATIC mp_obj_t pin_make_new(const mp_obj_type_t *type, mp_uint_t n_args, mp_uint_t n_kw, const mp_obj_t *args) {
|
||||
mp_arg_check_num(n_args, n_kw, 1, MP_OBJ_FUN_ARGS_MAX, true);
|
||||
|
||||
// Run an argument through the mapper and return the result.
|
||||
|
@ -418,7 +418,7 @@ STATIC const pyb_rtc_obj_t pyb_rtc_obj = {{&pyb_rtc_type}};
|
||||
|
||||
/// \classmethod \constructor()
|
||||
/// Create an RTC object.
|
||||
STATIC mp_obj_t pyb_rtc_make_new(mp_obj_t type_in, mp_uint_t n_args, mp_uint_t n_kw, const mp_obj_t *args) {
|
||||
STATIC mp_obj_t pyb_rtc_make_new(const mp_obj_type_t *type, mp_uint_t n_args, mp_uint_t n_kw, const mp_obj_t *args) {
|
||||
// check arguments
|
||||
mp_arg_check_num(n_args, n_kw, 0, 0, false);
|
||||
|
||||
|
@ -185,7 +185,7 @@ STATIC void pyb_servo_print(const mp_print_t *print, mp_obj_t self_in, mp_print_
|
||||
|
||||
/// \classmethod \constructor(id)
|
||||
/// Create a servo object. `id` is 1-4.
|
||||
STATIC mp_obj_t pyb_servo_make_new(mp_obj_t type_in, mp_uint_t n_args, mp_uint_t n_kw, const mp_obj_t *args) {
|
||||
STATIC mp_obj_t pyb_servo_make_new(const mp_obj_type_t *type, mp_uint_t n_args, mp_uint_t n_kw, const mp_obj_t *args) {
|
||||
// check arguments
|
||||
mp_arg_check_num(n_args, n_kw, 1, 1, false);
|
||||
|
||||
|
@ -466,7 +466,7 @@ STATIC mp_obj_t pyb_spi_init_helper(const pyb_spi_obj_t *self, mp_uint_t n_args,
|
||||
///
|
||||
/// At the moment, the NSS pin is not used by the SPI driver and is free
|
||||
/// for other use.
|
||||
STATIC mp_obj_t pyb_spi_make_new(mp_obj_t type_in, mp_uint_t n_args, mp_uint_t n_kw, const mp_obj_t *args) {
|
||||
STATIC mp_obj_t pyb_spi_make_new(const mp_obj_type_t *type, mp_uint_t n_args, mp_uint_t n_kw, const mp_obj_t *args) {
|
||||
// check arguments
|
||||
mp_arg_check_num(n_args, n_kw, 1, MP_OBJ_FUN_ARGS_MAX, true);
|
||||
|
||||
|
@ -637,7 +637,7 @@ STATIC mp_obj_t pyb_timer_init_helper(pyb_timer_obj_t *self, mp_uint_t n_args, c
|
||||
/// Construct a new timer object of the given id. If additional
|
||||
/// arguments are given, then the timer is initialised by `init(...)`.
|
||||
/// `id` can be 1 to 14, excluding 3.
|
||||
STATIC mp_obj_t pyb_timer_make_new(mp_obj_t type_in, mp_uint_t n_args, mp_uint_t n_kw, const mp_obj_t *args) {
|
||||
STATIC mp_obj_t pyb_timer_make_new(const mp_obj_type_t *type, mp_uint_t n_args, mp_uint_t n_kw, const mp_obj_t *args) {
|
||||
// check arguments
|
||||
mp_arg_check_num(n_args, n_kw, 1, MP_OBJ_FUN_ARGS_MAX, true);
|
||||
|
||||
|
@ -589,7 +589,7 @@ STATIC mp_obj_t pyb_uart_init_helper(pyb_uart_obj_t *self, mp_uint_t n_args, con
|
||||
/// - `UART(6)` is on `YA`: `(TX, RX) = (Y1, Y2) = (PC6, PC7)`
|
||||
/// - `UART(3)` is on `YB`: `(TX, RX) = (Y9, Y10) = (PB10, PB11)`
|
||||
/// - `UART(2)` is on: `(TX, RX) = (X3, X4) = (PA2, PA3)`
|
||||
STATIC mp_obj_t pyb_uart_make_new(mp_obj_t type_in, mp_uint_t n_args, mp_uint_t n_kw, const mp_obj_t *args) {
|
||||
STATIC mp_obj_t pyb_uart_make_new(const mp_obj_type_t *type, mp_uint_t n_args, mp_uint_t n_kw, const mp_obj_t *args) {
|
||||
// check arguments
|
||||
mp_arg_check_num(n_args, n_kw, 1, MP_OBJ_FUN_ARGS_MAX, true);
|
||||
|
||||
|
@ -354,7 +354,7 @@ STATIC void pyb_usb_vcp_print(const mp_print_t *print, mp_obj_t self_in, mp_prin
|
||||
|
||||
/// \classmethod \constructor()
|
||||
/// Create a new USB_VCP object.
|
||||
STATIC mp_obj_t pyb_usb_vcp_make_new(mp_obj_t type_in, mp_uint_t n_args, mp_uint_t n_kw, const mp_obj_t *args) {
|
||||
STATIC mp_obj_t pyb_usb_vcp_make_new(const mp_obj_type_t *type, mp_uint_t n_args, mp_uint_t n_kw, const mp_obj_t *args) {
|
||||
// check arguments
|
||||
mp_arg_check_num(n_args, n_kw, 0, 0, false);
|
||||
|
||||
@ -543,7 +543,7 @@ typedef struct _pyb_usb_hid_obj_t {
|
||||
|
||||
STATIC const pyb_usb_hid_obj_t pyb_usb_hid_obj = {{&pyb_usb_hid_type}};
|
||||
|
||||
STATIC mp_obj_t pyb_usb_hid_make_new(mp_obj_t type_in, mp_uint_t n_args, mp_uint_t n_kw, const mp_obj_t *args) {
|
||||
STATIC mp_obj_t pyb_usb_hid_make_new(const mp_obj_type_t *type, mp_uint_t n_args, mp_uint_t n_kw, const mp_obj_t *args) {
|
||||
// check arguments
|
||||
mp_arg_check_num(n_args, n_kw, 0, 0, false);
|
||||
|
||||
|
@ -83,7 +83,7 @@ void pyb_switch_print(const mp_print_t *print, mp_obj_t self_in, mp_print_kind_t
|
||||
|
||||
/// \classmethod \constructor()
|
||||
/// Create and return a switch object.
|
||||
STATIC mp_obj_t pyb_switch_make_new(mp_obj_t type_in, mp_uint_t n_args, mp_uint_t n_kw, const mp_obj_t *args) {
|
||||
STATIC mp_obj_t pyb_switch_make_new(const mp_obj_type_t *type, mp_uint_t n_args, mp_uint_t n_kw, const mp_obj_t *args) {
|
||||
// check arguments
|
||||
mp_arg_check_num(n_args, n_kw, 0, 0, false);
|
||||
|
||||
|
@ -89,7 +89,7 @@ void led_obj_print(const mp_print_t *print, mp_obj_t self_in, mp_print_kind_t ki
|
||||
mp_printf(print, "<LED %lu>", self->led_id);
|
||||
}
|
||||
|
||||
STATIC mp_obj_t led_obj_make_new(mp_obj_t type_in, uint n_args, uint n_kw, const mp_obj_t *args) {
|
||||
STATIC mp_obj_t led_obj_make_new(const mp_obj_type_t *type, uint n_args, uint n_kw, const mp_obj_t *args) {
|
||||
// check arguments
|
||||
mp_arg_check_num(n_args, n_kw, 1, 1, false);
|
||||
|
||||
|
@ -304,7 +304,7 @@ STATIC mp_obj_t pyb_timer_init_helper(pyb_timer_obj_t *self, uint n_args, const
|
||||
/// Construct a new timer object of the given id. If additional
|
||||
/// arguments are given, then the timer is initialised by `init(...)`.
|
||||
/// `id` can be 1 to 14, excluding 3.
|
||||
STATIC mp_obj_t pyb_timer_make_new(mp_obj_t type_in, mp_uint_t n_args, mp_uint_t n_kw, const mp_obj_t *args) {
|
||||
STATIC mp_obj_t pyb_timer_make_new(const mp_obj_type_t *type, mp_uint_t n_args, mp_uint_t n_kw, const mp_obj_t *args) {
|
||||
// check arguments
|
||||
mp_arg_check_num(n_args, n_kw, 1, MP_OBJ_FUN_ARGS_MAX, true);
|
||||
|
||||
|
@ -306,7 +306,7 @@ STATIC mp_obj_t pyb_uart_init_helper(pyb_uart_obj_t *self, uint n_args, const mp
|
||||
/// - `UART(6)` is on `YA`: `(TX, RX) = (Y1, Y2) = (PC6, PC7)`
|
||||
/// - `UART(3)` is on `YB`: `(TX, RX) = (Y9, Y10) = (PB10, PB11)`
|
||||
/// - `UART(2)` is on: `(TX, RX) = (X3, X4) = (PA2, PA3)`
|
||||
STATIC mp_obj_t pyb_uart_make_new(mp_obj_t type_in, uint n_args, uint n_kw, const mp_obj_t *args) {
|
||||
STATIC mp_obj_t pyb_uart_make_new(const mp_obj_type_t *type, uint n_args, uint n_kw, const mp_obj_t *args) {
|
||||
// check arguments
|
||||
mp_arg_check_num(n_args, n_kw, 1, MP_OBJ_FUN_ARGS_MAX, true);
|
||||
|
||||
|
@ -202,10 +202,10 @@ STATIC mp_obj_t fdfile_open(const mp_obj_type_t *type, mp_arg_val_t *args) {
|
||||
return MP_OBJ_FROM_PTR(o);
|
||||
}
|
||||
|
||||
STATIC mp_obj_t fdfile_make_new(mp_obj_t type_in, size_t n_args, size_t n_kw, const mp_obj_t *args) {
|
||||
STATIC mp_obj_t fdfile_make_new(const mp_obj_type_t *type, size_t n_args, size_t n_kw, const mp_obj_t *args) {
|
||||
mp_arg_val_t arg_vals[FILE_OPEN_NUM_ARGS];
|
||||
mp_arg_parse_all_kw_array(n_args, n_kw, args, FILE_OPEN_NUM_ARGS, file_open_args, arg_vals);
|
||||
return fdfile_open(MP_OBJ_TO_PTR(type_in), arg_vals);
|
||||
return fdfile_open(type, arg_vals);
|
||||
}
|
||||
|
||||
STATIC const mp_rom_map_elem_t rawfile_locals_dict_table[] = {
|
||||
|
@ -301,7 +301,7 @@ STATIC mp_obj_t ffimod_addr(mp_obj_t self_in, mp_obj_t symname_in) {
|
||||
}
|
||||
MP_DEFINE_CONST_FUN_OBJ_2(ffimod_addr_obj, ffimod_addr);
|
||||
|
||||
STATIC mp_obj_t ffimod_make_new(mp_obj_t type_in, size_t n_args, size_t n_kw, const mp_obj_t *args) {
|
||||
STATIC mp_obj_t ffimod_make_new(const mp_obj_type_t *type, size_t n_args, size_t n_kw, const mp_obj_t *args) {
|
||||
(void)n_args;
|
||||
(void)n_kw;
|
||||
|
||||
@ -315,7 +315,7 @@ STATIC mp_obj_t ffimod_make_new(mp_obj_t type_in, size_t n_args, size_t n_kw, co
|
||||
nlr_raise(mp_obj_new_exception_arg1(&mp_type_OSError, MP_OBJ_NEW_SMALL_INT(errno)));
|
||||
}
|
||||
mp_obj_ffimod_t *o = m_new_obj(mp_obj_ffimod_t);
|
||||
o->base.type = MP_OBJ_TO_PTR(type_in);
|
||||
o->base.type = type;
|
||||
o->handle = mod;
|
||||
return MP_OBJ_FROM_PTR(o);
|
||||
}
|
||||
@ -478,7 +478,7 @@ STATIC const mp_obj_type_t opaque_type = {
|
||||
*/
|
||||
|
||||
STATIC mp_obj_t mod_ffi_open(size_t n_args, const mp_obj_t *args) {
|
||||
return ffimod_make_new((mp_obj_t)&ffimod_type, n_args, 0, args);
|
||||
return ffimod_make_new(&ffimod_type, n_args, 0, args);
|
||||
}
|
||||
MP_DEFINE_CONST_FUN_OBJ_VAR_BETWEEN(mod_ffi_open_obj, 1, 2, mod_ffi_open);
|
||||
|
||||
|
@ -313,7 +313,7 @@ STATIC mp_obj_t socket_makefile(size_t n_args, const mp_obj_t *args) {
|
||||
}
|
||||
STATIC MP_DEFINE_CONST_FUN_OBJ_VAR_BETWEEN(socket_makefile_obj, 1, 3, socket_makefile);
|
||||
|
||||
STATIC mp_obj_t socket_make_new(mp_obj_t type_in, size_t n_args, size_t n_kw, const mp_obj_t *args) {
|
||||
STATIC mp_obj_t socket_make_new(const mp_obj_type_t *type_in, size_t n_args, size_t n_kw, const mp_obj_t *args) {
|
||||
(void)type_in;
|
||||
(void)n_kw;
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user