aboutsummaryrefslogtreecommitdiff
path: root/py/sequence.c
diff options
context:
space:
mode:
authorPaul Sokolovsky <pfalcon@users.sourceforge.net>2014-05-25 01:39:27 +0300
committerPaul Sokolovsky <pfalcon@users.sourceforge.net>2014-05-25 01:42:24 +0300
commitafaaf535e6cfaf599432b13a2fbe9373e6a2c4b8 (patch)
tree34ffa8efb2b5f06a128edc983d40025f703b5c26 /py/sequence.c
parent7a4ddd24281a7e21eeaa697644418015cf4dd650 (diff)
objslice: Support arbitrary objects start, stop, and step.
Older int-only encoding is not expressive enough to support arbitrary slice assignment operations.
Diffstat (limited to 'py/sequence.c')
-rw-r--r--py/sequence.c20
1 files changed, 16 insertions, 4 deletions
diff --git a/py/sequence.c b/py/sequence.c
index 966adaac0..2c1f6a836 100644
--- a/py/sequence.c
+++ b/py/sequence.c
@@ -52,12 +52,24 @@ void mp_seq_multiply(const void *items, uint item_sz, uint len, uint times, void
}
bool mp_seq_get_fast_slice_indexes(machine_uint_t len, mp_obj_t slice, machine_uint_t *begin, machine_uint_t *end) {
- machine_int_t start, stop, step;
- mp_obj_slice_get(slice, &start, &stop, &step);
- if (step != 1) {
+ mp_obj_t ostart, ostop, ostep;
+ machine_int_t start, stop;
+ mp_obj_slice_get(slice, &ostart, &ostop, &ostep);
+ if (ostep != mp_const_none && ostep != MP_OBJ_NEW_SMALL_INT(1)) {
return false;
}
+ if (ostart == mp_const_none) {
+ start = 0;
+ } else {
+ start = MP_OBJ_SMALL_INT_VALUE(ostart);
+ }
+ if (ostop == mp_const_none) {
+ stop = len;
+ } else {
+ stop = MP_OBJ_SMALL_INT_VALUE(ostop);
+ }
+
// Unlike subscription, out-of-bounds slice indexes are never error
if (start < 0) {
start = len + start;
@@ -67,7 +79,7 @@ bool mp_seq_get_fast_slice_indexes(machine_uint_t len, mp_obj_t slice, machine_u
} else if (start > len) {
start = len;
}
- if (stop <= 0) {
+ if (stop < 0) {
stop = len + stop;
// CPython returns empty sequence in such case
if (stop < 0) {