mirror of
https://github.com/UpsilonNumworks/Upsilon.git
synced 2026-01-20 01:08:15 +01:00
[python] Upgrade to micropython 1.11
This commit is contained in:
@@ -38,9 +38,9 @@
|
||||
#include "py/stream.h" // for mp_obj_print
|
||||
|
||||
mp_obj_type_t *mp_obj_get_type(mp_const_obj_t o_in) {
|
||||
if (MP_OBJ_IS_SMALL_INT(o_in)) {
|
||||
if (mp_obj_is_small_int(o_in)) {
|
||||
return (mp_obj_type_t*)&mp_type_int;
|
||||
} else if (MP_OBJ_IS_QSTR(o_in)) {
|
||||
} else if (mp_obj_is_qstr(o_in)) {
|
||||
return (mp_obj_type_t*)&mp_type_str;
|
||||
#if MICROPY_PY_BUILTINS_FLOAT
|
||||
} else if (mp_obj_is_float(o_in)) {
|
||||
@@ -112,7 +112,7 @@ bool mp_obj_is_true(mp_obj_t arg) {
|
||||
return 1;
|
||||
} else if (arg == mp_const_none) {
|
||||
return 0;
|
||||
} else if (MP_OBJ_IS_SMALL_INT(arg)) {
|
||||
} else if (mp_obj_is_small_int(arg)) {
|
||||
if (MP_OBJ_SMALL_INT_VALUE(arg) == 0) {
|
||||
return 0;
|
||||
} else {
|
||||
@@ -167,7 +167,7 @@ bool mp_obj_equal(mp_obj_t o1, mp_obj_t o2) {
|
||||
&& !mp_obj_is_float(o1)
|
||||
#endif
|
||||
#if MICROPY_PY_BUILTINS_COMPLEX
|
||||
&& !MP_OBJ_IS_TYPE(o1, &mp_type_complex)
|
||||
&& !mp_obj_is_type(o1, &mp_type_complex)
|
||||
#endif
|
||||
) {
|
||||
return true;
|
||||
@@ -177,8 +177,8 @@ bool mp_obj_equal(mp_obj_t o1, mp_obj_t o2) {
|
||||
}
|
||||
|
||||
// fast path for small ints
|
||||
if (MP_OBJ_IS_SMALL_INT(o1)) {
|
||||
if (MP_OBJ_IS_SMALL_INT(o2)) {
|
||||
if (mp_obj_is_small_int(o1)) {
|
||||
if (mp_obj_is_small_int(o2)) {
|
||||
// both SMALL_INT, and not equal if we get here
|
||||
return false;
|
||||
} else {
|
||||
@@ -189,20 +189,20 @@ bool mp_obj_equal(mp_obj_t o1, mp_obj_t o2) {
|
||||
}
|
||||
|
||||
// fast path for strings
|
||||
if (MP_OBJ_IS_STR(o1)) {
|
||||
if (MP_OBJ_IS_STR(o2)) {
|
||||
if (mp_obj_is_str(o1)) {
|
||||
if (mp_obj_is_str(o2)) {
|
||||
// both strings, use special function
|
||||
return mp_obj_str_equal(o1, o2);
|
||||
} else {
|
||||
// a string is never equal to anything else
|
||||
goto str_cmp_err;
|
||||
}
|
||||
} else if (MP_OBJ_IS_STR(o2)) {
|
||||
} else if (mp_obj_is_str(o2)) {
|
||||
// o1 is not a string (else caught above), so the objects are not equal
|
||||
str_cmp_err:
|
||||
#if MICROPY_PY_STR_BYTES_CMP_WARN
|
||||
if (MP_OBJ_IS_TYPE(o1, &mp_type_bytes) || MP_OBJ_IS_TYPE(o2, &mp_type_bytes)) {
|
||||
mp_warning("Comparison between bytes and str");
|
||||
if (mp_obj_is_type(o1, &mp_type_bytes) || mp_obj_is_type(o2, &mp_type_bytes)) {
|
||||
mp_warning(MP_WARN_CAT(BytesWarning), "Comparison between bytes and str");
|
||||
}
|
||||
#endif
|
||||
return false;
|
||||
@@ -230,22 +230,18 @@ mp_int_t mp_obj_get_int(mp_const_obj_t arg) {
|
||||
return 0;
|
||||
} else if (arg == mp_const_true) {
|
||||
return 1;
|
||||
} else if (MP_OBJ_IS_SMALL_INT(arg)) {
|
||||
} else if (mp_obj_is_small_int(arg)) {
|
||||
return MP_OBJ_SMALL_INT_VALUE(arg);
|
||||
} else if (MP_OBJ_IS_TYPE(arg, &mp_type_int)) {
|
||||
} else if (mp_obj_is_type(arg, &mp_type_int)) {
|
||||
return mp_obj_int_get_checked(arg);
|
||||
} else {
|
||||
if (MICROPY_ERROR_REPORTING == MICROPY_ERROR_REPORTING_TERSE) {
|
||||
mp_raise_TypeError("can't convert to int");
|
||||
} else {
|
||||
nlr_raise(mp_obj_new_exception_msg_varg(&mp_type_TypeError,
|
||||
"can't convert %s to int", mp_obj_get_type_str(arg)));
|
||||
}
|
||||
mp_obj_t res = mp_unary_op(MP_UNARY_OP_INT, (mp_obj_t)arg);
|
||||
return mp_obj_int_get_checked(res);
|
||||
}
|
||||
}
|
||||
|
||||
mp_int_t mp_obj_get_int_truncated(mp_const_obj_t arg) {
|
||||
if (MP_OBJ_IS_INT(arg)) {
|
||||
if (mp_obj_is_int(arg)) {
|
||||
return mp_obj_int_get_truncated(arg);
|
||||
} else {
|
||||
return mp_obj_get_int(arg);
|
||||
@@ -260,9 +256,9 @@ bool mp_obj_get_int_maybe(mp_const_obj_t arg, mp_int_t *value) {
|
||||
*value = 0;
|
||||
} else if (arg == mp_const_true) {
|
||||
*value = 1;
|
||||
} else if (MP_OBJ_IS_SMALL_INT(arg)) {
|
||||
} else if (mp_obj_is_small_int(arg)) {
|
||||
*value = MP_OBJ_SMALL_INT_VALUE(arg);
|
||||
} else if (MP_OBJ_IS_TYPE(arg, &mp_type_int)) {
|
||||
} else if (mp_obj_is_type(arg, &mp_type_int)) {
|
||||
*value = mp_obj_int_get_checked(arg);
|
||||
} else {
|
||||
return false;
|
||||
@@ -278,10 +274,10 @@ bool mp_obj_get_float_maybe(mp_obj_t arg, mp_float_t *value) {
|
||||
val = 0;
|
||||
} else if (arg == mp_const_true) {
|
||||
val = 1;
|
||||
} else if (MP_OBJ_IS_SMALL_INT(arg)) {
|
||||
} else if (mp_obj_is_small_int(arg)) {
|
||||
val = MP_OBJ_SMALL_INT_VALUE(arg);
|
||||
#if MICROPY_LONGINT_IMPL != MICROPY_LONGINT_IMPL_NONE
|
||||
} else if (MP_OBJ_IS_TYPE(arg, &mp_type_int)) {
|
||||
} else if (mp_obj_is_type(arg, &mp_type_int)) {
|
||||
val = mp_obj_int_as_float_impl(arg);
|
||||
#endif
|
||||
} else if (mp_obj_is_float(arg)) {
|
||||
@@ -317,18 +313,18 @@ void mp_obj_get_complex(mp_obj_t arg, mp_float_t *real, mp_float_t *imag) {
|
||||
} else if (arg == mp_const_true) {
|
||||
*real = 1;
|
||||
*imag = 0;
|
||||
} else if (MP_OBJ_IS_SMALL_INT(arg)) {
|
||||
} else if (mp_obj_is_small_int(arg)) {
|
||||
*real = MP_OBJ_SMALL_INT_VALUE(arg);
|
||||
*imag = 0;
|
||||
#if MICROPY_LONGINT_IMPL != MICROPY_LONGINT_IMPL_NONE
|
||||
} else if (MP_OBJ_IS_TYPE(arg, &mp_type_int)) {
|
||||
} else if (mp_obj_is_type(arg, &mp_type_int)) {
|
||||
*real = mp_obj_int_as_float_impl(arg);
|
||||
*imag = 0;
|
||||
#endif
|
||||
} else if (mp_obj_is_float(arg)) {
|
||||
*real = mp_obj_float_get(arg);
|
||||
*imag = 0;
|
||||
} else if (MP_OBJ_IS_TYPE(arg, &mp_type_complex)) {
|
||||
} else if (mp_obj_is_type(arg, &mp_type_complex)) {
|
||||
mp_obj_complex_get(arg, real, imag);
|
||||
} else {
|
||||
if (MICROPY_ERROR_REPORTING == MICROPY_ERROR_REPORTING_TERSE) {
|
||||
@@ -344,16 +340,16 @@ void mp_obj_get_complex(mp_obj_t arg, mp_float_t *real, mp_float_t *imag) {
|
||||
|
||||
// note: returned value in *items may point to the interior of a GC block
|
||||
void mp_obj_get_array(mp_obj_t o, size_t *len, mp_obj_t **items) {
|
||||
if (MP_OBJ_IS_TYPE(o, &mp_type_tuple)) {
|
||||
if (mp_obj_is_type(o, &mp_type_tuple)) {
|
||||
mp_obj_tuple_get(o, len, items);
|
||||
} else if (MP_OBJ_IS_TYPE(o, &mp_type_list)) {
|
||||
} else if (mp_obj_is_type(o, &mp_type_list)) {
|
||||
mp_obj_list_get(o, len, items);
|
||||
} else {
|
||||
if (MICROPY_ERROR_REPORTING == MICROPY_ERROR_REPORTING_TERSE) {
|
||||
mp_raise_TypeError("expected tuple/list");
|
||||
} else {
|
||||
nlr_raise(mp_obj_new_exception_msg_varg(&mp_type_TypeError,
|
||||
"object '%s' is not a tuple or list", mp_obj_get_type_str(o)));
|
||||
"object '%s' isn't a tuple or list", mp_obj_get_type_str(o)));
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -375,7 +371,7 @@ void mp_obj_get_array_fixed_n(mp_obj_t o, size_t len, mp_obj_t **items) {
|
||||
// is_slice determines whether the index is a slice index
|
||||
size_t mp_get_index(const mp_obj_type_t *type, size_t len, mp_obj_t index, bool is_slice) {
|
||||
mp_int_t i;
|
||||
if (MP_OBJ_IS_SMALL_INT(index)) {
|
||||
if (mp_obj_is_small_int(index)) {
|
||||
i = MP_OBJ_SMALL_INT_VALUE(index);
|
||||
} else if (!mp_obj_get_int_maybe(index, &i)) {
|
||||
if (MICROPY_ERROR_REPORTING == MICROPY_ERROR_REPORTING_TERSE) {
|
||||
@@ -413,7 +409,7 @@ size_t mp_get_index(const mp_obj_type_t *type, size_t len, mp_obj_t index, bool
|
||||
|
||||
mp_obj_t mp_obj_id(mp_obj_t o_in) {
|
||||
mp_int_t id = (mp_int_t)o_in;
|
||||
if (!MP_OBJ_IS_OBJ(o_in)) {
|
||||
if (!mp_obj_is_obj(o_in)) {
|
||||
return mp_obj_new_int(id);
|
||||
} else if (id >= 0) {
|
||||
// Many OSes and CPUs have affinity for putting "user" memories
|
||||
@@ -449,9 +445,9 @@ mp_obj_t mp_obj_len_maybe(mp_obj_t o_in) {
|
||||
if (
|
||||
#if !MICROPY_PY_BUILTINS_STR_UNICODE
|
||||
// It's simple - unicode is slow, non-unicode is fast
|
||||
MP_OBJ_IS_STR(o_in) ||
|
||||
mp_obj_is_str(o_in) ||
|
||||
#endif
|
||||
MP_OBJ_IS_TYPE(o_in, &mp_type_bytes)) {
|
||||
mp_obj_is_type(o_in, &mp_type_bytes)) {
|
||||
GET_STR_LEN(o_in, l);
|
||||
return MP_OBJ_NEW_SMALL_INT(l);
|
||||
} else {
|
||||
@@ -475,24 +471,24 @@ mp_obj_t mp_obj_subscr(mp_obj_t base, mp_obj_t index, mp_obj_t value) {
|
||||
}
|
||||
if (value == MP_OBJ_NULL) {
|
||||
if (MICROPY_ERROR_REPORTING == MICROPY_ERROR_REPORTING_TERSE) {
|
||||
mp_raise_TypeError("object does not support item deletion");
|
||||
mp_raise_TypeError("object doesn't support item deletion");
|
||||
} else {
|
||||
nlr_raise(mp_obj_new_exception_msg_varg(&mp_type_TypeError,
|
||||
"'%s' object does not support item deletion", mp_obj_get_type_str(base)));
|
||||
"'%s' object doesn't support item deletion", mp_obj_get_type_str(base)));
|
||||
}
|
||||
} else if (value == MP_OBJ_SENTINEL) {
|
||||
if (MICROPY_ERROR_REPORTING == MICROPY_ERROR_REPORTING_TERSE) {
|
||||
mp_raise_TypeError("object is not subscriptable");
|
||||
mp_raise_TypeError("object isn't subscriptable");
|
||||
} else {
|
||||
nlr_raise(mp_obj_new_exception_msg_varg(&mp_type_TypeError,
|
||||
"'%s' object is not subscriptable", mp_obj_get_type_str(base)));
|
||||
"'%s' object isn't subscriptable", mp_obj_get_type_str(base)));
|
||||
}
|
||||
} else {
|
||||
if (MICROPY_ERROR_REPORTING == MICROPY_ERROR_REPORTING_TERSE) {
|
||||
mp_raise_TypeError("object does not support item assignment");
|
||||
mp_raise_TypeError("object doesn't support item assignment");
|
||||
} else {
|
||||
nlr_raise(mp_obj_new_exception_msg_varg(&mp_type_TypeError,
|
||||
"'%s' object does not support item assignment", mp_obj_get_type_str(base)));
|
||||
"'%s' object doesn't support item assignment", mp_obj_get_type_str(base)));
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user