implements resolve_method on parfait type

with associated changes to class
adds note about the not being the final version
This commit is contained in:
Torsten Ruger
2017-04-25 09:06:49 +03:00
parent e387bdb5f2
commit 47683817ee
4 changed files with 57 additions and 11 deletions

View File

@ -55,13 +55,23 @@ module Parfait
@instance_type = type
end
def super_class
# 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
def super_class!
raise "No super_class for class #{@name}" unless @super_class_name
s = Parfait.object_space.get_class_by_name(@super_class_name)
s = super_class
raise "superclass not found for class #{@name} (#{@super_class_name})" unless s
s
end
# return the super class
# we only store the name, and so have to resolve.
# Nil name means no superclass, and so nil is a valid return value
def super_class
return nil unless @super_class_name
Parfait.object_space.get_class_by_name(@super_class_name)
end
# ruby 2.1 list (just for reference, keep at bottom)
#:allocate, :new, :superclass

View File

@ -114,6 +114,20 @@ module Parfait
nil
end
# resolve according to normal oo logic, ie look up in superclass if not present
# NOTE: this will probably not work in future as the code for the superclass
# method, being bound to t adifferent type, will assume that types (not the run-time
# actual types) layout. Either need to enforce some c++ style upwards compatibility (buuh)
# or copy the methods and recompile them for the actual type. (maybe still later dynamically)
# But for now we walk up, as it should really just be to object
def resolve_method( fname )
method = get_method(fname)
return method if method
sup = object_class.super_class
return nil unless sup
sup.instance_type.resolve_method(fname)
end
def == other
self.object_id == other.object_id
end