Class: Range
- Inherits:
-
Object
- Object
- Range
- Includes:
- HEnumerable, SEnumerable
- Defined in:
- lib/HDLRuby/hruby_high.rb,
lib/HDLRuby/std/sequencer.rb,
lib/HDLRuby/std/hruby_enum.rb
Overview
Extends the range class to support to_low
Instance Method Summary collapse
-
#heach(&ruby_block) ⇒ Object
Redefinition of heach to support also HDLRuby Values.
-
#seach(&ruby_block) ⇒ Object
HW iteration on each element.
-
#to_low ⇒ Object
Convert the first and last to HDLRuby::Low.
Instance Method Details
#heach(&ruby_block) ⇒ Object
Redefinition of heach to support also HDLRuby Values.
5759 5760 5761 5762 5763 5764 5765 5766 5767 |
# File 'lib/HDLRuby/hruby_high.rb', line 5759 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.
2245 2246 2247 2248 2249 2250 2251 2252 2253 2254 2255 2256 2257 2258 2259 2260 2261 2262 2263 2264 2265 2266 2267 2268 2269 2270 2271 2272 2273 2274 2275 2276 2277 2278 2279 2280 2281 2282 2283 2284 2285 2286 2287 2288 2289 |
# File 'lib/HDLRuby/std/sequencer.rb', line 2245 def seach(&ruby_block) # Create the iteration type. # if self.first < 0 || self.last < 0 then # fw = self.first.is_a?(Numeric) ? self.first.abs.width : # self.first.width # lw = self.last.is_a?(Numeric) ? self.last.abs.width : # self.last.width # typ = signed[[fw,lw].max] # else # typ = bit[[self.first.width,self.last.width].max] # end # 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 if this.last.is_a?(SignalI) or this.first.is_a?(SignalI) then size = this.last.to_expr - this.first.to_expr + 1 else size = this.last.to_i - this.first.to_i + 1 end size = size.to_expr.as(typ) # hw_enum = SEnumeratorBase.new(signed[32],size) do |idx| hw_enum = SEnumeratorBase.new(typ,size) do |idx| # idx.as(typ) + this.first 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 |
#to_low ⇒ Object
Convert the first and last to HDLRuby::Low
5748 5749 5750 5751 5752 5753 5754 |
# File 'lib/HDLRuby/hruby_high.rb', line 5748 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 |