Implementing generators in Truffle
Wei Zhang
ndrzmansn at gmail.com
Tue May 6 00:01:27 UTC 2014
Hi Timothy,
I don't think there is Truffle level support for generators yet.
In ZipPy we encode the control flow state of a generator in the heap. When
resuming the generator uses the control flow data to resume to the right
node.
So there is an extra overhead to keep track of the program location for
generators.
The source code of generator related nodes in ZipPy:
https://bitbucket.org/ssllab/zippy/src/5d112f1b56877c656ebe00af16d35082ef09bd2e/graal/edu.uci.python.nodes/src/edu/uci/python/nodes/generator/?at=default
There is a refactoring going on, so not all the classes are well organized
as they should be...
Hope this is helpful.
Any further question is welcomed.
Thanks,
/Wei
On Mon, May 5, 2014 at 4:31 PM, Timothy Baldridge <tbaldridge at gmail.com>wrote:
> I'm mostly interested in this for creating cheap co-routines and/or
> generators in languages. I have a fair amount of experience with RPython
> and implementation of yield semantics in that language is rather straight
> forward. From my reading of the Truffle documentation it didn't seem to be
> so straightforward.
>
> So I'd prefer to have true delimited continuations where a yield in one
> function could bounce up through several frames (as exceptions do), but I
> could settle for Python/C# style "within this method only" support.
>
> Timothy
>
>
> On Mon, May 5, 2014 at 4:17 PM, Thomas Wuerthinger <
> thomas.wuerthinger at oracle.com> wrote:
>
>> Timothy,
>>
>> We have currently no support for continuations in Truffle - it is however
>> on the list of features we would like to add. Lukas Stadler (CC’d) has done
>> some work on continuations in the context of HotSpot that we plan to port.
>> Maybe you can provide us with some details on what kind of delimited
>> continuation system would fit your needs.
>>
>> The ZipPy guys (e.g., Wei Zhang, CC’d) have done some work on optimizing
>> generators in Truffle as they require high-performance generators for their
>> Python implementation. Maybe they can share with you some of their
>> experiences.
>>
>> - thomas
>>
>> On 05 May 2014, at 23:53, Timothy Baldridge <tbaldridge at gmail.com> wrote:
>>
>> > For a language I'm writing (based on Truffle) I would love to be able to
>> > support yield at a language level. What's the best way to go about
>> this? Am
>> > I stuck implementing yield via state machines like C# does, or is there
>> > some sort of delimited continuation system in Truffle?
>> >
>> > Thanks,
>> >
>> > Timothy
>>
>>
>
>
> --
> “One of the main causes of the fall of the Roman Empire was that–lacking
> zero–they had no way to indicate successful termination of their C
> programs.”
> (Robert Firth)
>
More information about the graal-dev
mailing list