PyIter -> SlotIterator to reserve PyIter for protocol object

This commit is contained in:
Jeong YunWon
2021-09-23 01:51:18 +09:00
parent 0787ed0fd3
commit 8a46e638ce
25 changed files with 136 additions and 130 deletions

View File

@@ -4,7 +4,7 @@ use crate::{
coroutine::{Coro, Variant},
frame::FrameRef,
function::OptionalArg,
slots::{IteratorIterable, PyIter},
slots::{IteratorIterable, SlotIterator},
IdProtocol, PyClassImpl, PyContext, PyObjectRef, PyRef, PyResult, PyValue, TypeProtocol,
VirtualMachine,
};
@@ -182,7 +182,7 @@ impl PyValue for PyAsyncGenASend {
}
}
#[pyimpl(with(PyIter))]
#[pyimpl(with(SlotIterator))]
impl PyAsyncGenASend {
#[pymethod(name = "__await__")]
fn r#await(zelf: PyRef<Self>, _vm: &VirtualMachine) -> PyRef<Self> {
@@ -255,7 +255,7 @@ impl PyAsyncGenASend {
}
impl IteratorIterable for PyAsyncGenASend {}
impl PyIter for PyAsyncGenASend {
impl SlotIterator for PyAsyncGenASend {
fn next(zelf: &PyRef<Self>, vm: &VirtualMachine) -> PyResult {
zelf.send(vm.ctx.none(), vm)
}
@@ -276,7 +276,7 @@ impl PyValue for PyAsyncGenAThrow {
}
}
#[pyimpl(with(PyIter))]
#[pyimpl(with(SlotIterator))]
impl PyAsyncGenAThrow {
#[pymethod(name = "__await__")]
fn r#await(zelf: PyRef<Self>, _vm: &VirtualMachine) -> PyRef<Self> {
@@ -397,7 +397,7 @@ impl PyAsyncGenAThrow {
}
impl IteratorIterable for PyAsyncGenAThrow {}
impl PyIter for PyAsyncGenAThrow {
impl SlotIterator for PyAsyncGenAThrow {
fn next(zelf: &PyRef<Self>, vm: &VirtualMachine) -> PyResult {
zelf.send(vm.ctx.none(), vm)
}

View File

@@ -19,7 +19,7 @@ use crate::{
sliceable::{PySliceableSequence, PySliceableSequenceMut, SequenceIndex},
slots::{
AsBuffer, Callable, Comparable, Hashable, Iterable, IteratorIterable, PyComparisonOp,
PyIter, Unhashable,
SlotIterator, Unhashable,
},
utils::Either,
IdProtocol, IntoPyObject, PyClassDef, PyClassImpl, PyComparisonValue, PyContext, PyObjectRef,
@@ -741,10 +741,10 @@ impl PyValue for PyByteArrayIterator {
}
}
#[pyimpl(with(PyIter))]
#[pyimpl(with(SlotIterator))]
impl PyByteArrayIterator {}
impl IteratorIterable for PyByteArrayIterator {}
impl PyIter for PyByteArrayIterator {
impl SlotIterator for PyByteArrayIterator {
fn next(zelf: &PyRef<Self>, vm: &VirtualMachine) -> PyResult {
let pos = zelf.position.fetch_add(1);
if let Some(&ret) = zelf.bytearray.borrow_buf().get(pos) {

View File

@@ -10,7 +10,7 @@ use crate::{
protocol::{BufferInternal, BufferOptions, PyBuffer},
slots::{
AsBuffer, Callable, Comparable, Hashable, Iterable, IteratorIterable, PyComparisonOp,
PyIter, SlotConstructor,
SlotConstructor, SlotIterator,
},
utils::Either,
IdProtocol, IntoPyObject, IntoPyResult, PyClassImpl, PyComparisonValue, PyContext, PyObjectRef,
@@ -594,10 +594,10 @@ impl PyValue for PyBytesIterator {
}
}
#[pyimpl(with(PyIter))]
#[pyimpl(with(SlotIterator))]
impl PyBytesIterator {}
impl IteratorIterable for PyBytesIterator {}
impl PyIter for PyBytesIterator {
impl SlotIterator for PyBytesIterator {
fn next(zelf: &PyRef<Self>, vm: &VirtualMachine) -> PyResult {
let pos = zelf.position.fetch_add(1);
if let Some(&ret) = zelf.bytes.as_bytes().get(pos) {

View File

@@ -3,7 +3,7 @@ use crate::{
coroutine::{Coro, Variant},
frame::FrameRef,
function::OptionalArg,
slots::{IteratorIterable, PyIter},
slots::{IteratorIterable, SlotIterator},
IdProtocol, PyClassImpl, PyContext, PyObjectRef, PyRef, PyResult, PyValue, VirtualMachine,
};
@@ -19,7 +19,7 @@ impl PyValue for PyCoroutine {
}
}
#[pyimpl(with(PyIter))]
#[pyimpl(with(SlotIterator))]
impl PyCoroutine {
pub fn as_coro(&self) -> &Coro {
&self.inner
@@ -102,7 +102,7 @@ impl PyCoroutine {
}
impl IteratorIterable for PyCoroutine {}
impl PyIter for PyCoroutine {
impl SlotIterator for PyCoroutine {
fn next(zelf: &PyRef<Self>, vm: &VirtualMachine) -> PyResult {
zelf.send(vm.ctx.none(), vm)
}
@@ -120,7 +120,7 @@ impl PyValue for PyCoroutineWrapper {
}
}
#[pyimpl(with(PyIter))]
#[pyimpl(with(SlotIterator))]
impl PyCoroutineWrapper {
#[pymethod]
fn send(&self, val: PyObjectRef, vm: &VirtualMachine) -> PyResult {
@@ -140,7 +140,7 @@ impl PyCoroutineWrapper {
}
impl IteratorIterable for PyCoroutineWrapper {}
impl PyIter for PyCoroutineWrapper {
impl SlotIterator for PyCoroutineWrapper {
fn next(zelf: &PyRef<Self>, vm: &VirtualMachine) -> PyResult {
zelf.send(vm.ctx.none(), vm)
}

View File

@@ -5,7 +5,9 @@ use crate::{
dictdatatype::{self, DictKey},
function::{ArgIterable, FuncArgs, KwArgs, OptionalArg},
iterator,
slots::{Comparable, Hashable, Iterable, IteratorIterable, PyComparisonOp, PyIter, Unhashable},
slots::{
Comparable, Hashable, Iterable, IteratorIterable, PyComparisonOp, SlotIterator, Unhashable,
},
vm::{ReprGuard, VirtualMachine},
IdProtocol, IntoPyObject, ItemProtocol,
PyArithmaticValue::*,
@@ -708,7 +710,7 @@ macro_rules! dict_iterator {
}
}
#[pyimpl(with(PyIter))]
#[pyimpl(with(SlotIterator))]
impl $iter_name {
fn new(dict: PyDictRef) -> Self {
$iter_name {
@@ -730,7 +732,7 @@ macro_rules! dict_iterator {
}
impl IteratorIterable for $iter_name {}
impl PyIter for $iter_name {
impl SlotIterator for $iter_name {
#[allow(clippy::redundant_closure_call)]
fn next(zelf: &PyRef<Self>, vm: &VirtualMachine) -> PyResult {
match zelf.status.load() {
@@ -769,7 +771,7 @@ macro_rules! dict_iterator {
}
}
#[pyimpl(with(PyIter))]
#[pyimpl(with(SlotIterator))]
impl $reverse_iter_name {
fn new(dict: PyDictRef) -> Self {
$reverse_iter_name {
@@ -791,7 +793,7 @@ macro_rules! dict_iterator {
}
impl IteratorIterable for $reverse_iter_name {}
impl PyIter for $reverse_iter_name {
impl SlotIterator for $reverse_iter_name {
#[allow(clippy::redundant_closure_call)]
fn next(zelf: &PyRef<Self>, vm: &VirtualMachine) -> PyResult {
match zelf.status.load() {

View File

@@ -7,7 +7,7 @@ use crate::common::lock::PyRwLock;
use crate::{
function::OptionalArg,
iterator,
slots::{IteratorIterable, PyIter, SlotConstructor},
slots::{IteratorIterable, SlotConstructor, SlotIterator},
IntoPyObject, ItemProtocol, PyClassImpl, PyContext, PyObjectRef, PyRef, PyResult, PyValue,
TypeProtocol, VirtualMachine,
};
@@ -51,11 +51,11 @@ impl SlotConstructor for PyEnumerate {
}
}
#[pyimpl(with(PyIter, SlotConstructor), flags(BASETYPE))]
#[pyimpl(with(SlotIterator, SlotConstructor), flags(BASETYPE))]
impl PyEnumerate {}
impl IteratorIterable for PyEnumerate {}
impl PyIter for PyEnumerate {
impl SlotIterator for PyEnumerate {
fn next(zelf: &PyRef<Self>, vm: &VirtualMachine) -> PyResult {
let next_obj = iterator::call_next(vm, &zelf.iterator)?;
let mut counter = zelf.counter.write();
@@ -79,7 +79,7 @@ impl PyValue for PyReverseSequenceIterator {
}
}
#[pyimpl(with(PyIter))]
#[pyimpl(with(SlotIterator))]
impl PyReverseSequenceIterator {
pub fn new(obj: PyObjectRef, len: usize) -> Self {
Self {
@@ -137,7 +137,7 @@ impl PyReverseSequenceIterator {
}
impl IteratorIterable for PyReverseSequenceIterator {}
impl PyIter for PyReverseSequenceIterator {
impl SlotIterator for PyReverseSequenceIterator {
fn next(zelf: &PyRef<Self>, vm: &VirtualMachine) -> PyResult {
if let Exhausted = zelf.status.load() {
return Err(vm.new_stop_iteration());

View File

@@ -1,7 +1,7 @@
use super::PyTypeRef;
use crate::{
iterator,
slots::{IteratorIterable, PyIter, SlotConstructor},
slots::{IteratorIterable, SlotConstructor, SlotIterator},
PyClassImpl, PyContext, PyObjectRef, PyRef, PyResult, PyValue, VirtualMachine,
};
@@ -48,11 +48,11 @@ impl SlotConstructor for PyFilter {
}
}
#[pyimpl(with(PyIter, SlotConstructor), flags(BASETYPE))]
#[pyimpl(with(SlotIterator, SlotConstructor), flags(BASETYPE))]
impl PyFilter {}
impl IteratorIterable for PyFilter {}
impl PyIter for PyFilter {
impl SlotIterator for PyFilter {
fn next(zelf: &PyRef<Self>, vm: &VirtualMachine) -> PyResult {
let predicate = &zelf.predicate;
let iterator = &zelf.iterator;

View File

@@ -7,7 +7,7 @@ use crate::{
coroutine::{Coro, Variant},
frame::FrameRef,
function::OptionalArg,
slots::{IteratorIterable, PyIter},
slots::{IteratorIterable, SlotIterator},
IdProtocol, PyClassImpl, PyContext, PyObjectRef, PyRef, PyResult, PyValue, VirtualMachine,
};
@@ -23,7 +23,7 @@ impl PyValue for PyGenerator {
}
}
#[pyimpl(with(PyIter))]
#[pyimpl(with(SlotIterator))]
impl PyGenerator {
pub fn as_coro(&self) -> &Coro {
&self.inner
@@ -95,7 +95,7 @@ impl PyGenerator {
}
impl IteratorIterable for PyGenerator {}
impl PyIter for PyGenerator {
impl SlotIterator for PyGenerator {
fn next(zelf: &PyRef<Self>, vm: &VirtualMachine) -> PyResult {
zelf.send(vm.ctx.none(), vm)
}

View File

@@ -5,7 +5,7 @@
use super::{int, PyInt, PyTypeRef};
use crate::{
function::ArgCallable,
slots::{IteratorIterable, PyIter},
slots::{IteratorIterable, SlotIterator},
ItemProtocol, PyClassImpl, PyContext, PyObjectRef, PyRef, PyResult, PyValue, TypeProtocol,
VirtualMachine,
};
@@ -34,7 +34,7 @@ impl PyValue for PySequenceIterator {
}
}
#[pyimpl(with(PyIter))]
#[pyimpl(with(SlotIterator))]
impl PySequenceIterator {
pub fn new(obj: PyObjectRef) -> Self {
Self {
@@ -91,7 +91,7 @@ impl PySequenceIterator {
}
impl IteratorIterable for PySequenceIterator {}
impl PyIter for PySequenceIterator {
impl SlotIterator for PySequenceIterator {
fn next(zelf: &PyRef<Self>, vm: &VirtualMachine) -> PyResult {
if let IterStatus::Exhausted = zelf.status.load() {
return Err(vm.new_stop_iteration());
@@ -122,7 +122,7 @@ impl PyValue for PyCallableIterator {
}
}
#[pyimpl(with(PyIter))]
#[pyimpl(with(SlotIterator))]
impl PyCallableIterator {
pub fn new(callable: ArgCallable, sentinel: PyObjectRef) -> Self {
Self {
@@ -134,7 +134,7 @@ impl PyCallableIterator {
}
impl IteratorIterable for PyCallableIterator {}
impl PyIter for PyCallableIterator {
impl SlotIterator for PyCallableIterator {
fn next(zelf: &PyRef<Self>, vm: &VirtualMachine) -> PyResult {
if let IterStatus::Exhausted = zelf.status.load() {
return Err(vm.new_stop_iteration());

View File

@@ -10,7 +10,9 @@ use crate::{
function::{ArgIterable, FuncArgs, OptionalArg},
sequence::{self, SimpleSeq},
sliceable::{PySliceableSequence, PySliceableSequenceMut, SequenceIndex},
slots::{Comparable, Hashable, Iterable, IteratorIterable, PyComparisonOp, PyIter, Unhashable},
slots::{
Comparable, Hashable, Iterable, IteratorIterable, PyComparisonOp, SlotIterator, Unhashable,
},
utils::Either,
vm::{ReprGuard, VirtualMachine},
PyClassDef, PyClassImpl, PyComparisonValue, PyContext, PyObjectRef, PyRef, PyResult, PyValue,
@@ -484,7 +486,7 @@ impl PyValue for PyListIterator {
}
}
#[pyimpl(with(PyIter))]
#[pyimpl(with(SlotIterator))]
impl PyListIterator {
#[pymethod(magic)]
fn length_hint(&self) -> usize {
@@ -521,7 +523,7 @@ impl PyListIterator {
}
impl IteratorIterable for PyListIterator {}
impl PyIter for PyListIterator {
impl SlotIterator for PyListIterator {
fn next(zelf: &PyRef<Self>, vm: &VirtualMachine) -> PyResult {
if let Exhausted = zelf.status.load() {
return Err(vm.new_stop_iteration());
@@ -551,7 +553,7 @@ impl PyValue for PyListReverseIterator {
}
}
#[pyimpl(with(PyIter))]
#[pyimpl(with(SlotIterator))]
impl PyListReverseIterator {
#[pymethod(magic)]
fn length_hint(&self) -> usize {
@@ -595,7 +597,7 @@ impl PyListReverseIterator {
}
impl IteratorIterable for PyListReverseIterator {}
impl PyIter for PyListReverseIterator {
impl SlotIterator for PyListReverseIterator {
fn next(zelf: &PyRef<Self>, vm: &VirtualMachine) -> PyResult {
if let Exhausted = zelf.status.load() {
return Err(vm.new_stop_iteration());

View File

@@ -2,7 +2,7 @@ use super::PyTypeRef;
use crate::{
function::PosArgs,
iterator,
slots::{IteratorIterable, PyIter, SlotConstructor},
slots::{IteratorIterable, SlotConstructor, SlotIterator},
PyClassImpl, PyContext, PyObjectRef, PyRef, PyResult, PyValue, VirtualMachine,
};
@@ -39,7 +39,7 @@ impl SlotConstructor for PyMap {
}
}
#[pyimpl(with(PyIter, SlotConstructor), flags(BASETYPE))]
#[pyimpl(with(SlotIterator, SlotConstructor), flags(BASETYPE))]
impl PyMap {
#[pymethod(magic)]
fn length_hint(&self, vm: &VirtualMachine) -> PyResult<usize> {
@@ -52,7 +52,7 @@ impl PyMap {
}
impl IteratorIterable for PyMap {}
impl PyIter for PyMap {
impl SlotIterator for PyMap {
fn next(zelf: &PyRef<Self>, vm: &VirtualMachine) -> PyResult {
let next_objs = zelf
.iterators

View File

@@ -10,7 +10,8 @@ use crate::{
function::{ArgIterable, FuncArgs, OptionalArg, OptionalOption},
sliceable::PySliceableSequence,
slots::{
Comparable, Hashable, Iterable, IteratorIterable, PyComparisonOp, PyIter, SlotConstructor,
Comparable, Hashable, Iterable, IteratorIterable, PyComparisonOp, SlotConstructor,
SlotIterator,
},
utils::Either,
IdProtocol, IntoPyObject, ItemProtocol, PyClassDef, PyClassImpl, PyComparisonValue, PyContext,
@@ -179,7 +180,7 @@ impl PyValue for PyStrIterator {
}
}
#[pyimpl(with(PyIter))]
#[pyimpl(with(SlotIterator))]
impl PyStrIterator {
#[pymethod(magic)]
fn length_hint(&self) -> usize {
@@ -228,7 +229,7 @@ impl PyStrIterator {
}
impl IteratorIterable for PyStrIterator {}
impl PyIter for PyStrIterator {
impl SlotIterator for PyStrIterator {
fn next(zelf: &PyRef<Self>, vm: &VirtualMachine) -> PyResult {
if let Exhausted = zelf.status.load() {
return Err(vm.new_stop_iteration());

View File

@@ -3,7 +3,7 @@ use crate::common::hash::PyHash;
use crate::{
function::{FuncArgs, OptionalArg},
iterator,
slots::{Comparable, Hashable, Iterable, IteratorIterable, PyComparisonOp, PyIter},
slots::{Comparable, Hashable, Iterable, IteratorIterable, PyComparisonOp, SlotIterator},
IdProtocol, IntoPyRef, PyClassImpl, PyContext, PyObjectRef, PyRef, PyResult, PyValue,
TryFromObject, TypeProtocol, VirtualMachine,
};
@@ -478,7 +478,7 @@ impl PyValue for PyLongRangeIterator {
}
}
#[pyimpl(with(PyIter))]
#[pyimpl(with(SlotIterator))]
impl PyLongRangeIterator {
#[pyslot]
fn slot_new(_cls: PyTypeRef, _args: FuncArgs, vm: &VirtualMachine) -> PyResult {
@@ -514,7 +514,7 @@ impl PyLongRangeIterator {
}
impl IteratorIterable for PyLongRangeIterator {}
impl PyIter for PyLongRangeIterator {
impl SlotIterator for PyLongRangeIterator {
fn next(zelf: &PyRef<Self>, vm: &VirtualMachine) -> PyResult {
// TODO: In pathological case (index == usize::MAX) this can wrap around
// (since fetch_add wraps). This would result in the iterator spinning again
@@ -547,7 +547,7 @@ impl PyValue for PyRangeIterator {
}
}
#[pyimpl(with(PyIter))]
#[pyimpl(with(SlotIterator))]
impl PyRangeIterator {
#[pyslot]
fn slot_new(_cls: PyTypeRef, _args: FuncArgs, vm: &VirtualMachine) -> PyResult {
@@ -584,7 +584,7 @@ impl PyRangeIterator {
}
impl IteratorIterable for PyRangeIterator {}
impl PyIter for PyRangeIterator {
impl SlotIterator for PyRangeIterator {
fn next(zelf: &PyRef<Self>, vm: &VirtualMachine) -> PyResult {
// TODO: In pathological case (index == usize::MAX) this can wrap around
// (since fetch_add wraps). This would result in the iterator spinning again

View File

@@ -7,8 +7,8 @@ use crate::{
dictdatatype::{self, DictSize},
function::{ArgIterable, FuncArgs, OptionalArg, PosArgs},
slots::{
Comparable, Hashable, Iterable, IteratorIterable, PyComparisonOp, PyIter, SlotConstructor,
Unhashable,
Comparable, Hashable, Iterable, IteratorIterable, PyComparisonOp, SlotConstructor,
SlotIterator, Unhashable,
},
vm::{ReprGuard, VirtualMachine},
IdProtocol, PyClassImpl, PyComparisonValue, PyContext, PyObjectRef, PyRef, PyResult, PyValue,
@@ -833,7 +833,7 @@ impl PyValue for PySetIterator {
}
}
#[pyimpl(with(PyIter))]
#[pyimpl(with(SlotIterator))]
impl PySetIterator {
#[pymethod(magic)]
fn length_hint(&self) -> usize {
@@ -862,7 +862,7 @@ impl PySetIterator {
}
impl IteratorIterable for PySetIterator {}
impl PyIter for PySetIterator {
impl SlotIterator for PySetIterator {
fn next(zelf: &PyRef<Self>, vm: &VirtualMachine) -> PyResult {
match zelf.status.load() {
IterStatus::Exhausted => Err(vm.new_stop_iteration()),

View File

@@ -9,7 +9,8 @@ use crate::{
sequence::{self, SimpleSeq},
sliceable::PySliceableSequence,
slots::{
Comparable, Hashable, Iterable, IteratorIterable, PyComparisonOp, PyIter, SlotConstructor,
Comparable, Hashable, Iterable, IteratorIterable, PyComparisonOp, SlotConstructor,
SlotIterator,
},
utils::Either,
vm::{ReprGuard, VirtualMachine},
@@ -330,7 +331,7 @@ impl PyValue for PyTupleIterator {
}
}
#[pyimpl(with(PyIter))]
#[pyimpl(with(SlotIterator))]
impl PyTupleIterator {
#[pymethod(magic)]
fn length_hint(&self) -> usize {
@@ -376,7 +377,7 @@ impl PyTupleIterator {
}
impl IteratorIterable for PyTupleIterator {}
impl PyIter for PyTupleIterator {
impl SlotIterator for PyTupleIterator {
fn next(zelf: &PyRef<Self>, vm: &VirtualMachine) -> PyResult {
if let Exhausted = zelf.status.load() {
return Err(vm.new_stop_iteration());

View File

@@ -2,7 +2,7 @@ use super::PyTypeRef;
use crate::{
function::PosArgs,
iterator,
slots::{IteratorIterable, PyIter, SlotConstructor},
slots::{IteratorIterable, SlotConstructor, SlotIterator},
PyClassImpl, PyContext, PyObjectRef, PyRef, PyResult, PyValue, VirtualMachine,
};
@@ -30,11 +30,11 @@ impl SlotConstructor for PyZip {
}
}
#[pyimpl(with(PyIter, SlotConstructor), flags(BASETYPE))]
#[pyimpl(with(SlotIterator, SlotConstructor), flags(BASETYPE))]
impl PyZip {}
impl IteratorIterable for PyZip {}
impl PyIter for PyZip {
impl SlotIterator for PyZip {
fn next(zelf: &PyRef<Self>, vm: &VirtualMachine) -> PyResult {
if zelf.iterators.is_empty() {
Err(vm.new_stop_iteration())

View File

@@ -548,7 +548,7 @@ pub trait Iterable: PyValue {
}
#[pyimpl(with(Iterable))]
pub trait PyIter: PyValue + Iterable {
pub trait SlotIterator: PyValue + Iterable {
#[pyslot]
fn slot_iternext(zelf: &PyObjectRef, vm: &VirtualMachine) -> PyResult {
if let Some(zelf) = zelf.downcast_ref() {

View File

@@ -19,8 +19,8 @@ mod array {
protocol::{BufferInternal, BufferOptions, PyBuffer, ResizeGuard},
sliceable::{saturate_index, PySliceableSequence, PySliceableSequenceMut, SequenceIndex},
slots::{
AsBuffer, Comparable, Iterable, IteratorIterable, PyComparisonOp, PyIter,
SlotConstructor,
AsBuffer, Comparable, Iterable, IteratorIterable, PyComparisonOp, SlotConstructor,
SlotIterator,
},
IdProtocol, IntoPyObject, IntoPyResult, PyComparisonValue, PyObjectRef, PyRef, PyResult,
PyValue, TryFromObject, TypeProtocol, VirtualMachine,
@@ -1193,11 +1193,11 @@ mod array {
array: PyArrayRef,
}
#[pyimpl(with(PyIter))]
#[pyimpl(with(SlotIterator))]
impl PyArrayIter {}
impl IteratorIterable for PyArrayIter {}
impl PyIter for PyArrayIter {
impl SlotIterator for PyArrayIter {
fn next(zelf: &PyRef<Self>, vm: &VirtualMachine) -> PyResult {
let pos = zelf.position.fetch_add(1);
if let Some(item) = zelf.array.read().getitem_by_idx(pos, vm)? {

View File

@@ -11,8 +11,8 @@ mod _collections {
function::{FuncArgs, KwArgs, OptionalArg},
sequence, sliceable,
slots::{
Comparable, Hashable, Iterable, IteratorIterable, PyComparisonOp, PyIter,
SlotConstructor, Unhashable,
Comparable, Hashable, Iterable, IteratorIterable, PyComparisonOp, SlotConstructor,
SlotIterator, Unhashable,
},
vm::ReprGuard,
PyComparisonValue, PyObjectRef, PyRef, PyResult, PyValue, TypeProtocol, VirtualMachine,
@@ -609,7 +609,7 @@ mod _collections {
}
}
#[pyimpl(with(PyIter, SlotConstructor))]
#[pyimpl(with(SlotIterator, SlotConstructor))]
impl PyDequeIterator {
pub(crate) fn new(deque: PyDequeRef) -> Self {
PyDequeIterator {
@@ -641,7 +641,7 @@ mod _collections {
}
impl IteratorIterable for PyDequeIterator {}
impl PyIter for PyDequeIterator {
impl SlotIterator for PyDequeIterator {
fn next(zelf: &PyRef<Self>, vm: &VirtualMachine) -> PyResult {
match zelf.status.load() {
Exhausted => Err(vm.new_stop_iteration()),
@@ -698,7 +698,7 @@ mod _collections {
}
}
#[pyimpl(with(PyIter, SlotConstructor))]
#[pyimpl(with(SlotIterator, SlotConstructor))]
impl PyReverseDequeIterator {
#[pymethod(magic)]
fn length_hint(&self) -> usize {
@@ -721,7 +721,7 @@ mod _collections {
}
impl IteratorIterable for PyReverseDequeIterator {}
impl PyIter for PyReverseDequeIterator {
impl SlotIterator for PyReverseDequeIterator {
fn next(zelf: &PyRef<Self>, vm: &VirtualMachine) -> PyResult {
match zelf.status.load() {
Exhausted => Err(vm.new_stop_iteration()),

View File

@@ -3,7 +3,7 @@ use crate::{
builtins::{PyStr, PyStrRef},
function::{ArgIterable, ArgumentError, FromArgs, FuncArgs},
iterator,
slots::{IteratorIterable, PyIter},
slots::{IteratorIterable, SlotIterator},
types::create_simple_type,
PyClassImpl, PyObjectRef, PyRef, PyResult, PyValue, TryFromObject, TypeProtocol,
VirtualMachine,
@@ -95,10 +95,10 @@ impl fmt::Debug for Reader {
}
}
#[pyimpl(with(PyIter))]
#[pyimpl(with(SlotIterator))]
impl Reader {}
impl IteratorIterable for Reader {}
impl PyIter for Reader {
impl SlotIterator for Reader {
fn next(zelf: &PyRef<Self>, vm: &VirtualMachine) -> PyResult {
let string = iterator::call_next(vm, &zelf.iter)?;
let string = string.downcast::<PyStr>().map_err(|obj| {

View File

@@ -86,7 +86,7 @@ mod _io {
ArgBytesLike, ArgIterable, ArgMemoryBuffer, FuncArgs, OptionalArg, OptionalOption,
},
protocol::{BufferInternal, BufferOptions, PyBuffer, ResizeGuard},
slots::{Iterable, PyIter, SlotConstructor},
slots::{Iterable, SlotConstructor, SlotIterator},
utils::Either,
vm::{ReprGuard, VirtualMachine},
IdProtocol, IntoPyObject, PyContext, PyObjectRef, PyRef, PyResult, PyValue, StaticType,
@@ -344,7 +344,7 @@ mod _io {
#[derive(Debug, PyValue)]
struct _IOBase;
#[pyimpl(with(PyIter), flags(BASETYPE, HAS_DICT))]
#[pyimpl(with(SlotIterator), flags(BASETYPE, HAS_DICT))]
impl _IOBase {
#[pymethod]
fn seek(
@@ -523,7 +523,7 @@ mod _io {
}
}
impl PyIter for _IOBase {
impl SlotIterator for _IOBase {
fn slot_iternext(zelf: &PyObjectRef, vm: &VirtualMachine) -> PyResult {
let line = vm.call_method(zelf, "readline", ())?;
if !line.clone().try_to_bool(vm)? {

View File

@@ -10,7 +10,7 @@ mod decl {
builtins::{int, PyInt, PyIntRef, PyTupleRef, PyTypeRef},
function::{ArgCallable, FuncArgs, OptionalArg, OptionalOption, PosArgs},
iterator::{call_next, get_iter, get_next_object},
slots::{IteratorIterable, PyIter, SlotConstructor},
slots::{IteratorIterable, SlotConstructor, SlotIterator},
IdProtocol, IntoPyObject, PyObjectRef, PyRef, PyResult, PyValue, PyWeakRef, TypeProtocol,
VirtualMachine,
};
@@ -28,7 +28,7 @@ mod decl {
cached_iter: PyRwLock<Option<PyObjectRef>>,
}
#[pyimpl(with(PyIter))]
#[pyimpl(with(SlotIterator))]
impl PyItertoolsChain {
#[pyslot]
fn slot_new(cls: PyTypeRef, args: FuncArgs, vm: &VirtualMachine) -> PyResult {
@@ -55,7 +55,7 @@ mod decl {
}
}
impl IteratorIterable for PyItertoolsChain {}
impl PyIter for PyItertoolsChain {
impl SlotIterator for PyItertoolsChain {
fn next(zelf: &PyRef<Self>, vm: &VirtualMachine) -> PyResult {
loop {
let pos = zelf.cur_idx.load();
@@ -127,11 +127,11 @@ mod decl {
}
}
#[pyimpl(with(PyIter, SlotConstructor))]
#[pyimpl(with(SlotIterator, SlotConstructor))]
impl PyItertoolsCompress {}
impl IteratorIterable for PyItertoolsCompress {}
impl PyIter for PyItertoolsCompress {
impl SlotIterator for PyItertoolsCompress {
fn next(zelf: &PyRef<Self>, vm: &VirtualMachine) -> PyResult {
loop {
let sel_obj = call_next(vm, &zelf.selector)?;
@@ -187,10 +187,10 @@ mod decl {
}
}
#[pyimpl(with(PyIter, SlotConstructor))]
#[pyimpl(with(SlotIterator, SlotConstructor))]
impl PyItertoolsCount {}
impl IteratorIterable for PyItertoolsCount {}
impl PyIter for PyItertoolsCount {
impl SlotIterator for PyItertoolsCount {
fn next(zelf: &PyRef<Self>, vm: &VirtualMachine) -> PyResult {
let mut cur = zelf.cur.write();
let result = cur.clone();
@@ -223,10 +223,10 @@ mod decl {
}
}
#[pyimpl(with(PyIter, SlotConstructor))]
#[pyimpl(with(SlotIterator, SlotConstructor))]
impl PyItertoolsCycle {}
impl IteratorIterable for PyItertoolsCycle {}
impl PyIter for PyItertoolsCycle {
impl SlotIterator for PyItertoolsCycle {
fn next(zelf: &PyRef<Self>, vm: &VirtualMachine) -> PyResult {
let item = if let Some(item) = get_next_object(vm, &zelf.iter)? {
zelf.saved.write().push(item.clone());
@@ -288,7 +288,7 @@ mod decl {
}
}
#[pyimpl(with(PyIter, SlotConstructor), flags(BASETYPE))]
#[pyimpl(with(SlotIterator, SlotConstructor), flags(BASETYPE))]
impl PyItertoolsRepeat {
#[pymethod(magic)]
fn length_hint(&self, vm: &VirtualMachine) -> PyResult {
@@ -327,7 +327,7 @@ mod decl {
}
impl IteratorIterable for PyItertoolsRepeat {}
impl PyIter for PyItertoolsRepeat {
impl SlotIterator for PyItertoolsRepeat {
fn next(zelf: &PyRef<Self>, vm: &VirtualMachine) -> PyResult {
if let Some(ref times) = zelf.times {
let mut times = times.write();
@@ -370,10 +370,10 @@ mod decl {
}
}
#[pyimpl(with(PyIter, SlotConstructor))]
#[pyimpl(with(SlotIterator, SlotConstructor))]
impl PyItertoolsStarmap {}
impl IteratorIterable for PyItertoolsStarmap {}
impl PyIter for PyItertoolsStarmap {
impl SlotIterator for PyItertoolsStarmap {
fn next(zelf: &PyRef<Self>, vm: &VirtualMachine) -> PyResult {
let obj = call_next(vm, &zelf.iter)?;
let function = &zelf.function;
@@ -421,10 +421,10 @@ mod decl {
}
}
#[pyimpl(with(PyIter, SlotConstructor))]
#[pyimpl(with(SlotIterator, SlotConstructor))]
impl PyItertoolsTakewhile {}
impl IteratorIterable for PyItertoolsTakewhile {}
impl PyIter for PyItertoolsTakewhile {
impl SlotIterator for PyItertoolsTakewhile {
fn next(zelf: &PyRef<Self>, vm: &VirtualMachine) -> PyResult {
if zelf.stop_flag.load() {
return Err(vm.new_stop_iteration());
@@ -484,10 +484,10 @@ mod decl {
}
}
#[pyimpl(with(PyIter, SlotConstructor))]
#[pyimpl(with(SlotIterator, SlotConstructor))]
impl PyItertoolsDropwhile {}
impl IteratorIterable for PyItertoolsDropwhile {}
impl PyIter for PyItertoolsDropwhile {
impl SlotIterator for PyItertoolsDropwhile {
fn next(zelf: &PyRef<Self>, vm: &VirtualMachine) -> PyResult {
let predicate = &zelf.predicate;
let iterable = &zelf.iterable;
@@ -579,7 +579,7 @@ mod decl {
}
}
#[pyimpl(with(PyIter, SlotConstructor))]
#[pyimpl(with(SlotIterator, SlotConstructor))]
impl PyItertoolsGroupBy {
pub(super) fn advance(&self, vm: &VirtualMachine) -> PyResult<(PyObjectRef, PyObjectRef)> {
let new_value = call_next(vm, &self.iterable)?;
@@ -592,7 +592,7 @@ mod decl {
}
}
impl IteratorIterable for PyItertoolsGroupBy {}
impl PyIter for PyItertoolsGroupBy {
impl SlotIterator for PyItertoolsGroupBy {
fn next(zelf: &PyRef<Self>, vm: &VirtualMachine) -> PyResult {
let mut state = zelf.state.lock();
state.grouper = None;
@@ -639,10 +639,10 @@ mod decl {
type PyItertoolsGrouperRef = PyRef<PyItertoolsGrouper>;
#[pyimpl(with(PyIter))]
#[pyimpl(with(SlotIterator))]
impl PyItertoolsGrouper {}
impl IteratorIterable for PyItertoolsGrouper {}
impl PyIter for PyItertoolsGrouper {
impl SlotIterator for PyItertoolsGrouper {
fn next(zelf: &PyRef<Self>, vm: &VirtualMachine) -> PyResult {
let old_key = {
let mut state = zelf.groupby.state.lock();
@@ -707,7 +707,7 @@ mod decl {
)));
}
#[pyimpl(with(PyIter))]
#[pyimpl(with(SlotIterator))]
impl PyItertoolsIslice {
#[pyslot]
fn slot_new(cls: PyTypeRef, args: FuncArgs, vm: &VirtualMachine) -> PyResult {
@@ -772,7 +772,7 @@ mod decl {
}
impl IteratorIterable for PyItertoolsIslice {}
impl PyIter for PyItertoolsIslice {
impl SlotIterator for PyItertoolsIslice {
fn next(zelf: &PyRef<Self>, vm: &VirtualMachine) -> PyResult {
while zelf.cur.load() < zelf.next.load() {
call_next(vm, &zelf.iterable)?;
@@ -833,10 +833,10 @@ mod decl {
}
}
#[pyimpl(with(PyIter, SlotConstructor))]
#[pyimpl(with(SlotIterator, SlotConstructor))]
impl PyItertoolsFilterFalse {}
impl IteratorIterable for PyItertoolsFilterFalse {}
impl PyIter for PyItertoolsFilterFalse {
impl SlotIterator for PyItertoolsFilterFalse {
fn next(zelf: &PyRef<Self>, vm: &VirtualMachine) -> PyResult {
let predicate = &zelf.predicate;
let iterable = &zelf.iterable;
@@ -891,11 +891,11 @@ mod decl {
}
}
#[pyimpl(with(PyIter, SlotConstructor))]
#[pyimpl(with(SlotIterator, SlotConstructor))]
impl PyItertoolsAccumulate {}
impl IteratorIterable for PyItertoolsAccumulate {}
impl PyIter for PyItertoolsAccumulate {
impl SlotIterator for PyItertoolsAccumulate {
fn next(zelf: &PyRef<Self>, vm: &VirtualMachine) -> PyResult {
let iterable = &zelf.iterable;
@@ -987,7 +987,7 @@ mod decl {
}
}
#[pyimpl(with(PyIter, SlotConstructor))]
#[pyimpl(with(SlotIterator, SlotConstructor))]
impl PyItertoolsTee {
fn from_iter(iterable: PyObjectRef, vm: &VirtualMachine) -> PyResult {
let class = PyItertoolsTee::class(vm);
@@ -1014,7 +1014,7 @@ mod decl {
}
}
impl IteratorIterable for PyItertoolsTee {}
impl PyIter for PyItertoolsTee {
impl SlotIterator for PyItertoolsTee {
fn next(zelf: &PyRef<Self>, vm: &VirtualMachine) -> PyResult {
let value = zelf.tee_data.get_item(vm, zelf.index.load())?;
zelf.index.fetch_add(1);
@@ -1064,7 +1064,7 @@ mod decl {
}
}
#[pyimpl(with(PyIter, SlotConstructor))]
#[pyimpl(with(SlotIterator, SlotConstructor))]
impl PyItertoolsProduct {
fn update_idxs(&self, mut idxs: PyRwLockWriteGuard<'_, Vec<usize>>) {
if idxs.len() == 0 {
@@ -1090,7 +1090,7 @@ mod decl {
}
}
impl IteratorIterable for PyItertoolsProduct {}
impl PyIter for PyItertoolsProduct {
impl SlotIterator for PyItertoolsProduct {
fn next(zelf: &PyRef<Self>, vm: &VirtualMachine) -> PyResult {
// stop signal
if zelf.stop.load() {
@@ -1166,10 +1166,10 @@ mod decl {
}
}
#[pyimpl(with(PyIter, SlotConstructor))]
#[pyimpl(with(SlotIterator, SlotConstructor))]
impl PyItertoolsCombinations {}
impl IteratorIterable for PyItertoolsCombinations {}
impl PyIter for PyItertoolsCombinations {
impl SlotIterator for PyItertoolsCombinations {
fn next(zelf: &PyRef<Self>, vm: &VirtualMachine) -> PyResult {
// stop signal
if zelf.exhausted.load() {
@@ -1256,11 +1256,11 @@ mod decl {
}
}
#[pyimpl(with(PyIter, SlotConstructor))]
#[pyimpl(with(SlotIterator, SlotConstructor))]
impl PyItertoolsCombinationsWithReplacement {}
impl IteratorIterable for PyItertoolsCombinationsWithReplacement {}
impl PyIter for PyItertoolsCombinationsWithReplacement {
impl SlotIterator for PyItertoolsCombinationsWithReplacement {
fn next(zelf: &PyRef<Self>, vm: &VirtualMachine) -> PyResult {
// stop signal
if zelf.exhausted.load() {
@@ -1365,10 +1365,10 @@ mod decl {
}
}
#[pyimpl(with(PyIter, SlotConstructor))]
#[pyimpl(with(SlotIterator, SlotConstructor))]
impl PyItertoolsPermutations {}
impl IteratorIterable for PyItertoolsPermutations {}
impl PyIter for PyItertoolsPermutations {
impl SlotIterator for PyItertoolsPermutations {
fn next(zelf: &PyRef<Self>, vm: &VirtualMachine) -> PyResult {
// stop signal
if zelf.exhausted.load() {
@@ -1467,10 +1467,10 @@ mod decl {
fillvalue: PyObjectRef,
}
#[pyimpl(with(PyIter, SlotConstructor))]
#[pyimpl(with(SlotIterator, SlotConstructor))]
impl PyItertoolsZipLongest {}
impl IteratorIterable for PyItertoolsZipLongest {}
impl PyIter for PyItertoolsZipLongest {
impl SlotIterator for PyItertoolsZipLongest {
fn next(zelf: &PyRef<Self>, vm: &VirtualMachine) -> PyResult {
if zelf.iterators.is_empty() {
Err(vm.new_stop_iteration())
@@ -1521,10 +1521,10 @@ mod decl {
}
}
#[pyimpl(with(PyIter, SlotConstructor))]
#[pyimpl(with(SlotIterator, SlotConstructor))]
impl PyItertoolsPairwise {}
impl IteratorIterable for PyItertoolsPairwise {}
impl PyIter for PyItertoolsPairwise {
impl SlotIterator for PyItertoolsPairwise {
fn next(zelf: &PyRef<Self>, vm: &VirtualMachine) -> PyResult {
let old = match zelf.old.read().clone() {
None => call_next(vm, &zelf.iterator)?,

View File

@@ -406,7 +406,7 @@ pub(super) mod _os {
crt_fd::{Fd, Offset},
exceptions::IntoPyException,
function::{ArgBytesLike, FuncArgs, OptionalArg},
slots::{IteratorIterable, PyIter},
slots::{IteratorIterable, SlotIterator},
suppress_iph,
utils::Either,
vm::{ReprGuard, VirtualMachine},
@@ -855,7 +855,7 @@ pub(super) mod _os {
mode: OutputMode,
}
#[pyimpl(with(PyIter))]
#[pyimpl(with(SlotIterator))]
impl ScandirIterator {
#[pymethod]
fn close(&self) {
@@ -873,7 +873,7 @@ pub(super) mod _os {
}
}
impl IteratorIterable for ScandirIterator {}
impl PyIter for ScandirIterator {
impl SlotIterator for ScandirIterator {
fn next(zelf: &PyRef<Self>, vm: &VirtualMachine) -> PyResult {
if zelf.exhausted.load() {
return Err(vm.new_stop_iteration());

View File

@@ -18,7 +18,7 @@ pub(crate) mod _struct {
},
common::str::wchar_t,
function::{ArgBytesLike, ArgMemoryBuffer, PosArgs},
slots::{IteratorIterable, PyIter, SlotConstructor},
slots::{IteratorIterable, SlotConstructor, SlotIterator},
utils::Either,
IntoPyObject, PyObjectRef, PyRef, PyResult, PyValue, TryFromObject, VirtualMachine,
};
@@ -823,7 +823,7 @@ pub(crate) mod _struct {
}
}
#[pyimpl(with(PyIter))]
#[pyimpl(with(SlotIterator))]
impl UnpackIterator {
#[pymethod(magic)]
fn length_hint(&self) -> usize {
@@ -831,7 +831,7 @@ pub(crate) mod _struct {
}
}
impl IteratorIterable for UnpackIterator {}
impl PyIter for UnpackIterator {
impl SlotIterator for UnpackIterator {
fn next(zelf: &PyRef<Self>, vm: &VirtualMachine) -> PyResult {
let size = zelf.format_spec.size;
let offset = zelf.offset.fetch_add(size);

View File

@@ -9,7 +9,7 @@ use wasm_bindgen_futures::{future_to_promise, JsFuture};
use rustpython_vm::builtins::PyBaseExceptionRef;
use rustpython_vm::builtins::{PyFloatRef, PyStrRef, PyTypeRef};
use rustpython_vm::function::{OptionalArg, OptionalOption, PosArgs};
use rustpython_vm::slots::{IteratorIterable, PyIter};
use rustpython_vm::slots::{IteratorIterable, SlotIterator};
use rustpython_vm::types::create_simple_type;
use rustpython_vm::VirtualMachine;
use rustpython_vm::{
@@ -549,7 +549,7 @@ impl fmt::Debug for AwaitPromise {
}
}
#[pyimpl(with(PyIter))]
#[pyimpl(with(SlotIterator))]
impl AwaitPromise {
#[pymethod]
fn send(&self, val: Option<PyObjectRef>, vm: &VirtualMachine) -> PyResult {
@@ -588,7 +588,7 @@ impl AwaitPromise {
}
impl IteratorIterable for AwaitPromise {}
impl PyIter for AwaitPromise {
impl SlotIterator for AwaitPromise {
fn next(zelf: &PyRef<Self>, vm: &VirtualMachine) -> PyResult {
zelf.send(None, vm)
}