Beispiel #1
0
def Merge(e1,e2):    
    e = None
    def prepare():
        e.fresh = False
        for l in e.listeners.itervalues():
            l.prepare()
    def push1(x1):
        if e2.fresh or e2.cell.get() != None:
            x2 = e2.cell.get()
            for l in e.listeners.itervalues():
                l.push((x1,x2))
            e2.cell.set(None)
        else:
            e1.cell.set(x1)
    def push2(x2):
        if e1.fresh or e1.cell.get() != None:
            x1 = e1.cell.get()
            for l in e.listeners.itervalues():
                l.push((x1,x2))
            e1.cell.set(None)
        else:
            e2.cell.set(x2)
    def finish():
        x1 = e1.cell.get()
        x2 = e2.cell.get()
        e1.cell.set(None)
        e2.cell.set(None)
        if x2 != None:
            for l in e.listeners.itervalues():
                l.push((None,x2))
        if x1 != None:
            for l in e.listeners.itervalues():
                l.push((x1,None))
            for l in e.listeners.itervalues():
                l.finish()
        e.fresh = True
    def terminate1():
        e.term1 = True
        if e.term2:
            for l in e.listeners.itervalues():
                l.terminate()
    def terminate2():
        e.term2 = True
        if e.term1:
            for l in e.listeners.itervalues():
                l.terminate()
    e1.add_listener(FListener(prepare,push1,finish,terminate1))
    e2.add_listener(FListener(prepare,push2,finish,terminate2))
    
    if e1.type is None or e2.type is None:
        out_type = None
    else:
        # TODO(astory): option
        out_type = types.FType((e1.type.type, e2.type.type))
    e = FEvent(type=out_type)
    e.term1 = False
    e.term2 = False
    e1.cell = util.FRef()
    e2.cell = util.FRef()
    return e
Beispiel #2
0
def Snapshot(b1, e2):
    e = None

    def prepare():
        e.fresh = False
        for l in e.listeners.itervalues():
            l.prepare()

    def push(b):
        a = b1.pull()
        for l in e.listeners.itervalues():
            l.push((a, b))

    def finish():
        for l in e.listeners.itervalues():
            l.finish()
        e.fresh = True

    def terminate():
        for l in e.listeners.itervalues():
            l.terminate()

    e2.add_listener(FListener(prepare, push, finish, terminate))
    e = FEvent(type=types.FEventType((b1.type, e2.type)))
    return e
Beispiel #3
0
def Split(e):
    e1 = None
    e2 = None

    def prepare():
        e1.fresh = False
        e2.fresh = False
        for l in e1.listeners.itervalues():
            l.prepare()
        for l in e2.listeners.itervalues():
            l.prepare()

    def push((x1, x2)):
        for l in e1.listeners.itervalues():
            l.push(x1)
        for l in e2.listeners.itervalues():
            l.push(x2)

    def finish():
        for l in e1.listeners.itervalues():
            l.finish()
        for l in e2.listeners.itervalues():
            l.finish()
        e1.fresh = True
        e2.fresh = True

    def terminate():
        for l in e1.listeners.itervalues():
            l.terminate()
        for l in e2.listeners.itervalues():
            l.terminate()

    t1 = t2 = None
    if e.type is not None:
        try:
            (r1, r2) = e.type.type
            (t1, t2) = (types.FType(r1), types.FType(r2))
        except (TypeError, ValueError):
            raise types.FTypeException("%s not of type %s" % (e.type, "a * b"))

    e1 = FEvent(type=t1)
    e2 = FEvent(type=t2)
    e.add_listener(FListener(prepare, push, finish, terminate))
    return (e1, e2)
Beispiel #4
0
 def push(x):
     y = g(x)
     e = None
     if not (ef.table.has_key(y)):
         e = FEvent()
         ef.table[y] = e
         for l in ef.listeners.itervalues():
             l.push((y, e))
     else:
         e = ef.table[y]
     for l in e.listeners.itervalues():
         l.push(x)
Beispiel #5
0
def Apply(e1, ef2):
    e = None

    def prepare():
        e.fresh = False
        ef2.prepare()

    def push(x):
        ef2.push(x)

    def finish():
        ef2.finish()
        e.fresh = True

    e1.add_listener(FListener(prepare, push, finish, ef2.terminate))
    t = None
    if ef2.type_fun is not None:
        t = ef2.type_fun(e1.type)
    e = FEvent(ef2.add_listener, type=t)
    return e
Beispiel #6
0
 def mk():
     sube = FEvent()
     sube.last_cell = util.FRef()
     return sube
Beispiel #7
0
def Merge(e1, e2):
    e = None

    def prepare():
        e.fresh = False
        for l in e.listeners.itervalues():
            l.prepare()

    def push1(x1):
        if e2.fresh or e2.cell.get() != None:
            x2 = e2.cell.get()
            for l in e.listeners.itervalues():
                l.push((x1, x2))
            e2.cell.set(None)
        else:
            e1.cell.set(x1)

    def push2(x2):
        if e1.fresh or e1.cell.get() != None:
            x1 = e1.cell.get()
            for l in e.listeners.itervalues():
                l.push((x1, x2))
            e1.cell.set(None)
        else:
            e2.cell.set(x2)

    def finish():
        x1 = e1.cell.get()
        x2 = e2.cell.get()
        e1.cell.set(None)
        e2.cell.set(None)
        if x2 != None:
            for l in e.listeners.itervalues():
                l.push((None, x2))
        if x1 != None:
            for l in e.listeners.itervalues():
                l.push((x1, None))
            for l in e.listeners.itervalues():
                l.finish()
        e.fresh = True

    def terminate1():
        e.term1 = True
        if e.term2:
            for l in e.listeners.itervalues():
                l.terminate()

    def terminate2():
        e.term2 = True
        if e.term1:
            for l in e.listeners.itervalues():
                l.terminate()

    e1.add_listener(FListener(prepare, push1, finish, terminate1))
    e2.add_listener(FListener(prepare, push2, finish, terminate2))

    if e1.type is None or e2.type is None:
        out_type = None
    else:
        # TODO(astory): option
        out_type = types.FType((e1.type.type, e2.type.type))
    e = FEvent(type=out_type)
    e.term1 = False
    e.term2 = False
    e1.cell = util.FRef()
    e2.cell = util.FRef()
    return e
Beispiel #8
0
 def mk():
     sube = FEvent()
     sube.last_cell = util.FRef()
     return sube