Class: HDLRuby::High::Namespace
- Inherits:
-
Object
- Object
- HDLRuby::High::Namespace
- Includes:
- SingletonExtend
- Defined in:
- lib/HDLRuby/hruby_high.rb
Overview
Describes a namespace. Used for managing the access points to internals of hardware constructs.
Constant Summary collapse
- RESERVED =
The reserved names
Set.new( [ :user, :initialize, :add_method, :concat_namespace, :to_namespace, :user?, :user_deep?, :sub, :seq, :par, :hif, :helse, :hcase, :hwhen, :mux, :timed ])
Instance Attribute Summary collapse
-
#user ⇒ Object
readonly
The construct using the namespace.
Instance Method Summary collapse
-
#add_method(name, &ruby_block) ⇒ Object
Adds method
nameprovided the name is not empty and the method is not already defined in the current namespace. -
#clone ⇒ Object
Clones (safely) the namespace.
-
#concat_namespace(namespace) ⇒ Object
Concats another
namespaceto current one. -
#initialize(user) ⇒ Namespace
constructor
Creates a new namespace attached to
user. -
#to_namespace ⇒ Object
Ensure it is a namespace.
-
#user?(object) ⇒ Boolean
Tell if an
objectis the user of the namespace. -
#user_deep?(object) ⇒ Boolean
Tell if an
objectis the user of the namespace or of one of its concats.
Methods included from SingletonExtend
Constructor Details
#initialize(user) ⇒ Namespace
Creates a new namespace attached to user.
75 76 77 78 79 80 |
# File 'lib/HDLRuby/hruby_high.rb', line 75 def initialize(user) # Sets the user. @user = user # Initialize the concat namespaces. @concats = [] end |
Instance Attribute Details
#user ⇒ Object (readonly)
The construct using the namespace.
72 73 74 |
# File 'lib/HDLRuby/hruby_high.rb', line 72 def user @user end |
Instance Method Details
#add_method(name, &ruby_block) ⇒ Object
Adds method name provided the name is not empty and the method
is not already defined in the current namespace.
95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 |
# File 'lib/HDLRuby/hruby_high.rb', line 95 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 # Deactivated: overriding is now accepted. # if self.respond_to?(name) then # raise AnyError, # "Symbol #{name} is already defined." # end define_singleton_method(name,&ruby_block) end end |
#clone ⇒ Object
Clones (safely) the namespace.
83 84 85 86 87 88 89 90 91 |
# File 'lib/HDLRuby/hruby_high.rb', line 83 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) ⇒ Object
Concats another namespace to current one.
112 113 114 115 116 117 118 |
# File 'lib/HDLRuby/hruby_high.rb', line 112 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 ⇒ Object
Ensure it is a namespace
121 122 123 |
# File 'lib/HDLRuby/hruby_high.rb', line 121 def to_namespace return self end |
#user?(object) ⇒ Boolean
Tell if an object is the user of the namespace.
126 127 128 |
# File 'lib/HDLRuby/hruby_high.rb', line 126 def user?(object) return @user.equal?(object) end |
#user_deep?(object) ⇒ Boolean
Tell if an object is the user of the namespace or of one of its
concats.
132 133 134 135 136 137 138 139 140 |
# File 'lib/HDLRuby/hruby_high.rb', line 132 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 |