module HDLRuby::High::Htype

Module bringing high-level properties to Type classes.

NOTE: by default a type is not specified.

Constants

High

High-level libraries for describing digital hardware.

Public Class Methods

included(base) click to toggle source

Ensures initialize registers the type name

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

Public Instance Methods

[](rng) click to toggle source

Creates a new vector type of range rng and with current type as base.

# File lib/HDLRuby/hruby_high.rb, line 1427
def [](rng)
    return TypeVector.new(:"",self,rng)
end
binary(operator, expr0, expr1) click to toggle source

Performs binary operation operator on expressions expr0 and expr1.

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

Gets the computation method for operator.

# File lib/HDLRuby/hruby_high.rb, line 1467
def comp_operator(op)
    return (op.to_s + ":C").to_sym
end
constant(hsh) click to toggle source

Declares high-level untyped constant signals by name and value given by hsh of the current type.

# File lib/HDLRuby/hruby_high.rb, line 1460
def constant(hsh)
    High.top_user.make_constants(self,hsh)
end
define_operator(operator,&ruby_block) click to toggle source

Redefinition of operator.

# File lib/HDLRuby/hruby_high.rb, line 1500
def define_operator(operator,&ruby_block)
    # 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) click to toggle source

Interates over the overloaded operators.

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

Tells htype has been included.

# File lib/HDLRuby/hruby_high.rb, line 1358
def htype?
    return true
end
inner(*names) click to toggle source

Declares high-level untyped inner signals named names of the current type.

# File lib/HDLRuby/hruby_high.rb, line 1454
def inner(*names)
    High.top_user.make_inners(self,*names)
end
inout(*names) click to toggle source

Declares high-level untyped inout signals named names of the current type.

# File lib/HDLRuby/hruby_high.rb, line 1447
def inout(*names)
    # High.top_user.make_inouts(self.instantiate,*names)
    High.top_user.make_inouts(self,*names)
end
input(*names) click to toggle source

Declares high-level input signals named names of the current type.

# File lib/HDLRuby/hruby_high.rb, line 1434
def input(*names)
    High.top_user.make_inputs(self,*names)
end
left() click to toggle source

Gets the type as left value.

NOTE: used for asymetric types like TypeSystemI.

# File lib/HDLRuby/hruby_high.rb, line 1400
def left
    # By default self.
    self
end
name=(name) click to toggle source

Sets the name.

NOTE: can only be done if the name is not already set.

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

Declares high-level untyped output signals named names of the current type.

# File lib/HDLRuby/hruby_high.rb, line 1440
def output(*names)
    # High.top_user.make_outputs(self.instantiate,*names)
    High.top_user.make_outputs(self,*names)
end
register(name) click to toggle source

Register the name of the type.

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

Gets the type as right value.

NOTE: used for asymetric types like TypeSystemI.

# File lib/HDLRuby/hruby_high.rb, line 1408
def right
    # By default self.
    self
end
to_type() click to toggle source

Converts to a type. Returns self since it is already a type.

# File lib/HDLRuby/hruby_high.rb, line 1364
def to_type
    return self
end
typedef(name) click to toggle source

Declares a new type definition with name equivalent to current one.

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

Performs unary operation operator on expression expr.

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