@@ -119,6 +119,9 @@ iterator_printrepr(DeeObject *__restrict self,
119119
120120/* A default-constructed, raw iterator object behaves as empty. */
121121STATIC_ASSERT_MSG ((size_t )(uintptr_t )ITER_DONE == (size_t )-1 , "Assumed by definition of `iterator_iternext'" );
122+ #ifndef DCALL_RETURN_COMMON
123+ STATIC_ASSERT_MSG (sizeof (size_t ) == sizeof (void * ), "Assumed by definition of `iterator_iternext'" );
124+ #endif /* !DCALL_RETURN_COMMON */
122125#define iterator_iternext (*(DREF DeeObject *(DCALL *)(DeeObject *__restrict))&_DeeNone_retsm1_1)
123126
124127PRIVATE WUNUSED NONNULL ((1 )) size_t DCALL
@@ -300,7 +303,7 @@ PRIVATE struct type_method tpconst iterator_methods[] = {
300303 TYPE_METHOD_END
301304};
302305
303- INTDEF WUNUSED NONNULL ((1 )) DREF DeeObject * DCALL IteratorFuture_For (DeeObject * __restrict self );
306+ INTDEF WUNUSED NONNULL ((1 )) DREF DeeObject * DCALL IteratorFuture_Of (DeeObject * __restrict self );
304307INTDEF WUNUSED NONNULL ((1 )) DREF DeeObject * DCALL IteratorPending_For (DeeObject * __restrict self );
305308
306309PRIVATE WUNUSED NONNULL ((1 )) DREF DeeObject * DCALL
@@ -339,48 +342,10 @@ PRIVATE struct type_getset tpconst iterator_getsets[] = {
339342 & DeeMA_Iterator_index_set ,
340343 DeeMA_Iterator_index_flags ,
341344 "->?Dint\n"
342- "#tNotImplemented{@this Iterator isn't bi-directional (s.a. ?#isbidirectional)}"
343- "Get/set the current sequence index of @this Iterator\n"
344- "Note however that depending on the type of sequence, certain indices "
345- /**/ "may not have values bound to them. When invoked, ?#{op:next} usually skips "
346- /**/ "ahead to the first bound index, meaning that ?#{op:next} does not necessarily "
347- /**/ "increment the index counter linearly\n"
348- "${"
349- /**/ "property index: int = {\n"
350- /**/ " get(): int {\n"
351- /**/ " local result = 0;\n"
352- /**/ " local c;\n"
353- /**/ " for (local tp: type(this).__mro__) {\n"
354- /**/ " if (tp === Iterator)\n"
355- /**/ " break;\n"
356- /**/ " if (tp.hasprivateattribute(\"rewind\")) {\n"
357- /**/ " c = copy this;\n"
358- /**/ " c.rewind();\n"
359- /**/ " goto got_rewound_iter;\n"
360- /**/ " }\n"
361- /**/ " if (tp.hasprivateattribute(\"seq\")) {\n"
362- /**/ " c = this.seq.operator iter();\n"
363- /**/ " goto got_rewound_iter;\n"
364- /**/ " }\n"
365- /**/ " }\n"
366- /**/ " throw NotImplemented(\"...\");\n"
367- /**/ "got_rewound_iter:\n"
368- /**/ " while (c < this) {\n"
369- /**/ " ++c;\n"
370- /**/ " ++result;\n"
371- /**/ " }\n"
372- /**/ " return result;\n"
373- /**/ " }\n"
374- /**/ " set(index: int) {\n"
375- /**/ " index = index.operator int();\n"
376- /**/ " this.rewind();\n"
377- /**/ " this.advance(index);\n"
378- /**/ " }\n"
379- /**/ "}"
380- "}" ),
345+ "TODO" ),
381346
382347
383- TYPE_GETTER_AB ("future" , & IteratorFuture_For ,
348+ TYPE_GETTER_AB ("future" , & IteratorFuture_Of ,
384349 "->?DSequence\n"
385350 "Returns an abstract sequence proxy that always refers to the items that are "
386351 /**/ "still left to be yielded by @this Iterator. Note that for this to function "
@@ -656,69 +621,58 @@ PRIVATE char const iter_doc[] =
656621"${"
657622/**/ "operator bool() {\n"
658623/**/ " local c = copy this;\n"
659- /**/ " return try ({\n"
660- /**/ " c.operator next();\n"
661- /**/ " true;\n"
662- /**/ " }) catch (StopIteration from errors) (\n"
663- /**/ " false\n"
664- /**/ " );\n"
624+ /**/ " foreach (none: c)\n"
625+ /**/ " return true;\n"
626+ /**/ " return false;\n"
665627/**/ "}"
666628"}\n"
667629"\n"
668630
669631"+(step:?Dint)->\n"
670- "#tNotImplemented{@step is negative, and @this Iterator isn't bi-directional (s.a. ?#isbidirectional)}"
671- "#tIntegerOverflow{@step is too large}"
672- "Copies @this Iterator and advance it by yielding @step items from it before returning it\n"
673- "If the Iterator becomes exhausted before then, stop and return that exhausted iterator\n"
632+ "#tNotImplemented{@step is negative, and @this Iterator does not support ?#revert}"
633+ "#tIntegerOverflow{@step is too great or too small}"
634+ "Copies @this Iterator and ?#advance (or ?#revert when ${step < 0}) it by @step items.\n"
674635"\n"
675636
676- "+=(step:?Dint)->\n"
677- "#tNotImplemented{@step is negative, and @this Iterator isn't bi-directional (s.a. ?#isbidirectional)}"
678- "#tIntegerOverflow{@step is too large}"
679- "Advance @this Iterator by yielding @step items\n"
680- "If @this Iterator becomes exhausted before then, stop prematurely\n"
637+ "-(step:?Dint)->\n"
638+ "#tNotImplemented{@step is positive, and @this Iterator does not support ?#revert}"
639+ "#tIntegerOverflow{@step is too great or too small}"
640+ "Copies @this Iterator and ?#revert (or ?#advance when ${step < 0}) it by @step items.\n"
681641"\n"
682642
683- "++ ->\n"
684- "Advance @this Iterator by one. No-op if the Iterator has been exhausted\n "
685- "Note this is very similar to ?#{op:next}, however in the case of generator-like "
686- /**/ "iterators, doing this may be faster since no generator value has to be created \n"
643+ "+=(step:?Dint) ->\n"
644+ "#tNotImplemented{@step is negative, and @this Iterator does not support ?#revert} "
645+ "#tIntegerOverflow{@step is too great or too small} "
646+ "?#advance (or ?#revert when ${step < 0}) @this Iterator by @step items. \n"
687647"\n"
688648
689- "call(def?)->\n"
690- "Calling an operator as a function will invoke ${operator next}, and return "
691- /**/ "that value, allowing iterators to be used as function-like producers\n"
692- "${"
693- /**/ "operator call(def?) {\n"
694- /**/ " try {\n"
695- /**/ " return this.operator next();\n"
696- /**/ " } catch (StopIteration) {\n"
697- /**/ " if (def is bound)\n"
698- /**/ " return def;\n"
699- /**/ " throw;\n"
700- /**/ " }\n"
701- /**/ "}"
702- "}\n"
649+ "-=(step:?Dint)->\n"
650+ "#tNotImplemented{@step is positive, and @this Iterator does not support ?#revert}"
651+ "#tIntegerOverflow{@step is too great or too small}"
652+ "?#revert (or ?#advance when ${step < 0}) @this Iterator by @step items.\n"
703653"\n"
704654
705- "-(step:?Dint)->\n"
706- "#tNotImplemented{@step is positive, and @this Iterator isn't bi-directional (s.a. ?#isbidirectional)}"
707- "#tIntegerOverflow{@step is too large}"
708- "Copies @this Iterator and reverts it by @step before returning it\n"
709- "If the Iterator reaches its starting position before then, stop prematurely\n"
655+ "++->\n"
656+ "Advance @this Iterator by one. No-op if the Iterator has been exhausted\n"
657+ "Same as ${foreach (none: this) break;} or just calling ?#next\n"
710658"\n"
711659
712660"--->\n"
713- "#tNotImplemented{@this Iterator isn 't bi-directional (s.a. ?#isbidirectional) }"
714- "Decrement @this operator by one. No-op if the Iterator is already at its starting position \n"
661+ "#tNotImplemented{@this Iterator doesn 't support ?#revert }"
662+ "Revert the iterator by 1 step (same as ${this.revert(1)}) \n"
715663"\n"
716664
717- "-=(step:?Dint)->\n"
718- "#tNotImplemented{@step is positive, and @this Iterator isn't bi-directional (s.a. ?#isbidirectional)}"
719- "#tIntegerOverflow{@step is too large}"
720- "Revert @this Iterator by @step items\n"
721- "If @this Iterator reaches its starting position before then, stop prematurely\n"
665+ "call(def?)->\n"
666+ "Same as ?#next\n"
667+ "${"
668+ /**/ "operator ()(def?) {\n"
669+ /**/ " foreach (local next: this)\n"
670+ /**/ " return next;\n"
671+ /**/ " if (def is bound)\n"
672+ /**/ " return def;\n"
673+ /**/ " throw StopIteration();\n"
674+ /**/ "}"
675+ "}\n"
722676"\n"
723677
724678"<->\n"
@@ -814,7 +768,7 @@ typedef struct {
814768
815769INTDEF DeeTypeObject IteratorFuture_Type ;
816770INTERN WUNUSED NONNULL ((1 )) DREF DeeObject * DCALL
817- IteratorFuture_For (DeeObject * __restrict self ) {
771+ IteratorFuture_Of (DeeObject * __restrict self ) {
818772 return Dee_AsObject (IteratorFuture_New (self ));
819773}
820774
0 commit comments