Class: Verneuil::SymbolTable

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

Overview

A registry for methods.

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initializeSymbolTable

Returns a new instance of SymbolTable.



7
8
9
# File 'lib/verneuil/symbol_table.rb', line 7

def initialize
  @methods = {}
end

Instance Attribute Details

#methodsObject (readonly)

Returns the value of attribute methods.



5
6
7
# File 'lib/verneuil/symbol_table.rb', line 5

def methods
  @methods
end

Instance Method Details

#add(method) ⇒ Object

Defines a function. This function will override the default of calling back to Ruby. Methods added here must support at least #receiver, #name and #invoke.

Example:

# Replaces Foo#bar with the V method at address 15.
add(method_obj)


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

def add(method)
  key = [method.receiver, method.name]
  @methods[key] = method
end

#lookup_method(recv, name) ⇒ Object

Returns the function that matches the given receiver and method name.



26
27
28
29
30
31
32
33
34
# File 'lib/verneuil/symbol_table.rb', line 26

def lookup_method(recv, name)
  key = if recv
    [recv.class.name.to_sym, name]
  else
    [nil, name]
  end
  
  @methods[key]
end