Skip to content

Commit

Permalink
. Concludes the method refactoring
Browse files Browse the repository at this point in the history
  • Loading branch information
kschiess committed Feb 14, 2011
1 parent 082caeb commit 1b59efd
Show file tree
Hide file tree
Showing 7 changed files with 13 additions and 11 deletions.
3 changes: 2 additions & 1 deletion lib/verneuil/compiler.rb
Expand Up @@ -232,10 +232,11 @@ def accept_defn(name, args, body)
adr_end = @generator.fwd_adr
@generator.jump adr_end

@generator.program.symbol_table.add_method(
method = Verneuil::Method.new(
@class_context.last,
name,
@generator.current_adr)
@generator.program.symbols.add(method)

# Enters a new local scope and defines arguments
visit(args)
Expand Down
4 changes: 2 additions & 2 deletions lib/verneuil/process.rb
Expand Up @@ -154,7 +154,7 @@ def instr_ruby_call_implicit(name, argc)
end

# Verneuil method?
v_method = @program.symbol_table.lookup_method(nil, name)
v_method = @program.symbols.lookup_method(nil, name)
return v_method.invoke(self, nil) if v_method

# Ruby method! (or else)
Expand All @@ -173,7 +173,7 @@ def instr_ruby_call(name, argc)
# good situation.

# Verneuil method? (class method mask)
v_method = @program.symbol_table.lookup_method(receiver, name)
v_method = @program.symbols.lookup_method(receiver, name)
return v_method.invoke(self, receiver) if v_method

# Must be a Ruby method then. The catch allows internal classes like
Expand Down
6 changes: 3 additions & 3 deletions lib/verneuil/program.rb
Expand Up @@ -8,11 +8,11 @@ class Verneuil::Program
# Gives access to the internal array of instructions (the program memory)
attr_reader :instructions
# Access to the programs symbol table.
attr_reader :symbol_table
attr_reader :symbols

def initialize
@instructions = []
@symbol_table = Verneuil::SymbolTable.new
@symbols = Verneuil::SymbolTable.new
end

# Make programs behave nicely with respect to comparison.
Expand Down Expand Up @@ -50,7 +50,7 @@ def inspect
s = ''
@instructions.each_with_index do |instruction, idx|
method_label = ''
if entry=symbol_table.methods.find { |(r,n), m| m.address.ip == idx }
if entry=symbols.methods.find { |(r,n), m| m.address.ip == idx }
m = entry.last
method_label = [m.receiver, m.name].inspect
end
Expand Down
5 changes: 3 additions & 2 deletions lib/verneuil/symbol_table.rb
Expand Up @@ -9,11 +9,12 @@ def initialize
end

# Defines a function. This function will override the default of calling
# back to Ruby.
# 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(:Foo, :bar, Verneuil::Address.new(15))
# add(method_obj)
#
def add(method)
key = [method.receiver, method.name]
Expand Down
2 changes: 1 addition & 1 deletion spec/verneuil/compiler_spec.rb
Expand Up @@ -195,7 +195,7 @@

context "function :foo" do
let(:program) { compiler.compile(code) }
subject { program.symbol_table.lookup_method(nil, :foo) }
subject { program.symbols.lookup_method(nil, :foo) }

its(:name) { should == :foo }
it "should point to the address of the function" do
Expand Down
2 changes: 1 addition & 1 deletion spec/verneuil/process_spec.rb
Expand Up @@ -11,7 +11,7 @@ def process(program)
let(:program) {
generate { |g|
adr_fun = g.fwd_adr
g.program.symbol_table.add_method nil, :foo, adr_fun
g.program.symbols.add Verneuil::Method.new(nil, :foo, adr_fun)

g.ruby_call_implicit :foo, 0
g.halt
Expand Down
2 changes: 1 addition & 1 deletion spec/verneuil/symbol_table_spec.rb
Expand Up @@ -14,7 +14,7 @@
it "should handle addition of explicit methods (associated to a class)" do
class Foo; end
st.lookup_method(Foo.new, :bar).should be_nil
st.add(flexmock(:method, :receiver => :Foo, :name => :foo))
st.add(flexmock(:method, :receiver => Foo.name.to_sym, :name => :bar))

method = st.lookup_method(Foo.new, :bar)
method.should_not be_nil
Expand Down

0 comments on commit 1b59efd

Please sign in to comment.