Class: HDLRuby::High::TypeGen
- Defined in:
- lib/HDLRuby/hruby_high.rb
Overview
Describes a high-level generic type definition.
NOTE: this type does not correspond to any low-level type
Constant Summary collapse
Constants included from Low::Low2Symbol
Low::Low2Symbol::Low2SymbolPrefix, Low::Low2Symbol::Low2SymbolTable, Low::Low2Symbol::Symbol2LowTable
Instance Attribute Summary
Attributes inherited from Low::Type
Attributes included from Low::Hparent
Instance Method Summary collapse
-
#generate(*args) ⇒ Object
Generates the type with +args+ generic parameters.
-
#initialize(name, &ruby_block) ⇒ TypeGen
constructor
Creates a new generic type definition producing a new type by executing +ruby_block+.
-
#to_low(name = self.name) ⇒ Object
Converts the type to HDLRuby::Low and set its +name+.
Methods included from Htype
#[], #binary, #comp_operator, #constant, #define_operator, #each_overload, #htype?, included, #inner, #inout, #input, #left, #name=, #output, #register, #right, #to_type, #typedef, #unary
Methods included from Tprocess
#&, #*, #+, #+@, #-@, #/, #<<, #==, #abs, #lr, #make, #resolve, #slice, #~
Methods inherited from Low::Type
#base, #base?, #boolean?, #break_types!, #direction, #each_type_deep, #eql?, #equivalent?, #fixed?, #float?, #hash, #hierarchical?, #leaf?, #max, #min, #range, #range?, #regular?, #set_name!, #signed?, #struct?, #to_c, #to_hdr, #to_high, #to_vector, #to_verilog, #to_vhdl, #types?, #unsigned?, #vector?, #width
Methods included from Low::Low2Symbol
Methods included from Low::Hparent
Methods included from Low::Ltype
Constructor Details
#initialize(name, &ruby_block) ⇒ TypeGen
Creates a new generic type definition producing a new type by executing +ruby_block+.
1745 1746 1747 1748 1749 1750 1751 |
# File 'lib/HDLRuby/hruby_high.rb', line 1745 def initialize(name,&ruby_block) # Initialize the type structure. super(name) # Sets the block to execute when instantiating the type. @instance_proc = ruby_block end |
Instance Method Details
#generate(*args) ⇒ Object
Generates the type with +args+ generic parameters.
1754 1755 1756 1757 1758 1759 1760 1761 1762 1763 1764 1765 1766 1767 1768 1769 1770 1771 |
# File 'lib/HDLRuby/hruby_high.rb', line 1754 def generate(*args) # Generate the resulting type. gtype = High.top_user.instance_exec(*args,&@instance_proc) # Ensures a type has been produced. gtype = gtype.to_type if gtype.respond_to?(:to_type) unless gtype.is_a?(HDLRuby::Low::Type) then raise AnyError, "Generic type #{self.name} did not produce a valid type: #{gtype.class}" end # Create a new type definition from it. gtype = TypeDef.new(self.name.to_s + "_#{args.join(":")}", gtype) # Adds the possible overloaded operators. self.each_overload do |op,ruby_block| gtype.define_operator(op,&(ruby_block.curry[*args])) end # Returns the resulting type return gtype end |
#to_low(name = self.name) ⇒ Object
Converts the type to HDLRuby::Low and set its +name+.
NOTE: should be overridden by other type classes.
1776 1777 1778 1779 1780 1781 1782 1783 |
# File 'lib/HDLRuby/hruby_high.rb', line 1776 def to_low(name = self.name) # return HDLRuby::Low::TypeDef.new(name,self.def.to_low) typeDefL = HDLRuby::Low::TypeDef.new(name,self.def.to_low) # # For debugging: set the source high object # typeDefL.properties[:low2high] = self.hdr_id # self.properties[:high2low] = typeDefL return typeDefL end |