diff --git a/lib/typed/compiler/call_site.rb b/lib/typed/compiler/call_site.rb index ab9bf8a2..51ed0674 100644 --- a/lib/typed/compiler/call_site.rb +++ b/lib/typed/compiler/call_site.rb @@ -54,7 +54,7 @@ module Typed name = statement.name #puts "type #{type.inpect}" raise "No such class" unless type - method = type.resolve_method(name) + method = type.get_instance_method(name) #puts Register.machine.space.get_class_by_name(:Integer).method_names.to_a raise "Method not implemented #{type.inspect}.#{name}" unless method Register.issue_call( self , method ) diff --git a/lib/typed/parfait/behaviour.rb b/lib/typed/parfait/behaviour.rb index 12fb1d9c..67229661 100644 --- a/lib/typed/parfait/behaviour.rb +++ b/lib/typed/parfait/behaviour.rb @@ -28,38 +28,20 @@ module Parfait names end - def add_instance_method method - raise "not a method #{method.class} #{method.inspect}" unless method.is_a? TypedMethod - raise "syserr #{method.name.class}" unless method.name.is_a? Symbol - if self.is_a?(Class) and (method.for_class != self) - raise "Adding to wrong class, should be #{method.for_class}" - end - found = get_instance_method( method.name ) - if found - self.methods.delete(found) - end - self.methods.push method - #puts "#{self.name} add #{method.name}" + def add_instance_method( method ) + raise "not implemented #{method.class} #{method.inspect}" unless method.is_a? RubyMethod method end - def remove_instance_method method_name + def remove_instance_method( method_name ) found = get_instance_method( method_name ) - if found - self.methods.delete(found) - else - raise "No such method #{method_name} in #{self.name}" - end - return true + found ? self.methods.delete(found) : false end - def get_instance_method fname + def get_instance_method( fname ) raise "get_instance_method #{fname}.#{fname.class}" unless fname.is_a?(Symbol) #if we had a hash this would be easier. Detect or find would help too - self.methods.each do |m| - return m if(m.name == fname ) - end - nil + self.methods.find {|m| m.name == fname } end # get the method and if not found, try superclasses. raise error if not found diff --git a/lib/typed/parfait/type.rb b/lib/typed/parfait/type.rb index 691f939c..3f8fe57c 100644 --- a/lib/typed/parfait/type.rb +++ b/lib/typed/parfait/type.rb @@ -111,7 +111,7 @@ module Parfait return true end - def get_instance_method fname + def get_instance_method( fname ) raise "get_instance_method #{fname}.#{fname.class}" unless fname.is_a?(Symbol) #if we had a hash this would be easier. Detect or find would help too self.methods.each do |m| @@ -120,17 +120,6 @@ module Parfait nil end - # get the method and if not found, try superclasses. raise error if not found - def resolve_method m_name - raise "resolve_method #{m_name}.#{m_name.class}" unless m_name.is_a?(Symbol) - method = get_instance_method(m_name) - return method if method - if( self.super_class_name ) - method = self.super_class.resolve_method(m_name) - end - method - end - def == other self.object_id == other.object_id end @@ -192,10 +181,6 @@ module Parfait end alias :name :sof_reference_name - def super_class_name - nil # stop resolve recursing up metaclasses - end - def to_hash hash = Dictionary.new each_pair do |name, type | diff --git a/test/typed/parfait/test_class.rb b/test/typed/parfait/test_class.rb index 2cbf546d..55722e6e 100644 --- a/test/typed/parfait/test_class.rb +++ b/test/typed/parfait/test_class.rb @@ -22,8 +22,6 @@ class TestClass < MiniTest::Test assert_equal @try.method_names.get_length , @try.instance_methods.get_length end def test_remove_nothere - assert_raises RuntimeError do - @try.remove_instance_method(:foo) - end + assert !@try.remove_instance_method(:foo) end end diff --git a/test/typed/type/test_method_api.rb b/test/typed/type/test_method_api.rb index 213aae1e..bff10d9e 100644 --- a/test/typed/type/test_method_api.rb +++ b/test/typed/type/test_method_api.rb @@ -46,10 +46,10 @@ class TestMethodApi < MiniTest::Test test_remove_method assert_nil @try.get_instance_method(:foo) end - def test_resolve + def test_get_instance foo = foo_method :Object type = @space.get_class_by_name(:Object).instance_type type.add_instance_method(foo) - assert_equal :foo , type.resolve_method(:foo).name + assert_equal :foo , type.get_instance_method(:foo).name end end