From 48e18ac9cd3d4985504746983bb5a358e3b639a7 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Torsten=20R=C3=BCger?= Date: Tue, 1 Oct 2019 20:55:05 +0300 Subject: [PATCH] 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 --- lib/parfait/behaviour.rb | 1 + lib/parfait/singleton_class.rb | 11 +++++++---- lib/vool/send_statement.rb | 1 + test/parfait/test_singleton_class.rb | 6 ++++++ test/vool/class_send/test_class_send_inherited.rb | 9 ++++----- 5 files changed, 19 insertions(+), 9 deletions(-) diff --git a/lib/parfait/behaviour.rb b/lib/parfait/behaviour.rb index 03cdd18b..eec3cef2 100644 --- a/lib/parfait/behaviour.rb +++ b/lib/parfait/behaviour.rb @@ -80,6 +80,7 @@ module Parfait tm = @instance_type.method_names raise "resolve_method #{name}.#{m_name} has #{tm}:#{method_names}" end + #puts "resolve #{m_name}:#{super_class}:" return nil unless( s_class = super_class ) s_class.resolve_method(m_name) end diff --git a/lib/parfait/singleton_class.rb b/lib/parfait/singleton_class.rb index e0646a25..8f3e6bb2 100644 --- a/lib/parfait/singleton_class.rb +++ b/lib/parfait/singleton_class.rb @@ -54,14 +54,17 @@ module Parfait @clazz.set_type(@instance_type) 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 - return nil + @clazz.super_class.single_class if @clazz.super_class end - # no superclass, return nil to signal + # return the name of the superclass (see there) def super_class_name - nil + super_class.name if @clazz.super_class end end diff --git a/lib/vool/send_statement.rb b/lib/vool/send_statement.rb index 86acc055..d31bf9b8 100644 --- a/lib/vool/send_statement.rb +++ b/lib/vool/send_statement.rb @@ -44,6 +44,7 @@ module Vool @receiver = SelfExpression.new(compiler.receiver_type) if @receiver.is_a?(SelfExpression) if(@receiver.ct_type) method = @receiver.ct_type.get_method(@name) + #puts "Known #{@receiver.ct_type}: method #{method}" method = create_method_from_source(compiler) unless( method ) return simple_call(compiler, method) if method end diff --git a/test/parfait/test_singleton_class.rb b/test/parfait/test_singleton_class.rb index 1332099e..6bc0a3ff 100644 --- a/test/parfait/test_singleton_class.rb +++ b/test/parfait/test_singleton_class.rb @@ -55,5 +55,11 @@ module Parfait def test_type_is_single assert_equal true , @try.instance_type.is_single? 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 diff --git a/test/vool/class_send/test_class_send_inherited.rb b/test/vool/class_send/test_class_send_inherited.rb index 50d133a9..a048e185 100644 --- a/test/vool/class_send/test_class_send_inherited.rb +++ b/test/vool/class_send/test_class_send_inherited.rb @@ -7,12 +7,12 @@ module Vool def class_main <<-eos - class Space + class Object def self.one_plus() - return 1 + 1 + return 1 end end - class Space + class Space < Object def main(arg) return Space.one_plus end @@ -21,8 +21,7 @@ module Vool end 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(source) + ret = RubyX::RubyXCompiler.new(RubyX.default_test_options).ruby_to_mom(class_main) @ins = ret.compilers.find_compiler_name(:main).mom_instructions.next end def test_array