Class: HDLRuby::High::Std::SEnumerator

Inherits:
Object
  • Object
show all
Includes:
SEnumerable
Defined in:
lib/HDLRuby/std/sequencer.rb

Overview

Describes a sequencer enumerator class that allows to generate HW iteration over HW or SW objects within sequencers. This is the abstract Enumerator class.

Instance Method Summary collapse

Methods included from SEnumerable

#sall?, #sany?, #schain, #schunk, #schunk_while, #scompact, #scount, #scycle, #sdrop, #sdrop_while, #seach_cons, #seach_entry, #seach_nexts, #seach_slice, #sfind, #sfind_index, #sfirst, #sflat_map, #sgrep, #sgrep_v, #sgroup_by, #sinclude?, #sinject, #slazy, #smap, #smax, #smax_by, #smin, #smin_by, #sminmax, #sminmax_by, #snone?, #sone?, #spartition, #sreject, #sreverse_each, #sselect, #sslice_after, #sslice_before, #sslice_when, #ssort, #ssort_by, #ssort_merge, #ssum, #stake, #stake_while, #stally, #sto_a, #sto_h, #suniq, #szip

Instance Method Details

#+(obj) ⇒ Object

Return a new SEnumerator going on iteration over enumerable +obj+



1817
1818
1819
1820
1821
1822
1823
1824
1825
1826
1827
1828
1829
1830
# File 'lib/HDLRuby/std/sequencer.rb', line 1817

def +(obj)
    enum = self.clone
    obj_enum = obj.seach
    res = nil
    this = self
    HDLRuby::High.cur_system.open do
        res = this.type.inner(HDLRuby.uniq_name("enum_plus"))
    end
    return SEnumeratorBase.new(this.type,this.size+obj_enum.size) do|idx|
        HDLRuby::High.top_user.hif(idx < this.size) { res <= enum.snext }
        HDLRuby::High.top_user.helse            { res <= obj_enum.snext }
        res
    end
end

#seach(&ruby_block) ⇒ Object

Iterate on each element.



1741
1742
1743
1744
1745
1746
1747
1748
1749
1750
1751
1752
1753
# File 'lib/HDLRuby/std/sequencer.rb', line 1741

def seach(&ruby_block)
    # No block given, returns self.
    return self unless ruby_block
    # A block is given, iterate.
    this = self
    # Reinitialize the iteration.
    this.srewind
    # Perform the iteration.
    SequencerT.current.swhile(self.index < self.size) do
        # ruby_block.call(this.snext)
        HDLRuby::High.top_user.instance_exec(this.snext,&ruby_block)
    end
end

#seach_range(rng, &ruby_block) ⇒ Object

Iterator on each of the elements in range +rng+. NOTE:

  • Stop iteration when the end of the range is reached or when there are no elements left
  • This is not a method from Ruby but one specific for hardware where creating a array is very expensive.


1761
1762
1763
1764
1765
1766
1767
1768
1769
1770
1771
1772
# File 'lib/HDLRuby/std/sequencer.rb', line 1761

def seach_range(rng,&ruby_block)
    # No block given, returns a new enumerator.
    return SEnumeratorWrapper.new(self,:seach_range) unless ruby_block
    # A block is given, iterate.
    this = self
    # Perform the iteration.
    self.index <= rng.first
    SequencerT.current.swhile((self.index < self.size) & 
                              (self.index <= rng.last) ) do
        ruby_block.call(this.snext)
    end
end

#seach_with_index(&ruby_block) ⇒ Object

Iterate on each element with index.



1775
1776
1777
# File 'lib/HDLRuby/std/sequencer.rb', line 1775

def seach_with_index(&ruby_block)
    return self.with_index(&ruby_block)
end

#seach_with_object(val, &ruby_block) ⇒ Object

Iterate on each element with arbitrary object +obj+.



1780
1781
1782
1783
1784
1785
# File 'lib/HDLRuby/std/sequencer.rb', line 1780

def seach_with_object(val,&ruby_block)
    # self.seach do |elem|
    #     ruby_block(elem,val)
    # end
    return self.with_object(val,&ruby_block)
end

#with_index(&ruby_block) ⇒ Object

Iterates with an index.



1788
1789
1790
1791
1792
1793
1794
1795
1796
1797
1798
1799
1800
# File 'lib/HDLRuby/std/sequencer.rb', line 1788

def with_index(&ruby_block)
    # Is there a ruby block?
    if ruby_block then
        # Yes, iterate directly.
        idx = self.index
        return self.seach do |elem|
            ruby_block.call(elem,idx-1)
        end
    end
    # No, create a new enumerator with +with_index+ as default
    # iteration.
    return SEnumeratorWrapper.new(self,:with_index)
end

#with_object(obj) ⇒ Object

Return a new SEnumerator with an arbitrary arbitrary object +obj+.



1803
1804
1805
1806
1807
1808
1809
1810
1811
1812
1813
1814
# File 'lib/HDLRuby/std/sequencer.rb', line 1803

def with_object(obj)
    # Is there a ruby block?
    if ruby_block then
        # Yes, iterate directly.
        return self.seach do |elem|
            ruby_block.call(elem,val)
        end
    end
    # No, create a new enumerator with +with_index+ as default
    # iteration.
    return SEnumeratorWrapper.new(self,:with_object,obj)
end