Luke Palmer wrote: > > Benjamin Goldberg writes: [snip] > > 9/ New ops which provide access to the string iterator API. > > Yes. What is going to be used to store an iterator. An I reg, a P reg? > If it's a PMC, would it be possible to just implement the iterator > itself as a PMC, and use the standard iterator vtable methods (which > are?) for motion and dereferencing? Again, that involves a vtable > overhead and doesn't lend itself to JIT very well (which is very, very > important).
I envision that an iterator for a STRING* would be an INTVAL, but an iterator for a PerlString pmc would be an Iterator pmc. There are a number of reasons why INTVALs are best -- the most important ones being that they're *small*, and that we need do nothing at all in C code to prevent them from being garbage collected. Also, if STRING*s use INTVALs as their iterators, then PerlString can work with the Iterator.pmc class simply by wrapping these INTVALs inside Key.pmc objects, using key_new_integer. There are, alas, a few drawbacks to this. 1/ The algorithm needs to be designed so that these intvals are agnostic to the location of the string's location in memory -- if garbage collection moves the string's buffer, the iterator needs to remain valid. Thus, you can't use a pointer into the buffer which has been simply cast to an integer. (You *can*, however, subtract the start of the buffer from a pointer into the buffer, and then cast this ptrdiff_t into an INTVAL). 2/ If you need data more complex than an integer -- e.g., if your string's data is actually in some sort of tree, and you want to say, "the node at the end of the fourth branch from the twentieth branch from the firth branch from the root," then you're in trouble. Hmm, considering how much of a problem 2/ is, maybe we should use Key.pmc objects as our iterators? This would make PerlString's interface with Iterator even simpler. -- $a=24;split//,240513;s/\B/ => /for@@=qw(ac ab bc ba cb ca );{push(@b,$a),($a-=6)^=1 for 2..$a/6x--$|;print "[EMAIL PROTECTED] ]\n";((6<=($a-=6))?$a+=$_[$a%6]-$a%6:($a=pop @b))&&redo;}