Search code examples
pythongeneratorpypyrpython

are generators supported in RPython?


Are generators supported in RPython, because I just read something in PyPy's documentation that says they are not

PyPy Doc - Coding Guide

They seem easy to be translated to a statically typed language like C because every generation step is generated in function call.

Can someone explain why ? Or shed some more light on the subject. I am currently trying to learn the basics of writing RPython safe code.


Solution

  • Generators are not supported simply because they were not needed at the time. The problem is not really having a roughly equivalent functionality in C, but needing to keep a frame of generator alive. Since RPython frames are translated to C frames, to support full python generators you would need some support for getting C frame and copy it somewhere else, or some equivalent.

    This was simply hard/not needed and was not implemented.