module HDLRuby::Low::Low2Symbol

Module adding the conversion to symbol feature to HDLRuby objects.

Constants

Low2SymbolPrefix

The prefix used when building symbols.

Low2SymbolTable

The correspondance tables between HDLRuby objects and symbols.

Symbol2LowTable

Public Instance Methods

to_sym() click to toggle source

Converts to a symbol.

# File lib/HDLRuby/hruby_low2sym.rb, line 30
def to_sym
    # Get the associated symbol if any.
    @_symbol_equiv ||= Low2SymbolTable[self]
    unless @_symbol_equiv then
        # No symbol yet, create it.
        @_symbol_equiv =
            (Low2SymbolPrefix + Symbol2LowTable.size.to_s).to_sym
        # And regiter it.
        Symbol2LowTable[@_symbol_equiv] = self
        Low2SymbolTable[self] = @_symbol_equiv
    end
    # Now there is a symbol, return it.
    return @_symbol_equiv
end