Skip to content

Convert map, zip, filter, and enumerate to Any payload #634

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 4 commits into from
Mar 9, 2019
Merged
Show file tree
Hide file tree
Changes from 1 commit
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
Next Next commit
map
  • Loading branch information
OddCoincidence committed Mar 9, 2019
commit 303e19d7139c58586a330b72921d556f0b986833
32 changes: 25 additions & 7 deletions vm/src/obj/objmap.rs
Original file line number Diff line number Diff line change
@@ -1,6 +1,22 @@
use crate::pyobject::{
PyContext, PyFuncArgs, PyObject, PyObjectPayload, PyObjectPayload2, PyObjectRef, PyResult,
TypeProtocol,
};
use crate::vm::VirtualMachine;

use super::objiter;
use crate::pyobject::{PyContext, PyFuncArgs, PyObject, PyObjectPayload, PyResult, TypeProtocol};
use crate::vm::VirtualMachine; // Required for arg_check! to use isinstance

#[derive(Debug)]
pub struct PyMap {
mapper: PyObjectRef,
iterators: Vec<PyObjectRef>,
}

impl PyObjectPayload2 for PyMap {
fn required_type(ctx: &PyContext) -> PyObjectRef {
ctx.map_type()
}
}

fn map_new(vm: &mut VirtualMachine, args: PyFuncArgs) -> PyResult {
no_kwargs!(vm, args);
Expand All @@ -15,9 +31,11 @@ fn map_new(vm: &mut VirtualMachine, args: PyFuncArgs) -> PyResult {
.map(|iterable| objiter::get_iter(vm, iterable))
.collect::<Result<Vec<_>, _>>()?;
Ok(PyObject::new(
PyObjectPayload::MapIterator {
mapper: function.clone(),
iterators,
PyObjectPayload::AnyRustValue {
value: Box::new(PyMap {
mapper: function.clone(),
iterators,
}),
},
cls.clone(),
))
Expand All @@ -27,10 +45,10 @@ fn map_new(vm: &mut VirtualMachine, args: PyFuncArgs) -> PyResult {
fn map_next(vm: &mut VirtualMachine, args: PyFuncArgs) -> PyResult {
arg_check!(vm, args, required = [(map, Some(vm.ctx.map_type()))]);

if let PyObjectPayload::MapIterator {
if let Some(PyMap {
ref mapper,
ref iterators,
} = map.payload
}) = map.payload::<PyMap>()
{
let next_objs = iterators
.iter()
Expand Down
5 changes: 0 additions & 5 deletions vm/src/pyobject.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1512,10 +1512,6 @@ pub enum PyObjectPayload {
predicate: PyObjectRef,
iterator: PyObjectRef,
},
MapIterator {
mapper: PyObjectRef,
iterators: Vec<PyObjectRef>,
},
ZipIterator {
iterators: Vec<PyObjectRef>,
},
Expand Down Expand Up @@ -1573,7 +1569,6 @@ impl fmt::Debug for PyObjectPayload {
PyObjectPayload::Iterator { .. } => write!(f, "iterator"),
PyObjectPayload::EnumerateIterator { .. } => write!(f, "enumerate"),
PyObjectPayload::FilterIterator { .. } => write!(f, "filter"),
PyObjectPayload::MapIterator { .. } => write!(f, "map"),
PyObjectPayload::ZipIterator { .. } => write!(f, "zip"),
PyObjectPayload::Slice { .. } => write!(f, "slice"),
PyObjectPayload::Function { .. } => write!(f, "function"),
Expand Down
pFad - Phonifier reborn

Pfad - The Proxy pFad of © 2024 Garber Painting. All rights reserved.

Note: This service is not intended for secure transactions such as banking, social media, email, or purchasing. Use at your own risk. We assume no liability whatsoever for broken pages.


Alternative Proxies:

Alternative Proxy

pFad Proxy

pFad v3 Proxy

pFad v4 Proxy