def generator_new(space, __args__): args_w, kwds_w = __args__.unpack() #stolen from std/fake.py w_frame, w_running = args_w frame = space.interp_w(PyFrame, w_frame) running = space.int_w(w_running) new_generator = GeneratorIterator(frame) new_generator.running = running return space.wrap(new_generator)
def run(self): """Start this frame's execution.""" if self.getcode().co_flags & pycode.CO_GENERATOR: if self.getcode().co_flags & pycode.CO_YIELD_INSIDE_TRY: from pypy.interpreter.generator import GeneratorIteratorWithDel return self.space.wrap(GeneratorIteratorWithDel(self)) else: from pypy.interpreter.generator import GeneratorIterator return self.space.wrap(GeneratorIterator(self)) else: return self.execute_frame()
def initialize_as_generator(self, name, qualname): space = self.space flags = self.getcode().co_flags if flags & pycode.CO_COROUTINE: from pypy.interpreter.generator import Coroutine gen = Coroutine(self, name, qualname) ec = space.getexecutioncontext() w_wrapper = ec.w_coroutine_wrapper_fn gen.capture_origin(ec) elif flags & pycode.CO_ASYNC_GENERATOR: from pypy.interpreter.generator import AsyncGenerator gen = AsyncGenerator(self, name, qualname) ec = None w_wrapper = None elif flags & pycode.CO_GENERATOR: from pypy.interpreter.generator import GeneratorIterator gen = GeneratorIterator(self, name, qualname) ec = None w_wrapper = None else: raise AssertionError("bad co_flags") if space.config.translation.rweakref: self.f_generator_wref = rweakref.ref(gen) else: self.f_generator_nowref = gen w_gen = gen if w_wrapper is not None: if ec.in_coroutine_wrapper: raise oefmt( space.w_RuntimeError, "coroutine wrapper %R attempted " "to recursively wrap %R", w_wrapper, self.getcode()) ec.in_coroutine_wrapper = True try: w_gen = space.call_function(w_wrapper, w_gen) finally: ec.in_coroutine_wrapper = False return w_gen
def generator_new(space, frame, running): new_generator = GeneratorIterator(frame) new_generator.running = running return space.wrap(new_generator)
def generator_new(space, w_frame, running): frame = space.interp_w(PyFrame, w_frame, can_be_None=True) new_generator = GeneratorIterator(frame) new_generator.running = running return space.wrap(new_generator)