Module: HDLRuby::High::Htype
- Includes:
- Tprocess
- Included in:
- Type, TypeDef, TypeStruct, TypeTuple, TypeVector
- Defined in:
- lib/HDLRuby/hruby_high.rb,
lib/HDLRuby/std/sequencer_sync.rb
Overview
Enhance the Htype module for creating a shared signal.
Constant Summary collapse
Class Method Summary collapse
-
.included(base) ⇒ Object
Ensures initialize registers the type name.
Instance Method Summary collapse
-
#[](rng) ⇒ Object
Creates a new vector type of range
rngand with current type as base. -
#binary(operator, expr0, expr1) ⇒ Object
Performs binary operation
operatoron expressionsexpr0andexpr1. -
#comp_operator(op) ⇒ Object
Gets the computation method for
operator. -
#constant(hsh) ⇒ Object
Declares high-level untyped constant signals by name and value given by
hshof the current type. -
#define_operator(operator, &ruby_block) ⇒ Object
Redefinition of
operator. -
#define_operator_with_context(operator, &ruby_block) ⇒ Object
Redefinition of
operatorwhen requiring the context to be passed as argument (normally only used internally). -
#each_overload(&ruby_block) ⇒ Object
Interates over the overloaded operators.
-
#htype? ⇒ Boolean
Tells htype has been included.
-
#inner(*names) ⇒ Object
Declares high-level untyped inner signals named
namesof the current type. -
#inout(*names) ⇒ Object
Declares high-level untyped inout signals named
namesof the current type. -
#input(*names) ⇒ Object
Declares high-level input signals named
namesof the current type. -
#left ⇒ Object
Gets the type as left value.
-
#name=(name) ⇒ Object
Sets the
name. -
#output(*names) ⇒ Object
Declares high-level untyped output signals named
namesof the current type. -
#register(name) ⇒ Object
Register the
nameof the type. -
#right ⇒ Object
Gets the type as right value.
-
#shared(*args) ⇒ Object
Create new shared signals from
args. -
#to_type ⇒ Object
Converts to a type.
-
#typedef(name) ⇒ Object
Declares a new type definition with
nameequivalent to current one. -
#unary(operator, expr) ⇒ Object
Performs unary operation
operatoron expressionexpr.
Methods included from Tprocess
#&, #*, #+, #+@, #-@, #/, #<<, #==, #abs, #lr, #make, #resolve, #slice, #~
Class Method Details
.included(base) ⇒ Object
Ensures initialize registers the type name
1797 1798 1799 1800 1801 1802 1803 1804 1805 1806 |
# File 'lib/HDLRuby/hruby_high.rb', line 1797 def self.included(base) # built-in Ruby hook for modules base.class_eval do original_method = instance_method(:initialize) define_method(:initialize) do |*args, &block| original_method.bind(self).call(*args, &block) # Registers the name (if not empty). self.register(name) unless name.empty? end end end |
Instance Method Details
#[](rng) ⇒ Object
Creates a new vector type of range rng and with current type as
base.
1878 1879 1880 |
# File 'lib/HDLRuby/hruby_high.rb', line 1878 def [](rng) return TypeVector.new(:"",self,rng) end |
#binary(operator, expr0, expr1) ⇒ Object
Performs binary operation operator on expressions expr0
and expr1.
1937 1938 1939 1940 1941 1942 1943 1944 1945 1946 1947 1948 |
# File 'lib/HDLRuby/hruby_high.rb', line 1937 def binary(operator, expr0, expr1) # Look for a specific computation method. comp = comp_operator(operator) if self.respond_to?(comp) then # Found, use it. self.send(comp,expr0,expr1) else # Not found, back to default generation of binary expression. return Binary.new(self.send(operator,expr1.type),operator, expr0,expr1) end end |
#comp_operator(op) ⇒ Object
Gets the computation method for operator.
1918 1919 1920 |
# File 'lib/HDLRuby/hruby_high.rb', line 1918 def comp_operator(op) return (op.to_s + ":C").to_sym end |
#constant(hsh) ⇒ Object
Declares high-level untyped constant signals by name and
value given by hsh of the current type.
1911 1912 1913 |
# File 'lib/HDLRuby/hruby_high.rb', line 1911 def constant(hsh) High.top_user.make_constants(self,hsh) end |
#define_operator(operator, &ruby_block) ⇒ Object
Redefinition of operator.
1951 1952 1953 1954 1955 1956 1957 1958 1959 1960 1961 1962 1963 1964 |
# File 'lib/HDLRuby/hruby_high.rb', line 1951 def define_operator(operator,&ruby_block) # Ensure there is a block. ruby_block = proc {} unless block_given? # Register the operator as overloaded. @overloads ||= {} @overloads[operator] = ruby_block # Set the new method for the operator. self.define_singleton_method(comp_operator(operator)) do |*args| # puts "Top user=#{HDLRuby::High.top_user}" HDLRuby::High.top_user.sub(HDLRuby.uniq_name) do ruby_block.call(*args) end end end |
#define_operator_with_context(operator, &ruby_block) ⇒ Object
Redefinition of operator when requiring the context to be passed
as argument (normally only used internally).
1968 1969 1970 1971 1972 1973 1974 1975 1976 1977 1978 1979 1980 1981 1982 1983 |
# File 'lib/HDLRuby/hruby_high.rb', line 1968 def define_operator_with_context(operator,&ruby_block) # Ensure there is a block. ruby_block = proc {} unless block_given? # Register the operator as overloaded. @overloads ||= {} @overloads[operator] = ruby_block # Set the new method for the operator. self.define_singleton_method(comp_operator(operator)) do |*args| # puts "Top user=#{HDLRuby::High.top_user}" HDLRuby::High.top_user.sub(HDLRuby.uniq_name) do # It is assumed that the first argument of the ruby_block # is the context in which it must be executed. ruby_block.call(self,*args) end end end |
#each_overload(&ruby_block) ⇒ Object
Interates over the overloaded operators.
1986 1987 1988 1989 1990 1991 |
# File 'lib/HDLRuby/hruby_high.rb', line 1986 def each_overload(&ruby_block) # No ruby block? Return an enumerator. return to_enum(:each_overload) unless ruby_block # A block? Apply it on each overload if any. @overloads.each(&ruby_block) if @overloads end |
#htype? ⇒ Boolean
Tells htype has been included.
1809 1810 1811 |
# File 'lib/HDLRuby/hruby_high.rb', line 1809 def htype? return true end |
#inner(*names) ⇒ Object
Declares high-level untyped inner signals named names of the
current type.
1905 1906 1907 |
# File 'lib/HDLRuby/hruby_high.rb', line 1905 def inner(*names) High.top_user.make_inners(self,*names) end |
#inout(*names) ⇒ Object
Declares high-level untyped inout signals named names of the
current type.
1898 1899 1900 1901 |
# File 'lib/HDLRuby/hruby_high.rb', line 1898 def inout(*names) # High.top_user.make_inouts(self.instantiate,*names) High.top_user.make_inouts(self,*names) end |
#input(*names) ⇒ Object
Declares high-level input signals named names of the current type.
1885 1886 1887 |
# File 'lib/HDLRuby/hruby_high.rb', line 1885 def input(*names) High.top_user.make_inputs(self,*names) end |
#left ⇒ Object
Gets the type as left value.
NOTE: used for asymetric types like TypeSystemI.
1851 1852 1853 1854 |
# File 'lib/HDLRuby/hruby_high.rb', line 1851 def left # By default self. self end |
#name=(name) ⇒ Object
Sets the name.
NOTE: can only be done if the name is not already set.
1822 1823 1824 1825 1826 1827 1828 1829 1830 1831 1832 1833 1834 |
# File 'lib/HDLRuby/hruby_high.rb', line 1822 def name=(name) unless @name.empty? then raise AnyError, "Name of type already set to: #{@name}." end # Checks and sets the name. name = name.to_sym if name.empty? then raise AnyError, "Cannot set an empty name." end @name = name # Registers the name. self.register(name) end |
#output(*names) ⇒ Object
Declares high-level untyped output signals named names of the
current type.
1891 1892 1893 1894 |
# File 'lib/HDLRuby/hruby_high.rb', line 1891 def output(*names) # High.top_user.make_outputs(self.instantiate,*names) High.top_user.make_outputs(self,*names) end |
#register(name) ⇒ Object
Register the name of the type.
1837 1838 1839 1840 1841 1842 1843 1844 1845 |
# File 'lib/HDLRuby/hruby_high.rb', line 1837 def register(name) if self.name.empty? then raise AnyError, "Cannot register with empty name." else # Sets the hdl-like access to the type. obj = self # For using the right self within the proc High.space_reg(name) { obj } end end |
#right ⇒ Object
Gets the type as right value.
NOTE: used for asymetric types like TypeSystemI.
1859 1860 1861 1862 |
# File 'lib/HDLRuby/hruby_high.rb', line 1859 def right # By default self. self end |
#shared(*args) ⇒ Object
Create new shared signals from args.
args can be a name of list of names or a hash associating names to
default values.
360 361 362 363 364 365 366 367 368 369 370 371 372 373 374 |
# File 'lib/HDLRuby/std/sequencer_sync.rb', line 360 def shared(*args) # # Process the arguments. # Create the shared signal. sig = nil args.each do |arg| if arg.is_a?(Hash) then arg.each do |k,v| sig = SharedSignalI.new(self,k,v) end else sig = SharedSignalI.new(self,arg) end end return sig end |
#to_type ⇒ Object
Converts to a type. Returns self since it is already a type.
1815 1816 1817 |
# File 'lib/HDLRuby/hruby_high.rb', line 1815 def to_type return self end |
#typedef(name) ⇒ Object
Declares a new type definition with name equivalent to current one.
1867 1868 1869 1870 1871 1872 1873 1874 |
# File 'lib/HDLRuby/hruby_high.rb', line 1867 def typedef(name) # Create the new type. typ = TypeDef.new(name,self) # Register it. High.space_reg(name) { typ } # Return it. return typ end |
#unary(operator, expr) ⇒ Object
Performs unary operation operator on expression expr.
1923 1924 1925 1926 1927 1928 1929 1930 1931 1932 1933 |
# File 'lib/HDLRuby/hruby_high.rb', line 1923 def unary(operator,expr) # Look for a specific computation method. comp = comp_operator(operator) if self.respond_to?(comp) then # Found, use it. self.send(comp,expr) else # Not found, back to default generation of unary expression. return Unary.new(self.send(operator),operator,expr) end end |