From a7bfb6e6ee0d49928b82733d482c8778b423d778 Mon Sep 17 00:00:00 2001 From: Torsten Ruger Date: Sat, 23 Aug 2014 23:57:47 +0300 Subject: [PATCH] rename (corrected) method def to instance methods in class --- lib/ast/basic_expressions.rb | 2 +- lib/ast/function_expression.rb | 2 +- lib/ast/module_expression.rb | 2 +- lib/boot/boot_class.rb | 13 ++++++------- lib/boot/boot_space.rb | 8 ++++---- lib/register/call_implementation.rb | 4 ++-- lib/virtual/send_implementation.rb | 2 +- test/virtual/test_basic.rb | 2 +- test/virtual/test_methods.rb | 2 +- 9 files changed, 18 insertions(+), 19 deletions(-) diff --git a/lib/ast/basic_expressions.rb b/lib/ast/basic_expressions.rb index 596243a9..75d4978e 100644 --- a/lib/ast/basic_expressions.rb +++ b/lib/ast/basic_expressions.rb @@ -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 diff --git a/lib/ast/function_expression.rb b/lib/ast/function_expression.rb index 10ebbbb8..be832f55 100644 --- a/lib/ast/function_expression.rb +++ b/lib/ast/function_expression.rb @@ -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 diff --git a/lib/ast/module_expression.rb b/lib/ast/module_expression.rb index 4fa979ed..c1835414 100644 --- a/lib/ast/module_expression.rb +++ b/lib/ast/module_expression.rb @@ -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 diff --git a/lib/boot/boot_class.rb b/lib/boot/boot_class.rb index 574eb1a6..414b6ca0 100644 --- a/lib/boot/boot_class.rb +++ b/lib/boot/boot_class.rb @@ -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 diff --git a/lib/boot/boot_space.rb b/lib/boot/boot_space.rb index 1495ee0f..12781ba0 100644 --- a/lib/boot/boot_space.rb +++ b/lib/boot/boot_space.rb @@ -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 diff --git a/lib/register/call_implementation.rb b/lib/register/call_implementation.rb index d384a17c..8d2f879e 100644 --- a/lib/register/call_implementation.rb +++ b/lib/register/call_implementation.rb @@ -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 diff --git a/lib/virtual/send_implementation.rb b/lib/virtual/send_implementation.rb index 124e19d5..db08cf60 100644 --- a/lib/virtual/send_implementation.rb +++ b/lib/virtual/send_implementation.rb @@ -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] ) diff --git a/test/virtual/test_basic.rb b/test/virtual/test_basic.rb index 2015b17e..1a66d8f5 100644 --- a/test/virtual/test_basic.rb +++ b/test/virtual/test_basic.rb @@ -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 diff --git a/test/virtual/test_methods.rb b/test/virtual/test_methods.rb index 0b2a95c3..f0ecb9e2 100644 --- a/test/virtual/test_methods.rb +++ b/test/virtual/test_methods.rb @@ -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