示例#1
0
 def close(self,closureType,debug=0):
     closedEnv = self.copy()
     CLOS = Closure(closedEnv,closureType)
     if debug: CLOS.debugOn()
     CLOS.computeClosure()
     closedEnv.isConsistent = CLOS.isConsistent
     return closedEnv
示例#2
0
    def load(self, chunk):
        bc = BinaryChunk(chunk)
        proto = bc.undump()
        closure = Closure(proto, None, 0)
        self.stack.push(closure)

        if len(proto.upvalues) > 0:
            env = self.registry.get(Consts.LUA_RIDX_GLOBALS)
            closure.upvals[0] = env
            print('env: ', end='')
            env.dump()
        return ThreadStatus.OK
示例#3
0
    def load_proto(self, idx):
        proto = self.stack.closure.proto.get_protos()[idx]
        c = Closure(proto, None, 0)
        self.stack.push(c)

        for i in range(len(proto.upvalues)):
            upvalue = proto.get_upvalues()[i]
            idx = upvalue.get_idx()
            if upvalue.get_in_stack():
                if idx not in self.stack.open_upvalues:
                    self.stack.open_upvalues[idx] = self.stack.slots[idx]
                c.upvals[i] = self.stack.open_upvalues[idx]
            else:
                c.upvals[i] = self.stack.closure.upvals[idx]
示例#4
0
def test1():
    """Just three nodes and two links, should derive one new link, uncomment 
    link3 and an inconsistency should be created."""
    ENV = Environment()
    AXIOMS.add(Axiom("before","before","before"))
    AXIOMS.add(Axiom("before","includes","before"))
    node1 = EventNode(ENV,'crashed','OCCURRENCE')
    node2 = EventNode(ENV,'flying','STATE')
    node3 = EventNode(ENV,'saw','PERCEPTION')
    node4 = EventNode(ENV,'heard','PERCEPTION')
    link1 = Link(ENV,node1,'before',node2)
    link2 = Link(ENV,node2,'includes',node3)
    link3 = Link(ENV,node1,'after',node3)
    clos = Closure(ENV,"nodes")
    clos.computeClosure()
    print(ENV)
示例#5
0
def test1():
    """Just three nodes and two links, should derive one new link, uncomment 
    link3 and an inconsistency should be created."""
    ENV = Environment()
    AXIOMS.add(Axiom("before","before","before"))
    AXIOMS.add(Axiom("before","includes","before"))
    node1 = EventNode(ENV,'crashed','OCCURRENCE')
    node2 = EventNode(ENV,'flying','STATE')
    node3 = EventNode(ENV,'saw','PERCEPTION')
    node4 = EventNode(ENV,'heard','PERCEPTION')
    link1 = Link(ENV,node1,'before',node2)
    link2 = Link(ENV,node2,'includes',node3)
    link3 = Link(ENV,node1,'after',node3)
    clos = Closure(ENV,"nodes")
    clos.computeClosure()
    print ENV
示例#6
0
 def test_normal_case(self):
     fds = {
         frozenset(['F']): frozenset(['B', 'E', 'D']),
         frozenset(['B']): frozenset(['D']),
         frozenset(['B', 'D']): frozenset(['C']),
         frozenset(['E']): frozenset(['C', 'G']),
         frozenset(['A', 'B']): frozenset(['H', 'G']),
         frozenset(['H']): frozenset(['G'])
     }
     closure = set(['C', 'E', 'G'])
     self.assertEqual(Closure(fds, set(['E'])), closure)
示例#7
0
    def load(self, chunk_path):
        with open(chunk_path, 'rb') as f:
            chunk = f.read()
            if BinaryChunk.is_binary_chunk(chunk):
                bc = BinaryChunk(chunk)
                proto = bc.undump()
            else:
                with open(chunk_path, 'r') as f1:
                    chunk = f1.read()
                    proto = LuaCompiler.compile(chunk, chunk_path)

        closure = Closure(proto, None, 0)
        self.stack.push(closure)

        if len(proto.upvalues) > 0:
            env = self.registry.get(Consts.LUA_RIDX_GLOBALS)
            closure.upvals[0] = env
            print('env: ', end='')
            env.dump()
        return ThreadStatus.OK
示例#8
0
 def close(self,closureType,debug=0):
     closedEnv = self.copy()
     CLOS = Closure(closedEnv,closureType)
     if debug: CLOS.debugOn()
     CLOS.computeClosure()
     closedEnv.isConsistent = CLOS.isConsistent
     return closedEnv
示例#9
0
 def push_py_function(self, func):
     py_closure = Closure(None, func)
     self.stack.push(py_closure)
示例#10
0
 def load_proto(self, idx):
     proto = self.stack.closure.proto.get_protos()[idx]
     c = Closure(proto)
     self.stack.push(c)
示例#11
0
 def load(self, chunk):
     bc = BinaryChunk(chunk)
     proto = bc.undump()
     closure = Closure(proto, None)
     self.stack.push(closure)
     return ThreadStatus.OK
示例#12
0
 def push_py_closure(self, py_func, n):
     closure = Closure(None, py_func, n)
     for i in range(n, 0, -1):
         v = self.stack.pop()
         closure.upvals[i - 1] = v
     self.stack.push(closure)
示例#13
0
 def _lambda(args, env):
   arg0 = Native.ARG(args)
   arg1 = Native.ARG(args)
 
   return Closure(arg0, arg1, env)
示例#14
0
 def test_right_blank(self):
     fds = {frozenset(['A']): frozenset()}
     self.assertEqual(Closure(fds, set(['A'])), set(['A']))
示例#15
0
 def test_empty_fds(self):
     fds = {}
     self.assertEqual(Closure(fds, set(['A', 'E'])), set(['A', 'E']))