Class: FunctionTable

Inherits:
Object
  • Object
show all
Defined in:
lib/support.rb

Instance Method Summary collapse

Constructor Details

#initializeFunctionTable

Returns a new instance of FunctionTable.



64
65
66
67
68
# File 'lib/support.rb', line 64

def initialize
  @functions = Hash.new do |h,k|
    h[k] = []
  end
end

Instance Method Details

#[](name) ⇒ Object

HACK: just here for transition



75
76
77
78
# File 'lib/support.rb', line 75

def [](name) # HACK: just here for transition
  puts "\n# WARNING: FunctionTable.[] called from #{caller[0]}" if $DEBUG
  @functions[name].first
end

#add_function(name, type) ⇒ Object



85
86
87
88
# File 'lib/support.rb', line 85

def add_function(name, type)
  @functions[name] << type
  type
end

#cheat(name) ⇒ Object

HACK: just here for debugging



70
71
72
73
# File 'lib/support.rb', line 70

def cheat(name) # HACK: just here for debugging
  puts "\n# WARNING: FunctionTable.cheat called from #{caller[0]}" if $DEBUG
  @functions[name]
end

#has_key?(name) ⇒ Boolean

HACK: just here for transition

Returns:



80
81
82
83
# File 'lib/support.rb', line 80

def has_key?(name) # HACK: just here for transition
  puts "\n# WARNING: FunctionTable.has_key? called from #{caller[0]}" if $DEBUG
  @functions.has_key?(name)
end

#unify(name, type) ⇒ Object



90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
# File 'lib/support.rb', line 90

def unify(name, type)
  success = false
  @functions[name].each do |o| # unify(type)
    begin
      o.unify type
      success = true
    rescue
      # ignore
    end
  end
  unless success then
    yield(name, type) if block_given?
  end
  type
end