def _makeWaiters(arglist):
    waiters = []
    ids = set()
    cosim = None
    for arg in arglist:
        if isinstance(arg, GeneratorType):
            waiters.append(_inferWaiter(arg))
        elif isinstance(arg, _Instantiator):
            waiters.append(arg.waiter)
        elif isinstance(arg, Cosimulation):
            if cosim is not None:
                raise SimulationError(_error.MultipleCosim)
            cosim = arg
            waiters.append(_SignalTupleWaiter(cosim._waiter()))
        elif isinstance(arg, _Waiter):
            waiters.append(arg)
        elif arg == True:
            pass
        else:
            raise SimulationError(_error.ArgType, str(type(arg)))
        if id(arg) in ids:
            raise SimulationError(_error.DuplicatedArg)
        ids.add(id(arg))
    # add waiters for shadow signals
    for sig in _signals:
        if hasattr(sig, '_waiter'):
            waiters.append(sig._waiter)
    return waiters, cosim
Example #2
0
    def __init__(self, *args):
        """ Construct a simulation object.

        *args -- list of arguments. Each argument is a generator or
                 a nested sequence of generators.

        """
        _simulator._time = 0
        arglist = _flatten(*args)
        self._waiters, self._cosims = _makeWaiters(arglist)
        if Simulation._no_of_instances > 0:
            raise SimulationError(_error.MultipleSim)
        Simulation._no_of_instances += 1
        self._finished = False
        del _futureEvents[:]
        del _siglist[:]