From ea2622ee7b820dc4fb787aa47817b293fcb69c57 Mon Sep 17 00:00:00 2001 From: ben Date: Mon, 1 Apr 2019 19:38:20 +1300 Subject: [PATCH] Make slice.stop not an option --- vm/src/frame.rs | 11 ++++++++--- vm/src/obj/objslice.rs | 16 ++++++---------- 2 files changed, 14 insertions(+), 13 deletions(-) diff --git a/vm/src/frame.rs b/vm/src/frame.rs index 3a5f4c5ab..2cd080824 100644 --- a/vm/src/frame.rs +++ b/vm/src/frame.rs @@ -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) } diff --git a/vm/src/obj/objslice.rs b/vm/src/obj/objslice.rs index f6f02c8db..82e4cef8c 100644 --- a/vm/src/obj/objslice.rs +++ b/vm/src/obj/objslice.rs @@ -9,7 +9,7 @@ use num_bigint::BigInt; #[derive(Debug)] pub struct PySlice { pub start: Option, - pub stop: Option, + pub stop: PyObjectRef, pub step: Option, } @@ -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> { - 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> {