Class: HDLRuby::High::Std::AnyRange

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

Overview

Range substitute class for sequencers that supports any kind of bounds.

Instance Attribute Summary collapse

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_range, #seach_slice, #seach_with_index, #seach_with_object, #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

Constructor Details

#initialize(first, last) ⇒ AnyRange

Returns a new instance of AnyRange.



2280
2281
2282
2283
# File 'lib/HDLRuby/std/sequencer.rb', line 2280

def initialize(first,last)
    @first = first
    @last = last
end

Instance Attribute Details

#firstObject (readonly)

Returns the value of attribute first.



2278
2279
2280
# File 'lib/HDLRuby/std/sequencer.rb', line 2278

def first
  @first
end

#lastObject (readonly)

Returns the value of attribute last.



2278
2279
2280
# File 'lib/HDLRuby/std/sequencer.rb', line 2278

def last
  @last
end

Instance Method Details

#seach(&ruby_block) ⇒ Object

HW iteration on each element.



2286
2287
2288
2289
2290
2291
2292
2293
2294
2295
2296
2297
2298
2299
2300
2301
2302
2303
2304
2305
2306
2307
2308
2309
2310
2311
2312
2313
2314
# File 'lib/HDLRuby/std/sequencer.rb', line 2286

def seach(&ruby_block)
    # Create the iteration type: selection of the larger HDLRuby type
    # between first and last. If one of first and last is a Numeric,
    # priority to the non Numeric one.
    if (self.last.is_a?(Numeric)) then
        typ = self.first.to_expr.type
    elsif (self.first.is_a?(Numeric)) then
        typ = self.last.to_expr.type
    else
        typ = self.first.type.width > self.last.type.width ? 
            self.first.type : self.last.type
    end
    # Create the hardware iterator.
    this = self
    # size = this.size ? this.size : this.last - this.first + 1
    size = this.last - this.first + 1
    size = size.to_expr.as(typ)
    hw_enum = SEnumeratorBase.new(typ,size) do |idx|
        idx.as(typ) + this.first.to_expr.as(typ)
    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