class HDLRuby::High::Namespace

Describes a namespace. Used for managing the access points to internals of hardware constructs.

Constants

RESERVED

The reserved names

Attributes

user[R]

The construct using the namespace.

Public Class Methods

new(user) click to toggle source

Creates a new namespace attached to user.

# File lib/HDLRuby/hruby_high.rb, line 63
def initialize(user)
    # Sets the user.
    @user = user
    # Initialize the concat namespaces.
    @concats = []
end

Public Instance Methods

add_method(name,&ruby_block) click to toggle source

Adds method name provided the name is not empty and the method is not already defined in the current namespace.

# File lib/HDLRuby/hruby_high.rb, line 83
def add_method(name,&ruby_block)
    # puts "add_method with name=#{name} and parameters=#{ruby_block.parameters}"
    unless name.empty? then
        if RESERVED.include?(name.to_sym) then
            raise AnyError, 
                  "Resevered name #{name} cannot be overridden."
        end
        if self.respond_to?(name) then
            raise AnyError,
                  "Symbol #{name} is already defined."
        end
        define_singleton_method(name,&ruby_block) 
    end
end
clone() click to toggle source

Clones (safely) the namespace.

# File lib/HDLRuby/hruby_high.rb, line 71
def clone
    # Create the new namespace.
    res = Namespace.new(@user)
    # Adds the concats.
    @concats.each do |concat|
        res.concat_namespace(concat)
    end
    return res
end
concat_namespace(namespace) click to toggle source

Concats another namespace to current one.

# File lib/HDLRuby/hruby_high.rb, line 99
def concat_namespace(namespace)
    # Ensure namespace is really a namespace and concat it.
    namespace = namespace.to_namespace
    self.eigen_extend(namespace)
    # Adds the concat the the list.
    @concats << namespace
end
to_namespace() click to toggle source

Ensure it is a namespace

# File lib/HDLRuby/hruby_high.rb, line 108
def to_namespace
    return self
end
user?(object) click to toggle source

Tell if an object is the user of the namespace.

# File lib/HDLRuby/hruby_high.rb, line 113
def user?(object)
    return @user.equal?(object)
end
user_deep?(object) click to toggle source

Tell if an object is the user of the namespace or of one of its concats.

# File lib/HDLRuby/hruby_high.rb, line 119
def user_deep?(object)
    # puts "@user=#{@user}, @concats=#{@concats.size}, object=#{object}"
    # Convert the object to a user if appliable (for SystemT)
    object = object.to_user if object.respond_to?(:to_user)
    # Maybe object is the user of this namespace.
    return true if user?(object)
    # No, try in the concat namespaces.
    @concats.any? { |concat| concat.user_deep?(object) }
end