remove unused from type
This commit is contained in:
parent
2b3f9c398e
commit
1571c796bb
@ -54,7 +54,7 @@ module Typed
|
|||||||
name = statement.name
|
name = statement.name
|
||||||
#puts "type #{type.inpect}"
|
#puts "type #{type.inpect}"
|
||||||
raise "No such class" unless type
|
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
|
#puts Register.machine.space.get_class_by_name(:Integer).method_names.to_a
|
||||||
raise "Method not implemented #{type.inspect}.#{name}" unless method
|
raise "Method not implemented #{type.inspect}.#{name}" unless method
|
||||||
Register.issue_call( self , method )
|
Register.issue_call( self , method )
|
||||||
|
@ -28,38 +28,20 @@ module Parfait
|
|||||||
names
|
names
|
||||||
end
|
end
|
||||||
|
|
||||||
def add_instance_method method
|
def add_instance_method( method )
|
||||||
raise "not a method #{method.class} #{method.inspect}" unless method.is_a? TypedMethod
|
raise "not implemented #{method.class} #{method.inspect}" unless method.is_a? RubyMethod
|
||||||
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}"
|
|
||||||
method
|
method
|
||||||
end
|
end
|
||||||
|
|
||||||
def remove_instance_method method_name
|
def remove_instance_method( method_name )
|
||||||
found = get_instance_method( method_name )
|
found = get_instance_method( method_name )
|
||||||
if found
|
found ? self.methods.delete(found) : false
|
||||||
self.methods.delete(found)
|
|
||||||
else
|
|
||||||
raise "No such method #{method_name} in #{self.name}"
|
|
||||||
end
|
|
||||||
return true
|
|
||||||
end
|
end
|
||||||
|
|
||||||
def get_instance_method fname
|
def get_instance_method( fname )
|
||||||
raise "get_instance_method #{fname}.#{fname.class}" unless fname.is_a?(Symbol)
|
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
|
#if we had a hash this would be easier. Detect or find would help too
|
||||||
self.methods.each do |m|
|
self.methods.find {|m| m.name == fname }
|
||||||
return m if(m.name == fname )
|
|
||||||
end
|
|
||||||
nil
|
|
||||||
end
|
end
|
||||||
|
|
||||||
# get the method and if not found, try superclasses. raise error if not found
|
# get the method and if not found, try superclasses. raise error if not found
|
||||||
|
@ -111,7 +111,7 @@ module Parfait
|
|||||||
return true
|
return true
|
||||||
end
|
end
|
||||||
|
|
||||||
def get_instance_method fname
|
def get_instance_method( fname )
|
||||||
raise "get_instance_method #{fname}.#{fname.class}" unless fname.is_a?(Symbol)
|
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
|
#if we had a hash this would be easier. Detect or find would help too
|
||||||
self.methods.each do |m|
|
self.methods.each do |m|
|
||||||
@ -120,17 +120,6 @@ module Parfait
|
|||||||
nil
|
nil
|
||||||
end
|
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
|
def == other
|
||||||
self.object_id == other.object_id
|
self.object_id == other.object_id
|
||||||
end
|
end
|
||||||
@ -192,10 +181,6 @@ module Parfait
|
|||||||
end
|
end
|
||||||
alias :name :sof_reference_name
|
alias :name :sof_reference_name
|
||||||
|
|
||||||
def super_class_name
|
|
||||||
nil # stop resolve recursing up metaclasses
|
|
||||||
end
|
|
||||||
|
|
||||||
def to_hash
|
def to_hash
|
||||||
hash = Dictionary.new
|
hash = Dictionary.new
|
||||||
each_pair do |name, type |
|
each_pair do |name, type |
|
||||||
|
@ -22,8 +22,6 @@ class TestClass < MiniTest::Test
|
|||||||
assert_equal @try.method_names.get_length , @try.instance_methods.get_length
|
assert_equal @try.method_names.get_length , @try.instance_methods.get_length
|
||||||
end
|
end
|
||||||
def test_remove_nothere
|
def test_remove_nothere
|
||||||
assert_raises RuntimeError do
|
assert !@try.remove_instance_method(:foo)
|
||||||
@try.remove_instance_method(:foo)
|
|
||||||
end
|
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
@ -46,10 +46,10 @@ class TestMethodApi < MiniTest::Test
|
|||||||
test_remove_method
|
test_remove_method
|
||||||
assert_nil @try.get_instance_method(:foo)
|
assert_nil @try.get_instance_method(:foo)
|
||||||
end
|
end
|
||||||
def test_resolve
|
def test_get_instance
|
||||||
foo = foo_method :Object
|
foo = foo_method :Object
|
||||||
type = @space.get_class_by_name(:Object).instance_type
|
type = @space.get_class_by_name(:Object).instance_type
|
||||||
type.add_instance_method(foo)
|
type.add_instance_method(foo)
|
||||||
assert_equal :foo , type.resolve_method(:foo).name
|
assert_equal :foo , type.get_instance_method(:foo).name
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
Loading…
x
Reference in New Issue
Block a user