kopia lustrzana https://github.com/micropython/micropython
py,extmod: Some casts and minor refactors to quiet compiler warnings.
rodzic
ed52955c6b
commit
145796f037
|
@ -38,7 +38,7 @@
|
||||||
|
|
||||||
STATIC mp_obj_t time_sleep(mp_obj_t seconds_o) {
|
STATIC mp_obj_t time_sleep(mp_obj_t seconds_o) {
|
||||||
#if MICROPY_PY_BUILTINS_FLOAT
|
#if MICROPY_PY_BUILTINS_FLOAT
|
||||||
mp_hal_delay_ms(1000 * mp_obj_get_float(seconds_o));
|
mp_hal_delay_ms((mp_uint_t)(1000 * mp_obj_get_float(seconds_o)));
|
||||||
#else
|
#else
|
||||||
mp_hal_delay_ms(1000 * mp_obj_get_int(seconds_o));
|
mp_hal_delay_ms(1000 * mp_obj_get_int(seconds_o));
|
||||||
#endif
|
#endif
|
||||||
|
|
|
@ -227,10 +227,11 @@ STATIC void do_load(mp_obj_t module_obj, vstr_t *file) {
|
||||||
do_load_from_lexer(module_obj, lex);
|
do_load_from_lexer(module_obj, lex);
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
#endif
|
#else
|
||||||
|
|
||||||
// If we get here then the file was not frozen and we can't compile scripts.
|
// If we get here then the file was not frozen and we can't compile scripts.
|
||||||
mp_raise_msg(&mp_type_ImportError, "script compilation not supported");
|
mp_raise_msg(&mp_type_ImportError, "script compilation not supported");
|
||||||
|
#endif
|
||||||
}
|
}
|
||||||
|
|
||||||
STATIC void chop_component(const char *start, const char **end) {
|
STATIC void chop_component(const char *start, const char **end) {
|
||||||
|
|
|
@ -902,7 +902,7 @@ void mp_emit_bc_make_closure(emit_t *emit, scope_t *scope, mp_uint_t n_closed_ov
|
||||||
emit_write_bytecode_byte(emit, n_closed_over);
|
emit_write_bytecode_byte(emit, n_closed_over);
|
||||||
} else {
|
} else {
|
||||||
assert(n_closed_over <= 255);
|
assert(n_closed_over <= 255);
|
||||||
emit_bc_pre(emit, -2 - n_closed_over + 1);
|
emit_bc_pre(emit, -2 - (mp_int_t)n_closed_over + 1);
|
||||||
emit_write_bytecode_byte_raw_code(emit, MP_BC_MAKE_CLOSURE_DEFARGS, scope->raw_code);
|
emit_write_bytecode_byte_raw_code(emit, MP_BC_MAKE_CLOSURE_DEFARGS, scope->raw_code);
|
||||||
emit_write_bytecode_byte(emit, n_closed_over);
|
emit_write_bytecode_byte(emit, n_closed_over);
|
||||||
}
|
}
|
||||||
|
|
|
@ -332,7 +332,7 @@ int mp_format_float(FPTYPE f, char *buf, size_t buf_size, char fmt, int prec, ch
|
||||||
|
|
||||||
// Print the digits of the mantissa
|
// Print the digits of the mantissa
|
||||||
for (int i = 0; i < num_digits; ++i, --dec) {
|
for (int i = 0; i < num_digits; ++i, --dec) {
|
||||||
int32_t d = f;
|
int32_t d = (int32_t)f;
|
||||||
*s++ = '0' + d;
|
*s++ = '0' + d;
|
||||||
if (dec == 0 && prec > 0) {
|
if (dec == 0 && prec > 0) {
|
||||||
*s++ = '.';
|
*s++ = '.';
|
||||||
|
|
|
@ -672,7 +672,7 @@ mp_lexer_t *mp_lexer_new(qstr src_name, mp_reader_t reader) {
|
||||||
lex->source_name = src_name;
|
lex->source_name = src_name;
|
||||||
lex->reader = reader;
|
lex->reader = reader;
|
||||||
lex->line = 1;
|
lex->line = 1;
|
||||||
lex->column = -2; // account for 3 dummy bytes
|
lex->column = (size_t)-2; // account for 3 dummy bytes
|
||||||
lex->emit_dent = 0;
|
lex->emit_dent = 0;
|
||||||
lex->nested_bracket_level = 0;
|
lex->nested_bracket_level = 0;
|
||||||
lex->alloc_indent_level = MICROPY_ALLOC_LEXER_INDENT_INIT;
|
lex->alloc_indent_level = MICROPY_ALLOC_LEXER_INDENT_INIT;
|
||||||
|
|
|
@ -91,10 +91,8 @@ STATIC mp_obj_t mp_builtin___build_class__(size_t n_args, const mp_obj_t *args)
|
||||||
MP_DEFINE_CONST_FUN_OBJ_VAR(mp_builtin___build_class___obj, 2, mp_builtin___build_class__);
|
MP_DEFINE_CONST_FUN_OBJ_VAR(mp_builtin___build_class___obj, 2, mp_builtin___build_class__);
|
||||||
|
|
||||||
STATIC mp_obj_t mp_builtin_abs(mp_obj_t o_in) {
|
STATIC mp_obj_t mp_builtin_abs(mp_obj_t o_in) {
|
||||||
if (0) {
|
#if MICROPY_PY_BUILTINS_FLOAT
|
||||||
// dummy
|
if (mp_obj_is_float(o_in)) {
|
||||||
#if MICROPY_PY_BUILTINS_FLOAT
|
|
||||||
} else if (mp_obj_is_float(o_in)) {
|
|
||||||
mp_float_t value = mp_obj_float_get(o_in);
|
mp_float_t value = mp_obj_float_get(o_in);
|
||||||
// TODO check for NaN etc
|
// TODO check for NaN etc
|
||||||
if (value < 0) {
|
if (value < 0) {
|
||||||
|
@ -102,17 +100,17 @@ STATIC mp_obj_t mp_builtin_abs(mp_obj_t o_in) {
|
||||||
} else {
|
} else {
|
||||||
return o_in;
|
return o_in;
|
||||||
}
|
}
|
||||||
#if MICROPY_PY_BUILTINS_COMPLEX
|
#if MICROPY_PY_BUILTINS_COMPLEX
|
||||||
} else if (MP_OBJ_IS_TYPE(o_in, &mp_type_complex)) {
|
} else if (MP_OBJ_IS_TYPE(o_in, &mp_type_complex)) {
|
||||||
mp_float_t real, imag;
|
mp_float_t real, imag;
|
||||||
mp_obj_complex_get(o_in, &real, &imag);
|
mp_obj_complex_get(o_in, &real, &imag);
|
||||||
return mp_obj_new_float(MICROPY_FLOAT_C_FUN(sqrt)(real*real + imag*imag));
|
return mp_obj_new_float(MICROPY_FLOAT_C_FUN(sqrt)(real*real + imag*imag));
|
||||||
#endif
|
#endif
|
||||||
#endif
|
|
||||||
} else {
|
|
||||||
// this will raise a TypeError if the argument is not integral
|
|
||||||
return mp_obj_int_abs(o_in);
|
|
||||||
}
|
}
|
||||||
|
#endif
|
||||||
|
|
||||||
|
// this will raise a TypeError if the argument is not integral
|
||||||
|
return mp_obj_int_abs(o_in);
|
||||||
}
|
}
|
||||||
MP_DEFINE_CONST_FUN_OBJ_1(mp_builtin_abs_obj, mp_builtin_abs);
|
MP_DEFINE_CONST_FUN_OBJ_1(mp_builtin_abs_obj, mp_builtin_abs);
|
||||||
|
|
||||||
|
|
|
@ -106,7 +106,7 @@ STATIC mp_fp_as_int_class_t mp_classify_fp_as_int(mp_float_t val) {
|
||||||
#define MP_FLOAT_SIGN_SHIFT_I32 ((MP_FLOAT_FRAC_BITS + MP_FLOAT_EXP_BITS) % 32)
|
#define MP_FLOAT_SIGN_SHIFT_I32 ((MP_FLOAT_FRAC_BITS + MP_FLOAT_EXP_BITS) % 32)
|
||||||
#define MP_FLOAT_EXP_SHIFT_I32 (MP_FLOAT_FRAC_BITS % 32)
|
#define MP_FLOAT_EXP_SHIFT_I32 (MP_FLOAT_FRAC_BITS % 32)
|
||||||
|
|
||||||
if (e & (1 << MP_FLOAT_SIGN_SHIFT_I32)) {
|
if (e & (1U << MP_FLOAT_SIGN_SHIFT_I32)) {
|
||||||
#if MICROPY_FLOAT_IMPL == MICROPY_FLOAT_IMPL_DOUBLE
|
#if MICROPY_FLOAT_IMPL == MICROPY_FLOAT_IMPL_DOUBLE
|
||||||
e |= u.i[MP_ENDIANNESS_BIG] != 0;
|
e |= u.i[MP_ENDIANNESS_BIG] != 0;
|
||||||
#endif
|
#endif
|
||||||
|
|
11
py/runtime.c
11
py/runtime.c
|
@ -1410,16 +1410,13 @@ mp_obj_t mp_parse_compile_execute(mp_lexer_t *lex, mp_parse_input_kind_t parse_i
|
||||||
|
|
||||||
NORETURN void *m_malloc_fail(size_t num_bytes) {
|
NORETURN void *m_malloc_fail(size_t num_bytes) {
|
||||||
DEBUG_printf("memory allocation failed, allocating %u bytes\n", (uint)num_bytes);
|
DEBUG_printf("memory allocation failed, allocating %u bytes\n", (uint)num_bytes);
|
||||||
if (0) {
|
|
||||||
// dummy
|
|
||||||
#if MICROPY_ENABLE_GC
|
#if MICROPY_ENABLE_GC
|
||||||
} else if (gc_is_locked()) {
|
if (gc_is_locked()) {
|
||||||
mp_raise_msg(&mp_type_MemoryError, "memory allocation failed, heap is locked");
|
mp_raise_msg(&mp_type_MemoryError, "memory allocation failed, heap is locked");
|
||||||
#endif
|
|
||||||
} else {
|
|
||||||
nlr_raise(mp_obj_new_exception_msg_varg(&mp_type_MemoryError,
|
|
||||||
"memory allocation failed, allocating %u bytes", (uint)num_bytes));
|
|
||||||
}
|
}
|
||||||
|
#endif
|
||||||
|
nlr_raise(mp_obj_new_exception_msg_varg(&mp_type_MemoryError,
|
||||||
|
"memory allocation failed, allocating %u bytes", (uint)num_bytes));
|
||||||
}
|
}
|
||||||
|
|
||||||
NORETURN void mp_raise_msg(const mp_obj_type_t *exc_type, const char *msg) {
|
NORETURN void mp_raise_msg(const mp_obj_type_t *exc_type, const char *msg) {
|
||||||
|
|
|
@ -34,7 +34,7 @@
|
||||||
#include "py/mpprint.h"
|
#include "py/mpprint.h"
|
||||||
|
|
||||||
// returned value is always at least 1 greater than argument
|
// returned value is always at least 1 greater than argument
|
||||||
#define ROUND_ALLOC(a) (((a) & ((~0) - 7)) + 8)
|
#define ROUND_ALLOC(a) (((a) & ((~0U) - 7)) + 8)
|
||||||
|
|
||||||
// Init the vstr so it allocs exactly given number of bytes. Set length to zero.
|
// Init the vstr so it allocs exactly given number of bytes. Set length to zero.
|
||||||
void vstr_init(vstr_t *vstr, size_t alloc) {
|
void vstr_init(vstr_t *vstr, size_t alloc) {
|
||||||
|
|
Ładowanie…
Reference in New Issue