Skip to content

Commit 9d8bdd7

Browse files
zip
1 parent 303e19d commit 9d8bdd7

File tree

3 files changed

+22
-9
lines changed

3 files changed

+22
-9
lines changed

vm/src/obj/objmap.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -48,7 +48,7 @@ fn map_next(vm: &mut VirtualMachine, args: PyFuncArgs) -> PyResult {
4848
if let Some(PyMap {
4949
ref mapper,
5050
ref iterators,
51-
}) = map.payload::<PyMap>()
51+
}) = map.payload()
5252
{
5353
let next_objs = iterators
5454
.iter()

vm/src/obj/objzip.rs

Lines changed: 21 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,21 @@
1+
use crate::pyobject::{
2+
PyContext, PyFuncArgs, PyObject, PyObjectPayload, PyObjectPayload2, PyObjectRef, PyResult,
3+
TypeProtocol,
4+
};
5+
use crate::vm::VirtualMachine;
6+
17
use super::objiter;
2-
use crate::pyobject::{PyContext, PyFuncArgs, PyObject, PyObjectPayload, PyResult, TypeProtocol};
3-
use crate::vm::VirtualMachine; // Required for arg_check! to use isinstance
8+
9+
#[derive(Debug)]
10+
pub struct PyZip {
11+
iterators: Vec<PyObjectRef>,
12+
}
13+
14+
impl PyObjectPayload2 for PyZip {
15+
fn required_type(ctx: &PyContext) -> PyObjectRef {
16+
ctx.zip_type()
17+
}
18+
}
419

520
fn zip_new(vm: &mut VirtualMachine, args: PyFuncArgs) -> PyResult {
621
no_kwargs!(vm, args);
@@ -11,15 +26,17 @@ fn zip_new(vm: &mut VirtualMachine, args: PyFuncArgs) -> PyResult {
1126
.map(|iterable| objiter::get_iter(vm, iterable))
1227
.collect::<Result<Vec<_>, _>>()?;
1328
Ok(PyObject::new(
14-
PyObjectPayload::ZipIterator { iterators },
29+
PyObjectPayload::AnyRustValue {
30+
value: Box::new(PyZip { iterators }),
31+
},
1532
cls.clone(),
1633
))
1734
}
1835

1936
fn zip_next(vm: &mut VirtualMachine, args: PyFuncArgs) -> PyResult {
2037
arg_check!(vm, args, required = [(zip, Some(vm.ctx.zip_type()))]);
2138

22-
if let PyObjectPayload::ZipIterator { ref iterators } = zip.payload {
39+
if let Some(PyZip { ref iterators }) = zip.payload() {
2340
if iterators.is_empty() {
2441
Err(objiter::new_stop_iteration(vm))
2542
} else {

vm/src/pyobject.rs

Lines changed: 0 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1512,9 +1512,6 @@ pub enum PyObjectPayload {
15121512
predicate: PyObjectRef,
15131513
iterator: PyObjectRef,
15141514
},
1515-
ZipIterator {
1516-
iterators: Vec<PyObjectRef>,
1517-
},
15181515
Slice {
15191516
start: Option<BigInt>,
15201517
stop: Option<BigInt>,
@@ -1569,7 +1566,6 @@ impl fmt::Debug for PyObjectPayload {
15691566
PyObjectPayload::Iterator { .. } => write!(f, "iterator"),
15701567
PyObjectPayload::EnumerateIterator { .. } => write!(f, "enumerate"),
15711568
PyObjectPayload::FilterIterator { .. } => write!(f, "filter"),
1572-
PyObjectPayload::ZipIterator { .. } => write!(f, "zip"),
15731569
PyObjectPayload::Slice { .. } => write!(f, "slice"),
15741570
PyObjectPayload::Function { .. } => write!(f, "function"),
15751571
PyObjectPayload::Generator { .. } => write!(f, "generator"),

0 commit comments

Comments
 (0)