rubyx/lib/virtual/boot_class.rb

48 lines
1.4 KiB
Ruby
Raw Normal View History

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
# class is mainly a list of methods with a name (for now)
# 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()
# class methods
@instance_methods = []
@name = name.to_sym
2014-07-16 18:24:41 +02:00
@super_class_name = super_class_name.to_sym
@meta_class = Virtual::MetaClass.new(self)
end
attr_reader :name , :instance_methods , :meta_class , :context , :super_class_name
def add_instance_method method
raise "not a method #{method.class} #{method.inspect}" unless method.is_a? Virtual::CompiledMethod
raise "syserr " unless method.name.is_a? Symbol
@instance_methods << method
end
def get_instance_method fname
fname = fname.to_sym
f = @instance_methods.detect{ |f| f.name == fname }
f
end
# 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
end
2014-09-11 14:01:50 +02:00
raise "Method not found #{m_name}, for #{@name}" unless method
method
end
def to_s
inspect
end
end
2014-08-29 14:49:59 +02:00
end