class HDLRuby::High::TypeGen

Describes a high-level generic type definition.

NOTE: this type does not correspond to any low-level type

Constants

High

High-level libraries for describing digital hardware.

Public Class Methods

new(name,&ruby_block) click to toggle source

Creates a new generic type definition producing a new type by executing ruby_block.

Calls superclass method HDLRuby::High::Type::new
# File lib/HDLRuby/hruby_high.rb, line 1721
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

Public Instance Methods

generate(*args) click to toggle source

Generates the type with args generic parameters.

# File lib/HDLRuby/hruby_high.rb, line 1730
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) click to toggle source

Converts the type to HDLRuby::Low and set its name.

NOTE: should be overridden by other type classes.

# File lib/HDLRuby/hruby_high.rb, line 1752
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