fix code listener logic bug

next's position was only updated initially
previous logic relied on pushing everything long rightly
but it wasn't right, and no harm in setting position twice,
as events only fire if there is real change
This commit is contained in:
Torsten Ruger 2018-07-02 23:03:00 +03:00
parent a1197fb70c
commit 56f2742e89
7 changed files with 31 additions and 25 deletions

View File

@ -69,7 +69,7 @@ module Risc
previous.position_listener(objekt) if previous
previous = position
at += objekt.padded_length
log.debug "Object #{objekt.class}:#{before.to_s(16)} len: #{(at - before).to_s(16)}"
log.debug "Object #{objekt.class}:0x#{before.to_s(16)} len: #{(at - before).to_s(16)}"
end
at
end

View File

@ -17,21 +17,22 @@ module Risc
def position_inserted(position)
Position.log.debug "extending one at #{position}"
pos = CodeListener.init( position.object.next , @platform)
raise "HI #{position}" unless position.valid?
return unless position.valid?
puts "insert #{position.object.next.object_id.to_s(16)}" unless position.valid?
Position.log.debug "insert #{position.object.next.object_id.to_s(16)}"
pos.set( position + position.object.padded_length)
set_jump_for(position)
end
def position_changed(position)
Position.log.debug "Code changed #{position}"
nekst = position.object.next
if( nekst )
nekst_pos = Position.get(nekst)
unless(nekst_pos.valid?)
nekst_pos.set(position + position.object.padded_length)
end
Position.log.debug "Code changed, setting next #{position}"
nekst_pos.set(position + position.object.padded_length)
set_jump_for(position)
end
set_jump_for(position)
end
def position_changing(position , to)

View File

@ -25,7 +25,7 @@ module Risc
# Taking into account that BinaryCodes only take 13 instructions,
# meaning that chain may have to be extended
def position_changing(position , to)
Position.log.debug "Changing #{position} to 0x#{to.to_s(16)}, bin #{Position.get(@binary)}"
Position.log.debug "Instruction from #{position} to 0x#{to.to_s(16)}, bin #{Position.get(@binary)}"
update_index(to)
instruction = position.object
return unless instruction.next
@ -43,8 +43,11 @@ module Risc
index = (to - Position.get(@binary).at) / 4
raise "Invalid negative index #{index} , #{Position.get(@binary)}" if index < Parfait::BinaryCode.type_length
while(index >= (Parfait::BinaryCode.memory_size - 1) )
Position.log.debug "Binary Extend (#{index}) #{Position.get(@binary)}, 0x#{@binary.object_id.to_s(16)}"
@binary = @binary.ensure_next
Position.log.debug "Binary Extended (#{index}) #{Position.get(@binary)}"
index = (to - Position.get(@binary).at) / 4
Position.log.debug "Binary Extended new index (#{index}) #{Position.get(@binary)}"
end
@index = index - 2
raise "Invalid negative index #{@index} , #{Position.get(@binary)}" if index < 0

View File

@ -21,9 +21,8 @@ module Risc
end
class DummyPlatform
def self.boot
machine = Risc.machine.boot
machine.set_platform( self.new )
machine
Parfait.boot!
Risc.boot!
end
def translator
DummyTranslator.new

View File

@ -5,7 +5,7 @@ module Risc
def setup
DummyPlatform.boot
@binary = Parfait::BinaryCode.new(1)
@bin_pos = CodeListener.init(@binary).set(0)
@bin_pos = CodeListener.init(@binary, :interpreter).set(0)
@instruction = DummyInstruction.new
13.times {@instruction.last.insert(DummyInstruction.new) }
@position = InstructionListener.init(@instruction , @binary)

View File

@ -17,19 +17,6 @@ module Risc
assert_raises {@machine.add_constant( 1 )}
end
end
class TestMachinePos < MiniTest::Test
def setup
Parfait.boot!
Risc.boot!
@linker = Mom::MomCompiler.new.translate(:arm)
@linker.position_all
end
def test_positions_set
@linker.object_positions.each do |obj , position|
assert Position.get(obj).valid? , "#{Position.get(obj)} , #{obj.object_id.to_s(16)}"
end
end
end
class TestMachineInit < MiniTest::Test
def setup
Parfait.boot!
@ -60,6 +47,5 @@ module Risc
assert position.valid? , "#{position} , #{obj.object_id.to_s(16)}"
end
end
end
end

17
test/risc/test_linker1.rb Normal file
View File

@ -0,0 +1,17 @@
require_relative "helper"
module Risc
class TestMachinePos < MiniTest::Test
def setup
Parfait.boot!
Risc.boot!
@linker = RubyX::RubyXCompiler.new("class Space; def main(arg);a = 1;return a;end;end").ruby_to_risc(:arm)
@linker.position_all
end
def test_positions_set
@linker.object_positions.each do |obj , position|
assert Position.get(obj).valid? , "#{Position.get(obj)} , #{obj.object_id.to_s(16)}"
end
end
end
end