py: Fix configurability of builtin slice.

store-consts
Damien George 2014-06-01 13:49:35 +01:00
parent 3ebd4d0cae
commit c49ddb9315
5 changed files with 14 additions and 1 deletions

View File

@ -568,7 +568,9 @@ typedef struct {
} mp_bound_slice_t;
void mp_seq_multiply(const void *items, uint item_sz, uint len, uint times, void *dest);
#if MICROPY_PY_BUILTINS_SLICE
bool mp_seq_get_fast_slice_indexes(machine_uint_t len, mp_obj_t slice, mp_bound_slice_t *indexes);
#endif
#define mp_seq_copy(dest, src, len, item_t) memcpy(dest, src, len * sizeof(item_t))
#define mp_seq_cat(dest, src1, len1, src2, len2, item_t) { memcpy(dest, src1, (len1) * sizeof(item_t)); memcpy(dest + (len1), src2, (len2) * sizeof(item_t)); }
bool mp_seq_cmp_bytes(int op, const byte *data1, uint len1, const byte *data2, uint len2);

View File

@ -169,7 +169,9 @@ STATIC mp_obj_t array_subscr(mp_obj_t self_in, mp_obj_t index_in, mp_obj_t value
return MP_OBJ_NULL; // op not supported
} else {
mp_obj_array_t *o = self_in;
if (MP_OBJ_IS_TYPE(index_in, &mp_type_slice)) {
if (0) {
#if MICROPY_PY_BUILTINS_SLICE
} else if (MP_OBJ_IS_TYPE(index_in, &mp_type_slice)) {
if (value != MP_OBJ_SENTINEL) {
// Only getting a slice is suported so far, not assignment
// TODO: confirmed that both bytearray and array.array support
@ -187,6 +189,7 @@ STATIC mp_obj_t array_subscr(mp_obj_t self_in, mp_obj_t index_in, mp_obj_t value
byte *p = o->items;
memcpy(res->items, p + slice.start * sz, (slice.stop - slice.start) * sz);
return res;
#endif
} else {
uint index = mp_get_index(o->base.type, o->len, index_in, false);
if (value == MP_OBJ_SENTINEL) {

View File

@ -1185,7 +1185,9 @@ void *const mp_fun_table[MP_F_NUMBER_OF] = {
mp_import_name,
mp_import_from,
mp_import_all,
#if MICROPY_PY_BUILTINS_SLICE
mp_obj_new_slice,
#endif
mp_unpack_sequence,
mp_unpack_ex,
};

View File

@ -127,7 +127,9 @@ typedef enum {
MP_F_IMPORT_NAME,
MP_F_IMPORT_FROM,
MP_F_IMPORT_ALL,
#if MICROPY_PY_BUILTINS_SLICE
MP_F_NEW_SLICE,
#endif
MP_F_UNPACK_SEQUENCE,
MP_F_UNPACK_EX,
MP_F_NUMBER_OF,

View File

@ -51,6 +51,8 @@ void mp_seq_multiply(const void *items, uint item_sz, uint len, uint times, void
}
}
#if MICROPY_PY_BUILTINS_SLICE
bool mp_seq_get_fast_slice_indexes(machine_uint_t len, mp_obj_t slice, mp_bound_slice_t *indexes) {
mp_obj_t ostart, ostop, ostep;
machine_int_t start, stop;
@ -102,6 +104,8 @@ bool mp_seq_get_fast_slice_indexes(machine_uint_t len, mp_obj_t slice, mp_bound_
return true;
}
#endif
mp_obj_t mp_seq_extract_slice(uint len, const mp_obj_t *seq, mp_bound_slice_t *indexes) {
machine_int_t start = indexes->start, stop = indexes->stop;
machine_int_t step = indexes->step;