def __init__(self, config): coretypes.MarkingType.__init__(self, TypeInfo.register_type("Marking"), TypeInfo.register_type("MarkingSet"), config) # id provider for class attributes self.id_provider = utils.NameProvider( ) # used to produce attribute names self._process_place_types = {} #self.packing_enabled = config.bit_packing self.config = config self.chunk_manager = ChunkManager(self.id_provider.new(base="_packed")) self.add_method_generator(priv.mrkmethods.InitGenerator()) self.add_method_generator(priv.mrkmethods.DeallocGenerator()) self.add_method_generator(priv.mrkmethods.CopyGenerator()) self.add_method_generator(priv.mrkmethods.DumpExprGenerator()) self.add_method_generator(priv.mrkmethods.RichcmpGenerator()) self.add_method_generator(priv.mrkmethods.HashGenerator()) self._C_function_generators = [] self.add_C_function_generator(priv.mrkfunctions.DumpGenerator()) self.add_C_function_generator(priv.mrkfunctions.CopyGenerator()) self.add_C_function_generator(priv.mrkfunctions.CompareGenerator()) self.add_C_function_generator(priv.mrkfunctions.HashGenerator()) if config.normalize_pids: self.add_C_function_generator( priv.mrkpidfunctions.UpdatePidsGenerator()) self.add_C_function_generator( priv.mrkpidfunctions.NormalizePidsGenerator())
def __init__(self, config): coretypes.MarkingType.__init__(self, TypeInfo.register_type('Marking'), TypeInfo.register_type('set'), config) self.id_provider = utils.NameProvider() self._process_place_types = {} self.fields = set() self.create_field('_hash', TypeInfo.get('Int')) self.add_method_generator(priv.mrkmethods.InitGenerator()) self.add_method_generator(priv.mrkmethods.CopyGenerator()) self.add_method_generator(priv.mrkmethods.ReprGenerator()) self.add_method_generator(priv.mrkmethods.DumpGenerator()) self.add_method_generator(priv.mrkmethods.LineDumpGenerator()) if self.config.normalize_pids: self.add_method_generator(priv.mrkpidmethods.EqGenerator()) self.add_method_generator(priv.mrkpidmethods.HashGenerator()) self.add_method_generator(priv.mrkpidmethods.UpdatePidsGenerator()) self.add_method_generator(priv.mrkpidmethods.BuildPidTreeGenerator()) self.add_method_generator(priv.mrkpidmethods.PidFreeCmpGenerator()) self.add_method_generator(priv.mrkpidmethods.PidFreeHashGenerator()) else: self.add_method_generator(priv.mrkmethods.EqGenerator()) self.add_method_generator(priv.mrkmethods.HashGenerator())
def __init__(self, config): coretypes.MarkingType.__init__(self, TypeInfo.register_type('Marking'), TypeInfo.register_type('set'), config) self.id_provider = utils.NameProvider() self._process_place_types = {} self.fields = set() self.create_field('_hash', TypeInfo.get('Int')) self.add_method_generator(priv.mrkmethods.InitGenerator()) self.add_method_generator(priv.mrkmethods.CopyGenerator()) self.add_method_generator(priv.mrkmethods.ReprGenerator()) self.add_method_generator(priv.mrkmethods.DumpGenerator()) self.add_method_generator(priv.mrkmethods.LineDumpGenerator()) if self.config.normalize_pids: self.add_method_generator(priv.mrkpidmethods.EqGenerator()) self.add_method_generator(priv.mrkpidmethods.HashGenerator()) self.add_method_generator(priv.mrkpidmethods.UpdatePidsGenerator()) self.add_method_generator( priv.mrkpidmethods.BuildPidTreeGenerator()) self.add_method_generator(priv.mrkpidmethods.PidFreeCmpGenerator()) self.add_method_generator( priv.mrkpidmethods.PidFreeHashGenerator()) else: self.add_method_generator(priv.mrkmethods.EqGenerator()) self.add_method_generator(priv.mrkmethods.HashGenerator())
if type_info.is_BlackToken: return "BlackToken" elif type_info.is_Bool: return "bool" elif type_info.is_Int: return "int" elif type_info.is_String: return "str" else: return str(type_info) elif type_info.is_TupleType: return "tuple" else: return "object" TypeInfo.register_type("Multiset") class Field(object): def __init__(self, name, field_type): self.name = name self.type = field_type def access_from(self, marking_var): return "{}.{}".format(marking_var.name, self.name) def access_from_str(self, marking_str): return "{}.{}".format(marking_str, self.name) class StaticMarkingType(coretypes.MarkingType): """ Python marking type implementation, places as class attributes. """
def produce_and_compile_pyx(checker_env, id_prop_map): config = checker_env.config marking_type = checker_env.marking_type checker_env.register_cython_type(marking_type.type, 'net.Marking') TypeInfo.register_type('Marking') # functions = [] for identifier, prop in id_prop_map.iteritems(): gen_check_function(checker_env, identifier, prop) # updates env gen_main_check_function(checker_env, id_prop_map) # updates env # checker_module = cyast.Module(body = functions) base_dir = "build/" try: os.mkdir(base_dir) except OSError: pass f = open(base_dir + "checker.pyx", "w") f.write("cimport net\n") f.write("import net\n") f.write("cimport neco.ctypes.ctypes_ext as ctypes_ext\n") f.write("import sys, StringIO\n") f.write("import cPickle as pickle\n") f.write("from snakes.nets import *\n") for imp in config.checker_imports: f.write("from {} import *\n".format(imp)) for function_ast in checker_env.is_fireable_functions(): cyast.Unparser(function_ast, f) for function_ast in checker_env.get_all_functions(): cyast.Unparser(function_ast, f) for function_ast in checker_env.get_any_functions(): cyast.Unparser(function_ast, f) for function_ast in checker_env.functions(): cyast.Unparser(function_ast, f) f.close() search_paths = config.search_paths ctypes_source = search_file("ctypes.cpp", search_paths) macros = [] if config.normalize_pids: macros.append(( 'USE_PIDS', '1', )) # # remove -Wstrict-prototypes since we compile using g++ # (opt, ) = get_config_vars('OPT') os.environ['OPT'] = " ".join(flag for flag in opt.split() if flag != '-Wstrict-prototypes') # # compile checker # setup(name=base_dir + "checker.pyx", cmdclass={'build_ext': build_ext}, ext_modules=[ Extension("checker", [base_dir + "checker.pyx", ctypes_source], include_dirs=search_paths + [base_dir], extra_compile_args=[], extra_link_args=[], define_macros=macros, library_dirs=search_paths + [base_dir], language='c++') ], script_args=["build_ext", "--inplace"], options={'build': { 'build_base': 'build' }})
def produce_and_compile_pyx(checker_env, id_prop_map): config = checker_env.config marking_type = checker_env.marking_type checker_env.register_cython_type(marking_type.type, 'net.Marking') TypeInfo.register_type('Marking') # functions = [] for identifier, prop in id_prop_map.iteritems(): gen_check_function(checker_env, identifier, prop) # updates env gen_main_check_function(checker_env, id_prop_map) # updates env # checker_module = cyast.Module(body = functions) base_dir = "build/" try: os.mkdir(base_dir) except OSError: pass f = open(base_dir + "checker.pyx", "w") f.write("cimport net\n") f.write("import net\n") f.write("cimport neco.ctypes.ctypes_ext as ctypes_ext\n") f.write("import sys, StringIO\n") f.write("import cPickle as pickle\n") f.write("from snakes.nets import *\n") for imp in config.checker_imports: f.write("from {} import *\n".format(imp)) for function_ast in checker_env.is_fireable_functions(): cyast.Unparser(function_ast, f) for function_ast in checker_env.get_all_functions(): cyast.Unparser(function_ast, f) for function_ast in checker_env.get_any_functions(): cyast.Unparser(function_ast, f) for function_ast in checker_env.functions(): cyast.Unparser(function_ast, f) f.close() search_paths = config.search_paths ctypes_source = search_file("ctypes.cpp", search_paths) macros = [] if config.normalize_pids: macros.append(('USE_PIDS', '1',)) # # remove -Wstrict-prototypes since we compile using g++ # (opt,) = get_config_vars('OPT') os.environ['OPT'] = " ".join( flag for flag in opt.split() if flag != '-Wstrict-prototypes' ) # # compile checker # setup(name = base_dir + "checker.pyx", cmdclass = {'build_ext': build_ext}, ext_modules = [Extension("checker", [base_dir + "checker.pyx", ctypes_source], include_dirs = search_paths + [base_dir], extra_compile_args = [], extra_link_args = [], define_macros = macros, library_dirs = search_paths + [base_dir], language = 'c++')], script_args = ["build_ext", "--inplace"], options = { 'build': { 'build_base': 'build' } })
def __str__(self): return str( self.expr ) + " is of type " + self.type + " but type " + self.expected + " was expected." def from_neco_lib(f): return "ctypes_ext.%s" % f ################################################################################ # new types TypeInfo.register_type("MultiSet") TypeInfo.register_type("IntPlace") TypeInfo.register_type("Char") TypeInfo.register_type("Short") TypeInfo.register_type("UnsignedInt") TypeInfo.register_type("UnsignedChar") TypeInfo.register_type("PidPlace") TypeInfo.register_type("GeneratorPlace") ################################################################################ class CVars(object): def __init__(self, env, initial=None): self.env = env
self.expr = expr self.type = got self.expected = expected def __str__(self): return str(self.expr) + " is of type " + self.type + " but type " + self.expected + " was expected." def from_neco_lib(f): return "ctypes_ext.%s" % f ################################################################################ # new types TypeInfo.register_type("MultiSet") TypeInfo.register_type("IntPlace") TypeInfo.register_type("Char") TypeInfo.register_type("Short") TypeInfo.register_type("UnsignedInt") TypeInfo.register_type("UnsignedChar") TypeInfo.register_type("PidPlace") TypeInfo.register_type("GeneratorPlace") ################################################################################ class CVars(object): def __init__(self, env, initial = None): self.env = env
return "BlackToken" elif type_info.is_Bool: return "bool" elif type_info.is_Int: return "int" elif type_info.is_String: return "str" else: return str(type_info) elif type_info.is_TupleType: return "tuple" else: return "object" TypeInfo.register_type("Multiset") class Field(object): def __init__(self, name, field_type): self.name = name self.type = field_type def access_from(self, marking_var): return "{}.{}".format(marking_var.name, self.name) def access_from_str(self, marking_str): return "{}.{}".format(marking_str, self.name) class StaticMarkingType(coretypes.MarkingType):