2014-08-29 14:49:59 +02:00
|
|
|
require_relative "meta_class"
|
2014-06-03 19:47:06 +02:00
|
|
|
|
2014-08-29 14:49:59 +02:00
|
|
|
module Virtual
|
|
|
|
|
2014-07-12 20:59:17 +02:00
|
|
|
# class is mainly a list of methods with a name (for now)
|
2014-05-31 13:35:33 +02:00
|
|
|
# layout of object is seperated into Layout
|
2014-06-26 16:52:15 +02:00
|
|
|
class BootClass < Virtual::ObjectConstant
|
2014-07-16 18:24:41 +02:00
|
|
|
def initialize name , super_class_name = :Object
|
2014-06-03 19:47:06 +02:00
|
|
|
super()
|
2014-07-12 20:59:17 +02:00
|
|
|
# class methods
|
2014-08-23 22:57:47 +02:00
|
|
|
@instance_methods = []
|
2014-05-31 13:35:33 +02:00
|
|
|
@name = name.to_sym
|
2014-07-16 18:24:41 +02:00
|
|
|
@super_class_name = super_class_name.to_sym
|
2014-08-23 23:25:15 +02:00
|
|
|
@meta_class = Virtual::MetaClass.new(self)
|
2014-05-31 13:35:33 +02:00
|
|
|
end
|
2014-08-23 22:57:47 +02:00
|
|
|
attr_reader :name , :instance_methods , :meta_class , :context , :super_class_name
|
|
|
|
def add_instance_method method
|
2014-08-28 07:10:33 +02:00
|
|
|
raise "not a method #{method.class} #{method.inspect}" unless method.is_a? Virtual::CompiledMethod
|
2014-07-12 20:59:17 +02:00
|
|
|
raise "syserr " unless method.name.is_a? Symbol
|
2014-08-23 22:57:47 +02:00
|
|
|
@instance_methods << method
|
2014-05-31 13:35:33 +02:00
|
|
|
end
|
|
|
|
|
2014-08-23 22:57:47 +02:00
|
|
|
def get_instance_method fname
|
2014-06-03 21:16:57 +02:00
|
|
|
fname = fname.to_sym
|
2014-08-23 22:57:47 +02:00
|
|
|
f = @instance_methods.detect{ |f| f.name == fname }
|
2014-06-03 21:16:57 +02:00
|
|
|
f
|
2014-05-31 13:35:33 +02:00
|
|
|
end
|
|
|
|
|
2014-07-12 20:59:17 +02:00
|
|
|
# get the method and if not found, try superclasses. raise error if not found
|
2014-09-11 14:01:50 +02:00
|
|
|
def resolve_method m_name
|
|
|
|
method = get_instance_method(m_name)
|
|
|
|
unless method
|
|
|
|
unless( @name == :Object)
|
|
|
|
supr = BootSpace.space.get_or_create_class(@super_class_name)
|
|
|
|
method = supr.resolve_method(m_name)
|
|
|
|
end
|
2014-06-01 20:03:08 +02:00
|
|
|
end
|
2014-09-11 14:01:50 +02:00
|
|
|
raise "Method not found #{m_name}, for #{@name}" unless method
|
|
|
|
method
|
2014-05-31 13:35:33 +02:00
|
|
|
end
|
2014-06-03 21:16:57 +02:00
|
|
|
|
2014-09-16 15:06:56 +02:00
|
|
|
@@CLAZZ = { :names => [:name , :super_class_name , :instance_methods] , :types => [Virtual::Reference,Virtual::Reference,Virtual::Reference]}
|
|
|
|
def layout
|
|
|
|
@@CLAZZ
|
|
|
|
end
|
2014-09-16 16:16:56 +02:00
|
|
|
def mem_length
|
|
|
|
padded_words(3)
|
|
|
|
end
|
2014-06-05 17:17:00 +02:00
|
|
|
def to_s
|
2014-10-07 11:21:40 +02:00
|
|
|
inspect[0...300]
|
2014-06-05 17:17:00 +02:00
|
|
|
end
|
2014-05-31 13:35:33 +02:00
|
|
|
|
2014-05-31 11:52:29 +02:00
|
|
|
end
|
2014-08-29 14:49:59 +02:00
|
|
|
|
|
|
|
end
|