better assembly

but bug is still scuttling around there in
link/assembly process
This commit is contained in:
Torsten Ruger 2015-05-31 14:45:28 +03:00
parent 7a5cf03d73
commit 1509e7ba2f
2 changed files with 41 additions and 24 deletions

View File

@ -31,6 +31,7 @@ module Register
@machine.objects.each do |objekt| @machine.objects.each do |objekt|
next unless objekt.is_a? Parfait::BinaryCode next unless objekt.is_a? Parfait::BinaryCode
objekt.set_position at objekt.set_position at
# puts "CODE #{objekt.name} at #{objekt.position}"
at += objekt.mem_length at += objekt.mem_length
end end
# and then everything else # and then everything else
@ -47,7 +48,7 @@ module Register
end end
def assemble def assemble
#slightly analogous to the link # must be same order as link
begin begin
link link
# first we need to create the binary code for the methods # first we need to create the binary code for the methods
@ -96,8 +97,9 @@ module Register
raise "length error #{method.code.get_length}" if index > method.info.get_length raise "length error #{method.code.get_length}" if index > method.info.get_length
end end
end end
def assemble_any obj def assemble_any obj
puts "Assemble #{obj.class}(\n#{obj.to_s[0..500]}) at stream #{(@stream.length).to_s(16)} pos:#{obj.position.to_s(16)} , len:#{obj.mem_length}" puts "Assemble #{obj.class} at stream #{(@stream.length).to_s(16)} pos:#{obj.position.to_s(16)} , len:#{obj.mem_length}"
if @stream.length != obj.position if @stream.length != obj.position
raise "Assemble #{obj.class} at #{@stream.length.to_s(16)} not #{obj.position.to_s(16)}" raise "Assemble #{obj.class} at #{@stream.length.to_s(16)} not #{obj.position.to_s(16)}"
end end
@ -108,28 +110,34 @@ module Register
def type_word array def type_word array
word = 0 word = 0
array.each_with_index do |var , index| index = 0
type = (var.class == Integer) ? TYPE_INT : TYPE_REF array.each do |var |
#type = (var.class == Integer) ? TYPE_INT : TYPE_REF
#TODO
type = TYPE_REF
word += type << (index * TYPE_BITS) word += type << (index * TYPE_BITS)
index = index + 1
end end
word += ( (array.length + 1 ) / 8 ) << TYPE_LENGTH * TYPE_BITS word += ( (array.get_length + 1 ) / 8 ) << TYPE_LENGTH * TYPE_BITS
word word
end end
# write type and layout of the instance, and the variables that are passed # write type and layout of the instance, and the variables that are passed
# variables ar values, ie int or refs. For refs the object needs to save the object first # variables ar values, ie int or refs. For refs the object needs to save the object first
def assemble_self( object , variables ) def assemble_object( object )
unless @objects[object.object_id] unless @machine.objects.include? object
raise "Object(#{object.object_id}) not linked #{object.inspect}" raise "Object(#{object.object_id}) not linked #{object.inspect}"
end end
type = type_word(variables) layout = object.get_layout
type = type_word(layout)
@stream.write_uint32( type ) @stream.write_uint32( type )
write_ref_for(object.layout[:names] ) write_ref_for(layout )
variables.each do |var| layout.each do |var|
raise object.class.name unless var inst = object.instance_variable_get "@#{var}".to_sym
write_ref_for(var) puts "Nil for #{object.class}.#{var}" unless inst
write_ref_for(inst)
end end
pad_after( variables.length * 4 ) pad_after( layout.get_length * 4 )
object.position object.position
end end
@ -146,22 +154,22 @@ module Register
def assemble_Dictionary hash def assemble_Dictionary hash
# so here we can be sure to have _identical_ keys/values arrays # so here we can be sure to have _identical_ keys/values arrays
assemble_self( hash , [ hash.keys , hash.values ] ) assemble_object( hash , [ hash.keys , hash.values ] )
end end
def assemble_Space(machine) def assemble_Space(space)
assemble_self(machine , [machine.classes,machine.messages,machine.next_message,machine.next_frame] ) assemble_object(space )
end end
def assemble_Class(clazz) def assemble_Class(clazz)
assemble_self( clazz , [clazz.name , clazz.super_class_name, clazz.instance_methods] ) assemble_object( clazz )
end end
def assemble_Message me def assemble_Message me
assemble_self(me , []) assemble_object(me)
end end
def assemble_Frame me def assemble_Frame me
assemble_self(me , []) assemble_object(me )
end end
def assemble_Method(method) def assemble_Method(method)

View File

@ -26,6 +26,7 @@ module Virtual
layouts = { "Word" => [] , layouts = { "Word" => [] ,
"List" => [] , "List" => [] ,
"Message" => [], "Message" => [],
"MetaClass" => [],
"BinaryCode" => [], "BinaryCode" => [],
"Space" => ["classes","frames","messages","next_message","next_frame"], "Space" => ["classes","frames","messages","next_message","next_frame"],
"Frame" => ["locals" , "tmps" ], "Frame" => ["locals" , "tmps" ],
@ -44,10 +45,6 @@ module Virtual
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
supers = { "BinaryCode" => "Word", "Layout" => "List", "Class" => "Module"}
supers.each do |clazz , superclaszz| # set_super_class has no sideeffects, so setting twice ok
class_mappings[clazz].set_super_class class_mappings[superclaszz]
end
# next create layouts by adding instance variable names to the layouts # next create layouts by adding instance variable names to the layouts
class_mappings.each do |name , clazz| class_mappings.each do |name , clazz|
variables = layouts[name] variables = layouts[name]
@ -55,6 +52,18 @@ module Virtual
clazz.object_layout.add_instance_variable Virtual.new_word(var_name) clazz.object_layout.add_instance_variable Virtual.new_word(var_name)
end end
end end
# superclass and layout corrections
supers = { "BinaryCode" => "Word", "Layout" => "List", "Class" => "Module"}
supers.each do |classname , superclass_name|
clazz = class_mappings[classname]
super_class = class_mappings[superclass_name]
# set_super_class has no sideeffects, so setting twice ok
clazz.set_super_class super_class
# Add superclass layout too
super_class.object_layout.each do |var|
clazz.object_layout.add_instance_variable var
end
end
# now store the classes so we can hand them out later during object creation # now store the classes so we can hand them out later during object creation
# this can not be done earlier, as parfait objects are all the time created and would # this can not be done earlier, as parfait objects are all the time created and would