Class: RubyHDL::High::TypeGen

Inherits:
Type
  • Object
show all
Defined in:
lib/HDLRuby/std/sequencer_sw.rb

Overview

Describes a high-level generic type definition.

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

Instance Attribute Summary

Attributes inherited from Type

#name

Instance Method Summary collapse

Methods inherited from Type

#[], #base, #base?, #binary, #comp_operator, #constant, #define_operator, #define_operator_with_context, #direction, #each_overload, #each_type_deep, #eql?, #equivalent?, #fixed?, #float?, #hash, #hierarchical?, #htype?, #inner, #input, #leaf?, #left, #max, #min, #output, #range, #range?, #register, #regular?, #right, #signed?, #struct?, #to_c, #to_c_init, #to_type, #to_vector, #typedef, #types?, #unary, #unsigned?, #vector?, #width

Methods included from HDLRuby::Tprocess

#&, #*, #+, #+@, #-@, #/, #<<, #==, #abs, #lr, #make, #resolve, #slice, #~

Constructor Details

#initialize(name, &ruby_block) ⇒ TypeGen

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



1121
1122
1123
1124
1125
1126
# File 'lib/HDLRuby/std/sequencer_sw.rb', line 1121

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.



1129
1130
1131
1132
1133
1134
1135
1136
1137
1138
1139
1140
1141
1142
1143
1144
1145
1146
# File 'lib/HDLRuby/std/sequencer_sw.rb', line 1129

def generate(*args)
  # Generate the resulting type.
  gtype = RubyHDL::High.top_sblock.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?(Type) then
    raise "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_with_context(op,&(RubyHDL::High.curry_with_context(*args,&ruby_block)))
  end
  # Returns the resulting type
  return gtype
end