# Path: sydpy/_util/_util.py
# def getio_vars(func, intfs):
#         
# #     varnames = func.__code__.co_varnames
# #     symdict = {intf.name: intf for _,intf in intfs.items()}
#     symdict = intfs
# 
# #     try:    
# #         if func.arch == True:
# #             (arch_args, arch_ports, arch_confs, arch_arg_defs, arch_annot) = get_arch_args(func)
# #         
# #             for p in arch_ports:
# #                 symdict[p] = p
# #                 
# #     except AttributeError:
# #         pass
# 
#     if func.__code__.co_freevars:
#         for n, c in zip(func.__code__.co_freevars, func.__closure__):
#             try:
#                 symdict[n] = c.cell_contents
#             except NameError:
#                 raise NameError(n)
#     
#     
#     s = inspect.getsource(func)
#     tree = ast.parse(_dedent(s))
# 
# #     from astmonkey import visitors, transformers
# #     
# #     node = transformers.ParentNodeTransformer().visit(tree)
# #     visitor = visitors.GraphNodeVisitor()
# #     visitor.visit(node)
# #     
# #     visitor.graph.write_png('graph.png')
# 
#     v = _SigNameVisitor(symdict)
#     v.visit(tree)
#     
#     return v.inputs, v.outputs
# 
# Path: sydpy/_simulator.py
# def simwait(events=None):
#     """Delay process execution by waiting for events."""
#     sim = RequiredVariable('Simulator')
#     sim.wait(events)


from greenlet import greenlet
from sydpy._util._util import getio_vars
from sydpy._simulator import simwait
   
    def __init__(self, module, func, *args, exit_func=None, **kwargs):
        self.func = func
        self.func_params = kwargs
        self.module = module
        self.arch = self.module.current_arch
        self.module.proc_reg(self)
        self.name = module.qualified_name + "." + func.__name__
        senslist = []
        
        for a in args:
            if hasattr(a, 'subscribe'):
                senslist.append(a)
        
        self.senslist = senslist
        self._exit_func = exit_func
        
        # If the module is to be traslated to HDL, translate the process
        if module.hdl_gen:
            self.hdl_gen()
        
        greenlet.__init__(self)
    
    def run(self):
        if self.senslist:
            while(1):
                simwait(self.senslist)
                self.func(**self.func_params)
        else:
            self.func(**self.func_params)

# Path: sydpy/_util/_util.py
# def getio_vars(func, intfs):
#         
# #     varnames = func.__code__.co_varnames
# #     symdict = {intf.name: intf for _,intf in intfs.items()}
#     symdict = intfs
# 
# #     try:    
# #         if func.arch == True:
# #             (arch_args, arch_ports, arch_confs, arch_arg_defs, arch_annot) = get_arch_args(func)
# #         
# #             for p in arch_ports:
# #                 symdict[p] = p
# #                 
# #     except AttributeError:
# #         pass
# 
#     if func.__code__.co_freevars:
#         for n, c in zip(func.__code__.co_freevars, func.__closure__):
#             try:
#                 symdict[n] = c.cell_contents
#             except NameError:
#                 raise NameError(n)
#     
#     
#     s = inspect.getsource(func)
#     tree = ast.parse(_dedent(s))
# 
# #     from astmonkey import visitors, transformers
# #     
# #     node = transformers.ParentNodeTransformer().visit(tree)
# #     visitor = visitors.GraphNodeVisitor()
# #     visitor.visit(node)
# #     
# #     visitor.graph.write_png('graph.png')
# 
#     v = _SigNameVisitor(symdict)
#     v.visit(tree)
#     
#     return v.inputs, v.outputs
# 
# Path: sydpy/_simulator.py
# def simwait(events=None):
#     """Delay process execution by waiting for events."""
#     sim = RequiredVariable('Simulator')
#     sim.wait(events)


# Path: sydpy/_process.py
from greenlet import greenlet
from sydpy._util._util import getio_vars
from sydpy._simulator import simwait

   
    def __init__(self, module, func, *args, exit_func=None, **kwargs):
        self.func = func
        self.func_params = kwargs
        self.module = module
        self.arch = self.module.current_arch
        self.module.proc_reg(self)
        self.name = module.qualified_name + "." + func.__name__
        senslist = []
        
        for a in args:
            if hasattr(a, 'subscribe'):
                senslist.append(a)
        
        self.senslist = senslist
        self._exit_func = exit_func
        
        # If the module is to be traslated to HDL, translate the process
        if module.hdl_gen:
            self.hdl_gen()
        
        greenlet.__init__(self)
    
    def run(self):
        if self.senslist:
            while(1):
                simwait(self.senslist)
                self.func(**self.func_params)
        else:
            self.func(**self.func_params)

            simwait()