You'll want to first look at GeneratorRewriter.cs - it's responsible for taking 
a DLR AST and re-writing it so that it can re-start at an arbitrary location 
and so that it's stackless.  There's one of these for debugging and one that's 
used for IronPython's generators, you can probably adapt either one.  You can 
get the AST to re-write from the function code object but that's not public 
right now (we'll make it public if anyone has a compelling scenario to do so - 
this could be it but you'll probably need more public surface area as well).

>From there I think you just need to worry about having to save multiple frames 
>(which I get the impression is supported from the docs - eg f() calls g() and 
>then g switches).  For that you'll probably want to re-write all of the 
>dynamic expressions in the generator (these show up in several forms though 
>based upon how we're generating code-  there's a ReduciableDynamicExpression 
>and some PythonDynamicExpression's floating around now).  If greenlets only 
>works across calls then you just need to intercept the ones which are using 
>invoke binders.  If you can have a descriptor who's __get__ or __set__ 
>switches then you'd also need to handle gets/sets/etc...  If you can do 
>something like import a module which hasn't been loaded yet and then have the 
>top-level module code switch then you'll need to start getting really creative 
>:)  You'll then presumably need to change these into using some trampoline to 
>do the actual invocation.

Hopefully that will get you started - I'm sure there'll be lots of little 
issues so if you have questions feel free to ask.  If you get it all working we 
can figure out what exactly we need to make public and how we should expose 
that so you can do this as an extension - but I'm sure you'll initially be 
using a bunch of internal APIs.


From: [email protected] 
[mailto:[email protected]] On Behalf Of Tristan Zajonc
Sent: Sunday, May 30, 2010 6:59 PM
To: Discussion of IronPython
Subject: [IronPython] Implementing Greenlets API in IronPython

Hi -

The greenlets C-extension module (http://packages.python.org/greenlet/)  
provides a very basic api that is used by eventlet and gevent to provide 
asynchronous programming constructs.  It would be nice to have a reasonably 
performant version of the greenlet API in IronPython.

Before I start playing around with possibilities, is there an obvious approach 
to implement the greenlets API in IronPython?

Thanks
Tristan
_______________________________________________
Users mailing list
[email protected]
http://lists.ironpython.com/listinfo.cgi/users-ironpython.com

Reply via email to