improve boot
also move to superclass not superclass_name in class Makes ripples
This commit is contained in:
@@ -27,7 +27,7 @@ module Parfait
|
||||
include FakeMem
|
||||
def self.new_object *args
|
||||
# Space.space.get_class_by_name(:Word)
|
||||
puts "I am #{self}"
|
||||
#puts "I am #{self}"
|
||||
object = self.new(*args)
|
||||
object
|
||||
end
|
||||
|
@@ -15,12 +15,12 @@ require_relative "meta_class"
|
||||
module Parfait
|
||||
class Class < Module
|
||||
|
||||
def initialize name , super_class_name = :Object
|
||||
def initialize name , super_class = nil
|
||||
super()
|
||||
# class methods
|
||||
@instance_methods = []
|
||||
@name = name.to_sym
|
||||
@super_class_name = super_class_name.to_sym
|
||||
@super_class = super_class
|
||||
@meta_class = Virtual::MetaClass.new(self)
|
||||
@object_layout = []
|
||||
end
|
||||
@@ -31,6 +31,13 @@ module Parfait
|
||||
@instance_methods << method
|
||||
end
|
||||
|
||||
# this needs to be done during booting as we can't have all the classes and superclassses
|
||||
# instantiated. By that logic it should maybe be part of vm rather.
|
||||
# On the other hand vague plans to load the hierachy from sof exist, so for now...
|
||||
def set_super_class sup
|
||||
@super_class = sup
|
||||
end
|
||||
|
||||
def set_instance_names list
|
||||
@object_layout = Layout.new_object
|
||||
@object_layout.set_names list
|
||||
@@ -45,7 +52,7 @@ module Parfait
|
||||
def resolve_method m_name
|
||||
method = get_instance_method(m_name)
|
||||
unless method
|
||||
unless( @name == :Object)
|
||||
unless( @name == "Object" )
|
||||
supr = Space.space.get_class_by_name(@super_class_name)
|
||||
method = supr.resolve_method(m_name)
|
||||
end
|
||||
|
@@ -33,7 +33,7 @@ module Virtual
|
||||
name = name.to_sym
|
||||
f = @functions.detect{ |f| f.name == name }
|
||||
return f if f
|
||||
if( @me_self == :Object )
|
||||
if( @me_self == "Object" )
|
||||
puts "no function for :#{name} in Meta #{@me_self.inspect}"
|
||||
return nil
|
||||
else #recurse up class hierachy unless we're at Object
|
||||
|
@@ -53,7 +53,7 @@ module Parfait
|
||||
# this is the way to instantiate classes (not Parfait::Class.new)
|
||||
# so we get and keep exactly one per name
|
||||
def get_class_by_name name
|
||||
raise "uups #{name}.#{name.class}" unless name.is_a? Symbol
|
||||
raise "uups #{name}.#{name.class}" unless name.is_a? String or name.is_a? Word
|
||||
c = @classes[name]
|
||||
c
|
||||
end
|
||||
|
@@ -12,7 +12,7 @@ module Builtin
|
||||
# so it is responsible for initial setup (and relocation)
|
||||
def __init__ context
|
||||
function = Virtual::CompiledMethod.new(:__init__ , [] , Virtual::Integer)
|
||||
clazz = Virtual::Machine.instance.space.get_class_by_name :Kernel
|
||||
clazz = Virtual::Machine.instance.space.get_class_by_name "Kernel"
|
||||
method = clazz.resolve_method :main
|
||||
me = Virtual::Self.new(Virtual::Reference)
|
||||
code = Virtual::Set.new(Virtual::Self.new(me.type), me)
|
||||
|
@@ -35,7 +35,7 @@ module Virtual
|
||||
end
|
||||
def initialize name , arg_names , receiver = Virtual::Self.new , return_type = Virtual::Mystery
|
||||
@name = name.to_sym
|
||||
@class_name = :Object
|
||||
@class_name = "Object"
|
||||
@arg_names = arg_names
|
||||
@locals = []
|
||||
@tmps = []
|
||||
|
@@ -37,7 +37,7 @@ module Virtual
|
||||
#the_end = Halt.new
|
||||
@passes = [ "Virtual::SendImplementation" ]
|
||||
@space = Parfait::Space.new
|
||||
# @message = Message.new(the_end , the_end , :Object)
|
||||
# @message = Message.new(the_end , the_end , "Object" )
|
||||
end
|
||||
attr_reader :message , :passes , :space , :init , :main
|
||||
|
||||
@@ -77,28 +77,34 @@ module Virtual
|
||||
|
||||
def self.boot
|
||||
instance = self.instance
|
||||
instance.boot_classes! # boot is a verb here
|
||||
instance.boot_parfait! # boot is a verb here
|
||||
instance.boot
|
||||
instance
|
||||
end
|
||||
def self.instance
|
||||
@instance ||= Machine.new
|
||||
end
|
||||
|
||||
|
||||
# for testing, make sure no old artefacts hang around
|
||||
#maybe should be moved to test dir
|
||||
def self.reboot
|
||||
@instance = nil
|
||||
self.boot
|
||||
end
|
||||
# boot the classes, ie create a minimal set of classes with a minimal set of functions
|
||||
# minimal means only that which can not be coded in ruby
|
||||
# CompiledMethods are grabbed from respective modules by sending the method name. This should return the
|
||||
# implementation of the method (ie a method object), not actually try to implement it (as that's impossible in ruby)
|
||||
def boot_classes!
|
||||
def boot_parfait!
|
||||
boot_classes!
|
||||
# very fiddly chicken 'n egg problem. Functions need to be in the right order, and in fact we
|
||||
# have to define some dummies, just for the other to compile
|
||||
# TODO: go through the virtual parfait layer and adjust function names to what they really are
|
||||
obj = @space.create_class :Object , []
|
||||
obj = @space.get_class_by_name "Object"
|
||||
[:index_of , :_get_instance_variable , :_set_instance_variable].each do |f|
|
||||
obj.add_instance_method Builtin::Object.send(f , nil)
|
||||
end
|
||||
obj = @space.create_class :Kernel , []
|
||||
puts "CREATE Kernel #{obj}"
|
||||
obj = @space.get_class_by_name "Kernel"
|
||||
# create main first, __init__ calls it
|
||||
@main = Builtin::Kernel.send(:main , @context)
|
||||
obj.add_instance_method @main
|
||||
@@ -111,20 +117,33 @@ module Virtual
|
||||
# the point of which is that by the time main executes, all is "normal"
|
||||
@init = Block.new(:_init_ , nil )
|
||||
@init.add_code(Register::RegisterMain.new(underscore_init))
|
||||
obj = @space.create_class :Integer , []
|
||||
obj = @space.get_class_by_name "Integer"
|
||||
[:putint,:fibo].each do |f|
|
||||
obj.add_instance_method Builtin::Integer.send(f , nil)
|
||||
end
|
||||
obj = @space.create_class :Word , []
|
||||
obj = @space.get_class_by_name "Word"
|
||||
[:get , :set , :puts].each do |f|
|
||||
obj.add_instance_method Builtin::Word.send(f , nil)
|
||||
end
|
||||
obj = space.create_class :Array , []
|
||||
obj = space.get_class_by_name "List"
|
||||
[:get , :set , :push].each do |f|
|
||||
obj.add_instance_method Builtin::Array.send(f , nil)
|
||||
end
|
||||
end
|
||||
|
||||
def boot_classes!
|
||||
values = [ "Integer" , "Object" , "Value" , "Kernel"]
|
||||
rest = ["Word" , "Class" , "Dictionary" , "Space" , "List", "Layout"]
|
||||
(values + rest).each { |cl| @space.create_class(cl , []) }
|
||||
value_class = @space.get_class_by_name "Value"
|
||||
@space.get_class_by_name("Integer").set_super_class( value_class )
|
||||
object_class = @space.get_class_by_name("Object")
|
||||
object_class.set_super_class( value_class )
|
||||
rest.each do |name|
|
||||
cl = @space.get_class_by_name( name )
|
||||
cl.set_super_class(object_class)
|
||||
end
|
||||
end
|
||||
def boot
|
||||
# read all the files needed for a minimal system at compile
|
||||
classes = ["object"]
|
||||
|
@@ -28,7 +28,7 @@ module Virtual
|
||||
else
|
||||
# note: this is the current view: call internal send, even the method name says else
|
||||
# but send is "special" and accesses the internal method name and resolves.
|
||||
kernel = Virtual::Machine.instance.space.get_class_by_name(:Kernel)
|
||||
kernel = Virtual::Machine.instance.space.get_class_by_name("Kernel")
|
||||
method = kernel.get_instance_method(:__send)
|
||||
new_codes << MethodCall.new( method )
|
||||
raise "unimplemented: \n#{code}"
|
||||
|
Reference in New Issue
Block a user