@willow-dls/core
    Preparing search index...

    Class CircuitElementAbstract

    A circuit element is a component in a circuit. It represents the fundamental unit of a circuit and is connected via CircuitBuses. Elements can be logic gates or more complex combinatorial elements. They can even represent sequential elements, though sequential elements are much more complex and require much greater care when implementing.

    A circuit elements takes its inputs via CircuitBuses, processes them via the resolve function, and outputs the results via its output CircuitBuses. This model seems to work well for most elements, but some bi-directional elements require particularly tricky workarounds, such as Splitter.

    The simulation engine keeps track of what values are on the buses, and will take care to evaluate the circuit as few times as possible; if the inputs don't change, then it is assumed that the outputs won't change either and so the circuit element will not be resolved again. The engine will notify an element when its inputs change by calling resolve, which is responsible for propagating the inputs through the element and to the output buses. When the values on the output buses are changed, the engine will notify all downstream elements (that is, have inputs connected to these outputs) via their own resolve function.

    Hierarchy (View Summary)

    Index

    Constructors

    • Construct a new circuit element.

      Parameters

      • subsystem: string

        Since CircuitElement is CircuitLoggable, it accepts a subsystem label. Subclasses should provide a descriptive subsystem label which ends in "Element" to allow convenient regex matching. In fact, this convention is enforced; if an element's subsystem doesn't end in "Element", the word is appended directly to the subsystem label before being passed to the CircuitLoggable constructor. For example, if you provide "AndGate", the actual subsystem label will be "AndGateElement". But if you directly provide "AndGateElemement", that will be passed through unchanged.

      • inputs: CircuitBus[]

        An array of input CircuitBuses. Whenever the values on these buses change, the circuit element will be notified via the resolve function.

      • outputs: CircuitBus[]

        An array of output CircuitBuses.

      Returns CircuitElement

    Methods

    • Attach a logger to this loggable object so that messages logged with log will be send to this logger. Note that this can be called multiple times and multiple loggers can be attached to the same object. Log messages will be sent to all attached loggers.

      Parameters

      Returns void

    • Everything that is loggable gets a unique ID, which can help identify instances of objects in logs when many such instances exist. This ID is normally generated automatically by CircuitLoggable when it is instantiated, unless this method has been by child classes.

      Returns string

      A unique ID among all loggable objects.

    • Get the stored label of this element. See comments for setLabel.

      Returns null | string

      The stored label, or null if the label was never set.

    • Log a message, sending it to all loggers associated with this loggable.

      Parameters

      • level: LogLevel

        The log level to log the message at.

      • msg: string

        The message to log.

      • Optionaldata: any

        Any additional data to associate with the message.

      Returns void

    • Propagate all registered loggers (present and future) to the given loggable. This function will register the loggable object with the object it is being called on, establishing a parent-child relationship where all changes to the parent loggers will be propagated to the children.

      Parameters

      • loggable: CircuitLoggable

        The loggable object to attach all registered loggers to.

      Returns void

    • This method resets the circuit element to a known state, and is called at the beginning of each simulation run, but not between clock cycles. It is expected to be overridden only by child elements who have internal state which they may need to reset when the circuit is re-run with new inputs.

      For example, see the Splitter element or any of the flip-flops, which are sequential elements and thus must retain a history of inputs and outputs to know how to propagate new outputs.

      If you are going to override this method, be sure to still call the superclass method first: super.reset().

      Returns void

    • Compute this element's output values after the input values have changed. This function can use getInputs to get the inputs in the same order they were passed to the constructor. It is helpful to destructure the array using the same names as were provided to the constructor. Likewise, this function can use getOutputs to get the output buses in the same order they were passed to the constructor.

      The goal of this function is to actually do the logic of the element, translating the values on the input buses to values on the output buses.

      Returns number

      The actual propagation delay of this element. Even though this class provides getPropagationDelay and setPropagationDelay, a circuit element may actually take more or less time to evaluate itself, and in some cases, a fixed call to setPropagationDelay with a static number isn't appropriate at all (e.g. in the case of SubCircuit, which inherits the propagation delay from the actual subcircuit.)

    • Set the label on this element. Some circuit simulators allow arbitrary labels on all elements, which is useful for debugging purposes. If a label is provided, it will be printed in the logs to more easily identify circuit elements.

      Parameters

      • label: string

        The label of this circuit element.

      Returns CircuitElement

      An instance of this element for method chaining.

    • Store a propagation delay number. This function is useful when loading in circuit elements which support custom propagation delays, so that resolve can return the result of getPropagationDelay if it is constant and doesn't change with each resolution.

      Parameters

      • delay: number

        The propagation delay to store.

      Returns CircuitElement

      An instance of this element for method chaining.

    • Convert this element to a string for representation in log output.

      Returns string

      A string in the format of ClassName[id=XXX]('YYY') where ClassName is the name of the class, XXX is the unique loggable ID of the specific class instance, and YYY is the user-provided label set by setLabel, if any.