convert to PySliceRef as it is the only option
@@ -11,7 +11,7 @@ use crate::vm::VirtualMachine;
use super::objbool;
use super::objint::PyInt;
use super::objlist::PyList;
-use super::objslice::PySlice;
+use super::objslice::{PySlice, PySliceRef};
use super::objtuple::PyTuple;
pub trait PySliceableSequence {
@@ -147,11 +147,13 @@ pub trait PySliceableSequenceMut: PySliceableSequence {
fn del_stepped_slice(&mut self, range: Range<usize>, step: usize);
fn del_index(&mut self, index: usize);
- fn del_slice_items(&mut self, vm: &VirtualMachine, slice: &PyObjectRef) -> PyResult {
- // TODO: we could potentially avoid this copy and use slice
- match slice.payload() {
- Some(PySlice { start, stop, step }) => {
- let step = step.clone().unwrap_or_else(BigInt::one);
+ fn del_slice_items(&mut self, vm: &VirtualMachine, slice: &PySliceRef) -> PyResult {
+
+ let start = &slice.start;
+ let stop = &slice.stop;
+
+ let step = slice.step.clone().unwrap_or_else(BigInt::one);
+
if step.is_zero() {
Err(vm.new_value_error("slice step cannot be zero".to_string()))
} else if step.is_positive() {
@@ -173,7 +175,7 @@ pub trait PySliceableSequenceMut: PySliceableSequence {
}
}
} else {
- // TODO what to delete here?
+ // no del to do
Ok(vm.get_none())
}
} else {
@@ -198,13 +200,11 @@ pub trait PySliceableSequenceMut: PySliceableSequence {
}
}
} else {
- // TODO what to del here?
+ // no del to do
Ok(vm.get_none())
}
}
- }
- payload => panic!("del_slice_items called with non-slice: {:?}", payload),
- }
+
}
}
@@ -308,7 +308,12 @@ pub fn del_item<T: PySliceableSequenceMut>(
if subscript.payload::<PySlice>().is_some() {
if sequence.payload::<PyList>().is_some() {
- elements.del_slice_items(vm, &subscript)
+ if let Ok(slice) = subscript.downcast::<PySlice>() {
+ elements.del_slice_items(vm, &slice)
+ } else {
+ panic!("PySlice is not a slice? this should not be")
+ }
+
} else {
panic!("sequence del_item called for non-mutable-sequence")
}
