Make slice.stop not an option

This commit is contained in:
ben committed 2019-04-02 17:25:51 +13:00
1 parent e0f7fbb191
commit ea2622ee7b
2 files changed
+14 -13

No files matched your search

+8 -3
View File
@@ -407,10 +407,15 @@ impl Frame {
} else {
None
};
let stop = Some(self.pop_value());
let start = Some(self.pop_value());
let stop = self.pop_value();
let start = self.pop_value();
let obj = PySlice { start, stop, step }.into_ref(vm);
let obj = PySlice {
start: Some(start),
stop,
step,
}
.into_ref(vm);
self.push_value(obj.into_object());
Ok(None)
}
+6 -10
View File
@@ -9,7 +9,7 @@ use num_bigint::BigInt;
#[derive(Debug)]
pub struct PySlice {
pub start: Option<PyObjectRef>,
pub stop: Option<PyObjectRef>,
pub stop: PyObjectRef,
pub step: Option<PyObjectRef>,
}
@@ -30,7 +30,7 @@ fn slice_new(cls: PyClassRef, args: PyFuncArgs, vm: &VirtualMachine) -> PyResult
let stop = args.bind(vm)?;
PySlice {
start: None,
stop: Some(stop),
stop,
step: None,
}
}
@@ -39,7 +39,7 @@ fn slice_new(cls: PyClassRef, args: PyFuncArgs, vm: &VirtualMachine) -> PyResult
args.bind(vm)?;
PySlice {
start: Some(start),
stop: Some(stop),
stop,
step: step.into_option(),
}
}
@@ -60,8 +60,8 @@ impl PySliceRef {
get_property_value(vm, &self.start)
}
fn stop(self, vm: &VirtualMachine) -> PyObjectRef {
get_property_value(vm, &self.stop)
fn stop(self, _vm: &VirtualMachine) -> PyObjectRef {
self.stop.clone()
}
fn step(self, vm: &VirtualMachine) -> PyObjectRef {
@@ -77,11 +77,7 @@ impl PySliceRef {
}
pub fn stop_index(&self, vm: &VirtualMachine) -> PyResult<Option<BigInt>> {
if let Some(obj) = &self.stop {
to_index_value(vm, obj)
} else {
Ok(None)
}
to_index_value(vm, &self.stop)
}
pub fn step_index(&self, vm: &VirtualMachine) -> PyResult<Option<BigInt>> {