2014-06-03 20:47:06 +03:00
|
|
|
require_relative "meta_class"
|
|
|
|
|
2014-06-13 23:51:53 +03:00
|
|
|
module Boot
|
2014-07-12 21:59:17 +03:00
|
|
|
# class is mainly a list of methods with a name (for now)
|
2014-05-31 14:35:33 +03:00
|
|
|
# layout of object is seperated into Layout
|
2014-06-26 17:52:15 +03:00
|
|
|
class BootClass < Virtual::ObjectConstant
|
2014-07-16 19:24:41 +03:00
|
|
|
def initialize name , super_class_name = :Object
|
2014-06-03 20:47:06 +03:00
|
|
|
super()
|
2014-07-12 21:59:17 +03:00
|
|
|
# class methods
|
2014-07-16 19:24:41 +03:00
|
|
|
@method_definitions = []
|
2014-05-31 14:35:33 +03:00
|
|
|
@name = name.to_sym
|
2014-07-16 19:24:41 +03:00
|
|
|
@super_class_name = super_class_name.to_sym
|
2014-06-03 20:47:06 +03:00
|
|
|
@meta_class = MetaClass.new(self)
|
2014-05-31 14:35:33 +03:00
|
|
|
end
|
2014-08-22 09:21:59 +03:00
|
|
|
attr_reader :name , :method_definitions , :meta_class , :context , :super_class_name
|
2014-07-16 19:24:41 +03:00
|
|
|
def add_method_definition method
|
2014-08-07 15:37:32 +03:00
|
|
|
raise "not a method #{method.class} #{method.inspect}" unless method.is_a? Virtual::MethodDefinition
|
2014-07-12 21:59:17 +03:00
|
|
|
raise "syserr " unless method.name.is_a? Symbol
|
2014-07-16 19:24:41 +03:00
|
|
|
@method_definitions << method
|
2014-05-31 14:35:33 +03:00
|
|
|
end
|
|
|
|
|
2014-07-16 19:24:41 +03:00
|
|
|
def get_method_definition fname
|
2014-06-03 22:16:57 +03:00
|
|
|
fname = fname.to_sym
|
2014-07-16 19:24:41 +03:00
|
|
|
f = @method_definitions.detect{ |f| f.name == fname }
|
|
|
|
names = @method_definitions.collect{|f| f.name }
|
2014-06-03 22:16:57 +03:00
|
|
|
f
|
2014-05-31 14:35:33 +03:00
|
|
|
end
|
|
|
|
|
2014-07-12 21:59:17 +03:00
|
|
|
# get the method and if not found, try superclasses. raise error if not found
|
|
|
|
def resolve_method name
|
|
|
|
fun = get_method name
|
2014-06-01 21:03:08 +03:00
|
|
|
unless fun or name == :Object
|
2014-07-16 19:24:41 +03:00
|
|
|
supr = @context.object_space.get_or_create_class(@super_class_name)
|
2014-07-12 21:59:17 +03:00
|
|
|
fun = supr.get_method name
|
|
|
|
puts "#{supr.methods.collect(&:name)} for #{name} GOT #{fun.class}" if name == :index_of
|
2014-06-01 21:03:08 +03:00
|
|
|
end
|
2014-06-13 23:41:45 +03:00
|
|
|
raise "Method not found :#{name}, for #{inspect}" unless fun
|
2014-05-31 14:35:33 +03:00
|
|
|
fun
|
|
|
|
end
|
2014-06-03 22:16:57 +03:00
|
|
|
|
2014-06-05 18:17:00 +03:00
|
|
|
def to_s
|
|
|
|
inspect
|
|
|
|
end
|
2014-05-31 14:35:33 +03:00
|
|
|
|
2014-05-31 12:52:29 +03:00
|
|
|
end
|
|
|
|
end
|