def compile_CheckType(self, node): type_info = node.type if type_info.is_AnyType: return self.compile(node.body) test = cyast.Call(func=cyast.Name('isinstance'), args=[ cyast.E(node.variable.name), cyast.E(self.env.type2str(type_info)) ]) return cyast.Builder.If(test=test, body=self.compile(node.body))
def compile_Succs(self, node): body = [] body.extend(self.compile(node.body)) body.append(cyast.E("return " + node.arg_marking_acc_var.name)) f1 = cyast.Builder.FunctionCpDef( name=node.function_name, args=self.main_succ_function_args(node), body=body, lang=cyast.CpDef(public=True), returns=cyast.Name("set"), decl=[ cyast.CVar(name=node.arg_marking_acc_var.name, type=self.env.type2str( node.arg_marking_acc_var.type), init=self.env.marking_set_type.new_marking_set_expr( self.env)) ]) body = [cyast.E("l = ctypes_ext.neco_list_new()")] body.append( cyast.For( target=cyast.to_ast(cyast.E("e")), iter=cyast.to_ast(cyast.E("succs(m, ctx)")), body=[ cyast.to_ast( cyast.stmt(cyast.E("ctypes_ext.__Pyx_INCREF(e)"))), cyast.Expr( cyast.Call( func=cyast.to_ast( cyast.E("ctypes_ext.neco_list_push_front")), args=[cyast.to_ast(cyast.E("l")), cyast.Name("e")], keywords=[], starargs=None, kwargs=None)) ])) body.append(cyast.E("return l")) f2 = cyast.Builder.FunctionCDef( name="neco_succs", args=(cyast.A( "m", type=self.env.type2str(node.arg_marking_var.type)).param( "ctx", type=self.env.type2str(node.arg_ctx_var.type))), body=body, returns=cyast.Name("ctypes_ext.neco_list_t*"), decl=[ cyast.CVar(name="l", type="ctypes_ext.neco_list_t*"), cyast.CVar(name="e", type="Marking") ]) return [f1]
def call(self, args): self._function_name return cyast.Call(func=cyast.Name(self._function_name), args=args)
def compile_NormalizeMarking(self, node): return cyast.stmt( cyast.Call(func=cyast.E('normalize_pids'), args=[cyast.E(node.marking_var.name)]))
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_var = sub_arc.data['index'] self.env.try_declare_cvar(index_var.name, TypeInfo.get('Int')) self.env.try_declare_cvar(variable.name, place_type.token_type) assign = cyast.Assign(targets=[cyast.Name(variable.name)], value=place_type.get_token_expr( self.env, index_expr=index_var, marking_var=node.marking_var, compiled_index=cyast.Name( index_var.name))) enumeration = cyast.For(target=cyast.Name(index_var.name), iter=cyast.Call( func=cyast.Name('range'), args=[ cyast.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_var = sub_arc.data['index'] init = cyast.Assign(targets=[cyast.Name(index_var.name)], value=cyast.Num(0)) self.env.try_declare_cvar(index_var.name, TypeInfo.get('Int')) self.env.try_declare_cvar(variable.name, place_type.token_type) enumeration = cyast.For(target=cyast.Name(variable.name), iter=place_type.iterable_expr( env=self.env, marking_var=node.marking_var), body=[ cyast.AugAssign(target=cyast.Name( index_var.name), op=cyast.Add(), value=cyast.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'] 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
def compile_ProcedureCall(self, node): return cyast.stmt( cyast.Call(func=cyast.Name(node.function_name), args=[self.compile(arg) for arg in node.arguments]))
def add_marking_stmt(self, env, markingset_var, marking_var): return cyast.Call(func=cyast.Attribute(value=cyast.Name( markingset_var.name), attr=self.add_attribute_name), args=[cyast.E(marking_var.name)])
def new_marking_set_expr(self, env): return cyast.Call(func=cyast.Name("set"))
def normalize_marking_call(self, env, marking_var): return cyast.stmt( cyast.Call(func=cyast.E("{}.normalize_pids".format( marking_var.name)), args=[]))
def copy_marking_expr(self, env, marking_var): return cyast.Call( func=cyast.Attribute(name=marking_var.name, attr='copy'))
def new_marking_expr(self, env): return cyast.Call(func=cyast.Name(env.type2str(self.type)), args=[cyast.Name('alloc')], keywords=[cyast.Name('True')])