From 4c3007e6c0a60151692734916779f4554ba7955f Mon Sep 17 00:00:00 2001 From: Torsten Ruger Date: Thu, 29 Dec 2016 18:39:59 +0200 Subject: [PATCH] removing meta class (for now) --- lib/typed/method_compiler/basic_values.rb | 6 +-- lib/typed/parfait.rb | 1 - lib/typed/parfait/meta_class.rb | 58 ----------------------- test/typed/parfait/test_all.rb | 1 - test/typed/parfait/test_meta_class.rb | 55 --------------------- 5 files changed, 1 insertion(+), 120 deletions(-) delete mode 100644 lib/typed/parfait/meta_class.rb delete mode 100644 test/typed/parfait/test_meta_class.rb diff --git a/lib/typed/method_compiler/basic_values.rb b/lib/typed/method_compiler/basic_values.rb index 8b23ad3a..024dbac4 100644 --- a/lib/typed/method_compiler/basic_values.rb +++ b/lib/typed/method_compiler/basic_values.rb @@ -45,11 +45,7 @@ module Typed def on_ClassExpression expression name = expression.value - clazz = Parfait::Space.object_space.get_class_by_name! name - raise "No such class #{name}" unless clazz - reg = use_reg :MetaClass , clazz - add_load_constant( expression, clazz , reg ) - return reg + raise "No meta class #{name}" end end diff --git a/lib/typed/parfait.rb b/lib/typed/parfait.rb index 20f1b38c..9b1724f4 100644 --- a/lib/typed/parfait.rb +++ b/lib/typed/parfait.rb @@ -10,7 +10,6 @@ require_relative "parfait/list" require_relative "parfait/word" require_relative "parfait/binary_code" require_relative "parfait/typed_method" -require_relative "parfait/meta_class" require_relative "parfait/dictionary" require_relative "parfait/type" require_relative "parfait/message" diff --git a/lib/typed/parfait/meta_class.rb b/lib/typed/parfait/meta_class.rb deleted file mode 100644 index 33e41dbc..00000000 --- a/lib/typed/parfait/meta_class.rb +++ /dev/null @@ -1,58 +0,0 @@ -module Parfait - - # class that acts like a class, but is really the object - - # described in the ruby language book as the eigenclass, what you get with - # class MyClass - # class << self <--- this is called the eigenclass, or metaclass, and really is just - # .... the class object but gives us the ability to use the - # syntax as if it were a class - - # While the "real" metaclass is the type, we need to honor the constancy of the type - # So the type needs to be copied and replaced anytime it is edited. - # And then changed in the original object, and thus we need this level of indirection - - # Basically we implement the Behaviour protocol, by forwarding to the type - - class MetaClass < Object - include Logging - - attribute :object - - def initialize(object) - super() - self.object = object - end - - def name - self.object.get_type.name - end - # first part of the protocol is read, just forward to self.object.type - def methods - self.object.get_type.methods - end - def method_names - self.object.get_type.method_names - end - def get_instance_method fname - self.object.get_type.get_instance_method fname - end - - # the modifying part creates a new type - # forwards the action and replaces the type - def add_instance_method method - type = self.object.get_type.dup - ret = type.add_instance_method(method) - self.object.set_type type - ret - end - - def remove_instance_method method_name - type = self.object.get_type.dup - ret = type.remove_instance_method(method_name) - self.object.set_type type - ret - end - - end -end diff --git a/test/typed/parfait/test_all.rb b/test/typed/parfait/test_all.rb index c174b0cc..718e2ad6 100644 --- a/test/typed/parfait/test_all.rb +++ b/test/typed/parfait/test_all.rb @@ -4,7 +4,6 @@ require_relative "test_dictionary" require_relative "test_named_list" require_relative "test_list" require_relative "test_message" -require_relative "test_meta_class" require_relative "test_typed_method" require_relative "test_object" require_relative "test_space" diff --git a/test/typed/parfait/test_meta_class.rb b/test/typed/parfait/test_meta_class.rb deleted file mode 100644 index 9ec93833..00000000 --- a/test/typed/parfait/test_meta_class.rb +++ /dev/null @@ -1,55 +0,0 @@ -require_relative "../helper" - -class TestMeta < MiniTest::Test - - def setup - @space = Register.machine.boot.space - @try = @space.create_class(:Try , :Object).meta - end - - def foo_method for_class = :Try - args = Parfait::Type.for_hash( @try , { bar: :Integer}) - ::Parfait::TypedMethod.new @space.get_class_by_name(for_class).instance_type , :foo , args - end - - def test_meta - assert @try.name - end - - def test_meta_object - assert @space.get_class_by_name(:Object).meta - end - - def test_no_methods - assert_equal 0 , @try.method_names.get_length - end - - def test_meta_methods - assert @try.methods - end - - def test_add_method - foo = foo_method - assert_equal foo , @try.add_instance_method(foo) - assert_equal 1 , @try.method_names.get_length - assert_equal ":foo" , @try.method_names.inspect - end - def test_remove_method - test_add_method - assert_equal true , @try.remove_instance_method(:foo) - end - def test_remove_nothere - assert_raises RuntimeError do - @try.remove_instance_method(:foo) - end - end - def test_method_get - test_add_method - assert_equal Parfait::TypedMethod , @try.get_instance_method(:foo).class - end - def test_method_get_nothere - assert_nil @try.get_instance_method(:foo) - test_remove_method - assert_nil @try.get_instance_method(:foo) - end -end