more booting
This commit is contained in:
parent
e64733d72b
commit
3c0022191b
@ -15,7 +15,7 @@ require_relative "meta_class"
|
|||||||
module Parfait
|
module Parfait
|
||||||
class Class < Module
|
class Class < Module
|
||||||
|
|
||||||
def initialize name , super_class = nil
|
def initialize name , super_class
|
||||||
super( name , super_class)
|
super( name , super_class)
|
||||||
# the layout for this class (class = object of type Class) carries the class
|
# the layout for this class (class = object of type Class) carries the class
|
||||||
# as an instance. The relation is from an object through the Layout to it's class
|
# as an instance. The relation is from an object through the Layout to it's class
|
||||||
@ -34,16 +34,9 @@ module Parfait
|
|||||||
@object_layout.push name
|
@object_layout.push name
|
||||||
end
|
end
|
||||||
|
|
||||||
@@CLAZZ = { :names => [:name , :super_class_name , :instance_methods] , :types => [Virtual::Reference,Virtual::Reference,Virtual::Reference]}
|
|
||||||
def old_layout
|
|
||||||
@@CLAZZ
|
|
||||||
end
|
|
||||||
def mem_length
|
def mem_length
|
||||||
padded_words(3)
|
padded_words(3)
|
||||||
end
|
end
|
||||||
def to_s
|
|
||||||
inspect[0...300]
|
|
||||||
end
|
|
||||||
|
|
||||||
# ruby 2.1 list (just for reference, keep at bottom)
|
# ruby 2.1 list (just for reference, keep at bottom)
|
||||||
#:allocate, :new, :superclass
|
#:allocate, :new, :superclass
|
||||||
|
@ -19,15 +19,16 @@ module Parfait
|
|||||||
|
|
||||||
class Method < Object
|
class Method < Object
|
||||||
|
|
||||||
def initialize name , arg_names
|
def initialize clazz , name , arg_names
|
||||||
super()
|
super()
|
||||||
|
raise "No class #{name}" unless clazz
|
||||||
|
@for_class = clazz
|
||||||
@name = name
|
@name = name
|
||||||
@arg_names = arg_names
|
@arg_names = arg_names
|
||||||
@locals = []
|
@locals = []
|
||||||
@tmps = []
|
@tmps = []
|
||||||
end
|
end
|
||||||
attr_reader :name , :arg_names
|
attr_reader :name , :arg_names , :for_class
|
||||||
attr_accessor :for_class
|
|
||||||
|
|
||||||
|
|
||||||
# determine whether this method has a variable by the given name
|
# determine whether this method has a variable by the given name
|
||||||
|
@ -28,16 +28,19 @@ module Parfait
|
|||||||
def instance_methods
|
def instance_methods
|
||||||
@instance_methods
|
@instance_methods
|
||||||
end
|
end
|
||||||
|
|
||||||
def add_instance_method method
|
def add_instance_method method
|
||||||
raise "not a method #{method.class} #{method.inspect}" unless method.is_a? Method
|
raise "not a method #{method.class} #{method.inspect}" unless method.is_a? Method
|
||||||
raise "syserr #{method.name.class}" unless method.name.is_a? Word
|
raise "syserr #{method.name.class}" unless method.name.is_a? Word
|
||||||
method.for_class = self
|
|
||||||
@instance_methods << method
|
@instance_methods << method
|
||||||
|
puts "#{self.name} add #{method.name}"
|
||||||
method
|
method
|
||||||
end
|
end
|
||||||
|
|
||||||
def create_instance_method name , arg_names
|
def create_instance_method name , arg_names
|
||||||
add_instance_method Method.new( name , arg_names )
|
clazz = Space.object_space.get_class_by_name(self.name)
|
||||||
|
raise "??? #{self.name}" unless clazz
|
||||||
|
Method.new( clazz , name , arg_names )
|
||||||
end
|
end
|
||||||
|
|
||||||
# this needs to be done during booting as we can't have all the classes and superclassses
|
# this needs to be done during booting as we can't have all the classes and superclassses
|
||||||
@ -56,12 +59,11 @@ module Parfait
|
|||||||
def resolve_method m_name
|
def resolve_method m_name
|
||||||
raise "uups #{m_name}.#{m_name.class}" unless m_name.is_a? Word
|
raise "uups #{m_name}.#{m_name.class}" unless m_name.is_a? Word
|
||||||
method = get_instance_method(m_name)
|
method = get_instance_method(m_name)
|
||||||
unless method
|
return method if method
|
||||||
unless( @name == "Object" )
|
if( @super_class )
|
||||||
method = @super_class.resolve_method(m_name)
|
method = @super_class.resolve_method(m_name)
|
||||||
end
|
raise "Method not found #{m_name}, for \n#{self}" unless method
|
||||||
end
|
end
|
||||||
raise "Method not found #{m_name}, for #{@name}" unless method
|
|
||||||
method
|
method
|
||||||
end
|
end
|
||||||
|
|
||||||
|
@ -69,8 +69,8 @@ module Parfait
|
|||||||
c
|
c
|
||||||
end
|
end
|
||||||
|
|
||||||
def create_class name
|
def create_class name , superclass
|
||||||
c = Class.new_object(name)
|
c = Class.new_object(name , superclass)
|
||||||
raise "uups " if name.is_a? String
|
raise "uups " if name.is_a? String
|
||||||
@classes[name] = c
|
@classes[name] = c
|
||||||
end
|
end
|
||||||
|
@ -109,7 +109,7 @@ module Parfait
|
|||||||
|
|
||||||
# as we answered is_value? with true, sof will create a basic node with this string
|
# as we answered is_value? with true, sof will create a basic node with this string
|
||||||
def to_sof
|
def to_sof
|
||||||
"Parfait::Word('#{to_s}')"
|
"\"#{to_s}\""
|
||||||
end
|
end
|
||||||
|
|
||||||
#below here is OLD, DUBIOUS and needs to be checked TODO
|
#below here is OLD, DUBIOUS and needs to be checked TODO
|
||||||
|
@ -22,7 +22,7 @@ module Virtual
|
|||||||
class_mappings = {} #will later become instance variable
|
class_mappings = {} #will later become instance variable
|
||||||
|
|
||||||
values = [ "Value" , "Integer" , "Kernel" , "Object"].collect {|cl| Virtual.new_word(cl) }
|
values = [ "Value" , "Integer" , "Kernel" , "Object"].collect {|cl| Virtual.new_word(cl) }
|
||||||
value_classes = values.collect { |cl| @space.create_class(cl) }
|
value_classes = values.collect { |cl| @space.create_class(cl,nil) }
|
||||||
layouts = { "Word" => [] ,
|
layouts = { "Word" => [] ,
|
||||||
"List" => [] ,
|
"List" => [] ,
|
||||||
"Space" => ["classes","objects"],
|
"Space" => ["classes","objects"],
|
||||||
@ -33,10 +33,11 @@ module Virtual
|
|||||||
"Module" => ["name" , "instance_methods", "super_class", "meta_class"]
|
"Module" => ["name" , "instance_methods", "super_class", "meta_class"]
|
||||||
}
|
}
|
||||||
layouts.each do |name , layout|
|
layouts.each do |name , layout|
|
||||||
class_mappings[name] = @space.create_class(Virtual.new_word(name))
|
class_mappings[name] = @space.create_class(Virtual.new_word(name) , nil)
|
||||||
end
|
end
|
||||||
value_classes[1].set_super_class( value_classes[0] ) # #set superclass (value) for integer
|
value_classes[1].set_super_class( value_classes[0] ) # #set superclass (value) for integer
|
||||||
value_classes[3].set_super_class( value_classes[0] ) # and object
|
value_classes[2].set_super_class( value_classes[0] ) # and kernel (TODO is module)
|
||||||
|
value_classes[3].set_super_class( value_classes[2] ) # and object (TODO hacked to kernel)
|
||||||
class_mappings.each do |name , clazz| # and the rest
|
class_mappings.each do |name , clazz| # and the rest
|
||||||
clazz.set_super_class(value_classes[3]) # superclasses are object
|
clazz.set_super_class(value_classes[3]) # superclasses are object
|
||||||
end
|
end
|
||||||
@ -78,7 +79,6 @@ module Virtual
|
|||||||
obj = @class_mappings["Object"]
|
obj = @class_mappings["Object"]
|
||||||
[:index_of , :_get_instance_variable , :_set_instance_variable].each do |f|
|
[:index_of , :_get_instance_variable , :_set_instance_variable].each do |f|
|
||||||
obj.add_instance_method Builtin::Object.send(f , nil)
|
obj.add_instance_method Builtin::Object.send(f , nil)
|
||||||
puts "Object add #{f}"
|
|
||||||
end
|
end
|
||||||
obj = @class_mappings["Kernel"]
|
obj = @class_mappings["Kernel"]
|
||||||
# create main first, __init__ calls it
|
# create main first, __init__ calls it
|
||||||
|
@ -20,6 +20,7 @@ module Virtual
|
|||||||
end
|
end
|
||||||
new_method = CompiledMethodInfo.create_method(class_name, expression.name.to_s , args )
|
new_method = CompiledMethodInfo.create_method(class_name, expression.name.to_s , args )
|
||||||
new_method.info.receiver = r
|
new_method.info.receiver = r
|
||||||
|
new_method.for_class.add_instance_method new_method
|
||||||
|
|
||||||
#frame = frame.new_frame
|
#frame = frame.new_frame
|
||||||
return_type = nil
|
return_type = nil
|
||||||
|
Loading…
Reference in New Issue
Block a user