remove unused from type

This commit is contained in:
Torsten Ruger 2016-12-15 14:00:34 +02:00
parent 2b3f9c398e
commit 1571c796bb
5 changed files with 11 additions and 46 deletions

View File

@ -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 )

View File

@ -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

View File

@ -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 |

View File

@ -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

View File

@ -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