コード例 #1
0
ファイル: interp_coroutine.py プロジェクト: enyst/plexnet
 def __init__(self, space, state=None):
     self.space = space
     if state is None:
         state = AppCoroutine._get_state(space)
     Coroutine.__init__(self, state)
     self.flags = 0
     self.newsubctx()
コード例 #2
0
ファイル: interp_coroutine.py プロジェクト: griels/pypy-sc
 def __init__(self, space, state=None):
     self.space = space
     if state is None:
         state = AppCoroutine._get_state(space)
     Coroutine.__init__(self, state)
     self.flags = 0
     self.newsubctx()
コード例 #3
0
 def g(nrec, t, count=0):
     t.count = count
     if nrec < 0:
         raise ValueError
     if nrec:
         g(nrec - 1, t, count + 1)
     Coroutine.getmain().switch()
コード例 #4
0
 def g(nrec, t, count=0):
     t.count = count
     if nrec < 0:
         raise ValueError
     if nrec:
         g(nrec-1, t, count+1)
     Coroutine.getmain().switch()
コード例 #5
0
ファイル: interp_greenlet.py プロジェクト: enyst/plexnet
 def __init__(self, space, w_callable=None, is_main=False):
     Coroutine.__init__(self, self._get_state(space))
     self.space = space
     self.w_callable = w_callable
     self.active = is_main
     self.subctx = space.getexecutioncontext().Subcontext()
     if is_main:
         self.subctx.clear_framestack()      # wack
     else:
         self.bind(GreenletThunk(self))
コード例 #6
0
 def __init__(self, space, w_callable=None, is_main=False):
     Coroutine.__init__(self, self._get_state(space))
     self.space = space
     self.w_callable = w_callable
     self.active = is_main
     self.subctx = space.getexecutioncontext().Subcontext()
     if is_main:
         self.subctx.clear_framestack()  # wack
     else:
         self.bind(GreenletThunk(self))
コード例 #7
0
 def f():
     lst = [1]
     coro_f = Coroutine.getcurrent()
     coro_g = self.Coroutine()
     coro_h = self.Coroutine()
     coros = [coro_f, coro_g, coro_h]
     thunk_g = T(g, lst, coros)
     output('binding g after f set 1')
     coro_g.bind(thunk_g)
     thunk_h = T(h, lst, coros)
     output('binding h after f set 1')
     coro_h.bind(thunk_h)
     output('switching to g')
     coro_g.switch()
     lst.append(4)
     output('f appended 4')
     coro_g.switch()
     lst.append(6)
     output('f appended 6')
     coro_h.switch()
     lst.append(8)
     output('f appended 8')
     n = 0
     for i in lst:
         n = n * 10 + i
     return n
コード例 #8
0
 def f():
     lst = [1]
     coro_f = Coroutine.getcurrent()
     coro_g = self.Coroutine()
     coro_h = self.Coroutine()
     coros = [coro_f, coro_g, coro_h]
     thunk_g = T(g, lst, coros)
     output('binding g after f set 1')
     coro_g.bind(thunk_g)
     thunk_h = T(h, lst, coros)
     output('binding h after f set 1')
     coro_h.bind(thunk_h)
     output('switching to g')
     coro_g.switch()
     lst.append(4)
     output('f appended 4')
     coro_g.switch()
     lst.append(6)
     output('f appended 6')
     coro_h.switch()
     lst.append(8)
     output('f appended 8')
     n = 0
     for i in lst:
         n = n*10 + i
     return n
コード例 #9
0
 def f():
     coro_f = Coroutine.getcurrent()
     coro_f.__name__ = 'coro_f'
     coro_f1 = self.Coroutine()
     coro_f1.__name__ = 'coro_f1'
     thunk_f1 = T1(f1, coro_f1)
     output('binding f1 after f set 1')
     coro_f1.bind(thunk_f1)
     coro_f1.switch()
     output('return to main :-(')
     return thunk_f1.res
コード例 #10
0
 def f():
     coro_f = Coroutine.getcurrent()
     coro_f.__name__ = 'coro_f'
     coro_f1 = self.Coroutine()
     coro_f1.__name__ = 'coro_f1'
     thunk_f1 = T1(f1, coro_f1)
     output('binding f1 after f set 1')
     coro_f1.bind(thunk_f1)
     coro_f1.switch()
     output('return to main :-(')
     return thunk_f1.res
コード例 #11
0
    def test_hello_goodbye(self):
        class C(Coroutine):
            n = 2

            def __init__(self, n):
                Coroutine.__init__(self)
                self.n = n

            def hello(self):
                costate.hello_goodbye *= 10
                costate.hello_goodbye += self.n

            def goodbye(self):
                costate.hello_goodbye *= 10
                costate.hello_goodbye += self.n + 1

        class T(AbstractThunk):
            def call(self):
                pass

        costate = Coroutine._get_default_costate()
        costate.current.__class__ = C
        costate.hello_goodbye = 0

        def ep():
            syncstate.default_costate = costate
            costate.hello_goodbye = 0
            c1 = C(4)
            c1.bind(T())
            c1.switch()
            return costate.hello_goodbye

        output = self.wrap_stackless_function(ep)
        # expected result:
        #   goodbye main   3
        #   hello   c1     4
        #   goodbye c1     5
        #   hello   main   2
        assert output == 3452
コード例 #12
0
 def f():
     assert Coroutine.getmain().frame is None
     coro_g = self.Coroutine()
     coro_g.__name__ = 'coro_g'
     thunk_g = T(g, 42)
     coro_g.bind(thunk_g)
     coro_g.switch()
     res = thunk_g.count
     res *= 10
     res |= coro_g.frame is not None
     # testing kill
     coro_g.kill()
     res *= 10
     res |= coro_g.frame is None
     coro_g = self.Coroutine()
     # see what happens if we __del__
     thunk_g = T(g, -42)
     coro_g.bind(thunk_g)
     try:
         coro_g.switch()
     except ValueError:
         res += 500
     return res
コード例 #13
0
 def f():
     assert Coroutine.getmain().frame is None
     coro_g = self.Coroutine()
     coro_g.__name__ = 'coro_g'
     thunk_g = T(g, 42)
     coro_g.bind(thunk_g)
     coro_g.switch()
     res = thunk_g.count
     res *= 10
     res |= coro_g.frame is not None
     # testing kill
     coro_g.kill()
     res *= 10
     res |= coro_g.frame is None
     coro_g = self.Coroutine()
     # see what happens if we __del__
     thunk_g = T(g, -42)
     coro_g.bind(thunk_g)
     try:
         coro_g.switch()
     except ValueError:
         res += 500
     return res
コード例 #14
0
    def test_hello_goodbye(self):

        class C(Coroutine):
            n = 2
            def __init__(self, n):
                Coroutine.__init__(self)
                self.n = n
            def hello(self):
                costate.hello_goodbye *= 10
                costate.hello_goodbye += self.n
            def goodbye(self):
                costate.hello_goodbye *= 10
                costate.hello_goodbye += self.n + 1

        class T(AbstractThunk):
            def call(self):
                pass

        costate = Coroutine._get_default_costate()
        costate.current.__class__ = C
        costate.hello_goodbye = 0

        def ep():
            syncstate.default_costate = costate
            costate.hello_goodbye = 0
            c1 = C(4)
            c1.bind(T())
            c1.switch()
            return costate.hello_goodbye

        output = self.wrap_stackless_function(ep)
        # expected result:
        #   goodbye main   3
        #   hello   c1     4
        #   goodbye c1     5
        #   hello   main   2
        assert output == 3452
コード例 #15
0
 def __init__(self, n):
     Coroutine.__init__(self)
     self.n = n
コード例 #16
0
 def call(self):
     self.result = self.consume(self.tree)
     Coroutine.getmain().switch()
コード例 #17
0
 def __init__(self, n):
     Coroutine.__init__(self)
     self.n = n
コード例 #18
0
 def call(self):
     self.result = self.consume(self.tree)
     Coroutine.getmain().switch()