rename (corrected) method def to instance methods in class

This commit is contained in:
Torsten Ruger 2014-08-23 23:57:47 +03:00
parent ad6be2676c
commit a7bfb6e6ee
9 changed files with 18 additions and 19 deletions

View File

@ -40,7 +40,7 @@ module Ast
if method.has_var(name)
message.compile_get(method , name )
else
raise "Unimplemented"
raise "Unimplemented #{self}"
message.compile_send( method , name , Virtual::Self.new( Virtual::Mystery ) )
end
end

View File

@ -10,7 +10,7 @@ module Ast
new_method = Virtual::MethodDefinition.new(name , args , r )
new_method.class_name = r.is_a?(Boot::BootClass) ? r.name : method.class_name
clazz = Virtual::Object.space.get_or_create_class(new_method.class_name)
clazz.add_method_definition new_method
clazz.add_instance_method new_method
#frame = frame.new_frame
return_type = nil

View File

@ -29,7 +29,7 @@ module Ast
raise "only functions for now #{expression.inspect}" unless expression.is_a? Ast::FunctionExpression
#puts "compiling expression #{expression}"
expression_value = expression.compile(method,message )
clazz.add_method_definition(expression_value)
clazz.add_instance_method(expression_value)
#puts "compiled expression #{expression_value.inspect}"
end

View File

@ -7,22 +7,21 @@ module Boot
def initialize name , super_class_name = :Object
super()
# class methods
@method_definitions = []
@instance_methods = []
@name = name.to_sym
@super_class_name = super_class_name.to_sym
@meta_class = MetaClass.new(self)
end
attr_reader :name , :method_definitions , :meta_class , :context , :super_class_name
def add_method_definition method
attr_reader :name , :instance_methods , :meta_class , :context , :super_class_name
def add_instance_method method
raise "not a method #{method.class} #{method.inspect}" unless method.is_a? Virtual::MethodDefinition
raise "syserr " unless method.name.is_a? Symbol
@method_definitions << method
@instance_methods << method
end
def get_method_definition fname
def get_instance_method fname
fname = fname.to_sym
f = @method_definitions.detect{ |f| f.name == fname }
names = @method_definitions.collect{|f| f.name }
f = @instance_methods.detect{ |f| f.name == fname }
f
end

View File

@ -34,7 +34,7 @@ module Boot
puts "Runnning pass #{pass}"
all = main.blocks
@classes.each_value do |c|
c.method_definitions.each {|f| all += f.blocks }
c.instance_methods.each {|f| all += f.blocks }
end
all.each do |block|
pass.new.run(block)
@ -66,16 +66,16 @@ module Boot
obj = get_or_create_class :Object
[:index_of , :_get_instance_variable , :_set_instance_variable].each do |f|
#puts "Boot Object::#{f}"
obj.add_method_definition Boot::Object.send(f , @context)
obj.add_instance_method Boot::Object.send(f , @context)
end
[:putstring,:putint,:fibo,:exit].each do |f|
#puts "Boot Kernel::#{f}"
obj.add_method_definition Salama::Kernel.send(f , @context)
obj.add_instance_method Salama::Kernel.send(f , @context)
end
obj = get_or_create_class :String
[:get , :set , :puts].each do |f|
#puts "Boot String::#{f}"
obj.add_method_definition Boot::String.send(f , @context)
obj.add_instance_method Boot::String.send(f , @context)
end
end

View File

@ -12,8 +12,8 @@ module Register
next unless code.is_a? Virtual::FunctionCall
to = RegisterReference.new(:r0)
tmp = RegisterReference.new(:r5)
move = RegisterMachine.instance.ldr( to , tmp , code.to.index )
block.replace(code , [move] )
# move = RegisterMachine.instance.ldr( to , tmp , code.to.index )
# block.replace(code , [move] )
end
end

View File

@ -14,7 +14,7 @@ module Virtual
raise "unimplemented"
elsif( me.is_a? ObjectConstant )
clazz = me.clazz
method = clazz.get_method_definition code.name
method = clazz.get_instance_method code.name
raise "Method not implemented #{clazz.name}.#{code.name}" unless method
call = FunctionCall.new( method )
block.replace(code , [call] )

View File

@ -45,7 +45,7 @@ class TestBasic < MiniTest::Test
def test_module_name
@string_input = 'FooBar '
@output = "---RETURN_MARKER- &1 !ruby/object:Boot::BootClassRETURN_MARKER method_definitions: []RETURN_MARKER name: :FooBarRETURN_MARKER super_class_name: :ObjectRETURN_MARKER meta_class: !ruby/object:Boot::MetaClassRETURN_MARKER functions: []RETURN_MARKER me_self: *1RETURN_MARKER"
@output = "---RETURN_MARKER- &1 !ruby/object:Boot::BootClassRETURN_MARKER instance_methods: []RETURN_MARKER name: :FooBarRETURN_MARKER super_class_name: :ObjectRETURN_MARKER meta_class: !ruby/object:Boot::MetaClassRETURN_MARKER functions: []RETURN_MARKER me_self: *1RETURN_MARKER"
check
end

View File

@ -30,7 +30,7 @@ def String.length(x)
@length
end
HERE
@output = "---RETURN_MARKER- &7 !ruby/object:Virtual::MethodDefinitionRETURN_MARKER name: :lengthRETURN_MARKER args:RETURN_MARKER - :xRETURN_MARKER locals: []RETURN_MARKER tmps: []RETURN_MARKER receiver: &6 !ruby/object:Boot::BootClassRETURN_MARKER method_definitions:RETURN_MARKER - &2 !ruby/object:Virtual::MethodDefinitionRETURN_MARKER name: :getRETURN_MARKER args:RETURN_MARKER - &1 !ruby/class 'Virtual::Integer'RETURN_MARKER locals: []RETURN_MARKER tmps: []RETURN_MARKER receiver: *1RETURN_MARKER return_type: *1RETURN_MARKER blocks:RETURN_MARKER - &3 !ruby/object:Virtual::BlockRETURN_MARKER method: *2RETURN_MARKER name: :getRETURN_MARKER branch: RETURN_MARKER codes:RETURN_MARKER - !ruby/object:Virtual::MethodEnter {}RETURN_MARKER - !ruby/object:Virtual::BlockRETURN_MARKER method: *2RETURN_MARKER name: :get_returnRETURN_MARKER branch: RETURN_MARKER codes:RETURN_MARKER - !ruby/object:Virtual::MethodReturn {}RETURN_MARKER current: *3RETURN_MARKER - &4 !ruby/object:Virtual::MethodDefinitionRETURN_MARKER name: :setRETURN_MARKER args:RETURN_MARKER - *1RETURN_MARKER - *1RETURN_MARKER locals: []RETURN_MARKER tmps: []RETURN_MARKER receiver: *1RETURN_MARKER return_type: *1RETURN_MARKER blocks:RETURN_MARKER - &5 !ruby/object:Virtual::BlockRETURN_MARKER method: *4RETURN_MARKER name: :setRETURN_MARKER branch: RETURN_MARKER codes:RETURN_MARKER - !ruby/object:Virtual::MethodEnter {}RETURN_MARKER - !ruby/object:Virtual::BlockRETURN_MARKER method: *4RETURN_MARKER name: :set_returnRETURN_MARKER branch: RETURN_MARKER codes:RETURN_MARKER - !ruby/object:Virtual::MethodReturn {}RETURN_MARKER current: *5RETURN_MARKER name: :StringRETURN_MARKER super_class_name: :ObjectRETURN_MARKER meta_class: !ruby/object:Boot::MetaClassRETURN_MARKER functions: []RETURN_MARKER me_self: *6RETURN_MARKER return_type: !ruby/object:Virtual::ReturnRETURN_MARKER index: 0RETURN_MARKER type: !ruby/class 'Virtual::Mystery'RETURN_MARKER blocks:RETURN_MARKER - &8 !ruby/object:Virtual::BlockRETURN_MARKER method: *7RETURN_MARKER name: :lengthRETURN_MARKER branch: RETURN_MARKER codes:RETURN_MARKER - !ruby/object:Virtual::MethodEnter {}RETURN_MARKER - !ruby/object:Virtual::InstanceGetRETURN_MARKER name: :lengthRETURN_MARKER - !ruby/object:Virtual::BlockRETURN_MARKER method: *7RETURN_MARKER name: :length_returnRETURN_MARKER branch: RETURN_MARKER codes:RETURN_MARKER - !ruby/object:Virtual::MethodReturn {}RETURN_MARKER current: *8RETURN_MARKER"
@output = "---RETURN_MARKER- &7 !ruby/object:Virtual::MethodDefinitionRETURN_MARKER name: :lengthRETURN_MARKER args:RETURN_MARKER - :xRETURN_MARKER locals: []RETURN_MARKER tmps: []RETURN_MARKER receiver: &6 !ruby/object:Boot::BootClassRETURN_MARKER instance_methods:RETURN_MARKER - &2 !ruby/object:Virtual::MethodDefinitionRETURN_MARKER name: :getRETURN_MARKER args:RETURN_MARKER - &1 !ruby/class 'Virtual::Integer'RETURN_MARKER locals: []RETURN_MARKER tmps: []RETURN_MARKER receiver: *1RETURN_MARKER return_type: *1RETURN_MARKER blocks:RETURN_MARKER - &3 !ruby/object:Virtual::BlockRETURN_MARKER method: *2RETURN_MARKER name: :getRETURN_MARKER branch: RETURN_MARKER codes:RETURN_MARKER - !ruby/object:Virtual::MethodEnter {}RETURN_MARKER - !ruby/object:Virtual::BlockRETURN_MARKER method: *2RETURN_MARKER name: :get_returnRETURN_MARKER branch: RETURN_MARKER codes:RETURN_MARKER - !ruby/object:Virtual::MethodReturn {}RETURN_MARKER current: *3RETURN_MARKER - &4 !ruby/object:Virtual::MethodDefinitionRETURN_MARKER name: :setRETURN_MARKER args:RETURN_MARKER - *1RETURN_MARKER - *1RETURN_MARKER locals: []RETURN_MARKER tmps: []RETURN_MARKER receiver: *1RETURN_MARKER return_type: *1RETURN_MARKER blocks:RETURN_MARKER - &5 !ruby/object:Virtual::BlockRETURN_MARKER method: *4RETURN_MARKER name: :setRETURN_MARKER branch: RETURN_MARKER codes:RETURN_MARKER - !ruby/object:Virtual::MethodEnter {}RETURN_MARKER - !ruby/object:Virtual::BlockRETURN_MARKER method: *4RETURN_MARKER name: :set_returnRETURN_MARKER branch: RETURN_MARKER codes:RETURN_MARKER - !ruby/object:Virtual::MethodReturn {}RETURN_MARKER current: *5RETURN_MARKER name: :StringRETURN_MARKER super_class_name: :ObjectRETURN_MARKER meta_class: !ruby/object:Boot::MetaClassRETURN_MARKER functions: []RETURN_MARKER me_self: *6RETURN_MARKER return_type: !ruby/object:Virtual::ReturnRETURN_MARKER index: 0RETURN_MARKER type: !ruby/class 'Virtual::Mystery'RETURN_MARKER blocks:RETURN_MARKER - &8 !ruby/object:Virtual::BlockRETURN_MARKER method: *7RETURN_MARKER name: :lengthRETURN_MARKER branch: RETURN_MARKER codes:RETURN_MARKER - !ruby/object:Virtual::MethodEnter {}RETURN_MARKER - !ruby/object:Virtual::InstanceGetRETURN_MARKER name: :lengthRETURN_MARKER - !ruby/object:Virtual::BlockRETURN_MARKER method: *7RETURN_MARKER name: :length_returnRETURN_MARKER branch: RETURN_MARKER codes:RETURN_MARKER - !ruby/object:Virtual::MethodReturn {}RETURN_MARKER current: *8RETURN_MARKER"
check
end