Class: HDLRuby::High::Std::ChannelT

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

Overview

Describes a high-level channel type.

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(name, &ruby_block) ⇒ ChannelT

Creates a new channel type with +name+ built whose instances are created from +ruby_block+.



16
17
18
19
20
21
22
23
24
25
26
27
# File 'lib/HDLRuby/std/channel.rb', line 16

def initialize(name,&ruby_block)
    # Checks and sets the name.
    @name = name.to_sym
    # Sets the block for instantiating a channel.
    @ruby_block = ruby_block
    # Sets the instantiation procedure if named.
    return if @name.empty?
    obj = self
    HDLRuby::High.space_reg(@name) do |*args|
        obj.instantiate(*args)
    end
end

Instance Attribute Details

#nameObject (readonly)

The name of the channel type.



12
13
14
# File 'lib/HDLRuby/std/channel.rb', line 12

def name
  @name
end

Instance Method Details

#instantiate(*args) ⇒ Object Also known as: call

Intantiates a channel



30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
# File 'lib/HDLRuby/std/channel.rb', line 30

def instantiate(*args)
    obj = self
    # No argument, so not an instantiation but actually
    # an access to the channel type.
    return obj if args.empty?
    # Process the case of generic channel.
    if @ruby_block.arity > 0 then
        # Actually the arguments are generic arguments,
        # generates a new channel type with these arguments
        # fixed.
        ruby_block = @ruby_block
        return ChannelT.new(:"") do
            HDLRuby::High.top_user.instance_exec(*args,&ruby_block)
        end
    end
    # Generates the channels.
    channelI = nil
    args.each do |nameI|
        # puts "nameI=#{nameI}"
        channelI = ChannelI.new(nameI,&@ruby_block)
        # Already registered!
        # HDLRuby::High.space_reg(nameI) { channelI }
    end
    channelI
end