Module: HDLRuby::High::HRef

Includes:
Enumerable
Included in:
RefConcat, RefIndex, RefName, RefObject, RefRange, RefThis, SignalC, SignalI
Defined in:
lib/HDLRuby/hruby_high.rb

Overview

Module giving high-level reference properties.

Class Method Summary collapse

Instance Method Summary collapse

Methods included from Enumerable

#seach

Class Method Details

.included(klass) ⇒ Object

Properties of expressions are also required



3460
3461
3462
3463
3464
3465
3466
3467
3468
3469
3470
3471
3472
3473
3474
3475
3476
3477
3478
3479
3480
3481
3482
3483
3484
3485
3486
3487
3488
# File 'lib/HDLRuby/hruby_high.rb', line 3460

def self.included(klass)
    klass.class_eval do
        include HExpression
        include HArrow

        # Update the initialize to handle struct types accesses if
        # it is not a RefObject, this latter being a proxy to a
        # real component.
        if klass != RefObject then
            original_initialize = instance_method(:initialize)
            define_method(:initialize) do |*args, &block|
                original_initialize.bind(self).call(*args,&block)
                # Now process it if it is a structured type.
                if self.type.struct? then
                    self.type.each do |name,typ|
                        self.define_singleton_method(name) do
                            RefName.new(typ,self,name)
                        end
                    end
                end
            end
        end

        # Converts to a new expression.
        def to_expr
            self.to_ref
        end
    end
end

Instance Method Details

#each(&ruby_block) ⇒ Object

Iterate over the elements.

Returns an enumerator if no ruby block is given.



3506
3507
3508
3509
3510
3511
3512
3513
# File 'lib/HDLRuby/hruby_high.rb', line 3506

def each(&ruby_block)
    # No ruby block? Return an enumerator.
    return to_enum(:each) unless ruby_block
    # A block? Apply it on each element.
    self.type.range.heach do |i|
        yield(self[i])
    end
end

#objectsObject

Get the refered objects.



3516
3517
3518
3519
# File 'lib/HDLRuby/hruby_high.rb', line 3516

def objects
    return [ self.object] if self.is_a?(RefObject)
    return self.each.map { |ref| ref.objects }.flatten
end

#to_eventObject

Converts to a new event.



3498
3499
3500
3501
# File 'lib/HDLRuby/hruby_high.rb', line 3498

def to_event
    # return Event.new(:change,self.to_ref)
    return Event.new(:anyedge,self.to_ref)
end

#to_refObject

Converts to a new reference.

NOTE: to be redefined in case of non-reference class.

Raises:



3493
3494
3495
# File 'lib/HDLRuby/hruby_high.rb', line 3493

def to_ref
    raise AnyError, "Internal error: to_ref not defined yet for class: #{self.class}"
end