fixed layouts
also moved objects to machine, from space space has a list of objects, but implicit, not as an explicit array
This commit is contained in:
parent
aaa206fbca
commit
03bdc16810
@ -18,7 +18,7 @@ module Elf
|
||||
@object.add_section @text
|
||||
|
||||
@object_machine.run_passes
|
||||
assembler = Register::Assembler.new(@object_machine.space)
|
||||
assembler = Register::Assembler.new(@object_machine)
|
||||
set_text assembler.assemble
|
||||
|
||||
# for debug add labels to the block positions
|
||||
|
@ -54,9 +54,14 @@ module Parfait
|
||||
internal_object_set(LAYOUT_INDEX , layout)
|
||||
end
|
||||
|
||||
# so we can keep the raise in get_layout
|
||||
def has_layout?
|
||||
! internal_object_get(LAYOUT_INDEX).nil?
|
||||
end
|
||||
|
||||
def get_layout()
|
||||
l = internal_object_get(LAYOUT_INDEX)
|
||||
raise "No layout #{self.class}:#{self.to_s} #{self.object_id}" unless l
|
||||
raise "No layout #{self.class}:#{self.class} #{self.object_id}" unless l
|
||||
return l
|
||||
end
|
||||
|
||||
|
@ -27,13 +27,8 @@ module Parfait
|
||||
super()
|
||||
Parfait::Space.set_object_space self
|
||||
@classes = Parfait::Dictionary.new_object
|
||||
# this is like asking for troubles, but if the space instance is not registered
|
||||
# and the @classes up, one can not register classes.
|
||||
# all is good after this init
|
||||
#global objects (data)
|
||||
@objects = Parfait::List.new_object
|
||||
end
|
||||
attr_reader :classes , :objects , :frames, :messages, :next_message , :next_frame
|
||||
attr_reader :classes , :frames, :messages, :next_message , :next_frame
|
||||
|
||||
# need a two phase init for the object space (and generally parfait) because the space
|
||||
# is an interconnected graph, so not everthing is ready
|
||||
@ -50,25 +45,6 @@ module Parfait
|
||||
@next_frame = @frames.first
|
||||
end
|
||||
|
||||
# double check that all objects dependents are really in the space too (debugging)
|
||||
def double_check
|
||||
@objects.each do |o|
|
||||
check o
|
||||
end
|
||||
end
|
||||
# private
|
||||
def check object , recurse = true
|
||||
raise "No good #{self.class}" unless @objects.include? object
|
||||
puts "#{object.class}"
|
||||
puts "#{object}" if object.class == Parfait::Word
|
||||
check object.get_layout
|
||||
return unless recurse
|
||||
object.get_layout.each do |name|
|
||||
check name , false
|
||||
inst = object.instance_variable_get "@#{name}".to_sym
|
||||
check inst , false
|
||||
end
|
||||
end
|
||||
@@object_space = nil
|
||||
# Make the object space globally available
|
||||
def self.object_space
|
||||
@ -79,12 +55,6 @@ module Parfait
|
||||
@@object_space = space
|
||||
end
|
||||
|
||||
# Objects are data and get assembled after functions
|
||||
def add_object o
|
||||
return if @objects.include?(o)
|
||||
@objects.push o
|
||||
end
|
||||
|
||||
def get_main
|
||||
kernel = get_class_by_name "Object"
|
||||
kernel.get_instance_method "main"
|
||||
|
@ -1,7 +1,7 @@
|
||||
module Register
|
||||
class LinkException < Exception
|
||||
end
|
||||
# Assemble the object space into a binary.
|
||||
# Assemble the object machine into a binary.
|
||||
# Link first to get positions, then assemble
|
||||
|
||||
# The link function determines the length of an object and the assemble actually
|
||||
@ -14,28 +14,27 @@ module Register
|
||||
TYPE_BITS = 4
|
||||
TYPE_LENGTH = 6
|
||||
|
||||
def initialize space
|
||||
@space = space
|
||||
def initialize machine
|
||||
@machine = machine
|
||||
end
|
||||
attr_reader :objects
|
||||
|
||||
def link
|
||||
# want to have the methods first in the executable
|
||||
# so first we determine the code length for the methods and set the
|
||||
# binary code (array) to right length
|
||||
@space.objects.each do |objekt|
|
||||
@machine.objects.each do |objekt|
|
||||
next unless objekt.is_a? Parfait::Method
|
||||
objekt.code.set_length(objekt.info.mem_length / 4 , 0)
|
||||
end
|
||||
at = 0
|
||||
# then we make sure we really get the binary codes first
|
||||
@space.objects.each do |objekt|
|
||||
@machine.objects.each do |objekt|
|
||||
next unless objekt.is_a? Parfait::BinaryCode
|
||||
objekt.set_position at
|
||||
at += objekt.mem_length
|
||||
end
|
||||
# and then everything else
|
||||
@space.objects.each do | objekt|
|
||||
@machine.objects.each do | objekt|
|
||||
# have to tell the code that will be assembled where it is to
|
||||
# get the jumps/calls right
|
||||
if objekt.is_a? Parfait::Method
|
||||
@ -52,23 +51,23 @@ module Register
|
||||
begin
|
||||
link
|
||||
# first we need to create the binary code for the methods
|
||||
@space.objects.each do |objekt|
|
||||
@machine.objects.each do |objekt|
|
||||
next unless objekt.is_a? Parfait::Method
|
||||
assemble_binary_method(objekt)
|
||||
end
|
||||
@stream = StringIO.new
|
||||
#TODOmid , main = @objects.find{|k,objekt| objekt.is_a?(Virtual::CompiledMethod) and (objekt.name == :__init__ )}
|
||||
# initial_jump = @space.init
|
||||
# initial_jump = @machine.init
|
||||
# initial_jump.codes.each do |code|
|
||||
# code.assemble( @stream )
|
||||
# end
|
||||
# then write the methods to file
|
||||
@space.objects.each do |objekt|
|
||||
@machine.objects.each do |objekt|
|
||||
next unless objekt.is_a? Parfait::BinaryCode
|
||||
assemble_any( objekt )
|
||||
end
|
||||
# and then the rest of the object space
|
||||
@space.objects.each do | objekt|
|
||||
# and then the rest of the object machine
|
||||
@machine.objects.each do | objekt|
|
||||
next if objekt.is_a? Parfait::BinaryCode
|
||||
assemble_any( objekt )
|
||||
end
|
||||
@ -150,8 +149,8 @@ module Register
|
||||
assemble_self( hash , [ hash.keys , hash.values ] )
|
||||
end
|
||||
|
||||
def assemble_Space(space)
|
||||
assemble_self(space , [space.classes,space.objects, space.symbols,space.messages,space.next_message,space.next_frame] )
|
||||
def assemble_Space(machine)
|
||||
assemble_self(machine , [machine.classes,machine.messages,machine.next_message,machine.next_frame] )
|
||||
end
|
||||
|
||||
def assemble_Class(clazz)
|
||||
|
@ -27,7 +27,7 @@ module Virtual
|
||||
"List" => [] ,
|
||||
"Message" => [],
|
||||
"BinaryCode" => [],
|
||||
"Space" => ["classes","objects","frames","messages","next_message","next_frame"],
|
||||
"Space" => ["classes","frames","messages","next_message","next_frame"],
|
||||
"Frame" => ["locals" , "tmps" ],
|
||||
"Layout" => ["object_class"] ,
|
||||
"Class" => ["object_layout"],
|
||||
@ -65,19 +65,17 @@ module Virtual
|
||||
class_mappings["Kernel"] = value_classes[2] #need for further booting
|
||||
class_mappings["Object"] = value_classes[3] #need for further booting
|
||||
|
||||
# add space and instances which get created before the objects list
|
||||
[@space,@space.classes,@space.classes.keys, @space.classes.values,@space.objects].each do |o|
|
||||
@space.add_object o
|
||||
end
|
||||
@space.late_init
|
||||
|
||||
# add_object @space
|
||||
|
||||
values.each {|v| v.init_layout }
|
||||
|
||||
|
||||
# now update the layout on all objects created so far,
|
||||
# go through objects in space
|
||||
@space.objects.each do | o |
|
||||
@objects.each do | o |
|
||||
o.init_layout
|
||||
end
|
||||
@space.double_check
|
||||
boot_functions!
|
||||
end
|
||||
|
||||
|
@ -38,8 +38,9 @@ module Virtual
|
||||
def initialize
|
||||
@parser = Parser::Salama.new
|
||||
@passes = [ "Virtual::SendImplementation" ]
|
||||
@objects = []
|
||||
end
|
||||
attr_reader :passes , :space , :class_mappings , :init
|
||||
attr_reader :passes , :space , :class_mappings , :init , :objects
|
||||
|
||||
def run_passes
|
||||
Minimizer.new.run
|
||||
@ -62,6 +63,34 @@ module Virtual
|
||||
end
|
||||
end
|
||||
|
||||
# double check that all objects dependents are really in the space too (debugging)
|
||||
def double_check
|
||||
@objects.each do |o|
|
||||
check o
|
||||
end
|
||||
end
|
||||
# Objects are data and get assembled after functions
|
||||
def add_object o
|
||||
return false if @objects.include?(o)
|
||||
@objects.push o
|
||||
true
|
||||
end
|
||||
|
||||
# private
|
||||
def check object , recurse = true
|
||||
raise "No good #{object.class}" unless @objects.include? object
|
||||
puts "#{object.class}"
|
||||
puts "#{object}" if object.class == Parfait::Word
|
||||
check object.get_layout
|
||||
return unless recurse
|
||||
object.get_layout.each do |name|
|
||||
check name , false
|
||||
inst = object.instance_variable_get "@#{name}".to_sym
|
||||
check inst , false
|
||||
end
|
||||
end
|
||||
|
||||
|
||||
# Passes may be added to by anyone who wants
|
||||
# This is intentionally quite flexible, though one sometimes has to watch the order of them
|
||||
# most ordering is achieved by ordering the requires and using add_pass
|
||||
|
@ -10,12 +10,7 @@ module FakeMem
|
||||
@memory = [0,nil]
|
||||
@position = nil
|
||||
@length = -1
|
||||
if Parfait::Space.object_space and Parfait::Space.object_space.objects
|
||||
Parfait::Space.object_space.add_object self
|
||||
else
|
||||
# Note: the else is handled in boot, by ading the space "by hand", as it slips though
|
||||
# puts "Got away #{self.class}"
|
||||
end
|
||||
# Virtual::Machine.instance.add_object self
|
||||
if Virtual::Machine.instance.class_mappings
|
||||
init_layout
|
||||
else
|
||||
|
@ -1,24 +1,22 @@
|
||||
module Virtual
|
||||
|
||||
# garbage collect anything that is in the space but not reachable from init
|
||||
# collect anything that is in the space but and reachable from init
|
||||
class Collector
|
||||
def run
|
||||
@keepers = []
|
||||
init= Parfait::Space.object_space.get_class_by_name("Kernel").get_instance_method "__init__"
|
||||
keep init
|
||||
# init= Parfait::Space.object_space.get_class_by_name("Kernel").get_instance_method "__init__"
|
||||
keep Parfait::Space.object_space
|
||||
end
|
||||
|
||||
def keep object
|
||||
return if @keepers.include? object
|
||||
layout = object.get_layout
|
||||
begin
|
||||
puts "Object #{object.class} #{Parfait::Space.object_space.objects.include?(object)}"
|
||||
puts "Object #{layout.object_id} #{Parfait::Space.object_space.objects.include?(layout)}"
|
||||
keep layout
|
||||
rescue => e
|
||||
puts "for #{object.name}"
|
||||
raise e
|
||||
return if object.nil?
|
||||
return unless Machine.instance.add_object object
|
||||
# puts "adding #{object.class}"
|
||||
unless object.has_layout?
|
||||
object.init_layout
|
||||
end
|
||||
layout = object.get_layout
|
||||
puts "Layout #{layout.get_object_class.name} #{Machine.instance.objects.include?(layout)}"
|
||||
keep layout
|
||||
layout.each do |name|
|
||||
inst = object.instance_variable_get "@#{name}".to_sym
|
||||
keep inst
|
||||
|
Loading…
Reference in New Issue
Block a user