Update MicroPython from 1.12 to 1.17

This commit is contained in:
Yaya.Cout
2021-12-14 18:16:49 +01:00
parent 5cbce3c116
commit 38faecda29
162 changed files with 8326 additions and 3888 deletions

View File

@@ -39,85 +39,27 @@ void mp_seq_multiply(const void *items, size_t item_sz, size_t len, size_t times
for (size_t i = 0; i < times; i++) {
size_t copy_sz = item_sz * len;
memcpy(dest, items, copy_sz);
dest = (char*)dest + copy_sz;
dest = (char *)dest + copy_sz;
}
}
#if MICROPY_PY_BUILTINS_SLICE
bool mp_seq_get_fast_slice_indexes(mp_uint_t len, mp_obj_t slice, mp_bound_slice_t *indexes) {
mp_obj_t ostart, ostop, ostep;
mp_int_t start, stop;
mp_obj_slice_get(slice, &ostart, &ostop, &ostep);
mp_obj_slice_indices(slice, len, indexes);
if (ostep != mp_const_none && ostep != MP_OBJ_NEW_SMALL_INT(1)) {
indexes->step = mp_obj_get_int(ostep);
if (indexes->step == 0) {
mp_raise_ValueError("slice step cannot be zero");
}
} else {
indexes->step = 1;
}
if (ostart == mp_const_none) {
if (indexes->step > 0) {
start = 0;
} else {
start = len - 1;
}
} else {
start = mp_obj_get_int(ostart);
}
if (ostop == mp_const_none) {
if (indexes->step > 0) {
stop = len;
} else {
stop = 0;
}
} else {
stop = mp_obj_get_int(ostop);
if (stop >= 0 && indexes->step < 0) {
stop += 1;
}
}
// Unlike subscription, out-of-bounds slice indexes are never error
if (start < 0) {
start = len + start;
if (start < 0) {
if (indexes->step < 0) {
start = -1;
} else {
start = 0;
}
}
} else if (indexes->step > 0 && (mp_uint_t)start > len) {
start = len;
} else if (indexes->step < 0 && (mp_uint_t)start >= len) {
start = len - 1;
}
if (stop < 0) {
stop = len + stop;
if (stop < 0) {
stop = -1;
}
if (indexes->step < 0) {
stop += 1;
}
} else if ((mp_uint_t)stop > len) {
stop = len;
// If the index is negative then stop points to the last item, not after it
if (indexes->step < 0) {
indexes->stop++;
}
// CPython returns empty sequence in such case, or point for assignment is at start
if (indexes->step > 0 && start > stop) {
stop = start;
} else if (indexes->step < 0 && start < stop) {
stop = start + 1;
if (indexes->step > 0 && indexes->start > indexes->stop) {
indexes->stop = indexes->start;
} else if (indexes->step < 0 && indexes->start < indexes->stop) {
indexes->stop = indexes->start + 1;
}
indexes->start = start;
indexes->stop = stop;
return indexes->step == 1;
}
@@ -154,7 +96,7 @@ bool mp_seq_cmp_bytes(mp_uint_t op, const byte *data1, size_t len1, const byte *
// Let's deal only with > & >=
if (op == MP_BINARY_OP_LESS || op == MP_BINARY_OP_LESS_EQUAL) {
SWAP(const byte*, data1, data2);
SWAP(const byte *, data1, data2);
SWAP(size_t, len1, len2);
if (op == MP_BINARY_OP_LESS) {
op = MP_BINARY_OP_MORE;
@@ -221,7 +163,7 @@ bool mp_seq_cmp_objs(mp_uint_t op, const mp_obj_t *items1, size_t len1, const mp
}
// Otherwise, application of relation op gives the answer
return (mp_binary_op(op, items1[i], items2[i]) == mp_const_true);
return mp_binary_op(op, items1[i], items2[i]) == mp_const_true;
}
// If we had tie in the last element...
@@ -241,7 +183,7 @@ bool mp_seq_cmp_objs(mp_uint_t op, const mp_obj_t *items1, size_t len1, const mp
// Special-case of index() which searches for mp_obj_t
mp_obj_t mp_seq_index_obj(const mp_obj_t *items, size_t len, size_t n_args, const mp_obj_t *args) {
mp_obj_type_t *type = mp_obj_get_type(args[0]);
const mp_obj_type_t *type = mp_obj_get_type(args[0]);
mp_obj_t value = args[1];
size_t start = 0;
size_t stop = len;
@@ -260,15 +202,15 @@ mp_obj_t mp_seq_index_obj(const mp_obj_t *items, size_t len, size_t n_args, cons
}
}
mp_raise_ValueError("object not in sequence");
mp_raise_ValueError(MP_ERROR_TEXT("object not in sequence"));
}
mp_obj_t mp_seq_count_obj(const mp_obj_t *items, size_t len, mp_obj_t value) {
size_t count = 0;
for (size_t i = 0; i < len; i++) {
if (mp_obj_equal(items[i], value)) {
count++;
}
if (mp_obj_equal(items[i], value)) {
count++;
}
}
// Common sense says this cannot overflow small int