Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 4 additions & 0 deletions tests/snippets/3.1.3.2.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,3 +4,7 @@
assert 25 == squares[-1]
assert [9, 16, 25] == squares[-3:]
assert squares == squares[:]

assert [1, 9, 25] == squares[::2]
assert [4, 16] == squares[1::2]
assert [4] == squares[1:2:2]
24 changes: 15 additions & 9 deletions vm/src/objlist.rs
Original file line number Diff line number Diff line change
Expand Up @@ -29,19 +29,25 @@ pub fn get_item(vm: &mut VirtualMachine, l: &Vec<PyObjectRef>, b: PyObjectRef) -
&Some(stop) => get_pos(l, stop),
&None => l.len() as usize,
};
let step = match step {
//Some(step) => step as usize,
&None => 1 as usize,
_ => unimplemented!("stepped slicing not supported for type {:?}", l),
};
// TODO: we could potentially avoid this copy and use slice
let obj = PyObject::new(
Ok(PyObject::new(
PyObjectKind::List {
elements: l[start..stop].to_vec(),
elements: match step {
&None | &Some(1) => l[start..stop].to_vec(),
&Some(num) => {
if num < 0 {
unimplemented!("negative step indexing not yet supported")
};
l[start..stop]
.iter()
.step_by(num as usize)
.cloned()
.collect()
}
},
},
vm.get_type(),
);
Ok(obj)
))
}
_ => Err(vm.new_exception(format!(
"TypeError: indexing type {:?} with index {:?} is not supported (yet?)",
Expand Down