still working on the method dispatch
This commit is contained in:
@ -28,23 +28,20 @@ module Vm
|
||||
f
|
||||
end
|
||||
|
||||
# way of creating new functions that have not been parsed.
|
||||
def get_or_create_function name
|
||||
# get the function and if not found, try superclasses. raise error if not found
|
||||
def resolve_function name
|
||||
fun = get_function name
|
||||
unless fun or name == :Object
|
||||
supr = @context.object_space.get_or_create_class(@super_class)
|
||||
fun = supr.get_function name
|
||||
puts "#{supr.functions.collect(&:name)} for #{name} GOT #{fun.class}" if name == :index_of
|
||||
end
|
||||
unless fun
|
||||
fun = Core::Kernel.send(name , @context)
|
||||
@functions << fun
|
||||
end
|
||||
raise "Method not found :#{name}, for #{inspect}" unless fun
|
||||
fun
|
||||
end
|
||||
|
||||
def inspect
|
||||
"BootClass #{@name} , super #{@super_class} #{@functions.length} functions"
|
||||
"BootClass #{@name} < #{@super_class}:#{@functions.collect(&:name)}"
|
||||
end
|
||||
def to_s
|
||||
inspect
|
||||
|
@ -64,12 +64,16 @@ module Vm
|
||||
# dummies, just for the other to compile
|
||||
obj = get_or_create_class :Object
|
||||
[:index_of , :_get_instance_variable].each do |f|
|
||||
puts "adding #{f}"
|
||||
puts "Boot Object::#{f}"
|
||||
obj.add_function Boot::Object.send(f , @context)
|
||||
end
|
||||
[:utoa, :putstring,:putint,:fibo,:exit].each do |f|
|
||||
puts "Boot Kernel::#{f}"
|
||||
obj.add_function Core::Kernel.send(f , @context)
|
||||
end
|
||||
obj = get_or_create_class :String
|
||||
[:get , :set].each do |f|
|
||||
puts "adding #{f}"
|
||||
puts "Boot String::#{f}"
|
||||
obj.add_function Boot::String.send(f , @context)
|
||||
end
|
||||
end
|
||||
|
@ -30,14 +30,13 @@ module Vm
|
||||
puts "no function for :#{name} in Meta #{@me_self.inspect}" unless f
|
||||
f
|
||||
end
|
||||
# way of creating new functions that have not been parsed.
|
||||
def get_or_create_function name
|
||||
|
||||
# get the function and if not found, try superclasses. raise error if not found
|
||||
def resolve_function name
|
||||
fun = get_function name
|
||||
unless fun or name == :Object
|
||||
supr = @me_self.context.object_space.get_or_create_class(@super_class)
|
||||
fun = supr.get_function name
|
||||
puts "#{supr.functions.collect(&:name)} for #{name} GOT #{fun.class}"
|
||||
end
|
||||
# TODO THE BOOK says is class A derives from B , then the metaclass of A derives from the metaclass of B
|
||||
# just get to it ! (and stop whimpering)
|
||||
raise "Method not found #{name} , for #{inspect}" unless fun
|
||||
fun
|
||||
end
|
||||
|
||||
|
Reference in New Issue
Block a user