removing meta class (for now)

This commit is contained in:
Torsten Ruger 2016-12-29 18:39:59 +02:00
parent 80237e5033
commit 4c3007e6c0
5 changed files with 1 additions and 120 deletions

View File

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

View File

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

View File

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

View File

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

View File

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