Given the current :method and .yield implementations, the following code:
$ cat foo.pir
.sub main :main
$P1 = newclass 'foo'
$P2 = new 'foo'
$S1 = $P2.'bork'()
say $S1
$P3 = new 'foo'
$S1 = $P3.'bork'()
say $S1
.end
.namespace [ 'foo']
.sub bork :method
$I0 = 0
loop:
.yield($I0)
inc $I0
goto loop
.end
Generates the following output:
$ ./parrot foo.pir
0
1
Which is unsurprising given the current implementation. Is this desired
behavior, though?
I can work around this by storing an attribute on the class which keeps my
counter in the instance and then retrieving it with getattribute in the
loop, insuring that the state is pulled from the object instead of the
registers in the coroutine/method whenever the coroutine resumes.
Or we could have yield somehow be instance specific.
Regards.