Class: HDLRuby::High::Std::ChannelPortObject

Inherits:
ChannelPort
  • Object
show all
Defined in:
lib/HDLRuby/std/channel.rb

Overview

Wrapper to make an object run like a channel port.

Instance Method Summary collapse

Methods inherited from ChannelPort

#wrap

Constructor Details

#initialize(obj) ⇒ ChannelPortObject

Create a new object wrapper for +obj+.



926
927
928
# File 'lib/HDLRuby/std/channel.rb', line 926

def initialize(obj)
    @obj = obj
end

Instance Method Details

#read(*args, &ruby_block) ⇒ Object

Port read with arguments +args+ executing +ruby_block+ in case of success.



932
933
934
935
936
937
938
939
940
941
942
943
944
945
# File 'lib/HDLRuby/std/channel.rb', line 932

def read(*args,&ruby_block)
    # Get the target from the arguments.
    target = args.pop
    # Is there any argument left?
    unless (args.empty?) then
        # There are arguments left, perform an array access.
        target <= @obj[*args]
    else
        # There are no argument left, perform a direct access.
        target <= @obj
    end
    # Execute the ruby_block if any.
    ruby_block.call if ruby_block 
end

#write(*args, &ruby_block) ⇒ Object

Port write with argumnet +Args+ executing +ruby_block+ in case of success.



949
950
951
952
953
954
955
956
957
958
959
960
961
962
# File 'lib/HDLRuby/std/channel.rb', line 949

def write(*args,&ruby_block)
    # Get the value to write from the arguments.
    value = args.pop
    # Is there any argument left?
    unless (args.empty?) then
        # There are arguments left, perform an array access.
        @obj[*args] <= value
    else
        # There are no argument left, perform a direct access.
        @obj <= value
    end
    # Execute the ruby_block if any.
    ruby_block.call if ruby_block 
end