Example #1
0
 def visit_Call(self, node):
     func = node.func
     if func.__class__.__name__ == "Name" and func.id in self.names:
         self.calls.append(
             (func.id, node.args and node.args[0].s
              or None, [(k.arg, unparse(k.value)) for k in node.keywords]))
         return ast.Name(id="True")
     return node
Example #2
0
 def visit_Call (self, node) :
     func = node.func
     if func.__class__.__name__ == "Name" and func.id in self.names :
         self.calls.append((func.id,
                            node.args and node.args[0].s or None,
                            [(k.arg, unparse(k.value))
                             for k in node.keywords]))
         return ast.Name(id="True")
     return node
Example #3
0
 def build_AbcdSpec(self, node):
     for decl in node.context:
         self.build(decl)
     tasks = [
         self._build_TaskNet(decl.node) for name, decl in self.env.items()
         if decl.kind == Decl.TASK and decl.used
     ]
     net = reduce(operator.or_, tasks, self.build(node.body))
     # set local buffers marking, and hide them
     for name, decl in ((n, d) for n, d in self.env.items()
                        if d.kind == Decl.BUFFER):
         status = self.snk.buffer(name)
         for place in net.status(status):
             place = net.place(place)
             try:
                 place.reset(decl.marking)
             except ValueError as err:
                 self._raise(CompilationError,
                             "invalid initial marking (%s)" % err)
             if decl.capacity is None:
                 cap = None
             else:
                 #cap = [c.n if c else None for c in decl.capacity]
                 # TODO: accept more than integers as capacities
                 cap = []
                 for c in decl.capacity:
                     if c is None:
                         cap.append(None)
                     else:
                         try:
                             cap.append(self._eval(c))
                         except:
                             err = sys.exc_info()[1]
                             self._raise(
                                 CompilationError,
                                 "could not evaluate %r, %s" %
                                 (unparse(c), err))
             place.label(path=self.path, capacity=cap)
             # TODO: check capacity
         net.hide(status)
     if self.up is None:
         # set entry marking
         for place in net.status(self.snk.entry):
             net.place(place).reset(self.snk.dot)
         # rename nodes
         self._rename_nodes(net)
         # copy global declarations
         net.globals.update(self.globals)
         # add info about source file
         net.label(srcfile=str(node.st.text.filename))
         # add assertions
         net.label(asserts=node.asserts)
     return net
Example #4
0
 def build_AbcdSpec (self, node) :
     for decl in node.context :
         self.build(decl)
     tasks = [self._build_TaskNet(decl.node)
              for name, decl in self.env.items()
              if decl.kind == Decl.TASK and decl.used]
     net = reduce(operator.or_, tasks, self.build(node.body))
     # set local buffers marking, and hide them
     for name, decl in ((n, d) for n, d in self.env.items()
                        if d.kind == Decl.BUFFER) :
         status = self.snk.buffer(name)
         for place in net.status(status) :
             place = net.place(place)
             try :
                 place.reset(decl.marking)
             except ValueError as err :
                 self._raise(CompilationError,
                             "invalid initial marking (%s)" % err)
             if decl.capacity is None :
                 cap = None
             else :
                 #cap = [c.n if c else None for c in decl.capacity]
                 # TODO: accept more than integers as capacities
                 cap = []
                 for c in decl.capacity :
                     if c is None :
                         cap.append(None)
                     else :
                         try :
                             cap.append(self._eval(c))
                         except :
                             err = sys.exc_info()[1]
                             self._raise(CompilationError,
                                         "could not evaluate %r, %s"
                                         % (unparse(c), err))
             place.label(path=self.path,
                         capacity=cap)
             # TODO: check capacity
         net.hide(status)
     if self.up is None :
         # set entry marking
         for place in net.status(self.snk.entry) :
             net.place(place).reset(self.snk.dot)
         # rename nodes
         self._rename_nodes(net)
         # copy global declarations
         net.globals.update(self.globals)
         # add info about source file
         net.label(srcfile=str(node.st.text.filename))
         # add assertions
         net.label(asserts=node.asserts)
     return net
Example #5
0
 def _build_action (self, node) :
     net = self.snk.PetriNet("flow")
     e = self.snk.Place("e", [], self.snk.tBlackToken,
                        status=self.snk.entry)
     e.label(path=self.path)
     net.add_place(e)
     x = self.snk.Place("x", [], self.snk.tBlackToken,
                        status=self.snk.exit)
     x.label(path=self.path)
     net.add_place(x)
     t = self.snk.Transition("t", self.snk.Expression(unparse(node.guard)),
                             status=self.snk.tick("action"))
     t.label(srctext=node.st.source(),
             srcloc=(node.st.srow, node.st.scol,
                     node.st.erow, node.st.ecol),
             path=self.path)
     net.add_transition(t)
     net.add_input("e", "t", self.snk.Value(self.snk.dot))
     net.add_output("x", "t", self.snk.Value(self.snk.dot))
     net = reduce(operator.or_, [self.build(a) for a in node.accesses],
                  net)
     net.hide(self.snk.tick("action"))
     return net
Example #6
0
 def _build_action(self, node):
     net = self.snk.PetriNet("flow")
     e = self.snk.Place("e", [],
                        self.snk.tBlackToken,
                        status=self.snk.entry)
     e.label(path=self.path)
     net.add_place(e)
     x = self.snk.Place("x", [], self.snk.tBlackToken, status=self.snk.exit)
     x.label(path=self.path)
     net.add_place(x)
     t = self.snk.Transition("t",
                             self.snk.Expression(unparse(node.guard)),
                             status=self.snk.tick("action"))
     t.label(srctext=node.st.source(),
             srcloc=(node.st.srow, node.st.scol, node.st.erow,
                     node.st.ecol),
             path=self.path)
     net.add_transition(t)
     net.add_input("e", "t", self.snk.Value(self.snk.dot))
     net.add_output("x", "t", self.snk.Value(self.snk.dot))
     net = reduce(operator.or_, [self.build(a) for a in node.accesses], net)
     net.hide(self.snk.tick("action"))
     return net
Example #7
0
 def _eval (self, expr, *largs, **kwargs) :
     env = self.globals.copy()
     if isinstance(expr, ast.AST) :
         expr = unparse(expr)
     return env(expr, dict(*largs, **kwargs))
Example #8
0
 def build_arc_expr (self, node) :
     return self.snk.Expression(unparse(node))
Example #9
0
 def build_Import (self, node) :
     for alias in node.names :
         self[alias.asname or alias.name] = Decl(node)
     self.globals.declare(unparse(node))
Example #10
0
 def build_arc_expr(self, node):
     return self.snk.Expression(unparse(node))
Example #11
0
 def build_Import(self, node):
     for alias in node.names:
         self[alias.asname or alias.name] = Decl(node)
     self.globals.declare(unparse(node))
Example #12
0
 def _eval(self, expr, *largs, **kwargs):
     env = self.globals.copy()
     if isinstance(expr, ast.AST):
         expr = unparse(expr)
     return env(expr, dict(*largs, **kwargs))
Example #13
0
def unlet (expr, *names) :
    if not names :
        names = ["let"]
    drop = DropLet(names)
    new = DropTrue().visit(drop.visit(parse(expr)))
    return unparse(new), drop.calls
Example #14
0
def unlet(expr, *names):
    if not names:
        names = ["let"]
    drop = DropLet(names)
    new = DropTrue().visit(drop.visit(parse(expr)))
    return unparse(new), drop.calls