rename the objects accessor

and move to object keys, not object_id
This commit is contained in:
Torsten Ruger 2018-06-15 09:18:39 +03:00
parent 3cc9175efa
commit 2c765c8f14
8 changed files with 18 additions and 15 deletions

View File

@ -36,7 +36,7 @@ module Elf
end end
end end
@machine.objects.each do |id,slot| @machine.object_positions.each do |slot , position|
next if slot.is_a?(Parfait::BinaryCode) next if slot.is_a?(Parfait::BinaryCode)
if( slot.respond_to? :rxf_reference_name ) if( slot.respond_to? :rxf_reference_name )
label = "#{slot.rxf_reference_name}" label = "#{slot.rxf_reference_name}"

View File

@ -30,7 +30,7 @@ module Risc
# Objects are data and get assembled after functions # Objects are data and get assembled after functions
def self.add_object( objekt , depth) def self.add_object( objekt , depth)
return false if @objects[objekt.object_id] return false if @objects[objekt]
return true if objekt.is_a? Fixnum return true if objekt.is_a? Fixnum
return true if objekt.is_a?( Risc::Label) return true if objekt.is_a?( Risc::Label)
#puts message(objekt , depth) #puts message(objekt , depth)
@ -39,7 +39,7 @@ module Risc
raise "adding non parfait #{objekt.class}:#{objekt}" raise "adding non parfait #{objekt.class}:#{objekt}"
end end
#raise "Method #{objekt.name}" if objekt.is_a? Parfait::TypedMethod #raise "Method #{objekt.name}" if objekt.is_a? Parfait::TypedMethod
@objects[objekt.object_id] = objekt @objects[objekt] = objekt
true true
end end

View File

@ -47,8 +47,9 @@ module Risc
end end
end end
# machine keeps a list of all objects. this is lazily created with a collector # machine keeps a list of all objects and their positions.
def objects # this is lazily created with a collector
def object_positions
@objects ||= Collector.collect_space @objects ||= Collector.collect_space
end end
@ -96,7 +97,9 @@ module Risc
# return final position that is stored in code_start # return final position that is stored in code_start
def position_objects(at) def position_objects(at)
# want to have the objects first in the executable # want to have the objects first in the executable
sorted = objects.values.sort{|left,right| left.class.name <=> right.class.name} sorted = object_positions.values.sort do |left,right|
left.class.name <=> right.class.name
end
previous = nil previous = nil
sorted.each do | objekt| sorted.each do | objekt|
next if objekt.is_a?( Parfait::BinaryCode) or objekt.is_a?( Risc::Label ) next if objekt.is_a?( Parfait::BinaryCode) or objekt.is_a?( Risc::Label )
@ -141,7 +144,7 @@ module Risc
# constant loads into one instruction. # constant loads into one instruction.
# #
def create_binary def create_binary
objects.each do |id , method| object_positions.each do |id , method|
next unless method.is_a? Parfait::TypedMethod next unless method.is_a? Parfait::TypedMethod
writer = BinaryWriter.new(method.binary) writer = BinaryWriter.new(method.binary)
writer.assemble(method.cpu_instructions) writer.assemble(method.cpu_instructions)

View File

@ -35,7 +35,7 @@ module Risc
end end
def sorted_objects def sorted_objects
@machine.objects.values.sort do |left , right| @machine.object_positions.values.sort do |left , right|
Position.get(left).at <=> Position.get(right).at Position.get(left).at <=> Position.get(right).at
end end
end end
@ -118,7 +118,7 @@ module Risc
def write_object_check(object) def write_object_check(object)
log.debug "Write object #{object.class} #{object.inspect[0..100]}" log.debug "Write object #{object.class} #{object.inspect[0..100]}"
#Only initially created codes are collected. Binary_init and method "tails" not #Only initially created codes are collected. Binary_init and method "tails" not
if !@machine.objects.has_key?(object.object_id) and !object.is_a?(Parfait::BinaryCode) if !@machine.object_positions.has_key?(object) and !object.is_a?(Parfait::BinaryCode)
log.debug "Object at 0x#{Position.get(object).to_s(16)}:#{object.get_type()}" log.debug "Object at 0x#{Position.get(object).to_s(16)}:#{object.get_type()}"
raise "Object(0x#{object.object_id.to_s(16)}) not linked #{object.inspect}" raise "Object(0x#{object.object_id.to_s(16)}) not linked #{object.inspect}"
end end

View File

@ -34,7 +34,7 @@ module Risc
end end
def has_positions(platform) def has_positions(platform)
setup_for(platform) setup_for(platform)
@machine.objects.each do |id,obj| @machine.object_positions.each do |obj , pos|
assert Position.get(obj) assert Position.get(obj)
end end
end end

View File

@ -54,7 +54,7 @@ module Risc
@machine.translate(:interpreter) @machine.translate(:interpreter)
@machine.position_all @machine.position_all
@machine.create_binary @machine.create_binary
@machine.objects.each do |id , method| @machine.object_positions.each do | method , position|
next unless method.is_a? Parfait::TypedMethod next unless method.is_a? Parfait::TypedMethod
method.cpu_instructions.each do |ins| method.cpu_instructions.each do |ins|
ins.assemble(DevNull.new) ins.assemble(DevNull.new)

View File

@ -7,7 +7,7 @@ module Risc
@machine = Risc.machine.boot @machine = Risc.machine.boot
end end
def test_objects def test_objects
objects = @machine.objects objects = @machine.object_positions
assert_equal Hash , objects.class assert_equal Hash , objects.class
assert 350 < objects.length assert 350 < objects.length
end end
@ -41,7 +41,7 @@ module Risc
@machine.position_all @machine.position_all
end end
def test_positions_set def test_positions_set
@machine.objects.each do |id,obj| @machine.object_positions.each do |id,obj|
assert Position.get(obj).valid? , "#{Position.get(obj)} , #{obj.object_id.to_s(16)}" assert Position.get(obj).valid? , "#{Position.get(obj)} , #{obj.object_id.to_s(16)}"
end end
end end
@ -71,7 +71,7 @@ module Risc
assert 0 != bin.get_word(0) , "index 0 is 0 #{bin.inspect}" assert 0 != bin.get_word(0) , "index 0 is 0 #{bin.inspect}"
end end
def test_positions_set def test_positions_set
@machine.objects.each do |id,obj| @machine.object_positions.each do |id,obj|
assert Position.get(obj).valid? , "#{Position.get(obj)} , #{obj.object_id.to_s(16)}" assert Position.get(obj).valid? , "#{Position.get(obj)} , #{obj.object_id.to_s(16)}"
end end
end end

View File

@ -30,7 +30,7 @@ module Risc
def test_no_risc #by assembling, risc doesnt have assemble method def test_no_risc #by assembling, risc doesnt have assemble method
@machine.translate(:arm) @machine.translate(:arm)
@machine.position_all @machine.position_all
@machine.objects.each do |id , method| @machine.object_positions.each do |method , position|
next unless method.is_a? Parfait::TypedMethod next unless method.is_a? Parfait::TypedMethod
method.cpu_instructions.each do |ins| method.cpu_instructions.each do |ins|
ins.assemble(DevNull.new) ins.assemble(DevNull.new)