mirror of
https://github.com/UpsilonNumworks/Upsilon.git
synced 2026-01-19 08:47:28 +01:00
Update MicroPython from 1.12 to 1.17
This commit is contained in:
@@ -40,7 +40,7 @@ STATIC NORETURN void raise_exc(mp_obj_t exc, mp_lexer_t *lex) {
|
||||
// if lex!=NULL then the parser called us and we need to convert the
|
||||
// exception's type from ValueError to SyntaxError and add traceback info
|
||||
if (lex != NULL) {
|
||||
((mp_obj_base_t*)MP_OBJ_TO_PTR(exc))->type = &mp_type_SyntaxError;
|
||||
((mp_obj_base_t *)MP_OBJ_TO_PTR(exc))->type = &mp_type_SyntaxError;
|
||||
mp_obj_exception_add_traceback(exc, lex->source_name, lex->tok_line, MP_QSTRnull);
|
||||
}
|
||||
nlr_raise(exc);
|
||||
@@ -55,7 +55,7 @@ mp_obj_t mp_parse_num_integer(const char *restrict str_, size_t len, int base, m
|
||||
// check radix base
|
||||
if ((base != 0 && base < 2) || base > 36) {
|
||||
// this won't be reached if lex!=NULL
|
||||
mp_raise_ValueError("int() arg 2 must be >= 2 and <= 36");
|
||||
mp_raise_ValueError(MP_ERROR_TEXT("int() arg 2 must be >= 2 and <= 36"));
|
||||
}
|
||||
|
||||
// skip leading space
|
||||
@@ -73,7 +73,7 @@ mp_obj_t mp_parse_num_integer(const char *restrict str_, size_t len, int base, m
|
||||
}
|
||||
|
||||
// parse optional base prefix
|
||||
str += mp_parse_num_base((const char*)str, top - str, &base);
|
||||
str += mp_parse_num_base((const char *)str, top - str, &base);
|
||||
|
||||
// string should be an integer number
|
||||
mp_int_t int_val = 0;
|
||||
@@ -137,22 +137,23 @@ have_ret_val:
|
||||
overflow:
|
||||
// reparse using long int
|
||||
{
|
||||
const char *s2 = (const char*)str_val_start;
|
||||
const char *s2 = (const char *)str_val_start;
|
||||
ret_val = mp_obj_new_int_from_str_len(&s2, top - str_val_start, neg, base);
|
||||
str = (const byte*)s2;
|
||||
str = (const byte *)s2;
|
||||
goto have_ret_val;
|
||||
}
|
||||
|
||||
value_error:
|
||||
if (MICROPY_ERROR_REPORTING == MICROPY_ERROR_REPORTING_TERSE) {
|
||||
{
|
||||
#if MICROPY_ERROR_REPORTING <= MICROPY_ERROR_REPORTING_TERSE
|
||||
mp_obj_t exc = mp_obj_new_exception_msg(&mp_type_ValueError,
|
||||
"invalid syntax for integer");
|
||||
MP_ERROR_TEXT("invalid syntax for integer"));
|
||||
raise_exc(exc, lex);
|
||||
} else if (MICROPY_ERROR_REPORTING == MICROPY_ERROR_REPORTING_NORMAL) {
|
||||
#elif MICROPY_ERROR_REPORTING == MICROPY_ERROR_REPORTING_NORMAL
|
||||
mp_obj_t exc = mp_obj_new_exception_msg_varg(&mp_type_ValueError,
|
||||
"invalid syntax for integer with base %d", base);
|
||||
MP_ERROR_TEXT("invalid syntax for integer with base %d"), base);
|
||||
raise_exc(exc, lex);
|
||||
} else {
|
||||
#else
|
||||
vstr_t vstr;
|
||||
mp_print_t print;
|
||||
vstr_init_print(&vstr, 50, &print);
|
||||
@@ -161,6 +162,7 @@ value_error:
|
||||
mp_obj_t exc = mp_obj_new_exception_arg1(&mp_type_ValueError,
|
||||
mp_obj_new_str_from_vstr(&mp_type_str, &vstr));
|
||||
raise_exc(exc, lex);
|
||||
#endif
|
||||
}
|
||||
}
|
||||
|
||||
@@ -171,7 +173,7 @@ typedef enum {
|
||||
} parse_dec_in_t;
|
||||
|
||||
mp_obj_t mp_parse_num_decimal(const char *str, size_t len, bool allow_imag, bool force_complex, mp_lexer_t *lex) {
|
||||
#if MICROPY_PY_BUILTINS_FLOAT
|
||||
#if MICROPY_PY_BUILTINS_FLOAT
|
||||
|
||||
// DEC_VAL_MAX only needs to be rough and is used to retain precision while not overflowing
|
||||
// SMALL_NORMAL_VAL is the smallest power of 10 that is still a normal float
|
||||
@@ -179,17 +181,17 @@ mp_obj_t mp_parse_num_decimal(const char *str, size_t len, bool allow_imag, bool
|
||||
// Note: EXACT_POWER_OF_10 is at least floor(log_5(2^mantissa_length)). Indeed, 10^n = 2^n * 5^n
|
||||
// so we only have to store the 5^n part in the mantissa (the 2^n part will go into the float's
|
||||
// exponent).
|
||||
#if MICROPY_FLOAT_IMPL == MICROPY_FLOAT_IMPL_FLOAT
|
||||
#if MICROPY_FLOAT_IMPL == MICROPY_FLOAT_IMPL_FLOAT
|
||||
#define DEC_VAL_MAX 1e20F
|
||||
#define SMALL_NORMAL_VAL (1e-37F)
|
||||
#define SMALL_NORMAL_EXP (-37)
|
||||
#define EXACT_POWER_OF_10 (9)
|
||||
#elif MICROPY_FLOAT_IMPL == MICROPY_FLOAT_IMPL_DOUBLE
|
||||
#elif MICROPY_FLOAT_IMPL == MICROPY_FLOAT_IMPL_DOUBLE
|
||||
#define DEC_VAL_MAX 1e200
|
||||
#define SMALL_NORMAL_VAL (1e-307)
|
||||
#define SMALL_NORMAL_EXP (-307)
|
||||
#define EXACT_POWER_OF_10 (22)
|
||||
#endif
|
||||
#endif
|
||||
|
||||
const char *top = str + len;
|
||||
mp_float_t dec_val = 0;
|
||||
@@ -218,7 +220,7 @@ mp_obj_t mp_parse_num_decimal(const char *str, size_t len, bool allow_imag, bool
|
||||
if (str + 2 < top && (str[1] | 0x20) == 'n' && (str[2] | 0x20) == 'f') {
|
||||
// inf
|
||||
str += 3;
|
||||
dec_val = INFINITY;
|
||||
dec_val = (mp_float_t)INFINITY;
|
||||
if (str + 4 < top && (str[0] | 0x20) == 'i' && (str[1] | 0x20) == 'n' && (str[2] | 0x20) == 'i' && (str[3] | 0x20) == 't' && (str[4] | 0x20) == 'y') {
|
||||
// infinity
|
||||
str += 5;
|
||||
@@ -334,25 +336,25 @@ mp_obj_t mp_parse_num_decimal(const char *str, size_t len, bool allow_imag, bool
|
||||
}
|
||||
|
||||
// return the object
|
||||
#if MICROPY_PY_BUILTINS_COMPLEX
|
||||
#if MICROPY_PY_BUILTINS_COMPLEX
|
||||
if (imag) {
|
||||
return mp_obj_new_complex(0, dec_val);
|
||||
} else if (force_complex) {
|
||||
return mp_obj_new_complex(dec_val, 0);
|
||||
}
|
||||
#else
|
||||
#else
|
||||
if (imag || force_complex) {
|
||||
raise_exc(mp_obj_new_exception_msg(&mp_type_ValueError, "complex values not supported"), lex);
|
||||
raise_exc(mp_obj_new_exception_msg(&mp_type_ValueError, MP_ERROR_TEXT("complex values not supported")), lex);
|
||||
}
|
||||
#endif
|
||||
#endif
|
||||
else {
|
||||
return mp_obj_new_float(dec_val);
|
||||
}
|
||||
|
||||
value_error:
|
||||
raise_exc(mp_obj_new_exception_msg(&mp_type_ValueError, "invalid syntax for number"), lex);
|
||||
raise_exc(mp_obj_new_exception_msg(&mp_type_ValueError, MP_ERROR_TEXT("invalid syntax for number")), lex);
|
||||
|
||||
#else
|
||||
raise_exc(mp_obj_new_exception_msg(&mp_type_ValueError, "decimal numbers not supported"), lex);
|
||||
#endif
|
||||
#else
|
||||
raise_exc(mp_obj_new_exception_msg(&mp_type_ValueError, MP_ERROR_TEXT("decimal numbers not supported")), lex);
|
||||
#endif
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user