-
Notifications
You must be signed in to change notification settings - Fork 53
Description
Discussed in #392
Originally posted by markshannon May 20, 2022
Much like we have "virtual bound-methods" for calls to methods, we could have "virtual iterators" for iteration over sequences.
The LOAD_METHOD instruction pushes NULL func or func self to the stack, the latter being a representation of the bound-method types.MethodType(func, self).
We could do something similar for GET_ITER.
For non-sequence iterators, like range, generators etc, it would push NULL iter. For sequences, it would push seq 0.
The behavior of FOR_ITER would depend on whether SECOND is NULL.
NULL: Pushnext(iter)- Not
NULL: Pop index; pushindex+1; pushseq[index]
If we allow unboxed integers on the stack, then this could be reasonably efficient with specialization.
For this to be useful, we would need have tagged integers on the stack.
I doubt it would be worth implementing tagged ints just for this, but if we had tagged values for another reason, e.g. deferred reference counts, then it could be a worthwhile enhancement.