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:
parent
a1197fb70c
commit
56f2742e89
@ -69,7 +69,7 @@ module Risc
|
|||||||
previous.position_listener(objekt) if previous
|
previous.position_listener(objekt) if previous
|
||||||
previous = position
|
previous = position
|
||||||
at += objekt.padded_length
|
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
|
end
|
||||||
at
|
at
|
||||||
end
|
end
|
||||||
|
@ -17,22 +17,23 @@ module Risc
|
|||||||
def position_inserted(position)
|
def position_inserted(position)
|
||||||
Position.log.debug "extending one at #{position}"
|
Position.log.debug "extending one at #{position}"
|
||||||
pos = CodeListener.init( position.object.next , @platform)
|
pos = CodeListener.init( position.object.next , @platform)
|
||||||
|
raise "HI #{position}" unless position.valid?
|
||||||
return 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)
|
pos.set( position + position.object.padded_length)
|
||||||
set_jump_for(position)
|
set_jump_for(position)
|
||||||
end
|
end
|
||||||
|
|
||||||
def position_changed(position)
|
def position_changed(position)
|
||||||
|
Position.log.debug "Code changed #{position}"
|
||||||
nekst = position.object.next
|
nekst = position.object.next
|
||||||
if( nekst )
|
if( nekst )
|
||||||
nekst_pos = Position.get(nekst)
|
nekst_pos = Position.get(nekst)
|
||||||
unless(nekst_pos.valid?)
|
Position.log.debug "Code changed, setting next #{position}"
|
||||||
nekst_pos.set(position + position.object.padded_length)
|
nekst_pos.set(position + position.object.padded_length)
|
||||||
end
|
|
||||||
end
|
|
||||||
set_jump_for(position)
|
set_jump_for(position)
|
||||||
end
|
end
|
||||||
|
end
|
||||||
|
|
||||||
def position_changing(position , to)
|
def position_changing(position , to)
|
||||||
move_along = Position.at( to )
|
move_along = Position.at( to )
|
||||||
|
@ -25,7 +25,7 @@ module Risc
|
|||||||
# Taking into account that BinaryCodes only take 13 instructions,
|
# Taking into account that BinaryCodes only take 13 instructions,
|
||||||
# meaning that chain may have to be extended
|
# meaning that chain may have to be extended
|
||||||
def position_changing(position , to)
|
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)
|
update_index(to)
|
||||||
instruction = position.object
|
instruction = position.object
|
||||||
return unless instruction.next
|
return unless instruction.next
|
||||||
@ -43,8 +43,11 @@ module Risc
|
|||||||
index = (to - Position.get(@binary).at) / 4
|
index = (to - Position.get(@binary).at) / 4
|
||||||
raise "Invalid negative index #{index} , #{Position.get(@binary)}" if index < Parfait::BinaryCode.type_length
|
raise "Invalid negative index #{index} , #{Position.get(@binary)}" if index < Parfait::BinaryCode.type_length
|
||||||
while(index >= (Parfait::BinaryCode.memory_size - 1) )
|
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
|
@binary = @binary.ensure_next
|
||||||
|
Position.log.debug "Binary Extended (#{index}) #{Position.get(@binary)}"
|
||||||
index = (to - Position.get(@binary).at) / 4
|
index = (to - Position.get(@binary).at) / 4
|
||||||
|
Position.log.debug "Binary Extended new index (#{index}) #{Position.get(@binary)}"
|
||||||
end
|
end
|
||||||
@index = index - 2
|
@index = index - 2
|
||||||
raise "Invalid negative index #{@index} , #{Position.get(@binary)}" if index < 0
|
raise "Invalid negative index #{@index} , #{Position.get(@binary)}" if index < 0
|
||||||
|
@ -21,9 +21,8 @@ module Risc
|
|||||||
end
|
end
|
||||||
class DummyPlatform
|
class DummyPlatform
|
||||||
def self.boot
|
def self.boot
|
||||||
machine = Risc.machine.boot
|
Parfait.boot!
|
||||||
machine.set_platform( self.new )
|
Risc.boot!
|
||||||
machine
|
|
||||||
end
|
end
|
||||||
def translator
|
def translator
|
||||||
DummyTranslator.new
|
DummyTranslator.new
|
||||||
|
@ -5,7 +5,7 @@ module Risc
|
|||||||
def setup
|
def setup
|
||||||
DummyPlatform.boot
|
DummyPlatform.boot
|
||||||
@binary = Parfait::BinaryCode.new(1)
|
@binary = Parfait::BinaryCode.new(1)
|
||||||
@bin_pos = CodeListener.init(@binary).set(0)
|
@bin_pos = CodeListener.init(@binary, :interpreter).set(0)
|
||||||
@instruction = DummyInstruction.new
|
@instruction = DummyInstruction.new
|
||||||
13.times {@instruction.last.insert(DummyInstruction.new) }
|
13.times {@instruction.last.insert(DummyInstruction.new) }
|
||||||
@position = InstructionListener.init(@instruction , @binary)
|
@position = InstructionListener.init(@instruction , @binary)
|
||||||
|
@ -17,19 +17,6 @@ module Risc
|
|||||||
assert_raises {@machine.add_constant( 1 )}
|
assert_raises {@machine.add_constant( 1 )}
|
||||||
end
|
end
|
||||||
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
|
class TestMachineInit < MiniTest::Test
|
||||||
def setup
|
def setup
|
||||||
Parfait.boot!
|
Parfait.boot!
|
||||||
@ -60,6 +47,5 @@ module Risc
|
|||||||
assert position.valid? , "#{position} , #{obj.object_id.to_s(16)}"
|
assert position.valid? , "#{position} , #{obj.object_id.to_s(16)}"
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
17
test/risc/test_linker1.rb
Normal file
17
test/risc/test_linker1.rb
Normal 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
|
Loading…
Reference in New Issue
Block a user