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 Attribute Summary

Attributes inherited from ChannelPort

#scope

Instance Method Summary collapse

Methods inherited from ChannelPort

#wrap

Constructor Details

#initialize(obj) ⇒ ChannelPortObject

Create a new object wrapper for +obj+.



1368
1369
1370
1371
1372
# File 'lib/HDLRuby/std/channel.rb', line 1368

def initialize(obj)
    @obj = obj

    @scope = HDLRuby::High.cur_scope
end

Instance Method Details

#read(*args, &ruby_block) ⇒ Object

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



1376
1377
1378
1379
1380
1381
1382
1383
1384
1385
1386
1387
1388
1389
# File 'lib/HDLRuby/std/channel.rb', line 1376

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.



1393
1394
1395
1396
1397
1398
1399
1400
1401
1402
1403
1404
1405
1406
# File 'lib/HDLRuby/std/channel.rb', line 1393

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