mirror of
https://github.com/RustPython/RustPython.git
synced 2026-06-17 01:51:39 +09:00
Move PyIteratorValue to objiter.rs
This commit is contained in:
@@ -6,10 +6,11 @@ use std::ops::Deref;
|
||||
use num_traits::ToPrimitive;
|
||||
|
||||
use crate::function::OptionalArg;
|
||||
use crate::pyobject::{PyContext, PyIteratorValue, PyObjectRef, PyRef, PyResult, PyValue};
|
||||
use crate::pyobject::{PyContext, PyObjectRef, PyRef, PyResult, PyValue};
|
||||
use crate::vm::VirtualMachine;
|
||||
|
||||
use super::objint;
|
||||
use super::objiter::PyIteratorValue;
|
||||
use super::objtype::PyClassRef;
|
||||
|
||||
#[derive(Debug)]
|
||||
|
||||
@@ -5,11 +5,12 @@ use std::ops::{Deref, DerefMut};
|
||||
|
||||
use crate::function::{KwArgs, OptionalArg};
|
||||
use crate::pyobject::{
|
||||
DictProtocol, PyAttributes, PyContext, PyIteratorValue, PyObjectRef, PyRef, PyResult, PyValue,
|
||||
DictProtocol, PyAttributes, PyContext, PyObjectRef, PyRef, PyResult, PyValue,
|
||||
};
|
||||
use crate::vm::{ReprGuard, VirtualMachine};
|
||||
|
||||
use super::objiter;
|
||||
use super::objiter::PyIteratorValue;
|
||||
use super::objstr::{self, PyStringRef};
|
||||
use super::objtype;
|
||||
use crate::obj::objtype::PyClassRef;
|
||||
|
||||
@@ -2,7 +2,9 @@
|
||||
* Various types to support iteration.
|
||||
*/
|
||||
|
||||
use crate::pyobject::{PyContext, PyIteratorValue, PyObjectRef, PyRef, PyResult};
|
||||
use std::cell::Cell;
|
||||
|
||||
use crate::pyobject::{PyContext, PyObjectRef, PyRef, PyResult, PyValue};
|
||||
use crate::vm::VirtualMachine;
|
||||
|
||||
use super::objbytearray::PyByteArray;
|
||||
@@ -10,6 +12,7 @@ use super::objbytes::PyBytes;
|
||||
use super::objrange::PyRange;
|
||||
use super::objsequence;
|
||||
use super::objtype;
|
||||
use super::objtype::PyClassRef;
|
||||
|
||||
/*
|
||||
* This helper function is called at multiple places. First, it is called
|
||||
@@ -71,6 +74,21 @@ pub fn new_stop_iteration(vm: &VirtualMachine) -> PyObjectRef {
|
||||
vm.new_exception(stop_iteration_type, "End of iterator".to_string())
|
||||
}
|
||||
|
||||
// TODO: This is a workaround and shouldn't exist.
|
||||
// Each iterable type should have its own distinct iterator type.
|
||||
// (however, this boilerplate can be reused for "generic iterator" for types with only __getiter__)
|
||||
#[derive(Debug)]
|
||||
pub struct PyIteratorValue {
|
||||
pub position: Cell<usize>,
|
||||
pub iterated_obj: PyObjectRef,
|
||||
}
|
||||
|
||||
impl PyValue for PyIteratorValue {
|
||||
fn class(vm: &VirtualMachine) -> PyClassRef {
|
||||
vm.ctx.iter_type()
|
||||
}
|
||||
}
|
||||
|
||||
type PyIteratorValueRef = PyRef<PyIteratorValue>;
|
||||
|
||||
impl PyIteratorValueRef {
|
||||
|
||||
@@ -4,13 +4,12 @@ use std::fmt;
|
||||
use num_traits::ToPrimitive;
|
||||
|
||||
use crate::function::{OptionalArg, PyFuncArgs};
|
||||
use crate::pyobject::{
|
||||
IdProtocol, PyContext, PyIteratorValue, PyObjectRef, PyRef, PyResult, PyValue, TypeProtocol,
|
||||
};
|
||||
use crate::pyobject::{IdProtocol, PyContext, PyObjectRef, PyRef, PyResult, PyValue, TypeProtocol};
|
||||
use crate::vm::{ReprGuard, VirtualMachine};
|
||||
|
||||
use super::objbool;
|
||||
use super::objint;
|
||||
use super::objiter::PyIteratorValue;
|
||||
use super::objsequence::{
|
||||
get_elements, get_elements_cell, get_item, seq_equal, seq_ge, seq_gt, seq_le, seq_lt, seq_mul,
|
||||
PySliceableSequence,
|
||||
|
||||
@@ -6,10 +6,11 @@ use num_integer::Integer;
|
||||
use num_traits::{One, Signed, Zero};
|
||||
|
||||
use crate::function::{OptionalArg, PyFuncArgs};
|
||||
use crate::pyobject::{Either, PyContext, PyIteratorValue, PyObjectRef, PyRef, PyResult, PyValue};
|
||||
use crate::pyobject::{Either, PyContext, PyObjectRef, PyRef, PyResult, PyValue};
|
||||
use crate::vm::VirtualMachine;
|
||||
|
||||
use super::objint::{PyInt, PyIntRef};
|
||||
use super::objiter::PyIteratorValue;
|
||||
use super::objslice::PySliceRef;
|
||||
use super::objtype::PyClassRef;
|
||||
|
||||
|
||||
@@ -8,14 +8,13 @@ use std::fmt;
|
||||
use std::hash::{Hash, Hasher};
|
||||
|
||||
use crate::function::{OptionalArg, PyFuncArgs};
|
||||
use crate::pyobject::{
|
||||
PyContext, PyIteratorValue, PyObject, PyObjectRef, PyRef, PyResult, PyValue, TypeProtocol,
|
||||
};
|
||||
use crate::pyobject::{PyContext, PyObject, PyObjectRef, PyRef, PyResult, PyValue, TypeProtocol};
|
||||
use crate::vm::{ReprGuard, VirtualMachine};
|
||||
|
||||
use super::objbool;
|
||||
use super::objint;
|
||||
use super::objiter;
|
||||
use super::objiter::PyIteratorValue;
|
||||
use super::objtype;
|
||||
use super::objtype::PyClassRef;
|
||||
|
||||
|
||||
@@ -3,13 +3,12 @@ use std::fmt;
|
||||
use std::hash::{Hash, Hasher};
|
||||
|
||||
use crate::function::OptionalArg;
|
||||
use crate::pyobject::{
|
||||
IdProtocol, PyContext, PyIteratorValue, PyObjectRef, PyRef, PyResult, PyValue,
|
||||
};
|
||||
use crate::pyobject::{IdProtocol, PyContext, PyObjectRef, PyRef, PyResult, PyValue};
|
||||
use crate::vm::{ReprGuard, VirtualMachine};
|
||||
|
||||
use super::objbool;
|
||||
use super::objint;
|
||||
use super::objiter::PyIteratorValue;
|
||||
use super::objsequence::{
|
||||
get_elements, get_item, seq_equal, seq_ge, seq_gt, seq_le, seq_lt, seq_mul,
|
||||
};
|
||||
|
||||
@@ -1,5 +1,5 @@
|
||||
use std::any::Any;
|
||||
use std::cell::{Cell, RefCell};
|
||||
use std::cell::RefCell;
|
||||
use std::collections::HashMap;
|
||||
use std::fmt;
|
||||
use std::marker::PhantomData;
|
||||
@@ -1127,20 +1127,6 @@ where
|
||||
}
|
||||
}
|
||||
|
||||
// TODO: This is a workaround and shouldn't exist.
|
||||
// Each iterable type should have its own distinct iterator type.
|
||||
#[derive(Debug)]
|
||||
pub struct PyIteratorValue {
|
||||
pub position: Cell<usize>,
|
||||
pub iterated_obj: PyObjectRef,
|
||||
}
|
||||
|
||||
impl PyValue for PyIteratorValue {
|
||||
fn class(vm: &VirtualMachine) -> PyClassRef {
|
||||
vm.ctx.iter_type()
|
||||
}
|
||||
}
|
||||
|
||||
impl<T> PyObject<T>
|
||||
where
|
||||
T: Sized + PyObjectPayload,
|
||||
|
||||
Reference in New Issue
Block a user