the superclass of a singleton class is the singleton class of the superclass
And i have tests to prove it! That just rolls of the tongue, it had to be the commit message
This commit is contained in:
parent
2dcb2a9a72
commit
48e18ac9cd
@ -80,6 +80,7 @@ module Parfait
|
|||||||
tm = @instance_type.method_names
|
tm = @instance_type.method_names
|
||||||
raise "resolve_method #{name}.#{m_name} has #{tm}:#{method_names}"
|
raise "resolve_method #{name}.#{m_name} has #{tm}:#{method_names}"
|
||||||
end
|
end
|
||||||
|
#puts "resolve #{m_name}:#{super_class}:"
|
||||||
return nil unless( s_class = super_class )
|
return nil unless( s_class = super_class )
|
||||||
s_class.resolve_method(m_name)
|
s_class.resolve_method(m_name)
|
||||||
end
|
end
|
||||||
|
@ -54,14 +54,17 @@ module Parfait
|
|||||||
@clazz.set_type(@instance_type)
|
@clazz.set_type(@instance_type)
|
||||||
end
|
end
|
||||||
|
|
||||||
# Nil name means no superclass, and so nil returned
|
# the super class of a singleton classs is the singleton class of the super class.
|
||||||
|
# In effect the single classes shadow the class tree, leading to the fact that
|
||||||
|
# a class method defined in a super_class is accessible to a derived class in
|
||||||
|
# much the same way as normal methods are accessible in (normal) derived classes.
|
||||||
def super_class
|
def super_class
|
||||||
return nil
|
@clazz.super_class.single_class if @clazz.super_class
|
||||||
end
|
end
|
||||||
|
|
||||||
# no superclass, return nil to signal
|
# return the name of the superclass (see there)
|
||||||
def super_class_name
|
def super_class_name
|
||||||
nil
|
super_class.name if @clazz.super_class
|
||||||
end
|
end
|
||||||
|
|
||||||
end
|
end
|
||||||
|
@ -44,6 +44,7 @@ module Vool
|
|||||||
@receiver = SelfExpression.new(compiler.receiver_type) if @receiver.is_a?(SelfExpression)
|
@receiver = SelfExpression.new(compiler.receiver_type) if @receiver.is_a?(SelfExpression)
|
||||||
if(@receiver.ct_type)
|
if(@receiver.ct_type)
|
||||||
method = @receiver.ct_type.get_method(@name)
|
method = @receiver.ct_type.get_method(@name)
|
||||||
|
#puts "Known #{@receiver.ct_type}: method #{method}"
|
||||||
method = create_method_from_source(compiler) unless( method )
|
method = create_method_from_source(compiler) unless( method )
|
||||||
return simple_call(compiler, method) if method
|
return simple_call(compiler, method) if method
|
||||||
end
|
end
|
||||||
|
@ -55,5 +55,11 @@ module Parfait
|
|||||||
def test_type_is_single
|
def test_type_is_single
|
||||||
assert_equal true , @try.instance_type.is_single?
|
assert_equal true , @try.instance_type.is_single?
|
||||||
end
|
end
|
||||||
|
def test_super_class
|
||||||
|
assert_equal SingletonClass , @try.super_class.class
|
||||||
|
end
|
||||||
|
def test_super_class_name
|
||||||
|
assert_equal :"Object.Single" , @try.super_class_name
|
||||||
|
end
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
@ -7,12 +7,12 @@ module Vool
|
|||||||
|
|
||||||
def class_main
|
def class_main
|
||||||
<<-eos
|
<<-eos
|
||||||
class Space
|
class Object
|
||||||
def self.one_plus()
|
def self.one_plus()
|
||||||
return 1 + 1
|
return 1
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
class Space
|
class Space < Object
|
||||||
def main(arg)
|
def main(arg)
|
||||||
return Space.one_plus
|
return Space.one_plus
|
||||||
end
|
end
|
||||||
@ -21,8 +21,7 @@ module Vool
|
|||||||
end
|
end
|
||||||
|
|
||||||
def setup
|
def setup
|
||||||
source = "class Integer < Data4;def +(other);X.int_operator(:+);end;end;" + class_main
|
ret = RubyX::RubyXCompiler.new(RubyX.default_test_options).ruby_to_mom(class_main)
|
||||||
ret = RubyX::RubyXCompiler.new(RubyX.default_test_options).ruby_to_mom(source)
|
|
||||||
@ins = ret.compilers.find_compiler_name(:main).mom_instructions.next
|
@ins = ret.compilers.find_compiler_name(:main).mom_instructions.next
|
||||||
end
|
end
|
||||||
def test_array
|
def test_array
|
||||||
|
Loading…
Reference in New Issue
Block a user