lang-io / io /

import greenlet

from io.model import W_Object
from pypy.rlib.rcoroutine import make_coroutine_classes
d = make_coroutine_classes(W_Object)

Coroutine = d['Coroutine']
AbstractThunk = d['AbstractThunk']
BaseCoState = d['BaseCoState']

class W_Coroutine(Coroutine):
    def __init__(self, space, state, protos):
        Coroutine.__init__(self, state)

        W_Object.__init__(self, space, protos)

    def clone(self):
        return W_Coroutine(, self.costate, [self])

    def w_getcurrent(space):
        return W_Coroutine._get_state(space).current

    def w_getmain(space):
        return W_Coroutine._get_state(space).main
    def _get_state(space):
        # XXX: Need a propper caching machinery
        if space._coroutine_state is None:
            space._coroutine_state = AppCoState(space)
        return space._coroutine_state

    def run(self, space, w_receiver, w_context):
        if self.thunk is None:
            t = IoThunk(space, self.slots['runMessage'], w_receiver, w_context)
            p = self.lookup('parentCoroutine')
            if not space.isnil(p):
                self.parent = p

class AppCoState(BaseCoState):
    def __init__(self, space):
        BaseCoState.__init__(self) = space

    def post_install(self):
        self.main = W_Coroutine(, self, [])
        self.current = self.main
        # self.current.slots['parentCoroutine'] = self.main

class IoThunk(AbstractThunk):
    def __init__(self, space, w_message, w_receiver, w_context): = space
        self.w_message = w_message
        self.w_receiver = w_receiver
        self.w_context = w_context

    def call(self):
        t = self.w_message.eval(, self.w_receiver, self.w_context)
        self.w_receiver.slots['result'] = t
Tip: Filter by directory path e.g. /media app.js to search for public/media/app.js.
Tip: Use camelCasing e.g. ProjME to search for
Tip: Filter by extension type e.g. /repo .js to search for all .js files in the /repo directory.
Tip: Separate your search with spaces e.g. /ssh pom.xml to search for src/ssh/pom.xml.
Tip: Use ↑ and ↓ arrow keys to navigate and return to view the file.
Tip: You can also navigate files with Ctrl+j (next) and Ctrl+k (previous) and view the file with Ctrl+o.
Tip: You can also navigate files with Alt+j (next) and Alt+k (previous) and view the file with Alt+o.