objects didn't get positions

positions.empty? was wrong check
This commit is contained in:
Torsten Ruger 2018-06-16 10:58:54 +03:00
parent 698c845297
commit 7543236f4f
9 changed files with 17 additions and 28 deletions

View File

@ -50,7 +50,7 @@ module Risc
# machine keeps a list of all objects and their positions. # machine keeps a list of all objects and their positions.
# this is lazily created with a collector # this is lazily created with a collector
def object_positions def object_positions
Collector.collect_space if Position.positions.empty? Collector.collect_space if Position.positions.length < 2 #one is the label
Position.positions Position.positions
end end
@ -105,9 +105,7 @@ module Risc
sorted.each do |objekt| sorted.each do |objekt|
next unless Position.is_object(objekt) next unless Position.is_object(objekt)
before = at before = at
unless( Position.set?(objekt)) raise objekt.class unless( Position.set?(objekt)) #debug check
raise objekt.class
end
position = Position.get(objekt).set(at) position = Position.get(objekt).set(at)
previous.position_listener(objekt) if previous previous.position_listener(objekt) if previous
previous = position previous = position
@ -145,7 +143,7 @@ module Risc
# constant loads into one instruction. # constant loads into one instruction.
# #
def create_binary def create_binary
object_positions.each do |method,position| object_positions.keys.each do |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

@ -13,6 +13,7 @@ module Risc
Position.log.debug "extending one at #{position}" Position.log.debug "extending one at #{position}"
pos = CodeListener.init( position.object.next ) pos = CodeListener.init( position.object.next )
return unless position.valid? return unless position.valid?
puts "insert #{position.object.next.object_id.to_s(16)}" unless position.valid?
pos.set( position + position.object.padded_length) pos.set( position + position.object.padded_length)
set_jump_for(position) set_jump_for(position)
end end

View File

@ -91,8 +91,7 @@ module Risc
while(instruction) while(instruction)
position = Position.get_or_create(instruction) position = Position.get_or_create(instruction)
first = position unless first first = position unless first
il = InstructionListener.new( code ) position.position_listener( InstructionListener.new( code ) )
position.position_listener(il)
if instruction.respond_to?(:branch) if instruction.respond_to?(:branch)
# label_pos = Position.get(instruction.branch) # label_pos = Position.get(instruction.branch)
# label_pos.position_listener( BranchListener.new(il)) # label_pos.position_listener( BranchListener.new(il))

View File

@ -69,7 +69,7 @@ module Risc
def set(int) def set(int)
return int if int == self.at return int if int == self.at
trigger_changing( int ) trigger_changing( int )
Position.set_to(self , int) Position.set_cache(self , int)
@at = int @at = int
trigger_changed trigger_changed
self self
@ -157,9 +157,9 @@ module Risc
if pos == nil if pos == nil
str = "position accessed but not initialized, " str = "position accessed but not initialized, "
str += "0x#{object.object_id.to_s(16)}\n" str += "0x#{object.object_id.to_s(16)}\n"
str += "for #{object.class} " str += "class: #{object.class} "
str += "byte_length #{object.byte_length}" if object.respond_to?(:byte_length) str += "byte_length #{object.byte_length}" if object.respond_to?(:byte_length)
str += " for #{object.to_s[0...130]}" str += " object: #{object.to_s[0...130]}"
raise str raise str
end end
pos pos
@ -186,7 +186,7 @@ module Risc
# forward caches object -> position # forward caches object -> position
# reverse caches position.at > position # reverse caches position.at > position
# Labels do not participatein reverse cache # Labels do not participatein reverse cache
def self.set_to( position , to) def self.set_cache( position , to)
postest = Position.positions[position.object] unless to < 0 postest = Position.positions[position.object] unless to < 0
raise "Mismatch #{position}" if postest and postest != position raise "Mismatch #{position}" if postest and postest != position
@reverse_cache.delete(position.at) unless position.object.is_a?(Label) @reverse_cache.delete(position.at) unless position.object.is_a?(Label)

View File

@ -19,15 +19,14 @@ module Risc
def position_changing(position , to) def position_changing(position , to)
end end
# when the argument changes position, we update the objects # when the argument changes position, we update the next objects
# position to reflect that change # position to reflect that change
# #
def position_changed(previous) def position_changed(previous)
add = previous.object ? previous.object.padded_length : 0 add = previous.object ? previous.object.padded_length : 0
my_pos = previous.at + add next_at = previous.at + add
object_pos = Position.get(@object) next_pos = Position.get(@object)
return if my_pos == object_pos.at next_pos.set(next_at)
Position.set_to(object_pos , my_pos)
end end
end end
end end

View File

@ -104,7 +104,6 @@ module Risc
# write type of the instance, and the variables that are passed # write type 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 write_object( object ) def write_object( object )
write_object_check(object)
obj_written = write_object_variables(object) obj_written = write_object_variables(object)
log.debug "instances=#{object.get_instance_variables.inspect} mem_len=0x#{object.padded_length.to_s(16)}" log.debug "instances=#{object.get_instance_variables.inspect} mem_len=0x#{object.padded_length.to_s(16)}"
indexed_written = write_object_indexed(object) indexed_written = write_object_indexed(object)
@ -114,15 +113,6 @@ module Risc
Position.get(object) Position.get(object)
end end
def write_object_check(object)
log.debug "Write object #{object.class} #{object.inspect[0..100]}"
#Only initially created codes are collected. Binary_init and method "tails" not
unless object.is_a?(Parfait::BinaryCode)
log.debug "Object at 0x#{Position.get(object)}:#{object.get_type()}"
raise "Object(0x#{object.object_id.to_s(16)}) not linked #{object.inspect}"
end
end
def write_object_indexed(object) def write_object_indexed(object)
written = 0 written = 0
if( object.is_a? Parfait::List) if( object.is_a? Parfait::List)

View File

@ -15,7 +15,7 @@ module Risc
end end
def test_no_fire def test_no_fire
@pos.position_listener(self) @pos.position_listener(self)
Position.set_to(@pos,0) @pos.set(0)
assert_equal 0 , Position.get(@object).at assert_equal 0 , Position.get(@object).at
end end
def test_at def test_at

View File

@ -33,6 +33,7 @@ module Risc
sorted_objects = @text_writer.sorted_objects sorted_objects = @text_writer.sorted_objects
sorted_objects.each_slice(2) do |l,r| sorted_objects.each_slice(2) do |l,r|
next unless r next unless r
next if l.is_a?(Label) or r.is_a?(Label)
assert Position.get(l).at < Position.get(r).at , "#{Position.get(l)} < #{Position.get(r)} , #{l.object_id.to_s(16)}, #{r.object_id.to_s(16)}" assert Position.get(l).at < Position.get(r).at , "#{Position.get(l)} < #{Position.get(r)} , #{l.object_id.to_s(16)}, #{r.object_id.to_s(16)}"
end end
end end
@ -41,6 +42,7 @@ module Risc
sorted_objects.shift sorted_objects.shift
sorted_objects.each_slice(2) do |l,r| sorted_objects.each_slice(2) do |l,r|
next unless r next unless r
next if l.is_a?(Label) or r.is_a?(Label)
assert Position.get(l).at < Position.get(r).at , "#{Position.get(l)} < #{Position.get(r)} , #{l.object_id.to_s(16)}, #{r.object_id.to_s(16)}" assert Position.get(l).at < Position.get(r).at , "#{Position.get(l)} < #{Position.get(r)} , #{l.object_id.to_s(16)}, #{r.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.object_positions.each do |method , position| @machine.object_positions.keys.each do |method|
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)