Walter: any plan to add support for yield/return Iterators/generators?

Marcio mqmnews123 at sglebs.com
Wed Sep 6 09:34:46 PDT 2006


Steve Horne wrote:
> On Tue, 05 Sep 2006 21:24:39 -0400, Marcio <mqmnews123 at sglebs.com>
> wrote:
> 
>> Walter Bright wrote:
>>>> One of the things needed for sure is heap frames.
>>> That's right, instead of using the stack for the locals, the heap is 
>>> used. It isn't that much different from using a functor. In fact, now 
>>> that I think about it, a functor might be a better way to do it than yield.
>>
>> 	Smalltalk blocks, basically.
> 
> I don't think so.


	I was saying a functor would be a smalltalk block. But I still inquire 
if that is really enough for generators, and I am not sure. So, we are 
not disagreeing (you and me). Maybe we are disagreeing with Walter's 
claim that just a functor is enough.

	Having said that...

 > For each instance of a generator, you need a complete separate stack.
 > That stack is kept on the heap, separate from the normal processor
 > stack. Both have to be full stacks, since both contexts need to
 > support function calls - even recursion - independently. Even though
 > the generator itself is likely to be a single function with yields
 > done directly from itself, it still needs to call normal functions to
 > do its stuff.
 >

	... Perhaps the caller will see its runtime stack used by the generator 
as it runs until its next yield/return. So, the environments are 
maintained in the heap and survive the return (therefore values of 
variables are remembered) while the stack used between 2 yield/returns 
is borrowed from the caller's stack. So, in this case Walter would be right.

	Anyway, that is why I was curious about code generation tricks. I guess 
one can always use C# 2.0 and check the IL code it generates.


> But first, Walter needs to concentrate on achieving immortality, so he
> has time to do all this ;-)


	Exactly!! :-)

marcio



More information about the Digitalmars-d mailing list