Derive Class and MetaClass from Behaviour
Finally! If i remember the module was from before i had any non Object superclasses unified code, unified bugs :-) just makes sense
This commit is contained in:
@ -3,11 +3,14 @@
|
||||
# instance_methods is the attribute in the including class that has the methods
|
||||
|
||||
module Parfait
|
||||
module Behaviour
|
||||
class Behaviour < Object
|
||||
|
||||
def initialize
|
||||
attr_reader :instance_type , :instance_methods
|
||||
|
||||
def initialize(type)
|
||||
super()
|
||||
@instance_methods = List.new
|
||||
@instance_type = type
|
||||
end
|
||||
|
||||
def methods
|
||||
@ -24,9 +27,14 @@ module Parfait
|
||||
names
|
||||
end
|
||||
|
||||
def add_instance_method_for(name , type , frame , body )
|
||||
method = Parfait::VoolMethod.new(name , type , frame , body )
|
||||
add_instance_method( method )
|
||||
end
|
||||
|
||||
def add_instance_method( method )
|
||||
raise "not implemented #{method.class} #{method.inspect}" unless method.is_a? VoolMethod
|
||||
raise "HMM"
|
||||
@instance_methods.push(method)
|
||||
method
|
||||
end
|
||||
|
||||
@ -52,5 +60,10 @@ module Parfait
|
||||
method
|
||||
end
|
||||
|
||||
# adding an instance changes the instance_type to include that variable
|
||||
def add_instance_variable( name , type)
|
||||
@instance_type = @instance_type.add_instance_variable( name , type )
|
||||
end
|
||||
|
||||
end
|
||||
end
|
||||
|
@ -15,11 +15,9 @@
|
||||
# Each type in turn has a list of CallableMethods that hold binary code
|
||||
|
||||
module Parfait
|
||||
class Class < Object
|
||||
include Behaviour
|
||||
class Class < Behaviour
|
||||
|
||||
attr_reader :instance_type , :name , :instance_methods
|
||||
attr_reader :super_class_name , :meta_class
|
||||
attr_reader :name , :super_class_name , :meta_class
|
||||
|
||||
def self.type_length
|
||||
6
|
||||
@ -29,11 +27,9 @@ module Parfait
|
||||
end
|
||||
|
||||
def initialize( name , superclass , instance_type)
|
||||
super()
|
||||
super(instance_type)
|
||||
@name = name
|
||||
@super_class_name = superclass
|
||||
@instance_methods = List.new
|
||||
@instance_type = instance_type
|
||||
@meta_class = MetaClass.new( self )
|
||||
end
|
||||
|
||||
@ -48,26 +44,6 @@ module Parfait
|
||||
inspect
|
||||
end
|
||||
|
||||
def add_method_for(name , type , frame , body )
|
||||
method = Parfait::VoolMethod.new(name , type , frame , body )
|
||||
add_method( method )
|
||||
method
|
||||
end
|
||||
|
||||
def add_method(method)
|
||||
raise "Must be untyped method #{method}" unless method.is_a? Parfait::VoolMethod
|
||||
@instance_methods.push(method)
|
||||
end
|
||||
|
||||
def get_method(name)
|
||||
@instance_methods.find{|m| m.name == name }
|
||||
end
|
||||
|
||||
# adding an instance changes the instance_type to include that variable
|
||||
def add_instance_variable( name , type)
|
||||
@instance_type = @instance_type.add_instance_variable( name , type )
|
||||
end
|
||||
|
||||
# return the super class, but raise exception if either the super class name
|
||||
# or the super classs is nil.
|
||||
# Use only for non Object base class
|
||||
|
@ -14,10 +14,9 @@
|
||||
# There is a one to one relationship between a class instance and it's meta_class instance.
|
||||
|
||||
module Parfait
|
||||
class MetaClass < Object
|
||||
include Behaviour
|
||||
class MetaClass < Behaviour
|
||||
|
||||
attr_reader :instance_type , :instance_methods , :clazz
|
||||
attr_reader :clazz
|
||||
|
||||
def self.type_length
|
||||
4
|
||||
@ -27,9 +26,10 @@ module Parfait
|
||||
end
|
||||
|
||||
def initialize( clazz )
|
||||
super()
|
||||
type = Object.object_space.get_type_by_class_name(:Object)
|
||||
raise "No type for #{clazz.name}" unless type
|
||||
super( type )
|
||||
@clazz = clazz
|
||||
@instance_type = Object.object_space.get_type_by_class_name(:Object)
|
||||
end
|
||||
|
||||
def rxf_reference_name
|
||||
@ -43,25 +43,6 @@ module Parfait
|
||||
def to_s
|
||||
inspect
|
||||
end
|
||||
def add_method_for(name , type , frame , body )
|
||||
method = Parfait::VoolMethod.new(name , type , frame , body )
|
||||
add_method( method )
|
||||
method
|
||||
end
|
||||
|
||||
def add_method(method)
|
||||
raise "Must be untyped method #{method}" unless method.is_a? Parfait::VoolMethod
|
||||
@instance_methods.push(method)
|
||||
end
|
||||
|
||||
def get_method(name)
|
||||
@instance_methods.find{|m| m.name == name }
|
||||
end
|
||||
|
||||
# adding an instance changes the instance_type to include that variable
|
||||
def add_instance_variable( name , type)
|
||||
@instance_type = @instance_type.add_instance_variable( name , type )
|
||||
end
|
||||
|
||||
# Nil name means no superclass, and so nil returned
|
||||
def super_class
|
||||
|
Reference in New Issue
Block a user