[Python-Dev] Icon-style generators vs. jython

Samuele Pedroni pedroni@inf.ethz.ch
Sun, 18 Mar 2001 02:17:47 +0100


This is very prelimary, no time to read details, try things or look at 
Neil's impl.

As far as I have understood Icon generators are function with normal 
entry, exit points and multiple suspension points:
at a suspension point an eventual impl should save the cur frame status  
somehow inside the function obj together with the information
where the function should restart and then normally return a value or 

In jython we have frames, and function are encapsulated in objects so 
the whole should be doable (with some effort), I expect that we can deal
with the multi-entry-points with a jvm switch bytecode. Entry code or 
function dispatch code should handle restarting (we already have
a code the manages frame creation and function dispatch on every python 

There could be a problem with jythonc (the jython-to-java compiler) 
because it produces java source code and not directly bytecode,
because at source level AFAIK in java one cannot intermangle switches 
and other ctrl structures, so how to deal with multiple entry points.
(no goto ;)). We would have to rewrite it to produce bytecode directly.

What is expected behaviour wrt threads, should generators be reentrant 
(that mean that frame and restart info should be saved on a thread basis)
or are they somehow global active objects so if thread 1 call a 
generator that suspend then thread 2 will reenter it after the 
suspension point?

Freezing more than a frame is not directly possible in jython, frames 
are pushed and popped on java stack and function calls pass through
java calling mechanism. (I imagine you need a separate thread for doing