Пример #1
0
    def compile_MultiTokenEnumeration(self, node):
        place_type = self.env.marking_type.get_place_type_by_name(node.place_name)

        base = None
        current = None
        if place_type.provides_by_index_access:
            for sub_arc in node.multiarc.sub_arcs:
                variable = sub_arc.data['local_variable']
                index = sub_arc.data['index']

                assign = pyast.Assign(targets = [pyast.Name(variable)],
                                      value = place_type.get_token_expr(self.env,
                                                                      node.marking_var,
                                                                      pyast.Name(index)))
                enumeration = pyast.For(target = pyast.Name(index),
                                         iter = pyast.Call(func = pyast.Name('range'),
                                                         args = [pyast.Num(0), place_type.get_size_expr(self.env,
                                                                                                    node.marking_var)]),
                                       body = [ assign ])
                if base == None:
                    current = enumeration
                    base = enumeration
                else:
                    current.body.append(enumeration)
                    current = enumeration


        else:    # no index access
            for sub_arc in node.multiarc.sub_arcs:
                variable = sub_arc.data['local_variable']
                index = sub_arc.data['index']
                init = pyast.Assign(targets = [pyast.Name(index.name)],
                                   value = pyast.Num(0))

                enumeration = pyast.For(target = pyast.Name(variable.name),
                                       iter = place_type.iterable_expr(env = self.env,
                                                                        marking_var = node.marking_var),
                                       body = [ pyast.AugAssign(target = pyast.Name(index.name),
                                                               op = pyast.Add(),
                                                               value = pyast.Num(1)) ])
                if base == None:
                    current = [ init, enumeration ]
                    base = [ init, enumeration ]
                else:
                    current[1].body.append([init, enumeration])
                    current = [init, enumeration]

        indices = [ sub_arc.data['index'].name for sub_arc in node.multiarc.sub_arcs ]
        inner_base, inner = self.gen_different(indices)
        if isinstance(current, list):
            current[1].body.append(inner_base)
        else:
            current.body.append(inner_base)
        current = inner

        current.body.extend([ self.compile(node.body) ])

        return base
Пример #2
0
 def compile_ProcedureCall(self, node):
     return pyast.stmt(pyast.Call(func = pyast.Name(id = node.function_name),
                                   args = [ self.compile(arg) for arg in node.arguments ]))
Пример #3
0
 def new_marking_set_expr(self, env):
     return pyast.Call(func=pyast.Name(id='set'))
Пример #4
0
 def add_marking_stmt(self, env, markingset, marking):
     return pyast.stmt(
         pyast.Call(func=pyast.Attribute(
             value=pyast.Name(id=markingset.name), attr='add'),
                    args=[pyast.E(marking.name)]))
Пример #5
0
 def copy_marking_expr(self, env, marking_var, *args):
     return pyast.Call(func=pyast.Attribute(
         value=pyast.Name(id=marking_var.name), attr='copy'))