Module: HDLRuby::High::Htype
- Includes:
- Tprocess
- Included in:
- Type, TypeDef, TypeStruct, TypeTuple, TypeVector
- Defined in:
- lib/HDLRuby/hruby_high.rb
Overview
Module bringing high-level properties to Type classes.
NOTE: by default a type is not specified.
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 +rng+ and with current type as base.
-
#binary(operator, expr0, expr1) ⇒ Object
Performs binary operation +operator+ on expressions +expr0+ and +expr1+.
-
#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 +hsh+ of the current type.
-
#define_operator(operator, &ruby_block) ⇒ Object
Redefinition of +operator+.
-
#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 +names+ of the current type.
-
#inout(*names) ⇒ Object
Declares high-level untyped inout signals named +names+ of the current type.
-
#input(*names) ⇒ Object
Declares high-level input signals named +names+ of 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 +names+ of the current type.
-
#register(name) ⇒ Object
Register the +name+ of the type.
-
#right ⇒ Object
Gets the type as right value.
-
#to_type ⇒ Object
Converts to a type.
-
#typedef(name) ⇒ Object
Declares a new type definition with +name+ equivalent to current one.
-
#unary(operator, expr) ⇒ Object
Performs unary operation +operator+ on expression +expr+.
Methods included from Tprocess
#&, #*, #+, #+@, #-@, #/, #<<, #==, #abs, #lr, #make, #resolve, #slice, #~
Class Method Details
.included(base) ⇒ Object
Ensures initialize registers the type name
1549 1550 1551 1552 1553 1554 1555 1556 1557 1558 |
# File 'lib/HDLRuby/hruby_high.rb', line 1549 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.
1630 1631 1632 |
# File 'lib/HDLRuby/hruby_high.rb', line 1630 def [](rng) return TypeVector.new(:"",self,rng) end |
#binary(operator, expr0, expr1) ⇒ Object
Performs binary operation +operator+ on expressions +expr0+ and +expr1+.
1689 1690 1691 1692 1693 1694 1695 1696 1697 1698 1699 1700 |
# File 'lib/HDLRuby/hruby_high.rb', line 1689 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+.
1670 1671 1672 |
# File 'lib/HDLRuby/hruby_high.rb', line 1670 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.
1663 1664 1665 |
# File 'lib/HDLRuby/hruby_high.rb', line 1663 def constant(hsh) High.top_user.make_constants(self,hsh) end |
#define_operator(operator, &ruby_block) ⇒ Object
Redefinition of +operator+.
1703 1704 1705 1706 1707 1708 1709 1710 1711 1712 1713 1714 1715 1716 1717 1718 |
# File 'lib/HDLRuby/hruby_high.rb', line 1703 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.instance_exec do sub do HDLRuby::High.top_user.instance_exec(*args,&ruby_block) end end end end |
#each_overload(&ruby_block) ⇒ Object
Interates over the overloaded operators.
1721 1722 1723 1724 1725 1726 |
# File 'lib/HDLRuby/hruby_high.rb', line 1721 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.
1561 1562 1563 |
# File 'lib/HDLRuby/hruby_high.rb', line 1561 def htype? return true end |
#inner(*names) ⇒ Object
Declares high-level untyped inner signals named +names+ of the current type.
1657 1658 1659 |
# File 'lib/HDLRuby/hruby_high.rb', line 1657 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.
1650 1651 1652 1653 |
# File 'lib/HDLRuby/hruby_high.rb', line 1650 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.
1637 1638 1639 |
# File 'lib/HDLRuby/hruby_high.rb', line 1637 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.
1603 1604 1605 1606 |
# File 'lib/HDLRuby/hruby_high.rb', line 1603 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.
1574 1575 1576 1577 1578 1579 1580 1581 1582 1583 1584 1585 1586 |
# File 'lib/HDLRuby/hruby_high.rb', line 1574 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.
1643 1644 1645 1646 |
# File 'lib/HDLRuby/hruby_high.rb', line 1643 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.
1589 1590 1591 1592 1593 1594 1595 1596 1597 |
# File 'lib/HDLRuby/hruby_high.rb', line 1589 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.
1611 1612 1613 1614 |
# File 'lib/HDLRuby/hruby_high.rb', line 1611 def right # By default self. self end |
#to_type ⇒ Object
Converts to a type. Returns self since it is already a type.
1567 1568 1569 |
# File 'lib/HDLRuby/hruby_high.rb', line 1567 def to_type return self end |
#typedef(name) ⇒ Object
Declares a new type definition with +name+ equivalent to current one.
1619 1620 1621 1622 1623 1624 1625 1626 |
# File 'lib/HDLRuby/hruby_high.rb', line 1619 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+.
1675 1676 1677 1678 1679 1680 1681 1682 1683 1684 1685 |
# File 'lib/HDLRuby/hruby_high.rb', line 1675 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 |