Class: HDLRuby::High::TypeGen

Inherits:
Type show all
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

High =
HDLRuby::High

Constants included from Low::Low2Symbol

Low::Low2Symbol::Low2SymbolPrefix, Low::Low2Symbol::Low2SymbolTable, Low::Low2Symbol::Symbol2LowTable

Instance Attribute Summary

Attributes inherited from Type

#rctype

Attributes inherited from Low::Type

#name

Attributes included from Low::Hparent

#parent

Instance Method Summary collapse

Methods inherited from Type

#to_rcsim

Methods included from Htype

#[], #binary, #comp_operator, #constant, #define_operator, #define_operator_with_context, #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

#to_sym

Methods included from Low::Hparent

#hierarchy, #no_parent!, #scope

Methods included from Low::Ltype

included, #ltype?

Constructor Details

#initialize(name, &ruby_block) ⇒ TypeGen

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



1959
1960
1961
1962
1963
1964
1965
# File 'lib/HDLRuby/hruby_high.rb', line 1959

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.



1968
1969
1970
1971
1972
1973
1974
1975
1976
1977
1978
1979
1980
1981
1982
1983
1984
1985
1986
# File 'lib/HDLRuby/hruby_high.rb', line 1968

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]))
        gtype.define_operator_with_context(op,&(High.curry_with_context(*args,&ruby_block)))
    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.



1991
1992
1993
1994
1995
1996
1997
1998
# File 'lib/HDLRuby/hruby_high.rb', line 1991

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