<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 _Waiter class """

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


from myhdl._join import join
from myhdl._simulator import _siglist, _futureEvents


class _Waiter(object):

    __slots__ = ('caller', 'generator', 'hasRun', 'semaphore')
    
    def __init__(self, generator, caller=None):
        self.generator = generator
        self.hasRun = 0
        self.caller = caller
        self.semaphore = 0
        
    def next(self):
        self.hasRun = 1
        clone = _Waiter(self.generator, self.caller)
        clause = self.generator.next()
        if type(clause) in (tuple, list):
            if clause:
                return clause, clone
            else:
                return (None,), clone
        elif type(clause) is join:
            clone.semaphore = len(clause._args)-1
            return clause._args, clone
        else:
            return (clause,), clone
    
    def hasGreenLight(self):
        if self.semaphore:
            self.semaphore -= 1
            return 0
        else:
            return 1
    
       
class _WaiterList(list):

    def purge(self):
        if self:
            self[:] = [w for w in self if not w.hasRun]<commit_msg>nrTriggers check to optimize timing<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 _Waiter class """

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


from myhdl._join import join
from myhdl._simulator import _siglist, _futureEvents


class _Waiter(object):

    __slots__ = ('caller', 'generator', 'hasRun', 'nrTriggers', 'semaphore')
    
    def __init__(self, generator, caller=None):
        self.caller = caller
        self.generator = generator
        self.hasRun = 0
        self.nrTriggers = 1
        self.semaphore = 0
        
    def next(self):
        clause = self.generator.next()
        if type(clause) in (tuple, list):
            self.hasRun = 1
            clone = _Waiter(self.generator, self.caller)
            clone.nrTriggers = len(clause)
            if clause:
                return clause, clone
            else:
                return (None,), clone
        elif type(clause) is join:
            self.hasRun = 1
            clone = _Waiter(self.generator, self.caller)
            clone.semaphore = len(clause._args)-1
            return clause._args, clone
        else:
            if self.nrTriggers == 1:
                return (clause,), self
            else:
                self.hasRun = 1
                clone = _Waiter(self.generator, self.caller)
                return (clause,), clone
    
    def hasGreenLight(self):
        if self.semaphore:
            self.semaphore -= 1
            return 0
        else:
            return 1
    
       
class _WaiterList(list):

    def purge(self):
        if self:
            self[:] = [w for w in self if not w.hasRun]
{'fraction_non_alphanumeric': 0.0817812031684864, 'fraction_numerical': 0.012417041318775423, 'mean_word_length': 2.3017667844522967, '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': '3344302', 'n_tokens_mistral': 1382, 'n_tokens_neox': 1327, 'n_words': 513}