Class: FunctionTable

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

Instance Method Summary collapse

Constructor Details

#initializeFunctionTable

Returns a new instance of FunctionTable.



3
4
5
6
7
# File 'lib/function_table.rb', line 3

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

Instance Method Details

#[](name) ⇒ Object

HACK: just here for transition



14
15
16
17
# File 'lib/function_table.rb', line 14

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



24
25
26
27
# File 'lib/function_table.rb', line 24

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

#cheat(name) ⇒ Object

HACK: just here for debugging



9
10
11
12
# File 'lib/function_table.rb', line 9

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:

  • (Boolean)


19
20
21
22
# File 'lib/function_table.rb', line 19

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



29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
# File 'lib/function_table.rb', line 29

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