Class: Range

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

Overview

Extends the range class to support to_low

Instance Method Summary collapse

Instance Method Details

#heach(&ruby_block) ⇒ Object

Iterates over the range as hardware.

Returns an enumerator if no ruby block is given.



5215
5216
5217
5218
5219
5220
5221
5222
5223
# File 'lib/HDLRuby/hruby_high.rb', line 5215

def heach(&ruby_block)
    # No ruby block? Return an enumerator.
    return to_enum(:heach) unless ruby_block
    # Order the bounds to be able to iterate.
    first,last = self.first, self.last
    first,last = first > last ? [last,first] : [first,last]
    # Iterate.
    (first..last).each(&ruby_block)
end

#seach(&ruby_block) ⇒ Object

HW iteration on each element.



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

def seach(&ruby_block)
    # Create the iteration type.
    typ = bit[[self.first.width,self.last.width].max]
    # Create the hardware iterator.
    this = self
    size = this.size ? this.size : this.last - this.first + 1
    hw_enum = SEnumeratorBase.new(signed[32],size) do |idx|
        idx.as(typ) + this.first
    end
    # Is there a ruby block?
    if(ruby_block) then
        # Yes, apply it.
        return hw_enum.seach(&ruby_block)
    else
        # No, return the resulting enumerator.
        return hw_enum
    end
end

#to_lowObject

Convert the first and last to HDLRuby::Low



5204
5205
5206
5207
5208
5209
5210
# File 'lib/HDLRuby/hruby_high.rb', line 5204

def to_low
    first = self.first
    first = first.respond_to?(:to_low) ? first.to_low : first
    last = self.last
    last = last.respond_to?(:to_low) ? last.to_low : last
    return (first..last)
end