<commit_before>#  This file is part of the myhdl library, a Python package for using
#  Python as a Hardware Description Language.
#
#  Copyright (C) 2003 <NAME>
#
#  The myhdl library is free software; you can redistribute it and/or
#  modify it under the terms of the GNU Lesser General Public License as
#  published by the Free Software Foundation; either version 2.1 of the
#  License, or (at your option) any later version.
#
#  This library is distributed in the hope that it will be useful, but
#  WITHOUT ANY WARRANTY; without even the implied warranty of
#  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
#  Lesser General Public License for more details.

#  You should have received a copy of the GNU Lesser General Public
#  License along with this library; if not, write to the Free Software
#  Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA

""" Module that provides the Signal class and related objects.

This module provides the following objects:

Signal -- class to model hardware signals
posedge -- callable to model a rising edge on a signal in a yield statement
negedge -- callable to model a falling edge on a signal in a yield statement

"""
__author__ = "<NAME> <<EMAIL>>"
__revision__ = "$Revision$"
__date__ = "$Date$"

from __future__ import generators
from copy import deepcopy as copy

import _simulator as sim
from _simulator import _siglist, _futureEvents, now
from myhdl import intbv
from bin import bin

_schedule = _futureEvents.append

class _WaiterList(list):

    def purge(self):
        if self:
            self[:] = [w for w in self if not w.hasRun]
        

def posedge(sig):
    """ Return a posedge trigger object """
    return sig.posedge

def negedge(sig):
    """ Return a negedge trigger object """
    return sig.negedge

class Signal(object):

    """ Signal class.

    Properties:
    val -- current value (read-only)
    next -- next value (read-write)

    """

    __slots__ = ('_next', '_val', '_min', '_max', '_type', 
                 '_eventWaiters', '_posedgeWaiters', '_negedgeWaiters',
                 '_code', '_tracing', '_nrbits', '_checkVal',
                 '_printVcd'
                )

    def __new__(cls, val, delay=0):
        """ Return a new Signal (default or delay 0) or DelayedSignal """
        if delay:
            return object.__new__(DelayedSignal)
        else:
            return object.__new__(cls)

    def __init__(self, val):
        """ Construct a signal.

        val -- initial value
        
        """
        self._next = self._val = val
        self._min = self._max = self._nrbits = None
        self._type = (int, long, intbv)
        self._printVcd = self._printVcdStr
        if type(val) is bool:
            self._checkVal = self._checkBool
            self._nrbits = 1
        elif isinstance(val, (int, long)):
            self._checkVal = self._checkInt
            self._printVcd = self._printVcdHex
        elif isinstance(val, intbv):
            self._min = val._min
            self._max = val._max
            self._nrbits = val._nrbits
            if self._nrbits:
                self._checkVal = self._checkIntbvBounds
                self._printVcd = self._printVcdVec
            else:
                self._checkVal = self._checkInt
                self._printVcd = self._printVcdHex
        else:
            self._type = type(val)
            self._checkVal = self._checkType
        self._eventWaiters = _WaiterList()
        self._posedgeWaiters = _WaiterList()
        self._negedgeWaiters = _WaiterList()
        self._code = ""
        self._tracing = 0
        
    def _update(self):
        if self._val != self._next:
            waiters = self._eventWaiters[:]
            del self._eventWaiters[:]
            if not self._val and self._next:<commit_msg>vcd print for bool<commit_after>#  This file is part of the myhdl library, a Python package for using
#  Python as a Hardware Description Language.
#
#  Copyright (C) 2003 <NAME>
#
#  The myhdl library is free software; you can redistribute it and/or
#  modify it under the terms of the GNU Lesser General Public License as
#  published by the Free Software Foundation; either version 2.1 of the
#  License, or (at your option) any later version.
#
#  This library is distributed in the hope that it will be useful, but
#  WITHOUT ANY WARRANTY; without even the implied warranty of
#  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
#  Lesser General Public License for more details.

#  You should have received a copy of the GNU Lesser General Public
#  License along with this library; if not, write to the Free Software
#  Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA

""" Module that provides the Signal class and related objects.

This module provides the following objects:

Signal -- class to model hardware signals
posedge -- callable to model a rising edge on a signal in a yield statement
negedge -- callable to model a falling edge on a signal in a yield statement

"""
__author__ = "<NAME> <<EMAIL>>"
__revision__ = "$Revision$"
__date__ = "$Date$"

from __future__ import generators
from copy import deepcopy as copy

import _simulator as sim
from _simulator import _siglist, _futureEvents, now
from myhdl import intbv
from bin import bin

_schedule = _futureEvents.append

class _WaiterList(list):

    def purge(self):
        if self:
            self[:] = [w for w in self if not w.hasRun]
        

def posedge(sig):
    """ Return a posedge trigger object """
    return sig.posedge

def negedge(sig):
    """ Return a negedge trigger object """
    return sig.negedge

class Signal(object):

    """ Signal class.

    Properties:
    val -- current value (read-only)
    next -- next value (read-write)

    """

    __slots__ = ('_next', '_val', '_min', '_max', '_type', 
                 '_eventWaiters', '_posedgeWaiters', '_negedgeWaiters',
                 '_code', '_tracing', '_nrbits', '_checkVal',
                 '_printVcd'
                )

    def __new__(cls, val, delay=0):
        """ Return a new Signal (default or delay 0) or DelayedSignal """
        if delay:
            return object.__new__(DelayedSignal)
        else:
            return object.__new__(cls)

    def __init__(self, val):
        """ Construct a signal.

        val -- initial value
        
        """
        self._next = self._val = val
        self._min = self._max = self._nrbits = None
        self._type = (int, long, intbv)
        self._printVcd = self._printVcdStr
        if type(val) is bool:
            self._checkVal = self._checkBool
            self._printVcd = self._printVcdBit
            self._nrbits = 1
        elif isinstance(val, (int, long)):
            self._checkVal = self._checkInt
        elif isinstance(val, intbv):
            self._min = val._min
            self._max = val._max
            self._nrbits = val._nrbits
            if self._nrbits:
                self._checkVal = self._checkIntbvBounds
                self._printVcd = self._printVcdVec
            else:
                self._checkVal = self._checkInt
                self._printVcd = self._printVcdHex
        else:
            self._type = type(val)
            self._checkVal = self._checkType
        self._eventWaiters = _WaiterList()
        self._posedgeWaiters = _WaiterList()
        self._negedgeWaiters = _WaiterList()
        self._code = ""
        self._tracing = 0
        
    def _update(self):
        if self._val != self._next:
            waiters = self._eventWaiters[:]
            del self._eventWaiters[:]
            if not self._val and self._next:
{'fraction_non_alphanumeric': 0.08571056402240458, 'fraction_numerical': 0.0062524423602969914, 'mean_word_length': 2.3066322136089576, 'pattern_counts': {'":': 0, '<': 11, '<?xml version=': 0, '>': 11, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '3549113', 'n_tokens_mistral': 2207, 'n_tokens_neox': 2120, 'n_words': 790}