2014-06-03 19:47:06 +02:00
|
|
|
require_relative "meta_class"
|
|
|
|
|
2014-06-13 22:51:53 +02:00
|
|
|
module Boot
|
2014-05-31 13:35:33 +02:00
|
|
|
# class is mainly a list of functions with a name (for now)
|
|
|
|
# layout of object is seperated into Layout
|
2014-06-13 22:51:53 +02:00
|
|
|
class BootClass < Vm::ObjectConstant
|
2014-06-03 19:47:06 +02:00
|
|
|
def initialize name , context , super_class = :Object
|
|
|
|
super()
|
2014-05-31 13:35:33 +02:00
|
|
|
@context = context
|
|
|
|
# class functions
|
|
|
|
@functions = []
|
|
|
|
@name = name.to_sym
|
2014-06-03 19:47:06 +02:00
|
|
|
@super_class = super_class
|
|
|
|
@meta_class = MetaClass.new(self)
|
2014-05-31 13:35:33 +02:00
|
|
|
end
|
2014-06-10 23:38:46 +02:00
|
|
|
attr_reader :name , :functions , :meta_class , :context
|
2014-05-31 13:35:33 +02:00
|
|
|
|
|
|
|
def add_function function
|
2014-06-13 22:51:53 +02:00
|
|
|
raise "not a function #{function}" unless function.is_a? Vm::Function
|
2014-05-31 13:35:33 +02:00
|
|
|
raise "syserr " unless function.name.is_a? Symbol
|
|
|
|
@functions << function
|
|
|
|
end
|
|
|
|
|
2014-06-03 21:16:57 +02:00
|
|
|
def get_function fname
|
|
|
|
fname = fname.to_sym
|
|
|
|
f = @functions.detect{ |f| f.name == fname }
|
|
|
|
names = @functions.collect{|f| f.name }
|
|
|
|
f
|
2014-05-31 13:35:33 +02:00
|
|
|
end
|
|
|
|
|
2014-06-13 22:41:45 +02:00
|
|
|
# get the function and if not found, try superclasses. raise error if not found
|
|
|
|
def resolve_function name
|
2014-05-31 13:35:33 +02:00
|
|
|
fun = get_function name
|
2014-06-01 20:03:08 +02:00
|
|
|
unless fun or name == :Object
|
2014-06-03 19:47:06 +02:00
|
|
|
supr = @context.object_space.get_or_create_class(@super_class)
|
2014-06-01 20:03:08 +02:00
|
|
|
fun = supr.get_function name
|
|
|
|
puts "#{supr.functions.collect(&:name)} for #{name} GOT #{fun.class}" if name == :index_of
|
|
|
|
end
|
2014-06-13 22:41:45 +02:00
|
|
|
raise "Method not found :#{name}, for #{inspect}" unless fun
|
2014-05-31 13:35:33 +02:00
|
|
|
fun
|
|
|
|
end
|
2014-06-03 21:16:57 +02:00
|
|
|
|
|
|
|
def inspect
|
2014-06-13 22:41:45 +02:00
|
|
|
"BootClass #{@name} < #{@super_class}:#{@functions.collect(&:name)}"
|
2014-06-03 21:16:57 +02:00
|
|
|
end
|
2014-06-05 17:17:00 +02:00
|
|
|
def to_s
|
|
|
|
inspect
|
|
|
|
end
|
2014-05-31 13:35:33 +02:00
|
|
|
# Code interface follows. Note position is inheitted as is from Code
|
|
|
|
|
|
|
|
# length of the class is the length of it's functions
|
|
|
|
def length
|
|
|
|
@functions.inject(0) {| sum , item | sum + item.length}
|
|
|
|
end
|
|
|
|
|
|
|
|
# linking functions
|
|
|
|
def link_at( start , context)
|
|
|
|
super
|
|
|
|
@functions.each do |function|
|
|
|
|
function.link_at(start , context)
|
|
|
|
start += function.length
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
|
|
|
# assemble functions
|
|
|
|
def assemble( io )
|
|
|
|
@functions.each do |function|
|
|
|
|
function.assemble(io)
|
|
|
|
end
|
|
|
|
io
|
|
|
|
end
|
2014-05-31 11:52:29 +02:00
|
|
|
end
|
|
|
|
end
|