""" testing coroutines at interprepter level """ import py import os from pypy import conftest; conftest.translation_test_so_skip_if_appdirect() from pypy.rlib.rcoroutine import make_coroutine_classes from pypy.translator.c.test.test_stackless import StacklessTest from pypy.translator.c import gc def setup_module(mod): py.test.importorskip('greenlet') d = make_coroutine_classes(object) syncstate = d['syncstate'] Coroutine = d['Coroutine'] AbstractThunk = d['AbstractThunk'] def output(stuff): os.write(2, stuff + '\n') class _TestCoroutine(StacklessTest): backendopt = True Coroutine = Coroutine def setup_method(self, method): syncstate.reset() def _freeze_(self): # for 'self.Coroutine' return True
""" testing coroutines at interprepter level """ import os from pypy import conftest conftest.translation_test_so_skip_if_appdirect() from pypy.rlib.rcoroutine import make_coroutine_classes from pypy.translator.c.test.test_stackless import StacklessTest from pypy.translator.c import gc d = make_coroutine_classes(object) syncstate = d['syncstate'] Coroutine = d['Coroutine'] AbstractThunk = d['AbstractThunk'] def output(stuff): os.write(2, stuff + '\n') class _TestCoroutine(StacklessTest): backendopt = True Coroutine = Coroutine def setup_method(self, method): syncstate.reset() def _freeze_(self): # for 'self.Coroutine' return True
from pypy.rlib import rcoroutine from pypy.rlib import rstack from pypy.rlib.rstack import resume_state_create from pypy.translator.stackless.test.test_transform import llinterp_stackless_function from pypy.rpython.lltypesystem.lloperation import llop from pypy.rpython.lltypesystem import lltype namespace = rcoroutine.make_coroutine_classes(object) syncstate = namespace['syncstate'] AbstractThunk = namespace['AbstractThunk'] Coroutine = namespace['Coroutine'] class TestCoroutineReconstruction: def setup_meth(self): syncstate.reset() def test_simple_ish(self): output = [] def f(coro, n, x): if n == 0: coro.switch() rstack.resume_point("f_0") assert rstack.stack_frames_depth() == 9 return f(coro, n-1, 2*x) rstack.resume_point("f_1", coro, n, x) output.append(x) class T(AbstractThunk):
from pypy.rlib.rcoroutine import make_coroutine_classes from pypy.interpreter.baseobjspace import Wrappable d = make_coroutine_classes(Wrappable) Coroutine = d['Coroutine'] BaseCoState = d['BaseCoState'] AbstractThunk = d['AbstractThunk'] syncstate = d['syncstate'] CoroutineExit = d['CoroutineExit']
from pypy.rlib.rcoroutine import make_coroutine_classes from pypy.interpreter.baseobjspace import Wrappable d = make_coroutine_classes(Wrappable) Coroutine = d['Coroutine'] BaseCoState = d['BaseCoState'] AbstractThunk = d['AbstractThunk'] syncstate = d['syncstate']