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