mirror of
https://github.com/micropython/micropython.git
synced 2026-01-05 11:40:18 +01:00
all: Reformat C and Python source code with tools/codeformat.py.
This is run with uncrustify 0.70.1, and black 19.10b0.
This commit is contained in:
170
py/obj.h
170
py/obj.h
@@ -66,13 +66,13 @@ typedef struct _mp_obj_base_t mp_obj_base_t;
|
||||
// as many as we can to MP_OBJ_NULL because it's cheaper to load/compare 0.
|
||||
|
||||
#if MICROPY_DEBUG_MP_OBJ_SENTINELS
|
||||
#define MP_OBJ_NULL (MP_OBJ_FROM_PTR((void*)0))
|
||||
#define MP_OBJ_STOP_ITERATION (MP_OBJ_FROM_PTR((void*)4))
|
||||
#define MP_OBJ_SENTINEL (MP_OBJ_FROM_PTR((void*)8))
|
||||
#define MP_OBJ_NULL (MP_OBJ_FROM_PTR((void *)0))
|
||||
#define MP_OBJ_STOP_ITERATION (MP_OBJ_FROM_PTR((void *)4))
|
||||
#define MP_OBJ_SENTINEL (MP_OBJ_FROM_PTR((void *)8))
|
||||
#else
|
||||
#define MP_OBJ_NULL (MP_OBJ_FROM_PTR((void*)0))
|
||||
#define MP_OBJ_STOP_ITERATION (MP_OBJ_FROM_PTR((void*)0))
|
||||
#define MP_OBJ_SENTINEL (MP_OBJ_FROM_PTR((void*)4))
|
||||
#define MP_OBJ_NULL (MP_OBJ_FROM_PTR((void *)0))
|
||||
#define MP_OBJ_STOP_ITERATION (MP_OBJ_FROM_PTR((void *)0))
|
||||
#define MP_OBJ_SENTINEL (MP_OBJ_FROM_PTR((void *)4))
|
||||
#endif
|
||||
|
||||
// These macros/inline functions operate on objects and depend on the
|
||||
@@ -81,18 +81,21 @@ typedef struct _mp_obj_base_t mp_obj_base_t;
|
||||
|
||||
#if MICROPY_OBJ_REPR == MICROPY_OBJ_REPR_A
|
||||
|
||||
static inline bool mp_obj_is_small_int(mp_const_obj_t o)
|
||||
{ return ((((mp_int_t)(o)) & 1) != 0); }
|
||||
static inline bool mp_obj_is_small_int(mp_const_obj_t o) {
|
||||
return (((mp_int_t)(o)) & 1) != 0;
|
||||
}
|
||||
#define MP_OBJ_SMALL_INT_VALUE(o) (((mp_int_t)(o)) >> 1)
|
||||
#define MP_OBJ_NEW_SMALL_INT(small_int) ((mp_obj_t)((((mp_uint_t)(small_int)) << 1) | 1))
|
||||
|
||||
static inline bool mp_obj_is_qstr(mp_const_obj_t o)
|
||||
{ return ((((mp_int_t)(o)) & 7) == 2); }
|
||||
static inline bool mp_obj_is_qstr(mp_const_obj_t o) {
|
||||
return (((mp_int_t)(o)) & 7) == 2;
|
||||
}
|
||||
#define MP_OBJ_QSTR_VALUE(o) (((mp_uint_t)(o)) >> 3)
|
||||
#define MP_OBJ_NEW_QSTR(qst) ((mp_obj_t)((((mp_uint_t)(qst)) << 3) | 2))
|
||||
|
||||
static inline bool mp_obj_is_immediate_obj(mp_const_obj_t o)
|
||||
{ return ((((mp_int_t)(o)) & 7) == 6); }
|
||||
static inline bool mp_obj_is_immediate_obj(mp_const_obj_t o) {
|
||||
return (((mp_int_t)(o)) & 7) == 6;
|
||||
}
|
||||
#define MP_OBJ_IMMEDIATE_OBJ_VALUE(o) (((mp_uint_t)(o)) >> 3)
|
||||
#define MP_OBJ_NEW_IMMEDIATE_OBJ(val) ((mp_obj_t)(((val) << 3) | 6))
|
||||
|
||||
@@ -107,23 +110,27 @@ mp_float_t mp_obj_float_get(mp_obj_t self_in);
|
||||
mp_obj_t mp_obj_new_float(mp_float_t value);
|
||||
#endif
|
||||
|
||||
static inline bool mp_obj_is_obj(mp_const_obj_t o)
|
||||
{ return ((((mp_int_t)(o)) & 3) == 0); }
|
||||
static inline bool mp_obj_is_obj(mp_const_obj_t o) {
|
||||
return (((mp_int_t)(o)) & 3) == 0;
|
||||
}
|
||||
|
||||
#elif MICROPY_OBJ_REPR == MICROPY_OBJ_REPR_B
|
||||
|
||||
static inline bool mp_obj_is_small_int(mp_const_obj_t o)
|
||||
{ return ((((mp_int_t)(o)) & 3) == 1); }
|
||||
static inline bool mp_obj_is_small_int(mp_const_obj_t o) {
|
||||
return (((mp_int_t)(o)) & 3) == 1;
|
||||
}
|
||||
#define MP_OBJ_SMALL_INT_VALUE(o) (((mp_int_t)(o)) >> 2)
|
||||
#define MP_OBJ_NEW_SMALL_INT(small_int) ((mp_obj_t)((((mp_uint_t)(small_int)) << 2) | 1))
|
||||
|
||||
static inline bool mp_obj_is_qstr(mp_const_obj_t o)
|
||||
{ return ((((mp_int_t)(o)) & 7) == 3); }
|
||||
static inline bool mp_obj_is_qstr(mp_const_obj_t o) {
|
||||
return (((mp_int_t)(o)) & 7) == 3;
|
||||
}
|
||||
#define MP_OBJ_QSTR_VALUE(o) (((mp_uint_t)(o)) >> 3)
|
||||
#define MP_OBJ_NEW_QSTR(qst) ((mp_obj_t)((((mp_uint_t)(qst)) << 3) | 3))
|
||||
|
||||
static inline bool mp_obj_is_immediate_obj(mp_const_obj_t o)
|
||||
{ return ((((mp_int_t)(o)) & 7) == 7); }
|
||||
static inline bool mp_obj_is_immediate_obj(mp_const_obj_t o) {
|
||||
return (((mp_int_t)(o)) & 7) == 7;
|
||||
}
|
||||
#define MP_OBJ_IMMEDIATE_OBJ_VALUE(o) (((mp_uint_t)(o)) >> 3)
|
||||
#define MP_OBJ_NEW_IMMEDIATE_OBJ(val) ((mp_obj_t)(((val) << 3) | 7))
|
||||
|
||||
@@ -138,13 +145,15 @@ mp_float_t mp_obj_float_get(mp_obj_t self_in);
|
||||
mp_obj_t mp_obj_new_float(mp_float_t value);
|
||||
#endif
|
||||
|
||||
static inline bool mp_obj_is_obj(mp_const_obj_t o)
|
||||
{ return ((((mp_int_t)(o)) & 1) == 0); }
|
||||
static inline bool mp_obj_is_obj(mp_const_obj_t o) {
|
||||
return (((mp_int_t)(o)) & 1) == 0;
|
||||
}
|
||||
|
||||
#elif MICROPY_OBJ_REPR == MICROPY_OBJ_REPR_C
|
||||
|
||||
static inline bool mp_obj_is_small_int(mp_const_obj_t o)
|
||||
{ return ((((mp_int_t)(o)) & 1) != 0); }
|
||||
static inline bool mp_obj_is_small_int(mp_const_obj_t o) {
|
||||
return (((mp_int_t)(o)) & 1) != 0;
|
||||
}
|
||||
#define MP_OBJ_SMALL_INT_VALUE(o) (((mp_int_t)(o)) >> 1)
|
||||
#define MP_OBJ_NEW_SMALL_INT(small_int) ((mp_obj_t)((((mp_uint_t)(small_int)) << 1) | 1))
|
||||
|
||||
@@ -152,8 +161,9 @@ static inline bool mp_obj_is_small_int(mp_const_obj_t o)
|
||||
#define mp_const_float_e MP_ROM_PTR((mp_obj_t)(((0x402df854 & ~3) | 2) + 0x80800000))
|
||||
#define mp_const_float_pi MP_ROM_PTR((mp_obj_t)(((0x40490fdb & ~3) | 2) + 0x80800000))
|
||||
|
||||
static inline bool mp_obj_is_float(mp_const_obj_t o)
|
||||
{ return (((mp_uint_t)(o)) & 3) == 2 && (((mp_uint_t)(o)) & 0xff800007) != 0x00000006; }
|
||||
static inline bool mp_obj_is_float(mp_const_obj_t o) {
|
||||
return (((mp_uint_t)(o)) & 3) == 2 && (((mp_uint_t)(o)) & 0xff800007) != 0x00000006;
|
||||
}
|
||||
static inline mp_float_t mp_obj_float_get(mp_const_obj_t o) {
|
||||
union {
|
||||
mp_float_t f;
|
||||
@@ -170,33 +180,39 @@ static inline mp_obj_t mp_obj_new_float(mp_float_t f) {
|
||||
}
|
||||
#endif
|
||||
|
||||
static inline bool mp_obj_is_qstr(mp_const_obj_t o)
|
||||
{ return (((mp_uint_t)(o)) & 0xff80000f) == 0x00000006; }
|
||||
static inline bool mp_obj_is_qstr(mp_const_obj_t o) {
|
||||
return (((mp_uint_t)(o)) & 0xff80000f) == 0x00000006;
|
||||
}
|
||||
#define MP_OBJ_QSTR_VALUE(o) (((mp_uint_t)(o)) >> 4)
|
||||
#define MP_OBJ_NEW_QSTR(qst) ((mp_obj_t)((((mp_uint_t)(qst)) << 4) | 0x00000006))
|
||||
|
||||
static inline bool mp_obj_is_immediate_obj(mp_const_obj_t o)
|
||||
{ return (((mp_uint_t)(o)) & 0xff80000f) == 0x0000000e; }
|
||||
static inline bool mp_obj_is_immediate_obj(mp_const_obj_t o) {
|
||||
return (((mp_uint_t)(o)) & 0xff80000f) == 0x0000000e;
|
||||
}
|
||||
#define MP_OBJ_IMMEDIATE_OBJ_VALUE(o) (((mp_uint_t)(o)) >> 4)
|
||||
#define MP_OBJ_NEW_IMMEDIATE_OBJ(val) ((mp_obj_t)(((val) << 4) | 0xe))
|
||||
|
||||
static inline bool mp_obj_is_obj(mp_const_obj_t o)
|
||||
{ return ((((mp_int_t)(o)) & 3) == 0); }
|
||||
static inline bool mp_obj_is_obj(mp_const_obj_t o) {
|
||||
return (((mp_int_t)(o)) & 3) == 0;
|
||||
}
|
||||
|
||||
#elif MICROPY_OBJ_REPR == MICROPY_OBJ_REPR_D
|
||||
|
||||
static inline bool mp_obj_is_small_int(mp_const_obj_t o)
|
||||
{ return ((((uint64_t)(o)) & 0xffff000000000000) == 0x0001000000000000); }
|
||||
static inline bool mp_obj_is_small_int(mp_const_obj_t o) {
|
||||
return (((uint64_t)(o)) & 0xffff000000000000) == 0x0001000000000000;
|
||||
}
|
||||
#define MP_OBJ_SMALL_INT_VALUE(o) (((mp_int_t)((o) << 16)) >> 17)
|
||||
#define MP_OBJ_NEW_SMALL_INT(small_int) (((((uint64_t)(small_int)) & 0x7fffffffffff) << 1) | 0x0001000000000001)
|
||||
|
||||
static inline bool mp_obj_is_qstr(mp_const_obj_t o)
|
||||
{ return ((((uint64_t)(o)) & 0xffff000000000000) == 0x0002000000000000); }
|
||||
static inline bool mp_obj_is_qstr(mp_const_obj_t o) {
|
||||
return (((uint64_t)(o)) & 0xffff000000000000) == 0x0002000000000000;
|
||||
}
|
||||
#define MP_OBJ_QSTR_VALUE(o) ((((uint32_t)(o)) >> 1) & 0xffffffff)
|
||||
#define MP_OBJ_NEW_QSTR(qst) ((mp_obj_t)(((uint64_t)(((uint32_t)(qst)) << 1)) | 0x0002000000000001))
|
||||
|
||||
static inline bool mp_obj_is_immediate_obj(mp_const_obj_t o)
|
||||
{ return ((((uint64_t)(o)) & 0xffff000000000000) == 0x0003000000000000); }
|
||||
static inline bool mp_obj_is_immediate_obj(mp_const_obj_t o) {
|
||||
return (((uint64_t)(o)) & 0xffff000000000000) == 0x0003000000000000;
|
||||
}
|
||||
#define MP_OBJ_IMMEDIATE_OBJ_VALUE(o) ((((uint32_t)(o)) >> 46) & 3)
|
||||
#define MP_OBJ_NEW_IMMEDIATE_OBJ(val) (((uint64_t)(val) << 46) | 0x0003000000000000)
|
||||
|
||||
@@ -228,13 +244,17 @@ static inline mp_obj_t mp_obj_new_float(mp_float_t f) {
|
||||
}
|
||||
#endif
|
||||
|
||||
static inline bool mp_obj_is_obj(mp_const_obj_t o)
|
||||
{ return ((((uint64_t)(o)) & 0xffff000000000000) == 0x0000000000000000); }
|
||||
#define MP_OBJ_TO_PTR(o) ((void*)(uintptr_t)(o))
|
||||
static inline bool mp_obj_is_obj(mp_const_obj_t o) {
|
||||
return (((uint64_t)(o)) & 0xffff000000000000) == 0x0000000000000000;
|
||||
}
|
||||
#define MP_OBJ_TO_PTR(o) ((void *)(uintptr_t)(o))
|
||||
#define MP_OBJ_FROM_PTR(p) ((mp_obj_t)((uintptr_t)(p)))
|
||||
|
||||
// rom object storage needs special handling to widen 32-bit pointer to 64-bits
|
||||
typedef union _mp_rom_obj_t { uint64_t u64; struct { const void *lo, *hi; } u32; } mp_rom_obj_t;
|
||||
typedef union _mp_rom_obj_t { uint64_t u64;
|
||||
struct { const void *lo, *hi;
|
||||
} u32;
|
||||
} mp_rom_obj_t;
|
||||
#define MP_ROM_INT(i) {MP_OBJ_NEW_SMALL_INT(i)}
|
||||
#define MP_ROM_QSTR(q) {MP_OBJ_NEW_QSTR(q)}
|
||||
#if MP_ENDIANNESS_LITTLE
|
||||
@@ -252,7 +272,7 @@ typedef union _mp_rom_obj_t { uint64_t u64; struct { const void *lo, *hi; } u32;
|
||||
|
||||
// Cast mp_obj_t to object pointer
|
||||
#ifndef MP_OBJ_TO_PTR
|
||||
#define MP_OBJ_TO_PTR(o) ((void*)o)
|
||||
#define MP_OBJ_TO_PTR(o) ((void *)o)
|
||||
#endif
|
||||
|
||||
// Cast object pointer to mp_obj_t
|
||||
@@ -309,25 +329,25 @@ typedef struct _mp_rom_obj_t { mp_const_obj_t o; } mp_rom_obj_t;
|
||||
|
||||
#define MP_DEFINE_CONST_FUN_OBJ_0(obj_name, fun_name) \
|
||||
const mp_obj_fun_builtin_fixed_t obj_name = \
|
||||
{{&mp_type_fun_builtin_0}, .fun._0 = fun_name}
|
||||
{{&mp_type_fun_builtin_0}, .fun._0 = fun_name}
|
||||
#define MP_DEFINE_CONST_FUN_OBJ_1(obj_name, fun_name) \
|
||||
const mp_obj_fun_builtin_fixed_t obj_name = \
|
||||
{{&mp_type_fun_builtin_1}, .fun._1 = fun_name}
|
||||
{{&mp_type_fun_builtin_1}, .fun._1 = fun_name}
|
||||
#define MP_DEFINE_CONST_FUN_OBJ_2(obj_name, fun_name) \
|
||||
const mp_obj_fun_builtin_fixed_t obj_name = \
|
||||
{{&mp_type_fun_builtin_2}, .fun._2 = fun_name}
|
||||
{{&mp_type_fun_builtin_2}, .fun._2 = fun_name}
|
||||
#define MP_DEFINE_CONST_FUN_OBJ_3(obj_name, fun_name) \
|
||||
const mp_obj_fun_builtin_fixed_t obj_name = \
|
||||
{{&mp_type_fun_builtin_3}, .fun._3 = fun_name}
|
||||
{{&mp_type_fun_builtin_3}, .fun._3 = fun_name}
|
||||
#define MP_DEFINE_CONST_FUN_OBJ_VAR(obj_name, n_args_min, fun_name) \
|
||||
const mp_obj_fun_builtin_var_t obj_name = \
|
||||
{{&mp_type_fun_builtin_var}, MP_OBJ_FUN_MAKE_SIG(n_args_min, MP_OBJ_FUN_ARGS_MAX, false), .fun.var = fun_name}
|
||||
{{&mp_type_fun_builtin_var}, MP_OBJ_FUN_MAKE_SIG(n_args_min, MP_OBJ_FUN_ARGS_MAX, false), .fun.var = fun_name}
|
||||
#define MP_DEFINE_CONST_FUN_OBJ_VAR_BETWEEN(obj_name, n_args_min, n_args_max, fun_name) \
|
||||
const mp_obj_fun_builtin_var_t obj_name = \
|
||||
{{&mp_type_fun_builtin_var}, MP_OBJ_FUN_MAKE_SIG(n_args_min, n_args_max, false), .fun.var = fun_name}
|
||||
{{&mp_type_fun_builtin_var}, MP_OBJ_FUN_MAKE_SIG(n_args_min, n_args_max, false), .fun.var = fun_name}
|
||||
#define MP_DEFINE_CONST_FUN_OBJ_KW(obj_name, n_args_min, fun_name) \
|
||||
const mp_obj_fun_builtin_var_t obj_name = \
|
||||
{{&mp_type_fun_builtin_var}, MP_OBJ_FUN_MAKE_SIG(n_args_min, MP_OBJ_FUN_ARGS_MAX, true), .fun.kw = fun_name}
|
||||
{{&mp_type_fun_builtin_var}, MP_OBJ_FUN_MAKE_SIG(n_args_min, MP_OBJ_FUN_ARGS_MAX, true), .fun.kw = fun_name}
|
||||
|
||||
// These macros are used to define constant map/dict objects
|
||||
// You can put "static" in front of the definition to make it local
|
||||
@@ -339,7 +359,7 @@ typedef struct _mp_rom_obj_t { mp_const_obj_t o; } mp_rom_obj_t;
|
||||
.is_ordered = 1, \
|
||||
.used = MP_ARRAY_SIZE(table_name), \
|
||||
.alloc = MP_ARRAY_SIZE(table_name), \
|
||||
.table = (mp_map_elem_t*)(mp_rom_map_elem_t*)table_name, \
|
||||
.table = (mp_map_elem_t *)(mp_rom_map_elem_t *)table_name, \
|
||||
}
|
||||
|
||||
#define MP_DEFINE_CONST_DICT(dict_name, table_name) \
|
||||
@@ -351,7 +371,7 @@ typedef struct _mp_rom_obj_t { mp_const_obj_t o; } mp_rom_obj_t;
|
||||
.is_ordered = 1, \
|
||||
.used = MP_ARRAY_SIZE(table_name), \
|
||||
.alloc = MP_ARRAY_SIZE(table_name), \
|
||||
.table = (mp_map_elem_t*)(mp_rom_map_elem_t*)table_name, \
|
||||
.table = (mp_map_elem_t *)(mp_rom_map_elem_t *)table_name, \
|
||||
}, \
|
||||
}
|
||||
|
||||
@@ -402,7 +422,9 @@ typedef enum _mp_map_lookup_kind_t {
|
||||
|
||||
extern const mp_map_t mp_const_empty_map;
|
||||
|
||||
static inline bool mp_map_slot_is_filled(const mp_map_t *map, size_t pos) { return ((map)->table[pos].key != MP_OBJ_NULL && (map)->table[pos].key != MP_OBJ_SENTINEL); }
|
||||
static inline bool mp_map_slot_is_filled(const mp_map_t *map, size_t pos) {
|
||||
return (map)->table[pos].key != MP_OBJ_NULL && (map)->table[pos].key != MP_OBJ_SENTINEL;
|
||||
}
|
||||
|
||||
void mp_map_init(mp_map_t *map, size_t n);
|
||||
void mp_map_init_fixed_table(mp_map_t *map, size_t n, const mp_obj_t *table);
|
||||
@@ -421,7 +443,9 @@ typedef struct _mp_set_t {
|
||||
mp_obj_t *table;
|
||||
} mp_set_t;
|
||||
|
||||
static inline bool mp_set_slot_is_filled(const mp_set_t *set, size_t pos) { return ((set)->table[pos] != MP_OBJ_NULL && (set)->table[pos] != MP_OBJ_SENTINEL); }
|
||||
static inline bool mp_set_slot_is_filled(const mp_set_t *set, size_t pos) {
|
||||
return (set)->table[pos] != MP_OBJ_NULL && (set)->table[pos] != MP_OBJ_SENTINEL;
|
||||
}
|
||||
|
||||
void mp_set_init(mp_set_t *set, size_t n);
|
||||
mp_obj_t mp_set_lookup(mp_set_t *set, mp_obj_t index, mp_map_lookup_kind_t lookup_kind);
|
||||
@@ -672,7 +696,7 @@ extern const struct _mp_obj_exception_t mp_const_GeneratorExit_obj;
|
||||
// check for more specific object types.
|
||||
// Note: these are kept as macros because inline functions sometimes use much
|
||||
// more code space than the equivalent macros, depending on the compiler.
|
||||
#define mp_obj_is_type(o, t) (mp_obj_is_obj(o) && (((mp_obj_base_t*)MP_OBJ_TO_PTR(o))->type == (t))) // this does not work for checking int, str or fun; use below macros for that
|
||||
#define mp_obj_is_type(o, t) (mp_obj_is_obj(o) && (((mp_obj_base_t *)MP_OBJ_TO_PTR(o))->type == (t))) // this does not work for checking int, str or fun; use below macros for that
|
||||
#if MICROPY_OBJ_IMMEDIATE_OBJS
|
||||
// bool's are immediates, not real objects, so test for the 2 possible values.
|
||||
#define mp_obj_is_bool(o) ((o) == mp_const_false || (o) == mp_const_true)
|
||||
@@ -681,21 +705,23 @@ extern const struct _mp_obj_exception_t mp_const_GeneratorExit_obj;
|
||||
#endif
|
||||
#define mp_obj_is_int(o) (mp_obj_is_small_int(o) || mp_obj_is_type(o, &mp_type_int))
|
||||
#define mp_obj_is_str(o) (mp_obj_is_qstr(o) || mp_obj_is_type(o, &mp_type_str))
|
||||
#define mp_obj_is_str_or_bytes(o) (mp_obj_is_qstr(o) || (mp_obj_is_obj(o) && ((mp_obj_base_t*)MP_OBJ_TO_PTR(o))->type->binary_op == mp_obj_str_binary_op))
|
||||
#define mp_obj_is_fun(o) (mp_obj_is_obj(o) && (((mp_obj_base_t*)MP_OBJ_TO_PTR(o))->type->name == MP_QSTR_function))
|
||||
#define mp_obj_is_str_or_bytes(o) (mp_obj_is_qstr(o) || (mp_obj_is_obj(o) && ((mp_obj_base_t *)MP_OBJ_TO_PTR(o))->type->binary_op == mp_obj_str_binary_op))
|
||||
#define mp_obj_is_fun(o) (mp_obj_is_obj(o) && (((mp_obj_base_t *)MP_OBJ_TO_PTR(o))->type->name == MP_QSTR_function))
|
||||
|
||||
mp_obj_t mp_obj_new_type(qstr name, mp_obj_t bases_tuple, mp_obj_t locals_dict);
|
||||
static inline mp_obj_t mp_obj_new_bool(mp_int_t x) { return x ? mp_const_true : mp_const_false; }
|
||||
static inline mp_obj_t mp_obj_new_bool(mp_int_t x) {
|
||||
return x ? mp_const_true : mp_const_false;
|
||||
}
|
||||
mp_obj_t mp_obj_new_cell(mp_obj_t obj);
|
||||
mp_obj_t mp_obj_new_int(mp_int_t value);
|
||||
mp_obj_t mp_obj_new_int_from_uint(mp_uint_t value);
|
||||
mp_obj_t mp_obj_new_int_from_str_len(const char **str, size_t len, bool neg, unsigned int base);
|
||||
mp_obj_t mp_obj_new_int_from_ll(long long val); // this must return a multi-precision integer object (or raise an overflow exception)
|
||||
mp_obj_t mp_obj_new_int_from_ull(unsigned long long val); // this must return a multi-precision integer object (or raise an overflow exception)
|
||||
mp_obj_t mp_obj_new_str(const char* data, size_t len);
|
||||
mp_obj_t mp_obj_new_str_via_qstr(const char* data, size_t len);
|
||||
mp_obj_t mp_obj_new_str(const char *data, size_t len);
|
||||
mp_obj_t mp_obj_new_str_via_qstr(const char *data, size_t len);
|
||||
mp_obj_t mp_obj_new_str_from_vstr(const mp_obj_type_t *type, vstr_t *vstr);
|
||||
mp_obj_t mp_obj_new_bytes(const byte* data, size_t len);
|
||||
mp_obj_t mp_obj_new_bytes(const byte *data, size_t len);
|
||||
mp_obj_t mp_obj_new_bytearray(size_t n, void *items);
|
||||
mp_obj_t mp_obj_new_bytearray_by_ref(size_t n, void *items);
|
||||
#if MICROPY_PY_BUILTINS_FLOAT
|
||||
@@ -739,7 +765,9 @@ bool mp_obj_is_callable(mp_obj_t o_in);
|
||||
mp_obj_t mp_obj_equal_not_equal(mp_binary_op_t op, mp_obj_t o1, mp_obj_t o2);
|
||||
bool mp_obj_equal(mp_obj_t o1, mp_obj_t o2);
|
||||
|
||||
static inline bool mp_obj_is_integer(mp_const_obj_t o) { return mp_obj_is_int(o) || mp_obj_is_bool(o); } // returns true if o is bool, small int or long int
|
||||
static inline bool mp_obj_is_integer(mp_const_obj_t o) {
|
||||
return mp_obj_is_int(o) || mp_obj_is_bool(o);
|
||||
} // returns true if o is bool, small int or long int
|
||||
mp_int_t mp_obj_get_int(mp_const_obj_t arg);
|
||||
mp_int_t mp_obj_get_int_truncated(mp_const_obj_t arg);
|
||||
bool mp_obj_get_int_maybe(mp_const_obj_t arg, mp_int_t *value);
|
||||
@@ -796,7 +824,9 @@ void mp_str_print_quoted(const mp_print_t *print, const byte *str_data, size_t s
|
||||
#if MICROPY_FLOAT_HIGH_QUALITY_HASH
|
||||
mp_int_t mp_float_hash(mp_float_t val);
|
||||
#else
|
||||
static inline mp_int_t mp_float_hash(mp_float_t val) { return (mp_int_t)val; }
|
||||
static inline mp_int_t mp_float_hash(mp_float_t val) {
|
||||
return (mp_int_t)val;
|
||||
}
|
||||
#endif
|
||||
mp_obj_t mp_obj_float_binary_op(mp_binary_op_t op, mp_float_t lhs_val, mp_obj_t rhs); // can return MP_OBJ_NULL if op not supported
|
||||
|
||||
@@ -831,7 +861,7 @@ mp_obj_t mp_obj_dict_get(mp_obj_t self_in, mp_obj_t index);
|
||||
mp_obj_t mp_obj_dict_store(mp_obj_t self_in, mp_obj_t key, mp_obj_t value);
|
||||
mp_obj_t mp_obj_dict_delete(mp_obj_t self_in, mp_obj_t key);
|
||||
static inline mp_map_t *mp_obj_dict_get_map(mp_obj_t dict) {
|
||||
return &((mp_obj_dict_t*)MP_OBJ_TO_PTR(dict))->map;
|
||||
return &((mp_obj_dict_t *)MP_OBJ_TO_PTR(dict))->map;
|
||||
}
|
||||
|
||||
// set
|
||||
@@ -887,7 +917,7 @@ typedef struct _mp_obj_module_t {
|
||||
mp_obj_dict_t *globals;
|
||||
} mp_obj_module_t;
|
||||
static inline mp_obj_dict_t *mp_obj_module_get_globals(mp_obj_t module) {
|
||||
return ((mp_obj_module_t*)MP_OBJ_TO_PTR(module))->globals;
|
||||
return ((mp_obj_module_t *)MP_OBJ_TO_PTR(module))->globals;
|
||||
}
|
||||
// check if given module object is a package
|
||||
bool mp_obj_is_package(mp_obj_t module);
|
||||
@@ -920,18 +950,18 @@ mp_obj_t mp_seq_index_obj(const mp_obj_t *items, size_t len, size_t n_args, cons
|
||||
mp_obj_t mp_seq_count_obj(const mp_obj_t *items, size_t len, mp_obj_t value);
|
||||
mp_obj_t mp_seq_extract_slice(size_t len, const mp_obj_t *seq, mp_bound_slice_t *indexes);
|
||||
// Helper to clear stale pointers from allocated, but unused memory, to preclude GC problems
|
||||
#define mp_seq_clear(start, len, alloc_len, item_sz) memset((byte*)(start) + (len) * (item_sz), 0, ((alloc_len) - (len)) * (item_sz))
|
||||
#define mp_seq_clear(start, len, alloc_len, item_sz) memset((byte *)(start) + (len) * (item_sz), 0, ((alloc_len) - (len)) * (item_sz))
|
||||
#define mp_seq_replace_slice_no_grow(dest, dest_len, beg, end, slice, slice_len, item_sz) \
|
||||
/*printf("memcpy(%p, %p, %d)\n", dest + beg, slice, slice_len * (item_sz));*/ \
|
||||
memcpy(((char*)dest) + (beg) * (item_sz), slice, slice_len * (item_sz)); \
|
||||
memcpy(((char *)dest) + (beg) * (item_sz), slice, slice_len * (item_sz)); \
|
||||
/*printf("memmove(%p, %p, %d)\n", dest + (beg + slice_len), dest + end, (dest_len - end) * (item_sz));*/ \
|
||||
memmove(((char*)dest) + (beg + slice_len) * (item_sz), ((char*)dest) + (end) * (item_sz), (dest_len - end) * (item_sz));
|
||||
memmove(((char *)dest) + (beg + slice_len) * (item_sz), ((char *)dest) + (end) * (item_sz), (dest_len - end) * (item_sz));
|
||||
|
||||
// Note: dest and slice regions may overlap
|
||||
#define mp_seq_replace_slice_grow_inplace(dest, dest_len, beg, end, slice, slice_len, len_adj, item_sz) \
|
||||
/*printf("memmove(%p, %p, %d)\n", dest + beg + len_adj, dest + beg, (dest_len - beg) * (item_sz));*/ \
|
||||
memmove(((char*)dest) + (beg + slice_len) * (item_sz), ((char*)dest) + (end) * (item_sz), ((dest_len) + (len_adj) - ((beg) + (slice_len))) * (item_sz)); \
|
||||
memmove(((char*)dest) + (beg) * (item_sz), slice, slice_len * (item_sz));
|
||||
memmove(((char *)dest) + (beg + slice_len) * (item_sz), ((char *)dest) + (end) * (item_sz), ((dest_len) + (len_adj) - ((beg) + (slice_len))) * (item_sz)); \
|
||||
memmove(((char *)dest) + (beg) * (item_sz), slice, slice_len * (item_sz));
|
||||
|
||||
// Provide translation for legacy API
|
||||
#define MP_OBJ_IS_SMALL_INT mp_obj_is_small_int
|
||||
|
||||
Reference in New Issue
Block a user