<commit_before>module HDLRuby::High::Std

    ##
    # Standard HDLRuby::High library: fsm
    # 
    ########################################################################


    ## 
    # Describes a high-level fsm type.
    class FsmT
        include HDLRuby::High::HScope_missing

        # The state class
        class State
            attr_accessor :value, :name, :code
        end

        # The name of the FSM type.
        attr_reader :name

        # The namespace associated with the FSM
        attr_reader :namespace

        # The current and next state signals.
        attr_accessor :cur_state, :next_state

        # attr_reader :states, :mk_ev, :mk_rst, :namespace

        # Creates a new fsm type with +name+.
        #
        # The proc +ruby_block+ is executed when instantiating the fsm.
        def initialize(name)
            # Check and set the name
            @name = name.to_sym

            # Initialize the internals of the FSM.


            # Initialize the environment for building the FSM

            # The states
            @states = []

            # The current and next state signals
            @cur_state = nil
            @next_state = nil

            # The event synchronizing the fsm
            @mk_ev = proc { $clk.posedge }

            # The reset
            @mk_rst = proc { $rst }

            # Creates the namespace to execute the fsm block in.
            @namespace = Namespace.new(self)

            # Generates the function for setting up the fsm.
            obj = self # For using the right self within the proc
            HDLRuby::High.space_reg(@name) do |&ruby_block|
                if ruby_block then
                    # Builds the fsm.
                    obj.build(&ruby_block)
                else
                    # Return the fsm as is.
                    return obj
                end
            end

        end

        ## builds the fsm by executing +ruby_block+.
        def build(&ruby_block)
            # Use local variable for accessing the attribute since they will
            # be hidden when opening the sytem.
            states = @states
            namespace = @namespace
            this = self
            mk_ev = @mk_ev
            mk_rst = @mk_rst

            return_value = nil


            # Enters the current system
            HDLRuby::High.cur_system.open do

                sub do
                    HDLRuby::High.space_push(namespace)
                    # Execute the instantiation block
                    return_value =HDLRuby::High.top_user.instance_exec(&ruby_block)
                    HDLRuby::High.space_pop

                    # Create the state register.
                    name = HDLRuby::High.uniq_name
                    # Declare the state register.
                    this.cur_state = [states.size].inner(name)
                    # Declare the next state wire.
                    name = HDLRuby::High.uniq_name
                    this.next_state = [states.size].inner(name)

                    # Create the fsm code
                    # Control part: update of the state.
                    par(mk_ev.call) { this.cur_state <= this.next_state }
                    # Operative part: one case per state.
                    hcase(this.cur_state)
                    states.each do |st|
                        hwhen(st.value) do
                            # Prepare the default next state.
                            this.next_state <= mux(mk_rst.call , 0, this.cur_state + 1)<commit_msg>Fixed a bit of spacing in fsm.<commit_after>module HDLRuby::High::Std

    ##
    # Standard HDLRuby::High library: fsm
    # 
    ########################################################################


    ## 
    # Describes a high-level fsm type.
    class FsmT
        include HDLRuby::High::HScope_missing

        # The state class
        class State
            attr_accessor :value, :name, :code
        end

        # The name of the FSM type.
        attr_reader :name

        # The namespace associated with the FSM
        attr_reader :namespace

        # The current and next state signals.
        attr_accessor :cur_state, :next_state

        # attr_reader :states, :mk_ev, :mk_rst, :namespace

        # Creates a new fsm type with +name+.
        #
        # The proc +ruby_block+ is executed when instantiating the fsm.
        def initialize(name)
            # Check and set the name
            @name = name.to_sym

            # Initialize the internals of the FSM.


            # Initialize the environment for building the FSM

            # The states
            @states = []

            # The current and next state signals
            @cur_state = nil
            @next_state = nil

            # The event synchronizing the fsm
            @mk_ev = proc { $clk.posedge }

            # The reset
            @mk_rst = proc { $rst }

            # Creates the namespace to execute the fsm block in.
            @namespace = Namespace.new(self)

            # Generates the function for setting up the fsm.
            obj = self # For using the right self within the proc
            HDLRuby::High.space_reg(@name) do |&ruby_block|
                if ruby_block then
                    # Builds the fsm.
                    obj.build(&ruby_block)
                else
                    # Return the fsm as is.
                    return obj
                end
            end

        end

        ## builds the fsm by executing +ruby_block+.
        def build(&ruby_block)
            # Use local variable for accessing the attribute since they will
            # be hidden when opening the sytem.
            states = @states
            namespace = @namespace
            this = self
            mk_ev = @mk_ev
            mk_rst = @mk_rst

            return_value = nil

            # Enters the current system
            HDLRuby::High.cur_system.open do
                sub do
                    HDLRuby::High.space_push(namespace)
                    # Execute the instantiation block
                    return_value =HDLRuby::High.top_user.instance_exec(&ruby_block)
                    HDLRuby::High.space_pop

                    # Create the state register.
                    name = HDLRuby::High.uniq_name
                    # Declare the state register.
                    this.cur_state = [states.size].inner(name)
                    # Declare the next state wire.
                    name = HDLRuby::High.uniq_name
                    this.next_state = [states.size].inner(name)

                    # Create the fsm code
                    # Control part: update of the state.
                    par(mk_ev.call) { this.cur_state <= this.next_state }
                    # Operative part: one case per state.
                    hcase(this.cur_state)
                    states.each do |st|
                        hwhen(st.value) do
                            # Prepare the default next state.
                            this.next_state <= mux(mk_rst.call , 0, this.cur_state + 1)
{'fraction_non_alphanumeric': 0.084286319356205, 'fraction_numerical': 0.0005647324579980235, 'mean_word_length': 1.3348714568226763, 'pattern_counts': {'":': 0, '<': 7, '<?xml version=': 0, '>': 3, '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': '3181707', 'n_tokens_mistral': 1923, 'n_tokens_neox': 1704, 'n_words': 559}