Class: HDLRuby::High::Std::SEnumerator
- Inherits:
-
Object
- Object
- HDLRuby::High::Std::SEnumerator
- 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.
Direct Known Subclasses
SEnumeratorBase, SEnumeratorSub, SEnumeratorWrapper, SequencerChannel
Instance Method Summary collapse
-
#+(obj) ⇒ Object
Return a new SEnumerator going on iteration over enumerable +obj+.
-
#seach(&ruby_block) ⇒ Object
Iterate on each element.
-
#seach_range(rng, &ruby_block) ⇒ Object
Iterator on each of the elements in range +rng+.
-
#seach_with_index(&ruby_block) ⇒ Object
Iterate on each element with index.
-
#seach_with_object(val, &ruby_block) ⇒ Object
Iterate on each element with arbitrary object +obj+.
-
#with_index(&ruby_block) ⇒ Object
Iterates with an index.
-
#with_object(obj) ⇒ Object
Return a new SEnumerator with an arbitrary arbitrary object +obj+.
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+
1832 1833 1834 1835 1836 1837 1838 1839 1840 1841 1842 1843 1844 1845 |
# File 'lib/HDLRuby/std/sequencer.rb', line 1832 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.
1756 1757 1758 1759 1760 1761 1762 1763 1764 1765 1766 1767 1768 |
# File 'lib/HDLRuby/std/sequencer.rb', line 1756 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.
1776 1777 1778 1779 1780 1781 1782 1783 1784 1785 1786 1787 |
# File 'lib/HDLRuby/std/sequencer.rb', line 1776 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.
1790 1791 1792 |
# File 'lib/HDLRuby/std/sequencer.rb', line 1790 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+.
1795 1796 1797 1798 1799 1800 |
# File 'lib/HDLRuby/std/sequencer.rb', line 1795 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.
1803 1804 1805 1806 1807 1808 1809 1810 1811 1812 1813 1814 1815 |
# File 'lib/HDLRuby/std/sequencer.rb', line 1803 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+.
1818 1819 1820 1821 1822 1823 1824 1825 1826 1827 1828 1829 |
# File 'lib/HDLRuby/std/sequencer.rb', line 1818 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 |