Skip to content

Commit 303e19d

Browse files
map
1 parent 9a3b731 commit 303e19d

File tree

2 files changed

+25
-12
lines changed

2 files changed

+25
-12
lines changed

vm/src/obj/objmap.rs

Lines changed: 25 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,22 @@
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 PyMap {
11+
mapper: PyObjectRef,
12+
iterators: Vec<PyObjectRef>,
13+
}
14+
15+
impl PyObjectPayload2 for PyMap {
16+
fn required_type(ctx: &PyContext) -> PyObjectRef {
17+
ctx.map_type()
18+
}
19+
}
420

521
fn map_new(vm: &mut VirtualMachine, args: PyFuncArgs) -> PyResult {
622
no_kwargs!(vm, args);
@@ -15,9 +31,11 @@ fn map_new(vm: &mut VirtualMachine, args: PyFuncArgs) -> PyResult {
1531
.map(|iterable| objiter::get_iter(vm, iterable))
1632
.collect::<Result<Vec<_>, _>>()?;
1733
Ok(PyObject::new(
18-
PyObjectPayload::MapIterator {
19-
mapper: function.clone(),
20-
iterators,
34+
PyObjectPayload::AnyRustValue {
35+
value: Box::new(PyMap {
36+
mapper: function.clone(),
37+
iterators,
38+
}),
2139
},
2240
cls.clone(),
2341
))
@@ -27,10 +45,10 @@ fn map_new(vm: &mut VirtualMachine, args: PyFuncArgs) -> PyResult {
2745
fn map_next(vm: &mut VirtualMachine, args: PyFuncArgs) -> PyResult {
2846
arg_check!(vm, args, required = [(map, Some(vm.ctx.map_type()))]);
2947

30-
if let PyObjectPayload::MapIterator {
48+
if let Some(PyMap {
3149
ref mapper,
3250
ref iterators,
33-
} = map.payload
51+
}) = map.payload::<PyMap>()
3452
{
3553
let next_objs = iterators
3654
.iter()

vm/src/pyobject.rs

Lines changed: 0 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1512,10 +1512,6 @@ pub enum PyObjectPayload {
15121512
predicate: PyObjectRef,
15131513
iterator: PyObjectRef,
15141514
},
1515-
MapIterator {
1516-
mapper: PyObjectRef,
1517-
iterators: Vec<PyObjectRef>,
1518-
},
15191515
ZipIterator {
15201516
iterators: Vec<PyObjectRef>,
15211517
},
@@ -1573,7 +1569,6 @@ impl fmt::Debug for PyObjectPayload {
15731569
PyObjectPayload::Iterator { .. } => write!(f, "iterator"),
15741570
PyObjectPayload::EnumerateIterator { .. } => write!(f, "enumerate"),
15751571
PyObjectPayload::FilterIterator { .. } => write!(f, "filter"),
1576-
PyObjectPayload::MapIterator { .. } => write!(f, "map"),
15771572
PyObjectPayload::ZipIterator { .. } => write!(f, "zip"),
15781573
PyObjectPayload::Slice { .. } => write!(f, "slice"),
15791574
PyObjectPayload::Function { .. } => write!(f, "function"),

0 commit comments

Comments
 (0)